diff --git a/data/data/manifests/openshift/metal3-configmap.yaml.template b/data/data/manifests/openshift/metal3-configmap.yaml.template new file mode 100644 index 00000000000..5498894dc9d --- /dev/null +++ b/data/data/manifests/openshift/metal3-configmap.yaml.template @@ -0,0 +1,16 @@ +kind: ConfigMap +apiVersion: v1 +metadata: + name: metal3-configmap + namespace: openshift-machine-api +data: + http_port: "6180" + provisioning_interface: {{.ProvisioningInterface}} + provisioning_ip: "172.22.0.3/24" + dhcp_range: "172.22.0.10,172.22.0.100" + deploy_kernel_url: "http://172.22.0.3:6180/images/ironic-python-agent.kernel" + deploy_ramdisk_url: "http://172.22.0.3:6180/images/ironic-python-agent.initramfs" + ironic_endpoint: "http://172.22.0.3:6385/v1/" + ironic_inspector_endpoint: "http://172.22.0.3:5050/v1/" + cache_url: "http://192.168.111.1/images" + rhcos_image_url: {{.RhcosImage}} diff --git a/pkg/asset/manifests/openshift.go b/pkg/asset/manifests/openshift.go index bf83ed155a6..e6413716e54 100644 --- a/pkg/asset/manifests/openshift.go +++ b/pkg/asset/manifests/openshift.go @@ -21,6 +21,7 @@ import ( "github.com/openshift/installer/pkg/asset/templates/content/openshift" awstypes "github.com/openshift/installer/pkg/types/aws" azuretypes "github.com/openshift/installer/pkg/types/azure" + baremetaltypes "github.com/openshift/installer/pkg/types/baremetal" gcptypes "github.com/openshift/installer/pkg/types/gcp" openstacktypes "github.com/openshift/installer/pkg/types/openstack" vspheretypes "github.com/openshift/installer/pkg/types/vsphere" @@ -56,6 +57,7 @@ func (o *Openshift) Dependencies() []asset.Asset { &openshift.KubeadminPasswordSecret{}, &openshift.RoleCloudCredsSecretReader{}, &openshift.RoleBindingCloudCredsSecretReader{}, + &openshift.Metal3ConfigMap{}, } } @@ -161,11 +163,13 @@ func (o *Openshift) Generate(dependencies asset.Parents) error { kubeadminPasswordSecret := &openshift.KubeadminPasswordSecret{} roleCloudCredsSecretReader := &openshift.RoleCloudCredsSecretReader{} roleBindingCloudCredsSecretReader := &openshift.RoleBindingCloudCredsSecretReader{} + metal3ConfigMap := &openshift.Metal3ConfigMap{} dependencies.Get( cloudCredsSecret, kubeadminPasswordSecret, roleCloudCredsSecretReader, - roleBindingCloudCredsSecretReader) + roleBindingCloudCredsSecretReader, + metal3ConfigMap) assetData := map[string][]byte{ "99_kubeadmin-password-secret.yaml": applyTemplateData(kubeadminPasswordSecret.Files()[0].Data, templateData), @@ -182,6 +186,15 @@ func (o *Openshift) Generate(dependencies asset.Parents) error { assetData["99_rolebinding-cloud-creds-secret-reader.yaml"] = applyTemplateData(roleBindingCloudCredsSecretReader.Files()[0].Data, templateData) } + switch platform { + case baremetaltypes.Name: + baremetalTemplateData := &baremetalTemplateData{ + ProvisioningInterface: installConfig.Config.Platform.BareMetal.ProvisioningInterface, + RhcosImage: installConfig.Config.Platform.BareMetal.RhcosImage, + } + assetData["99_metal3-configmap.yaml"] = applyTemplateData(metal3ConfigMap.Files()[0].Data, baremetalTemplateData) + } + o.FileList = []*asset.File{} for name, data := range assetData { if len(data) == 0 { diff --git a/pkg/asset/manifests/template.go b/pkg/asset/manifests/template.go index c4f2641298d..35d13e3f95c 100644 --- a/pkg/asset/manifests/template.go +++ b/pkg/asset/manifests/template.go @@ -43,6 +43,11 @@ type cloudCredsSecretData struct { VSphere *VSphereCredsSecretData } +type baremetalTemplateData struct { + ProvisioningInterface string + RhcosImage string +} + type bootkubeTemplateData struct { CVOClusterID string EtcdCaBundle string diff --git a/pkg/asset/templates/content/openshift/metal3-configmap.go b/pkg/asset/templates/content/openshift/metal3-configmap.go new file mode 100644 index 00000000000..f42f59b6eee --- /dev/null +++ b/pkg/asset/templates/content/openshift/metal3-configmap.go @@ -0,0 +1,64 @@ +package openshift + +import ( + "os" + "path/filepath" + + "github.com/openshift/installer/pkg/asset" + "github.com/openshift/installer/pkg/asset/templates/content" +) + +const ( + metal3ConfigMapFileName = "metal3-configmap.yaml.template" +) + +var _ asset.WritableAsset = (*Metal3ConfigMap)(nil) + +// Metal3ConfigMap file list. +type Metal3ConfigMap struct { + FileList []*asset.File +} + +// Dependencies returns all of the dependencies directly needed by the asset +func (t *Metal3ConfigMap) Dependencies() []asset.Asset { + return []asset.Asset{} +} + +// Name returns the human-friendly name of the asset. +func (t *Metal3ConfigMap) Name() string { + return "Metal3ConfigMap" +} + +// Generate generates the actual files by this asset +func (t *Metal3ConfigMap) Generate(parents asset.Parents) error { + fileName := metal3ConfigMapFileName + 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 *Metal3ConfigMap) Files() []*asset.File { + return t.FileList +} + +// Load returns the asset from disk. +func (t *Metal3ConfigMap) Load(f asset.FileFetcher) (bool, error) { + file, err := f.FetchByName(filepath.Join(content.TemplateDir, metal3ConfigMapFileName)) + if err != nil { + if os.IsNotExist(err) { + return false, nil + } + return false, err + } + t.FileList = []*asset.File{file} + return true, nil +} diff --git a/pkg/types/baremetal/platform.go b/pkg/types/baremetal/platform.go index 38dd8fa1fb5..6e01667b5f7 100644 --- a/pkg/types/baremetal/platform.go +++ b/pkg/types/baremetal/platform.go @@ -66,4 +66,12 @@ type Platform struct { // DNSVIP is the VIP to use for internal DNS communication DNSVIP string `json:"dnsVIP"` + + // ProvisioningInterface specifies the name of the interface on the + // baremetal platform to use for provisioning. Specifies where ironic, + // dhcp, pxe etc runs. + ProvisioningInterface string `json:"provisioningInterface"` + + // RhcosImage is the image to use for provisioning new workers/masters. + RhcosImage string `json:"rhcosImage"` } diff --git a/pkg/types/baremetal/validation/platform.go b/pkg/types/baremetal/validation/platform.go index 9528903adc6..84b79c6a4cb 100644 --- a/pkg/types/baremetal/validation/platform.go +++ b/pkg/types/baremetal/validation/platform.go @@ -44,5 +44,14 @@ func ValidatePlatform(p *baremetal.Platform, fldPath *field.Path) field.ErrorLis if err := validate.IP(p.DNSVIP); err != nil { allErrs = append(allErrs, field.Invalid(fldPath.Child("dnsVIP"), p.DNSVIP, err.Error())) } + + if p.ProvisioningInterface == "" { + allErrs = append(allErrs, field.Required(fldPath.Child("provisioningInterface"), "provisioningInterface is required")) + } + + if err := validate.URI(p.RhcosImage); err != nil { + allErrs = append(allErrs, field.Invalid(fldPath.Child("rhcosImage"), p.RhcosImage, err.Error())) + } + return allErrs }