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

draft csi driver lvm extension #1

Merged
merged 35 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
226a276
Initial commit
ostempel Nov 5, 2024
a2dcb93
fix startup
ostempel Nov 8, 2024
8b39be7
remove webhooks
ostempel Nov 8, 2024
dd18f46
fix reconcile of resources
ostempel Nov 8, 2024
e5ce2e2
remove healtcheck and test for old csi-lvm
ostempel Nov 11, 2024
11ae5d2
add readme
ostempel Nov 11, 2024
36fa4df
Initial commit
ostempel Nov 5, 2024
3ef53e9
Merge branch 'main' of github.com:metal-stack/gardener-extenstion-csi…
ostempel Nov 11, 2024
fa24ef0
fix removing of old csi-lvm
ostempel Nov 11, 2024
dccc3b2
added migration docs
ostempel Nov 12, 2024
b2d051e
adjust readme
ostempel Nov 12, 2024
dd51c25
add api docs and fix code style
ostempel Nov 12, 2024
c40d048
validate csidriverlvm-config
ostempel Nov 12, 2024
7cc4401
fix reconciling of shoot
ostempel Nov 15, 2024
534425a
refactor reconcilation
ostempel Nov 15, 2024
751bd21
fix controller images
ostempel Nov 15, 2024
8f8b40d
fix reconciling of shoot
ostempel Nov 18, 2024
28e5348
adjust readme
ostempel Nov 18, 2024
a281ac9
fix testing of old csi-lvm
ostempel Nov 18, 2024
2fceb16
fix deletion of managed resource
ostempel Nov 19, 2024
0b7d824
finish draft
ostempel Nov 19, 2024
5bf755a
adjust makefile
ostempel Nov 19, 2024
4839b65
fix generate-in-docker
ostempel Nov 22, 2024
cbfddd7
adjust to feedback
ostempel Nov 25, 2024
3cb4dcb
added pipeline
ostempel Dec 13, 2024
2a03945
fixed linting
ostempel Dec 13, 2024
1ffd4a8
update alpine version
ostempel Dec 13, 2024
60ff612
Update README.md
ostempel Dec 13, 2024
afe7678
Update README.md
ostempel Dec 13, 2024
929ecdc
update Readme
ostempel Dec 13, 2024
6197406
Merge branch 'draft-csi-driver-lvm-extension' of github.com:metal-sta…
ostempel Dec 13, 2024
9647a5b
fix type
ostempel Dec 13, 2024
fb7f609
fix typo
ostempel Dec 13, 2024
10b3e27
remove own ptr-func from test
ostempel Dec 13, 2024
ee8680f
Merge branch 'draft-csi-driver-lvm-extension' of github.com:metal-sta…
ostempel Dec 13, 2024
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
30 changes: 30 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'

template: |
## General Changes

$CHANGES

categories:
- title: '🚀 Features'
labels:
- 'feature'
- 'enhancement'
- title: '🐛 Bug Fixes'
labels:
- 'fix'
- 'bugfix'
- 'bug'

version-resolver:
major:
labels:
- 'major'
minor:
labels:
- 'minor'
patch:
labels:
- 'patch'
default: patch
45 changes: 45 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: Docker Build Action
on:
pull_request:
branches:
- main
release:
types:
- published
push:
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
name: Docker Build
runs-on: ubuntu-latest

steps:
- name: Log in to the container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout
uses: actions/checkout@v3

- name: Make tag
run: |
[ "${GITHUB_EVENT_NAME}" == 'pull_request' ] && echo "tag=${GITHUB_HEAD_REF##*/}" >> $GITHUB_ENV || true
[ "${GITHUB_EVENT_NAME}" == 'release' ] && echo "tag=${GITHUB_REF##*/}" >> $GITHUB_ENV || true
[ "${GITHUB_EVENT_NAME}" == 'push' ] && echo "tag=latest" >> $GITHUB_ENV || true

- name: Build and push image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.tag }}
15 changes: 15 additions & 0 deletions .github/workflows/release-drafter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: Release Drafter Action

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35 changes: 35 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: Test Action
on:
pull_request:
branches:
- main
release:
types:
- published
push:
branches:
- main

jobs:
build:
name: Test and Lint
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: false

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
args: --build-tags integration -p bugs -p unused --timeout=3m

