Skip to content

Commit 90b76d3

Browse files
authored
Refactored codebase to use camel case for spec parameter in field.NewPath method (#4878)
* refactored field newPath method to use camel case for spec * reformated code * resolved comments
1 parent 287fa1f commit 90b76d3

12 files changed

+212
-212
lines changed

api/v1beta1/azurecluster_validation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (c *AzureCluster) validateClusterSpec(old *AzureCluster) field.ErrorList {
101101

102102
// If ClusterSpec has non-nil ExtendedLocation field but not enable EdgeZone feature gate flag, ClusterSpec validation failed.
103103
if !feature.Gates.Enabled(feature.EdgeZone) && c.Spec.ExtendedLocation != nil {
104-
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "ExtendedLocation"), "can be set only if the EdgeZone feature flag is enabled"))
104+
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "extendedLocation"), "can be set only if the EdgeZone feature flag is enabled"))
105105
}
106106

107107
if err := validateBastionSpec(c.Spec.BastionSpec, field.NewPath("spec").Child("azureBastion").Child("bastionSpec")); err != nil {
@@ -123,7 +123,7 @@ func (c *AzureCluster) validateClusterName() field.ErrorList {
123123
fmt.Sprintf("Cluster Name longer than allowed length of %d characters", clusterNameMaxLength)))
124124
}
125125
if success, _ := regexp.MatchString(clusterNameRegex, c.Name); !success {
126-
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata").Child("Name"), c.Name,
126+
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata").Child("name"), c.Name,
127127
fmt.Sprintf("Cluster Name doesn't match regex %s, can contain only lowercase alphanumeric characters and '-', must start/end with an alphanumeric character",
128128
clusterNameRegex)))
129129
}

