github.com/openshift/installer@v1.4.17/pkg/types/validation/featuregate_test.go (about) 1 package validation 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 v1 "github.com/openshift/api/config/v1" 9 "github.com/openshift/installer/pkg/types" 10 "github.com/openshift/installer/pkg/types/gcp" 11 "github.com/openshift/installer/pkg/types/vsphere" 12 ) 13 14 func TestFeatureGates(t *testing.T) { 15 cases := []struct { 16 name string 17 installConfig *types.InstallConfig 18 expected string 19 }{ 20 { 21 name: "GCP UserTags is allowed with Feature Gates enabled", 22 installConfig: func() *types.InstallConfig { 23 c := validInstallConfig() 24 c.FeatureSet = v1.TechPreviewNoUpgrade 25 c.GCP = validGCPPlatform() 26 c.GCP.UserTags = []gcp.UserTag{{ParentID: "a", Key: "b", Value: "c"}} 27 return c 28 }(), 29 }, 30 { 31 name: "GCP UserTags is not allowed without Feature Gates", 32 installConfig: func() *types.InstallConfig { 33 c := validInstallConfig() 34 c.GCP = validGCPPlatform() 35 c.GCP.UserTags = []gcp.UserTag{{ParentID: "a", Key: "b", Value: "c"}} 36 return c 37 }(), 38 expected: `^platform.gcp.userTags: Forbidden: this field is protected by the GCPLabelsTags feature gate which must be enabled through either the TechPreviewNoUpgrade or CustomNoUpgrade feature set$`, 39 }, 40 { 41 name: "GCP UserLabels is allowed with Feature Gates enabled", 42 installConfig: func() *types.InstallConfig { 43 c := validInstallConfig() 44 c.FeatureSet = v1.TechPreviewNoUpgrade 45 c.GCP = validGCPPlatform() 46 c.GCP.UserLabels = []gcp.UserLabel{{Key: "a", Value: "b"}} 47 return c 48 }(), 49 }, 50 { 51 name: "GCP UserProvisionedDNS is not allowed without Feature Gates", 52 installConfig: func() *types.InstallConfig { 53 c := validInstallConfig() 54 c.GCP = validGCPPlatform() 55 c.GCP.UserProvisionedDNS = gcp.UserProvisionedDNSEnabled 56 return c 57 }(), 58 expected: `^platform.gcp.userProvisionedDNS: Forbidden: this field is protected by the GCPClusterHostedDNS feature gate which must be enabled through either the TechPreviewNoUpgrade or CustomNoUpgrade feature set$`, 59 }, 60 { 61 name: "GCP UserLabels is not allowed without Feature Gates", 62 installConfig: func() *types.InstallConfig { 63 c := validInstallConfig() 64 c.GCP = validGCPPlatform() 65 c.GCP.UserLabels = []gcp.UserLabel{{Key: "a", Value: "b"}} 66 return c 67 }(), 68 expected: `^platform.gcp.userLabels: Forbidden: this field is protected by the GCPLabelsTags feature gate which must be enabled through either the TechPreviewNoUpgrade or CustomNoUpgrade feature set$`, 69 }, 70 { 71 name: "vSphere hosts is allowed with Feature Gates enabled", 72 installConfig: func() *types.InstallConfig { 73 c := validInstallConfig() 74 c.FeatureSet = v1.Default 75 c.VSphere = validVSpherePlatform() 76 c.VSphere.Hosts = []*vsphere.Host{{Role: "test"}} 77 return c 78 }(), 79 }, 80 { 81 name: "vSphere hosts is allowed with custom Feature Gates", 82 installConfig: func() *types.InstallConfig { 83 c := validInstallConfig() 84 c.FeatureSet = v1.CustomNoUpgrade 85 c.FeatureGates = []string{"VSphereStaticIPs=true"} 86 c.VSphere = validVSpherePlatform() 87 c.VSphere.Hosts = []*vsphere.Host{{Role: "test"}} 88 return c 89 }(), 90 }, 91 { 92 name: "vSphere hosts is not allowed with custom Feature Gate disabled", 93 installConfig: func() *types.InstallConfig { 94 c := validInstallConfig() 95 c.FeatureSet = v1.CustomNoUpgrade 96 c.FeatureGates = []string{"VSphereStaticIPs=false"} 97 c.VSphere = validVSpherePlatform() 98 c.VSphere.Hosts = []*vsphere.Host{{Role: "test"}} 99 return c 100 }(), 101 expected: `^platform.vsphere.hosts: Forbidden: this field is protected by the VSphereStaticIPs feature gate which must be enabled through either the TechPreviewNoUpgrade or CustomNoUpgrade feature set$`, 102 }, 103 { 104 name: "vSphere one vcenter is allowed with default Feature Gates", 105 installConfig: func() *types.InstallConfig { 106 c := validInstallConfig() 107 c.FeatureSet = v1.Default 108 c.VSphere = validVSpherePlatform() 109 c.VSphere.Hosts = []*vsphere.Host{{Role: "test"}} 110 return c 111 }(), 112 }, 113 { 114 name: "vSphere two vcenters is not allowed with Feature Gates disabled", 115 installConfig: func() *types.InstallConfig { 116 c := validInstallConfig() 117 c.FeatureSet = v1.CustomNoUpgrade 118 c.FeatureGates = []string{"VSphereMultiVCenters=false"} 119 c.VSphere = validVSpherePlatform() 120 c.VSphere.VCenters = append(c.VSphere.VCenters, vsphere.VCenter{Server: "additional-vcenter"}) 121 return c 122 }(), 123 expected: `^platform.vsphere.vcenters: Forbidden: this field is protected by the VSphereMultiVCenters feature gate which must be enabled through either the TechPreviewNoUpgrade or CustomNoUpgrade feature set`, 124 }, 125 { 126 name: "vSphere two vcenters is allowed with custom Feature Gate enabled", 127 installConfig: func() *types.InstallConfig { 128 c := validInstallConfig() 129 c.FeatureSet = v1.CustomNoUpgrade 130 c.FeatureGates = []string{"VSphereMultiVCenters=true"} 131 c.VSphere = validVSpherePlatform() 132 c.VSphere.VCenters = append(c.VSphere.VCenters, vsphere.VCenter{Server: "additional-vcenter"}) 133 return c 134 }(), 135 }, 136 { 137 name: "vSphere two vcenters is allowed with TechPreview Feature Set", 138 installConfig: func() *types.InstallConfig { 139 c := validInstallConfig() 140 c.FeatureSet = v1.TechPreviewNoUpgrade 141 c.VSphere = validVSpherePlatform() 142 c.VSphere.VCenters = append(c.VSphere.VCenters, vsphere.VCenter{Server: "Number2"}) 143 return c 144 }(), 145 }, 146 } 147 148 for _, tc := range cases { 149 t.Run(tc.name, func(t *testing.T) { 150 err := ValidateFeatureSet(tc.installConfig).ToAggregate() 151 if tc.expected == "" { 152 assert.NoError(t, err) 153 } else { 154 assert.Regexp(t, tc.expected, err) 155 } 156 }) 157 } 158 }