Skip to content

Commit beebc39

Browse files
Merge pull request #9931 from abhay-nutanix/OCPBUGS-61353
OCPBUGS-61353: Generated Redacted nutanix config for operator
2 parents 95ccf3f + 7794b28 commit beebc39

File tree

2 files changed

+142
-4
lines changed

2 files changed

+142
-4
lines changed

pkg/asset/manifests/operators.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/openshift/installer/pkg/asset/templates/content/manifests"
2323
"github.com/openshift/installer/pkg/asset/tls"
2424
"github.com/openshift/installer/pkg/types"
25+
"github.com/openshift/installer/pkg/types/nutanix"
2526
"github.com/openshift/installer/pkg/types/vsphere"
2627
"github.com/openshift/library-go/pkg/crypto"
2728
)
@@ -280,7 +281,8 @@ func redactedInstallConfig(config types.InstallConfig) ([]byte, error) {
280281
newConfig := config
281282

282283
newConfig.PullSecret = ""
283-
if newConfig.Platform.VSphere != nil {
284+
switch {
285+
case newConfig.Platform.VSphere != nil:
284286
p := config.VSphere
285287
newVCenters := make([]vsphere.VCenter, len(p.VCenters))
286288
for i, v := range p.VCenters {
@@ -308,6 +310,30 @@ func redactedInstallConfig(config types.InstallConfig) ([]byte, error) {
308310
FailureDomains: p.FailureDomains,
309311
}
310312
newConfig.Platform.VSphere = &newVSpherePlatform
313+
314+
case newConfig.Platform.Nutanix != nil:
315+
p := config.Nutanix
316+
newPrismCentral := nutanix.PrismCentral{
317+
Endpoint: p.PrismCentral.Endpoint,
318+
Username: "",
319+
Password: "",
320+
}
321+
newNutanixPlatform := nutanix.Platform{
322+
PrismCentral: newPrismCentral,
323+
PrismElements: p.PrismElements,
324+
ClusterOSImage: p.ClusterOSImage,
325+
PreloadedOSImageName: p.PreloadedOSImageName,
326+
DeprecatedAPIVIP: p.DeprecatedAPIVIP,
327+
APIVIPs: p.APIVIPs,
328+
DeprecatedIngressVIP: p.DeprecatedIngressVIP,
329+
IngressVIPs: p.IngressVIPs,
330+
DefaultMachinePlatform: p.DefaultMachinePlatform,
331+
SubnetUUIDs: p.SubnetUUIDs,
332+
LoadBalancer: p.LoadBalancer,
333+
FailureDomains: p.FailureDomains,
334+
PrismAPICallTimeout: p.PrismAPICallTimeout,
335+
}
336+
newConfig.Platform.Nutanix = &newNutanixPlatform
311337
}
312338

313339
return yaml.Marshal(newConfig)

pkg/asset/manifests/operators_test.go

Lines changed: 115 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import (
55

66
"github.com/stretchr/testify/assert"
77
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8-
"k8s.io/utils/pointer"
8+
"k8s.io/utils/ptr"
99

1010
"github.com/openshift/installer/pkg/ipnet"
1111
"github.com/openshift/installer/pkg/types"
12+
nutanixtypes "github.com/openshift/installer/pkg/types/nutanix"
1213
vspheretypes "github.com/openshift/installer/pkg/types/vsphere"
1314
)
1415

@@ -36,13 +37,13 @@ func TestRedactedInstallConfig(t *testing.T) {
3637
},
3738
ControlPlane: &types.MachinePool{
3839
Name: "control-plane",
39-
Replicas: pointer.Int64Ptr(3),
40+
Replicas: ptr.To(int64(3)),
4041
Architecture: types.ArchitectureAMD64,
4142
},
4243
Compute: []types.MachinePool{
4344
{
4445
Name: "compute",
45-
Replicas: pointer.Int64Ptr(3),
46+
Replicas: ptr.To(int64(3)),
4647
Architecture: types.ArchitectureAMD64,
4748
},
4849
},
@@ -131,3 +132,114 @@ sshKey: test-ssh-key
131132
}
132133
assert.Equal(t, expectedConfig, ic, "install config was unexpectedly modified")
133134
}
135+
136+
// TestRedactedInstallConfigNutanix tests the redactedInstallConfig function for Nutanix platform.
137+
func TestRedactedInstallConfigNutanix(t *testing.T) {
138+
createInstallConfigWithNutanix := func() *types.InstallConfig {
139+
return &types.InstallConfig{
140+
ObjectMeta: metav1.ObjectMeta{
141+
Name: "test-nutanix-cluster",
142+
},
143+
SSHKey: "test-ssh-key",
144+
BaseDomain: "test-domain",
145+
Networking: &types.Networking{
146+
MachineNetwork: []types.MachineNetworkEntry{
147+
{CIDR: *ipnet.MustParseCIDR("1.2.3.4/5")},
148+
},
149+
NetworkType: "test-network-type",
150+
ClusterNetwork: []types.ClusterNetworkEntry{
151+
{
152+
CIDR: *ipnet.MustParseCIDR("1.2.3.4/5"),
153+
HostPrefix: 6,
154+
},
155+
},
156+
ServiceNetwork: []ipnet.IPNet{*ipnet.MustParseCIDR("1.2.3.4/5")},
157+
},
158+
ControlPlane: &types.MachinePool{
159+
Name: "control-plane",
160+
Replicas: ptr.To(int64(3)),
161+
Architecture: types.ArchitectureAMD64,
162+
},
163+
Compute: []types.MachinePool{
164+
{
165+
Name: "compute",
166+
Replicas: ptr.To(int64(3)),
167+
Architecture: types.ArchitectureAMD64,
168+
},
169+
},
170+
Platform: types.Platform{
171+
Nutanix: &nutanixtypes.Platform{
172+
PrismCentral: nutanixtypes.PrismCentral{
173+
Endpoint: nutanixtypes.PrismEndpoint{
174+
Address: "test-prism-central.test.com",
175+
Port: 9440,
176+
},
177+
Username: "test-username",
178+
Password: "test-password",
179+
},
180+
PrismElements: []nutanixtypes.PrismElement{{
181+
UUID: "test-uuid",
182+
Endpoint: nutanixtypes.PrismEndpoint{
183+
Address: "test-prism-element.test.com",
184+
Port: 9440,
185+
},
186+
Name: "test-element",
187+
}},
188+
SubnetUUIDs: []string{"test-subnet-uuid"},
189+
},
190+
},
191+
PullSecret: "test-pull-secret",
192+
}
193+
}
194+
195+
expectedYaml := `baseDomain: test-domain
196+
compute:
197+
- architecture: amd64
198+
name: compute
199+
platform: {}
200+
replicas: 3
201+
controlPlane:
202+
architecture: amd64
203+
name: control-plane
204+
platform: {}
205+
replicas: 3
206+
metadata:
207+
creationTimestamp: null
208+
name: test-nutanix-cluster
209+
networking:
210+
clusterNetwork:
211+
- cidr: 1.2.3.4/5
212+
hostPrefix: 6
213+
machineNetwork:
214+
- cidr: 1.2.3.4/5
215+
networkType: test-network-type
216+
serviceNetwork:
217+
- 1.2.3.4/5
218+
platform:
219+
nutanix:
220+
prismCentral:
221+
endpoint:
222+
address: test-prism-central.test.com
223+
port: 9440
224+
password: ""
225+
username: ""
226+
prismElements:
227+
- endpoint:
228+
address: test-prism-element.test.com
229+
port: 9440
230+
name: test-element
231+
uuid: test-uuid
232+
subnetUUIDs:
233+
- test-subnet-uuid
234+
pullSecret: ""
235+
sshKey: test-ssh-key
236+
`
237+
238+
expectedConfig := createInstallConfigWithNutanix()
239+
ic := createInstallConfigWithNutanix()
240+
actualYaml, err := redactedInstallConfig(*ic)
241+
if assert.NoError(t, err, "unexpected error") {
242+
assert.Equal(t, expectedYaml, string(actualYaml), "unexpected yaml")
243+
}
244+
assert.Equal(t, expectedConfig, ic, "install config was unexpectedly modified")
245+
}

0 commit comments

Comments
 (0)