Skip to content

Commit

Permalink
add api docs and fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
ostempel committed Nov 12, 2024
1 parent b2d051e commit 20dfc5a
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 42 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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
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)
Expand All @@ -12,7 +12,7 @@ LEADER_ELECTION := false
IGNORE_OPERATION_ANNOTATION := false
WEBHOOK_CONFIG_URL := localhost

GOLANGCI_LINT_VERSION := v1.61.0
GOLANGCI_LINT_VERSION := v1.62.0
GO_VERSION := 1.23

ifeq ($(CI),true)
Expand Down
2 changes: 1 addition & 1 deletion charts/gardener-extension-csi-driver-lvm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v1
appVersion: "1.0"
description: A Helm chart for the csi-driver-lvm extension
name: gardener-extension-csi-driver-lvm
version: 0.2.0
version: 0.1.0
2 changes: 0 additions & 2 deletions charts/gardener-extension-csi-driver-lvm/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ rules:
- get
- list
- watch
- delete
- apiGroups:
- "storage.k8s.io"
resources:
Expand All @@ -55,7 +54,6 @@ rules:
- get
- list
- watch
- delete
- apiGroups:
- ""
resources:
Expand Down
2 changes: 1 addition & 1 deletion charts/images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ images:
- name: csi-resizer
sourceRepository: https://github.com/kubernetes-csi/external-resizer
repository: k8s.gcr.io/sig-storage/csi-resizer
tag: "v2.5.1"
tag: "v1.6.0"
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/gardener/gardener v1.97.4
github.com/go-logr/logr v1.4.2
github.com/golang/mock v1.6.0
github.com/metal-stack/metal-lib v0.18.4
github.com/metal-stack/metal-lib v0.19.0
github.com/onsi/ginkgo v1.16.5
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
Expand Down Expand Up @@ -91,15 +91,15 @@ require (
go.uber.org/mock v0.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.24.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
Expand Down
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -950,8 +950,8 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/metal-stack/metal-lib v0.18.4 h1:7HnfSwSbrKNHU+i6i79YFk/eeuhBhwIEHWpGqS7pYCc=
github.com/metal-stack/metal-lib v0.18.4/go.mod h1:Ctyi6zaXFr2NVrQZLFsDLnFCzupKnYErTtgRFKAsnbw=
github.com/metal-stack/metal-lib v0.19.0 h1:4yBnp/jPGgX9KeCje3A4MFL2oDjgjOjgsIK391LltRI=
github.com/metal-stack/metal-lib v0.19.0/go.mod h1:fCMaWwVGA/xAoGvBk72/nfzqBkHly0iOzrWpc55Fau4=
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8/go.mod h1:mC1jAcsrzbxHt8iiaC+zU4b1ylILSosueou12R++wfY=
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3/go.mod h1:RagcQ7I8IeTMnF8JTXieKnO4Z6JCsikNEzj0DwauVzE=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
Expand Down Expand Up @@ -1147,8 +1147,8 @@ golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -1286,8 +1286,8 @@ golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -1436,8 +1436,8 @@ golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand All @@ -1455,8 +1455,8 @@ golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU=
golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk=
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -1477,8 +1477,8 @@ golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import (
type ControllerConfiguration struct {
metav1.TypeMeta

// DefaultDevicePattern can be used to configure the glob pattern for the devices used by the LVM driver
DefaultDevicePattern *string

// DefaultHostWritePath can be used to configure the default path for the host write path - used on read-only filesystems (Talos OS "/var/etc/lvm")
DefaultHostWritePath *string

// HealthCheckConfig is the config for the health check controller
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/config/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import (
type ControllerConfiguration struct {
metav1.TypeMeta `json:",inline"`

// DefaultDevicePattern can be used to configure the glob pattern for the devices used by the LVM driver
// +optional
DefaultDevicePattern *string `json:"defaultDevicePattern,omitempty"`

// DefaultHostWritePath can be used to configure the default path for the host write path - used on read-only filesystems (Talos OS "/var/etc/lvm")
// +optional
DefaultHostWritePath *string `json:"defaultHostWritePath,omitempty"`

// HealthCheckConfig is the config for the health check controller
Expand Down
27 changes: 9 additions & 18 deletions pkg/controller/csi-driver-lvm/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"

Expand Down Expand Up @@ -55,7 +56,7 @@ type actuator struct {

// Reconcile the Extension resource.
func (a *actuator) Reconcile(ctx context.Context, log logr.Logger, ex *extensionsv1alpha1.Extension) error {
err := a.removeOldCsilvm(ctx)
err := a.checkForOldCsiLvm(ctx)

if err != nil {
return fmt.Errorf("unable to remove old csi-lvm driver: %w", err)
Expand Down Expand Up @@ -245,7 +246,6 @@ func (a *actuator) controllerObjects(namespace string) ([]client.Object, error)
}

var hostPathType corev1.HostPathType = corev1.HostPathDirectoryOrCreate
var replicas = int32(1)

csidriverlvmStatefulsetController := &appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -255,7 +255,7 @@ func (a *actuator) controllerObjects(namespace string) ([]client.Object, error)
Labels: map[string]string{},
},
Spec: appsv1.StatefulSetSpec{
Replicas: &replicas,
Replicas: ptr.To(int32(1)),
ServiceName: "csi-driver-lvm-controller",
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
Expand All @@ -265,7 +265,7 @@ func (a *actuator) controllerObjects(namespace string) ([]client.Object, error)
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "csi-driver-lvm",
"app": "csi-driver-lvm-controller",
},
Annotations: map[string]string{},
},
Expand Down Expand Up @@ -504,16 +504,14 @@ func (a *actuator) pluginObjects(namespace string, csidriverlvmConfig *v1alpha1.

var hostPathTypeCreate corev1.HostPathType = corev1.HostPathDirectoryOrCreate
var hostPathTypeDir corev1.HostPathType = corev1.HostPathDirectory
var revisionHistoryLimit = int32(10)
var healthPort = int32(9898)

csidriverlvmDaemonSetPlugin := &appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{
Name: "csi-driver-lvm-plugin",
Namespace: namespace,
},
Spec: appsv1.DaemonSetSpec{
RevisionHistoryLimit: &revisionHistoryLimit,
RevisionHistoryLimit: ptr.To(int32(10)),
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "csi-driver-lvm-plugin",
Expand Down Expand Up @@ -596,7 +594,7 @@ func (a *actuator) pluginObjects(namespace string, csidriverlvmConfig *v1alpha1.
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/healthz",
Port: intstr.FromInt32(healthPort),
Port: intstr.FromInt(9898),
Scheme: corev1.URISchemeHTTP,
},
},
Expand Down Expand Up @@ -749,8 +747,7 @@ func (a *actuator) pluginObjects(namespace string, csidriverlvmConfig *v1alpha1.
return objects, nil
}

func (a *actuator) removeOldCsilvm(ctx context.Context) error {

func (a *actuator) checkForOldCsiLvm(ctx context.Context) error {
namespace := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: oldNamespace,
Expand All @@ -760,10 +757,7 @@ func (a *actuator) removeOldCsilvm(ctx context.Context) error {
err := a.client.Get(ctx, client.ObjectKeyFromObject(namespace), namespace)

if err == nil {
err = a.client.Delete(ctx, namespace)
if err != nil {
return fmt.Errorf("error while deleting old csi-lvm namespace: %w", err)
}
return fmt.Errorf("old csi-lvm namespace still exists - please remove it via gardener-extension-provider-metal")
} else if !apierrors.IsNotFound(err) {
return fmt.Errorf("error while getting old csi-lvm namespace: %w", err)
}
Expand All @@ -777,10 +771,7 @@ func (a *actuator) removeOldCsilvm(ctx context.Context) error {

err = a.client.Get(ctx, client.ObjectKeyFromObject(storageClass), storageClass)
if err == nil {
err := a.client.Delete(ctx, storageClass)
if err != nil {
return fmt.Errorf("error while deleting old csi-lvm storageclass: %w", err)
}
return fmt.Errorf("old csi-lvm storage-class still exists - please remove it via gardener-extension-provider-metal")
} else if !apierrors.IsNotFound(err) {
return fmt.Errorf("error while getting old csi-lvm storageclass: %w", err)
}
Expand Down

0 comments on commit 20dfc5a

Please sign in to comment.