Skip to content

Commit

Permalink
add bootstrap kubeconfig to the osm bootstraping (#1156)
Browse files Browse the repository at this point in the history
Signed-off-by: Moath Qasim <[email protected]>
  • Loading branch information
moadqassem authored Jan 12, 2022
1 parent 4f5f591 commit bbe21e9
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 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/flatcar"
"github.com/kubermatic/machine-controller/pkg/userdata/helper"

ctrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -55,14 +56,14 @@ func getOSMBootstrapUserdata(ctx context.Context, client ctrlruntimeclient.Clien

// Ignition configuration is used for flatcar
if useIgnition(pconfig) {
return getOSMBootstrapUserDataForIgnition(ctx, req, pconfig.SSHPublicKeys, token, secretName, clusterName)
return getOSMBootstrapUserDataForIgnition(req, pconfig.SSHPublicKeys, token, secretName, clusterName)
}
// cloud-init is used for all other operating systems
return getOSMBootstrapUserDataForCloudInit(ctx, req, pconfig, token, secretName, clusterName)
return getOSMBootstrapUserDataForCloudInit(req, pconfig, token, secretName, clusterName)
}

// getOSMBootstrapUserDataForIgnition returns the userdata for the ignition bootstrap config
func getOSMBootstrapUserDataForIgnition(ctx context.Context, req plugin.UserDataRequest, sshPublicKeys []string, token, secretName, clusterName string) (string, error) {
func getOSMBootstrapUserDataForIgnition(req plugin.UserDataRequest, sshPublicKeys []string, token, secretName, clusterName string) (string, error) {
data := struct {
Token string
SecretName string
Expand Down Expand Up @@ -106,7 +107,7 @@ func getOSMBootstrapUserDataForIgnition(ctx context.Context, req plugin.UserData
}

// getOSMBootstrapUserDataForCloudInit returns the userdata for the cloud-init bootstrap script
func getOSMBootstrapUserDataForCloudInit(ctx context.Context, req plugin.UserDataRequest, pconfig *providerconfigtypes.Config, token, secretName, clusterName string) (string, error) {
func getOSMBootstrapUserDataForCloudInit(req plugin.UserDataRequest, pconfig *providerconfigtypes.Config, token, secretName, clusterName string) (string, error) {
data := struct {
Token string
SecretName string
Expand Down Expand Up @@ -166,17 +167,24 @@ func getOSMBootstrapUserDataForCloudInit(ctx context.Context, req plugin.UserDat
return "", fmt.Errorf("failed to parse download-binaries template: %v", err)
}

bootstrapKubeconfig, err := helper.StringifyKubeconfig(req.Kubeconfig)
if err != nil {
return "", fmt.Errorf("failed to format bootstrap kubeconfig: %v", err)
}

cloudInit := &bytes.Buffer{}
err = bsCloudInit.Execute(cloudInit, struct {
Script string
Service string
plugin.UserDataRequest
ProviderSpec *providerconfigtypes.Config
ProviderSpec *providerconfigtypes.Config
BootstrapKubeconfig string
}{
Script: base64.StdEncoding.EncodeToString(script.Bytes()),
Service: base64.StdEncoding.EncodeToString([]byte(bootstrapServiceContentTemplate)),
UserDataRequest: req,
ProviderSpec: pconfig,
Script: base64.StdEncoding.EncodeToString(script.Bytes()),
Service: base64.StdEncoding.EncodeToString([]byte(bootstrapServiceContentTemplate)),
UserDataRequest: req,
ProviderSpec: pconfig,
BootstrapKubeconfig: base64.StdEncoding.EncodeToString([]byte(bootstrapKubeconfig)),
})
if err != nil {
return "", fmt.Errorf("failed to execute cloudInitTemplate template: %v", err)
Expand Down Expand Up @@ -293,6 +301,11 @@ write_files:
encoding: b64
content: |
{{ .Script }}
- path: /etc/kubernetes/bootstrap-kubelet.conf
permissions: '0600'
encoding: b64
content: |
{{ .BootstrapKubeconfig }}
- path: /etc/systemd/system/bootstrap.service
permissions: '0644'
encoding: b64
Expand Down Expand Up @@ -331,6 +344,12 @@ reboot
{{- end }}
storage:
files:
- path: /etc/kubernetes/bootstrap-kubelet.conf
mode: 0600
filesystem: root
contents:
inline: |
{{ .BootstrapKubeconfig }}
- path: /opt/bin/bootstrap
mode: 0755
filesystem: root
Expand Down

0 comments on commit bbe21e9

Please sign in to comment.