Skip to content

Commit a21569c

Browse files
committed
capi/aws: use struct as input to GenerateMachines
This makes it easier to keep track what each argument is, specially as we add more fields.
1 parent d7bdcdf commit a21569c

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

pkg/asset/machines/aws/awsmachines.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,28 @@ import (
1616
"github.com/openshift/installer/pkg/types/aws"
1717
)
1818

19+
// MachineInput defines the inputs needed to generate a machine asset.
20+
type MachineInput struct {
21+
Role string
22+
Pool *types.MachinePool
23+
Subnets map[string]string
24+
Tags map[string]string
25+
PublicIP bool
26+
}
27+
1928
// GenerateMachines returns manifests and runtime objects to provision the control plane (including bootstrap, if applicable) nodes using CAPI.
20-
func GenerateMachines(clusterID string, region string, subnets map[string]string, pool *types.MachinePool, role string, userTags map[string]string) ([]*asset.RuntimeFile, error) {
21-
if poolPlatform := pool.Platform.Name(); poolPlatform != aws.Name {
29+
func GenerateMachines(clusterID string, in *MachineInput) ([]*asset.RuntimeFile, error) {
30+
if poolPlatform := in.Pool.Platform.Name(); poolPlatform != aws.Name {
2231
return nil, fmt.Errorf("non-AWS machine-pool: %q", poolPlatform)
2332
}
24-
mpool := pool.Platform.AWS
33+
mpool := in.Pool.Platform.AWS
2534

2635
total := int64(1)
27-
if pool.Replicas != nil {
28-
total = *pool.Replicas
36+
if in.Pool.Replicas != nil {
37+
total = *in.Pool.Replicas
2938
}
3039

31-
tags, err := CapaTagsFromUserTags(clusterID, userTags)
40+
tags, err := CapaTagsFromUserTags(clusterID, in.Tags)
3241
if err != nil {
3342
return nil, fmt.Errorf("failed to create machineapi.TagSpecifications from UserTags: %w", err)
3443
}
@@ -37,8 +46,8 @@ func GenerateMachines(clusterID string, region string, subnets map[string]string
3746

3847
for idx := int64(0); idx < total; idx++ {
3948
zone := mpool.Zones[int(idx)%len(mpool.Zones)]
40-
subnetID, ok := subnets[zone]
41-
if len(subnets) > 0 && !ok {
49+
subnetID, ok := in.Subnets[zone]
50+
if len(in.Subnets) > 0 && !ok {
4251
return nil, fmt.Errorf("no subnet for zone %s", zone)
4352
}
4453
subnet := &capa.AWSResourceReference{}
@@ -55,7 +64,7 @@ func GenerateMachines(clusterID string, region string, subnets map[string]string
5564

5665
awsMachine := &capa.AWSMachine{
5766
ObjectMeta: metav1.ObjectMeta{
58-
Name: fmt.Sprintf("%s-%s-%d", clusterID, pool.Name, idx),
67+
Name: fmt.Sprintf("%s-%s-%d", clusterID, in.Pool.Name, idx),
5968
Labels: map[string]string{
6069
"cluster.x-k8s.io/control-plane": "",
6170
},
@@ -103,7 +112,7 @@ func GenerateMachines(clusterID string, region string, subnets map[string]string
103112
Spec: capi.MachineSpec{
104113
ClusterName: clusterID,
105114
Bootstrap: capi.Bootstrap{
106-
DataSecretName: ptr.To(fmt.Sprintf("%s-%s", clusterID, role)),
115+
DataSecretName: ptr.To(fmt.Sprintf("%s-%s", clusterID, in.Role)),
107116
},
108117
InfrastructureRef: v1.ObjectReference{
109118
APIVersion: capa.GroupVersion.String(),

pkg/asset/machines/clusterapi.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ func (c *ClusterAPI) Generate(dependencies asset.Parents) error {
146146
}
147147

148148
pool.Platform.AWS = &mpool
149-
awsMachines, err := aws.GenerateMachines(
150-
clusterID.InfraID,
151-
installConfig.Config.Platform.AWS.Region,
152-
subnets,
153-
&pool,
154-
"master",
155-
installConfig.Config.Platform.AWS.UserTags,
149+
awsMachines, err := aws.GenerateMachines(clusterID.InfraID, &aws.MachineInput{
150+
Role: "master",
151+
Pool: &pool,
152+
Subnets: subnets,
153+
Tags: installConfig.Config.AWS.UserTags,
154+
PublicIP: false,
155+
},
156156
)
157157
if err != nil {
158158
return errors.Wrap(err, "failed to create master machine objects")

0 commit comments

Comments
 (0)