github.com/openshift/installer@v1.4.17/pkg/asset/imagebased/configimage/installconfig_test.go (about) 1 package configimage 2 3 import ( 4 "testing" 5 6 "github.com/golang/mock/gomock" 7 "github.com/stretchr/testify/assert" 8 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 9 "k8s.io/utils/ptr" 10 11 "github.com/openshift/installer/pkg/asset" 12 "github.com/openshift/installer/pkg/asset/mock" 13 "github.com/openshift/installer/pkg/ipnet" 14 "github.com/openshift/installer/pkg/types" 15 "github.com/openshift/installer/pkg/types/none" 16 ) 17 18 func TestInstallConfigLoad(t *testing.T) { 19 cases := []struct { 20 name string 21 data string 22 fetchError error 23 expectedFound bool 24 expectedError string 25 expectedConfig *types.InstallConfig 26 }{ 27 { 28 name: "unsupported platform", 29 data: ` 30 apiVersion: v1 31 metadata: 32 name: test-cluster 33 baseDomain: test-domain 34 networking: 35 networkType: OVNKubernetes 36 controlPlane: 37 architecture: amd64 38 hyperthreading: Enabled 39 name: master 40 platform: {} 41 replicas: 1 42 compute: 43 - architecture: amd64 44 hyperthreading: Enabled 45 name: worker 46 platform: {} 47 replicas: 0 48 platform: 49 aws: 50 region: us-east-1 51 pullSecret: "{\"auths\":{\"example.com\":{\"auth\":\"c3VwZXItc2VjcmV0Cg==\"}}}" 52 `, 53 expectedFound: false, 54 expectedError: `invalid install-config configuration: Platform: Unsupported value: "aws": supported values: "none"`, 55 }, 56 { 57 name: "no compute.replicas set for SNO", 58 data: ` 59 apiVersion: v1 60 metadata: 61 name: test-cluster 62 baseDomain: test-domain 63 networking: 64 networkType: OVNKubernetes 65 controlPlane: 66 architecture: amd64 67 hyperthreading: Enabled 68 name: master 69 platform: {} 70 replicas: 1 71 platform: 72 none : {} 73 pullSecret: "{\"auths\":{\"example.com\":{\"auth\":\"c3VwZXItc2VjcmV0Cg==\"}}}" 74 `, 75 expectedFound: false, 76 expectedError: "invalid install-config configuration: Compute.Replicas: Required value: Total number of Compute.Replicas must be 0 when ControlPlane.Replicas is 1 for platform none. Found 3", 77 }, 78 { 79 name: "incorrect controlplane.replicas set", 80 data: ` 81 apiVersion: v1 82 metadata: 83 name: test-cluster 84 baseDomain: test-domain 85 networking: 86 networkType: OVNKubernetes 87 controlPlane: 88 architecture: amd64 89 hyperthreading: Enabled 90 name: master 91 platform: {} 92 replicas: 2 93 compute: 94 - architecture: amd64 95 hyperthreading: Enabled 96 name: worker 97 platform: {} 98 replicas: 0 99 platform: 100 none : {} 101 pullSecret: "{\"auths\":{\"example.com\":{\"auth\":\"authorization value\"}}}" 102 `, 103 expectedFound: false, 104 expectedError: "invalid install-config configuration: ControlPlane.Replicas: Required value: Only Single Node OpenShift (SNO) is supported, total number of ControlPlane.Replicas must be 1. Found 2", 105 }, 106 { 107 name: "invalid number of MachineNetworks", 108 data: ` 109 apiVersion: v1 110 metadata: 111 name: test-cluster 112 baseDomain: test-domain 113 networking: 114 networkType: OVNKubernetes 115 machineNetwork: 116 - cidr: 10.0.0.0/16 117 - cidr: 10.10.0.0/24 118 controlPlane: 119 architecture: amd64 120 hyperthreading: Enabled 121 name: master 122 platform: {} 123 replicas: 1 124 compute: 125 - architecture: amd64 126 hyperthreading: Enabled 127 name: worker 128 platform: {} 129 replicas: 0 130 platform: 131 none : {} 132 pullSecret: "{\"auths\":{\"example.com\":{\"auth\":\"authorization value\"}}}" 133 `, 134 expectedFound: false, 135 expectedError: "invalid install-config configuration: Networking.MachineNetwork: Too many: 2: must have at most 1 items", 136 }, 137 { 138 name: "valid configuration for none platform for sno", 139 data: ` 140 apiVersion: v1 141 metadata: 142 name: test-cluster 143 baseDomain: test-domain 144 networking: 145 networkType: OVNKubernetes 146 compute: 147 - architecture: amd64 148 hyperthreading: Enabled 149 name: worker 150 platform: {} 151 replicas: 0 152 controlPlane: 153 architecture: amd64 154 hyperthreading: Enabled 155 name: master 156 platform: {} 157 replicas: 1 158 platform: 159 none : {} 160 pullSecret: "{\"auths\":{\"example.com\":{\"auth\":\"c3VwZXItc2VjcmV0Cg==\"}}}" 161 `, 162 expectedFound: true, 163 expectedConfig: &types.InstallConfig{ 164 TypeMeta: metav1.TypeMeta{ 165 APIVersion: types.InstallConfigVersion, 166 }, 167 ObjectMeta: metav1.ObjectMeta{ 168 Name: "test-cluster", 169 }, 170 AdditionalTrustBundlePolicy: types.PolicyProxyOnly, 171 BaseDomain: "test-domain", 172 Networking: &types.Networking{ 173 MachineNetwork: []types.MachineNetworkEntry{ 174 {CIDR: *ipnet.MustParseCIDR("10.0.0.0/16")}, 175 }, 176 NetworkType: "OVNKubernetes", 177 ServiceNetwork: []ipnet.IPNet{*ipnet.MustParseCIDR("172.30.0.0/16")}, 178 ClusterNetwork: []types.ClusterNetworkEntry{ 179 { 180 CIDR: *ipnet.MustParseCIDR("10.128.0.0/14"), 181 HostPrefix: 23, 182 }, 183 }, 184 }, 185 ControlPlane: &types.MachinePool{ 186 Name: "master", 187 Replicas: ptr.To[int64](1), 188 Hyperthreading: types.HyperthreadingEnabled, 189 Architecture: types.ArchitectureAMD64, 190 }, 191 Compute: []types.MachinePool{ 192 { 193 Name: "worker", 194 Replicas: ptr.To[int64](0), 195 Hyperthreading: types.HyperthreadingEnabled, 196 Architecture: types.ArchitectureAMD64, 197 }, 198 }, 199 Platform: types.Platform{None: &none.Platform{}}, 200 PullSecret: `{"auths":{"example.com":{"auth":"c3VwZXItc2VjcmV0Cg=="}}}`, 201 Publish: types.ExternalPublishingStrategy, 202 }, 203 }, 204 } 205 for _, tc := range cases { 206 t.Run(tc.name, func(t *testing.T) { 207 mockCtrl := gomock.NewController(t) 208 defer mockCtrl.Finish() 209 210 fileFetcher := mock.NewMockFileFetcher(mockCtrl) 211 fileFetcher.EXPECT().FetchByName(InstallConfigFilename). 212 Return( 213 &asset.File{ 214 Filename: InstallConfigFilename, 215 Data: []byte(tc.data)}, 216 tc.fetchError, 217 ).MaxTimes(2) 218 219 asset := &InstallConfig{} 220 found, err := asset.Load(fileFetcher) 221 assert.Equal(t, tc.expectedFound, found, "unexpected found value returned from Load") 222 if tc.expectedError != "" { 223 assert.Equal(t, tc.expectedError, err.Error()) 224 } else { 225 assert.NoError(t, err) 226 } 227 if tc.expectedFound { 228 assert.Equal(t, tc.expectedConfig, asset.Config, "unexpected Config in InstallConfig") 229 } 230 }) 231 } 232 }