Skip to content
Merged
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
19 changes: 5 additions & 14 deletions pkg/asset/cluster/tfvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion pkg/asset/manifests/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -52,6 +53,7 @@ func (o *Openshift) Dependencies() []asset.Asset {
&installconfig.InstallConfig{},
&installconfig.ClusterID{},
&password.KubeadminPassword{},
&openshiftinstall.Config{},

&openshift.CloudCredsSecret{},
&openshift.KubeadminPasswordSecret{},
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
105 changes: 105 additions & 0 deletions pkg/asset/openshiftinstall/openshiftinstall.go
Original file line number Diff line number Diff line change
@@ -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
}