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

[feat, docs] - Add ClusterClass support and create flavors #130

Merged
merged 12 commits into from
Feb 23, 2024
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ kubeconfig*
.devbox/*
docs/book
release/*
templates/cluster-template*.yaml
infrastructure-linode/*
57 changes: 39 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
REGISTRY ?= docker.io/linode
IMAGE_NAME ?= cluster-api-provider-linode
CONTROLLER_IMAGE ?= $(REGISTRY)/$(IMAGE_NAME)
TAG ?= dev
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.28.0
OS=$(shell uname -s | tr '[:upper:]' '[:lower:]')
Expand All @@ -12,7 +11,7 @@ ARCH_SHORT := amd64
else ifeq ($(ARCH_SHORT),aarch64)
ARCH_SHORT := arm64
endif
VERSION ?= $(shell git describe --tags --dirty=-dev)
VERSION ?= $(shell git describe --always --tag --dirty=-dev)
BUILD_ARGS := --build-arg VERSION=$(VERSION)
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -73,6 +72,10 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

.PHONY: generate-flavors ## Generate template flavors.
generate-flavors: $(KUSTOMIZE)
./hack/generate-flavors.sh

## --------------------------------------
## Development
## --------------------------------------
Expand Down Expand Up @@ -135,20 +138,16 @@ _e2etest: manifests generate _e2etest-infra
build: manifests generate fmt vet ## Build manager binary.
go build -ldflags="-X github.com/linode/cluster-api-provider-linode/version.version=$(VERSION)" -o bin/manager cmd/main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/main.go

# If you wish to build the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
.PHONY: docker-build
docker-build: ## Build docker image with the manager.
$(CONTAINER_TOOL) build $(BUILD_ARGS) . -t $(CONTROLLER_IMAGE):$(TAG)
$(CONTAINER_TOOL) build $(BUILD_ARGS) . -t $(CONTROLLER_IMAGE):$(VERSION)

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
$(CONTAINER_TOOL) push $(CONTROLLER_IMAGE):$(TAG)
$(CONTAINER_TOOL) push $(CONTROLLER_IMAGE):$(VERSION)

# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
Expand All @@ -163,7 +162,7 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
$(CONTAINER_TOOL) buildx use project-v3-builder
- $(CONTAINER_TOOL) buildx build $(BUILD_ARGS) --push --platform=$(PLATFORMS) --tag $(CONTROLLER_IMAGE):$(TAG) -f Dockerfile.cross .
- $(CONTAINER_TOOL) buildx build $(BUILD_ARGS) --push --platform=$(PLATFORMS) --tag $(CONTROLLER_IMAGE):$(VERSION) -f Dockerfile.cross .
- $(CONTAINER_TOOL) buildx rm project-v3-builder
rm Dockerfile.cross

Expand All @@ -190,20 +189,34 @@ tilt-cluster: ctlptl tilt kind clusterctl
##@ Release:

RELEASE_DIR ?= release
RELEASE_TAG ?= $(shell git describe --abbrev=0 2>/dev/null)

.PHONY: release
release: $(KUSTOMIZE) clean-release set-manifest-image release-manifests generate-flavors release-templates release-metadata clean-release-git

$(RELEASE_DIR):
mkdir -p $(RELEASE_DIR)/

.PHONY: release-metadata
release-metadata: $(RELEASE_DIR)
cp metadata.yaml $(RELEASE_DIR)/metadata.yaml

.PHONY: release-templates
release-templates: $(RELEASE_DIR)
mv templates/cluster-template* $(RELEASE_DIR)/
mv templates/clusterclass* $(RELEASE_DIR)/

.PHONY: set-manifest-image
set-manifest-image: ## Update kustomize image patch file for default resource.
sed -i'' -e 's@image: .*@image: '"${MANIFEST_IMG}:${MANIFEST_TAG}"'@' ./config/default/manager_image_patch.yaml
sed -i'' -e 's@image: .*@image: '"$(REGISTRY)/$(IMAGE_NAME):$(VERSION)"'@' ./config/default/manager_image_patch.yaml

.PHONY: release
release: $(KUSTOMIZE)
rm -rf $(RELEASE_DIR)
mkdir -p $(RELEASE_DIR)/
$(MAKE) set-manifest-image MANIFEST_IMG=$(REGISTRY)/$(IMAGE_NAME) MANIFEST_TAG=$(RELEASE_TAG)
.PHONY: release-manifests
release-manifests: $(KUSTOMIZE) $(RELEASE_DIR)
$(KUSTOMIZE) build config/default > $(RELEASE_DIR)/infrastructure-components.yaml
cp templates/cluster-template* $(RELEASE_DIR)/
cp metadata.yaml $(RELEASE_DIR)/metadata.yaml

.PHONY: local-release
local-release:
RELEASE_DIR=infrastructure-linode/0.0.0 $(MAKE) release
$(MAKE) clean-release-git

## --------------------------------------
## Cleanup
Expand All @@ -215,6 +228,14 @@ release: $(KUSTOMIZE)
clean:
rm -rf $(LOCALBIN)

.PHONY: clean-release-git
clean-release-git: ## Restores the git files usually modified during a release
git restore config/default/*manager_image_patch.yaml

.PHONY: clean-release
clean-release: clean-release-git
rm -rf $(RELEASE_DIR)

## --------------------------------------
## Build Dependencies
## --------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ docker_build(

local_resource(
'capi-controller-manager',
cmd='EXP_CLUSTER_RESOURCE_SET=true clusterctl init --addon helm',
cmd='EXP_CLUSTER_RESOURCE_SET=true CLUSTER_TOPOLOGY=true clusterctl init --addon helm',
)

manager_yaml = decode_yaml_stream(kustomize("config/default"))
Expand Down
143 changes: 92 additions & 51 deletions docs/src/developers/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
- [Setting up](#setting-up)
- [Base requirements](#base-requirements)
- [Clone the source code](#clone-the-source-code)
- [Enable git hooks](#enable-git-hooks)
- [Set up devbox](#recommended-set-up-devbox)
- [Get familiar with basic concepts](#get-familiar-with-basic-concepts)
- [Developing](#developing)
- [Enable git hooks](#enable-git-hooks)
- [Setting up the environment](#setting-up-the-environment)
- [Using devbox](#using-devbox)
- [Tilt Requirements](#tilt-requirements)
- [Using Tilt](#using-tilt)
- [Deploying a workload cluster](#deploying-a-workload-cluster)
- [Customizing the cluster deployment](#customizing-the-cluster-deployment)
- [Creating the workload cluster](#creating-the-workload-cluster)
- [Using the default flavor](#using-the-default-flavor)
- [Using ClusterClass (alpha)](#using-clusterclass)
- [Cleaning up the workload cluster](#cleaning-up-the-workload-cluster)
- [Automated Testing](#automated-testing)
- [E2E Testing](#e2e-testing)
Expand All @@ -27,60 +27,40 @@

### Base requirements

```admonish warning
Ensure you have your `LINODE_TOKEN` set as outlined in the
[getting started prerequisites](../topics/getting-started.md#Prerequisites) section.
```

There are no requirements since development dependencies are fetched as
needed via the make targets, but a recommendation is to
[install Devbox](https://jetpack.io/devbox/docs/installing_devbox/)

### Clone the source code

```shell
```sh
git clone https://github.com/linode/cluster-api-provider-linode
cd cluster-api-provider-linode
```

### Get familiar with basic concepts

This provider is based on the [Cluster API project](https://github.com/kubernetes-sigs/cluster-api).
It's recommended to familiarize yourself with Cluster API resources, concepts, and conventions
outlined in the [Cluster API Book](https://cluster-api.sigs.k8s.io/).

## Developing

This repository uses [Go Modules](https://github.com/golang/go/wiki/Modules)
to track and vendor dependencies.

To pin a new dependency, run:
```bash
go get <repository>@<version>
```

### Enable git hooks

To enable automatic code validation on code push, execute the following commands:

```bash
```sh
PATH="$PWD/bin:$PATH" make husky && husky install
```

If you would like to temporarily disable git hook, set `SKIP_GIT_PUSH_HOOK` value:

```bash
```sh
SKIP_GIT_PUSH_HOOK=1 git push
```

### Setting up the environment

```admonish warning
Ensure you have your `LINODE_TOKEN` set as outlined in the
[getting started prerequisites](../topics/getting-started.md#Prerequisites) section.
```
### [Recommended] Set up devbox

All development dependencies should be taken care of via Devbox and/or make target dependencies.

#### Using devbox

1. Install dependent packages in your project
```shell
1. Install dependent packages in your project
```sh
devbox install
```

Expand All @@ -89,18 +69,35 @@ All development dependencies should be taken care of via Devbox and/or make targ
```

2. Use devbox environment
```shell
```sh
devbox shell
```

From this point you can use the devbox shell like a regular shell.
From this point you can use the devbox shell like a regular shell.
The rest of the guide assumes a devbox shell is used, but the make target
dependencies will install any missing dependencies if needed when running
outside of a devbox shell.
outside a devbox shell.

### Get familiar with basic concepts

This provider is based on the [Cluster API project](https://github.com/kubernetes-sigs/cluster-api).
It's recommended to familiarize yourself with Cluster API resources, concepts, and conventions
outlined in the [Cluster API Book](https://cluster-api.sigs.k8s.io/).

## Developing

This repository uses [Go Modules](https://github.com/golang/go/wiki/Modules)
to track and vendor dependencies.

To pin a new dependency, run:
```sh
go get <repository>@<version>
```


### Using tilt
To build a kind cluster and start Tilt, simply run:
```shell
```sh
make tilt-cluster
```

Expand All @@ -109,19 +106,47 @@ Once your kind management cluster is up and running, you can

To tear down the tilt-cluster, run

```shell
```sh
kind delete cluster --name tilt
```

### Deploying a workload cluster

After your kind management cluster is up and running with Tilt, you should be ready to deploy your first cluster.

#### Generating the cluster templates

For local development, templates should be generated via:

```sh
make local-release
```

This creates `infrastructure-linode/0.0.0/` with all the cluster templates:

```sh
infrastructure-linode/0.0.0
├── cluster-template-kubeadm-clusterclass.yaml
├── cluster-template.yaml
├── infrastructure-components.yaml
└── metadata.yaml
```

This can then be used with `clusterctl` by adding the following to `~/.clusterctl/cluster-api.yaml`
(assuming the repo exists in the `$HOME` directory):

```
providers:
- name: linode
url: ${HOME}/cluster-api-provider-linode/infrastructure-linode/0.0.0/infrastructure-components.yaml
type: InfrastructureProvider
```

#### Customizing the cluster deployment

Here is a list of required configuration parameters:

```bash
```sh
# Cluster settings
export CLUSTER_NAME=capl-cluster
export KUBERNETES_VERSION=v1.29.1
Expand All @@ -137,30 +162,46 @@ export LINODE_MACHINE_TYPE=g6-standard-2
You can also use `clusterctl generate` to see which variables need to be set:

```
clusterctl generate cluster $CLUSTER_NAME --from ./templates/cluster-template.yaml --list-variables
clusterctl generate cluster $CLUSTER_NAME --infrastructure linode:0.0.0 [--flavor <flavor>] --list-variables
```

~~~

```admonish warning
Please note the templates require the use of `clusterctl generate` to substitute the environment variables properly.
```

#### Creating the workload cluster

##### Using the default flavor

Once you have all the necessary environment variables set,
you can deploy a workload cluster with the following command:
you can deploy a workload cluster with the default flavor:

```shell
```sh
clusterctl generate cluster $CLUSTER_NAME \
--kubernetes-version v1.29.1 \
--from templates/cluster-template.yaml \
--infrastructure linode:0.0.0 \
| kubectl apply -f -
```

This will provision the cluster with the CNI defaulted to [cilium](../topics/addons.md#cilium)
and the [linode-ccm](../topics/addons.md#ccm) installed.

##### Using ClusterClass (alpha)

~~~admonish success title=""
ClusterClass experimental feature is enabled by default in the KIND management cluster
created via `make tilt-cluster`
~~~

You can use the `clusterclass` flavor to create a workload cluster as well, assuming the
management cluster has the [ClusterTopology feature gate set](https://cluster-api.sigs.k8s.io/tasks/experimental-features/cluster-class/):

```sh
clusterctl generate cluster $CLUSTER_NAME \
--kubernetes-version v1.29.1 \
--infrastructure linode:0.0.0 \
--flavor kubeadm-clusterclass \
| kubectl apply -f -
```

```admonish question title=""
For any issues, please refer to the [troubleshooting guide](../topics/troubleshooting.md).
```
Expand All @@ -169,7 +210,7 @@ For any issues, please refer to the [troubleshooting guide](../topics/troublesho

To delete the cluster, simply run:

```bash
```sh
kubectl delete cluster $CLUSTER_NAME
```

Expand All @@ -182,7 +223,7 @@ For any issues, please refer to the [troubleshooting guide](../topics/troublesho
#### E2E Testing

To run E2E locally run:
```bash
```sh
make e2etest
```

Expand Down
Loading