@@ -20,12 +20,12 @@ import (
20
20
)
21
21
22
22
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" } ,
29
29
}
30
30
)
31
31
@@ -69,11 +69,11 @@ var _ = g.Describe("Service Annotation tests GCP", framework.LabelCCM, framework
69
69
}
70
70
})
71
71
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 () {
73
73
g .By ("Create service without annotations" )
74
74
service := & corev1.Service {
75
75
ObjectMeta : metav1.ObjectMeta {
76
- Name : "test-service-ip -validation" ,
76
+ Name : "test-service-annotation -validation" ,
77
77
Namespace : namespace ,
78
78
},
79
79
Spec : corev1.ServiceSpec {
@@ -87,7 +87,6 @@ var _ = g.Describe("Service Annotation tests GCP", framework.LabelCCM, framework
87
87
o .Expect (cl .Create (ctx , service )).To (o .Succeed ())
88
88
createdServices = append (createdServices , service .Name )
89
89
90
- g .By ("Verify LoadBalancer service creation" )
91
90
var lastIngressIP string
92
91
o .Eventually (func () (string , error ) {
93
92
updatedService := & corev1.Service {}
@@ -103,57 +102,39 @@ var _ = g.Describe("Service Annotation tests GCP", framework.LabelCCM, framework
103
102
return "" , nil
104
103
}, 2 * time .Minute , 10 * time .Second ).ShouldNot (o .BeEmpty (), "LoadBalancer service did not get an external IP" )
105
104
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
+ }
157
138
}
158
139
}
159
140
})
0 commit comments