Skip to content

Commit 55654cc

Browse files
GouthamMLYashwantGohokar
authored andcommitted
Update e2e for system tags
1 parent 07fecdb commit 55654cc

File tree

8 files changed

+90
-24
lines changed

8 files changed

+90
-24
lines changed

hack/run_e2e_test.sh

Lines changed: 2 additions & 1 deletion
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
}

pkg/cloudprovider/providers/oci/load_balancer_security_lists.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,13 +683,13 @@ func healthCheckPortInUse(serviceLister listersv1.ServiceLister, port int32) (bo
683683
if service.DeletionTimestamp != nil || service.Spec.Type != api.ServiceTypeLoadBalancer {
684684
continue
685685
}
686-
if service.Spec.ExternalTrafficPolicy == api.ServiceExternalTrafficPolicyCluster {
686+
if service.Spec.ExternalTrafficPolicy == api.ServiceExternalTrafficPolicyTypeCluster {
687687
// This service is using the default healthcheck port, so we must check if
688688
// any other service is also using this default healthcheck port.
689689
if port == lbNodesHealthCheckPort {
690690
return true, nil
691691
}
692-
} else if service.Spec.ExternalTrafficPolicy == api.ServiceExternalTrafficPolicyLocal {
692+
} else if service.Spec.ExternalTrafficPolicy == api.ServiceExternalTrafficPolicyTypeLocal {
693693
// This service is using a custom healthcheck port (enabled through setting
694694
// externalTrafficPolicy=Local on the service). As this port is unique
695695
// per service, we know no other service will be using this port too.

pkg/cloudprovider/providers/oci/load_balancer_security_lists_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
v1listers "k8s.io/client-go/listers/core/v1"
2828
"k8s.io/client-go/tools/cache"
29-
api "k8s.io/kubernetes/pkg/apis/core"
3029
k8sports "k8s.io/kubernetes/pkg/cluster/ports"
3130
)
3231

@@ -171,7 +170,7 @@ func TestGetNodeIngressRules(t *testing.T) {
171170
ObjectMeta: metav1.ObjectMeta{Namespace: "namespace", Name: "using-default-health-check-port"},
172171
Spec: v1.ServiceSpec{
173172
Type: v1.ServiceTypeLoadBalancer,
174-
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicy(api.ServiceExternalTrafficPolicyCluster),
173+
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster,
175174
Ports: []v1.ServicePort{{Port: 443}},
176175
},
177176
},
@@ -201,15 +200,15 @@ func TestGetNodeIngressRules(t *testing.T) {
201200
ObjectMeta: metav1.ObjectMeta{Namespace: "namespace", Name: "using-default-health-check-port"},
202201
Spec: v1.ServiceSpec{
203202
Type: v1.ServiceTypeLoadBalancer,
204-
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicy(api.ServiceExternalTrafficPolicyCluster),
203+
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster,
205204
Ports: []v1.ServicePort{{Port: 443}},
206205
},
207206
},
208207
{
209208
ObjectMeta: metav1.ObjectMeta{Namespace: "namespace", Name: "using-NodePort-health-check-port"},
210209
Spec: v1.ServiceSpec{
211210
Type: v1.ServiceTypeLoadBalancer,
212-
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicy(api.ServiceExternalTrafficPolicyLocal),
211+
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster,
213212
Ports: []v1.ServicePort{{Port: 8081}},
214213
HealthCheckNodePort: 32000,
215214
},
@@ -316,7 +315,7 @@ func TestGetNodeIngressRules(t *testing.T) {
316315
ObjectMeta: metav1.ObjectMeta{Namespace: "namespace", Name: "using-non-default-health-check-port"},
317316
Spec: v1.ServiceSpec{
318317
Type: v1.ServiceTypeLoadBalancer,
319-
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicy(api.ServiceExternalTrafficPolicyLocal),
318+
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeLocal,
320319
Ports: []v1.ServicePort{{Port: 8081}},
321320
},
322321
},
@@ -495,7 +494,7 @@ func TestGetNodeIngressRules_NLB(t *testing.T) {
495494
ObjectMeta: metav1.ObjectMeta{Namespace: "namespace", Name: "using-default-health-check-port"},
496495
Spec: v1.ServiceSpec{
497496
Type: v1.ServiceTypeLoadBalancer,
498-
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicy(api.ServiceExternalTrafficPolicyCluster),
497+
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster,
499498
Ports: []v1.ServicePort{{Port: 443}},
500499
},
501500
},
@@ -996,7 +995,7 @@ func TestGetLoadBalancerEgressRules(t *testing.T) {
996995
ObjectMeta: metav1.ObjectMeta{Namespace: "namespace", Name: "using-default-health-check-port"},
997996
Spec: v1.ServiceSpec{
998997
Type: v1.ServiceTypeLoadBalancer,
999-
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicy(api.ServiceExternalTrafficPolicyCluster),
998+
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster,
1000999
Ports: []v1.ServicePort{{Port: 80}},
10011000
},
10021001
},
@@ -1020,7 +1019,7 @@ func TestGetLoadBalancerEgressRules(t *testing.T) {
10201019
ObjectMeta: metav1.ObjectMeta{Namespace: "namespace", Name: "using-default-health-check-port"},
10211020
Spec: v1.ServiceSpec{
10221021
Type: v1.ServiceTypeLoadBalancer,
1023-
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicy(api.ServiceExternalTrafficPolicyLocal),
1022+
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeLocal,
10241023
HealthCheckNodePort: 30000,
10251024
},
10261025
},
@@ -1045,7 +1044,7 @@ func TestGetLoadBalancerEgressRules(t *testing.T) {
10451044
ObjectMeta: metav1.ObjectMeta{Namespace: "namespace", Name: "using-Nodeport-health-check-port"},
10461045
Spec: v1.ServiceSpec{
10471046
Type: v1.ServiceTypeLoadBalancer,
1048-
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicy(api.ServiceExternalTrafficPolicyLocal),
1047+
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeLocal,
10491048
Ports: []v1.ServicePort{{Port: 80}},
10501049
HealthCheckNodePort: 30000,
10511050
},
@@ -1055,7 +1054,7 @@ func TestGetLoadBalancerEgressRules(t *testing.T) {
10551054
Spec: v1.ServiceSpec{
10561055
Type: v1.ServiceTypeLoadBalancer,
10571056
Ports: []v1.ServicePort{{Port: 8080}},
1058-
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicy(api.ServiceExternalTrafficPolicyCluster),
1057+
ExternalTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster,
10591058
},
10601059
},
10611060
},

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

Lines changed: 16 additions & 2 deletions
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

Lines changed: 32 additions & 6 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 4 additions & 0 deletions
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
Lines changed: 22 additions & 0 deletions
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)