Skip to content

Commit

Permalink
adjust to feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ostempel committed Nov 25, 2024
1 parent 4839b65 commit 81d92cc
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ spec:
checksum/configmap-{{ include "name" . }}-config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
labels:
networking.gardener.cloud/to-runtime-apiserver: allowed
networking.gardener.cloud/to-dns: allowed
networking.gardener.cloud/to-public-networks: allowed
networking.gardener.cloud/to-private-networks: allowed
networking.resources.gardener.cloud/to-all-shoots-kube-apiserver-tcp-443: allowed
{{ include "labels" . | indent 8 }}
spec:
containers:
Expand All @@ -49,12 +46,6 @@ spec:
- --log-level={{ .Values.logLevel | default "info" }}
- --log-format={{ .Values.logFormat | default "json" }}
env:
- name: BACKEND_SECRET_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: BACKEND_SECRET_PREFIX
value: default-backend-secret-
- name: LEADER_ELECTION_NAMESPACE
valueFrom:
fieldRef:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if gt (int .Values.replicaCount) 1 }}
apiVersion: policy/v1beta1
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ include "name" . }}
Expand Down
2 changes: 1 addition & 1 deletion charts/gardener-extension-csi-driver-lvm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ config:
qps: 100
burst: 130

devicePattern: /dev/loop10[0,1]
devicePattern: /dev/nvme[0-1]n[0-9]
hostWritePath: /etc/lvm

