Skip to content

Commit

Permalink
fix e2e tests and bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
bschimke95 committed Jun 26, 2024
1 parent b69ba7b commit 0f93432
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 46 deletions.
66 changes: 66 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# syntax=docker/dockerfile:1.4

# Copyright 2018 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Build the manager binary
# Run this with docker build --build-arg builder_image=<golang:x.y.z>
ARG builder_image

# Build architecture
ARG ARCH

# Ignore Hadolint rule "Always tag the version of an image explicitly."
# It's an invalid finding since the image is explicitly set in the Makefile.
# https://github.com/hadolint/hadolint/wiki/DL3006
# hadolint ignore=DL3006
FROM ${builder_image} as builder
WORKDIR /workspace

# Run this with docker build --build-arg goproxy=$(go env GOPROXY) to override the goproxy
ARG goproxy=https://proxy.golang.org
# Run this with docker build --build-arg package=./controlplane/kubeadm or --build-arg package=./bootstrap/kubeadm
ENV GOPROXY=$goproxy

# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum

# Cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download

# Copy the sources
COPY ./ ./

# Build
ARG package=.
ARG ARCH
ARG ldflags

# Do not force rebuild of up-to-date packages (do not use -a) and use the compiler cache folder
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \
go build -trimpath -ldflags "${ldflags} -extldflags '-static'" \
-o manager ${package}

# Production image
FROM gcr.io/
WORKDIR /
COPY --from=builder /workspace/manager .
# Use uid of nonroot user (65532) because kubernetes expects numeric user when applying pod security policies
USER 65532
ENTRYPOINT ["/manager"]
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ dev-controlplane:
##@ release:

## latest git tag for the commit, e.g., v0.3.10
RELEASE_TAG ?= $(shell git describe --abbrev=0 --tags 2>/dev/null)
## set to v0.0.0 if no tag is found
RELEASE_TAG ?= $(shell git describe --abbrev=0 --tags 2>/dev/null || echo v0.0.0)
ifneq (,$(findstring -,$(RELEASE_TAG)))
PRE_RELEASE=true
endif
Expand Down Expand Up @@ -230,7 +231,7 @@ generate-bootstrap-conversions: $(CONVERSION_GEN)

# Build the docker image
docker-build-bootstrap: manager-bootstrap ## Build bootstrap
DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg TARGETARCH=$(ARCH) --build-arg package=./bootstrap/main.go --build-arg ldflags="$(LDFLAGS)" . -t ${BOOTSTRAP_IMG}:${BOOTSTRAP_IMG_TAG}
DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg package=./bootstrap/main.go --build-arg ldflags="$(LDFLAGS)" . -t ${BOOTSTRAP_IMG}:${BOOTSTRAP_IMG_TAG}

# Push the docker image
docker-push-bootstrap: ## Push bootstrap
Expand Down Expand Up @@ -302,7 +303,7 @@ generate-controlplane-conversions: $(CONVERSION_GEN)
--go-header-file=./hack/boilerplate.go.txt

docker-build-controlplane: manager-controlplane ## Build control-plane
DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg TARGETARCH=$(ARCH) --build-arg package=./controlplane/main.go --build-arg ldflags="$(LDFLAGS)" . -t ${CONTROLPLANE_IMG}:$(CONTROLPLANE_IMG_TAG)
DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg package=./controlplane/main.go --build-arg ldflags="$(LDFLAGS)" . -t ${CONTROLPLANE_IMG}:$(CONTROLPLANE_IMG_TAG)

