diff --git a/.github/workflows/go_modules_check.yaml b/.github/workflows/go_modules_check.yaml index 8365dd5..83853b2 100644 --- a/.github/workflows/go_modules_check.yaml +++ b/.github/workflows/go_modules_check.yaml @@ -37,7 +37,7 @@ jobs: echo "Processing $go_mod_file" while IFS= read -r line; do - if [[ "$line" == *github.com/deckhouse/sds-* || "$line" == *github.com/deckhouse/csi-* || "$line" == *github.com/deckhouse/virtualization ]]; then + if [[ ("$line" == *github.com/deckhouse/sds-* || "$line" == *github.com/deckhouse/csi-* || "$line" == *github.com/deckhouse/virtualization) && "$line" =~ *replace* ]]; then repository=$(echo "$line" | awk '{print $1}' | awk -F'/' '{ print "https://"$1"/"$2"/"$3".git" }') pseudo_tag=$(echo "$line" | awk '{print $2}') echo "Cloning repo $repository into $temp_dir" diff --git a/.github/workflows/trivy_check.yaml b/.github/workflows/trivy_check.yaml new file mode 100644 index 0000000..e1bed5b --- /dev/null +++ b/.github/workflows/trivy_check.yaml @@ -0,0 +1,32 @@ +name: Trivy check for sub repos + +on: + pull_request: + push: + branches: + - main + +jobs: + test: + name: Trivy check for sub repos + runs-on: [self-hosted, regular] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Prepare sub repo + run: | + version=v`grep "version :=" images/csi-ceph/werf.inc.yaml | awk -F'"' '{ print $2}'` + git clone --depth 1 --branch $version ${{ secrets.SOURCE_REPO }}/ceph/ceph-csi.git ./ceph-csi + cp -R ./images/csi-ceph/patches ./ceph-csi + cd ./ceph-csi + for patchfile in ./patches/*.patch ; do echo -n "Apply ${patchfile} ... "; git apply ${patchfile}; done + cd .. + + - name: Run Trivy vulnerability scanner in fs mode + uses: aquasecurity/trivy-action@master + with: + scan-type: 'fs' + scan-ref: '.' + trivy-config: trivy.yaml diff --git a/.golangci.yaml b/.golangci.yaml index 4655fb0..06979da 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -13,6 +13,10 @@ linters-settings: sections: - standard - default + - prefix(d8-controller) + - prefix(webhooks) + + errcheck: ignore: fmt:.*,[rR]ead|[wW]rite|[cC]lose,io:Copy @@ -24,7 +28,7 @@ linters: - gci - gocritic - gofmt - - goimports +# - goimports - gosimple - govet - ineffassign diff --git a/api/v1alpha1/ceph_storage_class.go b/api/v1alpha1/ceph_storage_class.go index f87cca3..b9094c7 100644 --- a/api/v1alpha1/ceph_storage_class.go +++ b/api/v1alpha1/ceph_storage_class.go @@ -24,7 +24,7 @@ const ( ) var ( - DefaultMountOptions = []string{"discard"} + DefaultMountOptionsRBD = []string{"discard"} ) type CephStorageClass struct { diff --git a/hooks/lib/module/module.py b/hooks/lib/module/module.py index 25e034d..6dd746c 100644 --- a/hooks/lib/module/module.py +++ b/hooks/lib/module/module.py @@ -35,25 +35,4 @@ def get_https_mode(module_name: str, values: dict) -> str: raise Exception("https mode is not defined") def get_module_name() -> str: - module = "" - file_path = os.path.abspath(__file__) - external_modules_dir = os.getenv("EXTERNAL_MODULES_DIR") - for dir in os.getenv("MODULES_DIR").split(":"): - if dir.startswith(external_modules_dir): - dir = external_modules_dir - if file_path.startswith(dir): - module = re.sub(f"{dir}/?\d?\d?\d?-?", "", file_path, 1).split("/")[0] - # /deckhouse/external-modules/virtualization/mr/hooks/hook_name.py - # {-------------------------- file_path --------------------------} - # {------ MODULES_DIR ------}{---------- regexp result ----------}} - # virtualization/mr/hooks/hook_name.py - # {-module-name-}{---------------------} - # or - # /deckhouse/modules/900-virtualization/hooks/hook_name.py - # {---------------------- file_path ----------------------} - # {-- MODULES_DIR --}{---{-------- regexp result --------}} - # virtualization/hooks/hook_name.py - # {-module-name-}{-----------------} - - break - return module \ No newline at end of file + return "csi-ceph" \ No newline at end of file diff --git a/images/controller/src/cmd/main.go b/images/controller/src/cmd/main.go index df80f00..57fd5ea 100644 --- a/images/controller/src/cmd/main.go +++ b/images/controller/src/cmd/main.go @@ -18,25 +18,25 @@ package main import ( "context" - "d8-controller/pkg/config" - "d8-controller/pkg/controller" - "d8-controller/pkg/kubutils" - "d8-controller/pkg/logger" "fmt" - "github.com/deckhouse/csi-ceph/api/v1alpha1" "os" goruntime "runtime" - "sigs.k8s.io/controller-runtime/pkg/cache" - + "github.com/deckhouse/csi-ceph/api/v1alpha1" v1 "k8s.io/api/core/v1" sv1 "k8s.io/api/storage/v1" extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/runtime" apiruntime "k8s.io/apimachinery/pkg/runtime" clientgoscheme "k8s.io/client-go/kubernetes/scheme" + "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/healthz" "sigs.k8s.io/controller-runtime/pkg/manager" + + "d8-controller/pkg/config" + "d8-controller/pkg/controller" + "d8-controller/pkg/kubutils" + "d8-controller/pkg/logger" ) var ( @@ -55,7 +55,7 @@ func main() { log, err := logger.NewLogger(cfgParams.Loglevel) if err != nil { - fmt.Println(fmt.Sprintf("unable to create NewLogger, err: %v", err)) + fmt.Printf("unable to create NewLogger, err: %v\n", err) os.Exit(1) } diff --git a/images/controller/src/go.mod b/images/controller/src/go.mod index 5028fca..0d0b5f2 100644 --- a/images/controller/src/go.mod +++ b/images/controller/src/go.mod @@ -3,26 +3,29 @@ module d8-controller go 1.22.2 require ( - github.com/deckhouse/csi-ceph/api v0.0.0-20240803013526-e9ed86f2f125 + github.com/deckhouse/csi-ceph/api v0.0.0-20240820170126-01a5c651eb9d github.com/go-logr/logr v1.4.2 - github.com/onsi/ginkgo/v2 v2.17.2 - github.com/onsi/gomega v1.33.1 - k8s.io/api v0.30.2 - k8s.io/apiextensions-apiserver v0.30.2 - k8s.io/apimachinery v0.30.2 - k8s.io/client-go v0.30.2 + github.com/onsi/ginkgo/v2 v2.20.0 + github.com/onsi/gomega v1.34.1 + k8s.io/api v0.31.0 + k8s.io/apiextensions-apiserver v0.31.0 + k8s.io/apimachinery v0.31.0 + k8s.io/client-go v0.31.0 k8s.io/klog/v2 v2.130.1 - sigs.k8s.io/controller-runtime v0.18.4 + sigs.k8s.io/controller-runtime v0.19.0 ) +replace github.com/deckhouse/csi-ceph/api => ../../../api + require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/emicklei/go-restful/v3 v3.12.1 // indirect github.com/evanphx/json-patch v4.12.0+incompatible // indirect github.com/evanphx/json-patch/v5 v5.9.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/fxamacker/cbor/v2 v2.7.0 // indirect github.com/go-openapi/jsonpointer v0.21.0 // indirect github.com/go-openapi/jsonreference v0.21.0 // indirect github.com/go-openapi/swag v0.23.0 // indirect @@ -33,36 +36,39 @@ require ( 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/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect github.com/google/uuid v1.6.0 // indirect github.com/imdario/mergo v0.3.16 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/compress v1.17.9 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/prometheus/client_golang v1.19.1 // indirect + github.com/prometheus/client_golang v1.20.2 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.54.0 // indirect + github.com/prometheus/common v0.55.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect - golang.org/x/net v0.26.0 // indirect - golang.org/x/oauth2 v0.21.0 // indirect - golang.org/x/sys v0.21.0 // indirect - golang.org/x/term v0.21.0 // indirect - golang.org/x/text v0.16.0 // indirect - golang.org/x/time v0.5.0 // indirect - golang.org/x/tools v0.22.0 // indirect + github.com/x448/float16 v0.8.4 // indirect + golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 // indirect + golang.org/x/net v0.28.0 // indirect + golang.org/x/oauth2 v0.22.0 // indirect + golang.org/x/sys v0.24.0 // indirect + golang.org/x/term v0.23.0 // indirect + golang.org/x/text v0.17.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 google.golang.org/protobuf v1.34.2 // indirect + gopkg.in/evanphx/json-patch.v4 v4.12.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/kube-openapi v0.0.0-20240620174524-b456828f718b // indirect - k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 // indirect + k8s.io/kube-openapi v0.0.0-20240826222958-65a50c78dec5 // indirect + k8s.io/utils v0.0.0-20240821151609-f90d01438635 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect diff --git a/images/controller/src/go.sum b/images/controller/src/go.sum index 5d39bc4..6d8f6ce 100644 --- a/images/controller/src/go.sum +++ b/images/controller/src/go.sum @@ -3,11 +3,9 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deckhouse/csi-ceph/api v0.0.0-20240704080803-ac76d22bedfc h1:v8SKPdpWrP6Q6Krd0z2vEDB28LG5GJINOVyUsg9iubU= -github.com/deckhouse/csi-ceph/api v0.0.0-20240704080803-ac76d22bedfc/go.mod h1:RVauoJf/CAJDIdJGLXBL8QHBxj/g68Wu5PqScJ3sChw= -github.com/deckhouse/csi-ceph/api v0.0.0-20240803013526-e9ed86f2f125/go.mod h1:RVauoJf/CAJDIdJGLXBL8QHBxj/g68Wu5PqScJ3sChw= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/emicklei/go-restful/v3 v3.12.1 h1:PJMDIM/ak7btuL8Ex0iYET9hxM3CI2sjZtzpL63nKAU= github.com/emicklei/go-restful/v3 v3.12.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= @@ -16,6 +14,8 @@ github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0 github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E= +github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ= @@ -42,8 +42,8 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6 h1:k7nVchz72niMH6YLQNvHSdIE7iqsQxK1P41mySCvssg= -github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw= +github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 h1:FKHo8hFI3A+7w0aUQuYXQ+6EN5stWmeY/AZqtM8xk9k= +github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= @@ -54,10 +54,14 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -67,30 +71,33 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/onsi/ginkgo/v2 v2.17.2 h1:7eMhcy3GimbsA3hEnVKdw/PQM9XN9krpKVXsZdph0/g= -github.com/onsi/ginkgo/v2 v2.17.2/go.mod h1:nP2DPOQoNsQmsVyv5rDA8JkXQoCs6goXIvr/PRJ1eCc= -github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk= -github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0= +github.com/onsi/ginkgo/v2 v2.20.0 h1:PE84V2mHqoT1sglvHc8ZdQtPcwmvvt29WLEEO3xmdZw= +github.com/onsi/ginkgo/v2 v2.20.0/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI= +github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k= +github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE= -github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v1.20.2 h1:5ctymQzZlyOON1666svgwn3s6IKWgfbjsejTMiXIyjg= +github.com/prometheus/client_golang v1.20.2/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= -github.com/prometheus/common v0.54.0 h1:ZlZy0BgJhTwVZUn7dLOkwCZHUkrAqd3WYtcFCWnM1D8= -github.com/prometheus/common v0.54.0/go.mod h1:/TQgMJP5CuVYveyT7n/0Ix8yLNNXy9yRSkhnLTHPDIQ= +github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc= +github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= -github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= +github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= @@ -102,40 +109,40 @@ go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY= -golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI= +golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 h1:kx6Ds3MlpiUHKj7syVnbp57++8WpuKPcR5yjLBjvLEA= +golang.org/x/exp v0.0.0-20240823005443-9b4947da3948/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= -golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= -golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +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/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= +golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= -golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +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/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= -golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +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/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U= +golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA= -golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c= +golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= +golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -147,6 +154,8 @@ google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWn gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSPG+6V4= +gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= @@ -154,22 +163,22 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/api v0.30.2 h1:+ZhRj+28QT4UOH+BKznu4CBgPWgkXO7XAvMcMl0qKvI= -k8s.io/api v0.30.2/go.mod h1:ULg5g9JvOev2dG0u2hig4Z7tQ2hHIuS+m8MNZ+X6EmI= -k8s.io/apiextensions-apiserver v0.30.2 h1:l7Eue2t6QiLHErfn2vwK4KgF4NeDgjQkCXtEbOocKIE= -k8s.io/apiextensions-apiserver v0.30.2/go.mod h1:lsJFLYyK40iguuinsb3nt+Sj6CmodSI4ACDLep1rgjw= -k8s.io/apimachinery v0.30.2 h1:fEMcnBj6qkzzPGSVsAZtQThU62SmQ4ZymlXRC5yFSCg= -k8s.io/apimachinery v0.30.2/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= -k8s.io/client-go v0.30.2 h1:sBIVJdojUNPDU/jObC+18tXWcTJVcwyqS9diGdWHk50= -k8s.io/client-go v0.30.2/go.mod h1:JglKSWULm9xlJLx4KCkfLLQ7XwtlbflV6uFFSHTMgVs= +k8s.io/api v0.31.0 h1:b9LiSjR2ym/SzTOlfMHm1tr7/21aD7fSkqgD/CVJBCo= +k8s.io/api v0.31.0/go.mod h1:0YiFF+JfFxMM6+1hQei8FY8M7s1Mth+z/q7eF1aJkTE= +k8s.io/apiextensions-apiserver v0.31.0 h1:fZgCVhGwsclj3qCw1buVXCV6khjRzKC5eCFt24kyLSk= +k8s.io/apiextensions-apiserver v0.31.0/go.mod h1:b9aMDEYaEe5sdK+1T0KU78ApR/5ZVp4i56VacZYEHxk= +k8s.io/apimachinery v0.31.0 h1:m9jOiSr3FoSSL5WO9bjm1n6B9KROYYgNZOb4tyZ1lBc= +k8s.io/apimachinery v0.31.0/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo= +k8s.io/client-go v0.31.0 h1:QqEJzNjbN2Yv1H79SsS+SWnXkBgVu4Pj3CJQgbx0gI8= +k8s.io/client-go v0.31.0/go.mod h1:Y9wvC76g4fLjmU0BA+rV+h2cncoadjvjjkkIGoTLcGU= k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= -k8s.io/kube-openapi v0.0.0-20240620174524-b456828f718b h1:Q9xmGWBvOGd8UJyccgpYlLosk/JlfP3xQLNkQlHJeXw= -k8s.io/kube-openapi v0.0.0-20240620174524-b456828f718b/go.mod h1:UxDHUPsUwTOOxSU+oXURfFBcAS6JwiRXTYqYwfuGowc= -k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 h1:jgGTlFYnhF1PM1Ax/lAlxUPE+KfCIXHaathvJg1C3ak= -k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -sigs.k8s.io/controller-runtime v0.18.4 h1:87+guW1zhvuPLh1PHybKdYFLU0YJp4FhJRmiHvm5BZw= -sigs.k8s.io/controller-runtime v0.18.4/go.mod h1:TVoGrfdpbA9VRFaRnKgk9P5/atA0pMwq+f+msb9M8Sg= +k8s.io/kube-openapi v0.0.0-20240826222958-65a50c78dec5 h1:6OWzFh8WiQWeeE7apc3kRV3z0CzprqBxVjntsPA0ed4= +k8s.io/kube-openapi v0.0.0-20240826222958-65a50c78dec5/go.mod h1:i67DWA0Mm5+JPl+R2ku1eehbRGBDthd8+S2jS9nKLQk= +k8s.io/utils v0.0.0-20240821151609-f90d01438635 h1:2wThSvJoW/Ncn9TmQEYXRnevZXi2duqHWf5OX9S3zjI= +k8s.io/utils v0.0.0-20240821151609-f90d01438635/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +sigs.k8s.io/controller-runtime v0.19.0 h1:nWVM7aq+Il2ABxwiCizrVDSlmDcshi9llbaFbC0ji/Q= +sigs.k8s.io/controller-runtime v0.19.0/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4= diff --git a/images/controller/src/pkg/config/config.go b/images/controller/src/pkg/config/config.go index d72572c..e8bbb27 100644 --- a/images/controller/src/pkg/config/config.go +++ b/images/controller/src/pkg/config/config.go @@ -14,10 +14,11 @@ limitations under the License. package config import ( - "d8-controller/pkg/logger" "log" "os" "time" + + "d8-controller/pkg/logger" ) const ( @@ -54,7 +55,6 @@ func NewConfig() *Options { opts.ControllerNamespace = os.Getenv(ControllerNamespaceEnv) if opts.ControllerNamespace == "" { - namespace, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace") if err != nil { log.Printf("Failed to get namespace from filesystem: %v", err) diff --git a/images/controller/src/pkg/controller/ceph_cluster_authentication_watcher.go b/images/controller/src/pkg/controller/ceph_cluster_authentication_watcher.go index 21aaecd..309b19e 100644 --- a/images/controller/src/pkg/controller/ceph_cluster_authentication_watcher.go +++ b/images/controller/src/pkg/controller/ceph_cluster_authentication_watcher.go @@ -18,14 +18,11 @@ package controller import ( "context" - "d8-controller/pkg/config" - "d8-controller/pkg/internal" - "d8-controller/pkg/logger" "fmt" - v1alpha1 "github.com/deckhouse/csi-ceph/api/v1alpha1" "reflect" "time" + v1alpha1 "github.com/deckhouse/csi-ceph/api/v1alpha1" corev1 "k8s.io/api/core/v1" k8serr "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" @@ -34,10 +31,13 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" - "sigs.k8s.io/controller-runtime/pkg/manager" + "d8-controller/pkg/config" + "d8-controller/pkg/internal" + "d8-controller/pkg/logger" ) const ( @@ -79,7 +79,7 @@ func RunCephClusterAuthenticationWatcherController( log.Info(fmt.Sprintf("[CephClusterAuthenticationReconciler] CephClusterAuthentication %s has been reconciled with message: %s", cephClusterAuthentication.Name, msg)) phase := internal.PhaseCreated if err != nil { - log.Error(err, fmt.Sprintf("[CephClusterAuthenticationReconciler] an error occured while reconciles the CephClusterAuthentication, name: %s", cephClusterAuthentication.Name)) + log.Error(err, fmt.Sprintf("[CephClusterAuthenticationReconciler] an error occurred while reconciles the CephClusterAuthentication, name: %s", cephClusterAuthentication.Name)) phase = internal.PhaseFailed } @@ -108,31 +108,29 @@ func RunCephClusterAuthenticationWatcherController( return nil, err } - err = c.Watch( - source.Kind(mgr.GetCache(), &v1alpha1.CephClusterAuthentication{}, - handler.TypedFuncs[*v1alpha1.CephClusterAuthentication]{ - CreateFunc: func(ctx context.Context, e event.TypedCreateEvent[*v1alpha1.CephClusterAuthentication], q workqueue.RateLimitingInterface) { - log.Info(fmt.Sprintf("[CreateFunc] get event for CephClusterAuthentication %q. Add to the queue", e.Object.GetName())) - request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: e.Object.GetNamespace(), Name: e.Object.GetName()}} - q.Add(request) - }, - UpdateFunc: func(ctx context.Context, e event.TypedUpdateEvent[*v1alpha1.CephClusterAuthentication], q workqueue.RateLimitingInterface) { - log.Info(fmt.Sprintf("[UpdateFunc] get event for CephClusterAuthentication %q. Check if it should be reconciled", e.ObjectNew.GetName())) - - oldCephClusterAuthentication := e.ObjectOld - newCephClusterAuthentication := e.ObjectNew - - if reflect.DeepEqual(oldCephClusterAuthentication.Spec, newCephClusterAuthentication.Spec) && newCephClusterAuthentication.DeletionTimestamp == nil { - log.Info(fmt.Sprintf("[UpdateFunc] an update event for the CephClusterAuthentication %s has no Spec field updates. It will not be reconciled", newCephClusterAuthentication.Name)) - return - } - - log.Info(fmt.Sprintf("[UpdateFunc] the CephClusterAuthentication %q will be reconciled. Add to the queue", newCephClusterAuthentication.Name)) - request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: newCephClusterAuthentication.Namespace, Name: newCephClusterAuthentication.Name}} - q.Add(request) - }, - }, - ), + err = c.Watch(source.Kind(mgr.GetCache(), &v1alpha1.CephClusterAuthentication{}, handler.TypedFuncs[*v1alpha1.CephClusterAuthentication, reconcile.Request]{ + CreateFunc: func(_ context.Context, e event.TypedCreateEvent[*v1alpha1.CephClusterAuthentication], q workqueue.TypedRateLimitingInterface[reconcile.Request]) { + log.Info(fmt.Sprintf("[CreateFunc] get event for CephClusterAuthentication %q. Add to the queue", e.Object.GetName())) + request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: e.Object.GetNamespace(), Name: e.Object.GetName()}} + q.Add(request) + }, + UpdateFunc: func(_ context.Context, e event.TypedUpdateEvent[*v1alpha1.CephClusterAuthentication], q workqueue.TypedRateLimitingInterface[reconcile.Request]) { + log.Info(fmt.Sprintf("[UpdateFunc] get event for CephClusterAuthentication %q. Check if it should be reconciled", e.ObjectNew.GetName())) + + oldCephClusterAuthentication := e.ObjectOld + newCephClusterAuthentication := e.ObjectNew + + if reflect.DeepEqual(oldCephClusterAuthentication.Spec, newCephClusterAuthentication.Spec) && newCephClusterAuthentication.DeletionTimestamp == nil { + log.Info(fmt.Sprintf("[UpdateFunc] an update event for the CephClusterAuthentication %s has no Spec field updates. It will not be reconciled", newCephClusterAuthentication.Name)) + return + } + + log.Info(fmt.Sprintf("[UpdateFunc] the CephClusterAuthentication %q will be reconciled. Add to the queue", newCephClusterAuthentication.Name)) + request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: newCephClusterAuthentication.Namespace, Name: newCephClusterAuthentication.Name}} + q.Add(request) + }, + }, + ), ) if err != nil { diff --git a/images/controller/src/pkg/controller/ceph_cluster_authentication_watcher_func.go b/images/controller/src/pkg/controller/ceph_cluster_authentication_watcher_func.go index 9298ce8..b2e5752 100644 --- a/images/controller/src/pkg/controller/ceph_cluster_authentication_watcher_func.go +++ b/images/controller/src/pkg/controller/ceph_cluster_authentication_watcher_func.go @@ -18,16 +18,17 @@ package controller import ( "context" - "d8-controller/pkg/internal" - "d8-controller/pkg/logger" "fmt" - v1alpha1 "github.com/deckhouse/csi-ceph/api/v1alpha1" "reflect" "strings" + v1alpha1 "github.com/deckhouse/csi-ceph/api/v1alpha1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + + "d8-controller/pkg/internal" + "d8-controller/pkg/logger" ) func validateCephClusterAuthenticationSpec(cephClusterAuthentication *v1alpha1.CephClusterAuthentication) (bool, string) { @@ -224,7 +225,7 @@ func reconcileSecretDeleteFunc(ctx context.Context, cl client.Client, log logger } } - _, err = removeFinalizerIfExists(ctx, cl, cephClusterAuthentication, CephClusterAuthenticationControllerFinalizerName) + err = removeFinalizerIfExists(ctx, cl, cephClusterAuthentication, CephClusterAuthenticationControllerFinalizerName) if err != nil { err = fmt.Errorf("[reconcileSecretDeleteFunc] unable to remove a finalizer %s from the CephClusterAuthentication %s: %w", CephClusterAuthenticationControllerFinalizerName, cephClusterAuthentication.Name, err) return true, err.Error(), err @@ -236,7 +237,7 @@ func reconcileSecretDeleteFunc(ctx context.Context, cl client.Client, log logger } func deleteSecret(ctx context.Context, cl client.Client, secret *corev1.Secret) error { - _, err := removeFinalizerIfExists(ctx, cl, secret, CephClusterAuthenticationControllerFinalizerName) + err := removeFinalizerIfExists(ctx, cl, secret, CephClusterAuthenticationControllerFinalizerName) if err != nil { return err } diff --git a/images/controller/src/pkg/controller/ceph_cluster_authentication_watcher_test.go b/images/controller/src/pkg/controller/ceph_cluster_authentication_watcher_test.go index c2844a8..42f51ab 100644 --- a/images/controller/src/pkg/controller/ceph_cluster_authentication_watcher_test.go +++ b/images/controller/src/pkg/controller/ceph_cluster_authentication_watcher_test.go @@ -19,17 +19,17 @@ package controller_test import ( "context" - "d8-controller/pkg/controller" - "d8-controller/pkg/internal" - "d8-controller/pkg/logger" v1alpha1 "github.com/deckhouse/csi-ceph/api/v1alpha1" - . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + + "d8-controller/pkg/controller" + "d8-controller/pkg/internal" + "d8-controller/pkg/logger" ) var _ = Describe(controller.CephClusterAuthenticationCtrlName, func() { diff --git a/images/controller/src/pkg/controller/ceph_cluster_connection_watcher.go b/images/controller/src/pkg/controller/ceph_cluster_connection_watcher.go index a86c15c..bf368cc 100644 --- a/images/controller/src/pkg/controller/ceph_cluster_connection_watcher.go +++ b/images/controller/src/pkg/controller/ceph_cluster_connection_watcher.go @@ -18,14 +18,11 @@ package controller import ( "context" - "d8-controller/pkg/config" - "d8-controller/pkg/internal" - "d8-controller/pkg/logger" "fmt" - v1alpha1 "github.com/deckhouse/csi-ceph/api/v1alpha1" "reflect" "time" + v1alpha1 "github.com/deckhouse/csi-ceph/api/v1alpha1" corev1 "k8s.io/api/core/v1" k8serr "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" @@ -34,10 +31,13 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" - "sigs.k8s.io/controller-runtime/pkg/manager" + "d8-controller/pkg/config" + "d8-controller/pkg/internal" + "d8-controller/pkg/logger" ) const ( @@ -79,7 +79,7 @@ func RunCephClusterConnectionWatcherController( log.Info(fmt.Sprintf("[CephClusterConnectionReconciler] CeohClusterConnection %s has been reconciled with message: %s", cephClusterConnection.Name, msg)) phase := internal.PhaseCreated if err != nil { - log.Error(err, fmt.Sprintf("[CephClusterConnectionReconciler] an error occured while reconciles the CephClusterConnection, name: %s", cephClusterConnection.Name)) + log.Error(err, fmt.Sprintf("[CephClusterConnectionReconciler] an error occurred while reconciles the CephClusterConnection, name: %s", cephClusterConnection.Name)) phase = internal.PhaseFailed } @@ -108,31 +108,29 @@ func RunCephClusterConnectionWatcherController( return nil, err } - err = c.Watch( - source.Kind(mgr.GetCache(), &v1alpha1.CephClusterConnection{}, - handler.TypedFuncs[*v1alpha1.CephClusterConnection]{ - CreateFunc: func(ctx context.Context, e event.TypedCreateEvent[*v1alpha1.CephClusterConnection], q workqueue.RateLimitingInterface) { - log.Info(fmt.Sprintf("[CreateFunc] get event for CephClusterConnection %q. Add to the queue", e.Object.GetName())) - request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: e.Object.GetNamespace(), Name: e.Object.GetName()}} - q.Add(request) - }, - UpdateFunc: func(ctx context.Context, e event.TypedUpdateEvent[*v1alpha1.CephClusterConnection], q workqueue.RateLimitingInterface) { - log.Info(fmt.Sprintf("[UpdateFunc] get event for CephClusterConnection %q. Check if it should be reconciled", e.ObjectNew.GetName())) - - oldCephClusterConnection := e.ObjectOld - newCephClusterConnection := e.ObjectNew - - if reflect.DeepEqual(oldCephClusterConnection.Spec, newCephClusterConnection.Spec) && newCephClusterConnection.DeletionTimestamp == nil { - log.Info(fmt.Sprintf("[UpdateFunc] an update event for the CephClusterConnection %s has no Spec field updates. It will not be reconciled", newCephClusterConnection.Name)) - return - } - - log.Info(fmt.Sprintf("[UpdateFunc] the CephClusterConnection %q will be reconciled. Add to the queue", newCephClusterConnection.Name)) - request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: newCephClusterConnection.Namespace, Name: newCephClusterConnection.Name}} - q.Add(request) - }, - }, - ), + err = c.Watch(source.Kind(mgr.GetCache(), &v1alpha1.CephClusterConnection{}, handler.TypedFuncs[*v1alpha1.CephClusterConnection, reconcile.Request]{ + CreateFunc: func(_ context.Context, e event.TypedCreateEvent[*v1alpha1.CephClusterConnection], q workqueue.TypedRateLimitingInterface[reconcile.Request]) { + log.Info(fmt.Sprintf("[CreateFunc] get event for CephClusterConnection %q. Add to the queue", e.Object.GetName())) + request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: e.Object.GetNamespace(), Name: e.Object.GetName()}} + q.Add(request) + }, + UpdateFunc: func(_ context.Context, e event.TypedUpdateEvent[*v1alpha1.CephClusterConnection], q workqueue.TypedRateLimitingInterface[reconcile.Request]) { + log.Info(fmt.Sprintf("[UpdateFunc] get event for CephClusterConnection %q. Check if it should be reconciled", e.ObjectNew.GetName())) + + oldCephClusterConnection := e.ObjectOld + newCephClusterConnection := e.ObjectNew + + if reflect.DeepEqual(oldCephClusterConnection.Spec, newCephClusterConnection.Spec) && newCephClusterConnection.DeletionTimestamp == nil { + log.Info(fmt.Sprintf("[UpdateFunc] an update event for the CephClusterConnection %s has no Spec field updates. It will not be reconciled", newCephClusterConnection.Name)) + return + } + + log.Info(fmt.Sprintf("[UpdateFunc] the CephClusterConnection %q will be reconciled. Add to the queue", newCephClusterConnection.Name)) + request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: newCephClusterConnection.Namespace, Name: newCephClusterConnection.Name}} + q.Add(request) + }, + }, + ), ) if err != nil { @@ -159,7 +157,7 @@ func RunCephClusterConnectionEventReconcile(ctx context.Context, cl client.Clien log.Debug(fmt.Sprintf("[RunCephClusterConnectionEventReconcile] finalizer %s was added to the CephClusterConnection %s: %t", CephClusterConnectionControllerFinalizerName, cephClusterConnection.Name, added)) configMapName := internal.CSICephConfigMapName - reconcileTypeForConfigMap, err := IdentifyReconcileFuncForConfigMap(log, configMapList, cephClusterConnection, controllerNamespace, configMapName) + reconcileTypeForConfigMap, err := IdentifyReconcileFuncForConfigMap(log, configMapList, cephClusterConnection, configMapName) if err != nil { err = fmt.Errorf("[RunCephClusterConnectionEventReconcile] error occurred while identifying the reconcile function for CephClusterConnection %s on ConfigMap %s: %w", cephClusterConnection.Name, internal.CSICephConfigMapName, err) return true, err.Error(), err diff --git a/images/controller/src/pkg/controller/ceph_cluster_connection_watcher_func.go b/images/controller/src/pkg/controller/ceph_cluster_connection_watcher_func.go index ae7141b..c20cbc1 100644 --- a/images/controller/src/pkg/controller/ceph_cluster_connection_watcher_func.go +++ b/images/controller/src/pkg/controller/ceph_cluster_connection_watcher_func.go @@ -18,19 +18,20 @@ package controller import ( "context" - "d8-controller/pkg/internal" - "d8-controller/pkg/logger" "encoding/json" "fmt" - v1alpha1 "github.com/deckhouse/csi-ceph/api/v1alpha1" "reflect" "slices" "strings" + v1alpha1 "github.com/deckhouse/csi-ceph/api/v1alpha1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "sigs.k8s.io/controller-runtime/pkg/client" + + "d8-controller/pkg/internal" + "d8-controller/pkg/logger" ) func validateCephClusterConnectionSpec(cephClusterConnection *v1alpha1.CephClusterConnection) (bool, string) { @@ -74,7 +75,7 @@ func updateCephClusterConnectionPhase(ctx context.Context, cl client.Client, cep } // ConfigMap -func IdentifyReconcileFuncForConfigMap(log logger.Logger, configMapList *corev1.ConfigMapList, cephClusterConnection *v1alpha1.CephClusterConnection, controllerNamespace, configMapName string) (reconcileType string, err error) { +func IdentifyReconcileFuncForConfigMap(log logger.Logger, configMapList *corev1.ConfigMapList, cephClusterConnection *v1alpha1.CephClusterConnection, configMapName string) (reconcileType string, err error) { if shouldReconcileByDeleteFunc(cephClusterConnection) { return internal.DeleteReconcile, nil } @@ -101,11 +102,7 @@ func shouldReconcileConfigMapByCreateFunc(configMapList *corev1.ConfigMapList, c for _, cm := range configMapList.Items { if cm.Name == configMapName { - if cm.Data["config.json"] == "" { - return true - } - - return false + return cm.Data["config.json"] == "" } } @@ -267,7 +264,7 @@ func reconcileConfigMapDeleteFunc(ctx context.Context, cl client.Client, log log } } - _, err = removeFinalizerIfExists(ctx, cl, cephClusterConnection, CephClusterConnectionControllerFinalizerName) + err = removeFinalizerIfExists(ctx, cl, cephClusterConnection, CephClusterConnectionControllerFinalizerName) if err != nil { err = fmt.Errorf("[reconcileConfigMapDeleteFunc] unable to remove finalizer from the CephClusterConnection %s: %w", cephClusterConnection.Name, err) return true, err.Error(), err @@ -313,10 +310,10 @@ func updateConfigMap(oldConfigMap *corev1.ConfigMap, cephClusterConnection *v1al clusterConfigs = append(clusterConfigs, newClusterConfig) } - newJsonData, _ := json.Marshal(clusterConfigs) + newJSONData, _ := json.Marshal(clusterConfigs) configMap := oldConfigMap.DeepCopy() - configMap.Data["config.json"] = string(newJsonData) + configMap.Data["config.json"] = string(newJSONData) if configMap.Labels == nil { configMap.Labels = map[string]string{} diff --git a/images/controller/src/pkg/controller/ceph_cluster_connection_watcher_test.go b/images/controller/src/pkg/controller/ceph_cluster_connection_watcher_test.go index dec1de2..a70a382 100644 --- a/images/controller/src/pkg/controller/ceph_cluster_connection_watcher_test.go +++ b/images/controller/src/pkg/controller/ceph_cluster_connection_watcher_test.go @@ -20,17 +20,17 @@ import ( "context" "encoding/json" - "d8-controller/pkg/controller" - "d8-controller/pkg/internal" - "d8-controller/pkg/logger" v1alpha1 "github.com/deckhouse/csi-ceph/api/v1alpha1" - . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + + "d8-controller/pkg/controller" + "d8-controller/pkg/internal" + "d8-controller/pkg/logger" ) var _ = Describe(controller.CephClusterConnectionCtrlName, func() { @@ -82,7 +82,7 @@ var _ = Describe(controller.CephClusterConnectionCtrlName, func() { Expect(shouldReconcile).To(BeFalse()) By("Verifying dependent ConfigMap") - verifyConfigMap(ctx, cl, cephClusterConnection, controllerNamespace) + verifyConfigMap(ctx, cl, cephClusterConnection) By("Verifying CephClusterConnection after create reconcile") createdCephClusterConnection = &v1alpha1.CephClusterConnection{} @@ -116,7 +116,7 @@ var _ = Describe(controller.CephClusterConnectionCtrlName, func() { Expect(shouldReconcile).To(BeFalse()) By("Verifying updated ConfigMap") - verifyConfigMap(ctx, cl, updatedCephClusterConnection, controllerNamespace) + verifyConfigMap(ctx, cl, updatedCephClusterConnection) By("Verifying CephClusterConnection after update reconcile") updatedCephClusterConnection = &v1alpha1.CephClusterConnection{} @@ -149,7 +149,7 @@ var _ = Describe(controller.CephClusterConnectionCtrlName, func() { Expect(shouldReconcile).To(BeFalse()) By("Verifying ConfigMap update after deletion") - verifyConfigMapWithoutClusterConnection(ctx, cl, cephClusterConnection, controllerNamespace) + verifyConfigMapWithoutClusterConnection(ctx, cl, cephClusterConnection) By("Verifying CephClusterConnection after delete reconcile") deletedCephClusterConnection = &v1alpha1.CephClusterConnection{} @@ -182,7 +182,7 @@ var _ = Describe(controller.CephClusterConnectionCtrlName, func() { Expect(shouldReconcile).To(BeFalse()) By("Verifying no ConfigMap entry created for invalid CephClusterConnection") - verifyConfigMapWithoutClusterConnection(ctx, cl, cephClusterConnection, controllerNamespace) + verifyConfigMapWithoutClusterConnection(ctx, cl, cephClusterConnection) By("Creating CephClusterConnection with empty Monitors") cephClusterConnection.Spec.ClusterID = clusterID @@ -198,7 +198,7 @@ var _ = Describe(controller.CephClusterConnectionCtrlName, func() { Expect(shouldReconcile).To(BeFalse()) By("Verifying no ConfigMap entry created for CephClusterConnection with empty Monitors") - verifyConfigMapWithoutClusterConnection(ctx, cl, cephClusterConnection, controllerNamespace) + verifyConfigMapWithoutClusterConnection(ctx, cl, cephClusterConnection) By("Fix CephClusterConnection") cephClusterConnection.Spec.Monitors = monitors @@ -211,7 +211,7 @@ var _ = Describe(controller.CephClusterConnectionCtrlName, func() { Expect(shouldReconcile).To(BeFalse()) By("Verifying ConfigMap entry created for fixed CephClusterConnection") - verifyConfigMap(ctx, cl, cephClusterConnection, controllerNamespace) + verifyConfigMap(ctx, cl, cephClusterConnection) By("Verifying CephClusterConnection after fix reconcile") cephClusterConnection = &v1alpha1.CephClusterConnection{} @@ -236,7 +236,7 @@ var _ = Describe(controller.CephClusterConnectionCtrlName, func() { Expect(shouldReconcile).To(BeFalse()) By("Verifying ConfigMap not changed for CephClusterConnection with empty Monitors after fix") - verifyConfigMap(ctx, cl, cephClusterConnection, controllerNamespace) + verifyConfigMap(ctx, cl, cephClusterConnection) By("Verifying CephClusterConnection not changed after fix reconcile") badCephClusterConnection = &v1alpha1.CephClusterConnection{} @@ -270,7 +270,7 @@ var _ = Describe(controller.CephClusterConnectionCtrlName, func() { Expect(shouldReconcile).To(BeFalse()) By("Verifying ConfigMap is empty after deletion of CephClusterConnection with empty Monitors") - verifyConfigMapWithoutClusterConnection(ctx, cl, cephClusterConnection, controllerNamespace) + verifyConfigMapWithoutClusterConnection(ctx, cl, cephClusterConnection) By("Verifying CephClusterConnection is deleted after deletion of CephClusterConnection with empty Monitors") badCephClusterConnection = &v1alpha1.CephClusterConnection{} @@ -279,7 +279,8 @@ var _ = Describe(controller.CephClusterConnectionCtrlName, func() { }) }) -func verifyConfigMap(ctx context.Context, cl client.Client, cephClusterConnection *v1alpha1.CephClusterConnection, controllerNamespace string) { +func verifyConfigMap(ctx context.Context, cl client.Client, cephClusterConnection *v1alpha1.CephClusterConnection) { + controllerNamespace := "test-namespace" configMap := &corev1.ConfigMap{} err := cl.Get(ctx, client.ObjectKey{Name: internal.CSICephConfigMapName, Namespace: controllerNamespace}, configMap) Expect(err).NotTo(HaveOccurred()) @@ -302,7 +303,8 @@ func verifyConfigMap(ctx context.Context, cl client.Client, cephClusterConnectio Expect(found).To(BeTrue(), "Cluster config not found in ConfigMap") } -func verifyConfigMapWithoutClusterConnection(ctx context.Context, cl client.Client, cephClusterConnection *v1alpha1.CephClusterConnection, controllerNamespace string) { +func verifyConfigMapWithoutClusterConnection(ctx context.Context, cl client.Client, cephClusterConnection *v1alpha1.CephClusterConnection) { + controllerNamespace := "test-namespace" configMap := &corev1.ConfigMap{} err := cl.Get(ctx, client.ObjectKey{Name: internal.CSICephConfigMapName, Namespace: controllerNamespace}, configMap) Expect(err).NotTo(HaveOccurred()) diff --git a/images/controller/src/pkg/controller/ceph_storage_class_watcher.go b/images/controller/src/pkg/controller/ceph_storage_class_watcher.go index 77b9beb..a9dfc71 100644 --- a/images/controller/src/pkg/controller/ceph_storage_class_watcher.go +++ b/images/controller/src/pkg/controller/ceph_storage_class_watcher.go @@ -18,14 +18,11 @@ package controller import ( "context" - "d8-controller/pkg/config" - "d8-controller/pkg/internal" - "d8-controller/pkg/logger" "fmt" - v1alpha1 "github.com/deckhouse/csi-ceph/api/v1alpha1" "reflect" "time" + v1alpha1 "github.com/deckhouse/csi-ceph/api/v1alpha1" v1 "k8s.io/api/storage/v1" k8serr "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" @@ -34,10 +31,13 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" - "sigs.k8s.io/controller-runtime/pkg/manager" + "d8-controller/pkg/config" + "d8-controller/pkg/internal" + "d8-controller/pkg/logger" ) const ( @@ -92,7 +92,7 @@ func RunCephStorageClassWatcherController( log.Info(fmt.Sprintf("[CephStorageClassReconciler] CephStorageClass %s has been reconciled with message: %s", cephSC.Name, msg)) phase := internal.PhaseCreated if err != nil { - log.Error(err, fmt.Sprintf("[CephStorageClassReconciler] an error occured while reconciles the CephStorageClass, name: %s", cephSC.Name)) + log.Error(err, fmt.Sprintf("[CephStorageClassReconciler] an error occurred while reconciles the CephStorageClass, name: %s", cephSC.Name)) phase = internal.PhaseFailed } @@ -121,31 +121,29 @@ func RunCephStorageClassWatcherController( return nil, err } - err = c.Watch( - source.Kind(mgr.GetCache(), &v1alpha1.CephStorageClass{}, - handler.TypedFuncs[*v1alpha1.CephStorageClass]{ - CreateFunc: func(ctx context.Context, e event.TypedCreateEvent[*v1alpha1.CephStorageClass], q workqueue.RateLimitingInterface) { - log.Info(fmt.Sprintf("[CreateFunc] get event for CephStorageClass %q. Add to the queue", e.Object.GetName())) - request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: e.Object.GetNamespace(), Name: e.Object.GetName()}} - q.Add(request) - }, - UpdateFunc: func(ctx context.Context, e event.TypedUpdateEvent[*v1alpha1.CephStorageClass], q workqueue.RateLimitingInterface) { - log.Info(fmt.Sprintf("[UpdateFunc] get event for CephStorageClass %q. Check if it should be reconciled", e.ObjectNew.GetName())) - - oldCephSC := e.ObjectOld - newCephSC := e.ObjectNew - - if reflect.DeepEqual(oldCephSC.Spec, newCephSC.Spec) && newCephSC.DeletionTimestamp == nil { - log.Info(fmt.Sprintf("[UpdateFunc] an update event for the CephStorageClass %s has no Spec field updates. It will not be reconciled", newCephSC.Name)) - return - } - - log.Info(fmt.Sprintf("[UpdateFunc] the CephStorageClass %q will be reconciled. Add to the queue", newCephSC.Name)) - request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: newCephSC.Namespace, Name: newCephSC.Name}} - q.Add(request) - }, - }, - ), + err = c.Watch(source.Kind(mgr.GetCache(), &v1alpha1.CephStorageClass{}, handler.TypedFuncs[*v1alpha1.CephStorageClass, reconcile.Request]{ + CreateFunc: func(_ context.Context, e event.TypedCreateEvent[*v1alpha1.CephStorageClass], q workqueue.TypedRateLimitingInterface[reconcile.Request]) { + log.Info(fmt.Sprintf("[CreateFunc] get event for CephStorageClass %q. Add to the queue", e.Object.GetName())) + request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: e.Object.GetNamespace(), Name: e.Object.GetName()}} + q.Add(request) + }, + UpdateFunc: func(_ context.Context, e event.TypedUpdateEvent[*v1alpha1.CephStorageClass], q workqueue.TypedRateLimitingInterface[reconcile.Request]) { + log.Info(fmt.Sprintf("[UpdateFunc] get event for CephStorageClass %q. Check if it should be reconciled", e.ObjectNew.GetName())) + + oldCephSC := e.ObjectOld + newCephSC := e.ObjectNew + + if reflect.DeepEqual(oldCephSC.Spec, newCephSC.Spec) && newCephSC.DeletionTimestamp == nil { + log.Info(fmt.Sprintf("[UpdateFunc] an update event for the CephStorageClass %s has no Spec field updates. It will not be reconciled", newCephSC.Name)) + return + } + + log.Info(fmt.Sprintf("[UpdateFunc] the CephStorageClass %q will be reconciled. Add to the queue", newCephSC.Name)) + request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: newCephSC.Namespace, Name: newCephSC.Name}} + q.Add(request) + }, + }, + ), ) if err != nil { log.Error(err, "[RunCephStorageClassWatcherController] unable to watch the events") @@ -187,7 +185,7 @@ func RunStorageClassEventReconcile(ctx context.Context, cl client.Client, log lo reconcileTypeForStorageClass, err := IdentifyReconcileFuncForStorageClass(log, scList, cephSC, controllerNamespace, clusterID) if err != nil { - err = fmt.Errorf("[RunStorageClassEventReconcile] error occured while identifying the reconcile function for StorageClass %s: %w", cephSC.Name, err) + err = fmt.Errorf("[RunStorageClassEventReconcile] error occurred while identifying the reconcile function for StorageClass %s: %w", cephSC.Name, err) return true, err.Error(), err } diff --git a/images/controller/src/pkg/controller/ceph_storage_class_watcher_func.go b/images/controller/src/pkg/controller/ceph_storage_class_watcher_func.go index 2da9084..e262840 100644 --- a/images/controller/src/pkg/controller/ceph_storage_class_watcher_func.go +++ b/images/controller/src/pkg/controller/ceph_storage_class_watcher_func.go @@ -18,20 +18,19 @@ package controller import ( "context" - "d8-controller/pkg/internal" - "d8-controller/pkg/logger" "fmt" "reflect" + "slices" "strings" storagev1alpha1 "github.com/deckhouse/csi-ceph/api/v1alpha1" - - "slices" - corev1 "k8s.io/api/core/v1" v1 "k8s.io/api/storage/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + + "d8-controller/pkg/internal" + "d8-controller/pkg/logger" ) func IdentifyReconcileFuncForStorageClass(log logger.Logger, scList *v1.StorageClassList, cephSC *storagev1alpha1.CephStorageClass, controllerNamespace, clusterID string) (reconcileType string, err error) { @@ -92,11 +91,9 @@ func shouldReconcileStorageClassByUpdateFunc(log logger.Logger, scList *v1.Stora } return false, nil - - } else { - err := fmt.Errorf("a storage class %s with provisioner % s does not belong to allowed provisioners: %v", oldSC.Name, oldSC.Provisioner, allowedProvisioners) - return false, err } + err := fmt.Errorf("a storage class %s with provisioner % s does not belong to allowed provisioners: %v", oldSC.Name, oldSC.Provisioner, allowedProvisioners) + return false, err } } @@ -227,7 +224,7 @@ func reconcileStorageClassDeleteFunc( } } - _, err = removeFinalizerIfExists(ctx, cl, cephSC, CephStorageClassControllerFinalizerName) + err = removeFinalizerIfExists(ctx, cl, cephSC, CephStorageClassControllerFinalizerName) if err != nil { err = fmt.Errorf("[reconcileStorageClassDeleteFunc] unable to remove a finalizer %s from the CephStorageClass %s: %w", CephStorageClassControllerFinalizerName, cephSC.Name, err) return true, err.Error(), err @@ -249,8 +246,6 @@ func ConfigureStorageClass(cephSC *storagev1alpha1.CephStorageClass, controllerN return nil, err } - mountOpt := storagev1alpha1.DefaultMountOptions - sc := &v1.StorageClass{ TypeMeta: metav1.TypeMeta{ Kind: StorageClassKind, @@ -269,7 +264,10 @@ func ConfigureStorageClass(cephSC *storagev1alpha1.CephStorageClass, controllerN ReclaimPolicy: &reclaimPolicy, VolumeBindingMode: &volumeBindingMode, AllowVolumeExpansion: &allowVolumeExpansion, - MountOptions: mountOpt, + } + + if cephSC.Spec.Type == storagev1alpha1.CephStorageClassTypeRBD { + sc.MountOptions = storagev1alpha1.DefaultMountOptionsRBD } return sc, nil @@ -285,7 +283,6 @@ func GetStorageClassProvisioner(cephStorageClasstype string) string { } return provisioner - } func GetStoragecClassParams(cephSC *storagev1alpha1.CephStorageClass, controllerNamespace, clusterID string) (map[string]string, error) { @@ -302,10 +299,10 @@ func GetStoragecClassParams(cephSC *storagev1alpha1.CephStorageClass, controller } if cephSC.Spec.Type == storagev1alpha1.CephStorageClassTypeRBD { - params["imageFeatures"] = "layering,journaling,exclusive-lock,object-map,fast-diff" + params["imageFeatures"] = "layering,exclusive-lock,object-map,fast-diff" params["csi.storage.k8s.io/fstype"] = cephSC.Spec.RBD.DefaultFSType params["pool"] = cephSC.Spec.RBD.Pool - params["mounter"] = "rbd-nbd" + // params["mounter"] = "rbd-nbd" } if cephSC.Spec.Type == storagev1alpha1.CephStorageClassTypeCephFS { @@ -347,7 +344,6 @@ func createStorageClassIfNotExists(ctx context.Context, cl client.Client, scList } func GetSCDiff(oldSC, newSC *v1.StorageClass) (string, error) { - if oldSC.Provisioner != newSC.Provisioner { err := fmt.Errorf("CephStorageClass %q: the provisioner field is different in the StorageClass %q", newSC.Name, oldSC.Name) return "", err @@ -405,7 +401,7 @@ func deleteStorageClass(ctx context.Context, cl client.Client, sc *v1.StorageCla return fmt.Errorf("a storage class %s with provisioner %s does not belong to allowed provisioners: %v", sc.Name, sc.Provisioner, allowedProvisioners) } - _, err := removeFinalizerIfExists(ctx, cl, sc, CephStorageClassControllerFinalizerName) + err := removeFinalizerIfExists(ctx, cl, sc, CephStorageClassControllerFinalizerName) if err != nil { return err } @@ -470,11 +466,9 @@ func validateCephStorageClassSpec(cephSC *storagev1alpha1.CephStorageClass) (boo if cephSC.Spec.CephFS == nil { validationPassed = false failedMsgBuilder.WriteString(fmt.Sprintf("CephStorageClass type is %s but the spec.cephfs field is empty; ", storagev1alpha1.CephStorageClassTypeRBD)) - } else { - if cephSC.Spec.CephFS.FSName == "" { - validationPassed = false - failedMsgBuilder.WriteString("the spec.cephfs.fsName field is empty; ") - } + } else if cephSC.Spec.CephFS.FSName == "" { + validationPassed = false + failedMsgBuilder.WriteString("the spec.cephfs.fsName field is empty; ") } default: validationPassed = false diff --git a/images/controller/src/pkg/controller/ceph_storage_class_watcher_test.go b/images/controller/src/pkg/controller/ceph_storage_class_watcher_test.go index 5e01f41..d31eabf 100644 --- a/images/controller/src/pkg/controller/ceph_storage_class_watcher_test.go +++ b/images/controller/src/pkg/controller/ceph_storage_class_watcher_test.go @@ -18,19 +18,19 @@ package controller_test import ( "context" - "d8-controller/pkg/controller" - "d8-controller/pkg/internal" - "d8-controller/pkg/logger" - v1alpha1 "github.com/deckhouse/csi-ceph/api/v1alpha1" + v1alpha1 "github.com/deckhouse/csi-ceph/api/v1alpha1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - corev1 "k8s.io/api/core/v1" v1 "k8s.io/api/storage/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + + "d8-controller/pkg/controller" + "d8-controller/pkg/internal" + "d8-controller/pkg/logger" ) var _ = Describe(controller.CephStorageClassCtrlName, func() { @@ -163,7 +163,7 @@ var _ = Describe(controller.CephStorageClassCtrlName, func() { sc := &v1.StorageClass{} err = cl.Get(ctx, client.ObjectKey{Name: nameForCephSC}, sc) Expect(err).NotTo(HaveOccurred()) - performStandardChecksForCephSc(sc, nameForCephSC, controllerNamespace, CephStorageClassConfig{ + performStandardChecksForCephSc(sc, nameForCephSC, CephStorageClassConfig{ ClusterConnectionName: clusterConnectionName, ClusterAuthenticationName: clusterAuthenticationName, ReclaimPolicy: reclaimPolicyDelete, @@ -226,7 +226,7 @@ var _ = Describe(controller.CephStorageClassCtrlName, func() { sc := &v1.StorageClass{} err = cl.Get(ctx, client.ObjectKey{Name: nameForCephSC}, sc) Expect(err).NotTo(HaveOccurred()) - performStandardChecksForCephSc(sc, nameForCephSC, controllerNamespace, CephStorageClassConfig{ + performStandardChecksForCephSc(sc, nameForCephSC, CephStorageClassConfig{ ClusterConnectionName: clusterConnectionName, ClusterAuthenticationName: clusterAuthenticationName, ReclaimPolicy: reclaimPolicyRetain, @@ -312,7 +312,7 @@ var _ = Describe(controller.CephStorageClassCtrlName, func() { sc := &v1.StorageClass{} err = cl.Get(ctx, client.ObjectKey{Name: nameForRBDSC}, sc) Expect(err).NotTo(HaveOccurred()) - performStandardChecksForCephSc(sc, nameForRBDSC, controllerNamespace, CephStorageClassConfig{ + performStandardChecksForCephSc(sc, nameForRBDSC, CephStorageClassConfig{ ClusterConnectionName: clusterConnectionName, ClusterAuthenticationName: clusterAuthenticationName, ReclaimPolicy: reclaimPolicyDelete, @@ -358,7 +358,7 @@ var _ = Describe(controller.CephStorageClassCtrlName, func() { sc := &v1.StorageClass{} err = cl.Get(ctx, client.ObjectKey{Name: nameForRBDSC}, sc) Expect(err).NotTo(HaveOccurred()) - performStandardChecksForCephSc(sc, nameForRBDSC, controllerNamespace, CephStorageClassConfig{ + performStandardChecksForCephSc(sc, nameForRBDSC, CephStorageClassConfig{ ClusterConnectionName: clusterConnectionName, ClusterAuthenticationName: clusterAuthenticationName, ReclaimPolicy: reclaimPolicyRetain, @@ -627,7 +627,7 @@ var _ = Describe(controller.CephStorageClassCtrlName, func() { sc := &v1.StorageClass{} err = cl.Get(ctx, client.ObjectKey{Name: nameForCephSC}, sc) Expect(err).NotTo(HaveOccurred()) - performStandardChecksForCephSc(sc, nameForCephSC, controllerNamespace, CephStorageClassConfig{ + performStandardChecksForCephSc(sc, nameForCephSC, CephStorageClassConfig{ ClusterConnectionName: clusterConnectionName, ClusterAuthenticationName: clusterAuthenticationName, ReclaimPolicy: reclaimPolicyDelete, @@ -738,7 +738,8 @@ func generateCephStorageClass(cfg CephStorageClassConfig) *v1alpha1.CephStorageC } } -func performStandardChecksForCephSc(sc *v1.StorageClass, nameForTestResource, controllerNamespace string, cfg CephStorageClassConfig) { +func performStandardChecksForCephSc(sc *v1.StorageClass, nameForTestResource string, cfg CephStorageClassConfig) { + controllerNamespace := "test-namespace" Expect(sc).NotTo(BeNil()) Expect(sc.Name).To(Equal(nameForTestResource)) Expect(sc.Finalizers).To(HaveLen(1)) diff --git a/images/controller/src/pkg/controller/common_func.go b/images/controller/src/pkg/controller/common_func.go index 57738d2..366a0bb 100644 --- a/images/controller/src/pkg/controller/common_func.go +++ b/images/controller/src/pkg/controller/common_func.go @@ -25,14 +25,10 @@ import ( ) func shouldReconcileByDeleteFunc(obj metav1.Object) bool { - if obj.GetDeletionTimestamp() != nil { - return true - } - - return false + return obj.GetDeletionTimestamp() != nil } -func removeFinalizerIfExists(ctx context.Context, cl client.Client, obj metav1.Object, finalizerName string) (bool, error) { +func removeFinalizerIfExists(ctx context.Context, cl client.Client, obj metav1.Object, finalizerName string) error { removed := false finalizers := obj.GetFinalizers() for i, f := range finalizers { @@ -47,11 +43,11 @@ func removeFinalizerIfExists(ctx context.Context, cl client.Client, obj metav1.O obj.SetFinalizers(finalizers) err := cl.Update(ctx, obj.(client.Object)) if err != nil { - return false, err + return err } } - return removed, nil + return nil } func addFinalizerIfNotExists(ctx context.Context, cl client.Client, obj metav1.Object, finalizerName string) (bool, error) { diff --git a/images/controller/src/pkg/controller/controller_suite_test.go b/images/controller/src/pkg/controller/controller_suite_test.go index 7b13a08..39dc0d2 100644 --- a/images/controller/src/pkg/controller/controller_suite_test.go +++ b/images/controller/src/pkg/controller/controller_suite_test.go @@ -18,22 +18,19 @@ package controller_test import ( "fmt" - v1alpha1 "github.com/deckhouse/csi-ceph/api/v1alpha1" "os" "testing" - v1 "k8s.io/api/apps/v1" - - "sigs.k8s.io/controller-runtime/pkg/client/fake" - + v1alpha1 "github.com/deckhouse/csi-ceph/api/v1alpha1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + v1 "k8s.io/api/apps/v1" sv1 "k8s.io/api/storage/v1" extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - apiruntime "k8s.io/apimachinery/pkg/runtime" clientgoscheme "k8s.io/client-go/kubernetes/scheme" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/client/fake" ) func TestController(t *testing.T) { diff --git a/images/controller/src/pkg/kubutils/kubernetes.go b/images/controller/src/pkg/kubutils/kubernetes.go index 4714cfe..57a44ad 100644 --- a/images/controller/src/pkg/kubutils/kubernetes.go +++ b/images/controller/src/pkg/kubutils/kubernetes.go @@ -15,12 +15,13 @@ package kubutils import ( "fmt" + "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" ) func KubernetesDefaultConfigCreate() (*rest.Config, error) { - //todo validate empty + // todo validate empty clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig( clientcmd.NewDefaultClientConfigLoadingRules(), &clientcmd.ConfigOverrides{}, diff --git a/images/controller/src/pkg/logger/logger.go b/images/controller/src/pkg/logger/logger.go index 345af2b..ef8fccf 100644 --- a/images/controller/src/pkg/logger/logger.go +++ b/images/controller/src/pkg/logger/logger.go @@ -19,6 +19,7 @@ package logger import ( "flag" "fmt" + "github.com/go-logr/logr" "k8s.io/klog/v2" "k8s.io/klog/v2/klogr" @@ -55,6 +56,8 @@ func NewLogger(level Verbosity) (*Logger, error) { flag.Parse() log := klogr.New().WithCallDepth(1) + // config := textlogger.NewConfig() + // log := textlogger.NewLogger(config) return &Logger{log: log}, nil } diff --git a/images/controller/werf.inc.yaml b/images/controller/werf.inc.yaml index 590e6e9..c0a68b5 100644 --- a/images/controller/werf.inc.yaml +++ b/images/controller/werf.inc.yaml @@ -4,11 +4,15 @@ --- image: {{ $.ImageName }}-golang-artifact from: {{ $.BASE_GOLANG_22_ALPINE }} +fromCacheVersion: 20240827144204 final: false git: - - add: /images/controller/src - to: /src + - add: / + to: / + includePaths: + - api + - images/controller/src stageDependencies: setup: - "**/*" @@ -17,9 +21,8 @@ mount: to: /go/pkg shell: setup: - - cd /src/cmd - - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" -o controller - - mv controller /controller + - cd /images/controller/src/cmd + - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" -o /controller - chmod +x /controller --- diff --git a/images/csi-ceph/patches/0001-fix-gomod.patch b/images/csi-ceph/patches/0001-fix-gomod.patch new file mode 100644 index 0000000..8d6cb5b --- /dev/null +++ b/images/csi-ceph/patches/0001-fix-gomod.patch @@ -0,0 +1,38 @@ +Subject: [PATCH] Fix +--- +Index: actions/retest/go.mod +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/actions/retest/go.mod b/actions/retest/go.mod +--- a/actions/retest/go.mod (revision 42797edd7e5e640e755a948a018d69c9200b7e60) ++++ b/actions/retest/go.mod (revision 18f10a7809fbc04de6dd5d161f227659ac4d6555) +@@ -10,7 +10,7 @@ + require ( + github.com/golang/protobuf v1.5.3 // indirect + github.com/google/go-querystring v1.1.0 // indirect +- golang.org/x/net v0.22.0 // indirect ++ golang.org/x/net v0.23.0 // indirect + google.golang.org/appengine v1.6.7 // indirect + google.golang.org/protobuf v1.33.0 // indirect + ) +Index: actions/retest/go.sum +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/actions/retest/go.sum b/actions/retest/go.sum +--- a/actions/retest/go.sum (revision 42797edd7e5e640e755a948a018d69c9200b7e60) ++++ b/actions/retest/go.sum (revision 18f10a7809fbc04de6dd5d161f227659ac4d6555) +@@ -11,8 +11,8 @@ + github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= + golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= + golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +-golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= +-golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= ++golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= ++golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= + golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI= + golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8= + golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/images/csi-ceph/patches/README.md b/images/csi-ceph/patches/README.md new file mode 100644 index 0000000..e69de29 diff --git a/images/csi-ceph/werf.inc.yaml b/images/csi-ceph/werf.inc.yaml index cc0cb57..6a0b3a0 100644 --- a/images/csi-ceph/werf.inc.yaml +++ b/images/csi-ceph/werf.inc.yaml @@ -1,3 +1,5 @@ +{{- $version := "3.12.1" }} + {{- $binaries := "/cephcsi /sbin/mount.ceph /usr/bin/ceph-fuse /bin/mount /bin/umount /sbin/fsck /sbin/modprobe /bin/kmod /usr/bin/rbd /usr/bin/rbd-nbd /sbin/blkid /sbin/mkfs /sbin/mkfs.ext4 /sbin/mkfs.xfs /sbin/blockdev /sbin/dumpe2fs /usr/sbin/xfs_io /usr/sbin/xfs_growfs /sbin/resize2fs" }} {{- $_ := set . "BASE_ALT_DEV" "registry.deckhouse.io/base_images/dev-alt:p10@sha256:76e6e163fa982f03468166203488b569e6d9fc10855d6a259c662706436cdcad" }} {{- $_ := set . "BASE_SCRATCH" "registry.deckhouse.io/base_images/scratch@sha256:b054705fcc9f2205777d80a558d920c0b4209efdc3163c22b5bfcb5dda1db5fc" }} @@ -7,13 +9,22 @@ image: {{ $.ImageName }}-binaries-artifact from: {{ $.BASE_ALT_DEV }} final: false +git: + - add: /images/{{ $.ImageName }} + to: / + stageDependencies: + setup: + - "**/*" + includePaths: + - patches + shell: install: - - mkdir -p /src - - cd /src - - git clone --branch v3.7.2 --depth 1 {{ env "SOURCE_REPO" }}/ceph/ceph-csi.git . - export GOPROXY={{ env "GOPROXY" }} - export CGO_ENABLED=1 + - git clone --branch v{{ $version }} --depth 1 {{ env "SOURCE_REPO" }}/ceph/ceph-csi.git /src + - cd /src + - for patchfile in /patches/*.patch ; do echo -n "Apply ${patchfile} ... "; git apply ${patchfile}; done - make cephcsi - cp _output/cephcsi /cephcsi - /binary_replace.sh -i "{{ $binaries }}" -o /relocate diff --git a/images/webhooks/src/go.mod b/images/webhooks/src/go.mod index 039314d..dd9b360 100644 --- a/images/webhooks/src/go.mod +++ b/images/webhooks/src/go.mod @@ -7,28 +7,30 @@ toolchain go1.22.2 require ( github.com/sirupsen/logrus v1.9.3 github.com/slok/kubewebhook/v2 v2.6.0 - k8s.io/api v0.30.0 - k8s.io/apimachinery v0.30.0 - k8s.io/klog/v2 v2.120.1 + k8s.io/api v0.31.0 + k8s.io/apimachinery v0.31.0 + k8s.io/klog/v2 v2.130.1 ) require ( - github.com/go-logr/logr v1.4.1 // indirect + github.com/fxamacker/cbor/v2 v2.7.0 // indirect + github.com/go-logr/logr v1.4.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/rogpeppe/go-internal v1.11.0 // indirect + github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/stretchr/testify v1.9.0 // indirect - golang.org/x/net v0.24.0 // indirect - golang.org/x/sys v0.19.0 // indirect - golang.org/x/text v0.14.0 // indirect + github.com/x448/float16 v0.8.4 // indirect + golang.org/x/net v0.28.0 // indirect + golang.org/x/sys v0.24.0 // indirect + golang.org/x/text v0.17.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - k8s.io/client-go v0.30.0 // indirect - k8s.io/utils v0.0.0-20240423183400-0849a56e8f22 // indirect + k8s.io/client-go v0.31.0 // indirect + k8s.io/utils v0.0.0-20240821151609-f90d01438635 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect diff --git a/images/webhooks/src/go.sum b/images/webhooks/src/go.sum index 5a26076..e39156f 100644 --- a/images/webhooks/src/go.sum +++ b/images/webhooks/src/go.sum @@ -3,8 +3,12 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E= +github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ= github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -32,6 +36,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/slok/kubewebhook/v2 v2.6.0 h1:NMDDXx219OcNDc17ZYpqGXW81/jkBNmkdEwFDcZDVcA= @@ -45,6 +50,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= +github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -58,6 +65,8 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= +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/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -67,10 +76,14 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= 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/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= @@ -94,14 +107,24 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= k8s.io/api v0.30.0 h1:siWhRq7cNjy2iHssOB9SCGNCl2spiF1dO3dABqZ8niA= k8s.io/api v0.30.0/go.mod h1:OPlaYhoHs8EQ1ql0R/TsUgaRPhpKNxIMrKQfWUp8QSE= +k8s.io/api v0.31.0 h1:b9LiSjR2ym/SzTOlfMHm1tr7/21aD7fSkqgD/CVJBCo= +k8s.io/api v0.31.0/go.mod h1:0YiFF+JfFxMM6+1hQei8FY8M7s1Mth+z/q7eF1aJkTE= k8s.io/apimachinery v0.30.0 h1:qxVPsyDM5XS96NIh9Oj6LavoVFYff/Pon9cZeDIkHHA= k8s.io/apimachinery v0.30.0/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= +k8s.io/apimachinery v0.31.0 h1:m9jOiSr3FoSSL5WO9bjm1n6B9KROYYgNZOb4tyZ1lBc= +k8s.io/apimachinery v0.31.0/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo= k8s.io/client-go v0.30.0 h1:sB1AGGlhY/o7KCyCEQ0bPWzYDL0pwOZO4vAtTSh/gJQ= k8s.io/client-go v0.30.0/go.mod h1:g7li5O5256qe6TYdAMyX/otJqMhIiGgTapdLchhmOaY= +k8s.io/client-go v0.31.0 h1:QqEJzNjbN2Yv1H79SsS+SWnXkBgVu4Pj3CJQgbx0gI8= +k8s.io/client-go v0.31.0/go.mod h1:Y9wvC76g4fLjmU0BA+rV+h2cncoadjvjjkkIGoTLcGU= k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw= k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= +k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= +k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= k8s.io/utils v0.0.0-20240423183400-0849a56e8f22 h1:ao5hUqGhsqdm+bYbjH/pRkCs0unBGe9UyDahzs9zQzQ= k8s.io/utils v0.0.0-20240423183400-0849a56e8f22/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +k8s.io/utils v0.0.0-20240821151609-f90d01438635 h1:2wThSvJoW/Ncn9TmQEYXRnevZXi2duqHWf5OX9S3zjI= +k8s.io/utils v0.0.0-20240821151609-f90d01438635/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4= diff --git a/images/webhooks/src/handlers/func.go b/images/webhooks/src/handlers/func.go index 114a1e2..d9783e6 100644 --- a/images/webhooks/src/handlers/func.go +++ b/images/webhooks/src/handlers/func.go @@ -20,9 +20,8 @@ import ( "context" "net/http" - "github.com/slok/kubewebhook/v2/pkg/log" - kwhhttp "github.com/slok/kubewebhook/v2/pkg/http" + "github.com/slok/kubewebhook/v2/pkg/log" "github.com/slok/kubewebhook/v2/pkg/model" kwhmutating "github.com/slok/kubewebhook/v2/pkg/webhook/mutating" kwhvalidating "github.com/slok/kubewebhook/v2/pkg/webhook/validating" @@ -47,7 +46,6 @@ func GetMutatingWebhookHandler(mutationFunc func(ctx context.Context, _ *model.A mutationWebhookHandler, err := kwhhttp.HandlerFor(kwhhttp.HandlerConfig{Webhook: mutationWebhook, Logger: logger}) return mutationWebhookHandler, err - } func GetValidatingWebhookHandler(validationFunc func(ctx context.Context, _ *model.AdmissionReview, obj metav1.Object) (*kwhvalidating.ValidatorResult, error), validatorID string, obj metav1.Object, logger log.Logger) (http.Handler, error) { @@ -68,7 +66,6 @@ func GetValidatingWebhookHandler(validationFunc func(ctx context.Context, _ *mod mutationWebhookHandler, err := kwhhttp.HandlerFor(kwhhttp.HandlerConfig{Webhook: mutationWebhook, Logger: logger}) return mutationWebhookHandler, err - } func contains(slice []string, s string) bool { diff --git a/images/webhooks/src/handlers/scValidator.go b/images/webhooks/src/handlers/scValidator.go index 91c6f36..18a4cad 100644 --- a/images/webhooks/src/handlers/scValidator.go +++ b/images/webhooks/src/handlers/scValidator.go @@ -22,12 +22,11 @@ import ( "fmt" "reflect" - "k8s.io/klog/v2" - "github.com/slok/kubewebhook/v2/pkg/model" kwhvalidating "github.com/slok/kubewebhook/v2/pkg/webhook/validating" storagev1 "k8s.io/api/storage/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/klog/v2" ) const ( @@ -41,7 +40,7 @@ var ( } ) -func SCValidate(ctx context.Context, arReview *model.AdmissionReview, obj metav1.Object) (*kwhvalidating.ValidatorResult, error) { +func SCValidate(_ context.Context, arReview *model.AdmissionReview, obj metav1.Object) (*kwhvalidating.ValidatorResult, error) { sc, ok := obj.(*storagev1.StorageClass) if !ok { // If not a storage class just continue the validation chain(if there is one) and do nothing. @@ -54,32 +53,31 @@ func SCValidate(ctx context.Context, arReview *model.AdmissionReview, obj metav1 klog.Infof("User %s is allowed to manage storage classes with provisioner %s", arReview.UserInfo.Username, sc.Provisioner) return &kwhvalidating.ValidatorResult{Valid: true}, nil - } else { - if arReview.Operation == model.OperationUpdate { - changed, err := isStorageClassChangedExceptAnnotations(arReview.OldObjectRaw, arReview.NewObjectRaw) - if err != nil { - return nil, err - } - - if !changed { - klog.Infof("User %s is allowed to change annotations for storage classes with provisioner %s", arReview.UserInfo.Username, sc.Provisioner) - return &kwhvalidating.ValidatorResult{Valid: true}, - nil - } + } + + if arReview.Operation == model.OperationUpdate { + changed, err := isStorageClassChangedExceptAnnotations(arReview.OldObjectRaw, arReview.NewObjectRaw) + if err != nil { + return nil, err } - klog.Infof("User %s is not allowed to manage storage classes with provisioner %s", arReview.UserInfo.Username, sc.Provisioner) - return &kwhvalidating.ValidatorResult{ - Valid: false, - Message: fmt.Sprintf("Direct modifications to the StorageClass (other than annotations) with the provisioner %s are not allowed. Please use CephStorageClass for such operations.", sc.Provisioner), - }, - nil + if !changed { + klog.Infof("User %s is allowed to change annotations for storage classes with provisioner %s", arReview.UserInfo.Username, sc.Provisioner) + return &kwhvalidating.ValidatorResult{Valid: true}, + nil + } } - } else { - return &kwhvalidating.ValidatorResult{Valid: true}, + + klog.Infof("User %s is not allowed to manage storage classes with provisioner %s", arReview.UserInfo.Username, sc.Provisioner) + return &kwhvalidating.ValidatorResult{ + Valid: false, + Message: fmt.Sprintf("Direct modifications to the StorageClass (other than annotations) with the provisioner %s are not allowed. Please use CephStorageClass for such operations.", sc.Provisioner), + }, nil } + return &kwhvalidating.ValidatorResult{Valid: true}, + nil } func isStorageClassChangedExceptAnnotations(oldObjectRaw, newObjectRaw []byte) (bool, error) { diff --git a/images/webhooks/src/main.go b/images/webhooks/src/main.go index d925111..ffacb7b 100644 --- a/images/webhooks/src/main.go +++ b/images/webhooks/src/main.go @@ -21,11 +21,12 @@ import ( "fmt" "net/http" "os" - "webhooks/handlers" "github.com/sirupsen/logrus" kwhlogrus "github.com/slok/kubewebhook/v2/pkg/log/logrus" storagev1 "k8s.io/api/storage/v1" + + "webhooks/handlers" ) type config struct { @@ -33,7 +34,7 @@ type config struct { keyFile string } -func httpHandlerHealthz(w http.ResponseWriter, r *http.Request) { +func httpHandlerHealthz(w http.ResponseWriter, _ *http.Request) { fmt.Fprint(w, "Ok.") } @@ -44,13 +45,17 @@ func initFlags() config { fl.StringVar(&cfg.certFile, "tls-cert-file", "", "TLS certificate file") fl.StringVar(&cfg.keyFile, "tls-key-file", "", "TLS key file") - fl.Parse(os.Args[1:]) + err := fl.Parse(os.Args[1:]) + if err != nil { + fmt.Fprintf(os.Stderr, "error parsing flags: %s", err) + os.Exit(1) + } return cfg } const ( port = ":8443" - SCValidatorId = "SCValidator" + SCValidatorID = "SCValidator" ) func main() { @@ -60,7 +65,7 @@ func main() { cfg := initFlags() - scValidatingWebhookHandler, err := handlers.GetValidatingWebhookHandler(handlers.SCValidate, SCValidatorId, &storagev1.StorageClass{}, logger) + scValidatingWebhookHandler, err := handlers.GetValidatingWebhookHandler(handlers.SCValidate, SCValidatorID, &storagev1.StorageClass{}, logger) if err != nil { fmt.Fprintf(os.Stderr, "error creating scValidatingWebhookHandler: %s", err) os.Exit(1) diff --git a/trivy.yaml b/trivy.yaml new file mode 100644 index 0000000..75925af --- /dev/null +++ b/trivy.yaml @@ -0,0 +1,2 @@ +format: table +exit-code: 1