Skip to content

Commit 1ba5d0c

Browse files
authored
validate operatingSystemSpec is not empty (#923)
Signed-off-by: Moath Qasim <[email protected]>
1 parent e76bbeb commit 1ba5d0c

File tree

13 files changed

+60
-1
lines changed

13 files changed

+60
-1
lines changed

pkg/cloudprovider/provider/alibaba/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ func (p *provider) getConfig(s v1alpha1.ProviderSpec) (*Config, *providerconfigt
351351
return nil, nil, fmt.Errorf("failed to decode providers config: %v", err)
352352
}
353353

354+
if pconfig.OperatingSystemSpec.Raw == nil {
355+
return nil, nil, errors.New("operatingSystemSpec in the MachineDeployment cannot be empty")
356+
}
357+
354358
rawConfig := alibabatypes.RawConfig{}
355359
if err = json.Unmarshal(pconfig.CloudProviderSpec.Raw, &rawConfig); err != nil {
356360
return nil, nil, fmt.Errorf("failed to decode alibaba providers config: %v", err)

pkg/cloudprovider/provider/anexia/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ func (p *provider) getConfig(s v1alpha1.ProviderSpec) (*Config, *providerconfigt
6767
return nil, nil, err
6868
}
6969

70+
if pConfig.OperatingSystemSpec.Raw == nil {
71+
return nil, nil, errors.New("operatingSystemSpec in the MachineDeployment cannot be empty")
72+
}
73+
7074
rawConfig := anxtypes.RawConfig{}
7175
if err = json.Unmarshal(pConfig.CloudProviderSpec.Raw, &rawConfig); err != nil {
7276
return nil, nil, err

pkg/cloudprovider/provider/aws/provider.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ func (p *provider) getConfig(s v1alpha1.ProviderSpec) (*Config, *providerconfigt
265265
if err != nil {
266266
return nil, nil, nil, err
267267
}
268+
269+
if pconfig.OperatingSystemSpec.Raw == nil {
270+
return nil, nil, nil, errors.New("operatingSystemSpec in the MachineDeployment cannot be empty")
271+
}
272+
268273
rawConfig := awstypes.RawConfig{}
269274
if err := json.Unmarshal(pconfig.CloudProviderSpec.Raw, &rawConfig); err != nil {
270275
return nil, nil, nil, fmt.Errorf("failed to unmarshal: %v", err)

pkg/cloudprovider/provider/azure/provider.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ func (p *provider) getConfig(s v1alpha1.ProviderSpec) (*config, *providerconfigt
191191
if err != nil {
192192
return nil, nil, err
193193
}
194+
195+
if pconfig.OperatingSystemSpec.Raw == nil {
196+
return nil, nil, errors.New("operatingSystemSpec in the MachineDeployment cannot be empty")
197+
}
198+
194199
rawCfg := azuretypes.RawConfig{}
195200
err = json.Unmarshal(pconfig.CloudProviderSpec.Raw, &rawCfg)
196201
if err != nil {

pkg/cloudprovider/provider/digitalocean/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ func (p *provider) getConfig(s v1alpha1.ProviderSpec) (*Config, *providerconfigt
110110
if err != nil {
111111
return nil, nil, err
112112
}
113+
114+
if pconfig.OperatingSystemSpec.Raw == nil {
115+
return nil, nil, errors.New("operatingSystemSpec in the MachineDeployment cannot be empty")
116+
}
113117
rawConfig := digitaloceantypes.RawConfig{}
114118
err = json.Unmarshal(pconfig.CloudProviderSpec.Raw, &rawConfig)
115119
if err != nil {

pkg/cloudprovider/provider/gce/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package gce
2323
import (
2424
"encoding/base64"
2525
"encoding/json"
26+
"errors"
2627
"fmt"
2728

2829
"golang.org/x/oauth2/google"
@@ -75,6 +76,10 @@ func newCloudProviderSpec(spec v1alpha1.ProviderSpec) (*gcetypes.CloudProviderSp
7576
if err != nil {
7677
return nil, nil, fmt.Errorf("cannot unmarshal machine.spec.providerconfig.value: %v", err)
7778
}
79+
80+
if providerConfig.OperatingSystemSpec.Raw == nil {
81+
return nil, nil, errors.New("operatingSystemSpec in the MachineDeployment cannot be empty")
82+
}
7883
// Retrieve cloud provider specification from cloud provider specification.
7984
cpSpec := &gcetypes.CloudProviderSpec{}
8085
err = json.Unmarshal(providerConfig.CloudProviderSpec.Raw, cpSpec)

pkg/cloudprovider/provider/hetzner/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ func (p *provider) getConfig(s v1alpha1.ProviderSpec) (*Config, *providerconfigt
8888
return nil, nil, err
8989
}
9090

91+
if pconfig.OperatingSystemSpec.Raw == nil {
92+
return nil, nil, errors.New("operatingSystemSpec in the MachineDeployment cannot be empty")
93+
}
94+
9195
rawConfig := hetznertypes.RawConfig{}
9296
if err = json.Unmarshal(pconfig.CloudProviderSpec.Raw, &rawConfig); err != nil {
9397
return nil, nil, err

pkg/cloudprovider/provider/kubevirt/provider.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package kubevirt
1919
import (
2020
"context"
2121
"encoding/json"
22+
"errors"
2223
"fmt"
2324
"strconv"
2425
"strings"
@@ -121,6 +122,10 @@ func (p *provider) getConfig(s v1alpha1.ProviderSpec) (*Config, *providerconfigt
121122
return nil, nil, err
122123
}
123124

125+
if pconfig.OperatingSystemSpec.Raw == nil {
126+
return nil, nil, errors.New("operatingSystemSpec in the MachineDeployment cannot be empty")
127+
}
128+
124129
rawConfig := kubevirttypes.RawConfig{}
125130
if err = json.Unmarshal(pconfig.CloudProviderSpec.Raw, &rawConfig); err != nil {
126131
return nil, nil, err

pkg/cloudprovider/provider/linode/provider.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ func (p *provider) getConfig(s v1alpha1.ProviderSpec) (*Config, *providerconfigt
116116
if err != nil {
117117
return nil, nil, err
118118
}
119+
120+
if pconfig.OperatingSystemSpec.Raw == nil {
121+
return nil, nil, errors.New("operatingSystemSpec in the MachineDeployment cannot be empty")
122+
}
123+
119124
rawConfig := linodetypes.RawConfig{}
120125
err = json.Unmarshal(pconfig.CloudProviderSpec.Raw, &rawConfig)
121126
if err != nil {

pkg/cloudprovider/provider/openstack/provider.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ func (p *provider) getConfig(s v1alpha1.ProviderSpec) (*Config, *providerconfigt
164164
if err != nil {
165165
return nil, nil, nil, err
166166
}
167+
168+
if pconfig.OperatingSystemSpec.Raw == nil {
169+
return nil, nil, nil, errors.New("operatingSystemSpec in the MachineDeployment cannot be empty")
170+
}
171+
167172
c := Config{}
168173
c.IdentityEndpoint, err = p.configVarResolver.GetConfigVarStringValueOrEnv(rawConfig.IdentityEndpoint, "OS_AUTH_URL")
169174
if err != nil {

0 commit comments

Comments
 (0)