@@ -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