github.com/openshift/installer@v1.4.17/pkg/asset/agent/manifests/agentclusterinstall_test.go (about)

     1  package manifests
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/golang/mock/gomock"
     9  	"github.com/pkg/errors"
    10  	"github.com/stretchr/testify/assert"
    11  	corev1 "k8s.io/api/core/v1"
    12  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    13  	"k8s.io/apimachinery/pkg/util/yaml"
    14  
    15  	configv1 "github.com/openshift/api/config/v1"
    16  	hiveext "github.com/openshift/assisted-service/api/hiveextension/v1beta1"
    17  	"github.com/openshift/assisted-service/models"
    18  	hivev1 "github.com/openshift/hive/apis/hive/v1"
    19  	"github.com/openshift/installer/pkg/asset"
    20  	"github.com/openshift/installer/pkg/asset/agent"
    21  	"github.com/openshift/installer/pkg/asset/agent/agentconfig"
    22  	"github.com/openshift/installer/pkg/asset/agent/workflow"
    23  	"github.com/openshift/installer/pkg/asset/mock"
    24  	"github.com/openshift/installer/pkg/types"
    25  	externaltype "github.com/openshift/installer/pkg/types/external"
    26  )
    27  
    28  func TestAgentClusterInstall_Generate(t *testing.T) {
    29  
    30  	installConfigWithoutNetworkType := getValidOptionalInstallConfig()
    31  	installConfigWithoutNetworkType.Config.NetworkType = ""
    32  
    33  	installConfigWithFIPS := getValidOptionalInstallConfig()
    34  	installConfigWithFIPS.Config.FIPS = true
    35  
    36  	goodACI := getGoodACI()
    37  	goodFIPSACI := getGoodACI()
    38  	goodFIPSACI.SetAnnotations(map[string]string{
    39  		installConfigOverrides: `{"fips":true}`,
    40  	})
    41  
    42  	installConfigWithProxy := getValidOptionalInstallConfig()
    43  	installConfigWithProxy.Config.Proxy = (*types.Proxy)(getProxy(getProxyValidOptionalInstallConfig().Config.Proxy))
    44  
    45  	goodProxyACI := getGoodACI()
    46  	goodProxyACI.Spec.Proxy = (*hiveext.Proxy)(getProxy(getProxyValidOptionalInstallConfig().Config.Proxy))
    47  
    48  	goodACIDualStackVIPs := getGoodACIDualStack()
    49  	goodACIDualStackVIPs.Spec.APIVIPs = []string{"192.168.122.10", "2001:db8:1111:2222:ffff:ffff:ffff:cafe"}
    50  	goodACIDualStackVIPs.Spec.IngressVIPs = []string{"192.168.122.11", "2001:db8:1111:2222:ffff:ffff:ffff:dead"}
    51  
    52  	installConfigWithCapabilities := getValidOptionalInstallConfig()
    53  	installConfigWithCapabilities.Config.Capabilities = &types.Capabilities{
    54  		BaselineCapabilitySet: configv1.ClusterVersionCapabilitySetNone,
    55  		AdditionalEnabledCapabilities: []configv1.ClusterVersionCapability{
    56  			configv1.ClusterVersionCapabilityMarketplace,
    57  		},
    58  	}
    59  
    60  	goodCapabilitiesACI := getGoodACI()
    61  	goodCapabilitiesACI.SetAnnotations(map[string]string{
    62  		installConfigOverrides: `{"capabilities":{"baselineCapabilitySet":"None","additionalEnabledCapabilities":["marketplace"]}}`,
    63  	})
    64  
    65  	installConfigWithNetworkOverride := getValidOptionalInstallConfig()
    66  	installConfigWithNetworkOverride.Config.Networking.NetworkType = "CustomNetworkType"
    67  
    68  	goodNetworkOverrideACI := getGoodACI()
    69  	goodNetworkOverrideACI.SetAnnotations(map[string]string{
    70  		installConfigOverrides: `{"networking":{"networkType":"CustomNetworkType","machineNetwork":[{"cidr":"10.10.11.0/24"}],"clusterNetwork":[{"cidr":"192.168.111.0/24","hostPrefix":23}],"serviceNetwork":["172.30.0.0/16"]}}`,
    71  	})
    72  
    73  	installConfigWithCPUPartitioning := getValidOptionalInstallConfig()
    74  	installConfigWithCPUPartitioning.Config.CPUPartitioning = types.CPUPartitioningAllNodes
    75  
    76  	goodCPUPartitioningACI := getGoodACI()
    77  	goodCPUPartitioningACI.SetAnnotations(map[string]string{
    78  		installConfigOverrides: `{"cpuPartitioningMode":"AllNodes"}`,
    79  	})
    80  
    81  	installConfigWExternalPlatform := getValidOptionalInstallConfig()
    82  	installConfigWExternalPlatform.Config.Platform = types.Platform{
    83  		External: &externaltype.Platform{
    84  			PlatformName:           "external",
    85  			CloudControllerManager: "",
    86  		},
    87  	}
    88  
    89  	goodExternalPlatformACI := getGoodACI()
    90  	goodExternalPlatformACI.Spec.APIVIPs = nil
    91  	goodExternalPlatformACI.Spec.IngressVIPs = nil
    92  	goodExternalPlatformACI.Spec.APIVIP = ""
    93  	goodExternalPlatformACI.Spec.IngressVIP = ""
    94  	val := true
    95  	goodExternalPlatformACI.Spec.Networking.UserManagedNetworking = &val
    96  	goodExternalPlatformACI.Spec.PlatformType = hiveext.ExternalPlatformType
    97  	goodExternalPlatformACI.Spec.ExternalPlatformSpec = &hiveext.ExternalPlatformSpec{
    98  		PlatformName: "external",
    99  	}
   100  	goodExternalPlatformACI.SetAnnotations(map[string]string{
   101  		installConfigOverrides: `{"platform":{"external":{"platformName":"external"}}}`,
   102  	})
   103  
   104  	installConfigWExternalOCIPlatform := getValidOptionalInstallConfig()
   105  	installConfigWExternalOCIPlatform.Config.Platform = types.Platform{
   106  		External: &externaltype.Platform{
   107  			PlatformName:           string(models.PlatformTypeOci),
   108  			CloudControllerManager: externaltype.CloudControllerManagerTypeExternal,
   109  		},
   110  	}
   111  
   112  	goodExternalOCIPlatformACI := getGoodACI()
   113  	val = true
   114  	goodExternalOCIPlatformACI.Spec.APIVIPs = nil
   115  	goodExternalOCIPlatformACI.Spec.IngressVIPs = nil
   116  	goodExternalOCIPlatformACI.Spec.APIVIP = ""
   117  	goodExternalOCIPlatformACI.Spec.IngressVIP = ""
   118  	goodExternalOCIPlatformACI.Spec.Networking.UserManagedNetworking = &val
   119  	goodExternalOCIPlatformACI.Spec.PlatformType = hiveext.ExternalPlatformType
   120  	goodExternalOCIPlatformACI.Spec.ExternalPlatformSpec = &hiveext.ExternalPlatformSpec{
   121  		PlatformName: string(models.PlatformTypeOci),
   122  	}
   123  	goodExternalOCIPlatformACI.SetAnnotations(map[string]string{
   124  		installConfigOverrides: `{"platform":{"external":{"platformName":"oci","cloudControllerManager":"External"}}}`,
   125  	})
   126  
   127  	goodBaremetalPlatformBMCACI := getGoodACI()
   128  	goodBaremetalPlatformBMCACI.SetAnnotations(map[string]string{
   129  		installConfigOverrides: `{"platform":{"baremetal":{"hosts":[{"name":"control-0.example.org","bmc":{"username":"bmc-user","password":"password","address":"172.22.0.10","disableCertificateVerification":true},"role":"master","bootMACAddress":"98:af:65:a5:8d:01","hardwareProfile":""},{"name":"control-1.example.org","bmc":{"username":"user2","password":"foo","address":"172.22.0.11","disableCertificateVerification":false},"role":"master","bootMACAddress":"98:af:65:a5:8d:02","hardwareProfile":""},{"name":"control-2.example.org","bmc":{"username":"admin","password":"bar","address":"172.22.0.12","disableCertificateVerification":true},"role":"master","bootMACAddress":"98:af:65:a5:8d:03","hardwareProfile":""}],"clusterProvisioningIP":"172.22.0.3","provisioningNetwork":"Managed","provisioningNetworkInterface":"eth0","provisioningNetworkCIDR":"172.22.0.0/24","provisioningDHCPRange":"172.22.0.10,172.22.0.254"}}}`,
   130  	})
   131  
   132  	cases := []struct {
   133  		name           string
   134  		dependencies   []asset.Asset
   135  		expectedError  string
   136  		expectedConfig *hiveext.AgentClusterInstall
   137  	}{
   138  		{
   139  			name: "missing install config",
   140  			dependencies: []asset.Asset{
   141  				&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
   142  				&agent.OptionalInstallConfig{},
   143  				&agentconfig.AgentHosts{},
   144  			},
   145  			expectedError: "missing configuration or manifest file",
   146  		},
   147  		{
   148  			name: "valid configuration",
   149  			dependencies: []asset.Asset{
   150  				&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
   151  				getValidOptionalInstallConfig(),
   152  				&agentconfig.AgentHosts{},
   153  			},
   154  			expectedConfig: goodACI,
   155  		},
   156  		{
   157  			name: "valid configuration with unspecified network type should result with ACI having default network type",
   158  			dependencies: []asset.Asset{
   159  				&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
   160  				installConfigWithoutNetworkType,
   161  				&agentconfig.AgentHosts{},
   162  			},
   163  			expectedConfig: goodACI,
   164  		},
   165  		{
   166  			name: "valid configuration with FIPS annotation",
   167  			dependencies: []asset.Asset{
   168  				&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
   169  				installConfigWithFIPS,
   170  				&agentconfig.AgentHosts{},
   171  			},
   172  			expectedConfig: goodFIPSACI,
   173  		},
   174  		{
   175  			name: "valid configuration with proxy",
   176  			dependencies: []asset.Asset{
   177  				&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
   178  				installConfigWithProxy,
   179  				&agentconfig.AgentHosts{},
   180  			},
   181  			expectedConfig: goodProxyACI,
   182  		},
   183  		{
   184  			name: "valid configuration dual stack",
   185  			dependencies: []asset.Asset{
   186  				&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
   187  				getValidOptionalInstallConfigDualStack(),
   188  				&agentconfig.AgentHosts{},
   189  			},
   190  			expectedConfig: getGoodACIDualStack(),
   191  		},
   192  		{
   193  			name: "valid configuration dual stack dual vips",
   194  			dependencies: []asset.Asset{
   195  				&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
   196  				getValidOptionalInstallConfigDualStackDualVIPs(),
   197  				&agentconfig.AgentHosts{},
   198  			},
   199  			expectedConfig: goodACIDualStackVIPs,
   200  		},
   201  		{
   202  			name: "valid configuration with capabilities",
   203  			dependencies: []asset.Asset{
   204  				&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
   205  				installConfigWithCapabilities,
   206  				&agentconfig.AgentHosts{},
   207  			},
   208  			expectedConfig: goodCapabilitiesACI,
   209  		},
   210  		{
   211  			name: "valid configuration with custom network type",
   212  			dependencies: []asset.Asset{
   213  				&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
   214  				installConfigWithNetworkOverride,
   215  				&agentconfig.AgentHosts{},
   216  			},
   217  			expectedConfig: goodNetworkOverrideACI,
   218  		},
   219  		{
   220  			name: "valid configuration with CPU Partitioning",
   221  			dependencies: []asset.Asset{
   222  				&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
   223  				installConfigWithCPUPartitioning,
   224  				&agentconfig.AgentHosts{},
   225  			},
   226  			expectedConfig: goodCPUPartitioningACI,
   227  		},
   228  		{
   229  			name: "valid configuration external generic platform",
   230  			dependencies: []asset.Asset{
   231  				&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
   232  				installConfigWExternalPlatform,
   233  				&agentconfig.AgentHosts{},
   234  			},
   235  			expectedConfig: goodExternalPlatformACI,
   236  		},
   237  		{
   238  			name: "valid configuration external OCI platform",
   239  			dependencies: []asset.Asset{
   240  				&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
   241  				installConfigWExternalOCIPlatform,
   242  				&agentconfig.AgentHosts{},
   243  			},
   244  			expectedConfig: goodExternalOCIPlatformACI,
   245  		},
   246  		{
   247  			name: "valid configuration BMC and provisioning network",
   248  			dependencies: []asset.Asset{
   249  				&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
   250  				getValidOptionalInstallConfigWithProvisioning(),
   251  				getAgentHostsWithBMCConfig(),
   252  			},
   253  			expectedConfig: goodBaremetalPlatformBMCACI,
   254  		},
   255  	}
   256  	for _, tc := range cases {
   257  		t.Run(tc.name, func(t *testing.T) {
   258  
   259  			parents := asset.Parents{}
   260  			parents.Add(tc.dependencies...)
   261  
   262  			asset := &AgentClusterInstall{}
   263  			err := asset.Generate(context.Background(), parents)
   264  
   265  			if tc.expectedError != "" {
   266  				assert.Equal(t, tc.expectedError, err.Error())
   267  			} else {
   268  				assert.NoError(t, err)
   269  				assert.Equal(t, tc.expectedConfig, asset.Config)
   270  				assert.NotEmpty(t, asset.Files())
   271  
   272  				configFile := asset.Files()[0]
   273  				assert.Equal(t, "cluster-manifests/agent-cluster-install.yaml", configFile.Filename)
   274  
   275  				var actualConfig hiveext.AgentClusterInstall
   276  				err = yaml.Unmarshal(configFile.Data, &actualConfig)
   277  				assert.NoError(t, err)
   278  				assert.Equal(t, *tc.expectedConfig, actualConfig)
   279  			}
   280  		})
   281  	}
   282  }
   283  
   284  func TestAgentClusterInstall_LoadedFromDisk(t *testing.T) {
   285  
   286  	emptyACI := &hiveext.AgentClusterInstall{}
   287  	emptyACI.Spec.Networking.NetworkType = "OVNKubernetes"
   288  
   289  	cases := []struct {
   290  		name           string
   291  		data           string
   292  		fetchError     error
   293  		expectedFound  bool
   294  		expectedError  string
   295  		expectedConfig *hiveext.AgentClusterInstall
   296  	}{
   297  		{
   298  			name: "valid-config-file",
   299  			data: `
   300  metadata:
   301    name: test-agent-cluster-install
   302    namespace: cluster0
   303  spec:
   304    apiVIP: 192.168.111.5
   305    ingressVIP: 192.168.111.4
   306    platformType: BareMetal
   307    clusterDeploymentRef:
   308      name: ostest
   309    imageSetRef:
   310      name: openshift-v4.10.0
   311    networking:
   312      machineNetwork:
   313      - cidr: 10.10.11.0/24
   314      clusterNetwork:
   315      - cidr: 10.128.0.0/14
   316        hostPrefix: 23
   317      serviceNetwork:
   318      - 172.30.0.0/16
   319      networkType: OVNKubernetes
   320    provisionRequirements:
   321      controlPlaneAgents: 3
   322      workerAgents: 2
   323    sshPublicKey: |
   324      ssh-rsa AAAAmyKey`,
   325  			expectedFound: true,
   326  			expectedConfig: &hiveext.AgentClusterInstall{
   327  				ObjectMeta: metav1.ObjectMeta{
   328  					Name:      "test-agent-cluster-install",
   329  					Namespace: "cluster0",
   330  				},
   331  				Spec: hiveext.AgentClusterInstallSpec{
   332  					APIVIP:       "192.168.111.5",
   333  					IngressVIP:   "192.168.111.4",
   334  					PlatformType: hiveext.BareMetalPlatformType,
   335  					ClusterDeploymentRef: corev1.LocalObjectReference{
   336  						Name: "ostest",
   337  					},
   338  					ImageSetRef: &hivev1.ClusterImageSetReference{
   339  						Name: "openshift-v4.10.0",
   340  					},
   341  					Networking: hiveext.Networking{
   342  						MachineNetwork: []hiveext.MachineNetworkEntry{
   343  							{
   344  								CIDR: "10.10.11.0/24",
   345  							},
   346  						},
   347  						ClusterNetwork: []hiveext.ClusterNetworkEntry{
   348  							{
   349  								CIDR:       "10.128.0.0/14",
   350  								HostPrefix: 23,
   351  							},
   352  						},
   353  						ServiceNetwork: []string{
   354  							"172.30.0.0/16",
   355  						},
   356  						NetworkType: "OVNKubernetes",
   357  					},
   358  					ProvisionRequirements: hiveext.ProvisionRequirements{
   359  						ControlPlaneAgents: 3,
   360  						WorkerAgents:       2,
   361  					},
   362  					SSHPublicKey: "ssh-rsa AAAAmyKey",
   363  				},
   364  			},
   365  			expectedError: "",
   366  		},
   367  		{
   368  			name: "valid-config-file-external-oci-platform",
   369  			data: `
   370  metadata:
   371    name: test-agent-cluster-install
   372    namespace: cluster0
   373  spec:
   374    platformType: External
   375    external:
   376      platformName: oci
   377    apiVIP: 192.168.111.5
   378    ingressVIP: 192.168.111.4
   379    clusterDeploymentRef:
   380      name: ostest
   381    imageSetRef:
   382      name: openshift-v4.14.0
   383    networking:
   384      machineNetwork:
   385      - cidr: 10.10.11.0/24
   386      clusterNetwork:
   387      - cidr: 10.128.0.0/14
   388        hostPrefix: 23
   389      serviceNetwork:
   390      - 172.30.0.0/16
   391      networkType: OVNKubernetes
   392    provisionRequirements:
   393      controlPlaneAgents: 3
   394      workerAgents: 2
   395    sshPublicKey: |
   396      ssh-rsa AAAAmyKey`,
   397  			expectedFound: true,
   398  			expectedConfig: &hiveext.AgentClusterInstall{
   399  				ObjectMeta: metav1.ObjectMeta{
   400  					Name:      "test-agent-cluster-install",
   401  					Namespace: "cluster0",
   402  				},
   403  				Spec: hiveext.AgentClusterInstallSpec{
   404  					APIVIP:       "192.168.111.5",
   405  					IngressVIP:   "192.168.111.4",
   406  					PlatformType: hiveext.ExternalPlatformType,
   407  					ExternalPlatformSpec: &hiveext.ExternalPlatformSpec{
   408  						PlatformName: string(models.PlatformTypeOci),
   409  					},
   410  					ClusterDeploymentRef: corev1.LocalObjectReference{
   411  						Name: "ostest",
   412  					},
   413  					ImageSetRef: &hivev1.ClusterImageSetReference{
   414  						Name: "openshift-v4.14.0",
   415  					},
   416  					Networking: hiveext.Networking{
   417  						MachineNetwork: []hiveext.MachineNetworkEntry{
   418  							{
   419  								CIDR: "10.10.11.0/24",
   420  							},
   421  						},
   422  						ClusterNetwork: []hiveext.ClusterNetworkEntry{
   423  							{
   424  								CIDR:       "10.128.0.0/14",
   425  								HostPrefix: 23,
   426  							},
   427  						},
   428  						ServiceNetwork: []string{
   429  							"172.30.0.0/16",
   430  						},
   431  						NetworkType:           "OVNKubernetes",
   432  						UserManagedNetworking: func(b bool) *bool { return &b }(true),
   433  					},
   434  					ProvisionRequirements: hiveext.ProvisionRequirements{
   435  						ControlPlaneAgents: 3,
   436  						WorkerAgents:       2,
   437  					},
   438  					SSHPublicKey: "ssh-rsa AAAAmyKey",
   439  				},
   440  			},
   441  			expectedError: "",
   442  		},
   443  		{
   444  			name: "lowercase-platform-type-backwards-compat",
   445  			data: `
   446  metadata:
   447    name: test-agent-cluster-install
   448    namespace: cluster0
   449  spec:
   450    apiVIP: 192.168.111.5
   451    ingressVIP: 192.168.111.4
   452    platformType: baremetal
   453    clusterDeploymentRef:
   454      name: ostest
   455    imageSetRef:
   456      name: openshift-v4.10.0
   457    networking:
   458      machineNetwork:
   459      - cidr: 10.10.11.0/24
   460      clusterNetwork:
   461      - cidr: 10.128.0.0/14
   462        hostPrefix: 23
   463      serviceNetwork:
   464      - 172.30.0.0/16
   465      networkType: OVNKubernetes
   466    provisionRequirements:
   467      controlPlaneAgents: 3
   468      workerAgents: 2
   469    sshPublicKey: |
   470      ssh-rsa AAAAmyKey`,
   471  			expectedFound: true,
   472  			expectedConfig: &hiveext.AgentClusterInstall{
   473  				ObjectMeta: metav1.ObjectMeta{
   474  					Name:      "test-agent-cluster-install",
   475  					Namespace: "cluster0",
   476  				},
   477  				Spec: hiveext.AgentClusterInstallSpec{
   478  					APIVIP:       "192.168.111.5",
   479  					IngressVIP:   "192.168.111.4",
   480  					PlatformType: hiveext.BareMetalPlatformType,
   481  					ClusterDeploymentRef: corev1.LocalObjectReference{
   482  						Name: "ostest",
   483  					},
   484  					ImageSetRef: &hivev1.ClusterImageSetReference{
   485  						Name: "openshift-v4.10.0",
   486  					},
   487  					Networking: hiveext.Networking{
   488  						MachineNetwork: []hiveext.MachineNetworkEntry{
   489  							{
   490  								CIDR: "10.10.11.0/24",
   491  							},
   492  						},
   493  						ClusterNetwork: []hiveext.ClusterNetworkEntry{
   494  							{
   495  								CIDR:       "10.128.0.0/14",
   496  								HostPrefix: 23,
   497  							},
   498  						},
   499  						ServiceNetwork: []string{
   500  							"172.30.0.0/16",
   501  						},
   502  						NetworkType: "OVNKubernetes",
   503  					},
   504  					ProvisionRequirements: hiveext.ProvisionRequirements{
   505  						ControlPlaneAgents: 3,
   506  						WorkerAgents:       2,
   507  					},
   508  					SSHPublicKey: "ssh-rsa AAAAmyKey",
   509  				},
   510  			},
   511  			expectedError: "",
   512  		},
   513  		{
   514  			name: "valid-config-file-network-type-openshiftsdn",
   515  			data: `
   516  metadata:
   517    name: test-agent-cluster-install
   518    namespace: cluster0
   519  spec:
   520    apiVIP: 192.168.111.5
   521    ingressVIP: 192.168.111.4
   522    clusterDeploymentRef:
   523      name: ostest
   524    imageSetRef:
   525      name: openshift-v4.10.0
   526    networking:
   527      clusterNetwork:
   528      - cidr: 10.128.0.0/14
   529        hostPrefix: 23
   530      serviceNetwork:
   531      - 172.30.0.0/16
   532      networkType: OpenShiftSDN
   533    provisionRequirements:
   534      controlPlaneAgents: 3
   535      workerAgents: 2
   536    sshPublicKey: |
   537      ssh-rsa AAAAmyKey`,
   538  			expectedFound: true,
   539  			expectedConfig: &hiveext.AgentClusterInstall{
   540  				ObjectMeta: metav1.ObjectMeta{
   541  					Name:      "test-agent-cluster-install",
   542  					Namespace: "cluster0",
   543  				},
   544  				Spec: hiveext.AgentClusterInstallSpec{
   545  					APIVIP:     "192.168.111.5",
   546  					IngressVIP: "192.168.111.4",
   547  					ClusterDeploymentRef: corev1.LocalObjectReference{
   548  						Name: "ostest",
   549  					},
   550  					ImageSetRef: &hivev1.ClusterImageSetReference{
   551  						Name: "openshift-v4.10.0",
   552  					},
   553  					Networking: hiveext.Networking{
   554  						ClusterNetwork: []hiveext.ClusterNetworkEntry{
   555  							{
   556  								CIDR:       "10.128.0.0/14",
   557  								HostPrefix: 23,
   558  							},
   559  						},
   560  						ServiceNetwork: []string{
   561  							"172.30.0.0/16",
   562  						},
   563  						NetworkType: "OpenShiftSDN",
   564  					},
   565  					ProvisionRequirements: hiveext.ProvisionRequirements{
   566  						ControlPlaneAgents: 3,
   567  						WorkerAgents:       2,
   568  					},
   569  					SSHPublicKey: "ssh-rsa AAAAmyKey",
   570  				},
   571  			},
   572  			expectedError: "",
   573  		},
   574  		{
   575  			name: "valid-config-file-no-network-type-specified-and-defaults-to-OVNKubernetes",
   576  			data: `
   577  metadata:
   578    name: test-agent-cluster-install
   579    namespace: cluster0
   580  spec:
   581    apiVIP: 192.168.111.5
   582    ingressVIP: 192.168.111.4
   583    clusterDeploymentRef:
   584      name: ostest
   585    imageSetRef:
   586      name: openshift-v4.10.0
   587    networking:
   588      machineNetwork:
   589      - cidr: 10.10.11.0/24
   590      clusterNetwork:
   591      - cidr: 10.128.0.0/14
   592        hostPrefix: 23
   593      serviceNetwork:
   594      - 172.30.0.0/16
   595    provisionRequirements:
   596      controlPlaneAgents: 3
   597      workerAgents: 2
   598    sshPublicKey: |
   599      ssh-rsa AAAAmyKey`,
   600  			expectedFound: true,
   601  			expectedConfig: &hiveext.AgentClusterInstall{
   602  				ObjectMeta: metav1.ObjectMeta{
   603  					Name:      "test-agent-cluster-install",
   604  					Namespace: "cluster0",
   605  				},
   606  				Spec: hiveext.AgentClusterInstallSpec{
   607  					APIVIP:     "192.168.111.5",
   608  					IngressVIP: "192.168.111.4",
   609  					ClusterDeploymentRef: corev1.LocalObjectReference{
   610  						Name: "ostest",
   611  					},
   612  					ImageSetRef: &hivev1.ClusterImageSetReference{
   613  						Name: "openshift-v4.10.0",
   614  					},
   615  					Networking: hiveext.Networking{
   616  						MachineNetwork: []hiveext.MachineNetworkEntry{
   617  							{
   618  								CIDR: "10.10.11.0/24",
   619  							},
   620  						},
   621  						ClusterNetwork: []hiveext.ClusterNetworkEntry{
   622  							{
   623  								CIDR:       "10.128.0.0/14",
   624  								HostPrefix: 23,
   625  							},
   626  						},
   627  						ServiceNetwork: []string{
   628  							"172.30.0.0/16",
   629  						},
   630  						NetworkType: "OVNKubernetes",
   631  					},
   632  					ProvisionRequirements: hiveext.ProvisionRequirements{
   633  						ControlPlaneAgents: 3,
   634  						WorkerAgents:       2,
   635  					},
   636  					SSHPublicKey: "ssh-rsa AAAAmyKey",
   637  				},
   638  			},
   639  		},
   640  		{
   641  			name: "valid-config-file-dual-stack",
   642  			data: `
   643  metadata:
   644    name: test-agent-cluster-install-dual-stack
   645    namespace: cluster0
   646  spec:
   647    apiVIP: 192.168.111.5
   648    ingressVIP: 192.168.111.4
   649    clusterDeploymentRef:
   650      name: ostest
   651    imageSetRef:
   652      name: openshift-v4.10.0
   653    networking:
   654      machineNetwork:
   655      - cidr: 10.10.11.0/24
   656      - cidr: 2001:db8:5dd8:c956::/64
   657      clusterNetwork:
   658      - cidr: 10.128.0.0/14
   659        hostPrefix: 23
   660      - cidr: 2001:db8:1111:2222::/64
   661        hostPrefix: 64
   662      serviceNetwork:
   663      - 172.30.0.0/16
   664      - fd02::/112
   665    provisionRequirements:
   666      controlPlaneAgents: 3
   667      workerAgents: 2
   668    sshPublicKey: |
   669      ssh-rsa AAAAmyKey`,
   670  			expectedFound: true,
   671  			expectedConfig: &hiveext.AgentClusterInstall{
   672  				ObjectMeta: metav1.ObjectMeta{
   673  					Name:      "test-agent-cluster-install-dual-stack",
   674  					Namespace: "cluster0",
   675  				},
   676  				Spec: hiveext.AgentClusterInstallSpec{
   677  					APIVIP:     "192.168.111.5",
   678  					IngressVIP: "192.168.111.4",
   679  					ClusterDeploymentRef: corev1.LocalObjectReference{
   680  						Name: "ostest",
   681  					},
   682  					ImageSetRef: &hivev1.ClusterImageSetReference{
   683  						Name: "openshift-v4.10.0",
   684  					},
   685  					Networking: hiveext.Networking{
   686  						MachineNetwork: []hiveext.MachineNetworkEntry{
   687  							{
   688  								CIDR: "10.10.11.0/24",
   689  							},
   690  							{
   691  								CIDR: "2001:db8:5dd8:c956::/64",
   692  							},
   693  						},
   694  						ClusterNetwork: []hiveext.ClusterNetworkEntry{
   695  							{
   696  								CIDR:       "10.128.0.0/14",
   697  								HostPrefix: 23,
   698  							},
   699  							{
   700  								CIDR:       "2001:db8:1111:2222::/64",
   701  								HostPrefix: 64,
   702  							},
   703  						},
   704  						ServiceNetwork: []string{
   705  							"172.30.0.0/16",
   706  							"fd02::/112",
   707  						},
   708  						NetworkType: "OVNKubernetes",
   709  					},
   710  					ProvisionRequirements: hiveext.ProvisionRequirements{
   711  						ControlPlaneAgents: 3,
   712  						WorkerAgents:       2,
   713  					},
   714  					SSHPublicKey: "ssh-rsa AAAAmyKey",
   715  				},
   716  			},
   717  			expectedError: "",
   718  		},
   719  		{
   720  			name:          "not-yaml",
   721  			data:          `This is not a yaml file`,
   722  			expectedError: "failed to unmarshal cluster-manifests/agent-cluster-install.yaml: error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go value of type v1beta1.AgentClusterInstall",
   723  		},
   724  		{
   725  			name:           "empty",
   726  			data:           "",
   727  			expectedFound:  true,
   728  			expectedConfig: emptyACI,
   729  		},
   730  		{
   731  			name:       "file-not-found",
   732  			fetchError: &os.PathError{Err: os.ErrNotExist},
   733  		},
   734  		{
   735  			name:          "error-fetching-file",
   736  			fetchError:    errors.New("fetch failed"),
   737  			expectedError: "failed to load cluster-manifests/agent-cluster-install.yaml file: fetch failed",
   738  		},
   739  		{
   740  			name: "unknown-field",
   741  			data: `
   742  metadata:
   743    name: test-agent-cluster-install
   744    namespace: cluster0
   745  spec:
   746    wrongField: wrongValue`,
   747  			expectedError: "failed to unmarshal cluster-manifests/agent-cluster-install.yaml: error unmarshaling JSON: while decoding JSON: json: unknown field \"wrongField\"",
   748  		},
   749  		{
   750  			name: "network-ip-address-incompatible-with-network-type",
   751  			data: `
   752  metadata:
   753    name: test-agent-cluster-install
   754    namespace: cluster0
   755  spec:
   756    apiVIP: 192.168.111.5
   757    ingressVIP: 192.168.111.4
   758    clusterDeploymentRef:
   759      name: ostest
   760    imageSetRef:
   761      name: openshift-v4.10.0
   762    networking:
   763      clusterNetwork:
   764      - cidr: fd01::/48
   765        hostPrefix: 23
   766      serviceNetwork:
   767      - fd02::/112
   768      - 172.30.0.0/16
   769      networkType: "OpenShiftSDN"
   770    provisionRequirements:
   771      controlPlaneAgents: 3
   772      workerAgents: 2
   773    sshPublicKey: |
   774      ssh-rsa AAAAmyKey`,
   775  			expectedError: "invalid NetworkType configured: [spec.networking.networkType: Required value: clusterNetwork CIDR is IPv6 and is not compatible with networkType OpenShiftSDN, spec.networking.networkType: Required value: serviceNetwork CIDR is IPv6 and is not compatible with networkType OpenShiftSDN]",
   776  		},
   777  		{
   778  			name: "invalid-config-file",
   779  			data: `
   780  metadata:
   781    name: test-agent-cluster-install
   782    namespace: cluster0
   783  spec:
   784    apiVIP: 192.168.111.5
   785    ingressVIP: 192.168.111.4
   786    platformType: aws
   787    clusterDeploymentRef:
   788      name: ostest
   789    imageSetRef:
   790      name: openshift-v4.10.0
   791    networking:
   792      machineNetwork:
   793      - cidr: 10.10.11.0/24
   794      clusterNetwork:
   795      - cidr: 10.128.0.0/14
   796        hostPrefix: 23
   797      serviceNetwork:
   798      - 172.30.0.0/16
   799      networkType: OVNKubernetes
   800    provisionRequirements:
   801      controlPlaneAgents: 3
   802      workerAgents: 2
   803    sshPublicKey: |
   804      ssh-rsa AAAAmyKey`,
   805  			expectedFound: false,
   806  			expectedError: "invalid PlatformType configured: spec.platformType: Unsupported value: \"aws\": supported values: \"BareMetal\", \"VSphere\", \"None\", \"External\"",
   807  		},
   808  	}
   809  	for _, tc := range cases {
   810  		t.Run(tc.name, func(t *testing.T) {
   811  
   812  			mockCtrl := gomock.NewController(t)
   813  			defer mockCtrl.Finish()
   814  
   815  			fileFetcher := mock.NewMockFileFetcher(mockCtrl)
   816  			fileFetcher.EXPECT().FetchByName(agentClusterInstallFilename).
   817  				Return(
   818  					&asset.File{
   819  						Filename: agentClusterInstallFilename,
   820  						Data:     []byte(tc.data)},
   821  					tc.fetchError,
   822  				)
   823  
   824  			asset := &AgentClusterInstall{}
   825  			found, err := asset.Load(fileFetcher)
   826  			assert.Equal(t, tc.expectedFound, found, "unexpected found value returned from Load")
   827  
   828  			if tc.expectedError != "" {
   829  				assert.Equal(t, tc.expectedError, err.Error())
   830  			} else {
   831  				assert.Equal(t, nil, err)
   832  			}
   833  
   834  			if tc.expectedFound {
   835  				assert.Equal(t, tc.expectedConfig, asset.Config, "unexpected Config in AgentClusterInstall")
   836  			}
   837  		})
   838  	}
   839  
   840  }