Skip to content

Commit 690231b

Browse files
GouthamMLYashwantGohokar
authored andcommitted
Update e2e for system tags
1 parent ff829c2 commit 690231b

File tree

6 files changed

+79
-12
lines changed

6 files changed

+79
-12
lines changed

hack/run_e2e_test.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ function run_e2e_tests_existing_cluster() {
6161
--volume-handle=${FSS_VOLUME_HANDLE} \
6262
--static-snapshot-compartment-id=${STATIC_SNAPSHOT_COMPARTMENT_ID} \
6363
--enable-parallel-run=${ENABLE_PARALLEL_RUN} \
64-
--run-uhp-e2e=${RUN_UHP_E2E}
64+
--run-uhp-e2e=${RUN_UHP_E2E} \
65+
--add-oke-system-tags="false"
6566
retval=$?
6667
return $retval
6768
}

test/e2e/cloud-provider-oci/csi_volume_creation.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,28 @@ import (
2828

2929
var _ = Describe("CSI Volume Creation", func() {
3030
f := framework.NewDefaultFramework("csi-basic")
31-
Context("[cloudprovider][storage][csi]", func() {
31+
Context("[cloudprovider][storage][csi][system-tags]", func() {
3232
It("Create PVC and POD for CSI.", func() {
3333
pvcJig := framework.NewPVCTestJig(f.ClientSet, "csi-provisioner-e2e-tests")
34-
34+
ctx := context.TODO()
3535
scName := f.CreateStorageClassOrFail(f.Namespace.Name, "blockvolume.csi.oraclecloud.com", nil, pvcJig.Labels, "WaitForFirstConsumer", false, "Delete", nil)
3636
pvc := pvcJig.CreateAndAwaitPVCOrFailCSI(f.Namespace.Name, framework.MinVolumeBlock, scName, nil, v1.PersistentVolumeFilesystem, v1.ReadWriteOnce, v1.ClaimPending)
3737
f.VolumeIds = append(f.VolumeIds, pvc.Spec.VolumeName)
3838
pvcJig.NewPodForCSI("app1", f.Namespace.Name, pvc.Name, setupF.AdLabel)
39+
volumeName := pvcJig.GetVolumeNameFromPVC(pvc.GetName(), f.Namespace.Name)
40+
compartmentId := f.GetCompartmentId(*setupF)
41+
// read created BV
42+
volumes, err := f.Client.BlockStorage().GetVolumesByName(ctx, volumeName, compartmentId)
43+
framework.ExpectNoError(err)
44+
// volume name duplicate should not exist
45+
for _, volume := range volumes {
46+
framework.Logf("volume details %v :", volume)
47+
framework.Logf("cluster ocid from setup is %s", setupF.ClusterOcid)
48+
if setupF.AddOkeSystemTags && !framework.HasOkeSystemTags(volume.SystemTags) {
49+
framework.Failf("the resource %s is expected to have oke system tags", *volume.Id)
50+
}
51+
}
52+
3953
})
4054

4155
It("Create PVC with VolumeSize 1Gi but should use default 50Gi", func() {

test/e2e/cloud-provider-oci/load_balancer.go

+32-6
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ var _ = Describe("Service [Slow]", func() {
5959
},
6060
},
6161
}
62-
Context("[cloudprovider][ccm][lb][SL]", func() {
62+
Context("[cloudprovider][ccm][lb][SL][system-tags]", func() {
6363
It("should be possible to create and mutate a Service type:LoadBalancer (change nodeport) [Canary]", func() {
6464
for _, test := range basicTestArray {
6565
By("Running test for: " + test.lbType)
@@ -99,6 +99,32 @@ var _ = Describe("Service [Slow]", func() {
9999
tcpService = jig.WaitForLoadBalancerOrFail(ns, tcpService.Name, loadBalancerCreateTimeout)
100100
jig.SanityCheckService(tcpService, v1.ServiceTypeLoadBalancer)
101101

102+
By("validating system tags on the loadbalancer")
103+
lbName := cloudprovider.GetLoadBalancerName(tcpService)
104+
sharedfw.Logf("LB Name is %s", lbName)
105+
ctx := context.TODO()
106+
compartmentId := ""
107+
if setupF.Compartment1 != "" {
108+
compartmentId = setupF.Compartment1
109+
} else if f.CloudProviderConfig.CompartmentID != "" {
110+
compartmentId = f.CloudProviderConfig.CompartmentID
111+
} else if f.CloudProviderConfig.Auth.CompartmentID != "" {
112+
compartmentId = f.CloudProviderConfig.Auth.CompartmentID
113+
} else {
114+
sharedfw.Failf("Compartment Id undefined.")
115+
}
116+
lbType := test.lbType
117+
if strings.HasSuffix(test.lbType, "-wris") {
118+
lbType = strings.TrimSuffix(test.lbType, "-wris")
119+
}
120+
loadBalancer, err := f.Client.LoadBalancer(zap.L().Sugar(), lbType, "", nil).GetLoadBalancerByName(ctx, compartmentId, lbName)
121+
sharedfw.ExpectNoError(err)
122+
sharedfw.Logf("Loadbalancer details %v:", loadBalancer)
123+
sharedfw.Logf("cluster ocid from setup is %s", setupF.ClusterOcid)
124+
if setupF.AddOkeSystemTags && !sharedfw.HasOkeSystemTags(loadBalancer.SystemTags) {
125+
sharedfw.Failf("Loadbalancer is expected to have the system tags")
126+
}
127+
102128
tcpNodePort := int(tcpService.Spec.Ports[0].NodePort)
103129
sharedfw.Logf("TCP node port: %d", tcpNodePort)
104130

@@ -1347,8 +1373,8 @@ var _ = Describe("LB Properties", func() {
13471373
{
13481374
"lb",
13491375
map[string]string{
1350-
cloudprovider.ServiceAnnotationLoadBalancerInternal: "true",
1351-
cloudprovider.ServiceAnnotationLoadBalancerShape: "flexible",
1376+
cloudprovider.ServiceAnnotationLoadBalancerInternal: "true",
1377+
cloudprovider.ServiceAnnotationLoadBalancerShape: "flexible",
13521378
cloudprovider.ServiceAnnotationLoadBalancerShapeFlexMin: "10",
13531379
cloudprovider.ServiceAnnotationLoadBalancerShapeFlexMax: "10",
13541380
},
@@ -1478,10 +1504,10 @@ var _ = Describe("LB Properties", func() {
14781504
{
14791505
"lb",
14801506
map[string]string{
1481-
cloudprovider.ServiceAnnotationLoadBalancerShape: "flexible",
1507+
cloudprovider.ServiceAnnotationLoadBalancerShape: "flexible",
14821508
cloudprovider.ServiceAnnotationLoadBalancerShapeFlexMin: "10",
14831509
cloudprovider.ServiceAnnotationLoadBalancerShapeFlexMax: "10",
1484-
cloudprovider.ServiceAnnotationLoadBalancerPolicy: cloudprovider.IPHashLoadBalancerPolicy,
1510+
cloudprovider.ServiceAnnotationLoadBalancerPolicy: cloudprovider.IPHashLoadBalancerPolicy,
14851511
},
14861512
map[string]string{
14871513
cloudprovider.ServiceAnnotationLoadBalancerPolicy: cloudprovider.LeastConnectionsLoadBalancerPolicy,
@@ -1590,7 +1616,7 @@ var _ = Describe("LB Properties", func() {
15901616
{
15911617
"lb",
15921618
map[string]string{
1593-
cloudprovider.ServiceAnnotationLoadBalancerShape: "flexible",
1619+
cloudprovider.ServiceAnnotationLoadBalancerShape: "flexible",
15941620
cloudprovider.ServiceAnnotationLoadBalancerShapeFlexMin: "10",
15951621
cloudprovider.ServiceAnnotationLoadBalancerShapeFlexMax: "10",
15961622
},

test/e2e/cloud-provider-oci/setup.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
1818
sharedfw.Logf("CloudProviderFramework Setup")
1919
sharedfw.Logf("Running tests with existing cluster.")
2020
return nil
21-
}, func(data []byte) {
22-
setupF = sharedfw.New()
23-
},
21+
}, func(data []byte) {
22+
setupF = sharedfw.New()
23+
},
2424
)
2525

2626
var _ = ginkgo.SynchronizedAfterSuite(func() {}, func() {

test/e2e/framework/framework.go

+4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ var (
103103
staticSnapshotCompartmentOCID string // Compartment ID for cross compartment snapshot test
104104
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)
105105
enableParallelRun bool
106+
addOkeSystemTags bool
106107
)
107108

108109
func init() {
@@ -134,6 +135,7 @@ func init() {
134135
flag.StringVar(&staticSnapshotCompartmentOCID, "static-snapshot-compartment-id", "", "Compartment ID for cross compartment snapshot test")
135136
flag.BoolVar(&runUhpE2E, "run-uhp-e2e", false, "Run UHP E2Es as well")
136137
flag.BoolVar(&enableParallelRun, "enable-parallel-run", true, "Enables parallel running of test suite")
138+
flag.BoolVar(&addOkeSystemTags, "add-oke-system-tags", false, "Adds oke system tags to new and existing loadbalancers and storage resources")
137139
}
138140

139141
// Framework is the context of the text execution.
@@ -167,6 +169,7 @@ type Framework struct {
167169
// Compartment ID for cross compartment snapshot test
168170
StaticSnapshotCompartmentOcid string
169171
RunUhpE2E bool
172+
AddOkeSystemTags bool
170173
}
171174

172175
// New creates a new a framework that holds the context of the test
@@ -191,6 +194,7 @@ func NewWithConfig() *Framework {
191194
VolumeHandle: volumeHandle,
192195
StaticSnapshotCompartmentOcid: staticSnapshotCompartmentOCID,
193196
RunUhpE2E: runUhpE2E,
197+
AddOkeSystemTags: addOkeSystemTags,
194198
}
195199

196200
f.CloudConfigPath = cloudConfigFile
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package framework
2+
3+
import (
4+
cloudprovider "github.com/oracle/oci-cloud-controller-manager/pkg/cloudprovider/providers/oci"
5+
)
6+
7+
const (
8+
okeSystemTagKey = "Cluster"
9+
)
10+
11+
func HasOkeSystemTags(systemTags map[string]map[string]interface{}) bool {
12+
Logf("actual system tags on the resource: %v", systemTags)
13+
if systemTags != nil {
14+
if okeSystemTag, okeSystemTagNsExists := systemTags[cloudprovider.OkeSystemTagNamesapce]; okeSystemTagNsExists {
15+
if _, okeSystemTagKeyExists := okeSystemTag[okeSystemTagKey]; okeSystemTagKeyExists {
16+
return true
17+
}
18+
}
19+
return false
20+
}
21+
return false
22+
}

0 commit comments

Comments
 (0)