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 3, 2020
1 parent f65d4ae commit 328db6e
Show file tree
Hide file tree
Showing 46 changed files with 669 additions and 852 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/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/api/... \
paths=./exp/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
8 changes: 5 additions & 3 deletions bootstrap/kubeadm/controllers/kubeadmconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ 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/util"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/cluster-api/util/secret"
Expand All @@ -57,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 @@ -97,7 +99,7 @@ func (r *KubeadmConfigReconciler) SetupWithManager(mgr ctrl.Manager, option cont
},
).
Watches(
&source.Kind{Type: &clusterv1.MachinePool{}},
&source.Kind{Type: &expv1.MachinePool{}},
&handler.EnqueueRequestsFromMapFunc{
ToRequests: handler.ToRequestsFunc(r.MachinePoolToBootstrapMapFunc),
},
Expand Down Expand Up @@ -565,7 +567,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
5 changes: 3 additions & 2 deletions bootstrap/util/configowner.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
"sigs.k8s.io/cluster-api/controllers/external"
expv1 "sigs.k8s.io/cluster-api/exp/api/v1alpha3"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -82,8 +83,8 @@ func GetConfigOwner(ctx context.Context, c client.Client, obj metav1.Object) (*C
return nil, errors.Wrapf(err, "failed to parse GroupVersion from %q", ref.APIVersion)
}

if (ref.Kind == "Machine" || ref.Kind == "MachinePool") &&
refgvk.Group == clusterv1.GroupVersion.Group {
if (ref.Kind == "Machine" && refgvk.Group == clusterv1.GroupVersion.Group) ||
(ref.Kind == "MachinePool" && refgvk.Group == expv1.GroupVersion.Group) {
return GetOwnerByRef(ctx, c, &corev1.ObjectReference{
APIVersion: ref.APIVersion,
Kind: ref.Kind,
Expand Down
10 changes: 6 additions & 4 deletions bootstrap/util/configowner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/utils/pointer"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha3"
expv1 "sigs.k8s.io/cluster-api/exp/api/v1alpha3"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

Expand All @@ -34,6 +35,7 @@ func TestGetConfigOwner(t *testing.T) {

scheme := runtime.NewScheme()
g.Expect(clusterv1.AddToScheme(scheme)).To(Succeed())
g.Expect(expv1.AddToScheme(scheme)).To(Succeed())

t.Run("should get the owner when present (Machine)", func(t *testing.T) {
g := NewWithT(t)
Expand Down Expand Up @@ -81,18 +83,18 @@ func TestGetConfigOwner(t *testing.T) {

t.Run("should get the owner when present (MachinePool)", func(t *testing.T) {
g := NewWithT(t)
myPool := &clusterv1.MachinePool{
myPool := &expv1.MachinePool{
ObjectMeta: metav1.ObjectMeta{
Name: "my-machine-pool",
Namespace: "my-ns",
Labels: map[string]string{
clusterv1.MachineControlPlaneLabelName: "",
},
},
Spec: clusterv1.MachinePoolSpec{
Spec: expv1.MachinePoolSpec{
ClusterName: "my-cluster",
},
Status: clusterv1.MachinePoolStatus{
Status: expv1.MachinePoolStatus{
InfrastructureReady: true,
},
}
Expand All @@ -103,7 +105,7 @@ func TestGetConfigOwner(t *testing.T) {
OwnerReferences: []metav1.OwnerReference{
{
Kind: "MachinePool",
APIVersion: clusterv1.GroupVersion.String(),
APIVersion: expv1.GroupVersion.String(),
Name: "my-machine-pool",
},
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/pkg/client/cluster/mover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ var moveTests = []struct {
"/v1, Kind=Secret, ns1/cluster1-ca",
"/v1, Kind=Secret, ns1/cluster1-kubeconfig",
"bootstrap.cluster.x-k8s.io/v1alpha3, Kind=DummyBootstrapConfigTemplate, ns1/mp1",
"cluster.x-k8s.io/v1alpha3, Kind=MachinePool, ns1/mp1",
"exp.cluster.x-k8s.io/v1alpha3, Kind=MachinePool, ns1/mp1",
"infrastructure.cluster.x-k8s.io/v1alpha3, Kind=DummyInfrastructureCluster, ns1/cluster1",
"infrastructure.cluster.x-k8s.io/v1alpha3, Kind=DummyInfrastructureMachineTemplate, ns1/mp1",
},
Expand Down
Loading

0 comments on commit 328db6e

Please sign in to comment.