feat: allow all network properties to be globally set

Global settings are cool if managed in a standard way (ugh env vars) so we'll add them back for golang plugins as necessary.
This commit is contained in:
Jose Diaz-Gonzalez
2021-03-22 17:13:54 -04:00
parent 84907be0cd
commit 8d26d06f5e
5 changed files with 210 additions and 41 deletions

View File

@@ -20,9 +20,7 @@ func attachAppToNetwork(containerID string, networkName string, appName string,
}
if phase == "deploy" {
property := "tld"
defaultValue := GetDefaultValue(property)
tld := common.PropertyGetDefault("network", appName, property, defaultValue)
tld := reportComputedTld(appName)
networkAlias := fmt.Sprintf("%v.%v", appName, processType)
if tld != "" {
@@ -62,14 +60,13 @@ func isConflictingPropertyValue(appName string, property string, value string) b
return false
}
otherProperty := "attach-post-create"
if property == otherProperty {
otherProperty = "attach-post-deploy"
otherValue := ""
if property == "attach-post-create" {
otherValue = reportComputedAttachPostDeploy(appName)
} else {
otherValue = reportComputedAttachPostCreate(appName)
}
defaultValue := GetDefaultValue(otherProperty)
otherValue := common.PropertyGetDefault("network", appName, otherProperty, defaultValue)
return value == otherValue
}

View File

@@ -17,7 +17,7 @@ import (
var (
// DefaultProperties is a map of all valid network properties with corresponding default property values
DefaultProperties = map[string]string{
"bind-all-interfaces": "false",
"bind-all-interfaces": "",
"attach-post-create": "",
"attach-post-deploy": "",
"initial-network": "",
@@ -26,7 +26,11 @@ var (
// GlobalProperties is a map of all valid global network properties
GlobalProperties = map[string]bool{
"initial-network": true,
"bind-all-interfaces": true,
"attach-post-create": true,
"attach-post-deploy": true,
"initial-network": true,
"tld": true,
}
)

View File

@@ -13,13 +13,22 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
}
flags := map[string]common.ReportFunc{
"--network-bind-all-interfaces": reportBindAllInterfaces,
"--network-attach-post-create": reportAttachPostCreate,
"--network-attach-post-deploy": reportAttachPostDeploy,
"--network-computed-initial-network": reportComputedInitialNetwork,
"--network-global-initial-network": reportGlobalInitialNetwork,
"--network-initial-network": reportInitialNetwork,
"--network-web-listeners": reportWebListeners,
"--network-bind-all-interfaces": reportBindAllInterfaces,
"--network-attach-post-create": reportAttachPostCreate,
"--network-attach-post-deploy": reportAttachPostDeploy,
"--network-computed-attach-post-create": reportComputedAttachPostCreate,
"--network-computed-attach-post-deploy": reportComputedAttachPostDeploy,
"--network-computed-bind-all-interfaces": reportComputedBindAllInterfaces,
"--network-computed-initial-network": reportComputedInitialNetwork,
"--network-computed-tld": reportComputedTld,
"--network-global-attach-post-create": reportGlobalAttachPostCreate,
"--network-global-attach-post-deploy": reportGlobalAttachPostDeploy,
"--network-global-bind-all-interfaces": reportGlobalBindAllInterfaces,
"--network-global-initial-network": reportGlobalInitialNetwork,
"--network-global-tld": reportGlobalTld,
"--network-initial-network": reportInitialNetwork,
"--network-tld": reportTld,
"--network-web-listeners": reportWebListeners,
}
flagKeys := []string{}
@@ -33,10 +42,6 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
return common.ReportSingleApp("network", appName, infoFlag, infoFlags, flagKeys, format, trimPrefix, uppercaseFirstCharacter)
}
func reportBindAllInterfaces(appName string) string {
return common.PropertyGet("network", appName, "bind-all-interfaces")
}
func reportAttachPostCreate(appName string) string {
return common.PropertyGet("network", appName, "attach-post-create")
}
@@ -45,6 +50,37 @@ func reportAttachPostDeploy(appName string) string {
return common.PropertyGet("network", appName, "attach-post-deploy")
}
func reportBindAllInterfaces(appName string) string {
return common.PropertyGet("network", appName, "bind-all-interfaces")
}
func reportComputedAttachPostCreate(appName string) string {
value := reportAttachPostCreate(appName)
if value == "" {
value = reportGlobalAttachPostCreate(appName)
}
return value
}
func reportComputedAttachPostDeploy(appName string) string {
value := reportAttachPostDeploy(appName)
if value == "" {
value = reportGlobalAttachPostDeploy(appName)
}
return value
}
func reportComputedBindAllInterfaces(appName string) string {
value := reportBindAllInterfaces(appName)
if value == "" {
value = reportGlobalBindAllInterfaces(appName)
}
return value
}
func reportComputedInitialNetwork(appName string) string {
value := reportInitialNetwork(appName)
if value == "" {
@@ -54,14 +90,43 @@ func reportComputedInitialNetwork(appName string) string {
return value
}
func reportComputedTld(appName string) string {
value := reportTld(appName)
if value == "" {
value = reportGlobalTld(appName)
}
return value
}
func reportGlobalAttachPostCreate(appName string) string {
return common.PropertyGet("network", "--global", "attach-post-create")
}
func reportGlobalAttachPostDeploy(appName string) string {
return common.PropertyGet("network", "--global", "attach-post-deploy")
}
func reportGlobalBindAllInterfaces(appName string) string {
return common.PropertyGetDefault("network", "--global", "bind-all-interfaces", "false")
}
func reportGlobalInitialNetwork(appName string) string {
return common.PropertyGet("network", "--global", "initial-network")
}
func reportGlobalTld(appName string) string {
return common.PropertyGet("network", "--global", "tld")
}
func reportInitialNetwork(appName string) string {
return common.PropertyGet("network", appName, "initial-network")
}
func reportTld(appName string) string {
return common.PropertyGet("network", appName, "tld")
}
func reportWebListeners(appName string) string {
return strings.Join(GetListeners(appName, "web"), " ")
}

View File

@@ -123,9 +123,20 @@ func TriggerNetworkGetPort(appName string, processType string, containerID strin
// TriggerNetworkGetProperty writes the network property to stdout for a given app container
func TriggerNetworkGetProperty(appName string, property string) error {
defaultValue := GetDefaultValue(property)
value := common.PropertyGetDefault("network", appName, property, defaultValue)
fmt.Println(value)
computedValueMap := map[string]common.ReportFunc{
"attach-post-create": reportComputedAttachPostCreate,
"attach-post-deploy": reportComputedAttachPostDeploy,
"bind-all-interfaces": reportComputedBindAllInterfaces,
"initial-network": reportComputedInitialNetwork,
"tld": reportComputedTld,
}
fn, ok := computedValueMap[property]
if !ok {
return fmt.Errorf("Invalid network property specified: %v", property)
}
fmt.Println(fn(appName))
return nil
}
@@ -207,9 +218,7 @@ func TriggerPostContainerCreate(containerType string, containerID string, appNam
}
property := "attach-post-create"
defaultValue := GetDefaultValue(property)
networkName := common.PropertyGetDefault("network", appName, property, defaultValue)
networkName := reportComputedAttachPostCreate(appName)
if networkName == "" {
return nil
@@ -249,9 +258,7 @@ func TriggerPostDelete(appName string) error {
// TriggerCorePostDeploy associates the container with a specified network
func TriggerCorePostDeploy(appName string) error {
property := "attach-post-deploy"
defaultValue := GetDefaultValue(property)
networkName := common.PropertyGetDefault("network", appName, property, defaultValue)
networkName := reportComputedAttachPostDeploy(appName)
if networkName == "" {
return nil
}