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

[controller] Remove isDefault field and refactor some logic in lsc controller #39

Merged
merged 10 commits into from
May 31, 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
7 changes: 1 addition & 6 deletions crds/doc-ru-localstorageclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ spec:
description: |
Описывает конфигурацию Kubernetes Storage Class.
properties:
isDefault:
description: |
Следует ли использовать данный Storage class по умолчанию.

> Обратите внимание, что false является значением по умолчанию.
reclaimPolicy:
description: |
Reclaim policy данного storage class'а. Может быть:
Expand Down Expand Up @@ -58,4 +53,4 @@ spec:
- Create (если все операции завершились успешно)
reason:
description: |
Дополнительная информация о состоянии Storage Class.
Дополнительная информация о состоянии Storage Class.
35 changes: 5 additions & 30 deletions crds/localstorageclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,13 @@ spec:
properties:
spec:
type: object
x-kubernetes-validations:
- rule: "!has(self.fileSystem)"
message: "The 'fileSystem' field is not supported yet and cannot be used."
- rule: has(self.lvm) == has(oldSelf.lvm) && has(self.fileSystem) == has(oldSelf.fileSystem)
message: "Modification error: Once defined, 'lvm' or 'fileSystem' configuration cannot be replaced or removed. Ensure the existing storage configuration type is maintained."
description: |
Defines a Kubernetes Storage class configuration.
required:
- reclaimPolicy
- volumeBindingMode
oneOf:
- required:
- lvm
- required:
- fileSystem
- lvm
properties:
isDefault:
type: boolean
default: false
description: |
Should this Storage class be used as default.

> Note that the default value is false.
reclaimPolicy:
type: string
x-kubernetes-validations:
Expand Down Expand Up @@ -120,16 +104,6 @@ spec:
The name of the thin pool.
minLength: 1
pattern: ^.*$
fileSystem:
type: object
x-kubernetes-validations:
- rule: self == oldSelf
message: Value is immutable.
required:
- localPath
properties:
localPath:
type: string
status:
type: object
description: |
Expand All @@ -152,10 +126,11 @@ spec:
- jsonPath: .status.phase
name: Phase
type: string
- jsonPath: .spec.isDefault
name: isDefault
type: boolean
- jsonPath: .status.reason
name: Reason
type: string
priority: 1
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
description: The age of this resource
9 changes: 7 additions & 2 deletions docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ In case of no free space in the pool, degradation in the module's operation as a

## How do I set the default StorageClass?

