From fdb887376fb31eef07e0ef2fd733b8c9689081a9 Mon Sep 17 00:00:00 2001 From: Paulo Sousa Date: Mon, 22 Jan 2024 11:12:35 -0300 Subject: [PATCH] controller: fix flavor apply proper order --- controllers/controller.go | 2 +- controllers/controller_test.go | 59 ++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/controllers/controller.go b/controllers/controller.go index cc9f50cf8..3e740da8b 100644 --- a/controllers/controller.go +++ b/controllers/controller.go @@ -212,7 +212,7 @@ func mergeInstanceWithFlavor(instance *v1alpha1.RpaasInstance, flavor v1alpha1.R return nil } - mergedInstanceSpec, err := mergeInstance(*flavor.Spec.InstanceTemplate, instance.Spec) + mergedInstanceSpec, err := mergeInstance(instance.Spec, *flavor.Spec.InstanceTemplate) if err != nil { return err } diff --git a/controllers/controller_test.go b/controllers/controller_test.go index dc53d5607..01ec49c05 100644 --- a/controllers/controller_test.go +++ b/controllers/controller_test.go @@ -590,6 +590,65 @@ func TestReconcileRpaasInstance_getRpaasInstance(t *testing.T) { return i }, }, + + "when there are multiple flavors and last on overrides ingress annotations": { + resources: []runtime.Object{ + &v1alpha1.RpaasFlavor{ + ObjectMeta: metav1.ObjectMeta{ + Name: "flavor-a", + Namespace: "default", + }, + Spec: v1alpha1.RpaasFlavorSpec{ + InstanceTemplate: &v1alpha1.RpaasInstanceSpec{ + Service: &nginxv1alpha1.NginxService{ + Annotations: map[string]string{ + "rpaas.extensions.tsuru.io/custom-annotation-svc": "custom svc annotation", + }, + }, + Ingress: &nginxv1alpha1.NginxIngress{ + Annotations: map[string]string{ + "rpaas.extensions.tsuru.io/custom-annotation-ingress": "foo", + }, + }, + }, + }, + }, + &v1alpha1.RpaasFlavor{ + ObjectMeta: metav1.ObjectMeta{ + Name: "flavor-b", + Namespace: "default", + }, + Spec: v1alpha1.RpaasFlavorSpec{ + InstanceTemplate: &v1alpha1.RpaasInstanceSpec{ + Ingress: &nginxv1alpha1.NginxIngress{ + Annotations: map[string]string{ + "rpaas.extensions.tsuru.io/custom-annotation-ingress": "bar", + "another.example.com/blah": "bleh", + }, + }, + }, + }, + }, + }, + instance: func(i *v1alpha1.RpaasInstance) *v1alpha1.RpaasInstance { + i.Spec.Flavors = []string{"flavor-a", "flavor-b"} + return i + }, + expected: func(i *v1alpha1.RpaasInstance) *v1alpha1.RpaasInstance { + i.Spec.Service = &nginxv1alpha1.NginxService{ + Annotations: map[string]string{ + "rpaas.extensions.tsuru.io/custom-annotation-svc": "custom svc annotation", + }, + } + i.Spec.Ingress = &nginxv1alpha1.NginxIngress{ + Annotations: map[string]string{ + "rpaas.extensions.tsuru.io/custom-annotation-ingress": "bar", + "another.example.com/blah": "bleh", + }, + } + return i + }, + }, } for name, tt := range tests {