docker-push-controlplane: ## Push control-plane
docker push ${CONTROLPLANE_IMG}:$(CONTROLPLANE_IMG_TAG)
Expand Down
3 changes: 2 additions & 1 deletion bootstrap/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ spec:
- /manager
args:
- --enable-leader-election
image: controller:latest
# TODO: how to only set this for the e2e tests
image: controller:dev
name: manager
terminationGracePeriodSeconds: 10
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
kind: CK8sConfig
metadata:
name: ck8sconfig-sample
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
kind: CK8sConfigTemplate
metadata:
name: ck8sconfigtemplate-sample
Expand Down
2 changes: 1 addition & 1 deletion controlplane/config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ patchesStrategicMerge:
# Protect the /metrics endpoint by putting it behind auth.
# If you want your controller-manager to expose the /metrics
# endpoint w/o any authn/z, please comment the following line.
- manager_auth_proxy_patch.yaml
#- manager_auth_proxy_patch.yaml

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
Expand Down
2 changes: 1 addition & 1 deletion controlplane/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spec:
- /manager
args:
- --enable-leader-election
image: controller:latest
image: controller:dev
name: manager
resources:
limits:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
kind: CK8sControlPlane
metadata:
name: ck8scontrolplane-sample
Expand Down
4 changes: 2 additions & 2 deletions docs/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The default behaviour is to `snap install k8s` using the matching track (e.g. in
You can override this behaviour by changing the default installation script by setting the following fields on the config template:

```yaml
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
kind: CK8sControlPlane
metadata:
name: ${CLUSTER_NAME}-control-plane
Expand Down Expand Up @@ -47,7 +47,7 @@ For airgap deployments, or environment you can specify `airGapped: true` to prev
Any extra yaml files placed in `/capi/manifests` will be applied once on the cluster after bootstrapping. Files are applied in alphabetical order, so you can use this in case of dependencies. Example:

```yaml
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
kind: CK8sControlPlane
metadata:
name: ${CLUSTER_NAME}-control-plane
Expand Down
3 changes: 2 additions & 1 deletion pkg/ck8s/manifests/k8sd-proxy-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ spec:
effect: NoSchedule
containers:
- name: k8sd-proxy
image: ghcr.io/canonical/cluster-api-k8s/socat:1.8.0.0
# TODO: change back to ghcr image once this is public
image: alpine/socat:1.8.0.0
env:
# TODO: Make this more robust by possibly finding/parsing the right IP.
# This works as a start but might not be sufficient as the kubelet IP might not match microcluster IP.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
- 10.46.0.0/16
serviceDomain: cluster.local
controlPlaneRef:
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
kind: CK8sControlPlane
name: ${CLUSTER_NAME}-control-plane
infrastructureRef:
Expand All @@ -27,7 +27,7 @@ metadata:
name: ${CLUSTER_NAME}
spec: {}
---
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
kind: CK8sControlPlane
metadata:
name: ${CLUSTER_NAME}-control-plane
Expand Down Expand Up @@ -69,12 +69,6 @@ spec:
permissions: "0777"
preK3sCommands:
- ./wait-signal.sh "${TOKEN}" "${SERVER}" "${NAMESPACE}"
serverConfig:
tlsSan:
- localhost
- 127.0.0.1
- 0.0.0.0
- host.docker.internal
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachineTemplate
Expand Down Expand Up @@ -111,7 +105,7 @@ spec:
clusterName: ${CLUSTER_NAME}
bootstrap:
configRef:
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
kind: CK8sConfigTemplate
name: ${CLUSTER_NAME}-md-0
infrastructureRef:
Expand All @@ -129,7 +123,7 @@ spec:
spec:
customImage: kindest/node:${KIND_IMAGE_VERSION}
---
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
kind: CK8sConfigTemplate
metadata:
name: ${CLUSTER_NAME}-md-0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
- 10.46.0.0/16
serviceDomain: cluster.local
controlPlaneRef:
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
kind: CK8sControlPlane
name: ${CLUSTER_NAME}-control-plane
infrastructureRef:
Expand All @@ -30,7 +30,7 @@ metadata:
name: ${CLUSTER_NAME}
spec: {}
---
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
kind: CK8sControlPlane
metadata:
name: ${CLUSTER_NAME}-control-plane
Expand All @@ -42,10 +42,6 @@ spec:
name: ${CLUSTER_NAME}-control-plane
replicas: ${CONTROL_PLANE_MACHINE_COUNT}
version: ${KUBERNETES_VERSION}
spec:
serverConfig:
tlsSan:
- 0.0.0.0
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachineTemplate
Expand Down Expand Up @@ -83,7 +79,7 @@ spec:
clusterName: ${CLUSTER_NAME}
bootstrap:
configRef:
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
kind: CK8sConfigTemplate
name: ${CLUSTER_NAME}-md-0
infrastructureRef:
Expand All @@ -101,7 +97,7 @@ spec:
spec:
customImage: kindest/node:${KIND_IMAGE_VERSION}
---
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
kind: CK8sConfigTemplate
metadata:
name: ${CLUSTER_NAME}-md-0
Expand Down
37 changes: 21 additions & 16 deletions test/e2e/data/infrastructure-docker/cluster-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ spec:
clusterNetwork:
pods:
cidrBlocks:
- 10.45.0.0/16
- 10.1.0.0/16
services:
cidrBlocks:
- 10.46.0.0/16
- 10.152.0.0/16
serviceDomain: cluster.local
controlPlaneRef:
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
kind: CK8sControlPlane
name: ${CLUSTER_NAME}-control-plane
infrastructureRef:
Expand All @@ -30,22 +30,24 @@ metadata:
name: ${CLUSTER_NAME}
spec: {}
---
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
kind: CK8sControlPlane
metadata:
name: ${CLUSTER_NAME}-control-plane
namespace: ${NAMESPACE}
spec:
infrastructureTemplate:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachineTemplate
name: ${CLUSTER_NAME}-control-plane
machineTemplate:
infrastructureTemplate:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachineTemplate
name: ${CLUSTER_NAME}-control-plane
spec:
airGapped: true
controlPlane:
extraKubeAPIServerArgs:
--anonymous-auth: "true"
replicas: ${CONTROL_PLANE_MACHINE_COUNT}
version: ${KUBERNETES_VERSION}
spec:
serverConfig:
tlsSan:
- 0.0.0.0
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachineTemplate
Expand All @@ -55,7 +57,8 @@ metadata:
spec:
template:
spec:
customImage: kindest/node:${KIND_IMAGE_VERSION}
# TODO: make this customable
customImage: k8s-snap:dev
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
Expand All @@ -82,7 +85,7 @@ spec:
clusterName: ${CLUSTER_NAME}
bootstrap:
configRef:
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
kind: CK8sConfigTemplate
name: ${CLUSTER_NAME}-md-0
infrastructureRef:
Expand All @@ -98,13 +101,15 @@ metadata:
spec:
template:
spec:
customImage: kindest/node:${KIND_IMAGE_VERSION}
# TODO: make this customable
customImage: k8s-snap:dev
---
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
kind: CK8sConfigTemplate
metadata:
name: ${CLUSTER_NAME}-md-0
namespace: ${NAMESPACE}
spec:
template:
spec:
airGapped: true

0 comments on commit 0f93432

Please sign in to comment.