@@ -37,7 +37,7 @@ var _ = Describe("Running the namespace add command", func() {
37
37
out = new (bytes.Buffer )
38
38
fakeClientSet = fake .NewSimpleClientset ()
39
39
40
- nsSpec := createNamespaceSpec (testNamespace , "" , false , false )
40
+ nsSpec := createNamespaceSpec (testNamespace , "" , false , false , false )
41
41
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), nsSpec , metav1.CreateOptions {})
42
42
Expect (err ).To (BeNil ())
43
43
@@ -69,7 +69,7 @@ var _ = Describe("Running the namespace add command", func() {
69
69
_ , err = addDeployment (fakeClientSet , constants .OSMControllerName , testMeshName , "osm-system-namespace" , "testVersion0.1.2" , true )
70
70
Expect (err ).To (BeNil ())
71
71
72
- nsSpec := createNamespaceSpec (testNamespace , "" , false , true )
72
+ nsSpec := createNamespaceSpec (testNamespace , "" , false , true , false )
73
73
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), nsSpec , metav1.CreateOptions {})
74
74
Expect (err ).ToNot (HaveOccurred ())
75
75
@@ -97,7 +97,7 @@ var _ = Describe("Running the namespace add command", func() {
97
97
_ , err = addDeployment (fakeClientSet , constants .OSMControllerName , testMeshName , "osm-system-namespace" , "testVersion0.1.2" , true )
98
98
Expect (err ).To (BeNil ())
99
99
100
- nsSpec := createNamespaceSpec (testNamespace , testMeshName , true , false )
100
+ nsSpec := createNamespaceSpec (testNamespace , testMeshName , true , false , false )
101
101
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), nsSpec , metav1.CreateOptions {})
102
102
Expect (err ).ToNot (HaveOccurred ())
103
103
@@ -129,7 +129,7 @@ var _ = Describe("Running the namespace add command", func() {
129
129
_ , err = addDeployment (fakeClientSet , constants .OSMControllerName , testMeshName , "osm-system-namespace" , "testVersion0.1.2" , true )
130
130
Expect (err ).To (BeNil ())
131
131
132
- nsSpec := createNamespaceSpec (testNamespace , "" , false , false )
132
+ nsSpec := createNamespaceSpec (testNamespace , "" , false , false , false )
133
133
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), nsSpec , metav1.CreateOptions {})
134
134
Expect (err ).To (BeNil ())
135
135
@@ -173,7 +173,7 @@ var _ = Describe("Running the namespace add command", func() {
173
173
_ , err = addDeployment (fakeClientSet , constants .OSMControllerName , testMeshName , "osm-system-namespace" , "testVersion0.1.2" , true )
174
174
Expect (err ).To (BeNil ())
175
175
176
- nsSpec := createNamespaceSpec (testNamespace , "" , false , false )
176
+ nsSpec := createNamespaceSpec (testNamespace , "" , false , false , false )
177
177
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), nsSpec , metav1.CreateOptions {})
178
178
Expect (err ).ToNot (HaveOccurred ())
179
179
@@ -217,7 +217,7 @@ var _ = Describe("Running the namespace add command", func() {
217
217
_ , err = addDeployment (fakeClientSet , constants .OSMControllerName , testMeshName , "osm-system-namespace" , "testVersion0.1.2" , true )
218
218
Expect (err ).To (BeNil ())
219
219
220
- nsSpec := createNamespaceSpec (testNamespace , "" , true , false )
220
+ nsSpec := createNamespaceSpec (testNamespace , "" , true , false , false )
221
221
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), nsSpec , metav1.CreateOptions {})
222
222
Expect (err ).ToNot (HaveOccurred ())
223
223
@@ -267,11 +267,11 @@ var _ = Describe("Running the namespace add command", func() {
267
267
_ , err = addDeployment (fakeClientSet , constants .OSMControllerName , testMeshName , "osm-system-namespace" , "testVersion0.1.2" , true )
268
268
Expect (err ).To (BeNil ())
269
269
270
- nsSpec := createNamespaceSpec (testNamespace , "" , false , false )
270
+ nsSpec := createNamespaceSpec (testNamespace , "" , false , false , false )
271
271
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), nsSpec , metav1.CreateOptions {})
272
272
Expect (err ).To (BeNil ())
273
273
274
- nsSpec2 := createNamespaceSpec (testNamespace2 , "" , false , false )
274
+ nsSpec2 := createNamespaceSpec (testNamespace2 , "" , false , false , false )
275
275
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), nsSpec2 , metav1.CreateOptions {})
276
276
Expect (err ).To (BeNil ())
277
277
@@ -316,7 +316,7 @@ var _ = Describe("Running the namespace add command", func() {
316
316
_ , err = addDeployment (fakeClientSet , constants .OSMControllerName , testMeshName , "osm-system-namespace" , "testVersion0.1.2" , true )
317
317
Expect (err ).To (BeNil ())
318
318
319
- nsSpec := createNamespaceSpec (testNamespace , "" , false , false )
319
+ nsSpec := createNamespaceSpec (testNamespace , "" , false , false , false )
320
320
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), nsSpec , metav1.CreateOptions {})
321
321
Expect (err ).To (BeNil ())
322
322
@@ -353,7 +353,7 @@ var _ = Describe("Running the namespace add command", func() {
353
353
out = new (bytes.Buffer )
354
354
fakeClientSet = fake .NewSimpleClientset ()
355
355
356
- nsSpec := createNamespaceSpec (testNamespace , "" , false , false )
356
+ nsSpec := createNamespaceSpec (testNamespace , "" , false , false , false )
357
357
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), nsSpec , metav1.CreateOptions {})
358
358
Expect (err ).To (BeNil ())
359
359
@@ -422,7 +422,7 @@ var _ = Describe("Running the namespace remove command", func() {
422
422
out = new (bytes.Buffer )
423
423
fakeClientSet = fake .NewSimpleClientset ()
424
424
425
- nsSpec := createNamespaceSpec (testNamespace , testMeshName , false , false )
425
+ nsSpec := createNamespaceSpec (testNamespace , testMeshName , false , false , false )
426
426
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), nsSpec , metav1.CreateOptions {})
427
427
Expect (err ).To (BeNil ())
428
428
@@ -451,7 +451,7 @@ var _ = Describe("Running the namespace remove command", func() {
451
451
})
452
452
})
453
453
454
- Describe ("with pre-existing namespace, correct label and annotation" , func () {
454
+ Describe ("with pre-existing namespace, correct label, injection annotation, and metrics annotation" , func () {
455
455
var (
456
456
out * bytes.Buffer
457
457
fakeClientSet kubernetes.Interface
@@ -462,7 +462,7 @@ var _ = Describe("Running the namespace remove command", func() {
462
462
out = new (bytes.Buffer )
463
463
fakeClientSet = fake .NewSimpleClientset ()
464
464
465
- nsSpec := createNamespaceSpec (testNamespace , testMeshName , true , false )
465
+ nsSpec := createNamespaceSpec (testNamespace , testMeshName , true , false , true )
466
466
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), nsSpec , metav1.CreateOptions {})
467
467
Expect (err ).ToNot (HaveOccurred ())
468
468
@@ -495,6 +495,12 @@ var _ = Describe("Running the namespace remove command", func() {
495
495
Expect (err ).ToNot (HaveOccurred ())
496
496
Expect (ns .Annotations ).ShouldNot (HaveKey (constants .SidecarInjectionAnnotation ))
497
497
})
498
+
499
+ It ("should correctly remove the metrics annotation on the namespace" , func () {
500
+ ns , err := fakeClientSet .CoreV1 ().Namespaces ().Get (context .TODO (), testNamespace , metav1.GetOptions {})
501
+ Expect (err ).ToNot (HaveOccurred ())
502
+ Expect (ns .Annotations ).ShouldNot (HaveKey (constants .MetricsAnnotation ))
503
+ })
498
504
})
499
505
500
506
Describe ("with pre-existing namespace and incorrect label" , func () {
@@ -508,7 +514,7 @@ var _ = Describe("Running the namespace remove command", func() {
508
514
out = new (bytes.Buffer )
509
515
fakeClientSet = fake .NewSimpleClientset ()
510
516
511
- nsSpec := createNamespaceSpec (testNamespace , testMeshName , false , false )
517
+ nsSpec := createNamespaceSpec (testNamespace , testMeshName , false , false , false )
512
518
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), nsSpec , metav1.CreateOptions {})
513
519
Expect (err ).To (BeNil ())
514
520
@@ -540,7 +546,7 @@ var _ = Describe("Running the namespace remove command", func() {
540
546
out = new (bytes.Buffer )
541
547
fakeClientSet = fake .NewSimpleClientset ()
542
548
543
- nsSpec := createNamespaceSpec (testNamespace , "" , false , false )
549
+ nsSpec := createNamespaceSpec (testNamespace , "" , false , false , false )
544
550
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), nsSpec , metav1.CreateOptions {})
545
551
Expect (err ).To (BeNil ())
546
552
@@ -563,7 +569,7 @@ var _ = Describe("Running the namespace remove command", func() {
563
569
})
564
570
})
565
571
566
- Describe ("with pre-existing ignored namespace with annotation " , func () {
572
+ Describe ("with pre-existing ignored namespace with injection and metrics annotations " , func () {
567
573
var (
568
574
out * bytes.Buffer
569
575
fakeClientSet kubernetes.Interface
@@ -574,7 +580,7 @@ var _ = Describe("Running the namespace remove command", func() {
574
580
out = new (bytes.Buffer )
575
581
fakeClientSet = fake .NewSimpleClientset ()
576
582
577
- nsSpec := createNamespaceSpec (testNamespace , testMeshName , true , true )
583
+ nsSpec := createNamespaceSpec (testNamespace , testMeshName , true , true , true )
578
584
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), nsSpec , metav1.CreateOptions {})
579
585
Expect (err ).To (BeNil ())
580
586
@@ -613,6 +619,12 @@ var _ = Describe("Running the namespace remove command", func() {
613
619
Expect (err ).ToNot (HaveOccurred ())
614
620
Expect (ns .Annotations ).ShouldNot (HaveKey (constants .SidecarInjectionAnnotation ))
615
621
})
622
+
623
+ It ("should correctly remove the metrics annotation on the namespace" , func () {
624
+ ns , err := fakeClientSet .CoreV1 ().Namespaces ().Get (context .TODO (), testNamespace , metav1.GetOptions {})
625
+ Expect (err ).ToNot (HaveOccurred ())
626
+ Expect (ns .Annotations ).ShouldNot (HaveKey (constants .MetricsAnnotation ))
627
+ })
616
628
})
617
629
618
630
Describe ("with non-existent namespace" , func () {
@@ -656,7 +668,7 @@ var _ = Describe("Running the namespace list command", func() {
656
668
657
669
// helper function that adds a name space to the clientset
658
670
addNamespace := func (name , mesh string , enableSideCarInjection bool ) {
659
- ns := createNamespaceSpec (name , mesh , enableSideCarInjection , false )
671
+ ns := createNamespaceSpec (name , mesh , enableSideCarInjection , false , false )
660
672
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), ns , metav1.CreateOptions {})
661
673
Expect (err ).To (BeNil ())
662
674
}
@@ -798,7 +810,7 @@ var _ = Describe("Running the namespace ignore command", func() {
798
810
out = new (bytes.Buffer )
799
811
fakeClientSet = fake .NewSimpleClientset ()
800
812
801
- nsSpec := createNamespaceSpec (testNamespace , "" , false , false )
813
+ nsSpec := createNamespaceSpec (testNamespace , "" , false , false , false )
802
814
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), nsSpec , metav1.CreateOptions {})
803
815
Expect (err ).NotTo (HaveOccurred ())
804
816
@@ -829,11 +841,11 @@ var _ = Describe("Running the namespace ignore command", func() {
829
841
out = new (bytes.Buffer )
830
842
fakeClientSet = fake .NewSimpleClientset ()
831
843
832
- nsSpec := createNamespaceSpec (testNamespace , "" , false , false )
844
+ nsSpec := createNamespaceSpec (testNamespace , "" , false , false , false )
833
845
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), nsSpec , metav1.CreateOptions {})
834
846
Expect (err ).NotTo (HaveOccurred ())
835
847
836
- nsSpec2 := createNamespaceSpec (testNamespace2 , "" , false , false )
848
+ nsSpec2 := createNamespaceSpec (testNamespace2 , "" , false , false , false )
837
849
_ , err = fakeClientSet .CoreV1 ().Namespaces ().Create (context .TODO (), nsSpec2 , metav1.CreateOptions {})
838
850
Expect (err ).NotTo (HaveOccurred ())
839
851
@@ -859,7 +871,7 @@ var _ = Describe("Running the namespace ignore command", func() {
859
871
})
860
872
})
861
873
862
- func createNamespaceSpec (namespace , meshName string , enableSideCarInjection bool , ignoreNamespace bool ) * v1.Namespace {
874
+ func createNamespaceSpec (namespace , meshName string , enableSideCarInjection bool , ignoreNamespace bool , enableMetrics bool ) * v1.Namespace {
863
875
labelMap := make (map [string ]string )
864
876
if meshName != "" {
865
877
labelMap [constants .OSMKubeResourceMonitorAnnotation ] = meshName
@@ -879,5 +891,9 @@ func createNamespaceSpec(namespace, meshName string, enableSideCarInjection bool
879
891
labelMap [constants .IgnoreLabel ] = trueValue
880
892
}
881
893
894
+ if enableMetrics {
895
+ labelMap [constants .MetricsAnnotation ] = "enabled"
896
+ }
897
+
882
898
return ns
883
899
}
0 commit comments