- name: Test
run: make test
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.idea/
vendor
tools/vendor
VERSION
helm
.vscode
hack/tools/bin/*
bin
.ci/
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:1.23 AS builder

WORKDIR /go/src/github.com/metal-stack/gardener-extension-csi-driver-lvm
COPY . .
RUN make install \
&& strip /go/bin/gardener-extension-csi-driver-lvm

FROM alpine:3.21
WORKDIR /
COPY charts /charts
COPY --from=builder /go/bin/gardener-extension-csi-driver-lvm /gardener-extension-csi-driver-lvm
CMD ["/gardener-extension-csi-driver-lvm"]
3 changes: 3 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine:3.21
COPY bin/gardener-extension-csi-driver-lvm /gardener-extension-csi-driver-lvm
CMD ["/gardener-extension-csi-driver-lvm"]
21 changes: 21 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 by the metal-stack.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
103 changes: 103 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
ENSURE_GARDENER_MOD := $(shell go get github.com/gardener/gardener@$$(go list -m -f "{{.Version}}" github.com/gardener/gardener))
GARDENER_HACK_DIR := $(shell go list -m -f "{{.Dir}}" github.com/gardener/gardener)/hack
IMAGE_TAG := $(or ${GITHUB_TAG_NAME}, latest)
REGISTRY := ghcr.io/metal-stack
IMAGE_PREFIX := $(REGISTRY)
REPO_ROOT := $(shell dirname "$(realpath $(lastword $(MAKEFILE_LIST)))")
HACK_DIR := $(REPO_ROOT)/hack
HOSTNAME := $(shell hostname)
LD_FLAGS := "-w -X github.com/metal-stack/gardener-extension-csi-driver-lvm/pkg/version.Version=$(IMAGE_TAG)"
VERIFY := true
LEADER_ELECTION := false
IGNORE_OPERATION_ANNOTATION := false
WEBHOOK_CONFIG_URL := localhost

GOLANGCI_LINT_VERSION := v1.62.0
GO_VERSION := 1.23

ifeq ($(CI),true)
DOCKER_TTY_ARG=""
else
DOCKER_TTY_ARG=t
endif

export GO111MODULE := on

TOOLS_DIR := $(HACK_DIR)/tools
include $(GARDENER_HACK_DIR)/tools.mk

#################################################################
# Rules related to binary build, Docker image build and release #
#################################################################

.PHONY: tidy
tidy:
@GO111MODULE=on go mod tidy
@mkdir -p $(REPO_ROOT)/.ci/hack && cp $(GARDENER_HACK_DIR)/.ci/* $(REPO_ROOT)/.ci/hack/ && chmod +xw $(REPO_ROOT)/.ci/hack/*

.PHONY: build
build:
go build -ldflags $(LD_FLAGS) -tags netgo -o bin/gardener-extension-csi-driver-lvm ./cmd/gardener-extension-csi-driver-lvm

.PHONY: install
install: tidy $(HELM)
@LD_FLAGS="-w -X github.com/gardener/$(EXTENSION_PREFIX)-$(NAME)/pkg/version.Version=$(VERSION)" \
bash $(GARDENER_HACK_DIR)/install.sh ./...

.PHONY: docker-image
docker-image:
@docker build --no-cache \
--build-arg VERIFY=$(VERIFY) \
--tag $(IMAGE_PREFIX)/gardener-extension-csi-driver-lvm:$(IMAGE_TAG) \
--file Dockerfile --memory 6g .

.PHONY: docker-push
docker-push:
@docker push $(IMAGE_PREFIX)/gardener-extension-csi-driver-lvm:$(IMAGE_TAG)

#####################################################################
# Rules for verification, formatting, linting, testing and cleaning #
#####################################################################

.PHONY: revendor
revendor:
@GO111MODULE=on go mod vendor
@GO111MODULE=on go mod tidy
@chmod +x $(REPO_ROOT)/vendor/github.com/gardener/gardener/hack/*
@chmod +x $(REPO_ROOT)/vendor/github.com/gardener/gardener/hack/.ci/*
@$(REPO_ROOT)/hack/update-github-templates.sh

.PHONY: clean
clean:
@$(shell find ./example -type f -name "controller-registration.yaml" -exec rm '{}' \;)
@bash $(GARDENER_HACK_DIR)/clean.sh ./cmd/... ./pkg/...

.PHONY: check-generate
check-generate:
@$(REPO_ROOT)/vendor/github.com/gardener/gardener/hack/check-generate.sh $(REPO_ROOT)

.PHONY: generate
generate: $(VGOPATH) $(HELM) $(YQ)
# echo $(shell git -c safe.directory=/go/src/github.com/metal-stack/gardener-extension-csi-driver-lvm describe --abbrev=0 --tags) > VERSION
@REPO_ROOT=$(REPO_ROOT) VGOPATH=$(VGOPATH) GARDENER_HACK_DIR=$(GARDENER_HACK_DIR) bash $(GARDENER_HACK_DIR)/generate-sequential.sh ./charts/... ./cmd/... ./pkg/...

.PHONY: generate-in-docker
generate-in-docker: tidy install $(HELM) $(YQ)
docker run --rm -i$(DOCKER_TTY_ARG) -v $(PWD):/go/src/github.com/metal-stack/gardener-extension-csi-driver-lvm golang:$(GO_VERSION) \
sh -c "cd /go/src/github.com/metal-stack/gardener-extension-csi-driver-lvm \
&& make generate \
&& chown -R $(shell id -u):$(shell id -g) ."

.PHONY: test
test:
go test -v ./...

.PHONY: push-to-gardener-local
push-to-gardener-local:
CGO_ENABLED=1 go build \
-ldflags "-extldflags '-static -s -w'" \
-tags 'osusergo netgo static_build' \
-o bin/gardener-extension-csi-driver-lvm \
./cmd/gardener-extension-csi-driver-lvm
docker build -f Dockerfile.dev -t ghcr.io/metal-stack/gardener-extension-csi-driver-lvm:latest .
kind --name gardener-local load docker-image ghcr.io/metal-stack/gardener-extension-csi-driver-lvm:latest
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# gardener-extension-csi-driver-lvm

Provides a Gardener extension for managing [csi-driver-lvm](https://github.com/metal-stack/csi-driver-lvm) for a shoot cluster.

As a safety measurement, the extension checks for the old [csi-lvm](https://github.com/metal-stack/csi-lvm/tree/master) and stops reconciling if the old driver is still available.
If not the extension will reconcile the new `csi-driver-lvm`.

## Development

This extension can be developed in the gardener-local devel environment. Before make sure you have created loop-devices on your machine (identical to how you would develop the csi-driver-lvm locally, refer to the repository [docs](https://github.com/metal-stack/csi-driver-lvm?tab=readme-ov-file#development) for further information).

```sh
for i in 100 101; do fallocate -l 1G loop${i}.img ; sudo losetup /dev/loop${i} loop${i}.img; done
sudo losetup -a
# use this for recreation or cleanup
# for i in 100 101; do sudo losetup -d /dev/loop${i}; rm -f loop${i}.img; done
```

1. Start up the local devel environment
1. The extension's docker image can be pushed into Kind using `make push-to-gardener-local`
1. Install the extension `kubectl apply -k example/`
1. Parametrize the `example/shoot.yaml` and apply with `kubectl -f example/shoot.yaml`

5 changes: 5 additions & 0 deletions charts/gardener-extension-csi-driver-lvm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for the csi-driver-lvm extension
name: gardener-extension-csi-driver-lvm
version: 0.1.0
4 changes: 4 additions & 0 deletions charts/gardener-extension-csi-driver-lvm/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//go:generate sh -c "bash $GARDENER_HACK_DIR/generate-controller-registration.sh csi-driver-lvm . $(cat ../../VERSION) ../../example/controller-registration.yaml Extension:csi-driver-lvm"

// Package chart enables go:generate support for generating the correct controller registration.
package chart
27 changes: 27 additions & 0 deletions charts/gardener-extension-csi-driver-lvm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{{- define "name" -}}
gardener-extension-csi-driver-lvm
{{- end -}}

{{- define "labels.app.key" -}}
app.kubernetes.io/name
{{- end -}}
{{- define "labels.app.value" -}}
{{ include "name" . }}
{{- end -}}

{{- define "labels" -}}
{{ include "labels.app.key" . }}: {{ include "labels.app.value" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{- define "image" -}}
{{- if hasPrefix "sha256:" .Values.image.tag }}
{{- printf "%s@%s" .Values.image.repository .Values.image.tag }}
{{- else }}
{{- printf "%s:%s" .Values.image.repository .Values.image.tag }}
{{- end }}
{{- end }}

{{- define "deploymentversion" -}}
apps/v1
{{- end -}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.imageVectorOverwrite }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "name" . }}-imagevector-overwrite
namespace: {{ .Release.Namespace }}
labels:
{{ include "labels" . | indent 4 }}
data:
images_overwrite.yaml: |
{{ .Values.imageVectorOverwrite | indent 4 }}
{{- end }}
25 changes: 25 additions & 0 deletions charts/gardener-extension-csi-driver-lvm/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "name" . }}-configmap
namespace: {{ .Release.Namespace }}
labels:
{{ include "labels" . | indent 4 }}
data:
config.yaml: |
---
apiVersion: csi-driver-lvm.metal.extensions.config.gardener.cloud/v1alpha1
kind: ControllerConfiguration
{{- if .Values.config.clientConnection }}
clientConnection:
acceptContentTypes: {{ required ".Values.config.clientConnection.acceptContentTypes is required" .Values.config.clientConnection.acceptContentTypes }}
contentType: {{ required ".Values.config.clientConnection.contentType is required" .Values.config.clientConnection.contentType }}
qps: {{ required ".Values.config.clientConnection.qps is required" .Values.config.clientConnection.qps }}
burst: {{ required ".Values.config.clientConnection.burst is required" .Values.config.clientConnection.burst }}
{{- end }}
{{- if .Values.config.hostWritePath }}
defaultHostWritePath: {{ .Values.config.hostWritePath }}
{{- end }}
{{- if .Values.config.devicePattern }}
defaultDevicePattern: {{ .Values.config.devicePattern }}
{{- end }}
Loading
Loading