Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

baremetal: Add cluster admin kubeconfig into a secret #4456

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Secret
apiVersion: v1
metadata:
namespace: openshift-machine-api
name: kubeconfig-kubelet-secret
data:
kubeconfig: {{.Base64EncodedKubeconfigKubeletData}}
22 changes: 17 additions & 5 deletions pkg/asset/manifests/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/installconfig"
"github.com/openshift/installer/pkg/asset/installconfig/gcp"
kubeconfig "github.com/openshift/installer/pkg/asset/installconfig/kubevirt"
"github.com/openshift/installer/pkg/asset/installconfig/kubevirt"
"github.com/openshift/installer/pkg/asset/installconfig/ovirt"
"github.com/openshift/installer/pkg/asset/kubeconfig"
"github.com/openshift/installer/pkg/asset/machines"
osmachine "github.com/openshift/installer/pkg/asset/machines/openstack"
openstackmanifests "github.com/openshift/installer/pkg/asset/manifests/openstack"
Expand Down Expand Up @@ -58,11 +59,13 @@ func (o *Openshift) Dependencies() []asset.Asset {
return []asset.Asset{
&installconfig.InstallConfig{},
&installconfig.ClusterID{},
&kubeconfig.Kubelet{},
&password.KubeadminPassword{},
&openshiftinstall.Config{},

&openshift.CloudCredsSecret{},
&openshift.KubeadminPasswordSecret{},
&openshift.KubeconfigKubeletSecret{},
&openshift.RoleCloudCredsSecretReader{},
&openshift.PrivateClusterOutbound{},
&openshift.BaremetalConfig{},
Expand All @@ -75,8 +78,9 @@ func (o *Openshift) Generate(dependencies asset.Parents) error {
installConfig := &installconfig.InstallConfig{}
clusterID := &installconfig.ClusterID{}
kubeadminPassword := &password.KubeadminPassword{}
kubeconfigKubelet := &kubeconfig.Kubelet{}
openshiftInstall := &openshiftinstall.Config{}
dependencies.Get(installConfig, kubeadminPassword, clusterID, openshiftInstall)
dependencies.Get(installConfig, kubeadminPassword, kubeconfigKubelet, clusterID, openshiftInstall)
var cloudCreds cloudCredsSecretData
platform := installConfig.Config.Platform.Name()
switch platform {
Expand Down Expand Up @@ -185,7 +189,7 @@ func (o *Openshift) Generate(dependencies asset.Parents) error {
},
}
case kubevirttypes.Name:
kubeconfigContent, err := kubeconfig.LoadKubeConfigContent()
kubeconfigContent, err := kubevirt.LoadKubeConfigContent()
if err != nil {
return err
}
Expand All @@ -196,26 +200,34 @@ func (o *Openshift) Generate(dependencies asset.Parents) error {
}
}

kubeconfigKubeletData, err := yaml.Marshal(kubeconfigKubelet.Config)
if err != nil {
return err
}
templateData := &openshiftTemplateData{
CloudCreds: cloudCreds,
Base64EncodedKubeadminPwHash: base64.StdEncoding.EncodeToString(kubeadminPassword.PasswordHash),
CloudCreds: cloudCreds,
Base64EncodedKubeadminPwHash: base64.StdEncoding.EncodeToString(kubeadminPassword.PasswordHash),
Base64EncodedKubeconfigKubeletData: base64.StdEncoding.EncodeToString(kubeconfigKubeletData),
}

cloudCredsSecret := &openshift.CloudCredsSecret{}
kubeadminPasswordSecret := &openshift.KubeadminPasswordSecret{}
kubeconfigKubeletSecret := &openshift.KubeconfigKubeletSecret{}
roleCloudCredsSecretReader := &openshift.RoleCloudCredsSecretReader{}
baremetalConfig := &openshift.BaremetalConfig{}
rhcosImage := new(rhcos.Image)

dependencies.Get(
cloudCredsSecret,
kubeadminPasswordSecret,
kubeconfigKubeletSecret,
roleCloudCredsSecretReader,
baremetalConfig,
rhcosImage)

assetData := map[string][]byte{
"99_kubeadmin-password-secret.yaml": applyTemplateData(kubeadminPasswordSecret.Files()[0].Data, templateData),
"99_kubeconfig-kubelet-secret.yaml": applyTemplateData(kubeconfigKubeletSecret.Files()[0].Data, templateData),
}

switch platform {
Expand Down
5 changes: 3 additions & 2 deletions pkg/asset/manifests/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type baremetalTemplateData struct {
}

type openshiftTemplateData struct {
CloudCreds cloudCredsSecretData
Base64EncodedKubeadminPwHash string
CloudCreds cloudCredsSecretData
Base64EncodedKubeadminPwHash string
Base64EncodedKubeconfigKubeletData string
}
65 changes: 65 additions & 0 deletions pkg/asset/templates/content/openshift/kubeconfig-kubelet-secret.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package openshift

import (
"os"
"path/filepath"

"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/templates/content"
)

const (
kubeconfigKubeletSecretFileName = "kubeconfig-kubelet-secret.yaml.template"
)

var _ asset.WritableAsset = (*KubeconfigKubeletSecret)(nil)

// KubeconfigKubeletSecret is the constant to represent contents of
// kubeconfig-kubelet-password-secret.yaml.template file
type KubeconfigKubeletSecret struct {
FileList []*asset.File
}

// Dependencies returns all of the dependencies directly needed by the asset
func (t *KubeconfigKubeletSecret) Dependencies() []asset.Asset {
return []asset.Asset{}
}

// Name returns the human-friendly name of the asset.
func (t *KubeconfigKubeletSecret) Name() string {
return "KubeconfigKubeletSecret"
}

// Generate generates the actual files by this asset
func (t *KubeconfigKubeletSecret) Generate(parents asset.Parents) error {
fileName := kubeconfigKubeletSecretFileName
data, err := content.GetOpenshiftTemplate(fileName)
if err != nil {
return err
}
t.FileList = []*asset.File{
{
Filename: filepath.Join(content.TemplateDir, fileName),
Data: []byte(data),
},
}
return nil
}

// Files returns the files generated by the asset.
func (t *KubeconfigKubeletSecret) Files() []*asset.File {
return t.FileList
}

// Load returns the asset from disk.
func (t *KubeconfigKubeletSecret) Load(f asset.FileFetcher) (bool, error) {
file, err := f.FetchByName(filepath.Join(content.TemplateDir, kubeconfigKubeletSecretFileName))
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
t.FileList = []*asset.File{file}
return true, nil
}