Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
asset/manifests: add openshift-install configmap
This adds support for generating the openshift-install ConfigMap when using a UPI installation flow. Before this, the ConfigMap was generated during the "cluster" target rather than the manifests target, so that we could distinguish between an IPI and a UPI installation. The user had the option of overriding the "invoker" field using the environment variable OPENSHIFT_INSTALL_INVOKER. Even if the environment variable was used, the ConfigMap would not be present in a UPI installation (because it wasn't generated in the "manifests" target). This change causes the installer to generate that ConfigMap in the "manifests" target (in addition to the "cluster" target) when it sees the environment variable. We will make use of this functionality in CI, where we specify the job as the invoker.
- Loading branch information
Showing
3 changed files
with
140 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
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 is the relative path of openshift-install within the asset | ||
// directory. | ||
ConfigPath = filepath.Join("openshift", "openshift-install.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" | ||
} | ||
|
||
// 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 := CreateInstallConfig("") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if cm != "" { | ||
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 | ||
} | ||
|
||
// CreateInstallConfig creates the openshift-install ConfigMap from the | ||
// OPENSHIFT_INSTALL_INVOKER environment variable, and if not present, from the | ||
// provided default invoker. If both the environment variable and the default | ||
// are the empty string, this returns an empty string (indicting that no | ||
// ConfigMap should be created. This returns an error if the marshalling to | ||
// YAML fails. | ||
func CreateInstallConfig(defaultInvoker string) (string, error) { | ||
var invoker string | ||
if env := os.Getenv("OPENSHIFT_INSTALL_INVOKER"); env != "" { | ||
invoker = env | ||
} else if defaultInvoker != "" { | ||
invoker = defaultInvoker | ||
} else { | ||
return "", nil | ||
} | ||
|
||
cm := &corev1.ConfigMap{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: corev1.SchemeGroupVersion.String(), | ||
Kind: "ConfigMap", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: "openshift-config", | ||
Name: "openshift-install", | ||
}, | ||
Data: map[string]string{ | ||
"version": version.Raw, | ||
"invoker": invoker, | ||
}, | ||
} | ||
|
||
cmData, err := yaml.Marshal(cm) | ||
if err != nil { | ||
return "", errors.Wrapf(err, "failed to create install-config ConfigMap") | ||
} | ||
|
||
return string(cmData), nil | ||
} |