Skip to content
Closed
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
34 changes: 34 additions & 0 deletions data/data/manifests/openshift/baremetal-deployment-crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This CRD is used to configure the baremetal provisioning system.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: baremetal.operator.openshift.io
spec:
group: operator.openshift.io
names:
kind: BaremetalDeployment
listKind: BaremetalDeployments
plural: baremetaldeployment
singular: baremetaldeployments
scope: Cluster
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
provisioningInterface:
type: string
provisioningIP:
type: string
ProvisioningNetworkCIDR:
type: string
ProvisioningDHCPOperatorStatus:
type: string
ProvisioningDHCPRange:
type: string
109 changes: 109 additions & 0 deletions pkg/asset/manifests/baremetal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package manifests

import (
"fmt"
"path/filepath"

"github.com/ghodss/yaml"
"github.com/pkg/errors"

operatorv1 "github.com/openshift/api/operator/v1"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/installconfig"
"github.com/openshift/installer/pkg/asset/templates/content/openshift"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var (
baremetalCrdFilename = filepath.Join(manifestDir, "baremetal-deployment-01-crd.yml")
baremetalCfgFilename = filepath.Join(manifestDir, "baremetal-deployment-02-config.yml")
)

// We need to manually create our CRDs first, so we can create the
// configuration instance of it in the installer.

// Baremetal generates the baremetal-deployment-*.yml files.
type Baremetal struct {
Config *operatorv1.Metal3Provisioning
FileList []*asset.File
}

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

// Name returns a human friendly name for the operator.
func (bmo *Baremetal) Name() string {
return "Baremetal Deployment Config"
}

// Dependencies returns all of the dependencies directly needed to generate
// baremetal configuration.
func (bmo *Baremetal) Dependencies() []asset.Asset {
return []asset.Asset{
&installconfig.InstallConfig{},
&openshift.BaremetalCRDs{},
}
}

// Generate generates the baremetal operator config and its CRD.
func (bmo *Baremetal) Generate(dependencies asset.Parents) error {
installConfig := &installconfig.InstallConfig{}
crds := &openshift.BaremetalCRDs{}
dependencies.Get(installConfig, crds)

baremetalConfig := installConfig.Config.Platform.BareMetal

config := &operatorv1.Metal3Provisioning{
TypeMeta: metav1.TypeMeta{
APIVersion: operatorv1.SchemeGroupVersion.String(),
Kind: "Baremetal",
},
ObjectMeta: metav1.ObjectMeta{
Name: "cluster",
// not namespaced
},
Spec: operatorv1.Metal3ProvisioningSpec{
ProvisioningInterface: baremetalConfig.ProvisioningInterface,
ProvisioningIP: baremetalConfig.ClusterProvisioningIP,
ProvisioningNetworkCIDR: baremetalConfig.ProvisioningNetworkCIDR,
ProvisioningDHCP: operatorv1.ProvisioningDHCP{
DHCPRange: baremetalConfig.ProvisioningDHCPRange,
},
},
}
// Can't initialize this in the struct literal above as it's embedded.
config.Spec.ProvisioningDHCP.ManagementState = baremetalConfig.ProvisioningDHCPManagementState

configData, err := yaml.Marshal(config)
if err != nil {
return errors.Wrapf(err, "failed to create %s manifests from InstallConfig", bmo.Name())
}

crdContents := ""
for _, crdFile := range crds.Files() {
crdContents = fmt.Sprintf("%s\n---\n%s", crdContents, crdFile.Data)
}

bmo.FileList = []*asset.File{
{
Filename: baremetalCrdFilename,
Data: []byte(crdContents),
},
{
Filename: baremetalCfgFilename,
Data: configData,
},
}

return nil
}

// Files returns the files generated by the asset.
func (bmo *Baremetal) Files() []*asset.File {
return bmo.FileList
}

// Load returns false since this asset is not written to disk by the installer.
func (bmo *Baremetal) Load(f asset.FileFetcher) (bool, error) {
return false, nil
}
62 changes: 62 additions & 0 deletions pkg/asset/templates/content/openshift/baremetal-deployment-crds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package openshift

import (
"os"
"path/filepath"

"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/templates/content"
)

const (
baremetalCRDfilename = "baremetal-deployment-crd.yaml"
)

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

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

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

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

// Generate generates the actual files by this asset
func (t *BaremetalCRDs) Generate(parents asset.Parents) error {
data, err := content.GetOpenshiftTemplate(baremetalCRDfilename)
if err != nil {
return err
}
t.FileList = append(t.FileList, &asset.File{
Filename: filepath.Join(content.TemplateDir, baremetalCRDfilename),
Data: []byte(data),
})
return nil
}

// Files returns the files generated by the asset.
func (t *BaremetalCRDs) Files() []*asset.File {
return t.FileList
}

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

return true, nil
}
23 changes: 23 additions & 0 deletions pkg/types/baremetal/platform.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package baremetal

