Skip to content

Commit

Permalink
⚠️ Add exp/ package with MachinePool
Browse files Browse the repository at this point in the history
Signed-off-by: Vince Prignano <vincepri@vmware.com>
  • Loading branch information
vincepri committed Mar 4, 2020
1 parent aa289e0 commit 2bd9fcf
Show file tree
Hide file tree
Showing 49 changed files with 710 additions and 900 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT ?=60s
export DOCKER_CLI_EXPERIMENTAL := enabled

# Directories.
EXP_DIR := exp
TOOLS_DIR := hack/tools
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
BIN_DIR := bin
Expand Down Expand Up @@ -209,6 +210,7 @@ generate-go-core: $(CONTROLLER_GEN) $(CONVERSION_GEN)
$(CONTROLLER_GEN) \
object:headerFile=./hack/boilerplate/boilerplate.generatego.txt \
paths=./api/... \
paths=./$(EXP_DIR)/api/... \
paths=./cmd/clusterctl/...
$(CONVERSION_GEN) \
--input-dirs=./api/v1alpha2 \
Expand Down Expand Up @@ -256,6 +258,8 @@ generate-core-manifests: $(CONTROLLER_GEN) ## Generate manifests for the core pr
$(CONTROLLER_GEN) \
paths=./api/... \
paths=./controllers/... \
paths=./$(EXP_DIR)/api/... \
paths=./$(EXP_DIR)/controllers/... \
crd:crdVersions=v1 \
rbac:roleName=manager-role \
output:crd:dir=./config/crd/bases \
Expand Down Expand Up @@ -297,7 +301,6 @@ generate-kubeadm-control-plane-manifests: $(CONTROLLER_GEN) ## Generate manifest
modules: ## Runs go mod to ensure modules are up to date.
go mod tidy
cd $(TOOLS_DIR); go mod tidy
cd $(E2E_FRAMEWORK_DIR); go mod tidy
cd $(CAPD_DIR); $(MAKE) modules

## --------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions api/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ func (*MachineDeployment) Hub() {}
func (*MachineDeploymentList) Hub() {}
func (*MachineHealthCheck) Hub() {}
func (*MachineHealthCheckList) Hub() {}
func (*MachinePool) Hub() {}
func (*MachinePoolList) Hub() {}
125 changes: 0 additions & 125 deletions api/v1alpha3/zz_generated.deepcopy.go

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

