From e3a2f2ef1e8eeb27c167db9f1c88fc003d74c05a Mon Sep 17 00:00:00 2001 From: Dmitri Fedotov Date: Tue, 5 Nov 2024 15:49:13 +0200 Subject: [PATCH] Use WorkerPool `ProviderConfig` for Ignition and ServeLabels --- example/30-infrastructure.yaml | 5 - example/30-worker.yaml | 8 + hack/api-reference/api.md | 177 +++++------------- pkg/apis/metal/register.go | 1 + pkg/apis/metal/types_cloudprofile.go | 6 - pkg/apis/metal/types_infrastructure.go | 13 -- pkg/apis/metal/types_worker.go | 17 ++ pkg/apis/metal/v1alpha1/register.go | 1 + pkg/apis/metal/v1alpha1/types_cloudprofile.go | 6 - .../metal/v1alpha1/types_infrastructure.go | 23 --- pkg/apis/metal/v1alpha1/types_worker.go | 25 +++ .../metal/v1alpha1/zz_generated.conversion.go | 38 +--- .../metal/v1alpha1/zz_generated.deepcopy.go | 53 ++---- pkg/apis/metal/zz_generated.deepcopy.go | 53 ++---- pkg/controller/worker/actuator.go | 10 - pkg/controller/worker/machines.go | 34 ++-- pkg/controller/worker/machines_test.go | 61 ------ pkg/controller/worker/suite_test.go | 25 ++- 18 files changed, 176 insertions(+), 380 deletions(-) diff --git a/example/30-infrastructure.yaml b/example/30-infrastructure.yaml index 3b26da1..ae7cfda 100644 --- a/example/30-infrastructure.yaml +++ b/example/30-infrastructure.yaml @@ -51,8 +51,3 @@ spec: providerConfig: apiVersion: metal.provider.extensions.gardener.cloud/v1alpha1 kind: InfrastructureConfig - worker: - WORKER_POOL_NAME: - extraIgnition: - raw: "the-ignition" - # override: true diff --git a/example/30-worker.yaml b/example/30-worker.yaml index 83ae40f..eaafde7 100644 --- a/example/30-worker.yaml +++ b/example/30-worker.yaml @@ -93,3 +93,11 @@ spec: zones: - my-machine-pool-a - my-machine-pool-b + providerConfig: + apiVersion: metal.provider.extensions.gardener.cloud/v1alpha1 + kind: WorkerConfig + extraIgnition: + raw: "the-ignition" + # override: true + serverLabels: + foo: bar diff --git a/hack/api-reference/api.md b/hack/api-reference/api.md index 7039e87..8ad7fea 100644 --- a/hack/api-reference/api.md +++ b/hack/api-reference/api.md @@ -13,8 +13,6 @@ Resource Types: CloudProfileConfig
  • ControlPlaneConfig -
  • -IgnitionConfig
  • CloudProfileConfig

    @@ -74,18 +72,6 @@ logical names and versions to provider-specific identifiers.

    RegionConfigs is the list of supported regions.

    - - -machineTypes
    - - -[]MachineType - - - - - -

    ControlPlaneConfig @@ -148,67 +134,6 @@ LoadBalancerConfig -

    IgnitionConfig -

    -

    -(Appears on: -WorkerConfig) -

    -

    -

    IgnitionConfig contains ignition settings.

    -

    - - - - - - - - - - - - - - - - - - - - - - - - - -
    FieldDescription
    -apiVersion
    -string
    - -metal.provider.extensions.gardener.cloud/v1alpha1 - -
    -kind
    -string -
    IgnitionConfig
    -raw
    - -string - -
    -(Optional) -

    Raw contains an inline ignition config, which is merged with the config from the os extension.

    -
    -override
    - -bool - -
    -(Optional) -

    Override configures, if ignition keys set by the os-extension are overridden -by extra ignition.

    -

    BgpPeer

    @@ -373,10 +298,14 @@ map[string]bool -

    InfrastructureConfig +

    IgnitionConfig

    -

    InfrastructureConfig infrastructure configuration resource

    +(Appears on: +WorkerConfig) +

    +

    +

    IgnitionConfig contains ignition settings.

    @@ -388,20 +317,46 @@ map[string]bool + + + +
    -worker
    +raw
    - -map[string]./pkg/apis/metal/v1alpha1.WorkerConfig - +string
    (Optional) -

    Worker contains settings per worker pool specific to the metal-operator

    +

    Raw contains an inline ignition config, which is merged with the config from the os extension.

    +
    +override
    + +bool + +
    +(Optional) +

    Override configures, if ignition keys set by the os-extension are overridden +by extra ignition.

    +

    InfrastructureConfig +

    +

    +

    InfrastructureConfig infrastructure configuration resource

    +

    + + + + + + + + + +
    FieldDescription

    InfrastructureStatus

    @@ -624,44 +579,6 @@ string -

    MachineType -

    -

    -(Appears on: -CloudProfileConfig) -

    -

    -

    - - - - - - - - - - - - - - - - - -
    FieldDescription
    -name
    - -string - -
    -
    -serverLabels
    - -map[string]string - -
    -

    MetallbConfig

    @@ -772,11 +689,7 @@ string

    WorkerConfig

    -(Appears on: -InfrastructureConfig) -

    -

    -

    WorkerConfig contains settings per pool, which are specific to the metal-operator.

    +

    WorkerConfig contains configuration settings for the worker nodes.

    @@ -797,7 +710,19 @@ IgnitionConfig + + + + diff --git a/pkg/apis/metal/register.go b/pkg/apis/metal/register.go index ccefc8c..97b8436 100644 --- a/pkg/apis/metal/register.go +++ b/pkg/apis/metal/register.go @@ -38,6 +38,7 @@ func addKnownTypes(scheme *runtime.Scheme) error { &InfrastructureConfig{}, &InfrastructureStatus{}, &ControlPlaneConfig{}, + &WorkerConfig{}, &WorkerStatus{}, ) return nil diff --git a/pkg/apis/metal/types_cloudprofile.go b/pkg/apis/metal/types_cloudprofile.go index 2ff0e89..e6554d0 100644 --- a/pkg/apis/metal/types_cloudprofile.go +++ b/pkg/apis/metal/types_cloudprofile.go @@ -19,12 +19,6 @@ type CloudProfileConfig struct { MachineImages []MachineImages // RegionConfigs is the list of supported regions. RegionConfigs []RegionConfig - MachineTypes []MachineType -} - -type MachineType struct { - Name string - ServerLabels map[string]string } // MachineImages is a mapping from logical names and versions to provider-specific identifiers. diff --git a/pkg/apis/metal/types_infrastructure.go b/pkg/apis/metal/types_infrastructure.go index d068e03..b19e1ac 100644 --- a/pkg/apis/metal/types_infrastructure.go +++ b/pkg/apis/metal/types_infrastructure.go @@ -8,24 +8,11 @@ import ( ) // +genclient - -// IgnitionConfig contains ignition settings. -type IgnitionConfig struct { - Raw string - Override bool -} - -// WorkerConfig contains settings per pool, which are specific to the metal-operator. -type WorkerConfig struct { - ExtraIgnition *IgnitionConfig -} - // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // InfrastructureConfig infrastructure configuration resource type InfrastructureConfig struct { metav1.TypeMeta - Worker map[string]WorkerConfig } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/pkg/apis/metal/types_worker.go b/pkg/apis/metal/types_worker.go index 86d6df4..27d5674 100644 --- a/pkg/apis/metal/types_worker.go +++ b/pkg/apis/metal/types_worker.go @@ -10,6 +10,17 @@ import ( // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// WorkerConfig contains configuration settings for the worker nodes. +type WorkerConfig struct { + metav1.TypeMeta + // ExtraIgnition contains additional Ignition for Worker nodes. + ExtraIgnition *IgnitionConfig + // ServerLabels is a map of labels that are applied to the ServerClaim for Server selection. + ServerLabels map[string]string +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + // WorkerStatus contains information about created worker resources. type WorkerStatus struct { metav1.TypeMeta @@ -33,3 +44,9 @@ type MachineImage struct { // Architecture is the CPU architecture of the machine image. Architecture *string } + +// IgnitionConfig contains ignition settings. +type IgnitionConfig struct { + Raw string + Override bool +} diff --git a/pkg/apis/metal/v1alpha1/register.go b/pkg/apis/metal/v1alpha1/register.go index 270d3cc..f1ad0bf 100644 --- a/pkg/apis/metal/v1alpha1/register.go +++ b/pkg/apis/metal/v1alpha1/register.go @@ -32,6 +32,7 @@ func addKnownTypes(scheme *runtime.Scheme) error { &InfrastructureConfig{}, &InfrastructureStatus{}, &ControlPlaneConfig{}, + &WorkerConfig{}, &WorkerStatus{}, ) return nil diff --git a/pkg/apis/metal/v1alpha1/types_cloudprofile.go b/pkg/apis/metal/v1alpha1/types_cloudprofile.go index 4e7311b..db80be4 100644 --- a/pkg/apis/metal/v1alpha1/types_cloudprofile.go +++ b/pkg/apis/metal/v1alpha1/types_cloudprofile.go @@ -19,12 +19,6 @@ type CloudProfileConfig struct { MachineImages []MachineImages `json:"machineImages"` // RegionConfigs is the list of supported regions. RegionConfigs []RegionConfig `json:"regionConfigs,omitempty"` - MachineTypes []MachineType `json:"machineTypes,omitempty"` -} - -type MachineType struct { - Name string `json:"name"` - ServerLabels map[string]string `json:"serverLabels,omitempty"` } // MachineImages is a mapping from logical names and versions to provider-specific identifiers. diff --git a/pkg/apis/metal/v1alpha1/types_infrastructure.go b/pkg/apis/metal/v1alpha1/types_infrastructure.go index a97247b..65f87fb 100644 --- a/pkg/apis/metal/v1alpha1/types_infrastructure.go +++ b/pkg/apis/metal/v1alpha1/types_infrastructure.go @@ -9,34 +9,11 @@ import ( // +genclient -// IgnitionConfig contains ignition settings. -type IgnitionConfig struct { - // Raw contains an inline ignition config, which is merged with the config from the os extension. - // +optional - Raw string `json:"raw,omitempty"` - - // Override configures, if ignition keys set by the os-extension are overridden - // by extra ignition. - // +optional - Override bool `json:"override,omitempty"` -} - -// WorkerConfig contains settings per pool, which are specific to the metal-operator. -type WorkerConfig struct { - // ExtraIgnition contains additional ignition configuration. - // +optional - ExtraIgnition *IgnitionConfig `json:"extraIgnition,omitempty"` -} - // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // InfrastructureConfig infrastructure configuration resource type InfrastructureConfig struct { metav1.TypeMeta `json:",inline"` - - // Worker contains settings per worker pool specific to the metal-operator - // +optional - Worker map[string]WorkerConfig `json:"worker,omitempty"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/pkg/apis/metal/v1alpha1/types_worker.go b/pkg/apis/metal/v1alpha1/types_worker.go index 577aa68..1cda074 100644 --- a/pkg/apis/metal/v1alpha1/types_worker.go +++ b/pkg/apis/metal/v1alpha1/types_worker.go @@ -9,6 +9,19 @@ import ( // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// WorkerConfig contains configuration settings for the worker nodes. +type WorkerConfig struct { + metav1.TypeMeta + // ExtraIgnition contains additional Ignition for Worker nodes. + // +optional + ExtraIgnition *IgnitionConfig `json:"extraIgnition,omitempty"` + // ServerLabels is a map of labels that are applied to the ServerClaim for Server selection. + // +optional + ServerLabels map[string]string `json:"serverLabels,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + // WorkerStatus contains information about created worker resources. type WorkerStatus struct { metav1.TypeMeta `json:",inline"` @@ -34,3 +47,15 @@ type MachineImage struct { // +optional Architecture *string `json:"architecture,omitempty"` } + +// IgnitionConfig contains ignition settings. +type IgnitionConfig struct { + // Raw contains an inline ignition config, which is merged with the config from the os extension. + // +optional + Raw string `json:"raw,omitempty"` + + // Override configures, if ignition keys set by the os-extension are overridden + // by extra ignition. + // +optional + Override bool `json:"override,omitempty"` +} diff --git a/pkg/apis/metal/v1alpha1/zz_generated.conversion.go b/pkg/apis/metal/v1alpha1/zz_generated.conversion.go index 25e8d4e..5854d8e 100644 --- a/pkg/apis/metal/v1alpha1/zz_generated.conversion.go +++ b/pkg/apis/metal/v1alpha1/zz_generated.conversion.go @@ -143,16 +143,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*MachineType)(nil), (*metal.MachineType)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha1_MachineType_To_metal_MachineType(a.(*MachineType), b.(*metal.MachineType), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*metal.MachineType)(nil), (*MachineType)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_metal_MachineType_To_v1alpha1_MachineType(a.(*metal.MachineType), b.(*MachineType), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*MetallbConfig)(nil), (*metal.MetallbConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha1_MetallbConfig_To_metal_MetallbConfig(a.(*MetallbConfig), b.(*metal.MetallbConfig), scope) }); err != nil { @@ -271,7 +261,6 @@ func Convert_metal_CloudControllerManagerConfig_To_v1alpha1_CloudControllerManag func autoConvert_v1alpha1_CloudProfileConfig_To_metal_CloudProfileConfig(in *CloudProfileConfig, out *metal.CloudProfileConfig, s conversion.Scope) error { out.MachineImages = *(*[]metal.MachineImages)(unsafe.Pointer(&in.MachineImages)) out.RegionConfigs = *(*[]metal.RegionConfig)(unsafe.Pointer(&in.RegionConfigs)) - out.MachineTypes = *(*[]metal.MachineType)(unsafe.Pointer(&in.MachineTypes)) return nil } @@ -283,7 +272,6 @@ func Convert_v1alpha1_CloudProfileConfig_To_metal_CloudProfileConfig(in *CloudPr func autoConvert_metal_CloudProfileConfig_To_v1alpha1_CloudProfileConfig(in *metal.CloudProfileConfig, out *CloudProfileConfig, s conversion.Scope) error { out.MachineImages = *(*[]MachineImages)(unsafe.Pointer(&in.MachineImages)) out.RegionConfigs = *(*[]RegionConfig)(unsafe.Pointer(&in.RegionConfigs)) - out.MachineTypes = *(*[]MachineType)(unsafe.Pointer(&in.MachineTypes)) return nil } @@ -337,7 +325,6 @@ func Convert_metal_IgnitionConfig_To_v1alpha1_IgnitionConfig(in *metal.IgnitionC } func autoConvert_v1alpha1_InfrastructureConfig_To_metal_InfrastructureConfig(in *InfrastructureConfig, out *metal.InfrastructureConfig, s conversion.Scope) error { - out.Worker = *(*map[string]metal.WorkerConfig)(unsafe.Pointer(&in.Worker)) return nil } @@ -347,7 +334,6 @@ func Convert_v1alpha1_InfrastructureConfig_To_metal_InfrastructureConfig(in *Inf } func autoConvert_metal_InfrastructureConfig_To_v1alpha1_InfrastructureConfig(in *metal.InfrastructureConfig, out *InfrastructureConfig, s conversion.Scope) error { - out.Worker = *(*map[string]WorkerConfig)(unsafe.Pointer(&in.Worker)) return nil } @@ -468,28 +454,6 @@ func Convert_metal_MachineImages_To_v1alpha1_MachineImages(in *metal.MachineImag return autoConvert_metal_MachineImages_To_v1alpha1_MachineImages(in, out, s) } -func autoConvert_v1alpha1_MachineType_To_metal_MachineType(in *MachineType, out *metal.MachineType, s conversion.Scope) error { - out.Name = in.Name - out.ServerLabels = *(*map[string]string)(unsafe.Pointer(&in.ServerLabels)) - return nil -} - -// Convert_v1alpha1_MachineType_To_metal_MachineType is an autogenerated conversion function. -func Convert_v1alpha1_MachineType_To_metal_MachineType(in *MachineType, out *metal.MachineType, s conversion.Scope) error { - return autoConvert_v1alpha1_MachineType_To_metal_MachineType(in, out, s) -} - -func autoConvert_metal_MachineType_To_v1alpha1_MachineType(in *metal.MachineType, out *MachineType, s conversion.Scope) error { - out.Name = in.Name - out.ServerLabels = *(*map[string]string)(unsafe.Pointer(&in.ServerLabels)) - return nil -} - -// Convert_metal_MachineType_To_v1alpha1_MachineType is an autogenerated conversion function. -func Convert_metal_MachineType_To_v1alpha1_MachineType(in *metal.MachineType, out *MachineType, s conversion.Scope) error { - return autoConvert_metal_MachineType_To_v1alpha1_MachineType(in, out, s) -} - func autoConvert_v1alpha1_MetallbConfig_To_metal_MetallbConfig(in *MetallbConfig, out *metal.MetallbConfig, s conversion.Scope) error { out.IPAddressPool = *(*[]string)(unsafe.Pointer(&in.IPAddressPool)) out.EnableSpeaker = in.EnableSpeaker @@ -540,6 +504,7 @@ func Convert_metal_RegionConfig_To_v1alpha1_RegionConfig(in *metal.RegionConfig, func autoConvert_v1alpha1_WorkerConfig_To_metal_WorkerConfig(in *WorkerConfig, out *metal.WorkerConfig, s conversion.Scope) error { out.ExtraIgnition = (*metal.IgnitionConfig)(unsafe.Pointer(in.ExtraIgnition)) + out.ServerLabels = *(*map[string]string)(unsafe.Pointer(&in.ServerLabels)) return nil } @@ -550,6 +515,7 @@ func Convert_v1alpha1_WorkerConfig_To_metal_WorkerConfig(in *WorkerConfig, out * func autoConvert_metal_WorkerConfig_To_v1alpha1_WorkerConfig(in *metal.WorkerConfig, out *WorkerConfig, s conversion.Scope) error { out.ExtraIgnition = (*IgnitionConfig)(unsafe.Pointer(in.ExtraIgnition)) + out.ServerLabels = *(*map[string]string)(unsafe.Pointer(&in.ServerLabels)) return nil } diff --git a/pkg/apis/metal/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/metal/v1alpha1/zz_generated.deepcopy.go index 03fd4ee..db24274 100644 --- a/pkg/apis/metal/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/metal/v1alpha1/zz_generated.deepcopy.go @@ -105,13 +105,6 @@ func (in *CloudProfileConfig) DeepCopyInto(out *CloudProfileConfig) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - if in.MachineTypes != nil { - in, out := &in.MachineTypes, &out.MachineTypes - *out = make([]MachineType, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } return } @@ -188,13 +181,6 @@ func (in *IgnitionConfig) DeepCopy() *IgnitionConfig { func (in *InfrastructureConfig) DeepCopyInto(out *InfrastructureConfig) { *out = *in out.TypeMeta = in.TypeMeta - if in.Worker != nil { - in, out := &in.Worker, &out.Worker - *out = make(map[string]WorkerConfig, len(*in)) - for key, val := range *in { - (*out)[key] = *val.DeepCopy() - } - } return } @@ -332,29 +318,6 @@ func (in *MachineImages) DeepCopy() *MachineImages { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MachineType) DeepCopyInto(out *MachineType) { - *out = *in - if in.ServerLabels != nil { - in, out := &in.ServerLabels, &out.ServerLabels - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineType. -func (in *MachineType) DeepCopy() *MachineType { - if in == nil { - return nil - } - out := new(MachineType) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MetallbConfig) DeepCopyInto(out *MetallbConfig) { *out = *in @@ -400,11 +363,19 @@ func (in *RegionConfig) DeepCopy() *RegionConfig { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WorkerConfig) DeepCopyInto(out *WorkerConfig) { *out = *in + out.TypeMeta = in.TypeMeta if in.ExtraIgnition != nil { in, out := &in.ExtraIgnition, &out.ExtraIgnition *out = new(IgnitionConfig) **out = **in } + if in.ServerLabels != nil { + in, out := &in.ServerLabels, &out.ServerLabels + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } return } @@ -418,6 +389,14 @@ func (in *WorkerConfig) DeepCopy() *WorkerConfig { return out } +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *WorkerConfig) 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 *WorkerStatus) DeepCopyInto(out *WorkerStatus) { *out = *in diff --git a/pkg/apis/metal/zz_generated.deepcopy.go b/pkg/apis/metal/zz_generated.deepcopy.go index bed9c79..e77d82a 100644 --- a/pkg/apis/metal/zz_generated.deepcopy.go +++ b/pkg/apis/metal/zz_generated.deepcopy.go @@ -105,13 +105,6 @@ func (in *CloudProfileConfig) DeepCopyInto(out *CloudProfileConfig) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - if in.MachineTypes != nil { - in, out := &in.MachineTypes, &out.MachineTypes - *out = make([]MachineType, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } return } @@ -188,13 +181,6 @@ func (in *IgnitionConfig) DeepCopy() *IgnitionConfig { func (in *InfrastructureConfig) DeepCopyInto(out *InfrastructureConfig) { *out = *in out.TypeMeta = in.TypeMeta - if in.Worker != nil { - in, out := &in.Worker, &out.Worker - *out = make(map[string]WorkerConfig, len(*in)) - for key, val := range *in { - (*out)[key] = *val.DeepCopy() - } - } return } @@ -332,29 +318,6 @@ func (in *MachineImages) DeepCopy() *MachineImages { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MachineType) DeepCopyInto(out *MachineType) { - *out = *in - if in.ServerLabels != nil { - in, out := &in.ServerLabels, &out.ServerLabels - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineType. -func (in *MachineType) DeepCopy() *MachineType { - if in == nil { - return nil - } - out := new(MachineType) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MetallbConfig) DeepCopyInto(out *MetallbConfig) { *out = *in @@ -400,11 +363,19 @@ func (in *RegionConfig) DeepCopy() *RegionConfig { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WorkerConfig) DeepCopyInto(out *WorkerConfig) { *out = *in + out.TypeMeta = in.TypeMeta if in.ExtraIgnition != nil { in, out := &in.ExtraIgnition, &out.ExtraIgnition *out = new(IgnitionConfig) **out = **in } + if in.ServerLabels != nil { + in, out := &in.ServerLabels, &out.ServerLabels + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } return } @@ -418,6 +389,14 @@ func (in *WorkerConfig) DeepCopy() *WorkerConfig { return out } +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *WorkerConfig) 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 *WorkerStatus) DeepCopyInto(out *WorkerStatus) { *out = *in diff --git a/pkg/controller/worker/actuator.go b/pkg/controller/worker/actuator.go index 7a54b5e..37a96ef 100644 --- a/pkg/controller/worker/actuator.go +++ b/pkg/controller/worker/actuator.go @@ -5,7 +5,6 @@ package worker import ( "context" - "fmt" extensionscontroller "github.com/gardener/gardener/extensions/pkg/controller" "github.com/gardener/gardener/extensions/pkg/controller/worker" @@ -84,15 +83,6 @@ type workerDelegate struct { worker *extensionsv1alpha1.Worker } -func (w *workerDelegate) getServerLabelsForMachineType(machineType string) (map[string]string, error) { - for _, t := range w.cloudProfileConfig.MachineTypes { - if t.Name == machineType { - return t.ServerLabels, nil - } - } - return nil, fmt.Errorf("no machine type %s found", machineType) -} - // NewWorkerDelegate creates a new context for a worker reconciliation. func NewWorkerDelegate( client client.Client, diff --git a/pkg/controller/worker/machines.go b/pkg/controller/worker/machines.go index 86c9672..7b27302 100644 --- a/pkg/controller/worker/machines.go +++ b/pkg/controller/worker/machines.go @@ -85,16 +85,19 @@ func (w *workerDelegate) GenerateMachineDeployments(ctx context.Context) (worker func (w *workerDelegate) generateMachineClassAndSecrets(ctx context.Context) ([]*machinecontrollerv1alpha1.MachineClass, []*corev1.Secret, error) { var ( - machineClasses []*machinecontrollerv1alpha1.MachineClass - machineClassSecrets []*corev1.Secret - infrastructureConfig metalv1alpha1.InfrastructureConfig + machineClasses []*machinecontrollerv1alpha1.MachineClass + machineClassSecrets []*corev1.Secret ) - err := json.Unmarshal(w.cluster.Shoot.Spec.Provider.InfrastructureConfig.Raw, &infrastructureConfig) - if err != nil { - return nil, nil, fmt.Errorf("failed to unmarshal infrastructure config: %w", err) - } for _, pool := range w.worker.Spec.Pools { + + workerConfig := &metalv1alpha1.WorkerConfig{} + if pool.ProviderConfig != nil && pool.ProviderConfig.Raw != nil { + if _, _, err := w.decoder.Decode(pool.ProviderConfig.Raw, nil, workerConfig); err != nil { + return nil, nil, fmt.Errorf("could not decode provider config: %+v", err) + } + } + workerPoolHash, err := w.generateHashForWorkerPool(pool) if err != nil { return nil, nil, fmt.Errorf("failed to generate hash for worker pool %s: %w", pool.Name, err) @@ -106,7 +109,7 @@ func (w *workerDelegate) generateMachineClassAndSecrets(ctx context.Context) ([] return nil, nil, err } - serverLabels, err := w.getServerLabelsForMachineType(pool.MachineType) + serverLabels, err := w.getServerLabelsForMachineType(workerConfig) if err != nil { return nil, nil, err } @@ -115,10 +118,10 @@ func (w *workerDelegate) generateMachineClassAndSecrets(ctx context.Context) ([] metal.ImageFieldName: machineImage, metal.ServerLabelsFieldName: serverLabels, } - metalConfig, ok := infrastructureConfig.Worker[pool.Name] - if ok && metalConfig.ExtraIgnition != nil { - machineClassProviderSpec[metal.IgnitionFieldName] = metalConfig.ExtraIgnition.Raw - machineClassProviderSpec[metal.IgnitionOverrideFieldName] = metalConfig.ExtraIgnition.Override + + if workerConfig.ExtraIgnition != nil { + machineClassProviderSpec[metal.IgnitionFieldName] = workerConfig.ExtraIgnition.Raw + machineClassProviderSpec[metal.IgnitionOverrideFieldName] = workerConfig.ExtraIgnition.Override } for zoneIndex, zone := range pool.Zones { @@ -206,3 +209,10 @@ func (w *workerDelegate) generateHashForWorkerPool(pool v1alpha1.WorkerPool) (st // Generate the worker pool hash. return worker.WorkerPoolHash(pool, w.cluster, nil, nil) } + +func (w *workerDelegate) getServerLabelsForMachineType(workerConfig *metalv1alpha1.WorkerConfig) (map[string]string, error) { + if workerConfig.ServerLabels != nil { + return workerConfig.ServerLabels, nil + } + return nil, fmt.Errorf("no server labels found for the given worker config") +} diff --git a/pkg/controller/worker/machines_test.go b/pkg/controller/worker/machines_test.go index ac9d09f..9d94e8d 100644 --- a/pkg/controller/worker/machines_test.go +++ b/pkg/controller/worker/machines_test.go @@ -6,7 +6,6 @@ package worker import ( "encoding/json" "fmt" - "github.com/gardener/gardener/extensions/pkg/controller/worker" genericworkeractuator "github.com/gardener/gardener/extensions/pkg/controller/worker/genericactuator" v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants" @@ -19,7 +18,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/serializer" . "sigs.k8s.io/controller-runtime/pkg/envtest/komega" - metalv1alpha1 "github.com/ironcore-dev/gardener-extension-provider-metal/pkg/apis/metal/v1alpha1" "github.com/ironcore-dev/gardener-extension-provider-metal/pkg/metal" ) @@ -54,7 +52,6 @@ var _ = Describe("Machines", func() { Name: className, }, } - By("deploying the machine class for a given multi zone cluster") decoder := serializer.NewCodecFactory(k8sClient.Scheme(), serializer.EnableStrict).UniversalDecoder() workerDelegate, err = NewWorkerDelegate(k8sClient, decoder, k8sClient.Scheme(), "", w, testCluster) @@ -68,63 +65,6 @@ var _ = Describe("Machines", func() { It("should create the expected machine class for a multi zone cluster", func(ctx SpecContext) { Expect(workerDelegate.DeployMachineClasses(ctx)).To(Succeed()) - - By("ensuring that the machine class for each pool has been deployed") - machineClassProviderSpec := map[string]any{ - "image": "registry/my-os", - "labels": map[string]any{ - metal.ClusterNameLabel: testCluster.ObjectMeta.Name, - }, - "serverLabels": map[string]string{ - "foo": "bar", - }, - } - - Eventually(Object(machineClass)).Should(SatisfyAll( - HaveField("CredentialsSecretRef", &corev1.SecretReference{ - Namespace: w.Spec.SecretRef.Namespace, - Name: w.Spec.SecretRef.Name, - }), - HaveField("SecretRef", &corev1.SecretReference{ - Namespace: ns.Name, - Name: className, - }), - HaveField("Provider", "metal"), - HaveField("NodeTemplate", &machinecontrollerv1alpha1.NodeTemplate{ - Capacity: pool.NodeTemplate.Capacity, - InstanceType: pool.MachineType, - Region: w.Spec.Region, - Zone: "zone1", - }), - HaveField("ProviderSpec", runtime.RawExtension{ - Raw: encodeMap(machineClassProviderSpec), - }), - )) - - By("ensuring that the machine class secret have been applied") - - Eventually(Object(machineClassSecret)).Should(SatisfyAll( - HaveField("ObjectMeta.Labels", HaveKeyWithValue(v1beta1constants.GardenerPurpose, v1beta1constants.GardenPurposeMachineClass)), - HaveField("Data", HaveKeyWithValue("userData", []byte("some-data"))), - )) - }) - - It("should forward ignition configuration", func(ctx SpecContext) { - infrastructureConfig := metalv1alpha1.InfrastructureConfig{ - Worker: map[string]metalv1alpha1.WorkerConfig{ - pool.Name: { - ExtraIgnition: &metalv1alpha1.IgnitionConfig{ - Raw: "abc", - Override: true, - }, - }, - }, - } - infraJSON, err := json.Marshal(infrastructureConfig) - Expect(err).To(Succeed()) - testCluster.Shoot.Spec.Provider.InfrastructureConfig.Raw = infraJSON - Expect(workerDelegate.DeployMachineClasses(ctx)).To(Succeed()) - By("ensuring that the machine class for each pool has been deployed") machineClassProviderSpec := map[string]any{ "image": "registry/my-os", @@ -166,7 +106,6 @@ var _ = Describe("Machines", func() { HaveField("Data", HaveKeyWithValue("userData", []byte("some-data"))), )) }) - }) It("should generate the machine deployments", func(ctx SpecContext) { diff --git a/pkg/controller/worker/suite_test.go b/pkg/controller/worker/suite_test.go index 6d7e0c9..c389a19 100644 --- a/pkg/controller/worker/suite_test.go +++ b/pkg/controller/worker/suite_test.go @@ -60,6 +60,9 @@ var ( testCluster *extensionscontroller.Cluster cloudProfileConfigJSON []byte + workerConfig *apiv1alpha1.WorkerConfig + workerConfigJSON []byte + w *gardenerextensionv1alpha1.Worker ) @@ -129,6 +132,17 @@ func SetupTest() (*corev1.Namespace, *gardener.ChartApplier) { volumeName := "test-volume" volumeType := "fast" + workerConfig = &apiv1alpha1.WorkerConfig{ + ServerLabels: map[string]string{ + "foo": "bar", + }, + ExtraIgnition: &apiv1alpha1.IgnitionConfig{ + Raw: "abc", + Override: true, + }, + } + workerConfigJSON, _ = json.Marshal(workerConfig) + // define test resources pool = gardenerextensionv1alpha1.WorkerPool{ MachineType: "large", @@ -156,20 +170,15 @@ func SetupTest() (*corev1.Namespace, *gardener.ChartApplier) { corev1.ResourceCPU: resource.MustParse("100m"), }, }, + ProviderConfig: &runtime.RawExtension{ + Raw: workerConfigJSON, + }, } cloudProfileConfig = &apiv1alpha1.CloudProfileConfig{ TypeMeta: metav1.TypeMeta{ APIVersion: apiv1alpha1.SchemeGroupVersion.String(), Kind: "CloudProfileConfig", }, - MachineTypes: []apiv1alpha1.MachineType{ - { - Name: "large", - ServerLabels: map[string]string{ - "foo": "bar", - }, - }, - }, MachineImages: []apiv1alpha1.MachineImages{ { Name: "my-os",
    (Optional) -

    ExtraIgnition contains additional ignition configuration.

    +

    ExtraIgnition contains additional Ignition for Worker nodes.

    +
    +serverLabels
    + +map[string]string + +
    +(Optional) +

    ServerLabels is a map of labels that are applied to the ServerClaim for Server selection.