Skip to content

Commit 4475fa7

Browse files
authored
Merge pull request #4254 from SD-13/kind_name_constants
Add constants for kind names
2 parents 3973bb6 + 6d87438 commit 4475fa7

36 files changed

+74
-61
lines changed

api/v1beta1/azurecluster_default_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func TestVnetDefaults(t *testing.T) {
145145
},
146146
AzureClusterClassSpec: AzureClusterClassSpec{
147147
IdentityRef: &corev1.ObjectReference{
148-
Kind: "AzureClusterIdentity",
148+
Kind: AzureClusterIdentityKind,
149149
},
150150
},
151151
},
@@ -161,7 +161,7 @@ func TestVnetDefaults(t *testing.T) {
161161
ResourceGroup: "cluster-test",
162162
AzureClusterClassSpec: AzureClusterClassSpec{
163163
IdentityRef: &corev1.ObjectReference{
164-
Kind: "AzureClusterIdentity",
164+
Kind: AzureClusterIdentityKind,
165165
},
166166
},
167167
},
@@ -183,7 +183,7 @@ func TestVnetDefaults(t *testing.T) {
183183
},
184184
AzureClusterClassSpec: AzureClusterClassSpec{
185185
IdentityRef: &corev1.ObjectReference{
186-
Kind: "AzureClusterIdentity",
186+
Kind: AzureClusterIdentityKind,
187187
},
188188
},
189189
},
@@ -206,7 +206,7 @@ func TestVnetDefaults(t *testing.T) {
206206
},
207207
AzureClusterClassSpec: AzureClusterClassSpec{
208208
IdentityRef: &corev1.ObjectReference{
209-
Kind: "AzureClusterIdentity",
209+
Kind: AzureClusterIdentityKind,
210210
},
211211
},
212212
},
@@ -228,7 +228,7 @@ func TestVnetDefaults(t *testing.T) {
228228
},
229229
AzureClusterClassSpec: AzureClusterClassSpec{
230230
IdentityRef: &corev1.ObjectReference{
231-
Kind: "AzureClusterIdentity",
231+
Kind: AzureClusterIdentityKind,
232232
},
233233
},
234234
},
@@ -251,7 +251,7 @@ func TestVnetDefaults(t *testing.T) {
251251
},
252252
AzureClusterClassSpec: AzureClusterClassSpec{
253253
IdentityRef: &corev1.ObjectReference{
254-
Kind: "AzureClusterIdentity",
254+
Kind: AzureClusterIdentityKind,
255255
},
256256
},
257257
},
@@ -273,7 +273,7 @@ func TestVnetDefaults(t *testing.T) {
273273
},
274274
AzureClusterClassSpec: AzureClusterClassSpec{
275275
IdentityRef: &corev1.ObjectReference{
276-
Kind: "AzureClusterIdentity",
276+
Kind: AzureClusterIdentityKind,
277277
},
278278
},
279279
},

api/v1beta1/azurecluster_validation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (c *AzureCluster) validateCluster(old *AzureCluster) (admission.Warnings, e
7979
}
8080

8181
return nil, apierrors.NewInvalid(
82-
schema.GroupKind{Group: "infrastructure.cluster.x-k8s.io", Kind: "AzureCluster"},
82+
schema.GroupKind{Group: "infrastructure.cluster.x-k8s.io", Kind: AzureClusterKind},
8383
c.Name, allErrs)
8484
}
8585

