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: auto certs through the init container #44

Merged
merged 4 commits into from
Sep 4, 2024
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
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ jobs:
if: "!contains(github.event.head_commit.message, '[ci skip]')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
Expand All @@ -34,3 +35,4 @@ jobs:
- name: Run e2e tests
run: |
make deploy
kubectl rollout status deploy/kcl-webhook-server --timeout=1m
108 changes: 101 additions & 7 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
permissions:
contents: write
jobs:
image-amd64:
webhook-init-image-amd64:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -26,6 +26,10 @@ jobs:
version: v0.11.2
install: true

- name: Copy and edit amd4 arch for Dockerfile
run: |
cp docker/amd64/Dockerfile.init Dockerfile

# <--- Login, build and push image to Docker Hub --->
- name: Login to Docker Hub
uses: docker/login-action@v3
Expand All @@ -37,7 +41,7 @@ jobs:
id: meta
uses: docker/metadata-action@v5
with:
images: kcllang/webhookserver
images: kcllang/webhook-init
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
Expand All @@ -47,7 +51,98 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

image-arm64:
webhook-server-image-amd64:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: v0.11.2
install: true

- name: Copy and edit amd4 arch for Dockerfile
run: |
cp docker/amd64/Dockerfile.server Dockerfile

# <--- Login, build and push image to Docker Hub --->
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: kcllang/webhook-server
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

webhook-init-image-arm64:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: v0.11.2
install: true

# <--- Login, build and push image to Docker Hub --->
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Copy and edit arm64 arch for Dockerfile
run: |
cp docker/amd64/Dockerfile.init Dockerfile
sed -i 's/kcllang/kcl-arm64\/kcllang/kcl/g' Dockerfile

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: kcllang/webhook-init-arm64
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

webhook-server-image-arm64:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -76,17 +171,16 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Edit arm64 arch for Dockerfile
- name: Copy and edit arm64 arch for Dockerfile
run: |
sed -i 's/ubuntu:22.04/arm64v8\/ubuntu:20.04/g' Dockerfile
cp docker/amd64/Dockerfile.server Dockerfile
sed -i 's/kcllang/kcl-arm64\/kcllang/kcl/g' Dockerfile
echo "ENV KCL_FAST_EVAL=1" >> Dockerfile

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: kcllang/webhookserver-arm64
images: kcllang/webhook-server-arm64
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
Expand Down
32 changes: 17 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
VERSION ?= 0.2.0

# Image URL to use all building/pushing image targets
IMG ?= kcllang/webhookserver
IMG ?= kcllang/webhook-server
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.30.0

Expand Down Expand Up @@ -68,7 +68,7 @@ help: ## Display this help.

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=webhook-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand All @@ -90,44 +90,46 @@ test: manifests generate fmt vet envtest ## Run tests.

.PHONY: build
build: ## Build binaries.
make manager
make webhook

.PHONY: build
build-linux: ## Build binaries.
make manager-linux
make webhook-linux

.PHONY: manager
manager: manifests generate fmt vet ## Build manager binary
go build -o bin/manager main.go
.PHONY: webhook
webhook: manifests generate fmt vet ## Build webhook server and init container binary
go build -o bin/wehbook-server cmd/webhook-server/main.go
go build -o bin/wehbook-init cmd/webhook-init/main.go

.PHONY: manager-linux
manager-linux: generate fmt vet
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o build/bin/manager main.go
.PHONY: webook-linux
webhook-linux: generate fmt vet
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o bin/wehbook-server cmd/webhook-server/main.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o bin/wehbook-init cmd/webhook-init/main.go

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

# If you wish built the manager image targeting other platforms you can use the --platform flag.
# If you wish built the webhook 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.
docker-build: ## Build docker image with the webhook.
docker build -t $(IMG) .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker-push: ## Push docker image with the webhook.
docker push ${IMG}

# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
# PLATFORMS defines the target platforms for the webhook image be build to provide support to multiple
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
# To properly provided solutions that supports more than one platform you should use this option.
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
.PHONY: docker-buildx
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
docker-buildx: test ## Build and push docker image for the webhook for cross-platform support
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
- docker buildx create --name project-v3-builder
Expand Down
32 changes: 0 additions & 32 deletions api/kclrun/v1alpha1/zz_generated.defaults.go

This file was deleted.

Loading
Loading