11 changes: 9 additions & 2 deletions bootstrap/kubeadm/config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,18 @@ rules:
resources:
- clusters
- clusters/status
- machinepools
- machinepools/status
- machines
- machines/status
verbs:
- get
- list
- watch
- apiGroups:
- exp.cluster.x-k8s.io
resources:
- machinepools
- machinepools/status
verbs:
- get
- list
- watch
31 changes: 18 additions & 13 deletions bootstrap/kubeadm/controllers/kubeadmconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import (
bsutil "sigs.k8s.io/cluster-api/bootstrap/util"
"sigs.k8s.io/cluster-api/controllers/remote"
capierrors "sigs.k8s.io/cluster-api/errors"
expv1 "sigs.k8s.io/cluster-api/exp/api/v1alpha3"
"sigs.k8s.io/cluster-api/feature"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/cluster-api/util/secret"
Expand All @@ -57,7 +59,8 @@ type InitLocker interface {
}

// +kubebuilder:rbac:groups=bootstrap.cluster.x-k8s.io,resources=kubeadmconfigs;kubeadmconfigs/status,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=clusters;clusters/status;machines;machines/status;machinepools;machinepools/status,verbs=get;list;watch
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=clusters;clusters/status;machines;machines/status,verbs=get;list;watch
// +kubebuilder:rbac:groups=exp.cluster.x-k8s.io,resources=machinepools;machinepools/status,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=secrets;events;configmaps,verbs=get;list;watch;create;update;patch;delete

// KubeadmConfigReconciler reconciles a KubeadmConfig object
Expand Down Expand Up @@ -88,30 +91,32 @@ func (r *KubeadmConfigReconciler) SetupWithManager(mgr ctrl.Manager, option cont

r.scheme = mgr.GetScheme()

err := ctrl.NewControllerManagedBy(mgr).
builder := ctrl.NewControllerManagedBy(mgr).
For(&bootstrapv1.KubeadmConfig{}).
WithOptions(option).
Watches(
&source.Kind{Type: &clusterv1.Machine{}},
&handler.EnqueueRequestsFromMapFunc{
ToRequests: handler.ToRequestsFunc(r.MachineToBootstrapMapFunc),
},
).
Watches(
&source.Kind{Type: &clusterv1.MachinePool{}},
&handler.EnqueueRequestsFromMapFunc{
ToRequests: handler.ToRequestsFunc(r.MachinePoolToBootstrapMapFunc),
},
).
Watches(
&source.Kind{Type: &clusterv1.Cluster{}},
&handler.EnqueueRequestsFromMapFunc{
ToRequests: handler.ToRequestsFunc(r.ClusterToKubeadmConfigs),
},
).
WithOptions(option).
Complete(r)
)

if err != nil {
if feature.Gates.Enabled(feature.MachinePool) {
builder = builder.Watches(
&source.Kind{Type: &expv1.MachinePool{}},
&handler.EnqueueRequestsFromMapFunc{
ToRequests: handler.ToRequestsFunc(r.MachinePoolToBootstrapMapFunc),
},
)
}

if err := builder.Complete(r); err != nil {
return errors.Wrap(err, "failed setting up with a controller manager")
}

Expand Down Expand Up @@ -565,7 +570,7 @@ func (r *KubeadmConfigReconciler) MachineToBootstrapMapFunc(o handler.MapObject)
func (r *KubeadmConfigReconciler) MachinePoolToBootstrapMapFunc(o handler.MapObject) []ctrl.Request {
result := []ctrl.Request{}

m, ok := o.Object.(*clusterv1.MachinePool)
m, ok := o.Object.(*expv1.MachinePool)
if !ok {
return nil
}
Expand Down
26 changes: 15 additions & 11 deletions bootstrap/kubeadm/controllers/kubeadmconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha3"
kubeadmv1beta1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/types/v1beta1"
fakeremote "sigs.k8s.io/cluster-api/controllers/remote/fake"
expv1 "sigs.k8s.io/cluster-api/exp/api/v1alpha3"
"sigs.k8s.io/cluster-api/util/secret"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -50,6 +51,9 @@ func setupScheme() *runtime.Scheme {
if err := clusterv1.AddToScheme(scheme); err != nil {
panic(err)
}
if err := expv1.AddToScheme(scheme); err != nil {
panic(err)
}
if err := bootstrapv1.AddToScheme(scheme); err != nil {
panic(err)
}
Expand Down Expand Up @@ -708,15 +712,15 @@ func TestReconcileIfJoinNodePoolsAndControlPlaneIsReady(t *testing.T) {

var useCases = []struct {
name string
machinePool *clusterv1.MachinePool
machinePool *expv1.MachinePool
configName string
configBuilder func(*clusterv1.MachinePool, string) *bootstrapv1.KubeadmConfig
configBuilder func(*expv1.MachinePool, string) *bootstrapv1.KubeadmConfig
}{
{
name: "Join a worker node with a fully compiled kubeadm config object",
machinePool: newWorkerMachinePool(cluster),
configName: "workerpool-join-cfg",
configBuilder: func(machinePool *clusterv1.MachinePool, name string) *bootstrapv1.KubeadmConfig {
configBuilder: func(machinePool *expv1.MachinePool, name string) *bootstrapv1.KubeadmConfig {
return newWorkerPoolJoinKubeadmConfig(machinePool)
},
},
Expand Down Expand Up @@ -1621,17 +1625,17 @@ func newControlPlaneMachine(cluster *clusterv1.Cluster, name string) *clusterv1.
}

// newMachinePool return a CAPI machine pool object; if cluster is not nil, the machine pool is linked to the cluster as well
func newMachinePool(cluster *clusterv1.Cluster, name string) *clusterv1.MachinePool {
machine := &clusterv1.MachinePool{
func newMachinePool(cluster *clusterv1.Cluster, name string) *expv1.MachinePool {
machine := &expv1.MachinePool{
TypeMeta: metav1.TypeMeta{
Kind: "MachinePool",
APIVersion: clusterv1.GroupVersion.String(),
APIVersion: expv1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: name,
},
Spec: clusterv1.MachinePoolSpec{
Spec: expv1.MachinePoolSpec{
Template: clusterv1.MachineTemplateSpec{
Spec: clusterv1.MachineSpec{
Bootstrap: clusterv1.Bootstrap{
Expand All @@ -1653,7 +1657,7 @@ func newMachinePool(cluster *clusterv1.Cluster, name string) *clusterv1.MachineP
return machine
}

func newWorkerMachinePool(cluster *clusterv1.Cluster) *clusterv1.MachinePool {
func newWorkerMachinePool(cluster *clusterv1.Cluster) *expv1.MachinePool {
return newMachinePool(cluster, "worker-machinepool")
}

Expand Down Expand Up @@ -1709,7 +1713,7 @@ func newControlPlaneInitKubeadmConfig(machine *clusterv1.Machine, name string) *

// newMachinePoolKubeadmConfig return a CABPK KubeadmConfig object; if machine pool is not nil,
// the KubeadmConfig is linked to the machine pool as well
func newMachinePoolKubeadmConfig(machinePool *clusterv1.MachinePool, name string) *bootstrapv1.KubeadmConfig {
func newMachinePoolKubeadmConfig(machinePool *expv1.MachinePool, name string) *bootstrapv1.KubeadmConfig {
config := &bootstrapv1.KubeadmConfig{
TypeMeta: metav1.TypeMeta{
Kind: "KubeadmConfig",
Expand All @@ -1724,7 +1728,7 @@ func newMachinePoolKubeadmConfig(machinePool *clusterv1.MachinePool, name string
config.ObjectMeta.OwnerReferences = []metav1.OwnerReference{
{
Kind: "MachinePool",
APIVersion: clusterv1.GroupVersion.String(),
APIVersion: expv1.GroupVersion.String(),
Name: machinePool.Name,
UID: types.UID(fmt.Sprintf("%s uid", machinePool.Name)),
},
Expand All @@ -1735,7 +1739,7 @@ func newMachinePoolKubeadmConfig(machinePool *clusterv1.MachinePool, name string
return config
}

func newWorkerPoolJoinKubeadmConfig(machinePool *clusterv1.MachinePool) *bootstrapv1.KubeadmConfig {
func newWorkerPoolJoinKubeadmConfig(machinePool *expv1.MachinePool) *bootstrapv1.KubeadmConfig {
c := newMachinePoolKubeadmConfig(machinePool, "workerpool-join-cfg")
c.Spec.JoinConfiguration = &kubeadmv1beta1.JoinConfiguration{
ControlPlane: nil,
Expand Down
2 changes: 2 additions & 0 deletions bootstrap/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
kubeadmbootstrapv1alpha2 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha2"
kubeadmbootstrapv1alpha3 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha3"
kubeadmbootstrapcontrollers "sigs.k8s.io/cluster-api/bootstrap/kubeadm/controllers"
expv1alpha3 "sigs.k8s.io/cluster-api/exp/api/v1alpha3"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -49,6 +50,7 @@ func init() {

_ = clientgoscheme.AddToScheme(scheme)
_ = clusterv1alpha3.AddToScheme(scheme)
_ = expv1alpha3.AddToScheme(scheme)
_ = kubeadmbootstrapv1alpha2.AddToScheme(scheme)
_ = kubeadmbootstrapv1alpha3.AddToScheme(scheme)
// +kubebuilder:scaffold:scheme
Expand Down
Loading

0 comments on commit 2bd9fcf

Please sign in to comment.