import (
operatorv1 "github.com/openshift/api/operator/v1"
)

// BMC stores the information about a baremetal host's management controller.
type BMC struct {
Username string `json:"username"`
Expand Down Expand Up @@ -30,6 +34,25 @@ type Platform struct {
// +optional
ClusterProvisioningIP string `json:"provisioningHostIP,omitempty"`

// ProvisioningInterface is the network interface used to provision new hosts.
// +optional
ProvisioningInterface string `json:"provisioningInterface"`
Comment on lines +38 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if these are optional, please add omitempty for json tag. also provide details on the default when not explicitly specified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry need to straighten all these out. It's actually not optional even :).


// ProvisioningNetworkCIDR defines the network to use for provisioning.
// +optional
ProvisioningNetworkCIDR string `json:"provisioningNetworkCIDR"`

// ProvisioningDHCPOperatorStatus defines whether or not we should be running
// DHCP on the provisioning network or if it will be handled by an outside source
// +optional
ProvisioningDHCPManagementState operatorv1.ManagementState `json:"provisioningDHCPManagementState"`

// ProvisioningDHCPRange is a comma separated start,end of the DHCP range used to
// assign hosts during provisioning.
// Defaults to the .20 address of ProvisioningNetworkCIDR
// +optional
ProvisioningDHCPRange string `json:"provisioningDHCPRange"`

// BootstrapProvisioningIP is the IP used on the bootstrap VM to
// bring up provisioning services that are used to create the
// control-plane machines
Expand Down
41 changes: 41 additions & 0 deletions pkg/types/baremetal/validation/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net"
"net/url"
"strings"

"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/baremetal"
Expand Down Expand Up @@ -71,6 +72,46 @@ func ValidatePlatform(p *baremetal.Platform, n *types.Networking, fldPath *field
allErrs = append(allErrs, field.Invalid(fldPath.Child("bootstrapProvisioningIP"), p.BootstrapProvisioningIP, err.Error()))
}

// Make sure the provisioning interface is set. Very little we can do to validate this
// as it's not on this machine.
if p.ProvisioningInterface == "" {
allErrs = append(allErrs, field.Invalid(fldPath.Child("provisioningInterface"), p.ProvisioningInterface, "Baremetal provisioning interface unset."))
}

// FIXME: Need to have better checking here.
if p.ProvisioningDHCPManagementState == "" {
allErrs = append(allErrs, field.Invalid(fldPath.Child("provisioningInterface"), p.ProvisioningInterface, "Baremetal provisioning interface unset."))
}

_, provNetwork, err := net.ParseCIDR(p.ProvisioningNetworkCIDR)
if err != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child("provisioningNetworkCIDR"), p.ProvisioningNetworkCIDR, err.Error()))
}

ranges := strings.Split(p.ProvisioningDHCPRange, ",")
if len(ranges) != 2 {
allErrs = append(allErrs, field.Invalid(fldPath.Child("provisioningDHCPRange"), p.ProvisioningDHCPRange, "DHCP Range must be two IPs separated by a comma"))
} else {
provisioningDHCPStart := ranges[0]
provisioningDHCPEnd := ranges[1]

if err := validate.IP(provisioningDHCPStart); err != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child("provisioningDHCPRange"), p.ProvisioningDHCPRange, err.Error()))
}

if provNetwork.Contains(net.ParseIP(provisioningDHCPStart)) != true {
allErrs = append(allErrs, field.Invalid(fldPath.Child("provisioningDHCPRange"), p.ProvisioningDHCPRange, "First IP not in provisioning network."))
}

if err := validate.IP(provisioningDHCPEnd); err != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child("provisioningDHCPRange"), p.ProvisioningDHCPRange, err.Error()))
}

if provNetwork.Contains(net.ParseIP(provisioningDHCPEnd)) != true {
allErrs = append(allErrs, field.Invalid(fldPath.Child("provisioningDHCPRange"), p.ProvisioningDHCPRange, "Second IP not in provisioning network."))
}
}

if p.Hosts == nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child("hosts"), p.Hosts, "bare metal hosts are missing"))
}
Expand Down
Loading