Skip to content

Commit

Permalink
Merge pull request #936 from fluxcd/flux-gc-skip
Browse files Browse the repository at this point in the history
Remove Flux GC markers from generated objects
  • Loading branch information
stefanprodan authored Jun 15, 2021
2 parents 17c310d + cc67315 commit b2436eb
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions pkg/canary/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func makeAnnotations(annotations map[string]string) (map[string]string, error) {
id := fmt.Sprintf("%x-%x-%x-%x-%x", uuid[0:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:])

for k, v := range annotations {
// skip Flux GC markers
if strings.Contains(k, "/checksum") {
continue
}
if k != idKey {
res[k] = v
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/router/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (i *IngressRouter) SetRoutes(

func (i *IngressRouter) makeAnnotations(annotations map[string]string) map[string]string {
res := make(map[string]string)
for k, v := range annotations {
for k, v := range makeAnnotations(annotations) {
if !strings.Contains(k, i.GetAnnotationWithPrefix("canary")) &&
!strings.Contains(k, "kubectl.kubernetes.io/last-applied-configuration") &&
!strings.Contains(k, i.GetAnnotationWithPrefix("canary-weight")) &&
Expand All @@ -232,7 +232,7 @@ func (i *IngressRouter) makeAnnotations(annotations map[string]string) map[strin
func (i *IngressRouter) makeHeaderAnnotations(annotations map[string]string,
header string, headerValue string, headerRegex string, cookie string) map[string]string {
res := make(map[string]string)
for k, v := range annotations {
for k, v := range makeAnnotations(annotations) {
if !strings.Contains(v, i.GetAnnotationWithPrefix("canary")) {
res[k] = v
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/router/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error {

if vtClone.ObjectMeta.Annotations == nil {
vtClone.ObjectMeta.Annotations = make(map[string]string)
} else {
vtClone.ObjectMeta.Annotations = makeAnnotations(vtClone.ObjectMeta.Annotations)
}

vtClone.ObjectMeta.Annotations[configAnnotation] = string(b)
Expand Down
4 changes: 2 additions & 2 deletions pkg/router/kubernetes_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ func (c *KubernetesDefaultRouter) reconcileService(canary *flaggerv1.Canary, nam
if svc.ObjectMeta.Annotations == nil {
svc.ObjectMeta.Annotations = make(map[string]string)
}
if diff := cmp.Diff(metadata.Annotations, svc.ObjectMeta.Annotations); diff != "" {
svcClone.ObjectMeta.Annotations = metadata.Annotations
if diff := cmp.Diff(makeAnnotations(metadata.Annotations), svc.ObjectMeta.Annotations); diff != "" {
svcClone.ObjectMeta.Annotations = makeAnnotations(metadata.Annotations)
updateService = true
}
if diff := cmp.Diff(metadata.Labels, svc.ObjectMeta.Labels); diff != "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/router/skipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (skp *SkipperRouter) Reconcile(canary *flaggerv1.Canary) error {
if cmp.Diff(iClone.Spec, canaryIngress.Spec) != "" {
ingressClone := canaryIngress.DeepCopy()
ingressClone.Spec = iClone.Spec
ingressClone.Annotations = iClone.Annotations
ingressClone.Annotations = makeAnnotations(iClone.Annotations)

_, err := skp.kubeClient.NetworkingV1().Ingresses(canary.Namespace).Update(context.TODO(), ingressClone, metav1.UpdateOptions{})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/router/traefik.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (tr *TraefikRouter) Reconcile(canary *flaggerv1.Canary) error {
Name: apexName,
Namespace: canary.Namespace,
Labels: tsMetadata.Labels,
Annotations: tsMetadata.Annotations,
Annotations: makeAnnotations(tsMetadata.Annotations),
OwnerReferences: []metav1.OwnerReference{
*metav1.NewControllerRef(canary, schema.GroupVersionKind{
Group: flaggerv1.SchemeGroupVersion.Group,
Expand Down
12 changes: 12 additions & 0 deletions pkg/router/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,15 @@ func includeLabelsByPrefix(labels map[string]string, includeLabelPrefixes []stri

return filteredLabels
}

func makeAnnotations(in map[string]string) map[string]string {
out := make(map[string]string)
for key, value := range in {
// skip Flux GC markers
if strings.Contains(key, "/checksum") {
continue
}
out[key] = value
}
return out
}

0 comments on commit b2436eb

Please sign in to comment.