@@ -516,6 +516,54 @@ k8sServicePort: "{{ .ControlPlaneEndpoint.Port }}"
516516 expectedMessage := "kube-proxy is disabled, but Cilium ConfigMap test-namespace/cilium-values does not have 'kubeProxyReplacement' enabled"
517517 Expect (resp .Result .Message ).To (Equal (expectedMessage ))
518518 })
519+
520+ It ("should error out when ConfigMap uses unknown templated values" , func () {
521+ cni := & v1alpha1.CNI {
522+ Provider : v1alpha1 .CNIProviderCilium ,
523+ AddonConfig : v1alpha1.AddonConfig {
524+ Values : & v1alpha1.AddonValues {
525+ SourceRef : & v1alpha1.ValuesReference {
526+ Kind : "ConfigMap" ,
527+ Name : "cilium-values" ,
528+ },
529+ },
530+ },
531+ }
532+ cluster := createTestClusterWithControlPlaneEndpoint (
533+ "test-cluster" ,
534+ "test-namespace" ,
535+ v1alpha1 .KubeProxyModeDisabled ,
536+ cni ,
537+ "192.168.1.100" ,
538+ 6443 ,
539+ )
540+ req := createAdmissionRequest (cluster )
541+
542+ // Create ConfigMap with unknown template field
543+ configMap := & corev1.ConfigMap {
544+ ObjectMeta : metav1.ObjectMeta {
545+ Name : "cilium-values" ,
546+ Namespace : "test-namespace" ,
547+ },
548+ Data : map [string ]string {
549+ "values.yaml" : `
550+ ipam:
551+ mode: kubernetes
552+ kubeProxyReplacement: true
553+ k8sServiceHost: "{{ .UnknownField.Host }}"
554+ k8sServicePort: "{{ .ControlPlaneEndpoint.Port }}"
555+ ` ,
556+ },
557+ }
558+
559+ client := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (configMap ).Build ()
560+ validator = NewAdvancedCiliumConfigurationValidator (client , decoder )
561+
562+ resp := validator .validate (context .Background (), req )
563+ Expect (resp .Allowed ).To (BeFalse ())
564+ Expect (resp .Result .Message ).To (ContainSubstring ("failed templating values" ))
565+ Expect (resp .Result .Message ).To (ContainSubstring ("can't evaluate field UnknownField" ))
566+ })
519567 })
520568})
521569
0 commit comments