Skip to content

Commit

Permalink
Make sure DC services, DC itself, and all pods get CommonAnnotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Miles-Garnsey committed Dec 18, 2023
1 parent e166636 commit cf0755f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pkg/cassandra/datacenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/Masterminds/semver/v3"
"github.com/adutra/goalesce"
"github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1"
cassdcapi "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1"
"github.com/k8ssandra/cass-operator/pkg/reconciliation"
Expand Down Expand Up @@ -157,7 +158,7 @@ func NewDatacenter(klusterKey types.NamespacedName, template *DatacenterConfig)
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: template.Meta.Name,
Annotations: map[string]string{},
Annotations: template.Meta.Annotations,
Labels: utils.MergeMap(map[string]string{
api.NameLabel: api.NameLabelValue,
api.PartOfLabel: api.PartOfLabelValue,
Expand Down Expand Up @@ -223,15 +224,22 @@ func NewDatacenter(klusterKey types.NamespacedName, template *DatacenterConfig)
m := template.Meta
dc.ObjectMeta.Labels = utils.MergeMap(dc.ObjectMeta.Labels, m.Labels)
dc.ObjectMeta.Annotations = utils.MergeMap(dc.ObjectMeta.Annotations, m.Annotations)
dc.ObjectMeta.Annotations = utils.MergeMap(dc.ObjectMeta.Annotations, m.CommonAnnotations)

if m.CommonLabels != nil {
dc.Spec.AdditionalLabels = m.CommonLabels
} else {
dc.Spec.AdditionalLabels = map[string]string{}
}

if m.CommonLabels != nil {
dc.Spec.AdditionalLabels = m.CommonLabels
if m.CommonAnnotations != nil {
m.ServiceConfig.AdditionalSeedService.Annotations = goalesce.MustDeepMerge(template.Meta.CommonAnnotations, m.ServiceConfig.AdditionalSeedService.Annotations)
m.ServiceConfig.AllPodsService.Annotations = goalesce.MustDeepMerge(template.Meta.CommonAnnotations, m.ServiceConfig.AllPodsService.Annotations)
m.ServiceConfig.DatacenterService.Annotations = goalesce.MustDeepMerge(template.Meta.CommonAnnotations, m.ServiceConfig.DatacenterService.Annotations)
m.ServiceConfig.NodePortService.Annotations = goalesce.MustDeepMerge(template.Meta.CommonAnnotations, m.ServiceConfig.NodePortService.Annotations)
m.ServiceConfig.SeedService.Annotations = goalesce.MustDeepMerge(template.Meta.CommonAnnotations, m.ServiceConfig.SeedService.Annotations)
} else {
dc.Spec.AdditionalLabels = map[string]string{}
dc.Spec.PodTemplateSpec.Annotations = map[string]string{}
}

dc.Spec.AdditionalServiceConfig = m.ServiceConfig.ToCassAdditionalServiceConfig()
Expand Down Expand Up @@ -370,8 +378,10 @@ func Coalesce(clusterName string, clusterTemplate *api.CassandraClusterTemplate,

dcConfig.Meta.Tags = goalesceutils.MergeCRs(clusterTemplate.Meta.Tags, dcTemplate.Meta.Tags)
dcConfig.Meta.CommonLabels = goalesceutils.MergeCRs(clusterTemplate.Meta.CommonLabels, dcTemplate.Meta.CommonLabels)

dcConfig.Meta.CommonAnnotations = goalesceutils.MergeCRs(clusterTemplate.Meta.CommonAnnotations, dcTemplate.Meta.CommonAnnotations)
dcConfig.Meta.Pods = goalesceutils.MergeCRs(clusterTemplate.Meta.Pods, dcTemplate.Meta.Pods)
dcConfig.Meta.Pods.Annotations = goalesce.MustDeepMerge(dcConfig.Meta.CommonAnnotations, dcConfig.Meta.Pods.Annotations)
dcConfig.Meta.ServiceConfig = goalesceutils.MergeCRs(clusterTemplate.Meta.ServiceConfig, dcTemplate.Meta.ServiceConfig)

AddPodTemplateSpecMeta(dcConfig, dcConfig.Meta)
Expand Down
13 changes: 13 additions & 0 deletions pkg/cassandra/datacenter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,19 @@ func TestNewDatacenter_MgmtAPIHeapSize_Set(t *testing.T) {
assert.Equal(t, dc.Spec.PodTemplateSpec.Spec.Containers[0].Env[0].Value, "999000000")
}

func TestCassDCGetsAnnotations(t *testing.T) {
template := GetDatacenterConfig()
template.Meta = api.EmbeddedObjectMeta{
CommonAnnotations: map[string]string{
"test": "test",
},
}
cassDC, _ := NewDatacenter(
types.NamespacedName{Name: "testdc", Namespace: "test-namespace"},
&template)
assert.Equal(t, cassDC.Annotations["test"], "test")
}

func TestNewDatacenter_McacDisabled_Set(t *testing.T) {
template := GetDatacenterConfig()
template.McacEnabled = false
Expand Down

0 comments on commit cf0755f

Please sign in to comment.