Skip to content

Commit

Permalink
✨ Add externallyManagedReplicaCount field to MachinePool
Browse files Browse the repository at this point in the history
  • Loading branch information
dthorsen committed Nov 16, 2021
1 parent 451d11e commit 4481e9b
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 24 deletions.
8 changes: 8 additions & 0 deletions config/crd/bases/cluster.x-k8s.io_machinepools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,14 @@ spec:
to.
minLength: 1
type: string
externallyManagedReplicaCount:
description: Whether the Replicas value is externally managed. This
is useful when the infrastructure is a managed machine pool, or
if the cluster-autoscaler is scaling the underlying cloud infrastructure
directly outside of cluster-api. Set this to true if you wish the
replica count to be managed outside of cluster-api. Defaults to
false.
type: boolean
failureDomains:
description: FailureDomains is the list of failure domains this MachinePool
should be attached to.
Expand Down
32 changes: 30 additions & 2 deletions exp/api/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1alpha3
import (
apimachineryconversion "k8s.io/apimachinery/pkg/conversion"
"sigs.k8s.io/cluster-api/exp/api/v1beta1"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)
Expand Down Expand Up @@ -59,13 +60,36 @@ func Convert_v1beta1_MachinePool_To_v1alpha3_MachinePool(in *v1beta1.MachinePool
func (src *MachinePool) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1beta1.MachinePool)

return Convert_v1alpha3_MachinePool_To_v1beta1_MachinePool(src, dst, nil)
if err := Convert_v1alpha3_MachinePool_To_v1beta1_MachinePool(src, dst, nil); err != nil {
return err
}

// Manually restore data.
restored := &v1beta1.MachinePool{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
return err
}

if restored.Spec.ExternallyManagedReplicaCount != nil {
dst.Spec.ExternallyManagedReplicaCount = restored.Spec.ExternallyManagedReplicaCount
}

return nil
}

func (dst *MachinePool) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1beta1.MachinePool)

return Convert_v1beta1_MachinePool_To_v1alpha3_MachinePool(src, dst, nil)
if err := Convert_v1beta1_MachinePool_To_v1alpha3_MachinePool(src, dst, nil); err != nil {
return err
}

// Preserve Hub data on down-conversion except for metadata
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}

return nil
}

func (src *MachinePoolList) ConvertTo(dstRaw conversion.Hub) error {
Expand All @@ -79,3 +103,7 @@ func (dst *MachinePoolList) ConvertFrom(srcRaw conversion.Hub) error {

return Convert_v1beta1_MachinePoolList_To_v1alpha3_MachinePoolList(src, dst, nil)
}

func Convert_v1beta1_MachinePoolSpec_To_v1alpha3_MachinePoolSpec(in *v1beta1.MachinePoolSpec, out *MachinePoolSpec, s apimachineryconversion.Scope) error {
return autoConvert_v1beta1_MachinePoolSpec_To_v1alpha3_MachinePoolSpec(in, out, s)
}
16 changes: 6 additions & 10 deletions exp/api/v1alpha3/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 31 additions & 2 deletions exp/api/v1alpha4/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,45 @@ limitations under the License.
package v1alpha4

import (
apimachineryconversion "k8s.io/apimachinery/pkg/conversion"
v1beta1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

func (src *MachinePool) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1beta1.MachinePool)

return Convert_v1alpha4_MachinePool_To_v1beta1_MachinePool(src, dst, nil)
if err := Convert_v1alpha4_MachinePool_To_v1beta1_MachinePool(src, dst, nil); err != nil {
return err
}

// Manually restore data.
restored := &v1beta1.MachinePool{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
return err
}

if restored.Spec.ExternallyManagedReplicaCount != nil {
dst.Spec.ExternallyManagedReplicaCount = restored.Spec.ExternallyManagedReplicaCount
}

return nil
}

func (dst *MachinePool) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1beta1.MachinePool)

return Convert_v1beta1_MachinePool_To_v1alpha4_MachinePool(src, dst, nil)
if err := Convert_v1beta1_MachinePool_To_v1alpha4_MachinePool(src, dst, nil); err != nil {
return err
}

// Preserve Hub data on down-conversion except for metadata
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}

return nil
}

func (src *MachinePoolList) ConvertTo(dstRaw conversion.Hub) error {
Expand All @@ -44,3 +69,7 @@ func (dst *MachinePoolList) ConvertFrom(srcRaw conversion.Hub) error {

return Convert_v1beta1_MachinePoolList_To_v1alpha4_MachinePoolList(src, dst, nil)
}

func Convert_v1beta1_MachinePoolSpec_To_v1alpha4_MachinePoolSpec(in *v1beta1.MachinePoolSpec, out *MachinePoolSpec, s apimachineryconversion.Scope) error {
return autoConvert_v1beta1_MachinePoolSpec_To_v1alpha4_MachinePoolSpec(in, out, s)
}
16 changes: 6 additions & 10 deletions exp/api/v1alpha4/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions exp/api/v1beta1/machinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ type MachinePoolSpec struct {
// FailureDomains is the list of failure domains this MachinePool should be attached to.
// +optional
FailureDomains []string `json:"failureDomains,omitempty"`

// Whether the Replicas value is externally managed. This is useful when
// the infrastructure is a managed machine pool, or if the cluster-autoscaler is scaling
// the underlying cloud infrastructure directly outside of cluster-api. Set this to true
// if you wish the replica count to be managed outside of cluster-api. Defaults to false.
// +optional
ExternallyManagedReplicaCount *bool `json:"externallyManagedReplicaCount,omitempty"`
}

// ANCHOR_END: MachinePoolSpec
Expand Down
5 changes: 5 additions & 0 deletions exp/api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4481e9b

Please sign in to comment.