Skip to content

Commit eae3c72

Browse files
Merge pull request #2195 from vr4manta/SPLAT-2651_rm_ptr
SPLAT-2651: Changed Node struct to not be pointer in CPIConfig
2 parents 2dd4388 + fe0b2cb commit eae3c72

3 files changed

Lines changed: 47 additions & 2 deletions

File tree

pkg/cloudprovider/vsphere/config_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,48 @@ func TestINIConfigConversion(t *testing.T) {
179179
})
180180
}
181181
}
182+
183+
func TestEmptyNodesOmittedInYAML(t *testing.T) {
184+
g := gmg.NewWithT(t)
185+
186+
// Create a config with an empty Nodes struct
187+
config := &CPIConfig{
188+
CommonConfig: CommonConfig{
189+
Global: Global{
190+
User: "testuser",
191+
Password: "testpass",
192+
},
193+
},
194+
Nodes: Nodes{}, // Empty struct, should be omitted
195+
}
196+
197+
yamlOutput, err := MarshalConfig(config)
198+
g.Expect(err).ToNot(gmg.HaveOccurred())
199+
200+
// Verify that "nodes:" does not appear in the output
201+
g.Expect(yamlOutput).ToNot(gmg.ContainSubstring("nodes:"))
202+
}
203+
204+
func TestNodesWithValuesIncludedInYAML(t *testing.T) {
205+
g := gmg.NewWithT(t)
206+
207+
// Create a config with a populated Nodes struct
208+
config := &CPIConfig{
209+
CommonConfig: CommonConfig{
210+
Global: Global{
211+
User: "testuser",
212+
Password: "testpass",
213+
},
214+
},
215+
Nodes: Nodes{
216+
InternalNetworkSubnetCIDR: "192.168.1.0/24",
217+
},
218+
}
219+
220+
yamlOutput, err := MarshalConfig(config)
221+
g.Expect(err).ToNot(gmg.HaveOccurred())
222+
223+
// Verify that "nodes:" DOES appear when the struct has values
224+
g.Expect(yamlOutput).To(gmg.ContainSubstring("nodes:"))
225+
g.Expect(yamlOutput).To(gmg.ContainSubstring("internalNetworkSubnetCidr: 192.168.1.0/24"))
226+
}

pkg/cloudprovider/vsphere/ini.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (iniConfig *cpiConfigINI) createConfig() (*CPIConfig, error) {
219219
iniConfig.Nodes.ExternalVMNetworkName != "" ||
220220
iniConfig.Nodes.ExcludeInternalNetworkSubnetCIDR != "" ||
221221
iniConfig.Nodes.ExcludeExternalNetworkSubnetCIDR != "" {
222-
cfg.Nodes = &Nodes{
222+
cfg.Nodes = Nodes{
223223
InternalNetworkSubnetCIDR: iniConfig.Nodes.InternalNetworkSubnetCIDR,
224224
ExternalNetworkSubnetCIDR: iniConfig.Nodes.ExternalNetworkSubnetCIDR,
225225
InternalVMNetworkName: iniConfig.Nodes.InternalVMNetworkName,

pkg/cloudprovider/vsphere/yaml.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ type Nodes struct {
140140
// CPIConfig is the YAML representation of vsphere-cloud-provider config
141141
type CPIConfig struct {
142142
CommonConfig `json:",inline"`
143-
Nodes *Nodes `json:"nodes,omitempty"`
143+
Nodes Nodes `json:"nodes,omitzero"`
144144
}
145145

146146
// readCPIConfigYAML parses vSphere cloud config file and stores it into CPIConfig

0 commit comments

Comments
 (0)