@@ -31,6 +31,7 @@ import (
3131 providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
3232 "github.com/kubermatic/machine-controller/pkg/userdata/convert"
3333 "github.com/kubermatic/machine-controller/pkg/userdata/helper"
34+ "github.com/kubermatic/machine-controller/pkg/userdata/rhel"
3435
3536 ctrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client"
3637)
@@ -123,6 +124,7 @@ func getOSMBootstrapUserDataForCloudInit(req plugin.UserDataRequest, pconfig *pr
123124 MachineName string
124125 EnterpriseLinux bool
125126 ProviderSpec * providerconfigtypes.Config
127+ RHELConfig rhel.Config
126128 }{
127129 Token : token ,
128130 SecretName : secretName ,
@@ -132,8 +134,9 @@ func getOSMBootstrapUserDataForCloudInit(req plugin.UserDataRequest, pconfig *pr
132134 }
133135
134136 var (
135- bsScript * template.Template
136- err error
137+ rhelConfig * rhel.Config
138+ bsScript * template.Template
139+ err error
137140 )
138141
139142 switch pconfig .OperatingSystem {
@@ -159,6 +162,10 @@ func getOSMBootstrapUserDataForCloudInit(req plugin.UserDataRequest, pconfig *pr
159162 return "" , fmt .Errorf ("failed to parse bootstrapZypperBinContentTemplate template: %v" , err )
160163 }
161164 case providerconfigtypes .OperatingSystemRHEL :
165+ rhelConfig , err = rhel .LoadConfig (pconfig .OperatingSystemSpec )
166+ if err != nil {
167+ return "" , fmt .Errorf ("failed to parse OperatingSystemSpec: %w" , err )
168+ }
162169 bsScript , err = template .New ("bootstrap-cloud-init" ).Parse (bootstrapYumBinContentTemplate )
163170 if err != nil {
164171 return "" , fmt .Errorf ("failed to parse bootstrapYumBinContentTemplate template: %v" , err )
@@ -182,12 +189,14 @@ func getOSMBootstrapUserDataForCloudInit(req plugin.UserDataRequest, pconfig *pr
182189 plugin.UserDataRequest
183190 ProviderSpec * providerconfigtypes.Config
184191 BootstrapKubeconfig string
192+ RHELConfig * rhel.Config
185193 }{
186194 Script : base64 .StdEncoding .EncodeToString (script .Bytes ()),
187195 Service : base64 .StdEncoding .EncodeToString ([]byte (bootstrapServiceContentTemplate )),
188196 UserDataRequest : req ,
189197 ProviderSpec : pconfig ,
190198 BootstrapKubeconfig : base64 .StdEncoding .EncodeToString ([]byte (bootstrapKfg )),
199+ RHELConfig : rhelConfig ,
191200 })
192201 if err != nil {
193202 return "" , fmt .Errorf ("failed to execute cloudInitTemplate template: %v" , err )
238247{{- if .EnterpriseLinux }}
239248yum install epel-release -y
240249{{- end }}
250+
241251yum install -y curl jq
252+
242253curl -s -k -v --header 'Authorization: Bearer {{ .Token }}' {{ .ServerURL }}/api/v1/namespaces/cloud-init-settings/secrets/{{ .SecretName }} | jq '.data["cloud-config"]' -r| base64 -d > /etc/cloud/cloud.cfg.d/{{ .SecretName }}.cfg
243254cloud-init clean
244255cloud-init --file /etc/cloud/cloud.cfg.d/{{ .SecretName }}.cfg init
@@ -305,7 +316,7 @@ write_files:
305316 encoding: b64
306317 content: |
307318 {{ .BootstrapKubeconfig }}
308- {{- if and (eq .ProviderSpec.CloudProvider "openstack") (eq .ProviderSpec.OperatingSystem "centos") }}
319+ {{- if and (eq .ProviderSpec.CloudProvider "openstack") (or ( eq .ProviderSpec.OperatingSystem "centos") (eq .ProviderSpec.OperatingSystem "rhel") ) }}
309320{{- /* The normal way of setting it via cloud-init is broken, see */}}
310321{{- /* https://bugs.launchpad.net/cloud-init/+bug/1662542 */}}
311322- path: /etc/hostname
@@ -328,6 +339,19 @@ write_files:
328339runcmd:
329340- systemctl restart bootstrap.service
330341- systemctl daemon-reload
342+ {{- if .RHELConfig }}
343+ rh_subscription:
344+ {{- if .RHELConfig.RHELUseSatelliteServer }}
345+ org: "{{.RHELConfig.RHELOrganizationName}}"
346+ activation-key: "{{.RHELConfig.RHELActivationKey}}"
347+ server-hostname: {{ .RHELConfig.RHELSatelliteServer }}
348+ rhsm-baseurl: https://{{ .RHELConfig.RHELSatelliteServer }}/pulp/repos
349+ {{- else }}
350+ username: "{{.RHELConfig.RHELSubscriptionManagerUser}}"
351+ password: "{{.RHELConfig.RHELSubscriptionManagerPassword}}"
352+ auto-attach: {{.RHELConfig.AttachSubscription}}
353+ {{- end }}
354+ {{- end }}
331355`
332356
333357 ignitionBootstrapBinContentTemplate = `#!/bin/bash
0 commit comments