From d9b3dc5eb87e9cef913ea53ba19cabdfe43dff87 Mon Sep 17 00:00:00 2001 From: Deepak Sharma Date: Wed, 6 Sep 2023 15:15:32 +0530 Subject: [PATCH] add support for maas tag placement (#90) --- api/v1alpha3/zz_generated.conversion.go | 1 + api/v1alpha4/groupversion_info.go | 4 +- api/v1beta1/groupversion_info.go | 4 +- api/v1beta1/maasmachine_types.go | 4 ++ api/v1beta1/zz_generated.deepcopy.go | 5 +++ ...ructure.cluster.x-k8s.io_maasmachines.yaml | 5 +++ ...cluster.x-k8s.io_maasmachinetemplates.yaml | 5 +++ go.mod | 2 +- go.sum | 2 + pkg/maas/client/mock/clienset_mock.go | 42 +++++++++++++++++++ pkg/maas/machine/machine.go | 4 ++ spectro/generated/core-global.yaml | 10 +++++ 12 files changed, 83 insertions(+), 5 deletions(-) diff --git a/api/v1alpha3/zz_generated.conversion.go b/api/v1alpha3/zz_generated.conversion.go index fb413de..554a13d 100644 --- a/api/v1alpha3/zz_generated.conversion.go +++ b/api/v1alpha3/zz_generated.conversion.go @@ -418,6 +418,7 @@ func autoConvert_v1beta1_MaasMachineSpec_To_v1alpha3_MaasMachineSpec(in *v1beta1 out.ResourcePool = (*string)(unsafe.Pointer(in.ResourcePool)) out.MinCPU = (*int)(unsafe.Pointer(in.MinCPU)) // WARNING: in.MinMemoryInMB requires manual conversion: does not exist in peer-type + // WARNING: in.Tags requires manual conversion: does not exist in peer-type out.Image = in.Image return nil } diff --git a/api/v1alpha4/groupversion_info.go b/api/v1alpha4/groupversion_info.go index b3fded1..5577cf6 100644 --- a/api/v1alpha4/groupversion_info.go +++ b/api/v1alpha4/groupversion_info.go @@ -15,8 +15,8 @@ limitations under the License. */ // Package v1alpha4 contains API Schema definitions for the infrastructure v1alpha4 API group -//+kubebuilder:object:generate=true -//+groupName=infrastructure.cluster.x-k8s.io +// +kubebuilder:object:generate=true +// +groupName=infrastructure.cluster.x-k8s.io package v1alpha4 import ( diff --git a/api/v1beta1/groupversion_info.go b/api/v1beta1/groupversion_info.go index 8b4a788..dcfd5ba 100644 --- a/api/v1beta1/groupversion_info.go +++ b/api/v1beta1/groupversion_info.go @@ -15,8 +15,8 @@ limitations under the License. */ // Package v1beta1 contains API Schema definitions for the infrastructure v1beta1 API group -//+kubebuilder:object:generate=true -//+groupName=infrastructure.cluster.x-k8s.io +// +kubebuilder:object:generate=true +// +groupName=infrastructure.cluster.x-k8s.io package v1beta1 import ( diff --git a/api/v1beta1/maasmachine_types.go b/api/v1beta1/maasmachine_types.go index bf759f4..1ee3fae 100644 --- a/api/v1beta1/maasmachine_types.go +++ b/api/v1beta1/maasmachine_types.go @@ -56,6 +56,10 @@ type MaasMachineSpec struct { // +kubebuilder:validation:Minimum=0 MinMemoryInMB *int `json:"minMemory"` + // Tags for placement + // +optional + Tags []string `json:"tags,omitempty"` + // Image will be the MaaS image id // +kubebuilder:validation:MinLength=1 Image string `json:"image"` diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index f154419..696f37c 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -244,6 +244,11 @@ func (in *MaasMachineSpec) DeepCopyInto(out *MaasMachineSpec) { *out = new(int) **out = **in } + if in.Tags != nil { + in, out := &in.Tags, &out.Tags + *out = make([]string, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MaasMachineSpec. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_maasmachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_maasmachines.yaml index 3917d89..cf16ffd 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_maasmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_maasmachines.yaml @@ -363,6 +363,11 @@ spec: systemID: description: SystemID will be the MaaS machine ID type: string + tags: + description: Tags for placement + items: + type: string + type: array required: - image - minCPU diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_maasmachinetemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_maasmachinetemplates.yaml index b0cc065..477a087 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_maasmachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_maasmachinetemplates.yaml @@ -211,6 +211,11 @@ spec: systemID: description: SystemID will be the MaaS machine ID type: string + tags: + description: Tags for placement + items: + type: string + type: array required: - image - minCPU diff --git a/go.mod b/go.mod index d92def3..372d6e6 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/onsi/ginkgo v1.16.5 github.com/onsi/gomega v1.17.0 github.com/pkg/errors v0.9.1 - github.com/spectrocloud/maas-client-go v0.0.1-beta1.0.20230325022351-83e132faf065 + github.com/spectrocloud/maas-client-go v0.0.1-beta1.0.20230830132549-2f7491722359 github.com/spf13/pflag v1.0.5 k8s.io/api v0.23.0 k8s.io/apiextensions-apiserver v0.23.0 diff --git a/go.sum b/go.sum index 5521fc9..daa7e55 100644 --- a/go.sum +++ b/go.sum @@ -449,6 +449,8 @@ github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spectrocloud/maas-client-go v0.0.1-beta1.0.20230325022351-83e132faf065 h1:9Hp6bTsg2Vpi4EYboy9/pLG3sRpDlePXEVDyvB9FljA= github.com/spectrocloud/maas-client-go v0.0.1-beta1.0.20230325022351-83e132faf065/go.mod h1:ih7QvZPySD8fiIo56wO+W40w1ojiqNnpLP0Zb6nKvKk= +github.com/spectrocloud/maas-client-go v0.0.1-beta1.0.20230830132549-2f7491722359 h1:Rx+qfNFGE1Oh+cfNB+MW4JGod04jaaJemZ84yAn8HwQ= +github.com/spectrocloud/maas-client-go v0.0.1-beta1.0.20230830132549-2f7491722359/go.mod h1:ih7QvZPySD8fiIo56wO+W40w1ojiqNnpLP0Zb6nKvKk= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= diff --git a/pkg/maas/client/mock/clienset_mock.go b/pkg/maas/client/mock/clienset_mock.go index 8690b4a..82ca8bd 100644 --- a/pkg/maas/client/mock/clienset_mock.go +++ b/pkg/maas/client/mock/clienset_mock.go @@ -135,6 +135,20 @@ func (mr *MockClientSetInterfaceMockRecorder) ResourcePools() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResourcePools", reflect.TypeOf((*MockClientSetInterface)(nil).ResourcePools)) } +// SSHKeys mocks base method. +func (m *MockClientSetInterface) SSHKeys() maasclient.SSHKeys { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SSHKeys") + ret0, _ := ret[0].(maasclient.SSHKeys) + return ret0 +} + +// SSHKeys indicates an expected call of SSHKeys. +func (mr *MockClientSetInterfaceMockRecorder) SSHKeys() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SSHKeys", reflect.TypeOf((*MockClientSetInterface)(nil).SSHKeys)) +} + // Spaces mocks base method. func (m *MockClientSetInterface) Spaces() maasclient.Spaces { m.ctrl.T.Helper() @@ -393,6 +407,20 @@ func (mr *MockMachineMockRecorder) OSSystem() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OSSystem", reflect.TypeOf((*MockMachine)(nil).OSSystem)) } +// PowerManagerOn mocks base method. +func (m *MockMachine) PowerManagerOn() maasclient.PowerManagerOn { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PowerManagerOn") + ret0, _ := ret[0].(maasclient.PowerManagerOn) + return ret0 +} + +// PowerManagerOn indicates an expected call of PowerManagerOn. +func (mr *MockMachineMockRecorder) PowerManagerOn() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PowerManagerOn", reflect.TypeOf((*MockMachine)(nil).PowerManagerOn)) +} + // PowerState mocks base method. func (m *MockMachine) PowerState() string { m.ctrl.T.Helper() @@ -1199,6 +1227,20 @@ func (mr *MockMachineAllocatorMockRecorder) WithSystemID(arg0 interface{}) *gomo return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WithSystemID", reflect.TypeOf((*MockMachineAllocator)(nil).WithSystemID), arg0) } +// WithTags mocks base method. +func (m *MockMachineAllocator) WithTags(arg0 []string) maasclient.MachineAllocator { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "WithTags", arg0) + ret0, _ := ret[0].(maasclient.MachineAllocator) + return ret0 +} + +// WithTags indicates an expected call of WithTags. +func (mr *MockMachineAllocatorMockRecorder) WithTags(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WithTags", reflect.TypeOf((*MockMachineAllocator)(nil).WithTags), arg0) +} + // WithZone mocks base method. func (m *MockMachineAllocator) WithZone(arg0 string) maasclient.MachineAllocator { m.ctrl.T.Helper() diff --git a/pkg/maas/machine/machine.go b/pkg/maas/machine/machine.go index 209521c..aefec7f 100644 --- a/pkg/maas/machine/machine.go +++ b/pkg/maas/machine/machine.go @@ -76,6 +76,10 @@ func (s *Service) DeployMachine(userDataB64 string) (_ *infrav1beta1.Machine, re allocator.WithResourcePool(*mm.Spec.ResourcePool) } + if len(mm.Spec.Tags) > 0 { + allocator.WithTags(mm.Spec.Tags) + } + m, err = allocator.Allocate(ctx) if err != nil { return nil, errors.Wrapf(err, "Unable to allocate machine") diff --git a/spectro/generated/core-global.yaml b/spectro/generated/core-global.yaml index 876af63..49f9d0d 100644 --- a/spectro/generated/core-global.yaml +++ b/spectro/generated/core-global.yaml @@ -830,6 +830,11 @@ spec: systemID: description: SystemID will be the MaaS machine ID type: string + tags: + description: Tags for placement + items: + type: string + type: array required: - image - minCPU @@ -1172,6 +1177,11 @@ spec: systemID: description: SystemID will be the MaaS machine ID type: string + tags: + description: Tags for placement + items: + type: string + type: array required: - image - minCPU