Skip to content

Commit

Permalink
Fix #39 to sync annotations
Browse files Browse the repository at this point in the history
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) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Nov 17, 2020
1 parent fcd101c commit 01e49cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion artifacts/operator-amd64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
},
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -469,7 +473,6 @@ func makeTLS(fni *faasv1.FunctionIngress) []v1beta1.IngressTLS {
return []v1beta1.IngressTLS{}
}


return []v1beta1.IngressTLS{
v1beta1.IngressTLS{
SecretName: fni.Spec.Domain + "-cert",
Expand Down

1 comment on commit 01e49cc

@goncalo-oliveira
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! 👍🏻

Please sign in to comment.