Skip to content

Commit 6ef9746

Browse files
machineSets: add os-stream label to machineSets and machines for aws
1 parent f60f85a commit 6ef9746

5 files changed

Lines changed: 29 additions & 3 deletions

File tree

pkg/asset/machines/aws/machines.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type machineProviderInput struct {
4141
}
4242

4343
// Machines returns a list of machines for a machinepool.
44+
// func Machines(clusterID string, region string, subnets aws.SubnetsByZone, pool *types.MachinePool, role, userDataSecret string, userTags map[string]string, publicSubnet bool, osImageStream string) ([]machineapi.Machine, *machinev1.ControlPlaneMachineSet, error) {
4445
func Machines(clusterID string, region string, subnets aws.SubnetsByZone, pool *types.MachinePool, role, userDataSecret string, userTags map[string]string, publicSubnet bool) ([]machineapi.Machine, *machinev1.ControlPlaneMachineSet, error) {
4546
if poolPlatform := pool.Platform.Name(); poolPlatform != awstypes.Name {
4647
return nil, nil, fmt.Errorf("non-AWS machine-pool: %q", poolPlatform)
@@ -98,6 +99,9 @@ func Machines(clusterID string, region string, subnets aws.SubnetsByZone, pool *
9899
"machine.openshift.io/cluster-api-cluster": clusterID,
99100
"machine.openshift.io/cluster-api-machine-role": role,
100101
"machine.openshift.io/cluster-api-machine-type": role,
102+
// TODO: understand if the label needs to be set here or if just setting it in
103+
// the MachineSet's Spec.Template.ObjectMeta.Labels is enough.
104+
// "machine.openshift.io/os-image-stream": osImageStream,
101105
},
102106
},
103107
Spec: machineapi.MachineSpec{
@@ -177,6 +181,8 @@ func Machines(clusterID string, region string, subnets aws.SubnetsByZone, pool *
177181
"machine.openshift.io/cluster-api-cluster": clusterID,
178182
"machine.openshift.io/cluster-api-machine-role": role,
179183
"machine.openshift.io/cluster-api-machine-type": role,
184+
// TODO: see if we need these labels on CPMSs
185+
// "machine.openshift.io/os-image-stream": osImageStream,
180186
},
181187
},
182188
Spec: machineapi.MachineSpec{

pkg/asset/machines/aws/machinesets.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type MachineSetInput struct {
2626
Role string
2727
UserDataSecret string
2828
Hosts map[string]icaws.Host
29+
OSImageStream string
2930
}
3031

3132
// MachineSets returns a list of machinesets for a machinepool.
@@ -48,7 +49,7 @@ func MachineSets(in *MachineSetInput) ([]*machineapi.MachineSet, error) {
4849
replicas++
4950
}
5051

51-
nodeLabels := make(map[string]string, 3)
52+
machineSpecLabels := make(map[string]string, 3)
5253
nodeTaints := []corev1.Taint{}
5354
instanceType := mpool.InstanceType
5455
publicSubnet := in.PublicSubnet
@@ -71,7 +72,7 @@ func MachineSets(in *MachineSetInput) ([]*machineapi.MachineSet, error) {
7172
if zone.PreferredInstanceType != "" {
7273
instanceType = zone.PreferredInstanceType
7374
}
74-
nodeLabels = map[string]string{
75+
machineSpecLabels = map[string]string{
7576
"node-role.kubernetes.io/edge": "",
7677
"machine.openshift.io/zone-type": zone.Type,
7778
"machine.openshift.io/zone-group": zone.GroupName,
@@ -112,13 +113,16 @@ func MachineSets(in *MachineSetInput) ([]*machineapi.MachineSet, error) {
112113
return nil, errors.Wrap(err, "failed to create provider")
113114
}
114115

116+
// TODO: use const for label
117+
machineSpecLabels["machine.openshift.io/os-image-stream"] = in.OSImageStream
118+
115119
name := fmt.Sprintf("%s-%s-%s", in.ClusterID, in.Pool.Name, az)
116120
spec := machineapi.MachineSpec{
117121
ProviderSpec: machineapi.ProviderSpec{
118122
Value: &runtime.RawExtension{Object: provider},
119123
},
120124
ObjectMeta: machineapi.ObjectMeta{
121-
Labels: nodeLabels,
125+
Labels: machineSpecLabels,
122126
},
123127
Taints: nodeTaints,
124128
}
@@ -150,6 +154,7 @@ func MachineSets(in *MachineSetInput) ([]*machineapi.MachineSet, error) {
150154
"machine.openshift.io/cluster-api-cluster": in.ClusterID,
151155
"machine.openshift.io/cluster-api-machine-role": in.Role,
152156
"machine.openshift.io/cluster-api-machine-type": in.Role,
157+
"machine.openshift.io/os-image-stream": in.OSImageStream,
153158
},
154159
},
155160
Spec: spec,

pkg/asset/machines/master.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ func (m *Master) Generate(ctx context.Context, dependencies asset.Parents) error
268268
masterUserDataSecretName,
269269
installConfig.Config.Platform.AWS.UserTags,
270270
awstypes.IsPublicOnlySubnetsEnabled(),
271+
// GetOSImageStream(ic),
271272
)
272273
if err != nil {
273274
return errors.Wrap(err, "failed to create master machine objects")

pkg/asset/machines/util.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/openshift/installer/pkg/asset/installconfig"
1212
"github.com/openshift/installer/pkg/asset/machines/machineconfig"
1313
"github.com/openshift/installer/pkg/asset/machines/vsphere"
14+
"github.com/openshift/installer/pkg/rhcos"
1415
"github.com/openshift/installer/pkg/types"
1516
azuretypes "github.com/openshift/installer/pkg/types/azure"
1617
vspheretypes "github.com/openshift/installer/pkg/types/vsphere"
@@ -19,6 +20,9 @@ import (
1920
const (
2021
// VsphereScsiByPath defines the path format for vsphere disks being added.
2122
VsphereScsiByPath = "/dev/disk/by-path/pci-0000:03:00.0-scsi-0:0:%d:0"
23+
24+
// OSImageStreamLabel is the label key used to identify the OS image stream for a machine.
25+
OSImageStreamLabel = "machine.openshift.io/os-image-stream"
2226
)
2327

2428
// NodeDiskSetup determines the path per disk type, and per platform and role, runs ForDiskSetup.
@@ -71,3 +75,12 @@ func NodeDiskSetup(installConfig *installconfig.InstallConfig, role string, disk
7175
}
7276
return nil, nil
7377
}
78+
79+
// GetOSImageStream returns the OS image stream value from the install config, defaulting to the
80+
// value of `DefaultOSImageStream` in as defined in pkg/rhcos/stream.go if not specified.
81+
func GetOSImageStream(ic *types.InstallConfig) string {
82+
if ic.OSImageStream == "" {
83+
return string(rhcos.DefaultOSImageStream)
84+
}
85+
return string(ic.OSImageStream)
86+
}

pkg/asset/machines/worker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ func (w *Worker) Generate(ctx context.Context, dependencies asset.Parents) error
554554
Role: pool.Name,
555555
UserDataSecret: workerUserDataSecretName,
556556
Hosts: dHosts,
557+
OSImageStream: GetOSImageStream(ic),
557558
})
558559
if err != nil {
559560
return errors.Wrap(err, "failed to create worker machine objects")

0 commit comments

Comments
 (0)