Skip to content

Commit

Permalink
[release/v1.45] rh_subscriprion bootstrap script (#1350)
Browse files Browse the repository at this point in the history
* rh_subscriprion bootstrap script

Signed-off-by: Waleed Malik <[email protected]>

* Fix tests

Signed-off-by: Waleed Malik <[email protected]>

Co-authored-by: Mattia Lavacca <[email protected]>
  • Loading branch information
ahmedwaleedmalik and mlavacca authored Jul 7, 2022
1 parent e35da15 commit b44997c
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 20 deletions.
8 changes: 4 additions & 4 deletions pkg/cloudprovider/provider/azure/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ var imageReferences = map[providerconfigtypes.OperatingSystem]compute.ImageRefer
providerconfigtypes.OperatingSystemRHEL: {
Publisher: to.StringPtr("RedHat"),
Offer: to.StringPtr("rhel-byos"),
Sku: to.StringPtr("rhel-lvm83"),
Version: to.StringPtr("8.3.20201109"),
Sku: to.StringPtr("rhel-lvm85"),
Version: to.StringPtr("8.5.20220316"),
},
providerconfigtypes.OperatingSystemFlatcar: {
Publisher: to.StringPtr("kinvolk"),
Expand All @@ -150,7 +150,7 @@ var osPlans = map[providerconfigtypes.OperatingSystem]*compute.Plan{
Product: pointer.StringPtr("flatcar-container-linux"),
},
providerconfigtypes.OperatingSystemRHEL: {
Name: pointer.StringPtr("rhel-lvm83"),
Name: pointer.StringPtr("rhel-lvm85"),
Publisher: pointer.StringPtr("redhat"),
Product: pointer.StringPtr("rhel-byos"),
},
Expand Down Expand Up @@ -180,7 +180,7 @@ func getOSImageReference(c *config, os providerconfigtypes.OperatingSystem) (*co
return &ref, nil
}

// New returns a digitalocean provider
// New returns a new azure provider
func New(configVarResolver *providerconfig.ConfigVarResolver) cloudprovidertypes.Provider {
return &provider{configVarResolver: configVarResolver}
}
Expand Down
30 changes: 27 additions & 3 deletions pkg/controller/machine/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
"github.com/kubermatic/machine-controller/pkg/userdata/convert"
"github.com/kubermatic/machine-controller/pkg/userdata/helper"
"github.com/kubermatic/machine-controller/pkg/userdata/rhel"

ctrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -123,6 +124,7 @@ func getOSMBootstrapUserDataForCloudInit(req plugin.UserDataRequest, pconfig *pr
MachineName string
EnterpriseLinux bool
ProviderSpec *providerconfigtypes.Config
RHELConfig rhel.Config
}{
Token: token,
SecretName: secretName,
Expand All @@ -132,8 +134,9 @@ func getOSMBootstrapUserDataForCloudInit(req plugin.UserDataRequest, pconfig *pr
}

var (
bsScript *template.Template
err error
rhelConfig *rhel.Config
bsScript *template.Template
err error
)

switch pconfig.OperatingSystem {
Expand All @@ -159,6 +162,10 @@ func getOSMBootstrapUserDataForCloudInit(req plugin.UserDataRequest, pconfig *pr
return "", fmt.Errorf("failed to parse bootstrapZypperBinContentTemplate template: %v", err)
}
case providerconfigtypes.OperatingSystemRHEL:
rhelConfig, err = rhel.LoadConfig(pconfig.OperatingSystemSpec)
if err != nil {
return "", fmt.Errorf("failed to parse OperatingSystemSpec: %w", err)
}
bsScript, err = template.New("bootstrap-cloud-init").Parse(bootstrapYumBinContentTemplate)
if err != nil {
return "", fmt.Errorf("failed to parse bootstrapYumBinContentTemplate template: %v", err)
Expand All @@ -182,12 +189,14 @@ func getOSMBootstrapUserDataForCloudInit(req plugin.UserDataRequest, pconfig *pr
plugin.UserDataRequest
ProviderSpec *providerconfigtypes.Config
BootstrapKubeconfig string
RHELConfig *rhel.Config
}{
Script: base64.StdEncoding.EncodeToString(script.Bytes()),
Service: base64.StdEncoding.EncodeToString([]byte(bootstrapServiceContentTemplate)),
UserDataRequest: req,
ProviderSpec: pconfig,
BootstrapKubeconfig: base64.StdEncoding.EncodeToString([]byte(bootstrapKfg)),
RHELConfig: rhelConfig,
})
if err != nil {
return "", fmt.Errorf("failed to execute cloudInitTemplate template: %v", err)
Expand Down Expand Up @@ -238,7 +247,9 @@ fi
{{- if .EnterpriseLinux }}
yum install epel-release -y
{{- end }}
yum install -y curl jq
curl -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
cloud-init clean
cloud-init --file /etc/cloud/cloud.cfg.d/{{ .SecretName }}.cfg init
Expand Down Expand Up @@ -305,7 +316,7 @@ write_files:
encoding: b64
content: |
{{ .BootstrapKubeconfig }}
{{- if and (eq .ProviderSpec.CloudProvider "openstack") (eq .ProviderSpec.OperatingSystem "centos") }}
{{- if and (eq .ProviderSpec.CloudProvider "openstack") (or (eq .ProviderSpec.OperatingSystem "centos") (eq .ProviderSpec.OperatingSystem "rhel")) }}
{{- /* The normal way of setting it via cloud-init is broken, see */}}
{{- /* https://bugs.launchpad.net/cloud-init/+bug/1662542 */}}
- path: /etc/hostname
Expand All @@ -328,6 +339,19 @@ write_files:
runcmd:
- systemctl restart bootstrap.service
- systemctl daemon-reload
{{- if .RHELConfig }}
rh_subscription:
{{- if .RHELConfig.RHELUseSatelliteServer }}
org: "{{.RHELConfig.RHELOrganizationName}}"
activation-key: "{{.RHELConfig.RHELActivationKey}}"
server-hostname: {{ .RHELConfig.RHELSatelliteServer }}
rhsm-baseurl: https://{{ .RHELConfig.RHELSatelliteServer }}/pulp/repos
{{- else }}
username: "{{.RHELConfig.RHELSubscriptionManagerUser}}"
password: "{{.RHELConfig.RHELSubscriptionManagerPassword}}"
auto-attach: {{.RHELConfig.AttachSubscription}}
{{- end }}
{{- end }}
`

ignitionBootstrapBinContentTemplate = `#!/bin/bash
Expand Down
3 changes: 0 additions & 3 deletions pkg/userdata/rhel/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,6 @@ write_files:
{{- /* https://bugs.launchpad.net/cloud-init/+bug/1662542 */}}
hostnamectl set-hostname {{ .MachineSpec.Name }}
{{ end }}
{{ if eq .CloudProviderName "azure" }}
yum update -y --disablerepo='*' --enablerepo='*microsoft*'
{{ end }}
yum install -y \
device-mapper-persistent-data \
lvm2 \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ write_files:
sed -i.orig '/.*swap.*/d' /etc/fstab
swapoff -a
yum install -y \
device-mapper-persistent-data \
lvm2 \
Expand Down
1 change: 0 additions & 1 deletion pkg/userdata/rhel/testdata/kubelet-v1.20-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ write_files:
sed -i.orig '/.*swap.*/d' /etc/fstab
swapoff -a
yum install -y \
device-mapper-persistent-data \
lvm2 \
Expand Down
1 change: 0 additions & 1 deletion pkg/userdata/rhel/testdata/kubelet-v1.21-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ write_files:
sed -i.orig '/.*swap.*/d' /etc/fstab
swapoff -a
yum install -y \
device-mapper-persistent-data \
lvm2 \
Expand Down
1 change: 0 additions & 1 deletion pkg/userdata/rhel/testdata/kubelet-v1.22-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ write_files:
sed -i.orig '/.*swap.*/d' /etc/fstab
swapoff -a
yum install -y \
device-mapper-persistent-data \
lvm2 \
Expand Down
1 change: 0 additions & 1 deletion pkg/userdata/rhel/testdata/kubelet-v1.22-nutanix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ write_files:
hostnamectl set-hostname node1
yum install -y \
device-mapper-persistent-data \
lvm2 \
Expand Down
1 change: 0 additions & 1 deletion pkg/userdata/rhel/testdata/kubelet-v1.23-aws-external.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ write_files:
sed -i.orig '/.*swap.*/d' /etc/fstab
swapoff -a
yum install -y \
device-mapper-persistent-data \
lvm2 \
Expand Down
1 change: 0 additions & 1 deletion pkg/userdata/rhel/testdata/kubelet-v1.23-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ write_files:
sed -i.orig '/.*swap.*/d' /etc/fstab
swapoff -a
yum install -y \
device-mapper-persistent-data \
lvm2 \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ write_files:
hostnamectl set-hostname node1
yum install -y \
device-mapper-persistent-data \
lvm2 \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ write_files:
hostnamectl set-hostname node1
yum install -y \
device-mapper-persistent-data \
lvm2 \
Expand Down
1 change: 0 additions & 1 deletion pkg/userdata/rhel/testdata/kubelet-v1.23-vsphere.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ write_files:
hostnamectl set-hostname node1
yum install -y \
device-mapper-persistent-data \
lvm2 \
Expand Down

0 comments on commit b44997c

Please sign in to comment.