Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 PCP-22⚠️ capi1 v1 Boostrap and CAPI changes #50

Open
wants to merge 13 commits into
base: spectro-v1beta1
Choose a base branch
from
3 changes: 3 additions & 0 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ const (
// An external controller must fulfill the contract of the InfraCluster resource.
// External infrastructure providers should ensure that the annotation, once set, cannot be removed.
ManagedByAnnotation = "cluster.x-k8s.io/managed-by"

// TakeOverCluster is the label used to mark the nodes that run on takeover-cluster instances.
TakeOverCluster = "cluster.x-k8s.io/takeover-cluster"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/kubeadm/config/default/manager_image_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ spec:
template:
spec:
containers:
- image: gcr.io/spectro-dev-public/release/kubeadm-bootstrap-controller-amd64:20220805
- image: gcr.io/spectro-dev-public/release/kubeadm-bootstrap-controller-amd64:dev
name: manager
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,12 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
return ctrl.Result{}, nil
}

// TODO: PCP-22 check (annotation to skip handleClusterNotInitialized and go for join )
// how to make this condition true for new cluster as kubeadm cluster is already initialized
// 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) {
log.Info("TESTING... skip handleClusterNotInitialized and push cluster for join")

if !annotations.IsTakeOverCluster(cluster.GetObjectMeta()) && !conditions.IsTrue(cluster, clusterv1.ControlPlaneInitializedCondition) {
return r.handleClusterNotInitialized(ctx, scope)
}

Expand All @@ -281,10 +285,12 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques

// it's a control plane join
if configOwner.IsControlPlaneMachine() {
log.Info("TESTING.... joinControlplane")
return r.joinControlplane(ctx, scope)
}

// It's a worker join
log.Info("TESTING.... It's a worker join")
return r.joinWorker(ctx, scope)
}

Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_image_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ spec:
template:
spec:
containers:
- image: gcr.io/spectro-dev-public/release/cluster-api-controller-amd64:20220805
- image: gcr.io/spectro-dev-public/release/cluster-api-controller-amd64:dev
name: manager
74 changes: 37 additions & 37 deletions controlplane/kubeadm/api/v1beta1/kubeadm_control_plane_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,23 @@ func (in *KubeadmControlPlane) ValidateCreate() error {
}

