Skip to content

Commit 7e59d6c

Browse files
mmamczurrino-gaelico
authored andcommitted
Split NEG related part of pkg/annotations into pkg/negannotation.
1 parent 77473e0 commit 7e59d6c

File tree

31 files changed

+672
-594
lines changed

31 files changed

+672
-594
lines changed

cmd/check-gke-ingress/app/ingress/rule.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
beconfigv1 "k8s.io/ingress-gce/pkg/apis/backendconfig/v1"
3232
beconfigclient "k8s.io/ingress-gce/pkg/backendconfig/client/clientset/versioned"
3333
feconfigclient "k8s.io/ingress-gce/pkg/frontendconfig/client/clientset/versioned"
34+
"k8s.io/ingress-gce/pkg/negannotation"
3435
)
3536

3637
const (
@@ -202,7 +203,7 @@ func CheckL7ILBNegAnnotation(c *ServiceChecker) (string, string, string) {
202203
if !ok {
203204
return L7ILBNegAnnotationCheck, report.Failed, fmt.Sprintf("No Neg annotation found in service %s/%s for internal HTTP(S) load balancing, internal ingress requires Neg as backends", c.namespace, c.name)
204205
}
205-
var res annotations.NegAnnotation
206+
var res negannotation.NegAnnotation
206207
if err := json.Unmarshal([]byte(val), &res); err != nil {
207208
return L7ILBNegAnnotationCheck, report.Failed, fmt.Sprintf("Invalid Neg annotation found in service %s/%s for internal HTTP(S) load balancing", c.namespace, c.name)
208209
}
@@ -301,7 +302,7 @@ func getFrontendConfigAnnotation(ing *networkingv1.Ingress) (string, bool) {
301302

302303
// getNegAnnotation gets the NEG annotation from a service object.
303304
func getNegAnnotation(svc *corev1.Service) (string, bool) {
304-
val, ok := svc.Annotations[annotations.NEGAnnotationKey]
305+
val, ok := svc.Annotations[negannotation.NEGAnnotationKey]
305306
if !ok {
306307
return "", false
307308
}

cmd/check-gke-ingress/app/ingress/rule_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
corev1 "k8s.io/api/core/v1"
2525
networkingv1 "k8s.io/api/networking/v1"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27+
"k8s.io/ingress-gce/pkg/negannotation"
2728

2829
"k8s.io/client-go/kubernetes/fake"
2930
"k8s.io/ingress-gce/cmd/check-gke-ingress/app/report"
@@ -594,7 +595,7 @@ func TestCheckL7ILBNegAnnotation(t *testing.T) {
594595
Name: "svc-1",
595596
Namespace: "test",
596597
Annotations: map[string]string{
597-
annotations.NEGAnnotationKey: `{"ingress": true,}`,
598+
negannotation.NEGAnnotationKey: `{"ingress": true,}`,
598599
},
599600
},
600601
},
@@ -607,7 +608,7 @@ func TestCheckL7ILBNegAnnotation(t *testing.T) {
607608
Name: "svc-1",
608609
Namespace: "test",
609610
Annotations: map[string]string{
610-
annotations.NEGAnnotationKey: `{"exposed_ports": {"80":{"name": "neg1"}}}`,
611+
negannotation.NEGAnnotationKey: `{"exposed_ports": {"80":{"name": "neg1"}}}`,
611612
},
612613
},
613614
},
@@ -620,7 +621,7 @@ func TestCheckL7ILBNegAnnotation(t *testing.T) {
620621
Name: "svc-1",
621622
Namespace: "test",
622623
Annotations: map[string]string{
623-
annotations.NEGAnnotationKey: `{"ingress": true}`,
624+
negannotation.NEGAnnotationKey: `{"ingress": true}`,
624625
},
625626
},
626627
},

cmd/ingress-controller-e2e-test/affinity_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"k8s.io/ingress-gce/pkg/e2e/adapter"
3232
"k8s.io/ingress-gce/pkg/fuzz"
3333
"k8s.io/ingress-gce/pkg/fuzz/features"
34+
"k8s.io/ingress-gce/pkg/negannotation"
3435
"k8s.io/ingress-gce/pkg/utils"
3536
)
3637

