Skip to content

Commit 9383e0a

Browse files
committed
updated test to cover OCP-79045
1 parent ba9d97d commit 9383e0a

File tree

1 file changed

+41
-60
lines changed

1 file changed

+41
-60
lines changed

pkg/annotations/gcp.go

+41-60
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import (
2020
)
2121

2222
var (
23-
annotationsToTest = map[string]string{
24-
"traffic-policy.network.alpha.openshift.io/local-with-fallback": "true",
25-
"alpha.cloud.google.com/load-balancer-backend-share": "",
26-
"networking.gke.io/internal-load-balancer-allow-global-access": "true",
27-
"networking.gke.io/internal-load-balancer-subnet": "",
28-
"cloud.google.com/network-tier": "Standard",
23+
annotationsToTest = map[string][]string{
24+
"traffic-policy.network.alpha.openshift.io/local-with-fallback": {"true"},
25+
"alpha.cloud.google.com/load-balancer-backend-share": {""},
26+
"networking.gke.io/internal-load-balancer-allow-global-access": {"true"},
27+
"networking.gke.io/internal-load-balancer-subnet": {""},
28+
"cloud.google.com/network-tier": {"Standard", "Premium", "InvalidValue"},
2929
}
3030
)
3131

@@ -69,11 +69,11 @@ var _ = g.Describe("Service Annotation tests GCP", framework.LabelCCM, framework
6969
}
7070
})
7171

72-
g.It("should validate IP changes only for specific annotations", func() {
72+
g.It("should validate annotations including network-tier and IP changes", func() {
7373
g.By("Create service without annotations")
7474
service := &corev1.Service{
7575
ObjectMeta: metav1.ObjectMeta{
76-
Name: "test-service-ip-validation",
76+
Name: "test-service-annotation-validation",
7777
Namespace: namespace,
7878
},
7979
Spec: corev1.ServiceSpec{
@@ -87,7 +87,6 @@ var _ = g.Describe("Service Annotation tests GCP", framework.LabelCCM, framework
8787
o.Expect(cl.Create(ctx, service)).To(o.Succeed())
8888
createdServices = append(createdServices, service.Name)
8989

90-
g.By("Verify LoadBalancer service creation")
9190
var lastIngressIP string
9291
o.Eventually(func() (string, error) {
9392
updatedService := &corev1.Service{}
@@ -103,57 +102,39 @@ var _ = g.Describe("Service Annotation tests GCP", framework.LabelCCM, framework
103102
return "", nil
104103
}, 2*time.Minute, 10*time.Second).ShouldNot(o.BeEmpty(), "LoadBalancer service did not get an external IP")
105104

106-
// Add and remove annotations alternately
107-
for key, value := range annotationsToTest {
108-
// Add annotation
109-
g.By(fmt.Sprintf("Adding annotation: %s=%s", key, value))
110-
latestService := &corev1.Service{}
111-
o.Expect(cl.Get(ctx, client.ObjectKey{Name: service.Name, Namespace: namespace}, latestService)).To(o.Succeed())
112-
113-
if latestService.Annotations == nil {
114-
latestService.Annotations = make(map[string]string)
115-
}
116-
latestService.Annotations[key] = value
117-
o.Expect(cl.Update(ctx, latestService)).To(o.Succeed())
118-
119-
// Validate IP change only for relevant annotations
120-
if key == "cloud.google.com/network-tier" {
121-
g.By(fmt.Sprintf("Validating Ingress IP change after annotation update: %s=%s", key, value))
122-
o.Eventually(func() (string, error) {
123-
updatedService := &corev1.Service{}
124-
err := cl.Get(ctx, client.ObjectKey{Name: service.Name, Namespace: namespace}, updatedService)
125-
if err != nil {
126-
return "", err
127-
}
128-
if len(updatedService.Status.LoadBalancer.Ingress) > 0 {
129-
return updatedService.Status.LoadBalancer.Ingress[0].IP, nil
130-
}
131-
132-
return "", nil
133-
}, 4*time.Minute, 10*time.Second).ShouldNot(o.Equal(lastIngressIP), "Ingress IP did not change after annotation update")
134-
}
135-
136-
// Remove annotation
137-
g.By(fmt.Sprintf("Removing annotation: %s", key))
138-
o.Expect(cl.Get(ctx, client.ObjectKey{Name: service.Name, Namespace: namespace}, latestService)).To(o.Succeed())
139-
delete(latestService.Annotations, key)
140-
o.Expect(cl.Update(ctx, latestService)).To(o.Succeed())
141-
142-
g.By("Validate IP change only for relevant annotations")
143-
if key == "cloud.google.com/network-tier" {
144-
g.By(fmt.Sprintf("Validating Ingress IP change after annotation removal: %s", key))
145-
o.Eventually(func() (string, error) {
146-
updatedService := &corev1.Service{}
147-
err := cl.Get(ctx, client.ObjectKey{Name: service.Name, Namespace: namespace}, updatedService)
148-
if err != nil {
149-
return "", err
150-
}
151-
if len(updatedService.Status.LoadBalancer.Ingress) > 0 {
152-
return updatedService.Status.LoadBalancer.Ingress[0].IP, nil
153-
}
154-
155-
return "", nil
156-
}, 4*time.Minute, 10*time.Second).ShouldNot(o.Equal(lastIngressIP), "Ingress IP did not change after annotation removal")
105+
for key, values := range annotationsToTest {
106+
for _, value := range values {
107+
g.By(fmt.Sprintf("Adding annotation: %s=%s", key, value))
108+
latestService := &corev1.Service{}
109+
o.Expect(cl.Get(ctx, client.ObjectKey{Name: service.Name, Namespace: namespace}, latestService)).To(o.Succeed())
110+
111+
if latestService.Annotations == nil {
112+
latestService.Annotations = make(map[string]string)
113+
}
114+
latestService.Annotations[key] = value
115+
116+
if key == "cloud.google.com/network-tier" && value != "Standard" && value != "Premium" {
117+
o.Expect(cl.Update(ctx, latestService)).ToNot(o.Succeed(), "The annotation 'cloud.google.com/network-tier', if specified, must be either 'Standard' or 'Premium'")
118+
continue
119+
}
120+
121+
o.Expect(cl.Update(ctx, latestService)).To(o.Succeed())
122+
123+
if key == "cloud.google.com/network-tier" {
124+
g.By(fmt.Sprintf("Validating Ingress IP change after annotation update: %s=%s", key, value))
125+
o.Eventually(func() (string, error) {
126+
updatedService := &corev1.Service{}
127+
err := cl.Get(ctx, client.ObjectKey{Name: service.Name, Namespace: namespace}, updatedService)
128+
if err != nil {
129+
return "", err
130+
}
131+
if len(updatedService.Status.LoadBalancer.Ingress) > 0 {
132+
return updatedService.Status.LoadBalancer.Ingress[0].IP, nil
133+
}
134+
135+
return "", nil
136+
}, 4*time.Minute, 10*time.Second).ShouldNot(o.Equal(lastIngressIP), "Ingress IP did not change after annotation update")
137+
}
157138
}
158139
}
159140
})

0 commit comments

Comments
 (0)