From 5462c7664637568d15d47977c27559de58405126 Mon Sep 17 00:00:00 2001 From: Manuel Lorenzo Date: Tue, 25 Feb 2025 11:51:31 +0100 Subject: [PATCH] MGMT-20025: Replace encode from yaml to json on Nutanix types --- internal/installcfg/builder/builder_test.go | 50 +++++++++++++++++++++ internal/installcfg/installcfg.go | 44 +++++++++--------- 2 files changed, 72 insertions(+), 22 deletions(-) diff --git a/internal/installcfg/builder/builder_test.go b/internal/installcfg/builder/builder_test.go index fe26b228539..25e8960e0cf 100644 --- a/internal/installcfg/builder/builder_test.go +++ b/internal/installcfg/builder/builder_test.go @@ -261,6 +261,38 @@ aEA8gNEmV+rb7h1v0r3EwDQYJKoZIhvcNAQELBQAwYTELMAkGA1UEBhMCaXMxCzAJBgNVBAgMAmRk assertVSphereCredentials(result) }) + nutanixInstallConfigOverrides := `{"platform":{"nutanix":{"prismCentral":{"endpoint":{"address":"prismcentral.openshift.com","port":9440},"username":"testUser","password":"testPassword"},"prismElements":[{"uuid": "0000-0000-0000-0000-0000","endpoint":{"address":"prism.openshift.com","port":9440}}],"subnetUUIDs":["0000-0000-0000-0000-0000"],"apiVIPs":["10.0.0.1"],"ingressVIPs":["10.0.0.2"]}}}` + + It("Nutanix platform in overrides is decoded correctly - installConfig.applyConfigOverrides", func() { + var result installcfg.InstallerConfigBaremetal + overrides := nutanixInstallConfigOverrides + err := installConfig.applyConfigOverrides(overrides, &result) + Expect(err).ShouldNot(HaveOccurred()) + assertNutanixPlatform(result) + }) + + It("Nutanix platform are unmarshalled correctly - installConfig.GetInstallConfig", func() { + var result installcfg.InstallerConfigBaremetal + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured().Return(false).Times(2) + cluster.InstallConfigOverrides = nutanixInstallConfigOverrides + data, err := installConfig.GetInstallConfig(&cluster, clusterInfraenvs, "") + Expect(err).ShouldNot(HaveOccurred()) + err = json.Unmarshal(data, &result) + Expect(err).ShouldNot(HaveOccurred()) + assertNutanixPlatform(result) + }) + + It("Nutanix credentials are unmarshalled correctly - installConfig.GetInstallConfig", func() { + var result installcfg.InstallerConfigBaremetal + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured().Return(false).Times(2) + cluster.InstallConfigOverrides = nutanixInstallConfigOverrides + data, err := installConfig.GetInstallConfig(&cluster, clusterInfraenvs, "") + Expect(err).ShouldNot(HaveOccurred()) + err = json.Unmarshal(data, &result) + Expect(err).ShouldNot(HaveOccurred()) + assertNutanixCredentials(result) + }) + It("correctly applies cluster overrides", func() { var result installcfg.InstallerConfigBaremetal mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured().Return(false).Times(2) @@ -935,6 +967,24 @@ func assertVSphereCredentials(result installcfg.InstallerConfigBaremetal) { Expect(result.Platform.Vsphere.FailureDomains[0].Topology.Folder).Should(Equal("/testDatacenter/vm/testFolder")) } +// asserts platform values against nutanixInstallConfigOverrides +func assertNutanixPlatform(result installcfg.InstallerConfigBaremetal) { + Expect(len(result.Platform.Nutanix.APIVIPs)).Should(Equal(1)) + Expect(len(result.Platform.Nutanix.IngressVIPs)).Should(Equal(1)) + Expect(result.Platform.Nutanix.PrismCentral.Endpoint.Address).Should(Equal("prismcentral.openshift.com")) + Expect(result.Platform.Nutanix.PrismCentral.Endpoint.Port).Should(Equal(int32(9440))) + Expect(result.Platform.Nutanix.PrismElements[0].UUID).Should(Equal("0000-0000-0000-0000-0000")) + Expect(result.Platform.Nutanix.PrismElements[0].Endpoint.Address).Should(Equal("prism.openshift.com")) + Expect(result.Platform.Nutanix.PrismElements[0].Endpoint.Port).Should(Equal(int32(9440))) + Expect(len(result.Platform.Nutanix.SubnetUUIDs)).Should(Equal(1)) +} + +// asserts platform values against nutanixInstallConfigOverrides +func assertNutanixCredentials(result installcfg.InstallerConfigBaremetal) { + Expect(result.Platform.Nutanix.PrismCentral.Username).Should(Equal("testUser")) + Expect(result.Platform.Nutanix.PrismCentral.Password).Should(Equal("testPassword")) +} + // asserts Baremetal Host BMC Configuration set by InstallConfigOverrides func assertBaremetalHostBMCConfig(result installcfg.InstallerConfigBaremetal) { Expect(result.Platform.Baremetal.Hosts[0].Name).Should(Equal("master-0")) diff --git a/internal/installcfg/installcfg.go b/internal/installcfg/installcfg.go index 36396f5a598..e8fc3be6f58 100644 --- a/internal/installcfg/installcfg.go +++ b/internal/installcfg/installcfg.go @@ -111,37 +111,37 @@ type VsphereInstallConfigPlatform struct { } type NutanixInstallConfigPlatform struct { - ID int `yaml:"-"` - APIVIPs []string `yaml:"apiVIPs,omitempty"` - DeprecatedAPIVIP string `yaml:"apiVIP,omitempty"` - IngressVIPs []string `yaml:"ingressVIPs,omitempty"` - DeprecatedIngressVIP string `yaml:"ingressVIP,omitempty"` - PrismCentral NutanixPrismCentral `yaml:"prismCentral"` - PrismElements []NutanixPrismElement `yaml:"prismElements"` - SubnetUUIDs []strfmt.UUID `yaml:"subnetUUIDs"` + ID int `json:"-"` + APIVIPs []string `json:"apiVIPs,omitempty"` + DeprecatedAPIVIP string `json:"apiVIP,omitempty"` + IngressVIPs []string `json:"ingressVIPs,omitempty"` + DeprecatedIngressVIP string `json:"ingressVIP,omitempty"` + PrismCentral NutanixPrismCentral `json:"prismCentral"` + PrismElements []NutanixPrismElement `json:"prismElements"` + SubnetUUIDs []strfmt.UUID `json:"subnetUUIDs"` } type NutanixPrismCentral struct { - ID int `yaml:"-"` - NutanixInstallConfigPlatformID int `yaml:"-"` - Endpoint NutanixEndpoint `yaml:"endpoint"` - Username string `yaml:"username"` - Password strfmt.Password `yaml:"password"` + ID int `json:"-"` + NutanixInstallConfigPlatformID int `json:"-"` + Endpoint NutanixEndpoint `json:"endpoint"` + Username string `json:"username"` + Password strfmt.Password `json:"password"` } type NutanixEndpoint struct { - ID int `yaml:"-"` - NutanixPrismCentralID int `yaml:"-"` - Address string `yaml:"address"` - Port int32 `yaml:"port"` + ID int `json:"-"` + NutanixPrismCentralID int `json:"-"` + Address string `json:"address"` + Port int32 `json:"port"` } type NutanixPrismElement struct { - ID int `yaml:"-"` - NutanixInstallConfigPlatformID int `yaml:"-"` - Endpoint NutanixEndpoint `yaml:"endpoint"` - UUID strfmt.UUID `yaml:"uuid"` - Name string `yaml:"name"` + ID int `json:"-"` + NutanixInstallConfigPlatformID int `json:"-"` + Endpoint NutanixEndpoint `json:"endpoint"` + UUID strfmt.UUID `json:"uuid"` + Name string `json:"name"` } // CloudControllerManager describes the type of cloud controller manager to be enabled.