@@ -29,6 +29,8 @@ import (
29
29
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
30
30
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31
31
"k8s.io/apimachinery/pkg/types"
32
+ "k8s.io/apimachinery/pkg/util/version"
33
+ utilversion "k8s.io/apiserver/pkg/util/version"
32
34
utilfeature "k8s.io/component-base/featuregate/testing"
33
35
"k8s.io/utils/ptr"
34
36
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -827,7 +829,7 @@ func TestReconciler_reconcileVariables(t *testing.T) {
827
829
},
828
830
XValidations : []clusterv1.ValidationRule {{
829
831
Rule : "true" ,
830
- MessageExpression : "'test error message, got value %s'.format([self])" ,
832
+ MessageExpression : "'test error message, got value %s'.format([self.enabled ])" ,
831
833
FieldPath : ".enabled" ,
832
834
}},
833
835
},
@@ -889,7 +891,7 @@ func TestReconciler_reconcileVariables(t *testing.T) {
889
891
},
890
892
XValidations : []clusterv1.ValidationRule {{
891
893
Rule : "true" ,
892
- MessageExpression : "'test error message, got value %s'.format([self])" ,
894
+ MessageExpression : "'test error message, got value %s'.format([self.enabled ])" ,
893
895
FieldPath : ".enabled" ,
894
896
}},
895
897
},
@@ -1196,6 +1198,17 @@ func TestReconciler_reconcileVariables(t *testing.T) {
1196
1198
RuntimeClient : fakeRuntimeClient ,
1197
1199
}
1198
1200
1201
+ // Pin the compatibility version used in variable CEL validation to 1.29, so we don't have to continuously refactor
1202
+ // the unit tests that verify that compatibility is handled correctly.
1203
+ effectiveVer := utilversion .DefaultComponentGlobalsRegistry .EffectiveVersionFor (utilversion .DefaultKubeComponent )
1204
+ if effectiveVer != nil {
1205
+ g .Expect (effectiveVer .MinCompatibilityVersion ()).To (Equal (version .MustParse ("v1.29" )))
1206
+ } else {
1207
+ v := utilversion .DefaultKubeEffectiveVersion ()
1208
+ v .SetMinCompatibilityVersion (version .MustParse ("v1.29" ))
1209
+ g .Expect (utilversion .DefaultComponentGlobalsRegistry .Register (utilversion .DefaultKubeComponent , v , nil )).To (Succeed ())
1210
+ }
1211
+
1199
1212
err := r .reconcileVariables (ctx , tt .clusterClass )
1200
1213
1201
1214
// Cleanup condition timestamps for easier comparison.
@@ -1204,6 +1217,7 @@ func TestReconciler_reconcileVariables(t *testing.T) {
1204
1217
}
1205
1218
g .Expect (tt .wantConditions ).To (Equal (tt .clusterClass .Status .Conditions ))
1206
1219
if tt .wantErrMessage != "" {
1220
+ g .Expect (err ).To (HaveOccurred ())
1207
1221
g .Expect (err .Error ()).To (Equal (tt .wantErrMessage ))
1208
1222
return
1209
1223
}
0 commit comments