-
Notifications
You must be signed in to change notification settings - Fork 1.5k
WIP: Configure BareMetal from the installer. #2849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
data/data/manifests/openshift/baremetal-deployment-crd.yaml
This file contains hidden or 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,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 |
This file contains hidden or 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,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
62
pkg/asset/templates/content/openshift/baremetal-deployment-crds.go
This file contains hidden or 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,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 | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
omitemptyfor json tag. also provide details on the default when not explicitly specified.There was a problem hiding this comment.
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 :).