From 01e49ccaa4eafe1bb019803cc485decaca3badbc Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Tue, 17 Nov 2020 11:16:03 +0000 Subject: [PATCH] Fix #39 to sync annotations Previously only the spec was synced, which is normal behaviour for a Kubernetes controller. This commit fixes: #39 where people want to set annotations and have them go into the Ingress resource. Going forward, this might be better done through the spec. Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- artifacts/operator-amd64.yaml | 2 +- pkg/controller/controller.go | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/artifacts/operator-amd64.yaml b/artifacts/operator-amd64.yaml index 80f679d3..90a8e28b 100644 --- a/artifacts/operator-amd64.yaml +++ b/artifacts/operator-amd64.yaml @@ -19,7 +19,7 @@ spec: serviceAccountName: ingress-operator containers: - name: operator - image: openfaas/ingress-operator:0.6.3 + image: openfaas/ingress-operator:0.6.5 imagePullPolicy: Always command: - ./ingress-operator diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 645397bc..bd12cdfa 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -127,6 +127,7 @@ func NewController( functionIngress.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: controller.enqueueFunction, UpdateFunc: func(old, new interface{}) { + oldFn, ok := checkCustomResourceType(old) if !ok { return @@ -135,7 +136,10 @@ func NewController( if !ok { return } - if diff := cmp.Diff(oldFn.Spec, newFn.Spec); diff != "" { + diffSpec := cmp.Diff(oldFn.Spec, newFn.Spec) + diffAnnotations := cmp.Diff(oldFn.ObjectMeta.Annotations, newFn.ObjectMeta.Annotations) + + if diffSpec != "" || diffAnnotations != "" { controller.enqueueFunction(new) } }, @@ -307,7 +311,7 @@ func (c *Controller) syncHandler(key string) error { // Update the Deployment resource if the fni definition differs if ingressNeedsUpdate(&old, fni) { - klog.Infof("Need to update FunctionIngress: %v", fniName) + klog.Infof("Updating FunctionIngress: %s", fniName) if old.ObjectMeta.Name != fni.ObjectMeta.Name { return fmt.Errorf("cannot rename object") @@ -344,8 +348,8 @@ func (c *Controller) syncHandler(key string) error { } func ingressNeedsUpdate(old, fni *faasv1.FunctionIngress) bool { - - return !cmp.Equal(old.Spec, fni.Spec) + return !cmp.Equal(old.Spec, fni.Spec) || + !cmp.Equal(old.ObjectMeta.Annotations, fni.ObjectMeta.Annotations) } func (c *Controller) updateFunctionStatus(fni *faasv1.FunctionIngress, deployment *appsv1beta2.Deployment) error { @@ -469,7 +473,6 @@ func makeTLS(fni *faasv1.FunctionIngress) []v1beta1.IngressTLS { return []v1beta1.IngressTLS{} } - return []v1beta1.IngressTLS{ v1beta1.IngressTLS{ SecretName: fni.Spec.Domain + "-cert",