@@ -224,7 +225,7 @@ func TestILBSA(t *testing.T) {
224225

225226
svcAnnotation := map[string]string{
226227
annotations.BetaBackendConfigKey: `{"default":"backendconfig-1"}`,
227-
annotations.NEGAnnotationKey: negVal.String(),
228+
negannotation.NEGAnnotationKey: negVal.String(),
228229
}
229230

230231
bcCRUD := adapter.BackendConfigCRUD{C: Framework.BackendConfigClient}
@@ -362,7 +363,7 @@ func TestRegionalXLBSA(t *testing.T) {
362363

363364
svcAnnotation := map[string]string{
364365
annotations.BetaBackendConfigKey: `{"default":"backendconfig-1"}`,
365-
annotations.NEGAnnotationKey: negVal.String(),
366+
negannotation.NEGAnnotationKey: negVal.String(),
366367
}
367368

368369
bcCRUD := adapter.BackendConfigCRUD{C: Framework.BackendConfigClient}

cmd/ingress-controller-e2e-test/app_protocols_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"k8s.io/ingress-gce/pkg/e2e/adapter"
2828
"k8s.io/ingress-gce/pkg/fuzz"
2929
"k8s.io/ingress-gce/pkg/fuzz/features"
30+
"k8s.io/ingress-gce/pkg/negannotation"
3031
)
3132

3233
func TestAppProtocol(t *testing.T) {
@@ -209,7 +210,7 @@ func TestRegionalXLBAppProtocol(t *testing.T) {
209210

210211
svcAnnotation := map[string]string{
211212
annotations.GoogleServiceApplicationProtocolKey: tc.annotationVal,
212-
annotations.NEGAnnotationKey: negVal.String(),
213+
negannotation.NEGAnnotationKey: negVal.String(),
213214
}
214215
_, err := e2e.CreateEchoService(s, "service-1", svcAnnotation)
215216
if err != nil {
@@ -281,7 +282,7 @@ func TestRegionalXLBProtocolTransition(t *testing.T) {
281282

282283
svcAnnotation := map[string]string{
283284
annotations.ServiceApplicationProtocolKey: tc.annotationVal,
284-
annotations.NEGAnnotationKey: negVal.String(),
285+
negannotation.NEGAnnotationKey: negVal.String(),
285286
}
286287
_, err := e2e.EnsureEchoService(s, "service-1", svcAnnotation, corev1.ServiceTypeNodePort, 1)
287288
if err != nil {
@@ -309,7 +310,7 @@ func TestRegionalXLBProtocolTransition(t *testing.T) {
309310
// Update the service with the new app protocol.
310311
svcAnnotation = map[string]string{
311312
annotations.ServiceApplicationProtocolKey: tc.newAnnotationVal,
312-
annotations.NEGAnnotationKey: negVal.String(),
313+
negannotation.NEGAnnotationKey: negVal.String(),
313314
}
314315

315316
if _, err = e2e.EnsureEchoService(s, "service-1", svcAnnotation, corev1.ServiceTypeNodePort, 1); err != nil {

cmd/ingress-controller-e2e-test/backend_config_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"k8s.io/ingress-gce/pkg/e2e"
3636
"k8s.io/ingress-gce/pkg/e2e/adapter"
3737
"k8s.io/ingress-gce/pkg/fuzz"
38+
"k8s.io/ingress-gce/pkg/negannotation"
3839
"k8s.io/ingress-gce/pkg/test"
3940
)
4041

@@ -233,24 +234,24 @@ func TestRegionalXLBBackendConfigNegatives(t *testing.T) {
233234
{
234235
desc: "backend config not exist",
235236
svcAnnotations: map[string]string{
236-
annotations.BackendConfigKey: `{"default":"backendconfig-1"}`,
237-
annotations.NEGAnnotationKey: negVal.String(),
237+
annotations.BackendConfigKey: `{"default":"backendconfig-1"}`,
238+
negannotation.NEGAnnotationKey: negVal.String(),
238239
},
239240
expectedMsg: "no BackendConfig",
240241
},
241242
{
242243
desc: "invalid format in backend config annotation",
243244
svcAnnotations: map[string]string{
244-
annotations.BackendConfigKey: `invalid`,
245-
annotations.NEGAnnotationKey: negVal.String(),
245+
annotations.BackendConfigKey: `invalid`,
246+
negannotation.NEGAnnotationKey: negVal.String(),
246247
},
247248
expectedMsg: fmt.Sprintf("%v", annotations.ErrBackendConfigInvalidJSON),
248249
},
249250
{
250251
desc: "enable IAP in backend config",
251252
svcAnnotations: map[string]string{
252-
annotations.BackendConfigKey: `{"default":"backendconfig-1"}`,
253-
annotations.NEGAnnotationKey: negVal.String(),
253+
annotations.BackendConfigKey: `{"default":"backendconfig-1"}`,
254+
negannotation.NEGAnnotationKey: negVal.String(),
254255
},
255256
backendConfig: fuzz.NewBackendConfigBuilder("", "backendconfig-1").
256257
SetIAPConfig(true, "bar").
@@ -260,8 +261,8 @@ func TestRegionalXLBBackendConfigNegatives(t *testing.T) {
260261
{
261262
desc: "enable CDN in backend config",
262263
svcAnnotations: map[string]string{
263-
annotations.BackendConfigKey: `{"default":"backendconfig-1"}`,
264-
annotations.NEGAnnotationKey: negVal.String(),
264+
annotations.BackendConfigKey: `{"default":"backendconfig-1"}`,
265+
negannotation.NEGAnnotationKey: negVal.String(),
265266
},
266267
backendConfig: fuzz.NewBackendConfigBuilder("", "backendconfig-1").
267268
EnableCDN(true).

cmd/ingress-controller-e2e-test/cdn_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"k8s.io/ingress-gce/pkg/e2e/adapter"
3535
"k8s.io/ingress-gce/pkg/fuzz"
3636
"k8s.io/ingress-gce/pkg/fuzz/features"
37+
"k8s.io/ingress-gce/pkg/negannotation"
3738
"k8s.io/ingress-gce/pkg/utils"
3839
"k8s.io/klog/v2"
3940
)
@@ -912,8 +913,8 @@ func setupIngress(s *e2e.Sandbox, ingressName, serviceName1, backendconfig1 stri
912913
Build()
913914

914915
serviceAnnotations := map[string]string{
915-
annotations.BackendConfigKey: fmt.Sprintf(`{"%s":"%s"}`, "default", backendconfig1),
916-
annotations.NEGAnnotationKey: `{"ingress": true}`,
916+
annotations.BackendConfigKey: fmt.Sprintf(`{"%s":"%s"}`, "default", backendconfig1),
917+
negannotation.NEGAnnotationKey: `{"ingress": true}`,
917918
}
918919

919920
// create the backend config with defaults

cmd/ingress-controller-e2e-test/draining_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"k8s.io/ingress-gce/pkg/e2e/adapter"
3232
"k8s.io/ingress-gce/pkg/fuzz"
3333
"k8s.io/ingress-gce/pkg/fuzz/features"
34+
"k8s.io/ingress-gce/pkg/negannotation"
3435
"k8s.io/ingress-gce/pkg/utils"
3536
)
3637

@@ -196,7 +197,7 @@ func TestRegionalXLBDrain(t *testing.T) {
196197

197198
backendConfigAnnotation := map[string]string{
198199
annotations.BetaBackendConfigKey: `{"default":"backendconfig-1"}`,
199-
annotations.NEGAnnotationKey: negVal.String(),
200+
negannotation.NEGAnnotationKey: negVal.String(),
200201
}
201202

202203
bcCRUD := adapter.BackendConfigCRUD{C: Framework.BackendConfigClient}

cmd/ingress-controller-e2e-test/healthcheck_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/ingress-gce/pkg/e2e/adapter"
3333
"k8s.io/ingress-gce/pkg/fuzz"
3434
"k8s.io/ingress-gce/pkg/fuzz/features"
35+
"k8s.io/ingress-gce/pkg/negannotation"
3536
)
3637

3738
func TestHealthCheck(t *testing.T) {
@@ -91,7 +92,7 @@ func TestHealthCheck(t *testing.T) {
9192

9293
// Update service for NEG
9394
if tc.want.Port != nil {
94-
svc.Annotations[annotations.NEGAnnotationKey] = `{"ingress":true}`
95+
svc.Annotations[negannotation.NEGAnnotationKey] = `{"ingress":true}`
9596
if _, err := Framework.Clientset.CoreV1().Services(s.Namespace).Update(ctx, svc, v1.UpdateOptions{}); err != nil {
9697
t.Fatalf("error updating port on svc: %v", err)
9798
}
@@ -204,8 +205,8 @@ func TestRegionalXLBHC(t *testing.T) {
204205
ctx := context.Background()
205206

206207
backendConfigAnnotation := map[string]string{
207-
annotations.BackendConfigKey: `{"default":"backendconfig-1"}`,
208-
annotations.NEGAnnotationKey: negVal.String(),
208+
annotations.BackendConfigKey: `{"default":"backendconfig-1"}`,
209+
negannotation.NEGAnnotationKey: negVal.String(),
209210
}
210211
tc.beConfig.Spec.HealthCheck = tc.want
211212

cmd/ingress-controller-e2e-test/ilb_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ import (
2323

2424
v1 "k8s.io/api/networking/v1"
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26-
"k8s.io/ingress-gce/pkg/annotations"
2726
"k8s.io/ingress-gce/pkg/e2e"
2827
"k8s.io/ingress-gce/pkg/e2e/adapter"
2928
"k8s.io/ingress-gce/pkg/fuzz"
3029
"k8s.io/ingress-gce/pkg/fuzz/features"
30+
"k8s.io/ingress-gce/pkg/negannotation"
3131
"k8s.io/ingress-gce/pkg/utils"
3232
)
3333

3434
var (
35-
negVal = annotations.NegAnnotation{Ingress: true}
35+
negVal = negannotation.NegAnnotation{Ingress: true}
3636
negAnnotation = map[string]string{
37-
annotations.NEGAnnotationKey: negVal.String()}
37+
negannotation.NEGAnnotationKey: negVal.String()}
3838
)
3939

4040
func TestILB(t *testing.T) {
@@ -735,7 +735,7 @@ func TestILBError(t *testing.T) {
735735
if err != nil {
736736
t.Fatalf("expect err = nil, but got %v", err)
737737
}
738-
svcAnnotation := annotations.FromService(svc)
738+
svcAnnotation := negannotation.FromService(svc)
739739
negAnnotation, ok, err := svcAnnotation.NEGAnnotation()
740740
if err != nil {
741741
t.Fatalf("expect err = nil, but got %v", err)

cmd/ingress-controller-e2e-test/logging_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"k8s.io/ingress-gce/pkg/e2e/adapter"
3131
"k8s.io/ingress-gce/pkg/fuzz"
3232
"k8s.io/ingress-gce/pkg/fuzz/features"
33+
"k8s.io/ingress-gce/pkg/negannotation"
3334
"k8s.io/ingress-gce/pkg/test"
3435
"k8s.io/ingress-gce/pkg/utils"
3536
"k8s.io/ingress-gce/pkg/utils/common"
@@ -257,8 +258,8 @@ func TestRegionalXLBLog(t *testing.T) {
257258
ctx := context.Background()
258259

259260
backendConfigAnnotation := map[string]string{
260-
annotations.BackendConfigKey: fmt.Sprintf(`{"default":"%s"}`, tc.beConfig.Name),
261-
annotations.NEGAnnotationKey: negVal.String(),
261+
annotations.BackendConfigKey: fmt.Sprintf(`{"default":"%s"}`, tc.beConfig.Name),
262+
negannotation.NEGAnnotationKey: negVal.String(),
262263
}
263264

264265
bcCRUD := adapter.BackendConfigCRUD{C: Framework.BackendConfigClient}

0 commit comments

Comments
 (0)