gardener:
Expand Down
10 changes: 2 additions & 8 deletions cmd/gardener-extension-csi-driver-lvm/app/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,19 @@ func (options *Options) run(ctx context.Context) error {
if err != nil {
return fmt.Errorf("could not instantiate controller-manager: %w", err)
}

log.Info("completed rest-options")

err = extensionscontroller.AddToScheme(mgr.GetScheme())
if err != nil {
return fmt.Errorf("could not add mgr-scheme to extension-controller: %w", err)
}

log.Info("added mgr-scheme to extensionscontroller")

err = install.AddToScheme(mgr.GetScheme())
if err != nil {
return fmt.Errorf("could not add mgr-scheme to installation")
}

log.Info("added mgr-schme to installation")
log.Info("added mgr-scheme to installation")

ctrlConfig := options.csidriverlvmOptions.Completed()
ctrlConfig.Apply(&controller.DefaultAddOptions.Config)
Expand All @@ -142,24 +139,21 @@ func (options *Options) run(ctx context.Context) error {
if err := options.controllerSwitches.Completed().AddToManager(ctx, mgr); err != nil {
return fmt.Errorf("could not add controllers to manager: %w", err)
}
log.Info("added controllers to manager")

if err := mgr.AddReadyzCheck("informer-sync", ghealth.NewCacheSyncHealthz(mgr.GetCache())); err != nil {
return fmt.Errorf("could not add ready check for informers: %w", err)
}

log.Info("added readyzcheck")

if err := mgr.AddHealthzCheck("ping", healthz.Ping); err != nil {
return fmt.Errorf("could not add health check to manager: %w", err)
}

log.Info("added healthzcheck")

if err := mgr.Start(ctx); err != nil {
return fmt.Errorf("error running manager: %w", err)
}

log.Info("started successfully")

return nil
}
4 changes: 2 additions & 2 deletions docs/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The migration solution so far has been tested manually:
5. install new controller & provisioner with helm
6. add additional storage class with name `csi-lvm` and type linear
1. mimics old storage class
2. default storage class
2. default storage class (not supported yet -> see default storage class of `gardener-extension-provider-metal`)
7. create new pvcs
8. create new pod with old and new pvcs and test

Expand All @@ -41,4 +41,4 @@ The migration solution so far has been tested manually:
To achieve this behaviour for csi-lvm, provided by [gardener-extension-provider-metal](https://github.com/metal-stack/gardener-extension-provider-metal/tree/master), we need to add the following workflow:

1. Add a feature gate to `gardener-extension-provider-metal` to disable csi-lvm.
2. When deploying `gardener-extension-csi-driver-lvm`, stop reconciliation if old provisioner is still available.
2. When deploying `gardener-extension-csi-driver-lvm`, stop reconciliation if old provisioner is still available.
2 changes: 1 addition & 1 deletion example/controller-registration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: ControllerDeployment
metadata:
name: csi-driver-lvm
helm:
rawChart: H4sIAAAAAAAAA+0ca2/bOLKf9SsItwu0wEqy/EgWAnp3aeK2QdskcHrZOywWAS3RthpZ1JJSmmzb/35DUpIpWY6spE2urYkAlinOg+S8OENnhplPIsJMcpWQiAc0Mj0emD4LLqEzvFzYj+7cutB2h0P5Ca36KZ+d/sDpDXs7O6Lf2ek5w0doeHfSzS3lCWYIPWKUJjeNa3r/nbZZ4/7vzzFLrGu8CG9LQ2zwzmCwdv97vX55/3tdp7/7CHW/5kTXtZ98/3EcnBEm9t1Fl46B47j42nGsbsfwCfdYECeyaw+9JuECeUIk0JQylMwJKssLKgTJiPCCuKhRwozLnGLXApLGQy/JT9Wa9d+nnjWjd6HRpP+D4aBi/3f7zmCr//fRbHtG3ZmQAJwQxOfI9FBnguHhyau98cHoaDQ+f723/+b84HBs5+NMj0YJo2EIIsLILOAJ9ILoWABWsQYWevLUwwmyLBv+zkbj08Pjo2fZV3KFF3FI7HXohNNBo1ww3TLqjmHYNjrB3gWekcwkkQhPQsJRaU5pHNPMXGWdQTRTlosyRrwELemjEn0j1rH/kIapWf8TAnsEC8lvHQm2jv963Z7T38Z/99Ha7P/5nIQx+GoriVvFgg323+n1dir73xv2d7b2/z7ap08m8sk0iAjqiHitg8wvX4zmmE3AkciXow0dSYgnJOQWBJLWBblW6OSXdEJYRECOrIDaglQJxxoUlzhMM54+fUJB5IWpX3BqoQzwBkZWYasMCiwuWjMioy8prc4iiEB4Io9IcGtMQoI5sY6AuVrOCtaCBTgVxRlC4k0wRXPMTxi8v0IdPse94Y4LZM8EeSAlxlsJnqECImZBlExR5xf+r194dSQjMeVBQtn1TShgjqQOoXtrhDBZbd7VDfFJHNLrBYmSLOAvhIPbcPTQl+uhteLnaW3sP4RJ02C2wLEpN/8SQifKTAoDP7IgIWtzBI3x/071/L/b393G//fSMutT0uozubHH+b4q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xwt8dZGByPzt98W8gVEfxnxocy3Gsq+97Vs7KrDr/eC5m1lMvLMuSsijuLBnrbnHX3eHGsRRvMcgW9epcPpf3qWtHyJvOTlcVHbJryA4IpyHqEqWLtzZ8t0NKY6f7R/dX508h6eWbwLLuKJSy+Cmna+gT7Wz96rZt27Zt27Zt28/b/gfPoIAUAFAAAA==
values:
image:
tag: v0.0.1
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/onsi/ginkgo v1.16.5
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
k8s.io/api v0.31.1
k8s.io/apimachinery v0.31.1
k8s.io/code-generator v0.31.1
Expand Down Expand Up @@ -77,12 +78,14 @@ require (
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo/v2 v2.19.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.74.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,8 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w=
github.com/ruudk/golang-pdf417 v0.0.0-20201230142125-a7e3863a1245/go.mod h1:pQAZKsJ8yyVxGRWYNEm9oFB8ieLgKFnamEyDmSA0BRk=
github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk=
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/csidriverlvm/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
type CsiDriverLvmConfig struct {
metav1.TypeMeta

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

// HostWritePath can be used to configure the host write path - used on read-only filesystems (Talos OS "/var/etc/lvm")
HostWritePath *string
}
34 changes: 28 additions & 6 deletions pkg/apis/csidriverlvm/v1alpha1/types.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package v1alpha1

import (
"regexp"
"path/filepath"

"github.com/go-logr/logr"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -16,7 +17,12 @@ const (
type CsiDriverLvmConfig struct {
metav1.TypeMeta `json:",inline"`

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

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

Expand All @@ -29,13 +35,29 @@ func (config *CsiDriverLvmConfig) ConfigureDefaults(hostWritePath *string, devic
}
}

func (config *CsiDriverLvmConfig) IsValid() bool {
re := regexp.MustCompile(`^(/[^/ ]*)+/?$`)

func (config *CsiDriverLvmConfig) IsValid(log logr.Logger) bool {
if (config.HostWritePath == nil) || (config.DevicePattern == nil) {
println("HostWritePath or DevicePattern is nil", config.HostWritePath, config.DevicePattern)
log.Info("hostWritePath or devicePattern is nil", config.HostWritePath, config.DevicePattern)
return false
}

if *config.HostWritePath == "" || *config.DevicePattern == "" {
log.Info("hostWritePath or devicePattern is empty", config.HostWritePath, config.DevicePattern)
return false
}

//glob pattern validation could be problematic -> go glob interpretation can be different from bash
_, err := filepath.Match(*config.DevicePattern, "")
if err != nil {
log.Info("bad device pattern")
return false
}

hasValidHostWritePath := filepath.IsAbs(*config.HostWritePath)
if !hasValidHostWritePath {
log.Info("hostWritePath is not absolute")
return false
}

return re.MatchString(*config.HostWritePath) && re.MatchString(*config.DevicePattern)
return true
}
112 changes: 112 additions & 0 deletions pkg/apis/csidriverlvm/v1alpha1/types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package v1alpha1

import (
"testing"

"github.com/go-logr/logr"
"github.com/stretchr/testify/assert"
)

var log = logr.New(logr.Discard().GetSink())

func stringPtr(s string) *string {
return &s
}

func TestConfig(t *testing.T) {

tt := []struct {
desc string
customData *CsiDriverLvmConfig
valid bool
}{
{
desc: "test nil config",
customData: &CsiDriverLvmConfig{
DevicePattern: nil,
HostWritePath: nil,
},
valid: false,
},
{
desc: "test devicePattern nil config",
customData: &CsiDriverLvmConfig{
DevicePattern: nil,
HostWritePath: stringPtr("/etc/lvm"),
},
valid: false,
},
{
desc: "test hostWritePath nil config",
customData: &CsiDriverLvmConfig{
DevicePattern: stringPtr("/dev/loop100"),
HostWritePath: nil,
},
valid: false,
},
{
desc: "test empty config",
customData: &CsiDriverLvmConfig{
DevicePattern: stringPtr(""),
HostWritePath: stringPtr(""),
},
valid: false,
},
{
desc: "test empty devicePattern config",
customData: &CsiDriverLvmConfig{
DevicePattern: stringPtr(""),
HostWritePath: stringPtr("/etc/lvm"),
},
valid: false,
},
{
desc: "test empty hostWritePath config",
customData: &CsiDriverLvmConfig{
DevicePattern: stringPtr("/dev/loop1"),
HostWritePath: stringPtr(""),
},
valid: false,
},
{
desc: "test invalid devicePattern config",
customData: &CsiDriverLvmConfig{
DevicePattern: stringPtr("[a-"),
HostWritePath: stringPtr("/etc/lvm"),
},
valid: false,
},
{
desc: "test not absolute hostWritePath config",
customData: &CsiDriverLvmConfig{
DevicePattern: stringPtr("[a-z]"),
HostWritePath: stringPtr("./etc/lvm"),
},
valid: false,
},
{
desc: "test not absolute hostWritePath config",
customData: &CsiDriverLvmConfig{
DevicePattern: stringPtr("[a-z]"),
HostWritePath: stringPtr("etc/lvm"),
},
valid: false,
},
{
desc: "test valid config",
customData: &CsiDriverLvmConfig{
DevicePattern: stringPtr("/dev/loop10[0,1]"),
HostWritePath: stringPtr("/etc/lvm"),
},
valid: true,
},
}

for _, tc := range tt {
t.Run(tc.desc, func(t *testing.T) {
println(tc.desc)
isConfigValid := tc.customData.IsValid(log)
assert.Equal(t, tc.valid, isConfigValid)
})
}
}
Loading

0 comments on commit 81d92cc

Please sign in to comment.