diff --git a/hack/run_e2e_test.sh b/hack/run_e2e_test.sh index eccc06f074..945c61ce90 100755 --- a/hack/run_e2e_test.sh +++ b/hack/run_e2e_test.sh @@ -61,7 +61,8 @@ function run_e2e_tests_existing_cluster() { --volume-handle=${FSS_VOLUME_HANDLE} \ --static-snapshot-compartment-id=${STATIC_SNAPSHOT_COMPARTMENT_ID} \ --enable-parallel-run=${ENABLE_PARALLEL_RUN} \ - --run-uhp-e2e=${RUN_UHP_E2E} + --run-uhp-e2e=${RUN_UHP_E2E} \ + --add-oke-system-tags="false" retval=$? return $retval } diff --git a/test/e2e/cloud-provider-oci/csi_volume_creation.go b/test/e2e/cloud-provider-oci/csi_volume_creation.go index 9155725b8e..82b03c2c9d 100644 --- a/test/e2e/cloud-provider-oci/csi_volume_creation.go +++ b/test/e2e/cloud-provider-oci/csi_volume_creation.go @@ -28,14 +28,28 @@ import ( var _ = Describe("CSI Volume Creation", func() { f := framework.NewDefaultFramework("csi-basic") - Context("[cloudprovider][storage][csi]", func() { + Context("[cloudprovider][storage][csi][system-tags]", func() { It("Create PVC and POD for CSI.", func() { pvcJig := framework.NewPVCTestJig(f.ClientSet, "csi-provisioner-e2e-tests") - + ctx := context.TODO() scName := f.CreateStorageClassOrFail(f.Namespace.Name, "blockvolume.csi.oraclecloud.com", nil, pvcJig.Labels, "WaitForFirstConsumer", false, "Delete", nil) pvc := pvcJig.CreateAndAwaitPVCOrFailCSI(f.Namespace.Name, framework.MinVolumeBlock, scName, nil, v1.PersistentVolumeFilesystem, v1.ReadWriteOnce, v1.ClaimPending) f.VolumeIds = append(f.VolumeIds, pvc.Spec.VolumeName) pvcJig.NewPodForCSI("app1", f.Namespace.Name, pvc.Name, setupF.AdLabel) + volumeName := pvcJig.GetVolumeNameFromPVC(pvc.GetName(), f.Namespace.Name) + compartmentId := f.GetCompartmentId(*setupF) + // read created BV + volumes, err := f.Client.BlockStorage().GetVolumesByName(ctx, volumeName, compartmentId) + framework.ExpectNoError(err) + // volume name duplicate should not exist + for _, volume := range volumes { + framework.Logf("volume details %v :", volume) + framework.Logf("cluster ocid from setup is %s", setupF.ClusterOcid) + if setupF.AddOkeSystemTags && !framework.HasOkeSystemTags(volume.SystemTags) { + framework.Failf("the resource %s is expected to have oke system tags", *volume.Id) + } + } + }) It("Create PVC with VolumeSize 1Gi but should use default 50Gi", func() { diff --git a/test/e2e/cloud-provider-oci/load_balancer.go b/test/e2e/cloud-provider-oci/load_balancer.go index 42b40d55eb..a2c0a0a4da 100644 --- a/test/e2e/cloud-provider-oci/load_balancer.go +++ b/test/e2e/cloud-provider-oci/load_balancer.go @@ -59,7 +59,7 @@ var _ = Describe("Service [Slow]", func() { }, }, } - Context("[cloudprovider][ccm][lb][SL]", func() { + Context("[cloudprovider][ccm][lb][SL][system-tags]", func() { It("should be possible to create and mutate a Service type:LoadBalancer (change nodeport) [Canary]", func() { for _, test := range basicTestArray { By("Running test for: " + test.lbType) @@ -99,6 +99,32 @@ var _ = Describe("Service [Slow]", func() { tcpService = jig.WaitForLoadBalancerOrFail(ns, tcpService.Name, loadBalancerCreateTimeout) jig.SanityCheckService(tcpService, v1.ServiceTypeLoadBalancer) + By("validating system tags on the loadbalancer") + lbName := cloudprovider.GetLoadBalancerName(tcpService) + sharedfw.Logf("LB Name is %s", lbName) + ctx := context.TODO() + compartmentId := "" + if setupF.Compartment1 != "" { + compartmentId = setupF.Compartment1 + } else if f.CloudProviderConfig.CompartmentID != "" { + compartmentId = f.CloudProviderConfig.CompartmentID + } else if f.CloudProviderConfig.Auth.CompartmentID != "" { + compartmentId = f.CloudProviderConfig.Auth.CompartmentID + } else { + sharedfw.Failf("Compartment Id undefined.") + } + lbType := test.lbType + if strings.HasSuffix(test.lbType, "-wris") { + lbType = strings.TrimSuffix(test.lbType, "-wris") + } + loadBalancer, err := f.Client.LoadBalancer(zap.L().Sugar(), lbType, "", nil).GetLoadBalancerByName(ctx, compartmentId, lbName) + sharedfw.ExpectNoError(err) + sharedfw.Logf("Loadbalancer details %v:", loadBalancer) + sharedfw.Logf("cluster ocid from setup is %s", setupF.ClusterOcid) + if setupF.AddOkeSystemTags && !sharedfw.HasOkeSystemTags(loadBalancer.SystemTags) { + sharedfw.Failf("Loadbalancer is expected to have the system tags") + } + tcpNodePort := int(tcpService.Spec.Ports[0].NodePort) sharedfw.Logf("TCP node port: %d", tcpNodePort) @@ -1347,8 +1373,8 @@ var _ = Describe("LB Properties", func() { { "lb", map[string]string{ - cloudprovider.ServiceAnnotationLoadBalancerInternal: "true", - cloudprovider.ServiceAnnotationLoadBalancerShape: "flexible", + cloudprovider.ServiceAnnotationLoadBalancerInternal: "true", + cloudprovider.ServiceAnnotationLoadBalancerShape: "flexible", cloudprovider.ServiceAnnotationLoadBalancerShapeFlexMin: "10", cloudprovider.ServiceAnnotationLoadBalancerShapeFlexMax: "10", }, @@ -1478,10 +1504,10 @@ var _ = Describe("LB Properties", func() { { "lb", map[string]string{ - cloudprovider.ServiceAnnotationLoadBalancerShape: "flexible", + cloudprovider.ServiceAnnotationLoadBalancerShape: "flexible", cloudprovider.ServiceAnnotationLoadBalancerShapeFlexMin: "10", cloudprovider.ServiceAnnotationLoadBalancerShapeFlexMax: "10", - cloudprovider.ServiceAnnotationLoadBalancerPolicy: cloudprovider.IPHashLoadBalancerPolicy, + cloudprovider.ServiceAnnotationLoadBalancerPolicy: cloudprovider.IPHashLoadBalancerPolicy, }, map[string]string{ cloudprovider.ServiceAnnotationLoadBalancerPolicy: cloudprovider.LeastConnectionsLoadBalancerPolicy, @@ -1590,7 +1616,7 @@ var _ = Describe("LB Properties", func() { { "lb", map[string]string{ - cloudprovider.ServiceAnnotationLoadBalancerShape: "flexible", + cloudprovider.ServiceAnnotationLoadBalancerShape: "flexible", cloudprovider.ServiceAnnotationLoadBalancerShapeFlexMin: "10", cloudprovider.ServiceAnnotationLoadBalancerShapeFlexMax: "10", }, diff --git a/test/e2e/cloud-provider-oci/setup.go b/test/e2e/cloud-provider-oci/setup.go index a12060e353..07f7d616e4 100644 --- a/test/e2e/cloud-provider-oci/setup.go +++ b/test/e2e/cloud-provider-oci/setup.go @@ -18,9 +18,9 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte { sharedfw.Logf("CloudProviderFramework Setup") sharedfw.Logf("Running tests with existing cluster.") return nil - }, func(data []byte) { - setupF = sharedfw.New() - }, +}, func(data []byte) { + setupF = sharedfw.New() +}, ) var _ = ginkgo.SynchronizedAfterSuite(func() {}, func() { diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 9848855171..7cc652c651 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -103,6 +103,7 @@ var ( staticSnapshotCompartmentOCID string // Compartment ID for cross compartment snapshot test runUhpE2E bool // Whether to run UHP E2Es, requires Volume Management Plugin enabled on the node and 16+ cores (check blockvolumeperformance public doc for the exact requirements) enableParallelRun bool + addOkeSystemTags bool ) func init() { @@ -134,6 +135,7 @@ func init() { flag.StringVar(&staticSnapshotCompartmentOCID, "static-snapshot-compartment-id", "", "Compartment ID for cross compartment snapshot test") flag.BoolVar(&runUhpE2E, "run-uhp-e2e", false, "Run UHP E2Es as well") flag.BoolVar(&enableParallelRun, "enable-parallel-run", true, "Enables parallel running of test suite") + flag.BoolVar(&addOkeSystemTags, "add-oke-system-tags", false, "Adds oke system tags to new and existing loadbalancers and storage resources") } // Framework is the context of the text execution. @@ -167,6 +169,7 @@ type Framework struct { // Compartment ID for cross compartment snapshot test StaticSnapshotCompartmentOcid string RunUhpE2E bool + AddOkeSystemTags bool } // New creates a new a framework that holds the context of the test @@ -191,6 +194,7 @@ func NewWithConfig() *Framework { VolumeHandle: volumeHandle, StaticSnapshotCompartmentOcid: staticSnapshotCompartmentOCID, RunUhpE2E: runUhpE2E, + AddOkeSystemTags: addOkeSystemTags, } f.CloudConfigPath = cloudConfigFile diff --git a/test/e2e/framework/system_tags_util.go b/test/e2e/framework/system_tags_util.go new file mode 100644 index 0000000000..a71f794750 --- /dev/null +++ b/test/e2e/framework/system_tags_util.go @@ -0,0 +1,22 @@ +package framework + +import ( + cloudprovider "github.com/oracle/oci-cloud-controller-manager/pkg/cloudprovider/providers/oci" +) + +const ( + okeSystemTagKey = "Cluster" +) + +func HasOkeSystemTags(systemTags map[string]map[string]interface{}) bool { + Logf("actual system tags on the resource: %v", systemTags) + if systemTags != nil { + if okeSystemTag, okeSystemTagNsExists := systemTags[cloudprovider.OkeSystemTagNamesapce]; okeSystemTagNsExists { + if _, okeSystemTagKeyExists := okeSystemTag[okeSystemTagKey]; okeSystemTagKeyExists { + return true + } + } + return false + } + return false +}