Skip to content

Commit

Permalink
Merge annotations instead of overwriting them
Browse files Browse the repository at this point in the history
  • Loading branch information
ynnt committed Nov 1, 2021
1 parent 26a90e9 commit 3373a86
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package mysqlcluster

import (
"github.com/imdario/mergo"
"github.com/presslabs/controller-util/syncer"
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -41,9 +42,9 @@ func NewHealthyReplicasSVCSyncer(c client.Client, scheme *runtime.Scheme, cluste
service.Spec.Type = core.ServiceTypeLoadBalancer
}

// set annotations
if len(cluster.Spec.ReplicaServiceSpec.Annotations) > 0 {
service.ObjectMeta.Annotations = cluster.Spec.ReplicaServiceSpec.Annotations
// merge annotations
if err := mergo.Merge(&service.ObjectMeta.Annotations, cluster.Spec.ReplicaServiceSpec); err != nil {
return err
}

// set service labels
Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/mysqlcluster/internal/syncer/master_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package mysqlcluster

import (
"github.com/imdario/mergo"
"github.com/presslabs/controller-util/syncer"
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -41,9 +42,9 @@ func NewMasterSVCSyncer(c client.Client, scheme *runtime.Scheme, cluster *mysqlc
service.Spec.Type = core.ServiceTypeLoadBalancer
}

// set annotations
if len(cluster.Spec.MasterServiceSpec.Annotations) > 0 {
service.ObjectMeta.Annotations = cluster.Spec.MasterServiceSpec.Annotations
// merge annotations
if err := mergo.Merge(&service.ObjectMeta.Annotations, cluster.Spec.MasterServiceSpec.Annotations); err != nil {
return err
}

// set service labels
Expand Down

0 comments on commit 3373a86

Please sign in to comment.