api/v1beta1/azurecluster_webhook.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,36 +57,36 @@ func (c *AzureCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings
5757
old := oldRaw.(*AzureCluster)
5858

5959
if err := webhookutils.ValidateImmutable(
60-
field.NewPath("Spec", "ResourceGroup"),
60+
field.NewPath("spec", "resourceGroup"),
6161
old.Spec.ResourceGroup,
6262
c.Spec.ResourceGroup); err != nil {
6363
allErrs = append(allErrs, err)
6464
}
6565

6666
if err := webhookutils.ValidateImmutable(
67-
field.NewPath("Spec", "SubscriptionID"),
67+
field.NewPath("spec", "subscriptionID"),
6868
old.Spec.SubscriptionID,
6969
c.Spec.SubscriptionID); err != nil {
7070
allErrs = append(allErrs, err)
7171
}
7272

7373
if err := webhookutils.ValidateImmutable(
74-
field.NewPath("Spec", "Location"),
74+
field.NewPath("spec", "location"),
7575
old.Spec.Location,
7676
c.Spec.Location); err != nil {
7777
allErrs = append(allErrs, err)
7878
}
7979

8080
if old.Spec.ControlPlaneEndpoint.Host != "" && c.Spec.ControlPlaneEndpoint.Host != old.Spec.ControlPlaneEndpoint.Host {
8181
allErrs = append(allErrs,
82-
field.Invalid(field.NewPath("spec", "ControlPlaneEndpoint", "Host"),
82+
field.Invalid(field.NewPath("spec", "controlPlaneEndpoint", "host"),
8383
c.Spec.ControlPlaneEndpoint.Host, "field is immutable"),
8484
)
8585
}
8686

8787
if old.Spec.ControlPlaneEndpoint.Port != 0 && c.Spec.ControlPlaneEndpoint.Port != old.Spec.ControlPlaneEndpoint.Port {
8888
allErrs = append(allErrs,
89-
field.Invalid(field.NewPath("spec", "ControlPlaneEndpoint", "Port"),
89+
field.Invalid(field.NewPath("spec", "controlPlaneEndpoint", "port"),
9090
c.Spec.ControlPlaneEndpoint.Port, "field is immutable"),
9191
)
9292
}
@@ -102,14 +102,14 @@ func (c *AzureCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings
102102
// if it's still not equal, return error.
103103
if !reflect.DeepEqual(c.Spec.AzureEnvironment, old.Spec.AzureEnvironment) {
104104
allErrs = append(allErrs,
105-
field.Invalid(field.NewPath("spec", "AzureEnvironment"),
105+
field.Invalid(field.NewPath("spec", "azureEnvironment"),
106106
c.Spec.AzureEnvironment, "field is immutable"),
107107
)
108108
}
109109
}
110110

111111
if err := webhookutils.ValidateImmutable(
112-
field.NewPath("Spec", "NetworkSpec", "PrivateDNSZoneName"),
112+
field.NewPath("spec", "networkSpec", "privateDNSZoneName"),
113113
old.Spec.NetworkSpec.PrivateDNSZoneName,
114114
c.Spec.NetworkSpec.PrivateDNSZoneName); err != nil {
115115
allErrs = append(allErrs, err)
@@ -118,13 +118,13 @@ func (c *AzureCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings
118118
// Allow enabling azure bastion but avoid disabling it.
119119
if old.Spec.BastionSpec.AzureBastion != nil && !reflect.DeepEqual(old.Spec.BastionSpec.AzureBastion, c.Spec.BastionSpec.AzureBastion) {
120120
allErrs = append(allErrs,
121-
field.Invalid(field.NewPath("spec", "BastionSpec", "AzureBastion"),
121+
field.Invalid(field.NewPath("spec", "bastionSpec", "azureBastion"),
122122
c.Spec.BastionSpec.AzureBastion, "azure bastion cannot be removed from a cluster"),
123123
)
124124
}
125125

126126
if err := webhookutils.ValidateImmutable(
127-
field.NewPath("Spec", "NetworkSpec", "ControlPlaneOutboundLB"),
127+
field.NewPath("spec", "networkSpec", "controlPlaneOutboundLB"),
128128
old.Spec.NetworkSpec.ControlPlaneOutboundLB,
129129
c.Spec.NetworkSpec.ControlPlaneOutboundLB); err != nil {
130130
allErrs = append(allErrs, err)

api/v1beta1/azuremachine_validation.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ func ValidateSystemAssignedIdentityRole(identityType VMIdentity, roleAssignmentN
162162
}
163163
if identityType == VMIdentitySystemAssigned {
164164
if role.DefinitionID == "" {
165-
allErrs = append(allErrs, field.Invalid(field.NewPath("Spec", "SystemAssignedIdentityRole", "DefinitionID"), role.DefinitionID, "the definitionID field cannot be empty"))
165+
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "systemAssignedIdentityRole", "definitionID"), role.DefinitionID, "the definitionID field cannot be empty"))
166166
}
167167
if role.Scope == "" {
168-
allErrs = append(allErrs, field.Invalid(field.NewPath("Spec", "SystemAssignedIdentityRole", "Scope"), role.Scope, "the scope field cannot be empty"))
168+
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "systemAssignedIdentityRole", "scope"), role.Scope, "the scope field cannot be empty"))
169169
}
170170
}
171171
if identityType != VMIdentitySystemAssigned && role != nil {
172-
allErrs = append(allErrs, field.Forbidden(field.NewPath("Spec", "Role"), "systemAssignedIdentityRole can only be set when identity is set to SystemAssigned"))
172+
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "role"), "systemAssignedIdentityRole can only be set when identity is set to SystemAssigned"))
173173
}
174174
return allErrs
175175
}
@@ -482,7 +482,7 @@ func ValidateVMExtensions(disableExtensionOperations *bool, vmExtensions []VMExt
482482
allErrs := field.ErrorList{}
483483

484484
if ptr.Deref(disableExtensionOperations, false) && len(vmExtensions) > 0 {
485-
allErrs = append(allErrs, field.Forbidden(field.NewPath("AzureMachineTemplate", "spec", "template", "spec", "VMExtensions"), "VMExtensions must be empty when DisableExtensionOperations is true"))
485+
allErrs = append(allErrs, field.Forbidden(field.NewPath("AzureMachineTemplate", "spec", "template", "spec", "vmExtensions"), "VMExtensions must be empty when DisableExtensionOperations is true"))
486486
}
487487

488488
return allErrs

api/v1beta1/azuremachine_webhook.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,70 +86,70 @@ func (mw *azureMachineWebhook) ValidateUpdate(ctx context.Context, oldObj, newOb
8686
}
8787

8888
if err := webhookutils.ValidateImmutable(
89-
field.NewPath("Spec", "Image"),
89+
field.NewPath("spec", "image"),
9090
old.Spec.Image,
9191
m.Spec.Image); err != nil {
9292
allErrs = append(allErrs, err)
9393
}
9494

9595
if err := webhookutils.ValidateImmutable(
96-
field.NewPath("Spec", "Identity"),
96+
field.NewPath("spec", "identity"),
9797
old.Spec.Identity,
9898
m.Spec.Identity); err != nil {
9999
allErrs = append(allErrs, err)
100100
}
101101

102102
if err := webhookutils.ValidateImmutable(
103-
field.NewPath("Spec", "SystemAssignedIdentityRole"),
103+
field.NewPath("spec", "systemAssignedIdentityRole"),
104104
old.Spec.SystemAssignedIdentityRole,
105105
m.Spec.SystemAssignedIdentityRole); err != nil {
106106
allErrs = append(allErrs, err)
107107
}
108108

109109
if err := webhookutils.ValidateImmutable(
110-
field.NewPath("Spec", "UserAssignedIdentities"),
110+
field.NewPath("spec", "userAssignedIdentities"),
111111
old.Spec.UserAssignedIdentities,
112112
m.Spec.UserAssignedIdentities); err != nil {
113113
allErrs = append(allErrs, err)
114114
}
115115

116116
if err := webhookutils.ValidateImmutable(
117-
field.NewPath("Spec", "RoleAssignmentName"),
117+
field.NewPath("spec", "roleAssignmentName"),
118118
old.Spec.RoleAssignmentName,
119119
m.Spec.RoleAssignmentName); err != nil {
120120
allErrs = append(allErrs, err)
121121
}
122122

123123
if err := webhookutils.ValidateImmutable(
124-
field.NewPath("Spec", "OSDisk"),
124+
field.NewPath("spec", "osDisk"),
125125
old.Spec.OSDisk,
126126
m.Spec.OSDisk); err != nil {
127127
allErrs = append(allErrs, err)
128128
}
129129

130130
if err := webhookutils.ValidateImmutable(
131-
field.NewPath("Spec", "DataDisks"),
131+
field.NewPath("spec", "dataDisks"),
132132
old.Spec.DataDisks,
133133
m.Spec.DataDisks); err != nil {
134134
allErrs = append(allErrs, err)
135135
}
136136

137137
if err := webhookutils.ValidateImmutable(
138-
field.NewPath("Spec", "SSHPublicKey"),
138+
field.NewPath("spec", "sshPublicKey"),
139139
old.Spec.SSHPublicKey,
140140
m.Spec.SSHPublicKey); err != nil {
141141
allErrs = append(allErrs, err)
142142
}
143143

144144
if err := webhookutils.ValidateImmutable(
145-
field.NewPath("Spec", "AllocatePublicIP"),
145+
field.NewPath("spec", "allocatePublicIP"),
146146
old.Spec.AllocatePublicIP,
147147
m.Spec.AllocatePublicIP); err != nil {
148148
allErrs = append(allErrs, err)
149149
}
150150

151151
if err := webhookutils.ValidateImmutable(
152-
field.NewPath("Spec", "EnableIPForwarding"),
152+
field.NewPath("spec", "enableIPForwarding"),
153153
old.Spec.EnableIPForwarding,
154154
m.Spec.EnableIPForwarding); err != nil {
155155
allErrs = append(allErrs, err)
@@ -181,7 +181,7 @@ func (mw *azureMachineWebhook) ValidateUpdate(ctx context.Context, oldObj, newOb
181181

182182
if old.Spec.Diagnostics != nil {
183183
if err := webhookutils.ValidateImmutable(
184-
field.NewPath("Spec", "Diagnostics"),
184+
field.NewPath("spec", "diagnostics"),
185185
old.Spec.Diagnostics,
186186
m.Spec.Diagnostics); err != nil {
187187
allErrs = append(allErrs, err)

api/v1beta1/azuremachinetemplate_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (r *AzureMachineTemplate) ValidateCreate(ctx context.Context, obj runtime.O
8787
}
8888

8989
if ptr.Deref(r.Spec.Template.Spec.DisableExtensionOperations, false) && len(r.Spec.Template.Spec.VMExtensions) > 0 {
90-
allErrs = append(allErrs, field.Forbidden(field.NewPath("AzureMachineTemplate", "spec", "template", "spec", "VMExtensions"), "VMExtensions must be empty when DisableExtensionOperations is true"))
90+
allErrs = append(allErrs, field.Forbidden(field.NewPath("AzureMachineTemplate", "spec", "template", "spec", "vmExtensions"), "VMExtensions must be empty when DisableExtensionOperations is true"))
9191
}
9292

9393
if len(allErrs) == 0 {

0 commit comments

Comments
 (0)