Skip to content

Commit

Permalink
Merge pull request #343 from stuggi/merge_annotations
Browse files Browse the repository at this point in the history
Merge Annotations and Labels in CreateOrPatch
  • Loading branch information
stuggi authored Sep 27, 2023
2 parents 1664bbc + 18d0ea2 commit 4f614f3
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion modules/certmanager/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (c *Certificate) CreateOrPatch(

op, err := controllerutil.CreateOrPatch(ctx, h.GetClient(), cert, func() error {
cert.Labels = util.MergeStringMaps(cert.Labels, c.certificate.Labels)
cert.Annotations = c.certificate.Annotations
cert.Annotations = util.MergeStringMaps(cert.Annotations, c.certificate.Annotations)
cert.Spec = c.certificate.Spec

err := controllerutil.SetControllerReference(h.GetBeforeObject(), cert, h.GetScheme())
Expand Down
2 changes: 1 addition & 1 deletion modules/certmanager/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (i *Issuer) CreateOrPatch(

op, err := controllerutil.CreateOrPatch(ctx, h.GetClient(), issuer, func() error {
issuer.Labels = util.MergeStringMaps(issuer.Labels, i.issuer.Labels)
issuer.Annotations = i.issuer.Annotations
issuer.Annotations = util.MergeStringMaps(issuer.Annotations, i.issuer.Annotations)
issuer.Spec = i.issuer.Spec

err := controllerutil.SetControllerReference(h.GetBeforeObject(), issuer, h.GetScheme())
Expand Down
2 changes: 1 addition & 1 deletion modules/common/configmap/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func createOrPatchConfigMap(
// create or update the CM
op, err := controllerutil.CreateOrPatch(ctx, h.GetClient(), configMap, func() error {

configMap.Labels = cm.Labels
configMap.Labels = util.MergeStringMaps(configMap.Labels, cm.Labels)
// add data from templates
renderedTemplateData, err := util.GetTemplateData(cm)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions modules/common/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ func (r *Route) CreateOrPatch(
}

op, err := controllerutil.CreateOrPatch(ctx, h.GetClient(), route, func() error {
route.Labels = r.route.Labels
route.Annotations = r.route.Annotations
route.Labels = util.MergeStringMaps(route.Labels, r.route.Labels)
route.Annotations = util.MergeStringMaps(route.Annotations, r.route.Annotations)
route.Spec = r.route.Spec
if len(route.Spec.Host) == 0 && len(route.Status.Ingress) > 0 {
route.Spec.Host = route.Status.Ingress[0].Host
Expand Down
2 changes: 1 addition & 1 deletion modules/common/secret/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func createOrUpdateSecret(

// create or update the CM
op, err := controllerutil.CreateOrPatch(ctx, h.GetClient(), secret, func() error {
secret.Labels = st.Labels
secret.Labels = util.MergeStringMaps(secret.Labels, st.Labels)
// add data from templates
renderedTemplateData, err := util.GetTemplateData(st)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions modules/common/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ func (s *Service) CreateOrPatch(
}

op, err := controllerutil.CreateOrPatch(ctx, h.GetClient(), service, func() error {
service.Labels = s.service.Labels
service.Annotations = s.service.Annotations
service.Labels = util.MergeStringMaps(service.Labels, s.service.Labels)
service.Annotations = util.MergeStringMaps(service.Annotations, s.service.Annotations)
service.Spec = s.service.Spec

err := controllerutil.SetControllerReference(h.GetBeforeObject(), service, h.GetScheme())
Expand Down

0 comments on commit 4f614f3

Please sign in to comment.