Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit 17dd198

Browse files
committed
stashing this
Signed-off-by: Chuck Ha <[email protected]>
1 parent 6df2d07 commit 17dd198

File tree

6 files changed

+33
-344
lines changed

6 files changed

+33
-344
lines changed

api/v1alpha2/kubeadmbootstrapconfig_types.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,18 @@ import (
2121
kubeadmv1beta1 "sigs.k8s.io/cluster-api-bootstrap-provider-kubeadm/kubeadm/v1beta1"
2222
)
2323

24-
// KubeadmConfigSpec defines the desired state of KubeadmConfig
24+
// KubeadmConfigSpec defines the desired state of KubeadmConfig.
25+
// Either ClusterConfiguration and InitConfiguration should be defined or the JoinConfiguration should be defined.
2526
type KubeadmConfigSpec struct {
26-
ClusterConfiguration kubeadmv1beta1.ClusterConfiguration `json:"clusterConfiguration"`
27-
InitConfiguration kubeadmv1beta1.InitConfiguration `json:"initConfiguration,omitempty"`
28-
JoinConfiguration kubeadmv1beta1.JoinConfiguration `json:"joinConfiguration,omitempty"`
27+
// ClusterConfiguration along with InitConfiguration are the configurations necessary for the init command
28+
// +optional
29+
ClusterConfiguration *kubeadmv1beta1.ClusterConfiguration `json:"clusterConfiguration"`
30+
// InitConfiguration along with ClusterConfiguration are the configurations necessary for the init command
31+
// +optional
32+
InitConfiguration *kubeadmv1beta1.InitConfiguration `json:"initConfiguration,omitempty"`
33+
// JoinConfiguration is the kubeadm configuration for the join command
34+
// +optional
35+
JoinConfiguration *kubeadmv1beta1.JoinConfiguration `json:"joinConfiguration,omitempty"`
2936
}
3037

3138
// KubeadmConfigStatus defines the observed state of KubeadmConfig

controllers/bootstrapdata.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,12 @@ func (u *BootstrapDataGenerator) GenerateControlPlaneInit(config *v1alpha2.Kubea
3636

3737
// TODO: use secrets for certs, plug into kubeadm
3838
// TODO: sub in things in the cluster configuration like the cluster name and other data we can extract from the cluster object
39-
config.Spec.ClusterConfiguration.APIVersion = "v1beta1"
40-
config.Spec.ClusterConfiguration.Kind = "ClusterConfiguration"
4139
clusterdata, err := json.Marshal(config.Spec.ClusterConfiguration)
4240
if err != nil {
4341
u.Error(err, "failed to marshal cluster configuration")
4442
return errors.WithStack(err)
4543
}
4644

47-
config.Spec.ClusterConfiguration.Kind = "v1beta1"
48-
config.Spec.ClusterConfiguration.APIVersion = "InitConfiguration"
4945
initdata, err := json.Marshal(config.Spec.InitConfiguration)
5046
if err != nil {
5147
u.Error(err, "failed to marshal init configuration")

controllers/kubeadmconfig_controller.go

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ package controllers
1818

1919
import (
2020
"context"
21-
"time"
21+
"encoding/json"
2222

2323
"github.com/go-logr/logr"
2424
"github.com/pkg/errors"
2525
apierrors "k8s.io/apimachinery/pkg/api/errors"
2626
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
kubeadmv1alpha2 "sigs.k8s.io/cluster-api-bootstrap-provider-kubeadm/api/v1alpha2"
28+
"sigs.k8s.io/cluster-api-bootstrap-provider-kubeadm/cloudinit"
2829
"sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha2"
2930
"sigs.k8s.io/cluster-api/pkg/util"
3031
ctrl "sigs.k8s.io/controller-runtime"
@@ -35,21 +36,13 @@ var (
3536
machineKind = v1alpha2.SchemeGroupVersion.WithKind("Machine")
3637
)
3738

38-
39-
// Locker are the methods necessary to add locking around the first control plane init.
40-
type Locker interface {
41-
Acquire(*v1alpha2.Cluster) bool
42-
Release(*v1alpha2.Cluster) bool
43-
}
44-
4539
type bootstrapDataGenerator interface {
4640
GenerateControlPlaneInit(config *kubeadmv1alpha2.KubeadmConfig) error
4741
}
4842

4943
// KubeadmConfigReconciler reconciles a KubeadmConfig object
5044
type KubeadmConfigReconciler struct {
5145
client.Client
52-
ControlPlaneInitLock Locker
5346
Log logr.Logger
5447
BootstrapDataGenerator bootstrapDataGenerator
5548
}
@@ -130,18 +123,28 @@ func (r *KubeadmConfigReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
130123
}
131124
}
132125

133-
if util.IsControlPlaneMachine(machine) {
134-
locked := r.ControlPlaneInitLock.Acquire(cluster)
135-
// Could not acquire the lock so let's try again in a sec
136-
if !locked {
137-
return ctrl.Result{RequeueAfter: 10 * time.Second}, nil
126+
// if the machine has cluster and or init defined on it then generate the init regular join
127+
if config.Spec.InitConfiguration != nil && config.Spec.ClusterConfiguration != nil {
128+
// get both of these to strings to pass to the cloud init control plane generator
129+
initdata, err := json.Marshal(config.Spec.InitConfiguration)
130+
if err != nil {
131+
log.Error(err, "failed to marshal init configuration")
132+
return ctrl.Result{}, err
138133
}
139-
140-
// Generate control plane init
141-
if err := r.BootstrapDataGenerator.GenerateControlPlaneInit(&config); err != nil {
142-
log.Error(err, "error generating control plane init")
134+
clusterdata, err := json.Marshal(config.Spec.ClusterConfiguration)
135+
if err != nil {
136+
log.Error(err, "failed to marshal cluster configuration")
143137
return ctrl.Result{}, err
144138
}
139+
140+
cloudinit.NewInitControlPlane(&cloudinit.ControlPlaneInput{
141+
InitConfiguration: string(initdata),
142+
ClusterConfiguration: string(clusterdata),
143+
})
144+
}
145+
146+
if util.IsControlPlaneMachine(machine) {
147+
145148
}
146149

147150
if err := r.Update(ctx, &config); err != nil {

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5 h1:VBM/0P5TWxwk+Nw6Z+lAw3DKgO76g
256256
k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
257257
sigs.k8s.io/cluster-api v0.0.0-20190725170330-835ee872f98d h1:DjeaMyqyw5tpps/prbudaojzp8gRMPV6L6MU4C8M8Eg=
258258
sigs.k8s.io/cluster-api v0.0.0-20190725170330-835ee872f98d/go.mod h1:DIiQEP2FjsAiEgBTgT5EEUAVM7XRy7aLgeERFXvZHaQ=
259+
sigs.k8s.io/controller-runtime v0.1.12 h1:ovDq28E64PeY1yR+6H7DthakIC09soiDCrKvfP2tPYo=
259260
sigs.k8s.io/controller-runtime v0.2.0-beta.4 h1:S1XVfRWR1MuIXZdkYx3jN8JDw+bbQxmWZroy0i87z/A=
260261
sigs.k8s.io/controller-runtime v0.2.0-beta.4/go.mod h1:HweyYKQ8fBuzdu2bdaeBJvsFgAi/OqBBnrVGXcqKhME=
261262
sigs.k8s.io/controller-tools v0.2.0-beta.4 h1:W+coTe+nkVNclQrikwlRp6GJKwgcrHzvIQZ9kCaak5A=

locker/control_plane_init_locker.go

Lines changed: 0 additions & 114 deletions
This file was deleted.

0 commit comments

Comments
 (0)