Files
flagger/pkg/router/util.go
Jiří Pinkava d2564874ab Fix panic when annotation of ingress is empty
When the annotation of ingress is not set, the returned value is nil
(not empty map). Trying to assign to this map leads to panic.

Signed-off-by: Jiří Pinkava <j-pi@seznam.cz>
2023-05-29 11:27:28 +02:00

40 lines
1.0 KiB
Go

package router
import (
"strings"
)
const (
toolkitMarker = "toolkit.fluxcd.io"
toolkitReconcileKey = "kustomize.toolkit.fluxcd.io/reconcile"
helmDriftDetectionKey = "helm.toolkit.fluxcd.io/driftDetection"
toolkitReconcileValue = "disabled"
)
func includeLabelsByPrefix(labels map[string]string, includeLabelPrefixes []string) map[string]string {
filteredLabels := make(map[string]string)
for key, value := range labels {
if strings.Contains(key, toolkitMarker) {
continue
}
for _, includeLabelPrefix := range includeLabelPrefixes {
if includeLabelPrefix == "*" || (includeLabelPrefix != "" && strings.HasPrefix(key, includeLabelPrefix)) {
filteredLabels[key] = value
break
}
}
}
return filteredLabels
}
func filterMetadata(meta map[string]string) map[string]string {
if meta == nil {
meta = map[string]string{}
}
// prevent Flux from overriding Flagger managed objects
meta[toolkitReconcileKey] = toolkitReconcileValue
meta[helmDriftDetectionKey] = toolkitReconcileValue
return meta
}