Skip to content

Commit 42119ed

Browse files
committed
Fix: allow cluster tags to be updated
1 parent b976cf5 commit 42119ed

File tree

2 files changed

+142
-1
lines changed

2 files changed

+142
-1
lines changed

cloud/scope/managed_control_plane.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,12 @@ func (s *ManagedControlPlaneScope) UpdateControlPlane(ctx context.Context, okeCl
674674
setControlPlaneSpecDefaults(spec)
675675

676676
actual := s.getSpecFromActual(okeCluster)
677+
678+
// Check for tag-only changes (tags live on OCIManagedCluster, not in control plane spec)
679+
tagsChanged := s.hasClusterTagChanges(okeCluster)
680+
677681
// Log the actual and desired specs
678-
if !s.compareSpecs(spec, actual) {
682+
if tagsChanged || !s.compareSpecs(spec, actual) {
679683
controlPlaneSpec := s.OCIManagedControlPlane.Spec
680684
updateOptions := oke.UpdateClusterOptionsDetails{}
681685
if controlPlaneSpec.ClusterOption.AdmissionControllerOptions != nil {
@@ -734,6 +738,8 @@ func (s *ManagedControlPlaneScope) UpdateControlPlane(ctx context.Context, okeCl
734738
Name: common.String(s.GetClusterName()),
735739
KubernetesVersion: controlPlaneSpec.Version,
736740
Options: &updateOptions,
741+
FreeformTags: s.getFreeFormTags(),
742+
DefinedTags: s.getDefinedTags(),
737743
}
738744
if controlPlaneSpec.ImagePolicyConfig != nil {
739745
details.ImagePolicyConfig = &oke.UpdateImagePolicyConfigDetails{
@@ -890,6 +896,18 @@ func (s *ManagedControlPlaneScope) getSpecFromActual(cluster *oke.Cluster) *infr
890896
return &spec
891897
}
892898

899+
func (s *ManagedControlPlaneScope) hasClusterTagChanges(okeCluster *oke.Cluster) bool {
900+
desiredFF := s.getFreeFormTags()
901+
desiredDT := s.getDefinedTags()
902+
actualFF := okeCluster.FreeformTags
903+
actualDT := map[string]map[string]interface{}{}
904+
if okeCluster.DefinedTags != nil {
905+
actualDT = okeCluster.DefinedTags
906+
}
907+
tagsChanged := !cmp.Equal(desiredFF, actualFF, cmpopts.EquateEmpty()) || !cmp.Equal(desiredDT, actualDT, cmpopts.EquateEmpty())
908+
return tagsChanged
909+
}
910+
893911
// ReconcileAddons reconciles addons which have been specified in the spec on the OKE cluster
894912
func (s *ManagedControlPlaneScope) ReconcileAddons(ctx context.Context, okeCluster *oke.Cluster) error {
895913
addonSpec := s.OCIManagedControlPlane.Spec.Addons

cloud/scope/managed_control_plane_test.go

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"io"
23+
"maps"
2324
"strings"
2425
"testing"
2526

@@ -351,6 +352,10 @@ func TestControlPlaneUpdation(t *testing.T) {
351352
},
352353
}
353354

355+
tagsUpdated := maps.Clone(tags)
356+
tagsUpdated["test-tag1"] = "tag1"
357+
tagsUpdated["test-tag2"] = "tag2"
358+
354359
definedTagsInterface := make(map[string]map[string]interface{})
355360
for ns, mapNs := range definedTags {
356361
mapValues := make(map[string]interface{})
@@ -360,6 +365,18 @@ func TestControlPlaneUpdation(t *testing.T) {
360365
definedTagsInterface[ns] = mapValues
361366
}
362367

368+
definedTagsUpdated := maps.Clone(definedTags)
369+
definedTagsUpdated["Operations"] = map[string]string{"Environment": "Production"}
370+
371+
definedTagsUpdatedInterface := make(map[string]map[string]interface{})
372+
for ns, mapNs := range definedTagsUpdated {
373+
mapValues := make(map[string]interface{})
374+
for k, v := range mapNs {
375+
mapValues[k] = v
376+
}
377+
definedTagsUpdatedInterface[ns] = mapValues
378+
}
379+
363380
setup := func(t *testing.T, g *WithT) {
364381
var err error
365382
mockCtrl = gomock.NewController(t)
@@ -515,6 +532,110 @@ func TestControlPlaneUpdation(t *testing.T) {
515532
KmsKeyId: common.String("etcd-kms-key-id"),
516533
},
517534
},
535+
{
536+
name: "control plane no change - cluster tags change",
537+
errorExpected: false,
538+
testSpecificSetup: func(cs *ManagedControlPlaneScope, okeClient *mock_containerengine.MockClient) {
539+
cs.OCIManagedControlPlane.Spec = infrastructurev1beta2.OCIManagedControlPlaneSpec{
540+
ClusterPodNetworkOptions: []infrastructurev1beta2.ClusterPodNetworkOptions{
541+
{
542+
CniType: infrastructurev1beta2.FlannelCNI,
543+
},
544+
},
545+
ImagePolicyConfig: &infrastructurev1beta2.ImagePolicyConfig{
546+
IsPolicyEnabled: common.Bool(true),
547+
KeyDetails: []infrastructurev1beta2.KeyDetails{{
548+
KmsKeyId: common.String("kms-key-id"),
549+
}},
550+
},
551+
ClusterOption: infrastructurev1beta2.ClusterOptions{
552+
AdmissionControllerOptions: &infrastructurev1beta2.AdmissionControllerOptions{
553+
IsPodSecurityPolicyEnabled: common.Bool(true),
554+
},
555+
AddOnOptions: &infrastructurev1beta2.AddOnOptions{
556+
IsKubernetesDashboardEnabled: common.Bool(true),
557+
IsTillerEnabled: common.Bool(false),
558+
},
559+
},
560+
KmsKeyId: common.String("etcd-kms-key-id"),
561+
Version: common.String("v1.24.5"),
562+
}
563+
// Deliberately change tags in the OCIManagedCluster to trigger a tag diff.
564+
cs.OCIClusterAccessor.(OCIManagedCluster).OCIManagedCluster.Spec.FreeformTags = tagsUpdated
565+
cs.OCIClusterAccessor.(OCIManagedCluster).OCIManagedCluster.Spec.DefinedTags = definedTagsUpdated
566+
// The UpdateCluster should be called, we don't care about all details so use gomock.Any().
567+
okeClient.EXPECT().UpdateCluster(gomock.Any(), gomock.Eq(oke.UpdateClusterRequest{
568+
ClusterId: common.String("id"),
569+
UpdateClusterDetails: oke.UpdateClusterDetails{
570+
Name: common.String("test"),
571+
KubernetesVersion: common.String("v1.24.5"),
572+
Options: &oke.UpdateClusterOptionsDetails{
573+
AdmissionControllerOptions: &oke.AdmissionControllerOptions{
574+
IsPodSecurityPolicyEnabled: common.Bool(true),
575+
},
576+
},
577+
FreeformTags: tagsUpdated, // This is the only update
578+
DefinedTags: definedTagsUpdatedInterface,
579+
ImagePolicyConfig: &oke.UpdateImagePolicyConfigDetails{
580+
IsPolicyEnabled: common.Bool(true),
581+
KeyDetails: []oke.KeyDetails{{
582+
KmsKeyId: common.String("kms-key-id"),
583+
}},
584+
},
585+
},
586+
})).
587+
Return(oke.UpdateClusterResponse{
588+
OpcWorkRequestId: common.String("opc-work-request-id"),
589+
}, nil).Times(1)
590+
},
591+
okeCluster: oke.Cluster{
592+
Id: common.String("id"),
593+
Name: common.String("test"),
594+
CompartmentId: common.String("test-compartment"),
595+
VcnId: common.String("vcn-id"),
596+
KubernetesVersion: common.String("v1.24.5"),
597+
Type: oke.ClusterTypeBasicCluster,
598+
FreeformTags: tags,
599+
DefinedTags: definedTagsInterface,
600+
EndpointConfig: &oke.ClusterEndpointConfig{
601+
SubnetId: common.String("subnet-id"),
602+
NsgIds: []string{"nsg-id"},
603+
IsPublicIpEnabled: common.Bool(true),
604+
},
605+
ClusterPodNetworkOptions: []oke.ClusterPodNetworkOptionDetails{
606+
oke.FlannelOverlayClusterPodNetworkOptionDetails{},
607+
},
608+
Options: &oke.ClusterCreateOptions{
609+
ServiceLbSubnetIds: []string{"lb-subnet-id"},
610+
KubernetesNetworkConfig: &oke.KubernetesNetworkConfig{
611+
PodsCidr: common.String("1.2.3.4/5"),
612+
ServicesCidr: common.String("5.6.7.8/9"),
613+
},
614+
AddOns: &oke.AddOnOptions{
615+
IsKubernetesDashboardEnabled: common.Bool(true),
616+
IsTillerEnabled: common.Bool(false),
617+
},
618+
AdmissionControllerOptions: &oke.AdmissionControllerOptions{
619+
IsPodSecurityPolicyEnabled: common.Bool(true),
620+
},
621+
PersistentVolumeConfig: &oke.PersistentVolumeConfigDetails{
622+
FreeformTags: tags,
623+
DefinedTags: definedTagsInterface,
624+
},
625+
ServiceLbConfig: &oke.ServiceLbConfigDetails{
626+
FreeformTags: tags,
627+
DefinedTags: definedTagsInterface,
628+
},
629+
},
630+
ImagePolicyConfig: &oke.ImagePolicyConfig{
631+
IsPolicyEnabled: common.Bool(true),
632+
KeyDetails: []oke.KeyDetails{{
633+
KmsKeyId: common.String("kms-key-id"),
634+
}},
635+
},
636+
KmsKeyId: common.String("etcd-kms-key-id"),
637+
},
638+
},
518639
{
519640
name: "control plane change",
520641
errorExpected: false,
@@ -557,6 +678,8 @@ func TestControlPlaneUpdation(t *testing.T) {
557678
IsPodSecurityPolicyEnabled: common.Bool(true),
558679
},
559680
},
681+
FreeformTags: tags,
682+
DefinedTags: definedTagsInterface,
560683
ImagePolicyConfig: &oke.UpdateImagePolicyConfigDetails{
561684
IsPolicyEnabled: common.Bool(true),
562685
KeyDetails: []oke.KeyDetails{{

0 commit comments

Comments
 (0)