const (
spec = "spec"
kubeadmConfigSpec = "kubeadmConfigSpec"
clusterConfiguration = "clusterConfiguration"
initConfiguration = "initConfiguration"
joinConfiguration = "joinConfiguration"
nodeRegistration = "nodeRegistration"
patches = "patches"
directory = "directory"
preKubeadmCommands = "preKubeadmCommands"
postKubeadmCommands = "postKubeadmCommands"
files = "files"
users = "users"
apiServer = "apiServer"
controllerManager = "controllerManager"
scheduler = "scheduler"
ntp = "ntp"
ignition = "ignition"
spec = "spec"
kubeadmConfigSpec = "kubeadmConfigSpec"
// clusterConfiguration = "clusterConfiguration"
// initConfiguration = "initConfiguration"
// joinConfiguration = "joinConfiguration"
// nodeRegistration = "nodeRegistration"
// patches = "patches"
// directory = "directory"
// preKubeadmCommands = "preKubeadmCommands"
// postKubeadmCommands = "postKubeadmCommands"
// files = "files"
// users = "users"
// apiServer = "apiServer"
// controllerManager = "controllerManager"
// scheduler = "scheduler"
// ntp = "ntp"
// ignition = "ignition"
)

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
Expand All @@ -134,26 +134,26 @@ func (in *KubeadmControlPlane) ValidateUpdate(old runtime.Object) error {
// For example, {"spec", "*"} will allow any path under "spec" to change.
allowedPaths := [][]string{
{"metadata", "*"},
//{spec, kubeadmConfigSpec, clusterConfiguration, "etcd", "local", "imageRepository"},
//{spec, kubeadmConfigSpec, clusterConfiguration, "etcd", "local", "imageTag"},
//{spec, kubeadmConfigSpec, clusterConfiguration, "etcd", "local", "extraArgs", "*"},
//{spec, kubeadmConfigSpec, clusterConfiguration, "dns", "imageRepository"},
//{spec, kubeadmConfigSpec, clusterConfiguration, "dns", "imageTag"},
//{spec, kubeadmConfigSpec, clusterConfiguration, "imageRepository"},
//{spec, kubeadmConfigSpec, clusterConfiguration, apiServer, "*"},
//{spec, kubeadmConfigSpec, clusterConfiguration, controllerManager, "*"},
//{spec, kubeadmConfigSpec, clusterConfiguration, scheduler, "*"},
//{spec, kubeadmConfigSpec, initConfiguration, nodeRegistration, "*"},
//{spec, kubeadmConfigSpec, initConfiguration, patches, directory},
//{spec, kubeadmConfigSpec, joinConfiguration, nodeRegistration, "*"},
//{spec, kubeadmConfigSpec, joinConfiguration, patches, directory},
//{spec, kubeadmConfigSpec, preKubeadmCommands},
//{spec, kubeadmConfigSpec, postKubeadmCommands},
//{spec, kubeadmConfigSpec, files},
//{spec, kubeadmConfigSpec, "verbosity"},
//{spec, kubeadmConfigSpec, users},
//{spec, kubeadmConfigSpec, ntp, "*"},
//{spec, kubeadmConfigSpec, ignition, "*"},
// {spec, kubeadmConfigSpec, clusterConfiguration, "etcd", "local", "imageRepository"},
// {spec, kubeadmConfigSpec, clusterConfiguration, "etcd", "local", "imageTag"},
// {spec, kubeadmConfigSpec, clusterConfiguration, "etcd", "local", "extraArgs", "*"},
// {spec, kubeadmConfigSpec, clusterConfiguration, "dns", "imageRepository"},
// {spec, kubeadmConfigSpec, clusterConfiguration, "dns", "imageTag"},
// {spec, kubeadmConfigSpec, clusterConfiguration, "imageRepository"},
// {spec, kubeadmConfigSpec, clusterConfiguration, apiServer, "*"},
// {spec, kubeadmConfigSpec, clusterConfiguration, controllerManager, "*"},
// {spec, kubeadmConfigSpec, clusterConfiguration, scheduler, "*"},
// {spec, kubeadmConfigSpec, initConfiguration, nodeRegistration, "*"},
// {spec, kubeadmConfigSpec, initConfiguration, patches, directory},
// {spec, kubeadmConfigSpec, joinConfiguration, nodeRegistration, "*"},
// {spec, kubeadmConfigSpec, joinConfiguration, patches, directory},
// {spec, kubeadmConfigSpec, preKubeadmCommands},
// {spec, kubeadmConfigSpec, postKubeadmCommands},
// {spec, kubeadmConfigSpec, files},
// {spec, kubeadmConfigSpec, "verbosity"},
// {spec, kubeadmConfigSpec, users},
// {spec, kubeadmConfigSpec, ntp, "*"},
// {spec, kubeadmConfigSpec, ignition, "*"},
// allow all fields to be modified
{spec, kubeadmConfigSpec, "*"},
{spec, "machineTemplate", "metadata", "*"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ spec:
template:
spec:
containers:
- image: gcr.io/spectro-dev-public/release/kubeadm-control-plane-controller-amd64:20220805
- image: gcr.io/spectro-dev-public/release/kubeadm-control-plane-controller-amd64:dev
name: manager
2 changes: 1 addition & 1 deletion controlplane/kubeadm/internal/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func (r *KubeadmControlPlaneReconciler) reconcileEtcdMembers(ctx context.Context
log := ctrl.LoggerFrom(ctx, "cluster", controlPlane.Cluster.Name)

// If etcd is not managed by KCP this is a no-op.
if !controlPlane.IsEtcdManaged() {
if annotations.IsTakeOverCluster(controlPlane.Cluster.GetObjectMeta()) || !controlPlane.IsEtcdManaged() {
return ctrl.Result{}, nil
}

Expand Down
5 changes: 4 additions & 1 deletion internal/controllers/cluster/cluster_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ func (r *Reconciler) reconcileControlPlane(ctx context.Context, cluster *cluster
if err != nil {
return ctrl.Result{}, err
}
if initialized {

// TODO: PCP-22 set controlPlaneInitializedCondition to true for takeOver cluster
// as CP are already initialized in existing cluster
if annotations.IsTakeOverCluster(cluster.GetObjectMeta()) || initialized {
conditions.MarkTrue(cluster, clusterv1.ControlPlaneInitializedCondition)
} else {
conditions.MarkFalse(cluster, clusterv1.ControlPlaneInitializedCondition, clusterv1.WaitingForControlPlaneProviderInitializedReason, clusterv1.ConditionSeverityInfo, "Waiting for control plane provider to indicate the control plane has been initialized")
Expand Down
2 changes: 1 addition & 1 deletion spectro/generated/bootstrap-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
- --bootstrap-token-ttl=${KUBEADM_BOOTSTRAP_TOKEN_TTL:=15m}
command:
- /manager
image: gcr.io/spectro-dev-public/release/kubeadm-bootstrap-controller-amd64:20220805
image: gcr.io/spectro-dev-public/release/kubeadm-bootstrap-controller-amd64:dev
imagePullPolicy: Always
name: manager
terminationGracePeriodSeconds: 10
Expand Down
2 changes: 1 addition & 1 deletion spectro/generated/bootstrap-global.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6241,7 +6241,7 @@ spec:
- --bootstrap-token-ttl=${KUBEADM_BOOTSTRAP_TOKEN_TTL:=15m}
command:
- /manager
image: gcr.io/spectro-dev-public/release/kubeadm-bootstrap-controller-amd64:20220805
image: gcr.io/spectro-dev-public/release/kubeadm-bootstrap-controller-amd64:dev
imagePullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion spectro/generated/controlplane-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
- --feature-gates=ClusterTopology=${CLUSTER_TOPOLOGY:=false},KubeadmBootstrapFormatIgnition=${EXP_KUBEADM_BOOTSTRAP_FORMAT_IGNITION:=false}
command:
- /manager
image: gcr.io/spectro-dev-public/release/kubeadm-control-plane-controller-amd64:20220805
image: gcr.io/spectro-dev-public/release/kubeadm-control-plane-controller-amd64:dev
imagePullPolicy: Always
name: manager
terminationGracePeriodSeconds: 10
Expand Down
2 changes: 1 addition & 1 deletion spectro/generated/controlplane-global.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6209,7 +6209,7 @@ spec:
- --feature-gates=ClusterTopology=${CLUSTER_TOPOLOGY:=false},KubeadmBootstrapFormatIgnition=${EXP_KUBEADM_BOOTSTRAP_FORMAT_IGNITION:=false}
command:
- /manager
image: gcr.io/spectro-dev-public/release/kubeadm-control-plane-controller-amd64:20220805
image: gcr.io/spectro-dev-public/release/kubeadm-control-plane-controller-amd64:dev
imagePullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion spectro/generated/core-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
- --feature-gates=MachinePool=${EXP_MACHINE_POOL:=false},ClusterResourceSet=${EXP_CLUSTER_RESOURCE_SET:=false},ClusterTopology=${CLUSTER_TOPOLOGY:=false},RuntimeSDK=${EXP_RUNTIME_SDK:=false}
command:
- /manager
image: gcr.io/spectro-dev-public/release/cluster-api-controller-amd64:20220805
image: gcr.io/spectro-dev-public/release/cluster-api-controller-amd64:dev
imagePullPolicy: Always
name: manager
terminationGracePeriodSeconds: 10
Expand Down
2 changes: 1 addition & 1 deletion spectro/generated/core-global.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9646,7 +9646,7 @@ spec:
- --feature-gates=MachinePool=${EXP_MACHINE_POOL:=false},ClusterResourceSet=${EXP_CLUSTER_RESOURCE_SET:=false},ClusterTopology=${CLUSTER_TOPOLOGY:=false},RuntimeSDK=${EXP_RUNTIME_SDK:=false}
command:
- /manager
image: gcr.io/spectro-dev-public/release/cluster-api-controller-amd64:20220805
image: gcr.io/spectro-dev-public/release/cluster-api-controller-amd64:dev
imagePullPolicy: Always
livenessProbe:
httpGet:
Expand Down
5 changes: 5 additions & 0 deletions util/annotations/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func IsExternallyManaged(o metav1.Object) bool {
return hasAnnotation(o, clusterv1.ManagedByAnnotation)
}

// IsTakeOverCluster returns true if the object has the `managed-by` annotation.
func IsTakeOverCluster(o metav1.Object) bool {
return hasAnnotation(o, clusterv1.TakeOverCluster)
}

// HasPaused returns true if the object has the `paused` annotation.
func HasPaused(o metav1.Object) bool {
return hasAnnotation(o, clusterv1.PausedAnnotation)
Expand Down
3 changes: 3 additions & 0 deletions util/secret/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"encoding/hex"
"fmt"
"math/big"
"path/filepath"
"strings"
Expand Down Expand Up @@ -238,6 +239,7 @@ func (c Certificates) EnsureAllExist() error {
func (c Certificates) Generate() error {
for _, certificate := range c {
if certificate.KeyPair == nil {
fmt.Println("TESTING.... Generate new certificates")
err := certificate.Generate()
if err != nil {
return err
Expand Down Expand Up @@ -268,6 +270,7 @@ func (c Certificates) LookupOrGenerate(ctx context.Context, ctrlclient client.Cl
return err
}

fmt.Println("TESTING.... Generate new certificates if that don't exist")
// Generate the certificates that don't exist
if err := c.Generate(); err != nil {
return err
Expand Down