@@ -722,4 +722,235 @@ var _ = Describe("ValuesProvider", func() {
722722 Expect (values ).NotTo (HaveKey ("controller" ))
723723 })
724724 })
725+
726+ Describe ("#isMutatingAdmissionPolicyEnabled" , func () {
727+ var testCluster * extensionscontroller.Cluster
728+
729+ BeforeEach (func () {
730+ calico := "calico"
731+ testCluster = & extensionscontroller.Cluster {
732+ Shoot : & gardencorev1beta1.Shoot {
733+ Spec : gardencorev1beta1.ShootSpec {
734+ Networking : & gardencorev1beta1.Networking {
735+ Type : & calico ,
736+ },
737+ Kubernetes : gardencorev1beta1.Kubernetes {
738+ Version : "1.33.0" ,
739+ },
740+ },
741+ },
742+ }
743+ })
744+
745+ It ("should return false if KubeAPIServer is nil" , func () {
746+ Expect (isMutatingAdmissionPolicyEnabled (testCluster )).To (BeFalse ())
747+ })
748+
749+ It ("should return false if feature gates are nil" , func () {
750+ testCluster .Shoot .Spec .Kubernetes .KubeAPIServer = & gardencorev1beta1.KubeAPIServerConfig {}
751+ Expect (isMutatingAdmissionPolicyEnabled (testCluster )).To (BeFalse ())
752+ })
753+
754+ It ("should return false if MutatingAdmissionPolicy feature gate is not set" , func () {
755+ testCluster .Shoot .Spec .Kubernetes .KubeAPIServer = & gardencorev1beta1.KubeAPIServerConfig {
756+ KubernetesConfig : gardencorev1beta1.KubernetesConfig {
757+ FeatureGates : map [string ]bool {"SomeOtherGate" : true },
758+ },
759+ }
760+ Expect (isMutatingAdmissionPolicyEnabled (testCluster )).To (BeFalse ())
761+ })
762+
763+ It ("should return false if MutatingAdmissionPolicy feature gate is disabled" , func () {
764+ testCluster .Shoot .Spec .Kubernetes .KubeAPIServer = & gardencorev1beta1.KubeAPIServerConfig {
765+ KubernetesConfig : gardencorev1beta1.KubernetesConfig {
766+ FeatureGates : map [string ]bool {"MutatingAdmissionPolicy" : false },
767+ },
768+ }
769+ Expect (isMutatingAdmissionPolicyEnabled (testCluster )).To (BeFalse ())
770+ })
771+
772+ It ("should return false if RuntimeConfig is nil" , func () {
773+ testCluster .Shoot .Spec .Kubernetes .KubeAPIServer = & gardencorev1beta1.KubeAPIServerConfig {
774+ KubernetesConfig : gardencorev1beta1.KubernetesConfig {
775+ FeatureGates : map [string ]bool {"MutatingAdmissionPolicy" : true },
776+ },
777+ }
778+ Expect (isMutatingAdmissionPolicyEnabled (testCluster )).To (BeFalse ())
779+ })
780+
781+ It ("should return false if neither v1alpha1 nor v1beta1 is enabled in RuntimeConfig" , func () {
782+ testCluster .Shoot .Spec .Kubernetes .KubeAPIServer = & gardencorev1beta1.KubeAPIServerConfig {
783+ KubernetesConfig : gardencorev1beta1.KubernetesConfig {
784+ FeatureGates : map [string ]bool {"MutatingAdmissionPolicy" : true },
785+ },
786+ RuntimeConfig : map [string ]bool {"some.other/v1" : true },
787+ }
788+ Expect (isMutatingAdmissionPolicyEnabled (testCluster )).To (BeFalse ())
789+ })
790+
791+ It ("should return true if feature gate is enabled and v1alpha1 is in RuntimeConfig" , func () {
792+ testCluster .Shoot .Spec .Kubernetes .KubeAPIServer = & gardencorev1beta1.KubeAPIServerConfig {
793+ KubernetesConfig : gardencorev1beta1.KubernetesConfig {
794+ FeatureGates : map [string ]bool {"MutatingAdmissionPolicy" : true },
795+ },
796+ RuntimeConfig : map [string ]bool {"admissionregistration.k8s.io/v1alpha1" : true },
797+ }
798+ Expect (isMutatingAdmissionPolicyEnabled (testCluster )).To (BeTrue ())
799+ })
800+
801+ It ("should return true if feature gate is enabled and v1beta1 is in RuntimeConfig" , func () {
802+ testCluster .Shoot .Spec .Kubernetes .KubeAPIServer = & gardencorev1beta1.KubeAPIServerConfig {
803+ KubernetesConfig : gardencorev1beta1.KubernetesConfig {
804+ FeatureGates : map [string ]bool {"MutatingAdmissionPolicy" : true },
805+ },
806+ RuntimeConfig : map [string ]bool {"admissionregistration.k8s.io/v1beta1" : true },
807+ }
808+ Expect (isMutatingAdmissionPolicyEnabled (testCluster )).To (BeTrue ())
809+ })
810+
811+ It ("should return true if feature gate is enabled and both v1alpha1 and v1beta1 are in RuntimeConfig" , func () {
812+ testCluster .Shoot .Spec .Kubernetes .KubeAPIServer = & gardencorev1beta1.KubeAPIServerConfig {
813+ KubernetesConfig : gardencorev1beta1.KubernetesConfig {
814+ FeatureGates : map [string ]bool {"MutatingAdmissionPolicy" : true },
815+ },
816+ RuntimeConfig : map [string ]bool {
817+ "admissionregistration.k8s.io/v1alpha1" : true ,
818+ "admissionregistration.k8s.io/v1beta1" : true ,
819+ },
820+ }
821+ Expect (isMutatingAdmissionPolicyEnabled (testCluster )).To (BeTrue ())
822+ })
823+
824+ It ("should return true for K8s >= 1.34 without any feature gate or RuntimeConfig (beta)" , func () {
825+ testCluster .Shoot .Spec .Kubernetes .Version = "1.34.0"
826+ Expect (isMutatingAdmissionPolicyEnabled (testCluster )).To (BeTrue ())
827+ })
828+
829+ It ("should return true for K8s >= 1.34 even without KubeAPIServer config (beta)" , func () {
830+ testCluster .Shoot .Spec .Kubernetes .Version = "1.35.0"
831+ Expect (isMutatingAdmissionPolicyEnabled (testCluster )).To (BeTrue ())
832+ })
833+
834+ It ("should return false for K8s >= 1.34 and < 1.36 if feature gate is explicitly disabled (beta)" , func () {
835+ testCluster .Shoot .Spec .Kubernetes .Version = "1.34.0"
836+ testCluster .Shoot .Spec .Kubernetes .KubeAPIServer = & gardencorev1beta1.KubeAPIServerConfig {
837+ KubernetesConfig : gardencorev1beta1.KubernetesConfig {
838+ FeatureGates : map [string ]bool {"MutatingAdmissionPolicy" : false },
839+ },
840+ }
841+ Expect (isMutatingAdmissionPolicyEnabled (testCluster )).To (BeFalse ())
842+ })
843+
844+ It ("should return false for K8s 1.35 if feature gate is explicitly disabled (beta)" , func () {
845+ testCluster .Shoot .Spec .Kubernetes .Version = "1.35.0"
846+ testCluster .Shoot .Spec .Kubernetes .KubeAPIServer = & gardencorev1beta1.KubeAPIServerConfig {
847+ KubernetesConfig : gardencorev1beta1.KubernetesConfig {
848+ FeatureGates : map [string ]bool {"MutatingAdmissionPolicy" : false },
849+ },
850+ }
851+ Expect (isMutatingAdmissionPolicyEnabled (testCluster )).To (BeFalse ())
852+ })
853+
854+ It ("should return true for K8s >= 1.36 even if feature gate is explicitly disabled (GA, locked on)" , func () {
855+ testCluster .Shoot .Spec .Kubernetes .Version = "1.36.0"
856+ testCluster .Shoot .Spec .Kubernetes .KubeAPIServer = & gardencorev1beta1.KubeAPIServerConfig {
857+ KubernetesConfig : gardencorev1beta1.KubernetesConfig {
858+ FeatureGates : map [string ]bool {"MutatingAdmissionPolicy" : false },
859+ },
860+ }
861+ Expect (isMutatingAdmissionPolicyEnabled (testCluster )).To (BeTrue ())
862+ })
863+
864+ It ("should return true for K8s >= 1.36 without any feature gate or RuntimeConfig (GA)" , func () {
865+ testCluster .Shoot .Spec .Kubernetes .Version = "1.36.0"
866+ Expect (isMutatingAdmissionPolicyEnabled (testCluster )).To (BeTrue ())
867+ })
868+
869+ It ("should return true for K8s >= 1.36 even without KubeAPIServer config (GA)" , func () {
870+ testCluster .Shoot .Spec .Kubernetes .Version = "1.37.1"
871+ Expect (isMutatingAdmissionPolicyEnabled (testCluster )).To (BeTrue ())
872+ })
873+ })
874+
875+ Describe ("#mutatingAdmissionPolicyAPIVersion" , func () {
876+ var testCluster * extensionscontroller.Cluster
877+
878+ BeforeEach (func () {
879+ testCluster = & extensionscontroller.Cluster {
880+ Shoot : & gardencorev1beta1.Shoot {
881+ Spec : gardencorev1beta1.ShootSpec {
882+ Kubernetes : gardencorev1beta1.Kubernetes {
883+ Version : "1.33.0" ,
884+ },
885+ },
886+ },
887+ }
888+ })
889+
890+ It ("should return v1alpha1 if no RuntimeConfig is set (< 1.34)" , func () {
891+ Expect (mutatingAdmissionPolicyAPIVersion (testCluster )).To (Equal ("v1alpha1" ))
892+ })
893+
894+ It ("should return v1alpha1 if only v1alpha1 is in RuntimeConfig (< 1.34)" , func () {
895+ testCluster .Shoot .Spec .Kubernetes .KubeAPIServer = & gardencorev1beta1.KubeAPIServerConfig {
896+ RuntimeConfig : map [string ]bool {"admissionregistration.k8s.io/v1alpha1" : true },
897+ }
898+ Expect (mutatingAdmissionPolicyAPIVersion (testCluster )).To (Equal ("v1alpha1" ))
899+ })
900+
901+ It ("should return v1beta1 if v1beta1 is in RuntimeConfig (< 1.34)" , func () {
902+ testCluster .Shoot .Spec .Kubernetes .KubeAPIServer = & gardencorev1beta1.KubeAPIServerConfig {
903+ RuntimeConfig : map [string ]bool {"admissionregistration.k8s.io/v1beta1" : true },
904+ }
905+ Expect (mutatingAdmissionPolicyAPIVersion (testCluster )).To (Equal ("v1beta1" ))
906+ })
907+
908+ It ("should return v1beta1 if both v1alpha1 and v1beta1 are in RuntimeConfig (< 1.34)" , func () {
909+ testCluster .Shoot .Spec .Kubernetes .KubeAPIServer = & gardencorev1beta1.KubeAPIServerConfig {
910+ RuntimeConfig : map [string ]bool {
911+ "admissionregistration.k8s.io/v1alpha1" : true ,
912+ "admissionregistration.k8s.io/v1beta1" : true ,
913+ },
914+ }
915+ Expect (mutatingAdmissionPolicyAPIVersion (testCluster )).To (Equal ("v1beta1" ))
916+ })
917+
918+ It ("should return v1alpha1 if v1beta1 is explicitly disabled in RuntimeConfig (< 1.34)" , func () {
919+ testCluster .Shoot .Spec .Kubernetes .KubeAPIServer = & gardencorev1beta1.KubeAPIServerConfig {
920+ RuntimeConfig : map [string ]bool {
921+ "admissionregistration.k8s.io/v1alpha1" : true ,
922+ "admissionregistration.k8s.io/v1beta1" : false ,
923+ },
924+ }
925+ Expect (mutatingAdmissionPolicyAPIVersion (testCluster )).To (Equal ("v1alpha1" ))
926+ })
927+
928+ It ("should return v1beta1 for K8s >= 1.34 (beta)" , func () {
929+ testCluster .Shoot .Spec .Kubernetes .Version = "1.34.0"
930+ Expect (mutatingAdmissionPolicyAPIVersion (testCluster )).To (Equal ("v1beta1" ))
931+ })
932+
933+ It ("should return v1beta1 for K8s 1.35 (beta)" , func () {
934+ testCluster .Shoot .Spec .Kubernetes .Version = "1.35.0"
935+ Expect (mutatingAdmissionPolicyAPIVersion (testCluster )).To (Equal ("v1beta1" ))
936+ })
937+
938+ It ("should return v1 for K8s >= 1.36 (GA)" , func () {
939+ testCluster .Shoot .Spec .Kubernetes .Version = "1.36.0"
940+ Expect (mutatingAdmissionPolicyAPIVersion (testCluster )).To (Equal ("v1" ))
941+ })
942+
943+ It ("should return v1 for K8s 1.36 even if v1beta1 is in RuntimeConfig" , func () {
944+ testCluster .Shoot .Spec .Kubernetes .Version = "1.36.2"
945+ testCluster .Shoot .Spec .Kubernetes .KubeAPIServer = & gardencorev1beta1.KubeAPIServerConfig {
946+ RuntimeConfig : map [string ]bool {"admissionregistration.k8s.io/v1beta1" : true },
947+ }
948+ Expect (mutatingAdmissionPolicyAPIVersion (testCluster )).To (Equal ("v1" ))
949+ })
950+
951+ It ("should return v1 for K8s versions higher than 1.36" , func () {
952+ testCluster .Shoot .Spec .Kubernetes .Version = "1.38.0"
953+ Expect (mutatingAdmissionPolicyAPIVersion (testCluster )).To (Equal ("v1" ))
954+ })
955+ })
725956})
0 commit comments