Skip to content

Commit

Permalink
Graduate MachinePools to stable API
Browse files Browse the repository at this point in the history
  • Loading branch information
mboersma committed Jun 13, 2024
1 parent 77a4db2 commit 15f85a4
Show file tree
Hide file tree
Showing 96 changed files with 1,771 additions and 1,668 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ generate-go-deepcopy: ## Run all generate-go-deepcopy-* targets

.PHONY: generate-go-deepcopy-core
generate-go-deepcopy-core: $(CONTROLLER_GEN) ## Generate deepcopy go code for core
$(MAKE) clean-generated-deepcopy SRC_DIRS="./api,./$(EXP_DIR)/api,./$(EXP_DIR)/addons/api,./$(EXP_DIR)/runtime/api,./$(EXP_DIR)/runtime/hooks/api"
$(MAKE) clean-generated-deepcopy SRC_DIRS="./api,./$(EXP_DIR)/api,./$(EXP_DIR)/addons/api,./$(EXP_DIR)/runtime/api,./$(EXP_DIR)/runtime/hooks/api,./internal/apis/core"
$(CONTROLLER_GEN) \
object:headerFile=./hack/boilerplate/boilerplate.generatego.txt \
paths=./api/... \
Expand All @@ -396,6 +396,7 @@ generate-go-deepcopy-core: $(CONTROLLER_GEN) ## Generate deepcopy go code for co
paths=./$(EXP_DIR)/ipam/api/... \
paths=./$(EXP_DIR)/runtime/api/... \
paths=./$(EXP_DIR)/runtime/hooks/api/... \
paths=./internal/apis/core/... \
paths=./internal/runtime/test/... \
paths=./cmd/clusterctl/... \
paths=./internal/test/builder/...
Expand Down
11 changes: 11 additions & 0 deletions api/v1beta1/condition_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,14 @@ const (
// the corresponding CRD).
ClusterClassOutdatedRefVersionsReason = "OutdatedRefVersions"
)

// Conditions and condition Reasons for the MachinePool object.

const (
// ReplicasReadyCondition reports an aggregate of current status of the replicas controlled by the MachinePool.
ReplicasReadyCondition ConditionType = "ReplicasReady"

// WaitingForReplicasReadyReason (Severity=Info) documents a machinepool waiting for the required replicas
// to be ready.
WaitingForReplicasReadyReason = "WaitingForReplicasReady"
)
2 changes: 2 additions & 0 deletions api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func (*ClusterClass) Hub() {}
func (*ClusterClassList) Hub() {}
func (*Machine) Hub() {}
func (*MachineList) Hub() {}
func (*MachinePool) Hub() {}
func (*MachinePoolList) Hub() {}
func (*MachineSet) Hub() {}
func (*MachineSetList) Hub() {}
func (*MachineDeployment) Hub() {}
Expand Down
10 changes: 5 additions & 5 deletions api/v1beta1/index/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

