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

⚠️ Add exp/ package with MachinePool #2512

Merged
merged 1 commit into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -39,6 +39,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 @@ -56,7 +58,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 @@ -87,30 +90,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 @@ -564,7 +569,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
29 changes: 18 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,8 @@ 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/feature"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/secret"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -51,6 +53,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 @@ -702,22 +707,24 @@ func TestReconcileIfJoinNodesAndControlPlaneIsReady(t *testing.T) {
}

func TestReconcileIfJoinNodePoolsAndControlPlaneIsReady(t *testing.T) {
_ = feature.MutableGates.Set("MachinePool=true")

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

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 @@ -1622,17 +1629,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 @@ -1654,7 +1661,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 @@ -1710,7 +1717,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 @@ -1725,7 +1732,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 @@ -1736,7 +1743,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
Loading