@@ -147,7 +147,7 @@ func validateIdentityRef(identityRef *corev1.ObjectReference, fldPath *field.Pat
147147
if identityRef == nil {
148148
return field.Required(fldPath, "identityRef is required")
149149
}
150-
if identityRef.Kind != "AzureClusterIdentity" {
150+
if identityRef.Kind != AzureClusterIdentityKind {
151151
return field.NotSupported(fldPath.Child("name"), identityRef.Name, []string{"AzureClusterIdentity"})
152152
}
153153
return nil

api/v1beta1/azurecluster_validation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,7 @@ func createValidCluster() *AzureCluster {
13121312
NetworkSpec: createValidNetworkSpec(),
13131313
AzureClusterClassSpec: AzureClusterClassSpec{
13141314
IdentityRef: &corev1.ObjectReference{
1315-
Kind: "AzureClusterIdentity",
1315+
Kind: AzureClusterIdentityKind,
13161316
},
13171317
},
13181318
},

api/v1beta1/azurecluster_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (c *AzureCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings
136136
return c.validateCluster(old)
137137
}
138138

139-
return nil, apierrors.NewInvalid(GroupVersion.WithKind("AzureCluster").GroupKind(), c.Name, allErrs)
139+
return nil, apierrors.NewInvalid(GroupVersion.WithKind(AzureClusterKind).GroupKind(), c.Name, allErrs)
140140
}
141141

142142
// validateSubnetUpdate validates a ClusterSpec.NetworkSpec.Subnets for immutability.

api/v1beta1/azureclusteridentity_validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ func (c *AzureClusterIdentity) validateClusterIdentity() (admission.Warnings, er
3232
if len(allErrs) == 0 {
3333
return nil, nil
3434
}
35-
return nil, apierrors.NewInvalid(GroupVersion.WithKind("AzureClusterIdentity").GroupKind(), c.Name, allErrs)
35+
return nil, apierrors.NewInvalid(GroupVersion.WithKind(AzureClusterIdentityKind).GroupKind(), c.Name, allErrs)
3636
}

api/v1beta1/azureclusteridentity_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (c *AzureClusterIdentity) ValidateUpdate(oldRaw runtime.Object) (admission.
5555
if len(allErrs) == 0 {
5656
return c.validateClusterIdentity()
5757
}
58-
return nil, apierrors.NewInvalid(GroupVersion.WithKind("AzureClusterIdentity").GroupKind(), c.Name, allErrs)
58+
return nil, apierrors.NewInvalid(GroupVersion.WithKind(AzureClusterIdentityKind).GroupKind(), c.Name, allErrs)
5959
}
6060

6161
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.

api/v1beta1/azuremachine_default_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ func (m mockClient) Get(ctx context.Context, key client.ObjectKey, obj client.Ob
567567
case *clusterv1.Cluster:
568568
obj.Spec = clusterv1.ClusterSpec{
569569
InfrastructureRef: &corev1.ObjectReference{
570-
Kind: "AzureCluster",
570+
Kind: AzureClusterKind,
571571
Name: "test-cluster",
572572
Namespace: "default",
573573
},

api/v1beta1/azuremachine_webhook_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ func (m mockDefaultClient) Get(ctx context.Context, key client.ObjectKey, obj cl
832832
obj.Spec.SubscriptionID = m.SubscriptionID
833833
case *clusterv1.Cluster:
834834
obj.Spec.InfrastructureRef = &corev1.ObjectReference{
835-
Kind: "AzureCluster",
835+
Kind: AzureClusterKind,
836836
Name: "test-cluster",
837837
}
838838
default:

api/v1beta1/azuremanagedcontrolplane_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func (mw *azureManagedControlPlaneWebhook) ValidateUpdate(ctx context.Context, o
264264
return nil, m.Validate(mw.Client)
265265
}
266266

267-
return nil, apierrors.NewInvalid(GroupVersion.WithKind("AzureManagedControlPlane").GroupKind(), m.Name, allErrs)
267+
return nil, apierrors.NewInvalid(GroupVersion.WithKind(AzureManagedControlPlaneKind).GroupKind(), m.Name, allErrs)
268268
}
269269

270270
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.

api/v1beta1/consts.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,16 @@ const (
158158
// value for the label is the CAPI Cluster Name.
159159
OwnedByClusterLabelKey = NameAzureProviderPrefix + string(ResourceLifecycleOwned)
160160
)
161+
162+
const (
163+
// AzureClusterKind indicates the kind of an AzureCluster.
164+
AzureClusterKind = "AzureCluster"
165+
// AzureMachinePoolKind indicates the kind of an AzureMachinePool.
166+
AzureMachinePoolKind = "AzureMachinePool"
167+
// AzureManagedClusterKind indicates the kind of an AzureManagedCluster.
168+
AzureManagedClusterKind = "AzureManagedCluster"
169+
// AzureManagedControlPlaneKind indicates the kind of an AzureManagedControlPlane.
170+
AzureManagedControlPlaneKind = "AzureManagedControlPlane"
171+
// AzureClusterIdentityKind indicates the kind of an AzureClusterIdentity.
172+
AzureClusterIdentityKind = "AzureClusterIdentity"
173+
)

0 commit comments

Comments
 (0)