Skip to content

Commit

Permalink
Generate CR to configure baremetal.
Browse files Browse the repository at this point in the history
Use a template to generate the baremetal config CR for use by the MAO
and the baremetal operator.
  • Loading branch information
imain committed Jan 22, 2020
1 parent ae27357 commit 9dfb595
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
@@ -0,0 +1,10 @@
apiVersion: metal3.io/v1alpha1
kind: Provisioning
metadata:
name: provisioning-configuration
spec:
provisioningInterface: {{.ProvisioningNetworkInterface}}
provisioningIP: {{.ClusterProvisioningIP}}
provisioningNetworkCIDR: {{.ProvisioningNetworkCIDR}}
provisioningDHCPExternal: {{.ProvisioningDHCPExternal}}
provisioningDHCPRange: {{.ProvisioningDHCPRange}}
9 changes: 8 additions & 1 deletion pkg/asset/manifests/openshift.go
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/openshift/installer/pkg/types"
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"
ovirttypes "github.com/openshift/installer/pkg/types/ovirt"
Expand Down Expand Up @@ -60,6 +61,7 @@ func (o *Openshift) Dependencies() []asset.Asset {
&openshift.KubeadminPasswordSecret{},
&openshift.RoleCloudCredsSecretReader{},
&openshift.PrivateClusterOutbound{},
&openshift.BaremetalConfig{},
}
}

Expand Down Expand Up @@ -179,10 +181,13 @@ func (o *Openshift) Generate(dependencies asset.Parents) error {
cloudCredsSecret := &openshift.CloudCredsSecret{}
kubeadminPasswordSecret := &openshift.KubeadminPasswordSecret{}
roleCloudCredsSecretReader := &openshift.RoleCloudCredsSecretReader{}
baremetalConfig := &openshift.BaremetalConfig{}

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

assetData := map[string][]byte{
"99_kubeadmin-password-secret.yaml": applyTemplateData(kubeadminPasswordSecret.Files()[0].Data, templateData),
Expand All @@ -192,6 +197,8 @@ func (o *Openshift) Generate(dependencies asset.Parents) error {
case awstypes.Name, openstacktypes.Name, vspheretypes.Name, azuretypes.Name, gcptypes.Name, ovirttypes.Name:
assetData["99_cloud-creds-secret.yaml"] = applyTemplateData(cloudCredsSecret.Files()[0].Data, templateData)
assetData["99_role-cloud-creds-secret-reader.yaml"] = applyTemplateData(roleCloudCredsSecretReader.Files()[0].Data, templateData)
case baremetaltypes.Name:
assetData["99_baremetal-provisioning-config.yaml"] = applyTemplateData(baremetalConfig.Files()[0].Data, *installConfig.Config.Platform.BareMetal)
}

if platform == azuretypes.Name && installConfig.Config.Publish == types.InternalPublishingStrategy {
Expand Down
@@ -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 (
baremetalConfigFilename = "baremetal-provisioning-config.yaml.template"
)

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

// BaremetalConfig is the custom resource definitions for the baremetal deployment
type BaremetalConfig struct {
FileList []*asset.File
}

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

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

// Generate generates the actual files by this asset
func (t *BaremetalConfig) Generate(parents asset.Parents) error {
fileName := baremetalConfigFilename
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 *BaremetalConfig) Files() []*asset.File {
return t.FileList
}

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

0 comments on commit 9dfb595

Please sign in to comment.