@@ -448,7 +448,7 @@ func Test_ingressValidator_checkGroupNameAnnotationUsage(t *testing.T) {
448
448
},
449
449
},
450
450
},
451
- wantErr : errors .New ("new value of `alb.ingress.kubernetes.io/group.name` annotation is forbidden" ),
451
+ wantErr : errors .New ("new usage of `alb.ingress.kubernetes.io/group.name` annotation is forbidden" ),
452
452
},
453
453
}
454
454
for _ , tt := range tests {
@@ -479,7 +479,8 @@ func Test_ingressValidator_checkIngressClassUsage(t *testing.T) {
479
479
}
480
480
481
481
type args struct {
482
- ing * networking.Ingress
482
+ ing * networking.Ingress
483
+ oldIng * networking.Ingress
483
484
}
484
485
tests := []struct {
485
486
name string
@@ -488,7 +489,7 @@ func Test_ingressValidator_checkIngressClassUsage(t *testing.T) {
488
489
wantErr error
489
490
}{
490
491
{
491
- name : "IngressClassName isn't specified " ,
492
+ name : "ingress creation without IngressClassName " ,
492
493
env : env {},
493
494
args : args {
494
495
ing : & networking.Ingress {
@@ -504,7 +505,7 @@ func Test_ingressValidator_checkIngressClassUsage(t *testing.T) {
504
505
wantErr : nil ,
505
506
},
506
507
{
507
- name : "IngressClass didn't exists " ,
508
+ name : "ingress creation with IngressClassName that refers to non-existent IngressClass " ,
508
509
env : env {},
509
510
args : args {
510
511
ing : & networking.Ingress {
@@ -520,7 +521,7 @@ func Test_ingressValidator_checkIngressClassUsage(t *testing.T) {
520
521
wantErr : errors .New ("invalid ingress class: ingressclasses.networking.k8s.io \" awesome-class\" not found" ),
521
522
},
522
523
{
523
- name : "IngressClass exists but IngressClassParams unspecified " ,
524
+ name : "ingress creation with IngressClassName that refers to IngressClass without params " ,
524
525
env : env {
525
526
ingClassList : []* networking.IngressClass {
526
527
{
@@ -544,7 +545,7 @@ func Test_ingressValidator_checkIngressClassUsage(t *testing.T) {
544
545
wantErr : nil ,
545
546
},
546
547
{
547
- name : "IngressClass exists and IngressClassParams exists, and namespaceSelector mismatches " ,
548
+ name : "ingress creation with IngressClassName that refers to IngressClass with IngressClassParams with mismatch namespaceSelector" ,
548
549
env : env {
549
550
nsList : []* corev1.Namespace {
550
551
{
@@ -600,7 +601,7 @@ func Test_ingressValidator_checkIngressClassUsage(t *testing.T) {
600
601
wantErr : errors .New ("invalid ingress class: namespaceSelector of IngressClassParams awesome-class-params mismatch" ),
601
602
},
602
603
{
603
- name : "IngressClass exists and IngressClassParams exists, and namespaceSelector matches" ,
604
+ name : "ingress creation with IngressClassName that refers to IngressClass with IngressClassParams with matches namespaceSelector " ,
604
605
env : env {
605
606
nsList : []* corev1.Namespace {
606
607
{
@@ -651,6 +652,106 @@ func Test_ingressValidator_checkIngressClassUsage(t *testing.T) {
651
652
},
652
653
wantErr : nil ,
653
654
},
655
+ {
656
+ name : "ingress updates with removed IngressClassName" ,
657
+ env : env {},
658
+ args : args {
659
+ ing : & networking.Ingress {
660
+ ObjectMeta : metav1.ObjectMeta {
661
+ Namespace : "awesome-ns" ,
662
+ Name : "awesome-ing" ,
663
+ },
664
+ Spec : networking.IngressSpec {
665
+ IngressClassName : nil ,
666
+ },
667
+ },
668
+ oldIng : & networking.Ingress {
669
+ ObjectMeta : metav1.ObjectMeta {
670
+ Namespace : "awesome-ns" ,
671
+ Name : "awesome-ing" ,
672
+ },
673
+ Spec : networking.IngressSpec {
674
+ IngressClassName : awssdk .String ("awesome-class" ),
675
+ },
676
+ },
677
+ },
678
+ wantErr : nil ,
679
+ },
680
+ {
681
+ name : "ingress updates with changed IngressClassName that refers to non-existent IngressClass" ,
682
+ env : env {},
683
+ args : args {
684
+ ing : & networking.Ingress {
685
+ ObjectMeta : metav1.ObjectMeta {
686
+ Namespace : "awesome-ns" ,
687
+ Name : "awesome-ing" ,
688
+ },
689
+ Spec : networking.IngressSpec {
690
+ IngressClassName : awssdk .String ("awesome-class" ),
691
+ },
692
+ },
693
+ oldIng : & networking.Ingress {
694
+ ObjectMeta : metav1.ObjectMeta {
695
+ Namespace : "awesome-ns" ,
696
+ Name : "awesome-ing" ,
697
+ },
698
+ Spec : networking.IngressSpec {
699
+ IngressClassName : awssdk .String ("old-awesome-class" ),
700
+ },
701
+ },
702
+ },
703
+ wantErr : errors .New ("invalid ingress class: ingressclasses.networking.k8s.io \" awesome-class\" not found" ),
704
+ },
705
+ {
706
+ name : "ingress updates with added IngressClassName that refers to non-existent IngressClass" ,
707
+ env : env {},
708
+ args : args {
709
+ ing : & networking.Ingress {
710
+ ObjectMeta : metav1.ObjectMeta {
711
+ Namespace : "awesome-ns" ,
712
+ Name : "awesome-ing" ,
713
+ },
714
+ Spec : networking.IngressSpec {
715
+ IngressClassName : awssdk .String ("awesome-class" ),
716
+ },
717
+ },
718
+ oldIng : & networking.Ingress {
719
+ ObjectMeta : metav1.ObjectMeta {
720
+ Namespace : "awesome-ns" ,
721
+ Name : "awesome-ing" ,
722
+ },
723
+ Spec : networking.IngressSpec {
724
+ IngressClassName : nil ,
725
+ },
726
+ },
727
+ },
728
+ wantErr : errors .New ("invalid ingress class: ingressclasses.networking.k8s.io \" awesome-class\" not found" ),
729
+ },
730
+ {
731
+ name : "ingress updates with unchanged IngressClassName that refers to non-existent IngressClass" ,
732
+ env : env {},
733
+ args : args {
734
+ ing : & networking.Ingress {
735
+ ObjectMeta : metav1.ObjectMeta {
736
+ Namespace : "awesome-ns" ,
737
+ Name : "awesome-ing" ,
738
+ },
739
+ Spec : networking.IngressSpec {
740
+ IngressClassName : awssdk .String ("awesome-class" ),
741
+ },
742
+ },
743
+ oldIng : & networking.Ingress {
744
+ ObjectMeta : metav1.ObjectMeta {
745
+ Namespace : "awesome-ns" ,
746
+ Name : "awesome-ing" ,
747
+ },
748
+ Spec : networking.IngressSpec {
749
+ IngressClassName : awssdk .String ("awesome-class" ),
750
+ },
751
+ },
752
+ },
753
+ wantErr : nil ,
754
+ },
654
755
}
655
756
for _ , tt := range tests {
656
757
t .Run (tt .name , func (t * testing.T ) {
@@ -675,7 +776,7 @@ func Test_ingressValidator_checkIngressClassUsage(t *testing.T) {
675
776
v := & ingressValidator {
676
777
classLoader : ingress .NewDefaultClassLoader (k8sClient ),
677
778
}
678
- err := v .checkIngressClassUsage (ctx , tt .args .ing )
779
+ err := v .checkIngressClassUsage (ctx , tt .args .ing , tt . args . oldIng )
679
780
if tt .wantErr != nil {
680
781
assert .EqualError (t , err , tt .wantErr .Error ())
681
782
} else {
0 commit comments