Skip to content

Commit 9d34ea6

Browse files
committed
fixup! refactor: Create placementGroup struct
1 parent 18fbdf7 commit 9d34ea6

File tree

9 files changed

+94
-23
lines changed

9 files changed

+94
-23
lines changed

api/v1alpha1/aws_node_types.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,21 @@ type AWSGenericNodeSpec struct {
3939
// +kubebuilder:validation:Optional
4040
AdditionalSecurityGroups AdditionalSecurityGroup `json:"additionalSecurityGroups,omitempty"`
4141

42-
// PlacementGroupName specifies the name of the placement group in which to launch nodes from this nodepool.
42+
// PlacementGroup specifies the placement group in which to launch the instance.
4343
// +kubebuilder:validation:Optional
44-
// +kubebuilder:validation:MinLength=1
45-
// +kubebuilder:validation:MaxLength=255
46-
PlacementGroupName string `json:"placementGroupName,omitempty"`
44+
PlacementGroup *PlacementGroup `json:"placementGroupName,omitempty"`
4745
}
4846

4947
type AdditionalSecurityGroup []SecurityGroup
5048

49+
type PlacementGroup struct {
50+
// Name is the name of the placement group.
51+
// +kubebuilder:validation:Required
52+
// +kubebuilder:validation:MinLength=1
53+
// +kubebuilder:validation:MaxLength=255
54+
Name string `json:"name"`
55+
}
56+
5157
type SecurityGroup struct {
5258
// ID is the id of the security group
5359
// +kubebuilder:validation:Optional

api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,16 @@ spec:
388388
default: m5.xlarge
389389
type: string
390390
placementGroupName:
391-
description: PlacementGroupName specifies the name of the placement group in which to launch nodes from this nodepool.
392-
maxLength: 255
393-
minLength: 1
394-
type: string
391+
description: PlacementGroup specifies the placement group in which to launch the instance.
392+
properties:
393+
name:
394+
description: Name is the name of the placement group.
395+
maxLength: 255
396+
minLength: 1
397+
type: string
398+
required:
399+
- name
400+
type: object
395401
type: object
396402
nodeRegistration:
397403
default: {}

api/v1alpha1/crds/caren.nutanix.com_awsworkernodeconfigs.yaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,17 @@ spec:
9090
description: The AWS instance type to use for the cluster Machines.
9191
type: string
9292
placementGroupName:
93-
description: PlacementGroupName specifies the name of the placement
94-
group in which to launch nodes from this nodepool.
95-
maxLength: 255
96-
minLength: 1
97-
type: string
93+
description: PlacementGroup specifies the placement group in which
94+
to launch the instance.
95+
properties:
96+
name:
97+
description: Name is the name of the placement group.
98+
maxLength: 255
99+
minLength: 1
100+
type: string
101+
required:
102+
- name
103+
type: object
98104
type: object
99105
nodeRegistration:
100106
default: {}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/handlers/aws/mutation/placementgroup/inject_control_plane.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
const (
2424
// VariableName is the external patch variable name.
25-
VariableName = "placementGroupName"
25+
VariableName = "placementGroup"
2626
)
2727

2828
type awsPlacementGroupControlPlanePatchHandler struct {
@@ -61,7 +61,7 @@ func (h *awsPlacementGroupControlPlanePatchHandler) Mutate(
6161
"holderRef", holderRef,
6262
)
6363

64-
placementGroupNameVar, err := variables.Get[string](
64+
placementGroupVar, err := variables.Get[v1alpha1.PlacementGroup](
6565
vars,
6666
h.variableName,
6767
h.variableFieldPath...,
@@ -80,7 +80,7 @@ func (h *awsPlacementGroupControlPlanePatchHandler) Mutate(
8080
"variableFieldPath",
8181
h.variableFieldPath,
8282
"variableValue",
83-
placementGroupNameVar,
83+
placementGroupVar,
8484
)
8585

8686
return patches.MutateIfApplicable(
@@ -98,7 +98,7 @@ func (h *awsPlacementGroupControlPlanePatchHandler) Mutate(
9898
"patchedObjectName", client.ObjectKeyFromObject(obj),
9999
).Info("setting placement group in control plane AWSMachineTemplate spec")
100100

101-
obj.Spec.Template.Spec.PlacementGroupName = placementGroupNameVar
101+
obj.Spec.Template.Spec.PlacementGroupName = placementGroupVar.Name
102102

103103
return nil
104104
},

pkg/handlers/aws/mutation/placementgroup/inject_control_plane_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var _ = Describe("Generate PlacementGroup patches for ControlPlane", func() {
3333
Vars: []runtimehooksv1.Variable{
3434
capitest.VariableWithValue(
3535
v1alpha1.ClusterConfigVariableName,
36-
"pg-1234",
36+
v1alpha1.PlacementGroup{Name: "pg-1234"},
3737
v1alpha1.ControlPlaneConfigVariableName,
3838
v1alpha1.AWSVariableName,
3939
VariableName,

pkg/handlers/aws/mutation/placementgroup/inject_worker.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (h *awsPlacementGroupWorkerPatchHandler) Mutate(
5555
"holderRef", holderRef,
5656
)
5757

58-
placementGroupNameVar, err := variables.Get[string](
58+
placementGroupVar, err := variables.Get[v1alpha1.PlacementGroup](
5959
vars,
6060
h.variableName,
6161
h.variableFieldPath...,
@@ -74,7 +74,7 @@ func (h *awsPlacementGroupWorkerPatchHandler) Mutate(
7474
"variableFieldPath",
7575
h.variableFieldPath,
7676
"variableValue",
77-
placementGroupNameVar,
77+
placementGroupVar,
7878
)
7979

8080
return patches.MutateIfApplicable(
@@ -92,7 +92,7 @@ func (h *awsPlacementGroupWorkerPatchHandler) Mutate(
9292
"patchedObjectName", client.ObjectKeyFromObject(obj),
9393
).Info("setting placement group in workers AWSMachineTemplate spec")
9494

95-
obj.Spec.Template.Spec.PlacementGroupName = placementGroupNameVar
95+
obj.Spec.Template.Spec.PlacementGroupName = placementGroupVar.Name
9696

9797
return nil
9898
},

pkg/handlers/aws/mutation/placementgroup/inject_worker_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var _ = Describe("Generate PlacementGroup patches for Worker", func() {
3030
Vars: []runtimehooksv1.Variable{
3131
capitest.VariableWithValue(
3232
v1alpha1.WorkerConfigVariableName,
33-
"pg-1234",
33+
v1alpha1.PlacementGroup{Name: "pg-1234"},
3434
v1alpha1.AWSVariableName,
3535
VariableName,
3636
),

pkg/handlers/aws/mutation/placementgroup/variables_test.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package placementgroup
55

66
import (
7+
"strings"
78
"testing"
89

910
"k8s.io/utils/ptr"
@@ -26,11 +27,43 @@ func TestVariableValidation(t *testing.T) {
2627
ControlPlane: &v1alpha1.AWSControlPlaneSpec{
2728
AWS: &v1alpha1.AWSControlPlaneNodeSpec{
2829
AWSGenericNodeSpec: v1alpha1.AWSGenericNodeSpec{
29-
PlacementGroupName: "pg-1234",
30+
PlacementGroup: &v1alpha1.PlacementGroup{
31+
Name: "pg-1234",
32+
},
3033
},
3134
},
3235
},
3336
},
3437
},
38+
capitest.VariableTestDef{
39+
Name: "specified empty group name",
40+
Vals: v1alpha1.AWSClusterConfigSpec{
41+
ControlPlane: &v1alpha1.AWSControlPlaneSpec{
42+
AWS: &v1alpha1.AWSControlPlaneNodeSpec{
43+
AWSGenericNodeSpec: v1alpha1.AWSGenericNodeSpec{
44+
PlacementGroup: &v1alpha1.PlacementGroup{
45+
Name: "",
46+
},
47+
},
48+
},
49+
},
50+
},
51+
ExpectError: true,
52+
},
53+
capitest.VariableTestDef{
54+
Name: "specified too long placement group name",
55+
Vals: v1alpha1.AWSClusterConfigSpec{
56+
ControlPlane: &v1alpha1.AWSControlPlaneSpec{
57+
AWS: &v1alpha1.AWSControlPlaneNodeSpec{
58+
AWSGenericNodeSpec: v1alpha1.AWSGenericNodeSpec{
59+
PlacementGroup: &v1alpha1.PlacementGroup{
60+
Name: strings.Repeat("a", 256), // 256 characters long
61+
},
62+
},
63+
},
64+
},
65+
},
66+
ExpectError: true,
67+
},
3568
)
3669
}

0 commit comments

Comments
 (0)