diff --git a/pkg/asset/cluster/tfvars.go b/pkg/asset/cluster/tfvars.go index 3514853ebb8..4d7551d0f5c 100644 --- a/pkg/asset/cluster/tfvars.go +++ b/pkg/asset/cluster/tfvars.go @@ -25,6 +25,7 @@ import ( azureconfig "github.com/openshift/installer/pkg/asset/installconfig/azure" gcpconfig "github.com/openshift/installer/pkg/asset/installconfig/gcp" "github.com/openshift/installer/pkg/asset/machines" + "github.com/openshift/installer/pkg/asset/openshiftinstall" "github.com/openshift/installer/pkg/asset/rhcos" "github.com/openshift/installer/pkg/tfvars" awstfvars "github.com/openshift/installer/pkg/tfvars/aws" @@ -43,7 +44,6 @@ import ( "github.com/openshift/installer/pkg/types/openstack" openstackdefaults "github.com/openshift/installer/pkg/types/openstack/defaults" "github.com/openshift/installer/pkg/types/vsphere" - "github.com/openshift/installer/pkg/version" ) const ( @@ -418,21 +418,12 @@ func injectInstallInfo(bootstrap []byte) (string, error) { return "", errors.Wrap(err, "failed to unmarshal bootstrap Ignition config") } - invoker := "user" - if env := os.Getenv("OPENSHIFT_INSTALL_INVOKER"); env != "" { - invoker = env + cm, err := openshiftinstall.CreateInstallConfigMap("openshift-install") + if err != nil { + return "", errors.Wrap(err, "failed to generate openshift-install config") } - config.Storage.Files = append(config.Storage.Files, ignition.FileFromString("/opt/openshift/manifests/openshift-install.yml", "root", 0644, fmt.Sprintf(`--- -apiVersion: v1 -kind: ConfigMap -metadata: - name: openshift-install - namespace: openshift-config -data: - version: "%s" - invoker: "%s" -`, version.Raw, invoker))) + config.Storage.Files = append(config.Storage.Files, ignition.FileFromString("/opt/openshift/manifests/openshift-install.yaml", "root", 0644, cm)) ign, err := json.Marshal(config) if err != nil { diff --git a/pkg/asset/manifests/openshift.go b/pkg/asset/manifests/openshift.go index aabcef33be0..44566f3c2f4 100644 --- a/pkg/asset/manifests/openshift.go +++ b/pkg/asset/manifests/openshift.go @@ -15,6 +15,7 @@ import ( "github.com/openshift/installer/pkg/asset/installconfig/gcp" "github.com/openshift/installer/pkg/asset/machines" openstackmanifests "github.com/openshift/installer/pkg/asset/manifests/openstack" + "github.com/openshift/installer/pkg/asset/openshiftinstall" osmachine "github.com/openshift/installer/pkg/asset/machines/openstack" "github.com/openshift/installer/pkg/asset/password" @@ -52,6 +53,7 @@ func (o *Openshift) Dependencies() []asset.Asset { &installconfig.InstallConfig{}, &installconfig.ClusterID{}, &password.KubeadminPassword{}, + &openshiftinstall.Config{}, &openshift.CloudCredsSecret{}, &openshift.KubeadminPasswordSecret{}, @@ -65,7 +67,8 @@ func (o *Openshift) Generate(dependencies asset.Parents) error { installConfig := &installconfig.InstallConfig{} clusterID := &installconfig.ClusterID{} kubeadminPassword := &password.KubeadminPassword{} - dependencies.Get(installConfig, kubeadminPassword, clusterID) + openshiftInstall := &openshiftinstall.Config{} + dependencies.Get(installConfig, kubeadminPassword, clusterID, openshiftInstall) var cloudCreds cloudCredsSecretData platform := installConfig.Config.Platform.Name() switch platform { @@ -193,6 +196,8 @@ func (o *Openshift) Generate(dependencies asset.Parents) error { }) } + o.FileList = append(o.FileList, openshiftInstall.Files()...) + asset.SortFiles(o.FileList) return nil diff --git a/pkg/asset/openshiftinstall/openshiftinstall.go b/pkg/asset/openshiftinstall/openshiftinstall.go new file mode 100644 index 00000000000..9216cc7936d --- /dev/null +++ b/pkg/asset/openshiftinstall/openshiftinstall.go @@ -0,0 +1,105 @@ +package openshiftinstall + +import ( + "os" + "path/filepath" + + "github.com/ghodss/yaml" + "github.com/pkg/errors" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/openshift/installer/pkg/asset" + "github.com/openshift/installer/pkg/version" +) + +var ( + configPath = filepath.Join("openshift", "openshift-install-manifests.yaml") +) + +// Config generates the openshift-install ConfigMap. +type Config struct { + File *asset.File +} + +var _ asset.WritableAsset = (*Config)(nil) + +// Name returns a human friendly name for the asset. +func (*Config) Name() string { + return "OpenShift Install (Manifests)" +} + +// Dependencies returns all of the dependencies directly needed to generate +// the asset. +func (*Config) Dependencies() []asset.Asset { + return []asset.Asset{} +} + +// Generate generates the openshift-install ConfigMap. +func (i *Config) Generate(dependencies asset.Parents) error { + cm, err := CreateInstallConfigMap("openshift-install-manifests") + if err != nil { + return err + } + + i.File = &asset.File{ + Filename: configPath, + Data: []byte(cm), + } + + return nil +} + +// Files returns the files generated by the asset. +func (i *Config) Files() []*asset.File { + if i.File != nil { + return []*asset.File{i.File} + } + return []*asset.File{} +} + +// Load loads the already-rendered files back from disk. +func (i *Config) Load(f asset.FileFetcher) (bool, error) { + file, err := f.FetchByName(configPath) + if os.IsNotExist(err) { + return false, nil + } else if err != nil { + return false, err + } + i.File = file + return true, nil +} + +// CreateInstallConfigMap creates an openshift-install ConfigMap from the +// OPENSHIFT_INSTALL_INVOKER environment variable and the given name for the +// ConfigMap. This returns an error if marshalling to YAML fails. +func CreateInstallConfigMap(name string) (string, error) { + var invoker string + if env := os.Getenv("OPENSHIFT_INSTALL_INVOKER"); env != "" { + invoker = env + } else { + invoker = "user" + } + + cm := &corev1.ConfigMap{ + TypeMeta: metav1.TypeMeta{ + APIVersion: corev1.SchemeGroupVersion.String(), + Kind: "ConfigMap", + }, + ObjectMeta: metav1.ObjectMeta{ + Namespace: "openshift-config", + Name: name, + }, + Data: map[string]string{ + "version": version.Raw, + "invoker": invoker, + }, + } + + cmData, err := yaml.Marshal(cm) + if err != nil { + return "", errors.Wrapf(err, "failed to create %q ConfigMap", name) + } + + return string(cmData), nil +}