Skip to content

Commit

Permalink
feat(controller): support to render custom values on ingress annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
nettoclaudio committed Sep 10, 2021
1 parent 7450c95 commit e0978dc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
30 changes: 30 additions & 0 deletions controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,10 @@ func renderCustomValues(instance *v1alpha1.RpaasInstance) error {
return err
}

if err := renderIngressCustomAnnotations(instance); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -1338,6 +1342,32 @@ func renderServiceCustomAnnotations(instance *v1alpha1.RpaasInstance) error {
return nil
}

func renderIngressCustomAnnotations(instance *v1alpha1.RpaasInstance) error {
if instance == nil {
return nil
}

if instance.Spec.Ingress == nil {
return nil
}

for k, v := range instance.Spec.Ingress.Annotations {
tmpl, err := template.New("rpaasv2.ingress.annotations").Parse(v)
if err != nil {
return err
}

var buffer bytes.Buffer
if err = tmpl.Execute(&buffer, instance); err != nil {
return err
}

instance.Spec.Ingress.Annotations[k] = buffer.String()
}

return nil
}

func mergeInstance(base v1alpha1.RpaasInstanceSpec, override v1alpha1.RpaasInstanceSpec) (merged v1alpha1.RpaasInstanceSpec, err error) {
err = genericMerge(&merged, base, override)
return
Expand Down
10 changes: 10 additions & 0 deletions controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ func TestReconcileRpaasInstance_getRpaasInstance(t *testing.T) {
"some-instance-annotation-key": "my custom value: {{ .Labels.rpaas_service }}/{{ .Labels.rpaas_instance }}/{{ .Name }}",
},
}
instance4.Spec.Ingress = &nginxv1alpha1.NginxIngress{
Annotations: map[string]string{
"some-instance-annotation-key": "my custom value: {{ .Labels.rpaas_service }}/{{ .Name }}",
},
}

instance5 := newEmptyRpaasInstance()
instance5.Name = "instance5"
Expand Down Expand Up @@ -608,6 +613,11 @@ func TestReconcileRpaasInstance_getRpaasInstance(t *testing.T) {
Zone: "test-zone",
TTL: func() *int32 { ttl := int32(30); return &ttl }(),
},
Ingress: &nginxv1alpha1.NginxIngress{
Annotations: map[string]string{
"some-instance-annotation-key": "my custom value: my-service-name/instance4",
},
},
},
},
},
Expand Down

0 comments on commit e0978dc

Please sign in to comment.