@@ -230,6 +230,18 @@ func TestValidateAgainstClass(t *testing.T) {
230230 },
231231 }
232232
233+ classWithMinorVersion := & enterpriseApi.PostgresClusterClass {
234+ ObjectMeta : metav1.ObjectMeta {Name : "prod-pinned" },
235+ Spec : enterpriseApi.PostgresClusterClassSpec {
236+ Provisioner : "postgresql.cnpg.io" ,
237+ Config : & enterpriseApi.PostgresClusterClassConfig {
238+ Instances : ptrInt32 (3 ),
239+ Storage : ptrQuantity ("50Gi" ),
240+ PostgresVersion : ptrString ("17.2" ),
241+ },
242+ },
243+ }
244+
233245 classWithPoolerEnabled := & enterpriseApi.PostgresClusterClass {
234246 ObjectMeta : metav1.ObjectMeta {Name : "pooler-class" },
235247 Spec : enterpriseApi.PostgresClusterClassSpec {
@@ -336,16 +348,84 @@ func TestValidateAgainstClass(t *testing.T) {
336348 wantErrField : "spec.postgresVersion" ,
337349 },
338350 {
339- name : "valid - minor version higher" ,
351+ name : "valid - minor version ignored when class has major only" ,
352+ class : classWithDefaults ,
353+ obj : & enterpriseApi.PostgresCluster {
354+ Spec : enterpriseApi.PostgresClusterSpec {
355+ Class : "prod" ,
356+ PostgresVersion : ptrString ("17.2" ),
357+ },
358+ },
359+ wantErrCount : 0 ,
360+ },
361+ {
362+ name : "valid - lower minor ignored when class has major only" ,
340363 class : classWithDefaults ,
341364 obj : & enterpriseApi.PostgresCluster {
342365 Spec : enterpriseApi.PostgresClusterSpec {
343366 Class : "prod" ,
367+ PostgresVersion : ptrString ("17.0" ),
368+ },
369+ },
370+ wantErrCount : 0 ,
371+ },
372+ {
373+ name : "valid - cluster minor equal to class minor" ,
374+ class : classWithMinorVersion ,
375+ obj : & enterpriseApi.PostgresCluster {
376+ Spec : enterpriseApi.PostgresClusterSpec {
377+ Class : "prod-pinned" ,
344378 PostgresVersion : ptrString ("17.2" ),
345379 },
346380 },
347381 wantErrCount : 0 ,
348382 },
383+ {
384+ name : "valid - cluster minor higher than class minor" ,
385+ class : classWithMinorVersion ,
386+ obj : & enterpriseApi.PostgresCluster {
387+ Spec : enterpriseApi.PostgresClusterSpec {
388+ Class : "prod-pinned" ,
389+ PostgresVersion : ptrString ("17.5" ),
390+ },
391+ },
392+ wantErrCount : 0 ,
393+ },
394+ {
395+ name : "invalid - cluster minor lower than class minor" ,
396+ class : classWithMinorVersion ,
397+ obj : & enterpriseApi.PostgresCluster {
398+ Spec : enterpriseApi.PostgresClusterSpec {
399+ Class : "prod-pinned" ,
400+ PostgresVersion : ptrString ("17.1" ),
401+ },
402+ },
403+ wantErrCount : 1 ,
404+ wantErrField : "spec.postgresVersion" ,
405+ },
406+ {
407+ name : "invalid - cluster major lower even with higher minor" ,
408+ class : classWithMinorVersion ,
409+ obj : & enterpriseApi.PostgresCluster {
410+ Spec : enterpriseApi.PostgresClusterSpec {
411+ Class : "prod-pinned" ,
412+ PostgresVersion : ptrString ("16.9" ),
413+ },
414+ },
415+ wantErrCount : 1 ,
416+ wantErrField : "spec.postgresVersion" ,
417+ },
418+ {
419+ name : "valid - cluster major higher than class with minor" ,
420+ class : classWithMinorVersion ,
421+ obj : & enterpriseApi.PostgresCluster {
422+ Spec : enterpriseApi.PostgresClusterSpec {
423+ Class : "prod-pinned" ,
424+ PostgresVersion : ptrString ("18" ),
425+ },
426+ },
427+ wantErrCount : 0 ,
428+ },
349429 {
350430 name : "invalid - connection pooler enabled when class disables" ,
351431 class : classWithDefaults ,
0 commit comments