const (
Expand All @@ -39,7 +39,7 @@ const (
// ByMachinePoolNode adds the machinepool node name index to the
// managers cache.
func ByMachinePoolNode(ctx context.Context, mgr ctrl.Manager) error {
if err := mgr.GetCache().IndexField(ctx, &expv1.MachinePool{},
if err := mgr.GetCache().IndexField(ctx, &clusterv1.MachinePool{},
MachinePoolNodeNameField,
MachinePoolByNodeName,
); err != nil {
Expand All @@ -51,7 +51,7 @@ func ByMachinePoolNode(ctx context.Context, mgr ctrl.Manager) error {

// MachinePoolByNodeName contains the logic to index MachinePools by Node name.
func MachinePoolByNodeName(o client.Object) []string {
machinepool, ok := o.(*expv1.MachinePool)
machinepool, ok := o.(*clusterv1.MachinePool)
if !ok {
panic(fmt.Sprintf("Expected a MachinePool but got a %T", o))
}
Expand All @@ -70,7 +70,7 @@ func MachinePoolByNodeName(o client.Object) []string {
// ByMachinePoolProviderID adds the machinepool providerID index to the
// managers cache.
func ByMachinePoolProviderID(ctx context.Context, mgr ctrl.Manager) error {
if err := mgr.GetCache().IndexField(ctx, &expv1.MachinePool{},
if err := mgr.GetCache().IndexField(ctx, &clusterv1.MachinePool{},
MachinePoolProviderIDField,
machinePoolByProviderID,
); err != nil {
Expand All @@ -81,7 +81,7 @@ func ByMachinePoolProviderID(ctx context.Context, mgr ctrl.Manager) error {
}

func machinePoolByProviderID(o client.Object) []string {
machinepool, ok := o.(*expv1.MachinePool)
machinepool, ok := o.(*clusterv1.MachinePool)
if !ok {
panic(fmt.Sprintf("Expected a MachinePool but got a %T", o))
}
Expand Down
18 changes: 9 additions & 9 deletions api/v1beta1/index/machinepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

func TestIndexMachinePoolByNodeName(t *testing.T) {
Expand All @@ -34,13 +34,13 @@ func TestIndexMachinePoolByNodeName(t *testing.T) {
}{
{
name: "when the machinepool has no NodeRef",
object: &expv1.MachinePool{},
object: &clusterv1.MachinePool{},
expected: []string{},
},
{
name: "when the machinepool has valid NodeRefs",
object: &expv1.MachinePool{
Status: expv1.MachinePoolStatus{
object: &clusterv1.MachinePool{
Status: clusterv1.MachinePoolStatus{
NodeRefs: []corev1.ObjectReference{
{
Name: "node1",
Expand Down Expand Up @@ -75,22 +75,22 @@ func TestIndexMachinePoolByProviderID(t *testing.T) {
}{
{
name: "MachinePool has no providerID",
object: &expv1.MachinePool{},
object: &clusterv1.MachinePool{},
expected: nil,
},
{
name: "MachinePool has invalid providerID",
object: &expv1.MachinePool{
Spec: expv1.MachinePoolSpec{
object: &clusterv1.MachinePool{
Spec: clusterv1.MachinePoolSpec{
ProviderIDList: []string{""},
},
},
expected: []string{},
},
{
name: "MachinePool has valid providerIDs",
object: &expv1.MachinePool{
Spec: expv1.MachinePoolSpec{
object: &clusterv1.MachinePool{
Spec: clusterv1.MachinePoolSpec{
ProviderIDList: []string{validProviderID, otherValidProviderID},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
capierrors "sigs.k8s.io/cluster-api/errors"
)

Expand All @@ -43,7 +42,7 @@ type MachinePoolSpec struct {
Replicas *int32 `json:"replicas,omitempty"`

// Template describes the machines that will be created.
Template clusterv1.MachineTemplateSpec `json:"template"`
Template MachineTemplateSpec `json:"template"`

// Minimum number of seconds for which a newly created machine instances should
// be ready.
Expand Down Expand Up @@ -121,7 +120,7 @@ type MachinePoolStatus struct {

// Conditions define the current service state of the MachinePool.
// +optional
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
Conditions Conditions `json:"conditions,omitempty"`
}

// ANCHOR_END: MachinePoolStatus
Expand Down Expand Up @@ -229,12 +228,12 @@ type MachinePool struct {
}

// GetConditions returns the set of conditions for this object.
func (m *MachinePool) GetConditions() clusterv1.Conditions {
func (m *MachinePool) GetConditions() Conditions {
return m.Status.Conditions
}

// SetConditions sets the conditions on this object.
func (m *MachinePool) SetConditions(conditions clusterv1.Conditions) {
func (m *MachinePool) SetConditions(conditions Conditions) {
m.Status.Conditions = conditions
}

Expand Down
132 changes: 132 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 15f85a4

Please sign in to comment.