Skip to content

Commit

Permalink
controller: change default flavor apply order
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheu committed Jan 22, 2024
1 parent fdb8873 commit 25278c0
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 6 deletions.
12 changes: 6 additions & 6 deletions controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ func (r *RpaasInstanceReconciler) mergeInstanceWithFlavors(ctx context.Context,
return nil, err
}

for _, defaultFlavor := range defaultFlavors {
if err := mergeInstanceWithFlavor(instance, defaultFlavor); err != nil {
return nil, err
}
}

for _, flavorName := range instance.Spec.Flavors {
flavorObjectKey := types.NamespacedName{
Name: flavorName,
Expand All @@ -198,12 +204,6 @@ func (r *RpaasInstanceReconciler) mergeInstanceWithFlavors(ctx context.Context,
}
}

for _, defaultFlavor := range defaultFlavors {
if err := mergeInstanceWithFlavor(instance, defaultFlavor); err != nil {
return nil, err
}
}

return instance, nil
}

Expand Down
98 changes: 98 additions & 0 deletions controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,104 @@ func TestReconcileRpaasInstance_getRpaasInstance(t *testing.T) {
return i
},
},

"when there are multiple flavors and one of them is default": {
resources: []runtime.Object{
&v1alpha1.RpaasFlavor{
ObjectMeta: metav1.ObjectMeta{
Name: "default",
Namespace: "default",
},
Spec: v1alpha1.RpaasFlavorSpec{
Default: true,
InstanceTemplate: &v1alpha1.RpaasInstanceSpec{
Service: &nginxv1alpha1.NginxService{
Annotations: map[string]string{
"rpaas.extensions.tsuru.io/custom-annotation-svc": "custom svc annotation",
},
},

PodTemplate: nginxv1alpha1.NginxPodTemplateSpec{
ServiceAccountName: "my-service-account",
Annotations: map[string]string{
"prometheus.io/path": "/status",
},
},
},
},
},
&v1alpha1.RpaasFlavor{
ObjectMeta: metav1.ObjectMeta{
Name: "flavor-a",
Namespace: "default",
},
Spec: v1alpha1.RpaasFlavorSpec{
InstanceTemplate: &v1alpha1.RpaasInstanceSpec{
PodTemplate: nginxv1alpha1.NginxPodTemplateSpec{
Annotations: map[string]string{
"logging.tsuru.io/sample": "0.5",
},
},
},
},
},
&v1alpha1.RpaasFlavor{
ObjectMeta: metav1.ObjectMeta{
Name: "flavor-b",
Namespace: "default",
},
Spec: v1alpha1.RpaasFlavorSpec{
InstanceTemplate: &v1alpha1.RpaasInstanceSpec{
PodTemplate: nginxv1alpha1.NginxPodTemplateSpec{
ServiceAccountName: "flavor-b-service-account",
},
Ingress: &nginxv1alpha1.NginxIngress{
Annotations: map[string]string{
"ingress.tsuru.io": "flavor-b",
},
},
},
},
},
&v1alpha1.RpaasFlavor{
ObjectMeta: metav1.ObjectMeta{
Name: "flavor-c",
Namespace: "default",
},
Spec: v1alpha1.RpaasFlavorSpec{
InstanceTemplate: &v1alpha1.RpaasInstanceSpec{
PodTemplate: nginxv1alpha1.NginxPodTemplateSpec{
ServiceAccountName: "flavor-c-service-account",
},
},
},
},
},
instance: func(i *v1alpha1.RpaasInstance) *v1alpha1.RpaasInstance {
i.Spec.Flavors = []string{"flavor-a", "flavor-b", "flavor-c"}
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.PodTemplate = nginxv1alpha1.NginxPodTemplateSpec{
ServiceAccountName: "flavor-c-service-account",
Annotations: map[string]string{
"prometheus.io/path": "/status",
"logging.tsuru.io/sample": "0.5",
},
}
i.Spec.Ingress = &nginxv1alpha1.NginxIngress{
Annotations: map[string]string{
"ingress.tsuru.io": "flavor-b",
},
}
return i
},
},
}

for name, tt := range tests {
Expand Down

0 comments on commit 25278c0

Please sign in to comment.