WIP: check if labels are nil before adding labels #449
@ -16,7 +16,7 @@ func SetRecipeLabel(compose *composetypes.Config, stackName string, recipe strin
|
||||
if service.Name == "app" {
|
||||
log.Debugf("set recipe label 'coop-cloud.%s.recipe' to %s for %s", stackName, recipe, stackName)
|
||||
labelKey := fmt.Sprintf("coop-cloud.%s.recipe", stackName)
|
||||
service.Deploy.Labels[labelKey] = recipe
|
||||
AddLabel(service, labelKey, recipe)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -28,7 +28,7 @@ func SetChaosLabel(compose *composetypes.Config, stackName string, chaos bool) {
|
||||
if service.Name == "app" {
|
||||
log.Debugf("set label 'coop-cloud.%s.chaos' to %v for %s", stackName, chaos, stackName)
|
||||
labelKey := fmt.Sprintf("coop-cloud.%s.chaos", stackName)
|
||||
service.Deploy.Labels[labelKey] = strconv.FormatBool(chaos)
|
||||
AddLabel(service, labelKey, strconv.FormatBool(chaos))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -39,7 +39,7 @@ func SetChaosVersionLabel(compose *composetypes.Config, stackName string, chaosV
|
||||
if service.Name == "app" {
|
||||
log.Debugf("set label 'coop-cloud.%s.chaos-version' to %v for %s", stackName, chaosVersion, stackName)
|
||||
labelKey := fmt.Sprintf("coop-cloud.%s.chaos-version", stackName)
|
||||
service.Deploy.Labels[labelKey] = chaosVersion
|
||||
AddLabel(service, labelKey, chaosVersion)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -56,7 +56,7 @@ func SetUpdateLabel(compose *composetypes.Config, stackName string, appEnv envfi
|
||||
}
|
||||
log.Debugf("set label 'coop-cloud.%s.autoupdate' to %s for %s", stackName, enable_auto_update, stackName)
|
||||
labelKey := fmt.Sprintf("coop-cloud.%s.autoupdate", stackName)
|
||||
service.Deploy.Labels[labelKey] = enable_auto_update
|
||||
AddLabel(service, labelKey, enable_auto_update)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -86,3 +86,10 @@ func GetTimeoutFromLabel(compose *composetypes.Config, stackName string) (int, e
|
||||
}
|
||||
return timeout, err
|
||||
}
|
||||
|
||||
func AddLabel(service composetypes.ServiceConfig, labelKey string, value string) {
|
||||
if service.Deploy.Labels == nil {
|
||||
service.Deploy.Labels = composetypes.Labels{}
|
||||
decentral1se marked this conversation as resolved
|
||||
}
|
||||
service.Deploy.Labels[labelKey] = value
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user
We have an unwritten (🙈) convention to use
...version=unknown
when we don't know what the version label will be. For example:bba1640913/pkg/upstream/stack/stack.go (L113)
More examples here.
So, maybe it's an idea to manually set the same config to be "unknown"?
I think this might be important in the case of "set label" logic since other logic will try to read this label later on.
Or, maybe it's too complicated / too much assumption. I am not sure. This will set the label on the deployed containers but it won't be present on the compose config?
Thanks for this comment, it made me realize my change silences the error but doesn't really add the labels
Gonna dig deeper