WIP: check if labels are nil before adding labels #449

Closed
ammaratef45 wants to merge 1 commits from nil_labels into main

View File

@ -16,7 +16,7 @@ func SetRecipeLabel(compose *composetypes.Config, stackName string, recipe strin
if service.Name == "app" { if service.Name == "app" {
log.Debugf("set recipe label 'coop-cloud.%s.recipe' to %s for %s", stackName, recipe, stackName) log.Debugf("set recipe label 'coop-cloud.%s.recipe' to %s for %s", stackName, recipe, stackName)
labelKey := fmt.Sprintf("coop-cloud.%s.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" { if service.Name == "app" {
log.Debugf("set label 'coop-cloud.%s.chaos' to %v for %s", stackName, chaos, stackName) log.Debugf("set label 'coop-cloud.%s.chaos' to %v for %s", stackName, chaos, stackName)
labelKey := fmt.Sprintf("coop-cloud.%s.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" { if service.Name == "app" {
log.Debugf("set label 'coop-cloud.%s.chaos-version' to %v for %s", stackName, chaosVersion, stackName) 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) 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) 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) 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 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
Review

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"?

deploy:
  labels:
    - "coop-cloud.${STACK_NAME}.version=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?

We have an unwritten (🙈) convention to use `...version=unknown` when we don't know what the version label will be. For example: https://git.coopcloud.tech/coop-cloud/abra/src/commit/bba1640913d4fe1f8b04d9ca606d9f967a9352b4/pkg/upstream/stack/stack.go#L113 More examples [here](https://git.coopcloud.tech/coop-cloud/abra/search?q=%22unknown%22). So, maybe it's an idea to manually set the same config to be "unknown"? ```yaml deploy: labels: - "coop-cloud.${STACK_NAME}.version=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?
Review

Thanks for this comment, it made me realize my change silences the error but doesn't really add the labels

Gonna dig deeper

Thanks for this comment, it made me realize my change silences the error but doesn't really add the labels Gonna dig deeper
}
service.Deploy.Labels[labelKey] = value
}