Skip to content
This repository was archived by the owner on Jul 2, 2025. It is now read-only.

Commit 9a32fe0

Browse files
committed
fix tag validation
1 parent 81fec4f commit 9a32fe0

File tree

3 files changed

+28
-33
lines changed

3 files changed

+28
-33
lines changed

pkg/vsphere/apis/provider_spec.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ const (
3535
type VsphereProviderSpec struct {
3636
V1 *VsphereProviderSpec1 `json:"v1,omitempty"`
3737
V2 *VsphereProviderSpec2 `json:"v2,omitempty"`
38+
39+
// SSHKeys is an optional array of ssh public keys to deploy to VM (may already be included in UserData)
40+
// +optional
41+
SSHKeys []string `json:"sshKeys,omitempty"`
42+
// Tags to be placed on the VM
43+
// +optional
44+
Tags map[string]string `json:"tags,omitempty"`
3845
}
3946

4047
// VsphereProviderSpec1 contains the fields of
@@ -101,13 +108,6 @@ type VsphereProviderSpec1 struct {
101108
// Customization is an experimental option to add a CustomizationSpec
102109
// +optional
103110
Customization string `json:"customization,omitempty"`
104-
105-
// SSHKeys is an optional array of ssh public keys to deploy to VM (may already be included in UserData)
106-
// +optional
107-
SSHKeys []string `json:"sshKeys,omitempty"`
108-
// Tags to be placed on the VM
109-
// +optional
110-
Tags map[string]string `json:"tags,omitempty"`
111111
}
112112

113113
// SpecVersion returns spec version
@@ -154,13 +154,6 @@ type VsphereProviderSpec2 struct {
154154
// e.g. sched.swap.vmxSwapEnabled=false to disable the VMX process swap file
155155
// +optional
156156
//ExtraConfig map[string]string `json:"extraConfig,omitempty"`
157-
158-
// SSHKeys is an optional array of ssh public keys to deploy to VM (may already be included in UserData)
159-
// +optional
160-
SSHKeys []string `json:"sshKeys,omitempty"`
161-
// Tags to be placed on the VM
162-
// +optional
163-
Tags map[string]string `json:"tags,omitempty"`
164157
}
165158

166159
// SpecVersion returns spec version

pkg/vsphere/apis/validation/validation.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,20 @@ import (
2626
)
2727

2828
// ValidateVsphereProviderSpec1 validates Vsphere provider spec
29-
func ValidateVsphereProviderSpec1(spec *api.VsphereProviderSpec1, secrets *corev1.Secret) []error {
29+
func ValidateVsphereProviderSpec1(spec *api.VsphereProviderSpec, secrets *corev1.Secret) []error {
3030
var allErrs []error
3131

32-
if "" == spec.Datastore && "" == spec.DatastoreCluster {
32+
v1 := spec.V1
33+
if "" == v1.Datastore && "" == v1.DatastoreCluster {
3334
allErrs = append(allErrs, fmt.Errorf("either datastoreCluster or datastore field is required"))
3435
}
35-
if "" == spec.TemplateVM {
36+
if "" == v1.TemplateVM {
3637
allErrs = append(allErrs, fmt.Errorf("templateVM is a required field"))
3738
}
38-
if "" == spec.ComputeCluster && "" == spec.ResourcePool && "" == spec.HostSystem {
39+
if "" == v1.ComputeCluster && "" == v1.ResourcePool && "" == v1.HostSystem {
3940
allErrs = append(allErrs, fmt.Errorf("either computeCluster or resourcePool or hostSystem field is required"))
4041
}
41-
if "" == spec.Network {
42+
if "" == v1.Network {
4243
allErrs = append(allErrs, fmt.Errorf("network is a required field"))
4344
}
4445

@@ -78,22 +79,23 @@ func validateSecrets(secret *corev1.Secret) []error {
7879
}
7980

8081
// ValidateVsphereProviderSpec2 validates Vsphere provider spec2
81-
func ValidateVsphereProviderSpec2(spec *api.VsphereProviderSpec2, secrets *corev1.Secret) []error {
82+
func ValidateVsphereProviderSpec2(spec *api.VsphereProviderSpec, secrets *corev1.Secret) []error {
8283
var allErrs []error
8384

84-
if "" == spec.Namespace {
85+
v2 := spec.V2
86+
if "" == v2.Namespace {
8587
allErrs = append(allErrs, fmt.Errorf("namespace is a required field"))
8688
}
87-
if "" == spec.ImageName {
89+
if "" == v2.ImageName {
8890
allErrs = append(allErrs, fmt.Errorf("imageName is a required field"))
8991
}
90-
if "" == spec.NetworkType {
92+
if "" == v2.NetworkType {
9193
allErrs = append(allErrs, fmt.Errorf("networkType is a required field"))
9294
}
93-
if "" == spec.NetworkName {
95+
if "" == v2.NetworkName {
9496
allErrs = append(allErrs, fmt.Errorf("networkName is a required field"))
9597
}
96-
if "" == spec.ClassName {
98+
if "" == v2.ClassName {
9799
allErrs = append(allErrs, fmt.Errorf("className is a required field"))
98100
}
99101

pkg/vsphere/machine_server_util.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,33 @@ func decodeProviderSpecAndSecret(machineClass *v1alpha1.MachineClass, secret *co
4343
}
4444

4545
if providerSpec.V1 != nil {
46-
err := validateSpec1(providerSpec.V1, secret)
46+
err := validateSpecV1(providerSpec, secret)
4747
return providerSpec, err
4848
}
4949

5050
if providerSpec.V2 != nil {
51-
err := validateSpec2(providerSpec.V2, secret)
51+
err := validateSpecV2(providerSpec, secret)
5252
return providerSpec, err
5353
}
5454

5555
return nil, fmt.Errorf("invalid providerSpec")
5656
}
5757

58-
// validateSpec1 validates api.VsphereProviderSpec1
59-
func validateSpec1(spec1 *api.VsphereProviderSpec1, secret *corev1.Secret) error {
58+
// validateSpecV1 validates api.VsphereProviderSpec1
59+
func validateSpecV1(spec *api.VsphereProviderSpec, secret *corev1.Secret) error {
6060
//Validate the Spec and Secrets
61-
ValidationErr := validation.ValidateVsphereProviderSpec1(spec1, secret)
61+
ValidationErr := validation.ValidateVsphereProviderSpec1(spec, secret)
6262
if ValidationErr != nil {
6363
err := fmt.Errorf("Error while validating ProviderSpec V1 %v", ValidationErr)
6464
return status.Error(codes.Internal, err.Error())
6565
}
6666
return nil
6767
}
6868

69-
// validateSpec2 validates api.VsphereProviderSpec2
70-
func validateSpec2(spec2 *api.VsphereProviderSpec2, secret *corev1.Secret) error {
69+
// validateSpecV2 validates api.VsphereProviderSpec2
70+
func validateSpecV2(spec *api.VsphereProviderSpec, secret *corev1.Secret) error {
7171
//Validate the Spec and Secrets
72-
ValidationErr := validation.ValidateVsphereProviderSpec2(spec2, secret)
72+
ValidationErr := validation.ValidateVsphereProviderSpec2(spec, secret)
7373
if ValidationErr != nil {
7474
err := fmt.Errorf("Error while validating ProviderSpec V2 %v", ValidationErr)
7575
return status.Error(codes.Internal, err.Error())

0 commit comments

Comments
 (0)