Set the `spec.IsDefault` field to `true` in the corresponding [LocalStorageClass](./cr.html#localstorageclass) custom resource.
Add the annotation `storageclass.kubernetes.io/is-default-class: "true"` to the corresponding StorageClass resource:

```shell
kubectl annotate storageclasses.storage.k8s.io <storageClassName> storageclass.kubernetes.io/is-default-class=true
```

## I don't want the module to be used on all nodes of the cluster. How can I select the desired nodes?

The nodes that will be involved with the module are determined by special labels specified in the `nodeSelector` field in the module settings.

To display and edit the module settings, you can execute the command:
Expand Down Expand Up @@ -251,4 +256,4 @@ If the labels are present, it's necessary to check for the existence of the labe
```shell
kubectl -n d8-sds-local-volume get po -l app=sds-local-volume-controller
kubectl -n d8-sds-local-volume logs -l app=sds-local-volume-controller
```
```
8 changes: 6 additions & 2 deletions docs/FAQ.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ Overprovisioning в LVMThin нужно использовать с осторо

## Как назначить StorageClass по умолчанию?

В соответствующем пользовательском ресурсе [LocalStorageClass](./cr.html#localstorageclass) в поле `spec.isDefault` указать `true`.
Добавьте аннотацию `storageclass.kubernetes.io/is-default-class: "true"` в соответствующий ресурс StorageClass:

```shell
kubectl annotate storageclasses.storage.k8s.io <storageClassName> storageclass.kubernetes.io/is-default-class=true
```

## Я не хочу, чтобы модуль использовался на всех узлах кластера. Как мне выбрать желаемые узлы?
Узлы, которые будут задействованы модулем, определяются специальными метками, указанными в поле `nodeSelector` в настройках модуля.
Expand Down Expand Up @@ -247,4 +251,4 @@ kubectl label node %node-name% my-custom-label-key=my-custom-label-value
```shell
kubectl -n d8-sds-local-volume get po -l app=sds-local-volume-controller
kubectl -n d8-sds-local-volume logs -l app=sds-local-volume-controller
```
```
1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ kind: LocalStorageClass
metadata:
name: local-storage-class
spec:
isDefault: false
lvm:
lvmVolumeGroups:
- name: vg-1-on-worker-0
Expand Down
4 changes: 2 additions & 2 deletions images/sds-local-volume-controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG BASE_ALPINE=registry.deckhouse.io/base_images/alpine:3.16.3@sha256:5548e9172c24a1b0ca9afdd2bf534e265c94b12b36b3e0c0302f5853eaf00abb
ARG BASE_GOLANG_20_ALPINE_BUILDER=registry.deckhouse.io/base_images/golang:1.20.5-alpine3.18@sha256:51a47fb0851397db2f506c15c426735bc23de31177cbdd962880c0879d1906a4
ARG BASE_GOLANG_22_ALPINE_BUILDER=registry.deckhouse.io/base_images/golang:1.22.1-alpine@sha256:0de6cf7cceab6ecbf0718bdfb675b08b78113c3709c5e4b99456cdb2ae8c2495

FROM $BASE_GOLANG_20_ALPINE_BUILDER as builder
FROM $BASE_GOLANG_22_ALPINE_BUILDER as builder

WORKDIR /go/src
ADD go.mod .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type LocalStorageClassList struct {
}

type LocalStorageClassSpec struct {
IsDefault bool `json:"isDefault"`
ReclaimPolicy string `json:"reclaimPolicy"`
VolumeBindingMode string `json:"volumeBindingMode"`
LVM *LocalStorageClassLVM `json:"lvm,omitempty"`
Expand Down
13 changes: 5 additions & 8 deletions images/sds-local-volume-controller/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"sds-local-volume-controller/pkg/controller"
"sds-local-volume-controller/pkg/kubutils"
"sds-local-volume-controller/pkg/logger"
"sds-local-volume-controller/pkg/monitoring"

"sigs.k8s.io/controller-runtime/pkg/cache"

v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -89,9 +89,8 @@ func main() {
}

managerOpts := manager.Options{
Scheme: scheme,
Cache: cacheOpt,
//MetricsBindAddress: cfgParams.MetricsPort,
Scheme: scheme,
Cache: cacheOpt,
LeaderElection: true,
LeaderElectionNamespace: cfgParams.ControllerNamespace,
LeaderElectionID: config.ControllerName,
Expand All @@ -105,14 +104,12 @@ func main() {
}
log.Info("[main] successfully created kubernetes manager")

metrics := monitoring.GetMetrics("")

if _, err = controller.RunLocalStorageClassWatcherController(mgr, *cfgParams, *log, metrics); err != nil {
if _, err = controller.RunLocalStorageClassWatcherController(mgr, *cfgParams, *log); err != nil {
log.Error(err, fmt.Sprintf("[main] unable to run %s", controller.LocalStorageClassCtrlName))
os.Exit(1)
}

if _, err = controller.RunLocalCSINodeWatcherController(mgr, *cfgParams, *log, metrics); err != nil {
if _, err = controller.RunLocalCSINodeWatcherController(mgr, *cfgParams, *log); err != nil {
log.Error(err, fmt.Sprintf("[main] unable to run %s", controller.LocalCSINodeWatcherCtrl))
os.Exit(1)
}
Expand Down
43 changes: 24 additions & 19 deletions images/sds-local-volume-controller/go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
module sds-local-volume-controller

go 1.21
go 1.22

require (
github.com/go-logr/logr v1.4.1
github.com/prometheus/client_golang v1.18.0
github.com/stretchr/testify v1.8.4
k8s.io/api v0.29.1
k8s.io/apiextensions-apiserver v0.29.1
k8s.io/apimachinery v0.29.1
k8s.io/client-go v0.29.1
github.com/go-logr/logr v1.4.2
github.com/onsi/ginkgo/v2 v2.19.0
github.com/onsi/gomega v1.33.1
github.com/stretchr/testify v1.9.0
k8s.io/api v0.29.5
k8s.io/apiextensions-apiserver v0.29.5
k8s.io/apimachinery v0.29.5
k8s.io/client-go v0.29.5
k8s.io/klog/v2 v2.120.1
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
sigs.k8s.io/controller-runtime v0.17.1
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0
sigs.k8s.io/controller-runtime v0.17.5
sigs.k8s.io/yaml v1.4.0
)

Expand All @@ -22,17 +23,19 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand All @@ -44,25 +47,27 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.21.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/component-base v0.29.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/component-base v0.29.5 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)
Loading