From 3f9e56ecefe98bac8318bcf857e760fcdb5a4b47 Mon Sep 17 00:00:00 2001 From: Kostiantyn Kalynovskyi Date: Sat, 23 Jan 2021 01:46:37 +0000 Subject: [PATCH] Add BMH manager executor api object Also this commit extends helper interface with inventory Change-Id: I8df785f1c095a2e9502f23e1c83c5fcfe6f811fd --- pkg/api/v1alpha1/baremetal_manager.go | 76 +++++++++++++++ pkg/api/v1alpha1/groupversion_info.go | 2 +- .../remotedirectconfiguration_types.go | 31 ------- pkg/api/v1alpha1/zz_generated.deepcopy.go | 92 ++++++++++++++++--- pkg/phase/helper.go | 12 ++- pkg/phase/helper_test.go | 9 ++ pkg/phase/ifc/helper.go | 2 + 7 files changed, 177 insertions(+), 47 deletions(-) create mode 100644 pkg/api/v1alpha1/baremetal_manager.go delete mode 100644 pkg/api/v1alpha1/remotedirectconfiguration_types.go diff --git a/pkg/api/v1alpha1/baremetal_manager.go b/pkg/api/v1alpha1/baremetal_manager.go new file mode 100644 index 000000000..64691cca7 --- /dev/null +++ b/pkg/api/v1alpha1/baremetal_manager.go @@ -0,0 +1,76 @@ +/* + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +kubebuilder:object:root=true + +// BaremetalManager allows execution of control operations against baremetal hosts +type BaremetalManager struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec BaremetalManagerSpec `json:"spec"` +} + +// BaremetalManagerSpec holds configuration for baremetal manager +type BaremetalManagerSpec struct { + Operation BaremetalOperation `json:"operation"` + HostSelector BaremetalHostSelector `json:"hostSelector"` + OperationOptions BaremetalOperationOptions `json:"operationOptions"` + // Timeout in seconds + Timeout int `json:"timeout"` +} + +// BaremetalOperationOptions hold operation options +type BaremetalOperationOptions struct { + RemoteDirect RemoteDirectOptions `json:"remoteDirect"` +} + +// RemoteDirectOptions holds configuration for remote direct operation +type RemoteDirectOptions struct { + ISOURL string `json:"isoURL"` +} + +// BaremetalHostSelector allows to select a host by label selector, by name and namespace +type BaremetalHostSelector struct { + LabelSelector string `json:"labelSelector"` + Name string `json:"name"` + Namespace string `json:"namespace"` +} + +// BaremetalOperation defines an operation to be performed against baremetal host +type BaremetalOperation string + +const ( + // BaremetalOperationReboot reboot + BaremetalOperationReboot BaremetalOperation = "reboot" + // BaremetalOperationPowerOff power off + BaremetalOperationPowerOff BaremetalOperation = "power-off" + // BaremetalOperationPowerOn power on + BaremetalOperationPowerOn BaremetalOperation = "power-on" + // BaremetalOperationRemoteDirect boot iso with given url + BaremetalOperationRemoteDirect BaremetalOperation = "remote-direct" + // BaremetalOperationEjectVirtualMedia eject virtual media + BaremetalOperationEjectVirtualMedia BaremetalOperation = "eject-virtual-media" +) + +// DefaultBaremetalManager returns BaremetalManager executor document with default values +func DefaultBaremetalManager() *BaremetalManager { + return &BaremetalManager{Spec: BaremetalManagerSpec{Timeout: 300}} +} diff --git a/pkg/api/v1alpha1/groupversion_info.go b/pkg/api/v1alpha1/groupversion_info.go index f9a311a19..422df7986 100644 --- a/pkg/api/v1alpha1/groupversion_info.go +++ b/pkg/api/v1alpha1/groupversion_info.go @@ -47,12 +47,12 @@ func init() { &KubeConfig{}, &KubernetesApply{}, &IsoConfiguration{}, - &RemoteDirectConfiguration{}, &ClusterMap{}, &ReplacementTransformer{}, &Templater{}, &BootConfiguration{}, &GenericContainer{}, + &BaremetalManager{}, ) _ = AddToScheme(Scheme) //nolint:errcheck } diff --git a/pkg/api/v1alpha1/remotedirectconfiguration_types.go b/pkg/api/v1alpha1/remotedirectconfiguration_types.go deleted file mode 100644 index 34758974b..000000000 --- a/pkg/api/v1alpha1/remotedirectconfiguration_types.go +++ /dev/null @@ -1,31 +0,0 @@ -/* -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// +kubebuilder:object:root=true - -// RemoteDirectConfiguration structure is inherited from apimachinery TypeMeta and ObjectMeta structures -// and defines parameters used to bootstrap the ephemeral node during the remote direct -type RemoteDirectConfiguration struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - // IsoURL specifies url to download ISO image for ephemeral node - IsoURL string `json:"isoUrl,omitempty"` -} diff --git a/pkg/api/v1alpha1/zz_generated.deepcopy.go b/pkg/api/v1alpha1/zz_generated.deepcopy.go index 19ad3bb43..a90d47f4f 100644 --- a/pkg/api/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/api/v1alpha1/zz_generated.deepcopy.go @@ -70,6 +70,80 @@ func (in *ApplyWaitOptions) DeepCopy() *ApplyWaitOptions { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BaremetalHostSelector) DeepCopyInto(out *BaremetalHostSelector) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BaremetalHostSelector. +func (in *BaremetalHostSelector) DeepCopy() *BaremetalHostSelector { + if in == nil { + return nil + } + out := new(BaremetalHostSelector) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BaremetalManager) DeepCopyInto(out *BaremetalManager) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BaremetalManager. +func (in *BaremetalManager) DeepCopy() *BaremetalManager { + if in == nil { + return nil + } + out := new(BaremetalManager) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BaremetalManager) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BaremetalManagerSpec) DeepCopyInto(out *BaremetalManagerSpec) { + *out = *in + out.HostSelector = in.HostSelector + out.OperationOptions = in.OperationOptions +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BaremetalManagerSpec. +func (in *BaremetalManagerSpec) DeepCopy() *BaremetalManagerSpec { + if in == nil { + return nil + } + out := new(BaremetalManagerSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BaremetalOperationOptions) DeepCopyInto(out *BaremetalOperationOptions) { + *out = *in + out.RemoteDirect = in.RemoteDirect +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BaremetalOperationOptions. +func (in *BaremetalOperationOptions) DeepCopy() *BaremetalOperationOptions { + if in == nil { + return nil + } + out := new(BaremetalOperationOptions) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *BootConfiguration) DeepCopyInto(out *BootConfiguration) { *out = *in @@ -574,30 +648,20 @@ func (in *Provider) DeepCopy() *Provider { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RemoteDirectConfiguration) DeepCopyInto(out *RemoteDirectConfiguration) { +func (in *RemoteDirectOptions) DeepCopyInto(out *RemoteDirectOptions) { *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RemoteDirectConfiguration. -func (in *RemoteDirectConfiguration) DeepCopy() *RemoteDirectConfiguration { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RemoteDirectOptions. +func (in *RemoteDirectOptions) DeepCopy() *RemoteDirectOptions { if in == nil { return nil } - out := new(RemoteDirectConfiguration) + out := new(RemoteDirectOptions) in.DeepCopyInto(out) return out } -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *RemoteDirectConfiguration) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ReplacementTransformer. func (in *ReplacementTransformer) DeepCopy() *ReplacementTransformer { if in == nil { diff --git a/pkg/phase/helper.go b/pkg/phase/helper.go index f5b60e900..fbe18d434 100644 --- a/pkg/phase/helper.go +++ b/pkg/phase/helper.go @@ -23,6 +23,8 @@ import ( "opendev.org/airship/airshipctl/pkg/cluster/clustermap" "opendev.org/airship/airshipctl/pkg/config" "opendev.org/airship/airshipctl/pkg/document" + "opendev.org/airship/airshipctl/pkg/inventory" + inventoryifc "opendev.org/airship/airshipctl/pkg/inventory/ifc" "opendev.org/airship/airshipctl/pkg/phase/ifc" "opendev.org/airship/airshipctl/pkg/util" ) @@ -34,7 +36,9 @@ type Helper struct { targetPath string phaseRepoDir string phaseEntryPointBasePath string - metadata *config.Metadata + + inventory inventoryifc.Inventory + metadata *config.Metadata } // NewHelper constructs metadata interface based on config @@ -58,6 +62,7 @@ func NewHelper(cfg *config.Config) (ifc.Helper, error) { helper.inventoryRoot = filepath.Join(helper.targetPath, helper.phaseRepoDir, helper.metadata.Inventory.Path) helper.phaseEntryPointBasePath = filepath.Join(helper.targetPath, helper.phaseRepoDir, helper.metadata.PhaseMeta.DocEntryPointPrefix) + helper.inventory = inventory.NewInventory(func() (*config.Config, error) { return cfg, nil }) return helper, nil } @@ -268,3 +273,8 @@ func (helper *Helper) PhaseEntryPointBasePath() string { func (helper *Helper) WorkDir() (string, error) { return filepath.Join(util.UserHomeDir(), config.AirshipConfigDir), nil } + +// Inventory return inventory interface +func (helper *Helper) Inventory() (inventoryifc.Inventory, error) { + return helper.inventory, nil +} diff --git a/pkg/phase/helper_test.go b/pkg/phase/helper_test.go index 2a404dbde..0ff694fd9 100644 --- a/pkg/phase/helper_test.go +++ b/pkg/phase/helper_test.go @@ -510,6 +510,15 @@ func TestHelperWorkdir(t *testing.T) { assert.Greater(t, len(workDir), 0) } +func TestHelperInventory(t *testing.T) { + helper, err := phase.NewHelper(testConfig(t)) + require.NoError(t, err) + require.NotNil(t, helper) + inv, err := helper.Inventory() + assert.NoError(t, err) + assert.NotNil(t, inv) +} + func testConfig(t *testing.T) *config.Config { t.Helper() confString := `apiVersion: airshipit.org/v1alpha1 diff --git a/pkg/phase/ifc/helper.go b/pkg/phase/ifc/helper.go index 41b658530..c76abcbc4 100644 --- a/pkg/phase/ifc/helper.go +++ b/pkg/phase/ifc/helper.go @@ -18,6 +18,7 @@ import ( "opendev.org/airship/airshipctl/pkg/api/v1alpha1" "opendev.org/airship/airshipctl/pkg/cluster/clustermap" "opendev.org/airship/airshipctl/pkg/document" + "opendev.org/airship/airshipctl/pkg/inventory/ifc" ) // Helper is a phase helper that provides phases with additional config related information @@ -34,5 +35,6 @@ type Helper interface { ClusterMap() (clustermap.ClusterMap, error) ExecutorDoc(phaseID ID) (document.Document, error) PhaseBundleRoot() string + Inventory() (ifc.Inventory, error) PhaseEntryPointBasePath() string }