chore: standardize variable naming
This commit is contained in:
1 parent
b24697443a
commit
a4c30c2ba9
10 files changed
+45
-45
No files matched your search
+10
-10
@@ -52,7 +52,7 @@ func BuildConfig(appName string) {
|
|||||||
if len(procParts) != 2 {
|
if len(procParts) != 2 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
procType := procParts[0]
|
processType := procParts[0]
|
||||||
procCount, err := strconv.Atoi(procParts[1])
|
procCount, err := strconv.Atoi(procParts[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
@@ -62,25 +62,25 @@ func BuildConfig(appName string) {
|
|||||||
for containerIndex < procCount {
|
for containerIndex < procCount {
|
||||||
containerIndex++
|
containerIndex++
|
||||||
containerIndexString := strconv.Itoa(containerIndex)
|
containerIndexString := strconv.Itoa(containerIndex)
|
||||||
containerIDFile := fmt.Sprintf("%v/CONTAINER.%v.%v", appRoot, procType, containerIndex)
|
containerIDFile := fmt.Sprintf("%v/CONTAINER.%v.%v", appRoot, processType, containerIndex)
|
||||||
|
|
||||||
containerID := common.ReadFirstLine(containerIDFile)
|
containerID := common.ReadFirstLine(containerIDFile)
|
||||||
if containerID == "" || !common.ContainerIsRunning(containerID) {
|
if containerID == "" || !common.ContainerIsRunning(containerID) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ipAddress := GetContainerIpaddress(appName, procType, containerID)
|
ipAddress := GetContainerIpaddress(appName, processType, containerID)
|
||||||
port := GetContainerPort(appName, procType, isHerokuishContainer, containerID)
|
port := GetContainerPort(appName, processType, isHerokuishContainer, containerID)
|
||||||
|
|
||||||
if ipAddress != "" {
|
if ipAddress != "" {
|
||||||
_, err := sh.Command("plugn", "trigger", "network-write-ipaddr", appName, procType, containerIndexString, ipAddress).Output()
|
_, err := sh.Command("plugn", "trigger", "network-write-ipaddr", appName, processType, containerIndexString, ipAddress).Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.LogWarn(err.Error())
|
common.LogWarn(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if port != "" {
|
if port != "" {
|
||||||
_, err := sh.Command("plugn", "trigger", "network-write-port", appName, procType, containerIndexString, port).Output()
|
_, err := sh.Command("plugn", "trigger", "network-write-port", appName, processType, containerIndexString, port).Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.LogWarn(err.Error())
|
common.LogWarn(err.Error())
|
||||||
}
|
}
|
||||||
@@ -90,8 +90,8 @@ func BuildConfig(appName string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetContainerIpaddress returns the ipaddr for a given app container
|
// GetContainerIpaddress returns the ipaddr for a given app container
|
||||||
func GetContainerIpaddress(appName, procType, containerID string) (ipAddr string) {
|
func GetContainerIpaddress(appName, processType, containerID string) (ipAddr string) {
|
||||||
if procType != "web" {
|
if processType != "web" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,8 +109,8 @@ func GetContainerIpaddress(appName, procType, containerID string) (ipAddr string
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetContainerPort returns the port for a given app container
|
// GetContainerPort returns the port for a given app container
|
||||||
func GetContainerPort(appName, procType string, isHerokuishContainer bool, containerID string) (port string) {
|
func GetContainerPort(appName, processType string, isHerokuishContainer bool, containerID string) (port string) {
|
||||||
if procType != "web" {
|
if processType != "web" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
procType := flag.Arg(1)
|
processType := flag.Arg(1)
|
||||||
isHerokuishContainer := common.ToBool(flag.Arg(2))
|
isHerokuishContainer := common.ToBool(flag.Arg(2))
|
||||||
|
|
||||||
if procType != "web" {
|
if processType != "web" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
procType := flag.Arg(1)
|
processType := flag.Arg(1)
|
||||||
containerID := flag.Arg(2)
|
containerID := flag.Arg(2)
|
||||||
|
|
||||||
ipAddress := network.GetContainerIpaddress(appName, procType, containerID)
|
ipAddress := network.GetContainerIpaddress(appName, processType, containerID)
|
||||||
fmt.Fprintln(os.Stdout, ipAddress)
|
fmt.Fprintln(os.Stdout, ipAddress)
|
||||||
}
|
}
|
||||||
@@ -13,10 +13,10 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
procType := flag.Arg(1)
|
processType := flag.Arg(1)
|
||||||
isHerokuishContainer := common.ToBool(flag.Arg(2))
|
isHerokuishContainer := common.ToBool(flag.Arg(2))
|
||||||
containerID := flag.Arg(3)
|
containerID := flag.Arg(3)
|
||||||
|
|
||||||
port := network.GetContainerPort(appName, procType, isHerokuishContainer, containerID)
|
port := network.GetContainerPort(appName, processType, isHerokuishContainer, containerID)
|
||||||
fmt.Fprintln(os.Stdout, port)
|
fmt.Fprintln(os.Stdout, port)
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
procType := flag.Arg(1)
|
processType := flag.Arg(1)
|
||||||
containerIndex := flag.Arg(2)
|
containerIndex := flag.Arg(2)
|
||||||
ip := flag.Arg(3)
|
ip := flag.Arg(3)
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
appRoot := strings.Join([]string{common.MustGetEnv("DOKKU_ROOT"), appName}, "/")
|
appRoot := strings.Join([]string{common.MustGetEnv("DOKKU_ROOT"), appName}, "/")
|
||||||
filename := fmt.Sprintf("%v/IP.%v.%v", appRoot, procType, containerIndex)
|
filename := fmt.Sprintf("%v/IP.%v.%v", appRoot, processType, containerIndex)
|
||||||
f, err := os.Create(filename)
|
f, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.LogFail(err.Error())
|
common.LogFail(err.Error())
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
procType := flag.Arg(1)
|
processType := flag.Arg(1)
|
||||||
containerIndex := flag.Arg(2)
|
containerIndex := flag.Arg(2)
|
||||||
port := flag.Arg(3)
|
port := flag.Arg(3)
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
appRoot := strings.Join([]string{common.MustGetEnv("DOKKU_ROOT"), appName}, "/")
|
appRoot := strings.Join([]string{common.MustGetEnv("DOKKU_ROOT"), appName}, "/")
|
||||||
filename := fmt.Sprintf("%v/PORT.%v.%v", appRoot, procType, containerIndex)
|
filename := fmt.Sprintf("%v/PORT.%v.%v", appRoot, processType, containerIndex)
|
||||||
f, err := os.Create(filename)
|
f, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.LogFail(err.Error())
|
common.LogFail(err.Error())
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ func ReportSingleApp(appName, infoFlag string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetResourceValue fetches a single value for a given app/process/request/key combination
|
// GetResourceValue fetches a single value for a given app/process/request/key combination
|
||||||
func GetResourceValue(appName string, processType string, requestType string, key string) (string, error) {
|
func GetResourceValue(appName string, processType string, resourceType string, key string) (string, error) {
|
||||||
resources, err := common.PropertyGetAll("resource", appName)
|
resources, err := common.PropertyGetAll("resource", appName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -76,10 +76,10 @@ func GetResourceValue(appName string, processType string, requestType string, ke
|
|||||||
|
|
||||||
defaultValue := ""
|
defaultValue := ""
|
||||||
for key, value := range resources {
|
for key, value := range resources {
|
||||||
if key == propertyKey("_default_", requestType, key) {
|
if key == propertyKey("_default_", resourceType, key) {
|
||||||
defaultValue = value
|
defaultValue = value
|
||||||
}
|
}
|
||||||
if key == propertyKey(processType, requestType, key) {
|
if key == propertyKey(processType, resourceType, key) {
|
||||||
return value, nil
|
return value, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,8 +99,8 @@ func Right(str string, length int, pad string) string {
|
|||||||
return str + times(pad, length-len(str))
|
return str + times(pad, length-len(str))
|
||||||
}
|
}
|
||||||
|
|
||||||
func propertyKey(processType string, requestType string, key string) string {
|
func propertyKey(processType string, resourceType string, key string) string {
|
||||||
return fmt.Sprintf("%v.%v.%v", processType, requestType, key)
|
return fmt.Sprintf("%v.%v.%v", processType, resourceType, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAppName(args []string) (string, error) {
|
func getAppName(args []string) (string, error) {
|
||||||
|
|||||||
+2
-2
@@ -19,7 +19,7 @@ func main() {
|
|||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
procType := flag.Arg(3)
|
processType := flag.Arg(3)
|
||||||
|
|
||||||
resources, err := common.PropertyGetAll("resource", appName)
|
resources, err := common.PropertyGetAll("resource", appName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -38,7 +38,7 @@ func main() {
|
|||||||
validReservations := map[string]bool{
|
validReservations := map[string]bool{
|
||||||
"memory": true,
|
"memory": true,
|
||||||
}
|
}
|
||||||
validPrefixes := []string{"_default_.", fmt.Sprintf("%s.", procType)}
|
validPrefixes := []string{"_default_.", fmt.Sprintf("%s.", processType)}
|
||||||
for _, validPrefix := range validPrefixes {
|
for _, validPrefix := range validPrefixes {
|
||||||
for key, value := range resources {
|
for key, value := range resources {
|
||||||
if !strings.HasPrefix(key, validPrefix) {
|
if !strings.HasPrefix(key, validPrefix) {
|
||||||
|
|||||||
@@ -9,15 +9,15 @@ import (
|
|||||||
"github.com/dokku/dokku/plugins/resource"
|
"github.com/dokku/dokku/plugins/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
// writes the resource property to stdout for a given app container
|
// writes the resource key to stdout for a given app container
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
procType := flag.Arg(1)
|
processType := flag.Arg(1)
|
||||||
resourceType := flag.Arg(1)
|
resourceType := flag.Arg(1)
|
||||||
property := flag.Arg(1)
|
key := flag.Arg(1)
|
||||||
|
|
||||||
value, err := resource.GetResourceValue(appName, procType, resourceType, property)
|
value, err := resource.GetResourceValue(appName, processType, resourceType, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.LogFail(err.Error())
|
common.LogFail(err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ func CommandLimit(args []string, processType string, r Resource) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return setRequestType(appName, processType, r, "limit")
|
return setResourceType(appName, processType, r, "limit")
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandLimitClear implements resource:limit-clear
|
// CommandLimitClear implements resource:limit-clear
|
||||||
@@ -22,7 +22,7 @@ func CommandLimitClear(args []string, processType string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
clearByRequestType(appName, processType, "limit")
|
clearByResourceType(appName, processType, "limit")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ func CommandReserve(args []string, processType string, r Resource) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return setRequestType(appName, processType, r, "reserve")
|
return setResourceType(appName, processType, r, "reserve")
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandReserveClear implements resource:reserve-clear
|
// CommandReserveClear implements resource:reserve-clear
|
||||||
@@ -43,13 +43,13 @@ func CommandReserveClear(args []string, processType string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
clearByRequestType(appName, processType, "reserve")
|
clearByResourceType(appName, processType, "reserve")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func clearByRequestType(appName string, processType string, requestType string) {
|
func clearByResourceType(appName string, processType string, resourceType string) {
|
||||||
noun := "limits"
|
noun := "limits"
|
||||||
if requestType == "reserve" {
|
if resourceType == "reserve" {
|
||||||
noun = "reservation"
|
noun = "reservation"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,13 +78,13 @@ func clearByRequestType(appName string, processType string, requestType string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, key := range resources {
|
for _, key := range resources {
|
||||||
property := propertyKey(processType, requestType, key)
|
property := propertyKey(processType, resourceType, key)
|
||||||
common.PropertyDelete("resource", appName, property)
|
common.PropertyDelete("resource", appName, property)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setRequestType(appName string, processType string, r Resource, requestType string) error {
|
func setResourceType(appName string, processType string, r Resource, resourceType string) error {
|
||||||
if len(processType) == 0 {
|
if len(processType) == 0 {
|
||||||
processType = "_default_"
|
processType = "_default_"
|
||||||
}
|
}
|
||||||
@@ -106,12 +106,12 @@ func setRequestType(appName string, processType string, r Resource, requestType
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !hasValues {
|
if !hasValues {
|
||||||
reportRequestType(appName, processType, requestType)
|
reportResourceType(appName, processType, resourceType)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
noun := "limits"
|
noun := "limits"
|
||||||
if requestType == "reserve" {
|
if resourceType == "reserve" {
|
||||||
noun = "reservation"
|
noun = "reservation"
|
||||||
}
|
}
|
||||||
message := fmt.Sprintf("Setting resource %v for %v", noun, appName)
|
message := fmt.Sprintf("Setting resource %v for %v", noun, appName)
|
||||||
@@ -125,7 +125,7 @@ func setRequestType(appName string, processType string, r Resource, requestType
|
|||||||
common.LogVerbose(fmt.Sprintf("%v: %v", key, value))
|
common.LogVerbose(fmt.Sprintf("%v: %v", key, value))
|
||||||
}
|
}
|
||||||
|
|
||||||
property := propertyKey(processType, requestType, key)
|
property := propertyKey(processType, resourceType, key)
|
||||||
err := common.PropertyWrite("resource", appName, property, value)
|
err := common.PropertyWrite("resource", appName, property, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -135,9 +135,9 @@ func setRequestType(appName string, processType string, r Resource, requestType
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func reportRequestType(appName string, processType string, requestType string) {
|
func reportResourceType(appName string, processType string, resourceType string) {
|
||||||
noun := "limits"
|
noun := "limits"
|
||||||
if requestType == "reserve" {
|
if resourceType == "reserve" {
|
||||||
noun = "reservation"
|
noun = "reservation"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,7 +157,7 @@ func reportRequestType(appName string, processType string, requestType string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, key := range resources {
|
for _, key := range resources {
|
||||||
property := propertyKey(processType, requestType, key)
|
property := propertyKey(processType, resourceType, key)
|
||||||
value := common.PropertyGet("resource", appName, property)
|
value := common.PropertyGet("resource", appName, property)
|
||||||
common.LogVerbose(fmt.Sprintf("%v: %v", key, value))
|
common.LogVerbose(fmt.Sprintf("%v: %v", key, value))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user