Skip to content

Commit

Permalink
remove cluster.status.controlPlaneInitialized
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Goldstein <[email protected]>
  • Loading branch information
ncdc committed Mar 9, 2021
1 parent 0746511 commit 4ab9974
Show file tree
Hide file tree
Showing 19 changed files with 144 additions and 60 deletions.
30 changes: 27 additions & 3 deletions api/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,40 @@ package v1alpha3
import (
apiconversion "k8s.io/apimachinery/pkg/conversion"
"sigs.k8s.io/cluster-api/api/v1alpha4"
"sigs.k8s.io/cluster-api/util/conditions"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

func (src *Cluster) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1alpha4.Cluster)

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

// Given this is a bool and there is no timestamp associated with it, when this condition is set, its timestamp
// will be "now". See https://github.com/kubernetes-sigs/cluster-api/issues/3798#issuecomment-708619826 for more
// discussion.
if src.Status.ControlPlaneInitialized {
conditions.MarkTrue(dst, v1alpha4.ControlPlaneInitializedCondition)
}

return nil
}

func (dst *Cluster) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1alpha4.Cluster)

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

if conditions.IsTrue(src, v1alpha4.ControlPlaneInitializedCondition) {
dst.Status.ControlPlaneInitialized = true
}

return nil
}

func (src *ClusterList) ConvertTo(dstRaw conversion.Hub) error {
Expand Down Expand Up @@ -174,10 +194,14 @@ func (dst *MachineHealthCheckList) ConvertFrom(srcRaw conversion.Hub) error {
}

// Convert_v1alpha3_Bootstrap_To_v1alpha4_Bootstrap is an autogenerated conversion function.
func Convert_v1alpha3_Bootstrap_To_v1alpha4_Bootstrap(in *Bootstrap, out *v1alpha4.Bootstrap, s apiconversion.Scope) error { //nolint
func Convert_v1alpha3_Bootstrap_To_v1alpha4_Bootstrap(in *Bootstrap, out *v1alpha4.Bootstrap, s apiconversion.Scope) error { // nolint
return autoConvert_v1alpha3_Bootstrap_To_v1alpha4_Bootstrap(in, out, s)
}

func Convert_v1alpha4_MachineRollingUpdateDeployment_To_v1alpha3_MachineRollingUpdateDeployment(in *v1alpha4.MachineRollingUpdateDeployment, out *MachineRollingUpdateDeployment, s apiconversion.Scope) error {
return autoConvert_v1alpha4_MachineRollingUpdateDeployment_To_v1alpha3_MachineRollingUpdateDeployment(in, out, s)
}

func Convert_v1alpha3_ClusterStatus_To_v1alpha4_ClusterStatus(in *ClusterStatus, out *v1alpha4.ClusterStatus, s apiconversion.Scope) error {
return autoConvert_v1alpha3_ClusterStatus_To_v1alpha4_ClusterStatus(in, out, s)
}
42 changes: 28 additions & 14 deletions api/v1alpha3/zz_generated.conversion.go

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

4 changes: 0 additions & 4 deletions api/v1alpha4/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ type ClusterStatus struct {
// +optional
InfrastructureReady bool `json:"infrastructureReady"`

// ControlPlaneInitialized defines if the control plane has been initialized.
// +optional
ControlPlaneInitialized bool `json:"controlPlaneInitialized"`

// ControlPlaneReady defines if the control plane is ready.
// +optional
ControlPlaneReady bool `json:"controlPlaneReady,omitempty"`
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha4/condition_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ const (
// its node reference populated.
MissingNodeRefReason = "MissingNodeRef"

// WaitingForControlPlaneProviderInitializedReason (Severity=Info) documents a cluster waiting for the control plane
// provider to report successful control plane initialization.
WaitingForControlPlaneProviderInitializedReason = "WaitingForControlPlaneProviderInitialized"

// ControlPlaneReady reports the ready condition from the control plane object defined for this cluster.
// This condition is mirrored from the Ready condition in the control plane ref object, and
// the absence of this condition might signal problems in the reconcile external loops or the fact that
Expand Down
3 changes: 2 additions & 1 deletion bootstrap/kubeadm/controllers/kubeadmconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
return ctrl.Result{}, nil
}

if !cluster.Status.ControlPlaneInitialized {
// Note: can't use IsFalse here because we need to handle the absence of the condition as well as false.
if !conditions.IsTrue(cluster, clusterv1.ControlPlaneInitializedCondition) {
return r.handleClusterNotInitialized(ctx, scope)
}

Expand Down
19 changes: 9 additions & 10 deletions bootstrap/kubeadm/controllers/kubeadmconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"context"
"fmt"
"reflect"
"sigs.k8s.io/cluster-api/util/patch"
"testing"
"time"

Expand All @@ -41,6 +40,7 @@ import (
"sigs.k8s.io/cluster-api/test/helpers"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/cluster-api/util/secret"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -423,7 +423,7 @@ func TestKubeadmConfigReconciler_Reconcile_ErrorIfJoiningControlPlaneHasInvalidC
// TODO: extract this kind of code into a setup function that puts the state of objects into an initialized controlplane (implies secrets exist)
cluster := newCluster("cluster")
cluster.Status.InfrastructureReady = true
cluster.Status.ControlPlaneInitialized = true
conditions.MarkTrue(cluster, clusterv1.ControlPlaneInitializedCondition)
cluster.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{Host: "100.105.150.1", Port: 6443}
controlPlaneInitMachine := newControlPlaneMachine(cluster, "control-plane-init-machine")
controlPlaneInitConfig := newControlPlaneInitKubeadmConfig(controlPlaneInitMachine, "control-plane-init-cfg")
Expand Down Expand Up @@ -462,7 +462,7 @@ func TestKubeadmConfigReconciler_Reconcile_RequeueIfControlPlaneIsMissingAPIEndp

cluster := newCluster("cluster")
cluster.Status.InfrastructureReady = true
cluster.Status.ControlPlaneInitialized = true
conditions.MarkTrue(cluster, clusterv1.ControlPlaneInitializedCondition)
controlPlaneInitMachine := newControlPlaneMachine(cluster, "control-plane-init-machine")
controlPlaneInitConfig := newControlPlaneInitKubeadmConfig(controlPlaneInitMachine, "control-plane-init-cfg")

Expand Down Expand Up @@ -498,7 +498,7 @@ func TestKubeadmConfigReconciler_Reconcile_RequeueIfControlPlaneIsMissingAPIEndp
func TestReconcileIfJoinNodesAndControlPlaneIsReady(t *testing.T) {
cluster := newCluster("cluster")
cluster.Status.InfrastructureReady = true
cluster.Status.ControlPlaneInitialized = true
conditions.MarkTrue(cluster, clusterv1.ControlPlaneInitializedCondition)
cluster.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{Host: "100.105.150.1", Port: 6443}

var useCases = []struct {
Expand Down Expand Up @@ -587,7 +587,7 @@ func TestReconcileIfJoinNodePoolsAndControlPlaneIsReady(t *testing.T) {

cluster := newCluster("cluster")
cluster.Status.InfrastructureReady = true
cluster.Status.ControlPlaneInitialized = true
conditions.MarkTrue(cluster, clusterv1.ControlPlaneInitializedCondition)
cluster.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{Host: "100.105.150.1", Port: 6443}

var useCases = []struct {
Expand Down Expand Up @@ -666,7 +666,7 @@ func TestKubeadmConfigSecretCreatedStatusNotPatched(t *testing.T) {

cluster := newCluster("cluster")
cluster.Status.InfrastructureReady = true
cluster.Status.ControlPlaneInitialized = true
conditions.MarkTrue(cluster, clusterv1.ControlPlaneInitializedCondition)
cluster.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{Host: "100.105.150.1", Port: 6443}

controlPlaneInitMachine := newControlPlaneMachine(cluster, "control-plane-init-machine")
Expand Down Expand Up @@ -735,7 +735,7 @@ func TestBootstrapTokenTTLExtension(t *testing.T) {

cluster := newCluster("cluster")
cluster.Status.InfrastructureReady = true
cluster.Status.ControlPlaneInitialized = true
conditions.MarkTrue(cluster, clusterv1.ControlPlaneInitializedCondition)
cluster.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{Host: "100.105.150.1", Port: 6443}

controlPlaneInitMachine := newControlPlaneMachine(cluster, "control-plane-init-machine")
Expand Down Expand Up @@ -887,7 +887,7 @@ func TestBootstrapTokenRotationMachinePool(t *testing.T) {

cluster := newCluster("cluster")
cluster.Status.InfrastructureReady = true
cluster.Status.ControlPlaneInitialized = true
conditions.MarkTrue(cluster, clusterv1.ControlPlaneInitializedCondition)
cluster.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{Host: "100.105.150.1", Port: 6443}

controlPlaneInitMachine := newControlPlaneMachine(cluster, "control-plane-init-machine")
Expand Down Expand Up @@ -1305,7 +1305,7 @@ func TestKubeadmConfigReconciler_Reconcile_AlwaysCheckCAVerificationUnlessReques
// Setup work for an initialized cluster
clusterName := "my-cluster"
cluster := newCluster(clusterName)
cluster.Status.ControlPlaneInitialized = true
conditions.MarkTrue(cluster, clusterv1.ControlPlaneInitializedCondition)
cluster.Status.InfrastructureReady = true
cluster.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{
Host: "example.com",
Expand Down Expand Up @@ -1433,7 +1433,6 @@ func TestKubeadmConfigReconciler_Reconcile_DoesNotFailIfCASecretsAlreadyExist(t

cluster := newCluster("my-cluster")
cluster.Status.InfrastructureReady = true
cluster.Status.ControlPlaneInitialized = false
m := newControlPlaneMachine(cluster, "control-plane-machine")
configName := "my-config"
c := newControlPlaneInitKubeadmConfig(m, configName)
Expand Down
4 changes: 3 additions & 1 deletion cmd/clusterctl/client/cluster/mover.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"k8s.io/apimachinery/pkg/util/version"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -137,7 +138,8 @@ func (o *objectMover) checkProvisioningCompleted(graph *objectGraph) error {
continue
}

if !clusterObj.Status.ControlPlaneInitialized {
// Note: can't use IsFalse here because we need to handle the absence of the condition as well as false.
if !conditions.IsTrue(clusterObj, clusterv1.ControlPlaneInitializedCondition) {
errList = append(errList, errors.Errorf("cannot start the move operation while the control plane for %q %s/%s is not yet initialized", clusterObj.GroupVersionKind(), clusterObj.GetNamespace(), clusterObj.GetName()))
continue
}
Expand Down
54 changes: 43 additions & 11 deletions cmd/clusterctl/client/cluster/mover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
"sigs.k8s.io/cluster-api/cmd/clusterctl/internal/test"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -643,8 +644,10 @@ func Test_objectMover_checkProvisioningCompleted(t *testing.T) {
Name: "cluster1",
},
Status: clusterv1.ClusterStatus{
InfrastructureReady: false,
ControlPlaneInitialized: true,
InfrastructureReady: false,
Conditions: clusterv1.Conditions{
*conditions.TrueCondition(clusterv1.ControlPlaneInitializedCondition),
},
},
},
},
Expand All @@ -665,8 +668,31 @@ func Test_objectMover_checkProvisioningCompleted(t *testing.T) {
Name: "cluster1",
},
Status: clusterv1.ClusterStatus{
InfrastructureReady: true,
ControlPlaneInitialized: false,
InfrastructureReady: true,
},
},
},
},
wantErr: true,
},
{
name: "Blocks with a cluster with ControlPlaneInitialized=False",
fields: fields{
objs: []client.Object{
&clusterv1.Cluster{
TypeMeta: metav1.TypeMeta{
Kind: "Cluster",
APIVersion: clusterv1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: "ns1",
Name: "cluster1",
},
Status: clusterv1.ClusterStatus{
InfrastructureReady: true,
Conditions: clusterv1.Conditions{
*conditions.FalseCondition(clusterv1.ControlPlaneInitializedCondition, "", clusterv1.ConditionSeverityInfo, ""),
},
},
},
},
Expand All @@ -690,9 +716,11 @@ func Test_objectMover_checkProvisioningCompleted(t *testing.T) {
ControlPlaneRef: &corev1.ObjectReference{},
},
Status: clusterv1.ClusterStatus{
InfrastructureReady: true,
ControlPlaneInitialized: true,
ControlPlaneReady: false,
InfrastructureReady: true,
Conditions: clusterv1.Conditions{
*conditions.TrueCondition(clusterv1.ControlPlaneInitializedCondition),
},
ControlPlaneReady: false,
},
},
},
Expand All @@ -714,8 +742,10 @@ func Test_objectMover_checkProvisioningCompleted(t *testing.T) {
UID: "cluster1",
},
Status: clusterv1.ClusterStatus{
InfrastructureReady: true,
ControlPlaneInitialized: true,
InfrastructureReady: true,
Conditions: clusterv1.Conditions{
*conditions.TrueCondition(clusterv1.ControlPlaneInitializedCondition),
},
},
},
&clusterv1.Machine{
Expand Down Expand Up @@ -758,8 +788,10 @@ func Test_objectMover_checkProvisioningCompleted(t *testing.T) {
UID: "cluster1",
},
Status: clusterv1.ClusterStatus{
InfrastructureReady: true,
ControlPlaneInitialized: true,
InfrastructureReady: true,
Conditions: clusterv1.Conditions{
*conditions.TrueCondition(clusterv1.ControlPlaneInitializedCondition),
},
},
},
&clusterv1.Machine{
Expand Down
3 changes: 0 additions & 3 deletions config/crd/bases/cluster.x-k8s.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,6 @@ spec:
- type
type: object
type: array
controlPlaneInitialized:
description: ControlPlaneInitialized defines if the control plane has been initialized.
type: boolean
controlPlaneReady:
description: ControlPlaneReady defines if the control plane is ready.
type: boolean
Expand Down
Loading

0 comments on commit 4ab9974

Please sign in to comment.