Skip to content

Commit

Permalink
MGMT-20025: Replace encode from yaml to json on Nutanix types
Browse files Browse the repository at this point in the history
  • Loading branch information
mlorenzofr committed Feb 26, 2025
1 parent 39bc1ae commit c6babc6
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 22 deletions.
52 changes: 52 additions & 0 deletions internal/installcfg/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"],"defaultMachinePlatform":{"bootType":"Legacy"},"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)
Expand Down Expand Up @@ -935,6 +967,26 @@ 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(result.Platform.Nutanix.APIVIPs).Should(Equal("10.0.0.1"))
Expect(result.Platform.Nutanix.IngressVIPs).Should(Equal("10.0.0.2"))
Expect(result.Platform.Nutanix.PrismCentral.Username).Should(Equal("testUser"))
Expect(result.Platform.Nutanix.PrismCentral.Password).Should(Equal("testPassword"))
Expect(result.Platform.Nutanix.PrismCentral.Endpoint.Address).Should(Equal("prismcentral.openshift.com"))
Expect(result.Platform.Nutanix.PrismCentral.Endpoint.Port).Should(Equal("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("9440"))
Expect(result.Platform.Nutanix.SubnetUUIDs[0]).Should(Equal("0000-0000-0000-0000-0000"))
}

// 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"))
Expand Down
44 changes: 22 additions & 22 deletions internal/installcfg/installcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c6babc6

Please sign in to comment.