From 9f4c20e7c434885fa80f488f332e3d3c8e414927 Mon Sep 17 00:00:00 2001 From: mgianluc Date: Fri, 22 Mar 2024 09:18:26 +0100 Subject: [PATCH 01/10] Bump go modules Start development for new release --- Makefile | 2 +- config/default/manager_auth_proxy_patch.yaml | 2 +- config/default/manager_image_patch.yaml | 2 +- go.mod | 24 +++++----- go.sum | 48 ++++++++++---------- hack/tools/go.mod | 12 ++--- hack/tools/go.sum | 28 +++++------- manifest/deployment-shard.yaml | 4 +- manifest/manifest.yaml | 4 +- 9 files changed, 61 insertions(+), 65 deletions(-) diff --git a/Makefile b/Makefile index bbe9aa51..8d9a24fe 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ ARCH ?= amd64 OS ?= $(shell uname -s | tr A-Z a-z) K8S_LATEST_VER ?= $(shell curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt) export CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME) -TAG ?= main +TAG ?= dev .PHONY: all all: build diff --git a/config/default/manager_auth_proxy_patch.yaml b/config/default/manager_auth_proxy_patch.yaml index a03918f5..c20df17e 100644 --- a/config/default/manager_auth_proxy_patch.yaml +++ b/config/default/manager_auth_proxy_patch.yaml @@ -15,4 +15,4 @@ spec: - "--report-mode=0" - --shard-key= - "--v=5" - - "--version=main" + - "--version=dev" diff --git a/config/default/manager_image_patch.yaml b/config/default/manager_image_patch.yaml index b0e3a6ce..69525b25 100644 --- a/config/default/manager_image_patch.yaml +++ b/config/default/manager_image_patch.yaml @@ -8,5 +8,5 @@ spec: spec: containers: # Change the value of image field below to your controller image URL - - image: projectsveltos/addon-controller-amd64:main + - image: projectsveltos/addon-controller-amd64:dev name: controller diff --git a/go.mod b/go.mod index 74cab055..707a7002 100644 --- a/go.mod +++ b/go.mod @@ -12,8 +12,8 @@ require ( github.com/fluxcd/source-controller/api v1.2.4 github.com/gdexlab/go-render v1.0.1 github.com/go-logr/logr v1.4.1 - github.com/onsi/ginkgo/v2 v2.16.0 - github.com/onsi/gomega v1.31.1 + github.com/onsi/ginkgo/v2 v2.17.0 + github.com/onsi/gomega v1.32.0 github.com/pkg/errors v0.9.1 github.com/projectsveltos/libsveltos v0.26.1-0.20240315101738-cf8cc0af064f github.com/prometheus/client_golang v1.19.0 @@ -21,14 +21,14 @@ require ( github.com/yuin/gopher-lua v1.1.1 golang.org/x/text v0.14.0 helm.sh/helm/v3 v3.14.3 - k8s.io/api v0.29.1 - k8s.io/apiextensions-apiserver v0.29.1 - k8s.io/apimachinery v0.29.1 - k8s.io/cli-runtime v0.29.1 - k8s.io/client-go v0.29.1 - k8s.io/component-base v0.29.1 + k8s.io/api v0.29.3 + k8s.io/apiextensions-apiserver v0.29.3 + k8s.io/apimachinery v0.29.3 + k8s.io/cli-runtime v0.29.3 + k8s.io/client-go v0.29.3 + k8s.io/component-base v0.29.3 k8s.io/klog/v2 v2.120.1 - k8s.io/utils v0.0.0-20240102154912-e7106e64919e + k8s.io/utils v0.0.0-20240310230437-4693a0247e57 sigs.k8s.io/cluster-api v1.6.3 sigs.k8s.io/controller-runtime v0.17.2 sigs.k8s.io/kustomize/api v0.16.0 @@ -82,7 +82,7 @@ require ( github.com/gobwas/glob v0.2.3 // 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/btree v1.1.2 // indirect github.com/google/cel-go v0.17.7 // indirect github.com/google/gnostic-models v0.6.8 // indirect @@ -168,7 +168,7 @@ require ( golang.org/x/tools v0.17.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect google.golang.org/appengine v1.6.8 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20231002182017-d307bd883b97 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20231211222908-989df2bf70f3 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 // indirect google.golang.org/grpc v1.60.1 // indirect google.golang.org/protobuf v1.33.0 // indirect @@ -176,7 +176,7 @@ require ( 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/apiserver v0.29.1 // indirect + k8s.io/apiserver v0.29.3 // indirect k8s.io/kube-openapi v0.0.0-20240103195357-a9f8850cb432 // indirect k8s.io/kubectl v0.29.1 // indirect oras.land/oras-go v1.2.4 // indirect diff --git a/go.sum b/go.sum index e731e9be..f97e6252 100644 --- a/go.sum +++ b/go.sum @@ -174,8 +174,8 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/gomodule/redigo v1.8.2 h1:H5XSIre1MB5NbPYFp+i1NBbb5qN1W8Y8YAQoAYbkm8k= github.com/gomodule/redigo v1.8.2/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0= github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU= @@ -312,10 +312,10 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= -github.com/onsi/ginkgo/v2 v2.16.0 h1:7q1w9frJDzninhXxjZd+Y/x54XNjG/UlRLIYPZafsPM= -github.com/onsi/ginkgo/v2 v2.16.0/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs= -github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo= -github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0= +github.com/onsi/ginkgo/v2 v2.17.0 h1:kdnunFXpBjbzN56hcJHrXZ8M+LOkenKA7NnBzTNigTI= +github.com/onsi/ginkgo/v2 v2.17.0/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs= +github.com/onsi/gomega v1.32.0 h1:JRYU78fJ1LPxlckP6Txi/EYqJvjtMrDC04/MM5XRHPk= +github.com/onsi/gomega v1.32.0/go.mod h1:a4x4gW6Pz2yK1MAmvluYme5lvYTn61afQ2ETw/8n4Lg= github.com/opencontainers/go-digest v1.0.1-0.20220411205349-bde1400a84be h1:f2PlhC9pm5sqpBZFvnAoKj+KzXRzbjFMA+TqXfJdgho= github.com/opencontainers/go-digest v1.0.1-0.20220411205349-bde1400a84be/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/go-digest/blake3 v0.0.0-20231025023718-d50d2fec9c98 h1:LTxrNWOPwquJy9Cu3oz6QHJIO5M5gNyOZtSybXdyLA4= @@ -532,8 +532,8 @@ google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAs google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/genproto v0.0.0-20231212172506-995d672761c0 h1:YJ5pD9rF8o9Qtta0Cmy9rdBwkSjrTCT6XTiUQVOtIos= google.golang.org/genproto v0.0.0-20231212172506-995d672761c0/go.mod h1:l/k7rMz0vFTBPy+tFSGvXEd3z+BcoG1k7EHbqm+YBsY= -google.golang.org/genproto/googleapis/api v0.0.0-20231002182017-d307bd883b97 h1:W18sezcAYs+3tDZX4F80yctqa12jcP1PUS2gQu1zTPU= -google.golang.org/genproto/googleapis/api v0.0.0-20231002182017-d307bd883b97/go.mod h1:iargEX0SFPm3xcfMI0d1domjg0ZF4Aa0p2awqyxhvF0= +google.golang.org/genproto/googleapis/api v0.0.0-20231211222908-989df2bf70f3 h1:EWIeHfGuUf00zrVZGEgYFxok7plSAXBGcH7NNdMAWvA= +google.golang.org/genproto/googleapis/api v0.0.0-20231211222908-989df2bf70f3/go.mod h1:k2dtGpRrbsSyKcNPKKI5sstZkrNCZwpU/ns96JoHbGg= google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 h1:6G8oQ016D88m1xAKljMlBOOGWDZkes4kMhgGFlf8WcQ= google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917/go.mod h1:xtjpI3tXFPP051KaWnhvxkiubL/6dJ18vLVf7q2pTOU= google.golang.org/grpc v1.60.1 h1:26+wFr+cNqSGFcOXcabYC0lUVJVRa2Sb2ortSK7VrEU= @@ -563,30 +563,30 @@ gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g= helm.sh/helm/v3 v3.14.3 h1:HmvRJlwyyt9HjgmAuxHbHv3PhMz9ir/XNWHyXfmnOP4= helm.sh/helm/v3 v3.14.3/go.mod h1:v6myVbyseSBJTzhmeE39UcPLNv6cQK6qss3dvgAySaE= -k8s.io/api v0.29.1 h1:DAjwWX/9YT7NQD4INu49ROJuZAAAP/Ijki48GUPzxqw= -k8s.io/api v0.29.1/go.mod h1:7Kl10vBRUXhnQQI8YR/R327zXC8eJ7887/+Ybta+RoQ= -k8s.io/apiextensions-apiserver v0.29.1 h1:S9xOtyk9M3Sk1tIpQMu9wXHm5O2MX6Y1kIpPMimZBZw= -k8s.io/apiextensions-apiserver v0.29.1/go.mod h1:zZECpujY5yTW58co8V2EQR4BD6A9pktVgHhvc0uLfeU= -k8s.io/apimachinery v0.29.1 h1:KY4/E6km/wLBguvCZv8cKTeOwwOBqFNjwJIdMkMbbRc= -k8s.io/apimachinery v0.29.1/go.mod h1:6HVkd1FwxIagpYrHSwJlQqZI3G9LfYWRPAkUvLnXTKU= -k8s.io/apiserver v0.29.1 h1:e2wwHUfEmMsa8+cuft8MT56+16EONIEK8A/gpBSco+g= -k8s.io/apiserver v0.29.1/go.mod h1:V0EpkTRrJymyVT3M49we8uh2RvXf7fWC5XLB0P3SwRw= -k8s.io/cli-runtime v0.29.1 h1:By3WVOlEWYfyxhGko0f/IuAOLQcbBSMzwSaDren2JUs= -k8s.io/cli-runtime v0.29.1/go.mod h1:vjEY9slFp8j8UoMhV5AlO8uulX9xk6ogfIesHobyBDU= -k8s.io/client-go v0.29.1 h1:19B/+2NGEwnFLzt0uB5kNJnfTsbV8w6TgQRz9l7ti7A= -k8s.io/client-go v0.29.1/go.mod h1:TDG/psL9hdet0TI9mGyHJSgRkW3H9JZk2dNEUS7bRks= +k8s.io/api v0.29.3 h1:2ORfZ7+bGC3YJqGpV0KSDDEVf8hdGQ6A03/50vj8pmw= +k8s.io/api v0.29.3/go.mod h1:y2yg2NTyHUUkIoTC+phinTnEa3KFM6RZ3szxt014a80= +k8s.io/apiextensions-apiserver v0.29.3 h1:9HF+EtZaVpFjStakF4yVufnXGPRppWFEQ87qnO91YeI= +k8s.io/apiextensions-apiserver v0.29.3/go.mod h1:po0XiY5scnpJfFizNGo6puNU6Fq6D70UJY2Cb2KwAVc= +k8s.io/apimachinery v0.29.3 h1:2tbx+5L7RNvqJjn7RIuIKu9XTsIZ9Z5wX2G22XAa5EU= +k8s.io/apimachinery v0.29.3/go.mod h1:hx/S4V2PNW4OMg3WizRrHutyB5la0iCUbZym+W0EQIU= +k8s.io/apiserver v0.29.3 h1:xR7ELlJ/BZSr2n4CnD3lfA4gzFivh0wwfNfz9L0WZcE= +k8s.io/apiserver v0.29.3/go.mod h1:hrvXlwfRulbMbBgmWRQlFru2b/JySDpmzvQwwk4GUOs= +k8s.io/cli-runtime v0.29.3 h1:r68rephmmytoywkw2MyJ+CxjpasJDQY7AGc3XY2iv1k= +k8s.io/cli-runtime v0.29.3/go.mod h1:aqVUsk86/RhaGJwDhHXH0jcdqBrgdF3bZWk4Z9D4mkM= +k8s.io/client-go v0.29.3 h1:R/zaZbEAxqComZ9FHeQwOh3Y1ZUs7FaHKZdQtIc2WZg= +k8s.io/client-go v0.29.3/go.mod h1:tkDisCvgPfiRpxGnOORfkljmS+UrW+WtXAy2fTvXJB0= k8s.io/cluster-bootstrap v0.28.4 h1:4MKNy1Qd9QY7pl47rSMGIORF+tm3CUaqC1M8U9bjn4Q= k8s.io/cluster-bootstrap v0.28.4/go.mod h1:/c4ro/R4yf4EtJgFgFtvnHkbDOHwubeKJXh5R1c89Bc= -k8s.io/component-base v0.29.1 h1:MUimqJPCRnnHsskTTjKD+IC1EHBbRCVyi37IoFBrkYw= -k8s.io/component-base v0.29.1/go.mod h1:fP9GFjxYrLERq1GcWWZAE3bqbNcDKDytn2srWuHTtKc= +k8s.io/component-base v0.29.3 h1:Oq9/nddUxlnrCuuR2K/jp6aflVvc0uDvxMzAWxnGzAo= +k8s.io/component-base v0.29.3/go.mod h1:Yuj33XXjuOk2BAaHsIGHhCKZQAgYKhqIxIjIr2UXYio= k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw= k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= k8s.io/kube-openapi v0.0.0-20240103195357-a9f8850cb432 h1:+XYBQU3ZKUu60H6fEnkitTTabGoKfIG8zczhZBENu9o= k8s.io/kube-openapi v0.0.0-20240103195357-a9f8850cb432/go.mod h1:Pa1PvrP7ACSkuX6I7KYomY6cmMA0Tx86waBhDUgoKPw= k8s.io/kubectl v0.29.1 h1:rWnW3hi/rEUvvg7jp4iYB68qW5un/urKbv7fu3Vj0/s= k8s.io/kubectl v0.29.1/go.mod h1:SZzvLqtuOJYSvZzPZR9weSuP0wDQ+N37CENJf0FhDF4= -k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCfRziVtos3ofG/sQ= -k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +k8s.io/utils v0.0.0-20240310230437-4693a0247e57 h1:gbqbevonBh57eILzModw6mrkbwM0gQBEuevE/AaBsHY= +k8s.io/utils v0.0.0-20240310230437-4693a0247e57/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= oras.land/oras-go v1.2.4 h1:djpBY2/2Cs1PV87GSJlxv4voajVOMZxqqtq9AB8YNvY= oras.land/oras-go v1.2.4/go.mod h1:DYcGfb3YF1nKjcezfX2SNlDAeQFKSXmf+qrFmrh4324= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.0 h1:TgtAeesdhpm2SGwkQasmbeqDo8th5wOBA5h/AjTKA4I= diff --git a/hack/tools/go.mod b/hack/tools/go.mod index 3c62e226..07e894ee 100644 --- a/hack/tools/go.mod +++ b/hack/tools/go.mod @@ -4,9 +4,9 @@ go 1.21 require ( github.com/a8m/envsubst v1.4.2 - github.com/onsi/ginkgo/v2 v2.16.0 + github.com/onsi/ginkgo/v2 v2.17.0 golang.org/x/oauth2 v0.18.0 - k8s.io/client-go v0.29.1 + k8s.io/client-go v0.29.3 sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20240313184151-cb5107b36b64 sigs.k8s.io/controller-tools v0.14.0 sigs.k8s.io/kind v0.22.0 @@ -25,7 +25,7 @@ require ( github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/gobuffalo/flect v1.0.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/protobuf v1.5.3 // indirect + github.com/golang/protobuf v1.5.4 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect @@ -51,13 +51,13 @@ require ( golang.org/x/time v0.3.0 // indirect golang.org/x/tools v0.17.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/api v0.29.1 // indirect + k8s.io/api v0.29.3 // indirect k8s.io/apiextensions-apiserver v0.29.0 // indirect - k8s.io/apimachinery v0.29.1 // indirect + k8s.io/apimachinery v0.29.3 // indirect k8s.io/klog/v2 v2.110.1 // indirect k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect diff --git a/hack/tools/go.sum b/hack/tools/go.sum index 8bc0f554..ca0319e9 100644 --- a/hack/tools/go.sum +++ b/hack/tools/go.sum @@ -43,12 +43,10 @@ github.com/gobuffalo/flect v1.0.2/go.mod h1:A5msMlrHtLqh9umBSnvabjsMrCcCpAyzglnD github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I= github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -99,8 +97,8 @@ github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.16.0 h1:7q1w9frJDzninhXxjZd+Y/x54XNjG/UlRLIYPZafsPM= -github.com/onsi/ginkgo/v2 v2.16.0/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs= +github.com/onsi/ginkgo/v2 v2.17.0 h1:kdnunFXpBjbzN56hcJHrXZ8M+LOkenKA7NnBzTNigTI= +github.com/onsi/ginkgo/v2 v2.17.0/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs= github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM= @@ -192,10 +190,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= @@ -211,14 +207,14 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 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.29.1 h1:DAjwWX/9YT7NQD4INu49ROJuZAAAP/Ijki48GUPzxqw= -k8s.io/api v0.29.1/go.mod h1:7Kl10vBRUXhnQQI8YR/R327zXC8eJ7887/+Ybta+RoQ= +k8s.io/api v0.29.3 h1:2ORfZ7+bGC3YJqGpV0KSDDEVf8hdGQ6A03/50vj8pmw= +k8s.io/api v0.29.3/go.mod h1:y2yg2NTyHUUkIoTC+phinTnEa3KFM6RZ3szxt014a80= k8s.io/apiextensions-apiserver v0.29.0 h1:0VuspFG7Hj+SxyF/Z/2T0uFbI5gb5LRgEyUVE3Q4lV0= k8s.io/apiextensions-apiserver v0.29.0/go.mod h1:TKmpy3bTS0mr9pylH0nOt/QzQRrW7/h7yLdRForMZwc= -k8s.io/apimachinery v0.29.1 h1:KY4/E6km/wLBguvCZv8cKTeOwwOBqFNjwJIdMkMbbRc= -k8s.io/apimachinery v0.29.1/go.mod h1:6HVkd1FwxIagpYrHSwJlQqZI3G9LfYWRPAkUvLnXTKU= -k8s.io/client-go v0.29.1 h1:19B/+2NGEwnFLzt0uB5kNJnfTsbV8w6TgQRz9l7ti7A= -k8s.io/client-go v0.29.1/go.mod h1:TDG/psL9hdet0TI9mGyHJSgRkW3H9JZk2dNEUS7bRks= +k8s.io/apimachinery v0.29.3 h1:2tbx+5L7RNvqJjn7RIuIKu9XTsIZ9Z5wX2G22XAa5EU= +k8s.io/apimachinery v0.29.3/go.mod h1:hx/S4V2PNW4OMg3WizRrHutyB5la0iCUbZym+W0EQIU= +k8s.io/client-go v0.29.3 h1:R/zaZbEAxqComZ9FHeQwOh3Y1ZUs7FaHKZdQtIc2WZg= +k8s.io/client-go v0.29.3/go.mod h1:tkDisCvgPfiRpxGnOORfkljmS+UrW+WtXAy2fTvXJB0= k8s.io/klog/v2 v2.110.1 h1:U/Af64HJf7FcwMcXyKm2RPM22WZzyR7OSpYj5tg3cL0= k8s.io/klog/v2 v2.110.1/go.mod h1:YGtd1984u+GgbuZ7e08/yBuAfKLSO0+uR1Fhi6ExXjo= k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/AuzbMm96cd3YHRTU83I780= diff --git a/manifest/deployment-shard.yaml b/manifest/deployment-shard.yaml index 628967af..5bf3de4f 100644 --- a/manifest/deployment-shard.yaml +++ b/manifest/deployment-shard.yaml @@ -23,10 +23,10 @@ spec: - --report-mode=0 - --shard-key={{.SHARD}} - --v=5 - - --version=main + - --version=dev command: - /manager - image: projectsveltos/addon-controller-amd64:main + image: projectsveltos/addon-controller-amd64:dev livenessProbe: failureThreshold: 3 httpGet: diff --git a/manifest/manifest.yaml b/manifest/manifest.yaml index 93ae8f0f..ed358d1e 100644 --- a/manifest/manifest.yaml +++ b/manifest/manifest.yaml @@ -3603,10 +3603,10 @@ spec: - --report-mode=0 - --shard-key= - --v=5 - - --version=main + - --version=dev command: - /manager - image: projectsveltos/addon-controller-amd64:main + image: projectsveltos/addon-controller-amd64:dev livenessProbe: failureThreshold: 3 httpGet: From e19e37b2093415694350bf82feafe5d0302c5e9c Mon Sep 17 00:00:00 2001 From: mgianluc Date: Fri, 22 Mar 2024 11:19:04 +0100 Subject: [PATCH 02/10] Add fv for agentless mode --- .github/workflows/main.yaml | 28 ++++++++ Makefile | 14 +++- manifest/deployment-agentless.yaml | 68 +++++++++++++++++++ scripts/extract_deployment-agentless.sh | 43 ++++++++++++ ...loyment.sh => extract_deployment-shard.sh} | 2 +- test/fv/drift_test.go | 65 +++++++++++++++--- 6 files changed, 208 insertions(+), 12 deletions(-) create mode 100644 manifest/deployment-agentless.yaml create mode 100755 scripts/extract_deployment-agentless.sh rename scripts/{extract_deployment.sh => extract_deployment-shard.sh} (95%) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 1f52cbc2..764daadb 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -98,3 +98,31 @@ jobs: run: make create-cluster fv-sharding env: FV: true + FV_AGENTLESS: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: Set up Go + uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # tag=v5.0.0 + with: + go-version: 1.21.5 + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + with: + # this might remove tools that are actually needed, + # if set to "true" but frees about 6 GB + tool-cache: false + + # all of these default to true, but feel free to set to + # "false" if necessary for your workflow + android: true + dotnet: true + haskell: true + large-packages: true + docker-images: true + swap-storage: true + - name: fv-agentless + run: make create-cluster fv-agentless + env: + FV: true diff --git a/Makefile b/Makefile index 8d9a24fe..86fca4fc 100644 --- a/Makefile +++ b/Makefile @@ -123,7 +123,8 @@ manifests: $(CONTROLLER_GEN) $(KUSTOMIZE) $(ENVSUBST) fmt generate ## Generate W $(CONTROLLER_GEN) rbac:roleName=controller-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases MANIFEST_IMG=$(CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) $(MAKE) set-manifest-image $(KUSTOMIZE) build config/default | $(ENVSUBST) > manifest/manifest.yaml - ./scripts/extract_deployment.sh manifest/manifest.yaml manifest/deployment-shard.yaml + ./scripts/extract_deployment-shard.sh manifest/manifest.yaml manifest/deployment-shard.yaml + ./scripts/extract_deployment-agentless.sh manifest/manifest.yaml manifest/deployment-agentless.yaml .PHONY: generate generate: $(CONTROLLER_GEN) ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. @@ -206,6 +207,17 @@ fv-sharding: $(KUBECTL) $(GINKGO) ## Run Sveltos Controller tests using existing rm -f test/addon-controller-deployment-shard.yaml cd test/fv; $(GINKGO) -nodes $(NUM_NODES) --label-filter='FV' --v --trace --randomize-all +.PHONY: fv-agentless +fv-agentless: $(KUBECTL) $(GINKGO) ## Run Sveltos Controller tests using existing cluster + $(KUBECTL) apply -f https://raw.githubusercontent.com/projectsveltos/drift-detection-manager/$(TAG)/manifest/mgmt_cluster_common_manifest.yaml + $(KUBECTL) apply -f manifest/drift_detection_manager_rbac.yaml + cp manifest/deployment-agentless.yaml test/addon-controller-deployment-agentless.yaml + $(KUBECTL) apply -f test/addon-controller-deployment-agentless.yaml + rm -f test/addon-controller-deployment-agentless.yaml + @echo "Waiting for projectsveltos addon-controller to be available..." + $(KUBECTL) wait --for=condition=Available deployment/addon-controller -n projectsveltos --timeout=$(TIMEOUT) + cd test/fv; $(GINKGO) -nodes $(NUM_NODES) --label-filter='FV' --v --trace --randomize-all + .PHONY: create-cluster create-cluster: $(KIND) $(CLUSTERCTL) $(KUBECTL) $(ENVSUBST) ## Create a new kind cluster designed for development $(MAKE) create-control-cluster diff --git a/manifest/deployment-agentless.yaml b/manifest/deployment-agentless.yaml new file mode 100644 index 00000000..c72be7c6 --- /dev/null +++ b/manifest/deployment-agentless.yaml @@ -0,0 +1,68 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + control-plane: addon-controller + name: addon-controller + namespace: projectsveltos +spec: + replicas: 1 + selector: + matchLabels: + control-plane: addon-controller + template: + metadata: + annotations: + kubectl.kubernetes.io/default-container: controller + labels: + control-plane: addon-controller + spec: + containers: + - args: + - --diagnostics-address=:8443 + - --report-mode=0 + - --agent-in-mgmt-cluster + - --v=5 + - --version=dev + command: + - /manager + image: projectsveltos/addon-controller-amd64:dev + livenessProbe: + failureThreshold: 3 + httpGet: + path: /healthz + port: healthz + scheme: HTTP + initialDelaySeconds: 15 + periodSeconds: 20 + name: controller + ports: + - containerPort: 8443 + name: metrics + protocol: TCP + - containerPort: 9440 + name: healthz + protocol: TCP + readinessProbe: + failureThreshold: 3 + httpGet: + path: /readyz + port: healthz + scheme: HTTP + initialDelaySeconds: 5 + periodSeconds: 10 + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + volumeMounts: + - mountPath: /tmp + name: tmp + securityContext: + runAsNonRoot: true + serviceAccountName: addon-controller + terminationGracePeriodSeconds: 10 + volumes: + - emptyDir: {} + name: tmp diff --git a/scripts/extract_deployment-agentless.sh b/scripts/extract_deployment-agentless.sh new file mode 100755 index 00000000..ca581c6b --- /dev/null +++ b/scripts/extract_deployment-agentless.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# Define the YAML file path +yaml_file=$1 +output_file=$2 + +# Create a temporary directory to store the split sections +mkdir -p temp_yaml_sections + +# Initialize variables for section counting and flag to track changes +section_count=0 +in_section=false + +# Iterate through the YAML file +while IFS= read -r line; do + if [[ $line == '---' ]]; then + # Start a new section + in_section=true + section_count=$((section_count + 1)) + current_section_file="temp_yaml_sections/section_${section_count}.yaml" + continue + fi + + if [[ $in_section == true ]]; then + # Replace "shard-key=" with "- --agent-in-mgmt-cluster'" + if [[ $line == *"shard-key"* ]]; then + line=$(echo "$line" | sed "s/shard-key=/agent-in-mgmt-cluster/") + fi + + # Write the line to the current section file + echo "$line" >> "$current_section_file" + fi +done < "$yaml_file" + +# Iterate through the split sections and print those with "kind: Deployment" +for section_file in temp_yaml_sections/*.yaml; do + if grep -q "kind: Deployment" "$section_file"; then + cat "$section_file" > $output_file + fi +done + +# Remove the temporary directory +rm -r temp_yaml_sections \ No newline at end of file diff --git a/scripts/extract_deployment.sh b/scripts/extract_deployment-shard.sh similarity index 95% rename from scripts/extract_deployment.sh rename to scripts/extract_deployment-shard.sh index 06266fd2..7460ecf4 100755 --- a/scripts/extract_deployment.sh +++ b/scripts/extract_deployment-shard.sh @@ -22,7 +22,7 @@ while IFS= read -r line; do fi if [[ $in_section == true ]]; then - # Replace "shard-key=" with "shard-key='shard1'" + # Replace "shard-key=" with "shard-key='{{.SHARD}}'" if [[ $line == *"shard-key"* ]]; then line=$(echo "$line" | sed "s/shard-key=/shard-key={{.SHARD}}/") fi diff --git a/test/fv/drift_test.go b/test/fv/drift_test.go index d6e2f962..35461834 100644 --- a/test/fv/drift_test.go +++ b/test/fv/drift_test.go @@ -19,10 +19,12 @@ package fv_test import ( "context" "fmt" + "strings" "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "sigs.k8s.io/controller-runtime/pkg/client" appsv1 "k8s.io/api/apps/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -84,16 +86,40 @@ var _ = Describe("Helm", Serial, func() { types.NamespacedName{Namespace: "kyverno", Name: "kyverno-admission-controller"}, depl) }, timeout, pollingInterval).Should(BeNil()) - Byf("Verifying drift detection manager deployment is created in the workload cluster") - Eventually(func() bool { - depl := &appsv1.Deployment{} - err = workloadClient.Get(context.TODO(), - types.NamespacedName{Namespace: "projectsveltos", Name: "drift-detection-manager"}, depl) - if err != nil { - return false - } - return *depl.Spec.Replicas == depl.Status.ReadyReplicas - }, timeout, pollingInterval).Should(BeTrue()) + if isAgentLessMode() { + Byf("Verifying drift detection manager deployment is created in the management cluster") + Eventually(func() bool { + listOptions := []client.ListOption{ + client.MatchingLabels( + map[string]string{ + "cluster-name": kindWorkloadCluster.Name, + "cluster-namespace": kindWorkloadCluster.Namespace, + }, + ), + } + + depls := &appsv1.DeploymentList{} + err = k8sClient.List(context.TODO(), depls, listOptions...) + if err != nil { + return false + } + if len(depls.Items) != 1 { + return false + } + return *depls.Items[0].Spec.Replicas == depls.Items[0].Status.ReadyReplicas + }, timeout, pollingInterval).Should(BeTrue()) + } else { + Byf("Verifying drift detection manager deployment is created in the workload cluster") + Eventually(func() bool { + depl := &appsv1.Deployment{} + err = workloadClient.Get(context.TODO(), + types.NamespacedName{Namespace: "projectsveltos", Name: "drift-detection-manager"}, depl) + if err != nil { + return false + } + return *depl.Spec.Replicas == depl.Status.ReadyReplicas + }, timeout, pollingInterval).Should(BeTrue()) + } Byf("Verifying ClusterSummary %s status is set to Deployed for Helm feature", clusterSummary.Name) verifyFeatureStatusIsProvisioned(kindWorkloadCluster.Namespace, clusterSummary.Name, configv1alpha1.FeatureHelm) @@ -171,3 +197,22 @@ var _ = Describe("Helm", Serial, func() { }, timeout, pollingInterval).Should(BeTrue()) }) }) + +func isAgentLessMode() bool { + By("Getting addon-controller pod") + addonControllerDepl := &appsv1.Deployment{} + Expect(k8sClient.Get(context.TODO(), + types.NamespacedName{Namespace: "projectsveltos", Name: "addon-controller"}, + addonControllerDepl)).To(Succeed()) + + Expect(len(addonControllerDepl.Spec.Template.Spec.Containers)).To(Equal(1)) + + for i := range addonControllerDepl.Spec.Template.Spec.Containers[0].Args { + if strings.Contains(addonControllerDepl.Spec.Template.Spec.Containers[0].Args[i], "agent-in-mgmt-cluster") { + By("Addon-controller in agentless mode") + return true + } + } + + return false +} From c2005a0538dc7baf5158439b86c45e7cff8028ab Mon Sep 17 00:00:00 2001 From: mgianluc Date: Mon, 25 Mar 2024 14:43:05 +0100 Subject: [PATCH 03/10] Watchers - ClusterProfile watches and reacts only to ClusterSet instances changes - Profile watches and reacts only to Set instances changes --- controllers/clusterprofile_controller.go | 10 ---------- controllers/profile_controller.go | 10 ---------- 2 files changed, 20 deletions(-) diff --git a/controllers/clusterprofile_controller.go b/controllers/clusterprofile_controller.go index 89138f90..1a070ec7 100644 --- a/controllers/clusterprofile_controller.go +++ b/controllers/clusterprofile_controller.go @@ -232,16 +232,6 @@ func (r *ClusterProfileReconciler) SetupWithManager(mgr ctrl.Manager) error { return err } - // When Set changes, according to SetPredicates, - // one or more ClusterProfiles need to be reconciled. - err = c.Watch(source.Kind(mgr.GetCache(), &libsveltosv1alpha1.Set{}), - handler.EnqueueRequestsFromMapFunc(r.requeueClusterProfileForCluster), - SetPredicates(mgr.GetLogger().WithValues("predicate", "setpredicate")), - ) - if err != nil { - return err - } - // At this point we don't know yet whether CAPI is present in the cluster. // Later on, in main, we detect that and if CAPI is present WatchForCAPI will be invoked. diff --git a/controllers/profile_controller.go b/controllers/profile_controller.go index 58ffbf82..1a120307 100644 --- a/controllers/profile_controller.go +++ b/controllers/profile_controller.go @@ -240,16 +240,6 @@ func (r *ProfileReconciler) SetupWithManager(mgr ctrl.Manager) error { return err } - // When ClusterSet changes, according to SetPredicates, - // one or more ClusterProfiles need to be reconciled. - err = c.Watch(source.Kind(mgr.GetCache(), &libsveltosv1alpha1.ClusterSet{}), - handler.EnqueueRequestsFromMapFunc(r.requeueProfileForSet), - SetPredicates(mgr.GetLogger().WithValues("predicate", "clustersetpredicate")), - ) - if err != nil { - return err - } - // When Set changes, according to SetPredicates, // one or more ClusterProfiles need to be reconciled. err = c.Watch(source.Kind(mgr.GetCache(), &libsveltosv1alpha1.Set{}), From effae87995062c3b9500afe47f2c8710f6430e89 Mon Sep 17 00:00:00 2001 From: mgianluc Date: Tue, 26 Mar 2024 12:08:22 +0100 Subject: [PATCH 04/10] Use reconciler logger in transformation functions --- cmd/main.go | 5 ++++ controllers/clusterprofile_controller.go | 1 + controllers/clusterprofile_transformations.go | 28 +++++++++---------- controllers/clusterset_controller.go | 2 ++ controllers/clusterset_transformations.go | 2 +- controllers/clustersummary_controller.go | 1 + controllers/clustersummary_transformations.go | 7 ++--- controllers/profile_controller.go | 1 + controllers/profile_transformation_common.go | 13 ++++----- controllers/profile_transformations.go | 6 ++-- controllers/set_controller.go | 2 ++ controllers/set_transformations.go | 2 +- controllers/set_utils.go | 8 +++--- 13 files changed, 44 insertions(+), 34 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index b66bb5c0..b6c10243 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -379,6 +379,7 @@ func getProfileReconciler(mgr manager.Manager) *controllers.ProfileReconciler { ClusterLabels: make(map[corev1.ObjectReference]map[string]string), Mux: sync.Mutex{}, ConcurrentReconciles: concurrentReconciles, + Logger: ctrl.Log.WithName("profilereconciler"), } } @@ -393,6 +394,7 @@ func getClusterProfileReconciler(mgr manager.Manager) *controllers.ClusterProfil ClusterLabels: make(map[corev1.ObjectReference]map[string]string), Mux: sync.Mutex{}, ConcurrentReconciles: concurrentReconciles, + Logger: ctrl.Log.WithName("clusterprofilereconciler"), } } @@ -413,6 +415,7 @@ func getClusterSummaryReconciler(ctx context.Context, mgr manager.Manager) *cont ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), PolicyMux: sync.Mutex{}, ConcurrentReconciles: concurrentReconciles, + Logger: ctrl.Log.WithName("clustersummaryreconciler"), } } @@ -426,6 +429,7 @@ func getSetReconciler(mgr manager.Manager) *controllers.SetReconciler { SetMap: make(map[corev1.ObjectReference]*libsveltosset.Set), Sets: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), ClusterLabels: make(map[corev1.ObjectReference]map[string]string), + Logger: ctrl.Log.WithName("setreconciler"), } } @@ -439,6 +443,7 @@ func getClusterSetReconciler(mgr manager.Manager) *controllers.ClusterSetReconci ClusterSetMap: make(map[corev1.ObjectReference]*libsveltosset.Set), ClusterSets: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), ClusterLabels: make(map[corev1.ObjectReference]map[string]string), + Logger: ctrl.Log.WithName("clustersetreconciler"), } } diff --git a/controllers/clusterprofile_controller.go b/controllers/clusterprofile_controller.go index 1a070ec7..df31fb47 100644 --- a/controllers/clusterprofile_controller.go +++ b/controllers/clusterprofile_controller.go @@ -48,6 +48,7 @@ type ClusterProfileReconciler struct { client.Client Scheme *runtime.Scheme ConcurrentReconciles int + Logger logr.Logger // use a Mutex to update Map as MaxConcurrentReconciles is higher than one Mux sync.Mutex diff --git a/controllers/clusterprofile_transformations.go b/controllers/clusterprofile_transformations.go index bc4e0a7e..3356e4ee 100644 --- a/controllers/clusterprofile_transformations.go +++ b/controllers/clusterprofile_transformations.go @@ -26,44 +26,44 @@ import ( configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" ) -func (r *ClusterProfileReconciler) requeueClusterProfileForCluster( +func (r *ClusterProfileReconciler) requeueClusterProfileForClusterSet( ctx context.Context, o client.Object, ) []reconcile.Request { - cluster := o + clusterSet := o r.Mux.Lock() defer r.Mux.Unlock() - addTypeInformationToObject(r.Scheme, cluster) + addTypeInformationToObject(r.Scheme, clusterSet) - return requeueForCluster(cluster, r.ClusterProfiles, r.ClusterLabels, r.ClusterMap, configv1alpha1.ClusterProfileKind) + return requeueForSet(clusterSet, r.ClusterSetMap, configv1alpha1.ClusterProfileKind, r.Logger) } -func (r *ClusterProfileReconciler) requeueClusterProfileForMachine( +func (r *ClusterProfileReconciler) requeueClusterProfileForCluster( ctx context.Context, o client.Object, ) []reconcile.Request { - machine := o.(*clusterv1.Machine) - - addTypeInformationToObject(r.Scheme, machine) + cluster := o r.Mux.Lock() defer r.Mux.Unlock() - return requeueForMachine(machine, r.ClusterProfiles, r.ClusterLabels, r.ClusterMap, configv1alpha1.ClusterProfileKind) + addTypeInformationToObject(r.Scheme, cluster) + + return requeueForCluster(cluster, r.ClusterProfiles, r.ClusterLabels, r.ClusterMap, configv1alpha1.ClusterProfileKind, r.Logger) } -func (r *ClusterProfileReconciler) requeueClusterProfileForClusterSet( +func (r *ClusterProfileReconciler) requeueClusterProfileForMachine( ctx context.Context, o client.Object, ) []reconcile.Request { - clusterSet := o + machine := o.(*clusterv1.Machine) + + addTypeInformationToObject(r.Scheme, machine) r.Mux.Lock() defer r.Mux.Unlock() - addTypeInformationToObject(r.Scheme, clusterSet) - - return requeueForSet(clusterSet, r.ClusterSetMap, configv1alpha1.ClusterProfileKind) + return requeueForMachine(machine, r.ClusterProfiles, r.ClusterLabels, r.ClusterMap, configv1alpha1.ClusterProfileKind, r.Logger) } diff --git a/controllers/clusterset_controller.go b/controllers/clusterset_controller.go index f93ea713..4d68a0cd 100644 --- a/controllers/clusterset_controller.go +++ b/controllers/clusterset_controller.go @@ -20,6 +20,7 @@ import ( "context" "sync" + "github.com/go-logr/logr" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -43,6 +44,7 @@ type ClusterSetReconciler struct { client.Client Scheme *runtime.Scheme ConcurrentReconciles int + Logger logr.Logger // use a Mutex to update Map as MaxConcurrentReconciles is higher than one Mux sync.Mutex diff --git a/controllers/clusterset_transformations.go b/controllers/clusterset_transformations.go index 2ac04267..885a2f42 100644 --- a/controllers/clusterset_transformations.go +++ b/controllers/clusterset_transformations.go @@ -36,5 +36,5 @@ func (r *ClusterSetReconciler) requeueClusterSetForCluster( addTypeInformationToObject(r.Scheme, cluster) - return requeueForCluster(cluster, r.ClusterSets, r.ClusterLabels, r.ClusterMap, libsveltosv1alpha1.ClusterSetKind) + return requeueForCluster(cluster, r.ClusterSets, r.ClusterLabels, r.ClusterMap, libsveltosv1alpha1.ClusterSetKind, r.Logger) } diff --git a/controllers/clustersummary_controller.go b/controllers/clustersummary_controller.go index 7bff63d0..98ee8d94 100644 --- a/controllers/clustersummary_controller.go +++ b/controllers/clustersummary_controller.go @@ -82,6 +82,7 @@ type ClusterSummaryReconciler struct { *rest.Config client.Client Scheme *runtime.Scheme + Logger logr.Logger ReportMode ReportMode AgentInMgmtCluster bool // if true, indicates drift-detection-manager needs to be started in the management cluster ShardKey string // when set, only clusters matching the ShardKey will be reconciled diff --git a/controllers/clustersummary_transformations.go b/controllers/clustersummary_transformations.go index 2d07712b..486a44b7 100644 --- a/controllers/clustersummary_transformations.go +++ b/controllers/clustersummary_transformations.go @@ -21,7 +21,6 @@ import ( "fmt" corev1 "k8s.io/api/core/v1" - "k8s.io/klog/v2/textlogger" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -37,7 +36,7 @@ func (r *ClusterSummaryReconciler) requeueClusterSummaryForFluxSource( ctx context.Context, o client.Object, ) []reconcile.Request { - logger := textlogger.NewLogger(textlogger.NewConfig()).WithValues( + logger := r.Logger.WithValues( "objectMapper", "requeueClusterSummaryForFluxSources", "reference", @@ -104,7 +103,7 @@ func (r *ClusterSummaryReconciler) requeueClusterSummaryForReference( ctx context.Context, o client.Object, ) []reconcile.Request { - logger := textlogger.NewLogger(textlogger.NewConfig()).WithValues( + logger := r.Logger.WithValues( "objectMapper", "requeueClusterSummaryForConfigMap", "reference", @@ -167,7 +166,7 @@ func (r *ClusterSummaryReconciler) requeueClusterSummaryForCluster( ) []reconcile.Request { cluster := o - logger := textlogger.NewLogger(textlogger.NewConfig()).WithValues( + logger := r.Logger.WithValues( "objectMapper", "requeueClusterSummaryForCluster", "namespace", diff --git a/controllers/profile_controller.go b/controllers/profile_controller.go index 1a120307..5414f21f 100644 --- a/controllers/profile_controller.go +++ b/controllers/profile_controller.go @@ -49,6 +49,7 @@ type ProfileReconciler struct { client.Client Scheme *runtime.Scheme ConcurrentReconciles int + Logger logr.Logger // use a Mutex to update Map as MaxConcurrentReconciles is higher than one Mux sync.Mutex diff --git a/controllers/profile_transformation_common.go b/controllers/profile_transformation_common.go index 22da1f21..4bc3da1e 100644 --- a/controllers/profile_transformation_common.go +++ b/controllers/profile_transformation_common.go @@ -21,12 +21,13 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/labels" - "k8s.io/klog/v2/textlogger" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/reconcile" + "github.com/go-logr/logr" + libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" libsveltosset "github.com/projectsveltos/libsveltos/lib/set" @@ -36,10 +37,9 @@ func requeueForCluster(cluster client.Object, profileSelectors map[corev1.ObjectReference]libsveltosv1alpha1.Selector, clusterLabels map[corev1.ObjectReference]map[string]string, clusterMap map[corev1.ObjectReference]*libsveltosset.Set, - kindType string) []reconcile.Request { + kindType string, logger logr.Logger) []reconcile.Request { - logger := textlogger.NewLogger(textlogger.NewConfig(textlogger.Verbosity(logs.LogInfo))).WithValues( - "cluster", fmt.Sprintf("%s/%s", cluster.GetNamespace(), cluster.GetName())) + logger = logger.WithValues("cluster", fmt.Sprintf("%s/%s", cluster.GetNamespace(), cluster.GetName())) logger.V(logs.LogDebug).Info("reacting to Cluster change") apiVersion, kind := cluster.GetObjectKind().GroupVersionKind().ToAPIVersionAndKind() @@ -93,10 +93,9 @@ func requeueForMachine(machine client.Object, profileSelectors map[corev1.ObjectReference]libsveltosv1alpha1.Selector, clusterLabels map[corev1.ObjectReference]map[string]string, clusterMap map[corev1.ObjectReference]*libsveltosset.Set, - kind string) []reconcile.Request { + kind string, logger logr.Logger) []reconcile.Request { - logger := textlogger.NewLogger(textlogger.NewConfig(textlogger.Verbosity(logs.LogInfo))).WithValues( - "machine", fmt.Sprintf("%s/%s", machine.GetNamespace(), machine.GetName())) + logger = logger.WithValues("machine", fmt.Sprintf("%s/%s", machine.GetNamespace(), machine.GetName())) logger.V(logs.LogDebug).Info("reacting to CAPI Machine change") diff --git a/controllers/profile_transformations.go b/controllers/profile_transformations.go index d16757ee..e63fa31d 100644 --- a/controllers/profile_transformations.go +++ b/controllers/profile_transformations.go @@ -37,7 +37,7 @@ func (r *ProfileReconciler) requeueProfileForCluster( addTypeInformationToObject(r.Scheme, cluster) - return requeueForCluster(cluster, r.Profiles, r.ClusterLabels, r.ClusterMap, configv1alpha1.ProfileKind) + return requeueForCluster(cluster, r.Profiles, r.ClusterLabels, r.ClusterMap, configv1alpha1.ProfileKind, r.Logger) } func (r *ProfileReconciler) requeueProfileForMachine( @@ -51,7 +51,7 @@ func (r *ProfileReconciler) requeueProfileForMachine( r.Mux.Lock() defer r.Mux.Unlock() - return requeueForMachine(machine, r.Profiles, r.ClusterLabels, r.ClusterMap, configv1alpha1.ProfileKind) + return requeueForMachine(machine, r.Profiles, r.ClusterLabels, r.ClusterMap, configv1alpha1.ProfileKind, r.Logger) } func (r *ProfileReconciler) requeueProfileForSet( @@ -65,5 +65,5 @@ func (r *ProfileReconciler) requeueProfileForSet( addTypeInformationToObject(r.Scheme, set) - return requeueForSet(set, r.SetMap, configv1alpha1.ProfileKind) + return requeueForSet(set, r.SetMap, configv1alpha1.ProfileKind, r.Logger) } diff --git a/controllers/set_controller.go b/controllers/set_controller.go index ba2a002e..2d650ac7 100644 --- a/controllers/set_controller.go +++ b/controllers/set_controller.go @@ -31,6 +31,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" + "github.com/go-logr/logr" "github.com/pkg/errors" "github.com/projectsveltos/addon-controller/pkg/scope" @@ -44,6 +45,7 @@ type SetReconciler struct { client.Client Scheme *runtime.Scheme ConcurrentReconciles int + Logger logr.Logger // use a Mutex to update Map as MaxConcurrentReconciles is higher than one Mux sync.Mutex diff --git a/controllers/set_transformations.go b/controllers/set_transformations.go index ebdf46c0..b6f72bbf 100644 --- a/controllers/set_transformations.go +++ b/controllers/set_transformations.go @@ -36,5 +36,5 @@ func (r *SetReconciler) requeueSetForCluster( addTypeInformationToObject(r.Scheme, cluster) - return requeueForCluster(cluster, r.Sets, r.ClusterLabels, r.ClusterMap, libsveltosv1alpha1.SetKind) + return requeueForCluster(cluster, r.Sets, r.ClusterLabels, r.ClusterMap, libsveltosv1alpha1.SetKind, r.Logger) } diff --git a/controllers/set_utils.go b/controllers/set_utils.go index 59d5422d..a0dc116e 100644 --- a/controllers/set_utils.go +++ b/controllers/set_utils.go @@ -20,11 +20,12 @@ import ( "fmt" corev1 "k8s.io/api/core/v1" - "k8s.io/klog/v2/textlogger" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/reconcile" + "github.com/go-logr/logr" + "github.com/projectsveltos/addon-controller/pkg/scope" logs "github.com/projectsveltos/libsveltos/lib/logsettings" libsveltosset "github.com/projectsveltos/libsveltos/lib/set" @@ -98,10 +99,9 @@ func selectMoreClusters(setScope *scope.SetScope) { func requeueForSet(set client.Object, setMap map[corev1.ObjectReference]*libsveltosset.Set, - kindType string) []reconcile.Request { + kindType string, logger logr.Logger) []reconcile.Request { - logger := textlogger.NewLogger(textlogger.NewConfig(textlogger.Verbosity(logs.LogInfo))).WithValues( - "set", fmt.Sprintf("%s/%s", set.GetNamespace(), set.GetName())) + logger = logger.WithValues("set", fmt.Sprintf("%s/%s", set.GetNamespace(), set.GetName())) logger.V(logs.LogDebug).Info("reacting to (Cluster)Set change") apiVersion, kind := set.GetObjectKind().GroupVersionKind().ToAPIVersionAndKind() From c9a48b89832ab27624b35c5a4bccc17dc329338d Mon Sep 17 00:00:00 2001 From: mgianluc Date: Tue, 26 Mar 2024 12:48:24 +0100 Subject: [PATCH 05/10] Update ClusterProfile/Profile spec SetRefs is now defined as ```yaml // SetRefs identifies referenced (cluster)Sets. // - ClusterProfile can reference ClusterSet; // - Profile can reference Set; // +optional SetRefs []string `json:"setRefs,omitempty"` ``` - In the context of a ClusterProfile is a slice with ClusterSet's names. - In the context of a Profile is a slice with Set's names (namespace is implicitly the Profile namespace). --- api/v1alpha1/spec.go | 2 +- api/v1alpha1/zz_generated.deepcopy.go | 2 +- ...fig.projectsveltos.io_clusterprofiles.yaml | 61 +----- ...ig.projectsveltos.io_clustersummaries.yaml | 61 +----- .../config.projectsveltos.io_profiles.yaml | 61 +----- controllers/clusterprofile_controller.go | 9 +- controllers/clusterprofile_controller_test.go | 14 +- controllers/profile_controller.go | 14 +- controllers/profile_controller_test.go | 18 +- manifest/manifest.yaml | 183 +----------------- pkg/scope/clusterprofile.go | 5 + test/fv/reference_clusterset_test.go | 8 +- 12 files changed, 30 insertions(+), 408 deletions(-) diff --git a/api/v1alpha1/spec.go b/api/v1alpha1/spec.go index b89c761d..aedbbda4 100644 --- a/api/v1alpha1/spec.go +++ b/api/v1alpha1/spec.go @@ -352,7 +352,7 @@ type Spec struct { // - ClusterProfile can reference ClusterSet; // - Profile can reference Set; // +optional - SetRefs []corev1.ObjectReference `json:"setRefs,omitempty"` + SetRefs []string `json:"setRefs,omitempty"` // SyncMode specifies how features are synced in a matching workload cluster. // - OneTime means, first time a workload cluster matches the ClusterProfile, diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 9c1e155a..0300dc21 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -779,7 +779,7 @@ func (in *Spec) DeepCopyInto(out *Spec) { } if in.SetRefs != nil { in, out := &in.SetRefs, &out.SetRefs - *out = make([]corev1.ObjectReference, len(*in)) + *out = make([]string, len(*in)) copy(*out, *in) } if in.MaxUpdate != nil { diff --git a/config/crd/bases/config.projectsveltos.io_clusterprofiles.yaml b/config/crd/bases/config.projectsveltos.io_clusterprofiles.yaml index f29f3838..1bca6acc 100644 --- a/config/crd/bases/config.projectsveltos.io_clusterprofiles.yaml +++ b/config/crd/bases/config.projectsveltos.io_clusterprofiles.yaml @@ -387,66 +387,7 @@ spec: - ClusterProfile can reference ClusterSet; - Profile can reference Set; items: - description: |- - ObjectReference contains enough information to let you inspect or modify the referred object. - --- - New uses of this type are discouraged because of difficulty describing its usage when embedded in APIs. - 1. Ignored fields. It includes many fields which are not generally honored. For instance, ResourceVersion and FieldPath are both very rarely valid in actual usage. - 2. Invalid usage help. It is impossible to add specific help for individual usage. In most embedded usages, there are particular - restrictions like, "must refer only to types A and B" or "UID not honored" or "name must be restricted". - Those cannot be well described when embedded. - 3. Inconsistent validation. Because the usages are different, the validation rules are different by usage, which makes it hard for users to predict what will happen. - 4. The fields are both imprecise and overly precise. Kind is not a precise mapping to a URL. This can produce ambiguity - during interpretation and require a REST mapping. In most cases, the dependency is on the group,resource tuple - and the version of the actual struct is irrelevant. - 5. We cannot easily change it. Because this type is embedded in many locations, updates to this type - will affect numerous schemas. Don't make new APIs embed an underspecified API type they do not control. - - - Instead of using this type, create a locally provided and used type that is well-focused on your reference. - For example, ServiceReferences for admission registration: https://github.com/kubernetes/api/blob/release-1.17/admissionregistration/v1/types.go#L533 . - properties: - apiVersion: - description: API version of the referent. - type: string - fieldPath: - description: |- - If referring to a piece of an object instead of an entire object, this string - should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. - For example, if the object reference is to a container within a pod, this would take on a value like: - "spec.containers{name}" (where "name" refers to the name of the container that triggered - the event) or if no container name is specified "spec.containers[2]" (container with - index 2 in this pod). This syntax is chosen only to have some well-defined way of - referencing a part of an object. - TODO: this design is not final and this field is subject to change in the future. - type: string - kind: - description: |- - Kind of the referent. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - name: - description: |- - Name of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - type: string - namespace: - description: |- - Namespace of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ - type: string - resourceVersion: - description: |- - Specific resourceVersion to which this reference is made, if any. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency - type: string - uid: - description: |- - UID of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids - type: string - type: object - x-kubernetes-map-type: atomic + type: string type: array stopMatchingBehavior: default: WithdrawPolicies diff --git a/config/crd/bases/config.projectsveltos.io_clustersummaries.yaml b/config/crd/bases/config.projectsveltos.io_clustersummaries.yaml index 1fa709f7..aaf1fc62 100644 --- a/config/crd/bases/config.projectsveltos.io_clustersummaries.yaml +++ b/config/crd/bases/config.projectsveltos.io_clustersummaries.yaml @@ -403,66 +403,7 @@ spec: - ClusterProfile can reference ClusterSet; - Profile can reference Set; items: - description: |- - ObjectReference contains enough information to let you inspect or modify the referred object. - --- - New uses of this type are discouraged because of difficulty describing its usage when embedded in APIs. - 1. Ignored fields. It includes many fields which are not generally honored. For instance, ResourceVersion and FieldPath are both very rarely valid in actual usage. - 2. Invalid usage help. It is impossible to add specific help for individual usage. In most embedded usages, there are particular - restrictions like, "must refer only to types A and B" or "UID not honored" or "name must be restricted". - Those cannot be well described when embedded. - 3. Inconsistent validation. Because the usages are different, the validation rules are different by usage, which makes it hard for users to predict what will happen. - 4. The fields are both imprecise and overly precise. Kind is not a precise mapping to a URL. This can produce ambiguity - during interpretation and require a REST mapping. In most cases, the dependency is on the group,resource tuple - and the version of the actual struct is irrelevant. - 5. We cannot easily change it. Because this type is embedded in many locations, updates to this type - will affect numerous schemas. Don't make new APIs embed an underspecified API type they do not control. - - - Instead of using this type, create a locally provided and used type that is well-focused on your reference. - For example, ServiceReferences for admission registration: https://github.com/kubernetes/api/blob/release-1.17/admissionregistration/v1/types.go#L533 . - properties: - apiVersion: - description: API version of the referent. - type: string - fieldPath: - description: |- - If referring to a piece of an object instead of an entire object, this string - should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. - For example, if the object reference is to a container within a pod, this would take on a value like: - "spec.containers{name}" (where "name" refers to the name of the container that triggered - the event) or if no container name is specified "spec.containers[2]" (container with - index 2 in this pod). This syntax is chosen only to have some well-defined way of - referencing a part of an object. - TODO: this design is not final and this field is subject to change in the future. - type: string - kind: - description: |- - Kind of the referent. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - name: - description: |- - Name of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - type: string - namespace: - description: |- - Namespace of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ - type: string - resourceVersion: - description: |- - Specific resourceVersion to which this reference is made, if any. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency - type: string - uid: - description: |- - UID of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids - type: string - type: object - x-kubernetes-map-type: atomic + type: string type: array stopMatchingBehavior: default: WithdrawPolicies diff --git a/config/crd/bases/config.projectsveltos.io_profiles.yaml b/config/crd/bases/config.projectsveltos.io_profiles.yaml index eaa2b4cd..e2f538da 100644 --- a/config/crd/bases/config.projectsveltos.io_profiles.yaml +++ b/config/crd/bases/config.projectsveltos.io_profiles.yaml @@ -387,66 +387,7 @@ spec: - ClusterProfile can reference ClusterSet; - Profile can reference Set; items: - description: |- - ObjectReference contains enough information to let you inspect or modify the referred object. - --- - New uses of this type are discouraged because of difficulty describing its usage when embedded in APIs. - 1. Ignored fields. It includes many fields which are not generally honored. For instance, ResourceVersion and FieldPath are both very rarely valid in actual usage. - 2. Invalid usage help. It is impossible to add specific help for individual usage. In most embedded usages, there are particular - restrictions like, "must refer only to types A and B" or "UID not honored" or "name must be restricted". - Those cannot be well described when embedded. - 3. Inconsistent validation. Because the usages are different, the validation rules are different by usage, which makes it hard for users to predict what will happen. - 4. The fields are both imprecise and overly precise. Kind is not a precise mapping to a URL. This can produce ambiguity - during interpretation and require a REST mapping. In most cases, the dependency is on the group,resource tuple - and the version of the actual struct is irrelevant. - 5. We cannot easily change it. Because this type is embedded in many locations, updates to this type - will affect numerous schemas. Don't make new APIs embed an underspecified API type they do not control. - - - Instead of using this type, create a locally provided and used type that is well-focused on your reference. - For example, ServiceReferences for admission registration: https://github.com/kubernetes/api/blob/release-1.17/admissionregistration/v1/types.go#L533 . - properties: - apiVersion: - description: API version of the referent. - type: string - fieldPath: - description: |- - If referring to a piece of an object instead of an entire object, this string - should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. - For example, if the object reference is to a container within a pod, this would take on a value like: - "spec.containers{name}" (where "name" refers to the name of the container that triggered - the event) or if no container name is specified "spec.containers[2]" (container with - index 2 in this pod). This syntax is chosen only to have some well-defined way of - referencing a part of an object. - TODO: this design is not final and this field is subject to change in the future. - type: string - kind: - description: |- - Kind of the referent. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - name: - description: |- - Name of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - type: string - namespace: - description: |- - Namespace of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ - type: string - resourceVersion: - description: |- - Specific resourceVersion to which this reference is made, if any. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency - type: string - uid: - description: |- - UID of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids - type: string - type: object - x-kubernetes-map-type: atomic + type: string type: array stopMatchingBehavior: default: WithdrawPolicies diff --git a/controllers/clusterprofile_controller.go b/controllers/clusterprofile_controller.go index df31fb47..3847c506 100644 --- a/controllers/clusterprofile_controller.go +++ b/controllers/clusterprofile_controller.go @@ -324,7 +324,7 @@ func (r *ClusterProfileReconciler) updateMaps(profileScope *scope.ProfileScope) // For each referenced ClusterSet, add ClusterProfile as consumer for i := range profileScope.GetSpec().SetRefs { clusterSet := profileScope.GetSpec().SetRefs[i] - clusterSetInfo := &corev1.ObjectReference{Name: clusterSet.Name, + clusterSetInfo := &corev1.ObjectReference{Name: clusterSet, Kind: libsveltosv1alpha1.ClusterSetKind, APIVersion: libsveltosv1alpha1.GroupVersion.String()} getConsumersForEntry(r.ClusterSetMap, clusterSetInfo).Insert(clusterProfileInfo) } @@ -337,20 +337,19 @@ func (r *ClusterProfileReconciler) GetController() controller.Controller { return r.ctrl } -func (r *ClusterProfileReconciler) getClustersFromClusterSets(ctx context.Context, clusterSetRefs []corev1.ObjectReference, +func (r *ClusterProfileReconciler) getClustersFromClusterSets(ctx context.Context, clusterSetRefs []string, logger logr.Logger) ([]corev1.ObjectReference, error) { clusters := make([]corev1.ObjectReference, 0) for i := range clusterSetRefs { clusterSet := &libsveltosv1alpha1.ClusterSet{} if err := r.Client.Get(ctx, - types.NamespacedName{Name: clusterSetRefs[i].Name}, + types.NamespacedName{Name: clusterSetRefs[i]}, clusterSet); err != nil { if apierrors.IsNotFound(err) { continue } - logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to get set %s/%s", - clusterSetRefs[i].Namespace, clusterSetRefs[i].Name)) + logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to get clusterSet %s", clusterSetRefs[i])) return nil, err } diff --git a/controllers/clusterprofile_controller_test.go b/controllers/clusterprofile_controller_test.go index 27a7c04d..0de1f5b6 100644 --- a/controllers/clusterprofile_controller_test.go +++ b/controllers/clusterprofile_controller_test.go @@ -133,17 +133,9 @@ var _ = Describe("Profile: Reconciler", func() { }, } - clusterProfile.Spec.SetRefs = []corev1.ObjectReference{ - { - Name: clusterSet1.Name, - Kind: libsveltosv1alpha1.ClusterSetKind, - APIVersion: libsveltosv1alpha1.GroupVersion.String(), - }, - { - Name: clusterSet2.Name, - Kind: libsveltosv1alpha1.ClusterSetKind, - APIVersion: libsveltosv1alpha1.GroupVersion.String(), - }, + clusterProfile.Spec.SetRefs = []string{ + clusterSet1.Name, + clusterSet2.Name, } initObjects := []client.Object{ diff --git a/controllers/profile_controller.go b/controllers/profile_controller.go index 5414f21f..896e1e93 100644 --- a/controllers/profile_controller.go +++ b/controllers/profile_controller.go @@ -199,7 +199,7 @@ func (r *ProfileReconciler) reconcileNormal( } // Get all clusters from referenced Sets - clusterSetClusters, err := r.getClustersFromSets(ctx, profileScope.GetSpec().SetRefs, logger) + clusterSetClusters, err := r.getClustersFromSets(ctx, profileScope.Namespace(), profileScope.GetSpec().SetRefs, logger) if err != nil { return reconcile.Result{Requeue: true, RequeueAfter: normalRequeueAfter} } @@ -288,10 +288,6 @@ func (r *ProfileReconciler) limitReferencesToNamespace(profile *configv1alpha1.P for i := range profile.Spec.KustomizationRefs { profile.Spec.KustomizationRefs[i].Namespace = profile.Namespace } - - for i := range profile.Spec.SetRefs { - profile.Spec.SetRefs[i].Namespace = profile.Namespace - } } func (r *ProfileReconciler) cleanMaps(profileScope *scope.ProfileScope) { @@ -349,7 +345,7 @@ func (r *ProfileReconciler) updateMaps(profileScope *scope.ProfileScope) { // For each referenced Set, add Profile as consumer for i := range profileScope.GetSpec().SetRefs { set := profileScope.GetSpec().SetRefs[i] - setInfo := &corev1.ObjectReference{Namespace: set.Namespace, Name: set.Name, + setInfo := &corev1.ObjectReference{Namespace: profileScope.Namespace(), Name: set, Kind: libsveltosv1alpha1.SetKind, APIVersion: libsveltosv1alpha1.GroupVersion.String()} getConsumersForEntry(r.SetMap, setInfo).Insert(profileInfo) } @@ -362,20 +358,20 @@ func (r *ProfileReconciler) GetController() controller.Controller { return r.ctrl } -func (r *ProfileReconciler) getClustersFromSets(ctx context.Context, setRefs []corev1.ObjectReference, +func (r *ProfileReconciler) getClustersFromSets(ctx context.Context, namespace string, setRefs []string, logger logr.Logger) ([]corev1.ObjectReference, error) { clusters := make([]corev1.ObjectReference, 0) for i := range setRefs { set := &libsveltosv1alpha1.Set{} if err := r.Client.Get(ctx, - types.NamespacedName{Namespace: setRefs[i].Namespace, Name: setRefs[i].Name}, + types.NamespacedName{Namespace: namespace, Name: setRefs[i]}, set); err != nil { if apierrors.IsNotFound(err) { continue } logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to get set %s/%s", - setRefs[i].Namespace, setRefs[i].Name)) + namespace, setRefs[i])) return nil, err } diff --git a/controllers/profile_controller_test.go b/controllers/profile_controller_test.go index 9c548750..beb8510c 100644 --- a/controllers/profile_controller_test.go +++ b/controllers/profile_controller_test.go @@ -172,19 +172,9 @@ var _ = Describe("Profile Controller", func() { }, } - profile.Spec.SetRefs = []corev1.ObjectReference{ - { - Namespace: profile.Namespace, - Name: set1.Name, - Kind: libsveltosv1alpha1.ClusterSetKind, - APIVersion: libsveltosv1alpha1.GroupVersion.String(), - }, - { - Namespace: profile.Namespace, - Name: set2.Name, - Kind: libsveltosv1alpha1.ClusterSetKind, - APIVersion: libsveltosv1alpha1.GroupVersion.String(), - }, + profile.Spec.SetRefs = []string{ + set1.Name, + set2.Name, } initObjects := []client.Object{ @@ -208,7 +198,7 @@ var _ = Describe("Profile Controller", func() { } clusters, err := controllers.GetClustersFromSets(reconciler, context.TODO(), - profile.Spec.SetRefs, logger) + profile.Namespace, profile.Spec.SetRefs, logger) Expect(err).To(BeNil()) Expect(clusters).ToNot(BeNil()) for i := range set1.Status.SelectedClusterRefs { diff --git a/manifest/manifest.yaml b/manifest/manifest.yaml index ed358d1e..5394e38b 100644 --- a/manifest/manifest.yaml +++ b/manifest/manifest.yaml @@ -764,66 +764,7 @@ spec: - ClusterProfile can reference ClusterSet; - Profile can reference Set; items: - description: |- - ObjectReference contains enough information to let you inspect or modify the referred object. - --- - New uses of this type are discouraged because of difficulty describing its usage when embedded in APIs. - 1. Ignored fields. It includes many fields which are not generally honored. For instance, ResourceVersion and FieldPath are both very rarely valid in actual usage. - 2. Invalid usage help. It is impossible to add specific help for individual usage. In most embedded usages, there are particular - restrictions like, "must refer only to types A and B" or "UID not honored" or "name must be restricted". - Those cannot be well described when embedded. - 3. Inconsistent validation. Because the usages are different, the validation rules are different by usage, which makes it hard for users to predict what will happen. - 4. The fields are both imprecise and overly precise. Kind is not a precise mapping to a URL. This can produce ambiguity - during interpretation and require a REST mapping. In most cases, the dependency is on the group,resource tuple - and the version of the actual struct is irrelevant. - 5. We cannot easily change it. Because this type is embedded in many locations, updates to this type - will affect numerous schemas. Don't make new APIs embed an underspecified API type they do not control. - - - Instead of using this type, create a locally provided and used type that is well-focused on your reference. - For example, ServiceReferences for admission registration: https://github.com/kubernetes/api/blob/release-1.17/admissionregistration/v1/types.go#L533 . - properties: - apiVersion: - description: API version of the referent. - type: string - fieldPath: - description: |- - If referring to a piece of an object instead of an entire object, this string - should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. - For example, if the object reference is to a container within a pod, this would take on a value like: - "spec.containers{name}" (where "name" refers to the name of the container that triggered - the event) or if no container name is specified "spec.containers[2]" (container with - index 2 in this pod). This syntax is chosen only to have some well-defined way of - referencing a part of an object. - TODO: this design is not final and this field is subject to change in the future. - type: string - kind: - description: |- - Kind of the referent. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - name: - description: |- - Name of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - type: string - namespace: - description: |- - Namespace of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ - type: string - resourceVersion: - description: |- - Specific resourceVersion to which this reference is made, if any. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency - type: string - uid: - description: |- - UID of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids - type: string - type: object - x-kubernetes-map-type: atomic + type: string type: array stopMatchingBehavior: default: WithdrawPolicies @@ -1949,66 +1890,7 @@ spec: - ClusterProfile can reference ClusterSet; - Profile can reference Set; items: - description: |- - ObjectReference contains enough information to let you inspect or modify the referred object. - --- - New uses of this type are discouraged because of difficulty describing its usage when embedded in APIs. - 1. Ignored fields. It includes many fields which are not generally honored. For instance, ResourceVersion and FieldPath are both very rarely valid in actual usage. - 2. Invalid usage help. It is impossible to add specific help for individual usage. In most embedded usages, there are particular - restrictions like, "must refer only to types A and B" or "UID not honored" or "name must be restricted". - Those cannot be well described when embedded. - 3. Inconsistent validation. Because the usages are different, the validation rules are different by usage, which makes it hard for users to predict what will happen. - 4. The fields are both imprecise and overly precise. Kind is not a precise mapping to a URL. This can produce ambiguity - during interpretation and require a REST mapping. In most cases, the dependency is on the group,resource tuple - and the version of the actual struct is irrelevant. - 5. We cannot easily change it. Because this type is embedded in many locations, updates to this type - will affect numerous schemas. Don't make new APIs embed an underspecified API type they do not control. - - - Instead of using this type, create a locally provided and used type that is well-focused on your reference. - For example, ServiceReferences for admission registration: https://github.com/kubernetes/api/blob/release-1.17/admissionregistration/v1/types.go#L533 . - properties: - apiVersion: - description: API version of the referent. - type: string - fieldPath: - description: |- - If referring to a piece of an object instead of an entire object, this string - should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. - For example, if the object reference is to a container within a pod, this would take on a value like: - "spec.containers{name}" (where "name" refers to the name of the container that triggered - the event) or if no container name is specified "spec.containers[2]" (container with - index 2 in this pod). This syntax is chosen only to have some well-defined way of - referencing a part of an object. - TODO: this design is not final and this field is subject to change in the future. - type: string - kind: - description: |- - Kind of the referent. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - name: - description: |- - Name of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - type: string - namespace: - description: |- - Namespace of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ - type: string - resourceVersion: - description: |- - Specific resourceVersion to which this reference is made, if any. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency - type: string - uid: - description: |- - UID of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids - type: string - type: object - x-kubernetes-map-type: atomic + type: string type: array stopMatchingBehavior: default: WithdrawPolicies @@ -2692,66 +2574,7 @@ spec: - ClusterProfile can reference ClusterSet; - Profile can reference Set; items: - description: |- - ObjectReference contains enough information to let you inspect or modify the referred object. - --- - New uses of this type are discouraged because of difficulty describing its usage when embedded in APIs. - 1. Ignored fields. It includes many fields which are not generally honored. For instance, ResourceVersion and FieldPath are both very rarely valid in actual usage. - 2. Invalid usage help. It is impossible to add specific help for individual usage. In most embedded usages, there are particular - restrictions like, "must refer only to types A and B" or "UID not honored" or "name must be restricted". - Those cannot be well described when embedded. - 3. Inconsistent validation. Because the usages are different, the validation rules are different by usage, which makes it hard for users to predict what will happen. - 4. The fields are both imprecise and overly precise. Kind is not a precise mapping to a URL. This can produce ambiguity - during interpretation and require a REST mapping. In most cases, the dependency is on the group,resource tuple - and the version of the actual struct is irrelevant. - 5. We cannot easily change it. Because this type is embedded in many locations, updates to this type - will affect numerous schemas. Don't make new APIs embed an underspecified API type they do not control. - - - Instead of using this type, create a locally provided and used type that is well-focused on your reference. - For example, ServiceReferences for admission registration: https://github.com/kubernetes/api/blob/release-1.17/admissionregistration/v1/types.go#L533 . - properties: - apiVersion: - description: API version of the referent. - type: string - fieldPath: - description: |- - If referring to a piece of an object instead of an entire object, this string - should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. - For example, if the object reference is to a container within a pod, this would take on a value like: - "spec.containers{name}" (where "name" refers to the name of the container that triggered - the event) or if no container name is specified "spec.containers[2]" (container with - index 2 in this pod). This syntax is chosen only to have some well-defined way of - referencing a part of an object. - TODO: this design is not final and this field is subject to change in the future. - type: string - kind: - description: |- - Kind of the referent. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - name: - description: |- - Name of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - type: string - namespace: - description: |- - Namespace of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ - type: string - resourceVersion: - description: |- - Specific resourceVersion to which this reference is made, if any. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency - type: string - uid: - description: |- - UID of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids - type: string - type: object - x-kubernetes-map-type: atomic + type: string type: array stopMatchingBehavior: default: WithdrawPolicies diff --git a/pkg/scope/clusterprofile.go b/pkg/scope/clusterprofile.go index ca6eb45a..ad14b443 100644 --- a/pkg/scope/clusterprofile.go +++ b/pkg/scope/clusterprofile.go @@ -88,6 +88,11 @@ func (s *ProfileScope) Close(ctx context.Context) error { return s.PatchObject(ctx) } +// Namespace returns the Profile namespace. +func (s *ProfileScope) Namespace() string { + return s.Profile.GetNamespace() +} + // Name returns the Profile name. func (s *ProfileScope) Name() string { return s.Profile.GetName() diff --git a/test/fv/reference_clusterset_test.go b/test/fv/reference_clusterset_test.go index 555d29dc..a72c8e03 100644 --- a/test/fv/reference_clusterset_test.go +++ b/test/fv/reference_clusterset_test.go @@ -60,13 +60,7 @@ var _ = Describe("ClusterSet", func() { Byf("Creating ClusterProfile referencing ClusterSet") clusterProfile := getClusterProfile(namePrefix, map[string]string{key: value}) clusterProfile.Spec.ClusterSelector = "" - clusterProfile.Spec.SetRefs = []corev1.ObjectReference{ - { - Kind: libsveltosv1alpha1.ClusterSetKind, - APIVersion: libsveltosv1alpha1.GroupVersion.String(), - Name: clusterSet.Name, - }, - } + clusterProfile.Spec.SetRefs = []string{clusterSet.Name} clusterProfile.Spec.SyncMode = configv1alpha1.SyncModeContinuous Expect(k8sClient.Create(context.TODO(), clusterProfile)).To(Succeed()) From dab52735ba68ee2a300bd690e54058f456eedb62 Mon Sep 17 00:00:00 2001 From: mgianluc Date: Tue, 26 Mar 2024 15:52:42 +0100 Subject: [PATCH 06/10] Optmize internal structures for better memory usage --- cmd/main.go | 3 - controllers/clusterprofile_controller.go | 50 +---- controllers/clusterprofile_controller_test.go | 39 ++-- .../clusterprofile_transformations_test.go | 26 +-- controllers/clustersummary_controller.go | 59 +---- controllers/clustersummary_controller_test.go | 208 ++++++++---------- .../clustersummary_transformations_test.go | 11 +- controllers/controllers_suite_test.go | 28 +-- controllers/profile_controller.go | 25 +-- controllers/profile_controller_test.go | 2 - controllers/profile_transformation_common.go | 8 +- controllers/profile_transformations_test.go | 72 ++---- 12 files changed, 195 insertions(+), 336 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index b6c10243..8aaf7d86 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -374,7 +374,6 @@ func getProfileReconciler(mgr manager.Manager) *controllers.ProfileReconciler { Scheme: mgr.GetScheme(), SetMap: make(map[corev1.ObjectReference]*libsveltosset.Set), ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ProfileMap: make(map[corev1.ObjectReference]*libsveltosset.Set), Profiles: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), ClusterLabels: make(map[corev1.ObjectReference]map[string]string), Mux: sync.Mutex{}, @@ -389,7 +388,6 @@ func getClusterProfileReconciler(mgr manager.Manager) *controllers.ClusterProfil Scheme: mgr.GetScheme(), ClusterSetMap: make(map[corev1.ObjectReference]*libsveltosset.Set), ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterProfileMap: make(map[corev1.ObjectReference]*libsveltosset.Set), ClusterProfiles: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), ClusterLabels: make(map[corev1.ObjectReference]map[string]string), Mux: sync.Mutex{}, @@ -412,7 +410,6 @@ func getClusterSummaryReconciler(ctx context.Context, mgr manager.Manager) *cont Deployer: d, ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), PolicyMux: sync.Mutex{}, ConcurrentReconciles: concurrentReconciles, Logger: ctrl.Log.WithName("clustersummaryreconciler"), diff --git a/controllers/clusterprofile_controller.go b/controllers/clusterprofile_controller.go index 3847c506..f6a4c603 100644 --- a/controllers/clusterprofile_controller.go +++ b/controllers/clusterprofile_controller.go @@ -58,8 +58,7 @@ type ClusterProfileReconciler struct { // key: Sveltos/Cluster; value: set of all ClusterProfiles matching the Cluster ClusterMap map[corev1.ObjectReference]*libsveltosset.Set - // key: ClusterProfile; value: set of Sveltos/CAPI Clusters matched - ClusterProfileMap map[corev1.ObjectReference]*libsveltosset.Set + // key: ClusterProfile; value ClusterProfile Selector ClusterProfiles map[corev1.ObjectReference]libsveltosv1alpha1.Selector @@ -71,31 +70,6 @@ type ClusterProfileReconciler struct { // we need Cluster labels to know which ClusterProfile to reconcile ClusterLabels map[corev1.ObjectReference]map[string]string - // Reason for the two maps: - // ClusterProfile, via ClusterSelector, matches Sveltos/CAPI Clusters based on Cluster labels. - // When a Sveltos/Cluster labels change, one or more ClusterProfile needs to be reconciled. - // In order to achieve so, ClusterProfile reconciler watches for Sveltos/CAPI Clusters. When a Sveltos/Cluster - // label changes, find all the ClusterProfiles currently referencing it and reconcile those. - // Problem is no I/O should be present inside a MapFunc (given a Sveltos/Cluster, return all the ClusterProfiles matching it). - // In the MapFunc, if the list ClusterProfiles operation failed, we would be unable to retry or re-enqueue the rigth set of - // ClusterProfiles. - // Instead the approach taken is following: - // - when a ClusterProfile is reconciled, update the ClusterProfiles amd the ClusterMap; - // - in the MapFunc, given the Sveltos/Cluster that changed: - // * use ClusterProfiles to find all ClusterProfile matching the Cluster and reconcile those; - // - in order to reconcile ClusterProfiles previously matching the Cluster and not anymore, use ClusterMap. - // - // The ClusterProfileMap is used to update ClusterMap. Consider following scenarios to understand the need: - // 1. ClusterProfile A references Clusters 1 and 2. When reconciled, ClusterMap will have 1 => A and 2 => A; - // and ClusterProfileMap A => 1,2 - // 2. Cluster 2 label changes and now ClusterProfile matches Cluster 1 only. We ned to remove the entry 2 => A in ClusterMap. But - // when we reconcile ClusterProfile we have its current version we don't have its previous version. So we know ClusterProfile A - // now matches Sveltos/Cluster 1, but we don't know it used to match Sveltos/Cluster 2. - // So we use ClusterProfileMap (at this point value stored here corresponds to reconciliation #1. We know currently - // ClusterProfile matches Sveltos/Cluster 1 only and looking at ClusterProfileMap we know it used to reference - // Svetos/CAPI Cluster 1 and 2. - // So we can remove 2 => A from ClusterMap. Only after this update, we update ClusterProfileMap (so new value will be A => 1) - ctrl controller.Controller } @@ -275,7 +249,6 @@ func (r *ClusterProfileReconciler) cleanMaps(profileScope *scope.ProfileScope) { clusterProfileInfo := getKeyFromObject(r.Scheme, profileScope.Profile) - delete(r.ClusterProfileMap, *clusterProfileInfo) delete(r.ClusterProfiles, *clusterProfileInfo) // ClusterMap contains for each cluster, list of ClusterProfiles matching @@ -294,17 +267,16 @@ func (r *ClusterProfileReconciler) cleanMaps(profileScope *scope.ProfileScope) { } func (r *ClusterProfileReconciler) updateMaps(profileScope *scope.ProfileScope) { - currentClusters := getCurrentClusterSet(profileScope.GetStatus().MatchingClusterRefs) - r.Mux.Lock() defer r.Mux.Unlock() clusterProfileInfo := getKeyFromObject(r.Scheme, profileScope.Profile) - // Get list of Clusters not matched anymore by ClusterProfile - var toBeRemoved []corev1.ObjectReference - if v, ok := r.ClusterProfileMap[*clusterProfileInfo]; ok { - toBeRemoved = v.Difference(currentClusters) + for k, l := range r.ClusterMap { + l.Erase(clusterProfileInfo) + if l.Len() == 0 { + delete(r.ClusterMap, k) + } } // For each currently matching Cluster, add ClusterProfile as consumer @@ -315,10 +287,11 @@ func (r *ClusterProfileReconciler) updateMaps(profileScope *scope.ProfileScope) getConsumersForEntry(r.ClusterMap, clusterInfo).Insert(clusterProfileInfo) } - // For each Cluster not matched anymore, remove ClusterProfile as consumer - for i := range toBeRemoved { - clusterName := toBeRemoved[i] - getConsumersForEntry(r.ClusterMap, &clusterName).Erase(clusterProfileInfo) + for k, l := range r.ClusterSetMap { + l.Erase(clusterProfileInfo) + if l.Len() == 0 { + delete(r.ClusterSetMap, k) + } } // For each referenced ClusterSet, add ClusterProfile as consumer @@ -329,7 +302,6 @@ func (r *ClusterProfileReconciler) updateMaps(profileScope *scope.ProfileScope) getConsumersForEntry(r.ClusterSetMap, clusterSetInfo).Insert(clusterProfileInfo) } - r.ClusterProfileMap[*clusterProfileInfo] = currentClusters r.ClusterProfiles[*clusterProfileInfo] = profileScope.GetSpec().ClusterSelector } diff --git a/controllers/clusterprofile_controller_test.go b/controllers/clusterprofile_controller_test.go index 0de1f5b6..a8cff61f 100644 --- a/controllers/clusterprofile_controller_test.go +++ b/controllers/clusterprofile_controller_test.go @@ -71,13 +71,12 @@ var _ = Describe("Profile: Reconciler", func() { WithObjects(initObjects...).Build() reconciler := &controllers.ClusterProfileReconciler{ - Client: c, - Scheme: scheme, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterProfileMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterProfiles: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), - ClusterLabels: make(map[corev1.ObjectReference]map[string]string), - Mux: sync.Mutex{}, + Client: c, + Scheme: scheme, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ClusterProfiles: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), + ClusterLabels: make(map[corev1.ObjectReference]map[string]string), + Mux: sync.Mutex{}, } clusterProfileName := client.ObjectKey{ @@ -148,13 +147,12 @@ var _ = Describe("Profile: Reconciler", func() { WithObjects(initObjects...).Build() reconciler := &controllers.ClusterProfileReconciler{ - Client: c, - Scheme: scheme, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterProfileMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterProfiles: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), - ClusterLabels: make(map[corev1.ObjectReference]map[string]string), - Mux: sync.Mutex{}, + Client: c, + Scheme: scheme, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ClusterProfiles: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), + ClusterLabels: make(map[corev1.ObjectReference]map[string]string), + Mux: sync.Mutex{}, } clusters, err := controllers.GetClustersFromClusterSets(reconciler, context.TODO(), @@ -206,13 +204,12 @@ var _ = Describe("Profile: Reconciler", func() { addOwnerReference(ctx, c, clusterSummary, clusterProfile) reconciler := &controllers.ClusterProfileReconciler{ - Client: c, - Scheme: scheme, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterProfileMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterProfiles: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), - ClusterLabels: make(map[corev1.ObjectReference]map[string]string), - Mux: sync.Mutex{}, + Client: c, + Scheme: scheme, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ClusterProfiles: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), + ClusterLabels: make(map[corev1.ObjectReference]map[string]string), + Mux: sync.Mutex{}, } clusterProfileName := client.ObjectKey{ diff --git a/controllers/clusterprofile_transformations_test.go b/controllers/clusterprofile_transformations_test.go index 1e4803cb..54d7f239 100644 --- a/controllers/clusterprofile_transformations_test.go +++ b/controllers/clusterprofile_transformations_test.go @@ -82,13 +82,12 @@ var _ = Describe("ClusterProfileReconciler map functions", func() { c := fake.NewClientBuilder().WithScheme(scheme).WithStatusSubresource(initObjects...).WithObjects(initObjects...).Build() reconciler := &controllers.ClusterProfileReconciler{ - Client: c, - Scheme: scheme, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterProfileMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterProfiles: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), - ClusterLabels: make(map[corev1.ObjectReference]map[string]string), - Mux: sync.Mutex{}, + Client: c, + Scheme: scheme, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ClusterProfiles: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), + ClusterLabels: make(map[corev1.ObjectReference]map[string]string), + Mux: sync.Mutex{}, } By("Setting ClusterProfileReconciler internal structures") @@ -103,14 +102,6 @@ var _ = Describe("ClusterProfileReconciler map functions", func() { clusterInfo := corev1.ObjectReference{APIVersion: cluster.APIVersion, Kind: cluster.Kind, Namespace: cluster.Namespace, Name: cluster.Name} reconciler.ClusterMap[clusterInfo] = clusterProfileSet - // ClusterProfileMap contains, per ClusterProfile, list of matched Clusters. - clusterSet1 := &libsveltosset.Set{} - reconciler.ClusterProfileMap[nonMatchingInfo] = clusterSet1 - - clusterSet2 := &libsveltosset.Set{} - clusterSet2.Insert(&clusterInfo) - reconciler.ClusterProfileMap[matchingInfo] = clusterSet2 - By("Expect only matchingClusterProfile to be requeued") requests := controllers.RequeueClusterProfileForCluster(reconciler, context.TODO(), cluster) expected := reconcile.Request{NamespacedName: types.NamespacedName{Name: matchingClusterProfile.Name}} @@ -122,9 +113,6 @@ var _ = Describe("ClusterProfileReconciler map functions", func() { reconciler.ClusterProfiles[nonMatchingInfo] = nonMatchingClusterProfile.Spec.ClusterSelector - clusterSet1.Insert(&clusterInfo) - reconciler.ClusterProfileMap[nonMatchingInfo] = clusterSet1 - clusterProfileSet.Insert(&nonMatchingInfo) reconciler.ClusterMap[clusterInfo] = clusterProfileSet @@ -141,8 +129,6 @@ var _ = Describe("ClusterProfileReconciler map functions", func() { Expect(c.Update(context.TODO(), nonMatchingClusterProfile)).To(Succeed()) emptySet := &libsveltosset.Set{} - reconciler.ClusterProfileMap[matchingInfo] = emptySet - reconciler.ClusterProfileMap[nonMatchingInfo] = emptySet reconciler.ClusterMap[clusterInfo] = emptySet reconciler.ClusterProfiles[matchingInfo] = matchingClusterProfile.Spec.ClusterSelector diff --git a/controllers/clustersummary_controller.go b/controllers/clustersummary_controller.go index 98ee8d94..929b5df5 100644 --- a/controllers/clustersummary_controller.go +++ b/controllers/clustersummary_controller.go @@ -31,7 +31,6 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/rest" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/util/annotations" @@ -90,34 +89,7 @@ type ClusterSummaryReconciler struct { ConcurrentReconciles int PolicyMux sync.Mutex // use a Mutex to update Map as MaxConcurrentReconciles is higher than one ReferenceMap map[corev1.ObjectReference]*libsveltosset.Set // key: Referenced object; value: set of all ClusterSummaries referencing the resource - ClusterSummaryMap map[types.NamespacedName]*libsveltosset.Set // key: ClusterSummary namespace/name; value: set of referenced resources - - // key: Sveltos/Cluster; value: set of all ClusterSummaries for that Cluster - ClusterMap map[corev1.ObjectReference]*libsveltosset.Set - - // Reason for the two maps: - // ClusterSummary references ConfigMaps/Secrets containing policies to be deployed in a Sveltos/Cluster. - // When a ConfigMap/Secret changes, all the ClusterSummaries referencing it need to be reconciled. - // In order to achieve so, ClusterSummary reconciler could watch for ConfigMaps/Secrets. When a ConfigMap/Secret spec changes, - // find all the ClusterSummaries currently referencing it and reconcile those. Problem is no I/O should be present inside a MapFunc - // (given a ConfigMap/Secret, return all the ClusterSummary referencing such ConfigMap/Secret). - // In the MapFunc, if the list ClusterSummaries operation failed, we would be unable to retry or re-enqueue the ClusterSummaries - // referencing the ConfigMap that changed. - // Instead the approach taken is following: - // - when a ClusterSummary is reconciled, update the ReferenceMap; - // - in the MapFunc, given the ConfigMap/Secret that changed, we can immeditaly get all the ClusterSummaries needing a reconciliation (by - // using the ReferenceMap); - // - if a ClusterSummary is referencing a ConfigMap/Secret but its reconciliation is still queued, when ConfigMap/Secret changes, - // ReferenceMap won't have such ClusterSummary. This is not a problem as ClusterSummary reconciliation is already queued and will happen. - // - // The ClusterSummaryMap is used to update ReferenceMap. Consider following scenarios to understand the need: - // 1. ClusterSummary A references ConfigMaps 1 and 2. When reconciled, ReferenceMap will have 1 => A and 2 => A; - // and ClusterSummaryMap A => 1,2 - // 2. ClusterSummary A changes and now references ConfigMap 1 only. We ned to remove the entry 2 => A in ReferenceMap. But - // when we reconcile ClusterSummary we have its current version we don't have its previous version. So we use ClusterSummaryMap (at this - // point value stored here corresponds to reconciliation #1. We know currently ClusterSummary references ConfigMap 1 only and looking - // at ClusterSummaryMap we know it used to reference ConfigMap 1 and 2. So we can remove 2 => A from ReferenceMap. Only after this - // update, we update ClusterSummaryMap (so new value will be A => 1) + ClusterMap map[corev1.ObjectReference]*libsveltosset.Set // key: Sveltos/Cluster; value: set of all ClusterSummaries for that Cluster ctrl controller.Controller } @@ -662,8 +634,6 @@ func (r *ClusterSummaryReconciler) cleanMaps(clusterSummaryScope *scope.ClusterS r.PolicyMux.Lock() defer r.PolicyMux.Unlock() - delete(r.ClusterSummaryMap, types.NamespacedName{Namespace: clusterSummaryScope.Namespace(), Name: clusterSummaryScope.Name()}) - clusterSummaryInfo := getKeyFromObject(r.Scheme, clusterSummaryScope.ClusterSummary) for i := range r.ClusterMap { @@ -699,15 +669,15 @@ func (r *ClusterSummaryReconciler) updateMaps(ctx context.Context, clusterSummar clusterInfo := getKeyFromObject(r.Scheme, clusterObject) clusterSummaryInfo := corev1.ObjectReference{APIVersion: configv1alpha1.GroupVersion.String(), - Kind: configv1alpha1.ClusterProfileKind, Namespace: clusterSummaryScope.Namespace(), + Kind: configv1alpha1.ClusterSummaryKind, Namespace: clusterSummaryScope.Namespace(), Name: clusterSummaryScope.Name()} r.getClusterMapForEntry(clusterInfo).Insert(&clusterSummaryInfo) - // Get list of References not referenced anymore by ClusterSummary - var toBeRemoved []corev1.ObjectReference - clusterSummaryName := types.NamespacedName{Namespace: clusterSummaryScope.Namespace(), Name: clusterSummaryScope.Name()} - if v, ok := r.ClusterSummaryMap[clusterSummaryName]; ok { - toBeRemoved = v.Difference(currentReferences) + for k, l := range r.ReferenceMap { + l.Erase(&clusterSummaryInfo) + if l.Len() == 0 { + delete(r.ReferenceMap, k) + } } // For each currently referenced instance, add ClusterSummary as consumer @@ -723,21 +693,6 @@ func (r *ClusterSummaryReconciler) updateMaps(ctx context.Context, clusterSummar ) } - // For each resource not reference anymore, remove ClusterSummary as consumer - for i := range toBeRemoved { - referencedResource := toBeRemoved[i] - r.getReferenceMapForEntry(&referencedResource).Erase( - &corev1.ObjectReference{ - APIVersion: configv1alpha1.GroupVersion.String(), - Kind: configv1alpha1.ClusterSummaryKind, - Namespace: clusterSummaryScope.Namespace(), - Name: clusterSummaryScope.Name(), - }, - ) - } - - // Update list of resources currently referenced by ClusterSummary - r.ClusterSummaryMap[clusterSummaryName] = currentReferences return nil } diff --git a/controllers/clustersummary_controller_test.go b/controllers/clustersummary_controller_test.go index 5ceabdcc..b496c7c1 100644 --- a/controllers/clustersummary_controller_test.go +++ b/controllers/clustersummary_controller_test.go @@ -115,13 +115,12 @@ var _ = Describe("ClustersummaryController", func() { c := fake.NewClientBuilder().WithScheme(scheme).WithStatusSubresource(initObjects...).WithObjects(initObjects...).Build() reconciler := &controllers.ClusterSummaryReconciler{ - Client: c, - Scheme: scheme, - Deployer: nil, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), - PolicyMux: sync.Mutex{}, + Client: c, + Scheme: scheme, + Deployer: nil, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + PolicyMux: sync.Mutex{}, } Expect(controllers.IsReady(reconciler, context.TODO(), clusterSummary, logr.Logger{})).To(BeTrue()) @@ -142,13 +141,12 @@ var _ = Describe("ClustersummaryController", func() { c := fake.NewClientBuilder().WithScheme(scheme).WithStatusSubresource(initObjects...).WithObjects(initObjects...).Build() reconciler := &controllers.ClusterSummaryReconciler{ - Client: c, - Scheme: scheme, - Deployer: nil, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), - PolicyMux: sync.Mutex{}, + Client: c, + Scheme: scheme, + Deployer: nil, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + PolicyMux: sync.Mutex{}, } Expect(controllers.IsPaused(reconciler, context.TODO(), clusterSummary)).To(BeFalse()) @@ -172,13 +170,12 @@ var _ = Describe("ClustersummaryController", func() { c := fake.NewClientBuilder().WithScheme(scheme).WithStatusSubresource(initObjects...).WithObjects(initObjects...).Build() reconciler := &controllers.ClusterSummaryReconciler{ - Client: c, - Scheme: scheme, - Deployer: nil, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), - PolicyMux: sync.Mutex{}, + Client: c, + Scheme: scheme, + Deployer: nil, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + PolicyMux: sync.Mutex{}, } Expect(controllers.IsPaused(reconciler, context.TODO(), clusterSummary)).To(BeFalse()) @@ -204,13 +201,12 @@ var _ = Describe("ClustersummaryController", func() { Expect(err).To(BeNil()) reconciler := &controllers.ClusterSummaryReconciler{ - Client: c, - Scheme: scheme, - Deployer: nil, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), - PolicyMux: sync.Mutex{}, + Client: c, + Scheme: scheme, + Deployer: nil, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + PolicyMux: sync.Mutex{}, } Expect(controllers.ShouldReconcile(reconciler, clusterSummaryScope, @@ -241,13 +237,12 @@ var _ = Describe("ClustersummaryController", func() { Expect(err).To(BeNil()) reconciler := &controllers.ClusterSummaryReconciler{ - Client: c, - Scheme: scheme, - Deployer: nil, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), - PolicyMux: sync.Mutex{}, + Client: c, + Scheme: scheme, + Deployer: nil, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + PolicyMux: sync.Mutex{}, } Expect(controllers.UpdateChartMap(reconciler, context.TODO(), clusterSummaryScope, @@ -309,13 +304,12 @@ var _ = Describe("ClustersummaryController", func() { Expect(err).To(BeNil()) reconciler := &controllers.ClusterSummaryReconciler{ - Client: c, - Scheme: scheme, - Deployer: nil, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), - PolicyMux: sync.Mutex{}, + Client: c, + Scheme: scheme, + Deployer: nil, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + PolicyMux: sync.Mutex{}, } Expect(controllers.ShouldReconcile(reconciler, clusterSummaryScope, textlogger.NewLogger(textlogger.NewConfig()))).To(BeTrue()) @@ -361,13 +355,12 @@ var _ = Describe("ClustersummaryController", func() { Expect(err).To(BeNil()) reconciler := &controllers.ClusterSummaryReconciler{ - Client: c, - Scheme: scheme, - Deployer: nil, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), - PolicyMux: sync.Mutex{}, + Client: c, + Scheme: scheme, + Deployer: nil, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + PolicyMux: sync.Mutex{}, } failureMsg := randomString() @@ -445,13 +438,12 @@ var _ = Describe("ClustersummaryController", func() { Expect(err).To(BeNil()) reconciler := &controllers.ClusterSummaryReconciler{ - Client: c, - Scheme: scheme, - Deployer: nil, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), - PolicyMux: sync.Mutex{}, + Client: c, + Scheme: scheme, + Deployer: nil, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + PolicyMux: sync.Mutex{}, } controllers.ResetFeatureStatus(reconciler, clusterSummaryScope, configv1alpha1.FeatureStatusFailed) @@ -508,13 +500,12 @@ var _ = Describe("ClustersummaryController", func() { Expect(err).To(BeNil()) reconciler := &controllers.ClusterSummaryReconciler{ - Client: c, - Scheme: scheme, - Deployer: nil, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), - PolicyMux: sync.Mutex{}, + Client: c, + Scheme: scheme, + Deployer: nil, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + PolicyMux: sync.Mutex{}, } Expect(controllers.ShouldReconcile(reconciler, clusterSummaryScope, @@ -551,13 +542,12 @@ var _ = Describe("ClustersummaryController", func() { Expect(err).To(BeNil()) reconciler := &controllers.ClusterSummaryReconciler{ - Client: c, - Scheme: scheme, - Deployer: nil, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), - PolicyMux: sync.Mutex{}, + Client: c, + Scheme: scheme, + Deployer: nil, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + PolicyMux: sync.Mutex{}, } Expect(controllers.ShouldReconcile(reconciler, clusterSummaryScope, @@ -576,13 +566,12 @@ var _ = Describe("ClustersummaryController", func() { deployer := fakedeployer.GetClient(context.TODO(), textlogger.NewLogger(textlogger.NewConfig()), c) reconciler := &controllers.ClusterSummaryReconciler{ - Client: c, - Scheme: scheme, - Deployer: deployer, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), - PolicyMux: sync.Mutex{}, + Client: c, + Scheme: scheme, + Deployer: deployer, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + PolicyMux: sync.Mutex{}, } clusterSummaryName := client.ObjectKey{ @@ -622,13 +611,12 @@ var _ = Describe("ClustersummaryController", func() { deployer := fakedeployer.GetClient(context.TODO(), textlogger.NewLogger(textlogger.NewConfig()), c) reconciler := &controllers.ClusterSummaryReconciler{ - Client: c, - Scheme: scheme, - Deployer: deployer, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), - PolicyMux: sync.Mutex{}, + Client: c, + Scheme: scheme, + Deployer: deployer, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + PolicyMux: sync.Mutex{}, } clusterSummaryScope, err := scope.NewClusterSummaryScope(&scope.ClusterSummaryScopeParams{ @@ -679,13 +667,12 @@ var _ = Describe("ClustersummaryController", func() { deployer := fakedeployer.GetClient(context.TODO(), textlogger.NewLogger(textlogger.NewConfig()), c) reconciler := &controllers.ClusterSummaryReconciler{ - Client: c, - Scheme: scheme, - Deployer: deployer, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), - PolicyMux: sync.Mutex{}, + Client: c, + Scheme: scheme, + Deployer: deployer, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + PolicyMux: sync.Mutex{}, } clusterSummaryScope, err := scope.NewClusterSummaryScope(&scope.ClusterSummaryScopeParams{ @@ -743,13 +730,12 @@ var _ = Describe("ClustersummaryController", func() { deployer := fakedeployer.GetClient(context.TODO(), textlogger.NewLogger(textlogger.NewConfig()), c) reconciler := &controllers.ClusterSummaryReconciler{ - Client: c, - Scheme: scheme, - Deployer: deployer, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), - PolicyMux: sync.Mutex{}, + Client: c, + Scheme: scheme, + Deployer: deployer, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + PolicyMux: sync.Mutex{}, } clusterSummaryScope, err := scope.NewClusterSummaryScope(&scope.ClusterSummaryScopeParams{ @@ -805,13 +791,12 @@ var _ = Describe("ClustersummaryController", func() { deployer := fakedeployer.GetClient(context.TODO(), textlogger.NewLogger(textlogger.NewConfig()), c) reconciler := &controllers.ClusterSummaryReconciler{ - Client: c, - Scheme: scheme, - Deployer: deployer, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), - PolicyMux: sync.Mutex{}, + Client: c, + Scheme: scheme, + Deployer: deployer, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + PolicyMux: sync.Mutex{}, } clusterSummaryScope, err := scope.NewClusterSummaryScope(&scope.ClusterSummaryScopeParams{ @@ -992,13 +977,12 @@ var _ = Describe("ClustersummaryController", func() { deployer := fakedeployer.GetClient(context.TODO(), textlogger.NewLogger(textlogger.NewConfig()), c) reconciler := &controllers.ClusterSummaryReconciler{ - Client: c, - Scheme: scheme, - Deployer: deployer, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), - PolicyMux: sync.Mutex{}, + Client: c, + Scheme: scheme, + Deployer: deployer, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + PolicyMux: sync.Mutex{}, } clusterSummaryScope, err := scope.NewClusterSummaryScope(&scope.ClusterSummaryScopeParams{ diff --git a/controllers/clustersummary_transformations_test.go b/controllers/clustersummary_transformations_test.go index 6ce0d0ca..663fe53f 100644 --- a/controllers/clustersummary_transformations_test.go +++ b/controllers/clustersummary_transformations_test.go @@ -102,12 +102,11 @@ var _ = Describe("ClusterSummaryTransformations map functions", func() { c := fake.NewClientBuilder().WithScheme(scheme).WithStatusSubresource(initObjects...).WithObjects(initObjects...).Build() reconciler := &controllers.ClusterSummaryReconciler{ - Client: c, - Scheme: scheme, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), - PolicyMux: sync.Mutex{}, + Client: c, + Scheme: scheme, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + PolicyMux: sync.Mutex{}, } set := libsveltosset.Set{} diff --git a/controllers/controllers_suite_test.go b/controllers/controllers_suite_test.go index 2c1fb2ac..f3727c83 100644 --- a/controllers/controllers_suite_test.go +++ b/controllers/controllers_suite_test.go @@ -30,7 +30,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" "k8s.io/klog/v2" "k8s.io/klog/v2/textlogger" ctrl "sigs.k8s.io/controller-runtime" @@ -161,25 +160,23 @@ var _ = AfterSuite(func() { func getClusterSummaryReconciler(c client.Client, dep deployer.DeployerInterface) *controllers.ClusterSummaryReconciler { return &controllers.ClusterSummaryReconciler{ - Client: c, - Scheme: scheme, - Deployer: dep, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterSummaryMap: make(map[types.NamespacedName]*libsveltosset.Set), - PolicyMux: sync.Mutex{}, + Client: c, + Scheme: scheme, + Deployer: dep, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ReferenceMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + PolicyMux: sync.Mutex{}, } } func getClusterProfileReconciler(c client.Client) *controllers.ClusterProfileReconciler { return &controllers.ClusterProfileReconciler{ - Client: c, - Scheme: scheme, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterProfileMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterProfiles: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), - ClusterLabels: make(map[corev1.ObjectReference]map[string]string), - Mux: sync.Mutex{}, + Client: c, + Scheme: scheme, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ClusterProfiles: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), + ClusterLabels: make(map[corev1.ObjectReference]map[string]string), + Mux: sync.Mutex{}, } } @@ -188,7 +185,6 @@ func getProfileReconciler(c client.Client) *controllers.ProfileReconciler { Client: c, Scheme: scheme, ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ProfileMap: make(map[corev1.ObjectReference]*libsveltosset.Set), Profiles: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), ClusterLabels: make(map[corev1.ObjectReference]map[string]string), Mux: sync.Mutex{}, diff --git a/controllers/profile_controller.go b/controllers/profile_controller.go index 896e1e93..4a31f035 100644 --- a/controllers/profile_controller.go +++ b/controllers/profile_controller.go @@ -59,8 +59,7 @@ type ProfileReconciler struct { // key: Sveltos/Cluster; value: set of all Profiles matching the Cluster ClusterMap map[corev1.ObjectReference]*libsveltosset.Set - // key: Profile; value: set of Sveltos/CAPI Clusters matched - ProfileMap map[corev1.ObjectReference]*libsveltosset.Set + // key: Profile; value Profile Selector Profiles map[corev1.ObjectReference]libsveltosv1alpha1.Selector @@ -296,7 +295,6 @@ func (r *ProfileReconciler) cleanMaps(profileScope *scope.ProfileScope) { profileInfo := getKeyFromObject(r.Scheme, profileScope.Profile) - delete(r.ProfileMap, *profileInfo) delete(r.Profiles, *profileInfo) // ClusterMap contains for each cluster, set of Profiles matching @@ -315,17 +313,16 @@ func (r *ProfileReconciler) cleanMaps(profileScope *scope.ProfileScope) { } func (r *ProfileReconciler) updateMaps(profileScope *scope.ProfileScope) { - currentClusters := getCurrentClusterSet(profileScope.GetStatus().MatchingClusterRefs) - r.Mux.Lock() defer r.Mux.Unlock() profileInfo := getKeyFromObject(r.Scheme, profileScope.Profile) - // Get list of Clusters not matched anymore by Profile - var toBeRemoved []corev1.ObjectReference - if v, ok := r.ProfileMap[*profileInfo]; ok { - toBeRemoved = v.Difference(currentClusters) + for k, l := range r.ClusterMap { + l.Erase(profileInfo) + if l.Len() == 0 { + delete(r.ClusterMap, k) + } } // For each currently matching Cluster, add Profile as consumer @@ -336,10 +333,11 @@ func (r *ProfileReconciler) updateMaps(profileScope *scope.ProfileScope) { getConsumersForEntry(r.ClusterMap, clusterInfo).Insert(profileInfo) } - // For each Cluster not matched anymore, remove Profile as consumer - for i := range toBeRemoved { - clusterName := toBeRemoved[i] - getConsumersForEntry(r.ClusterMap, &clusterName).Erase(profileInfo) + for k, l := range r.SetMap { + l.Erase(profileInfo) + if l.Len() == 0 { + delete(r.SetMap, k) + } } // For each referenced Set, add Profile as consumer @@ -350,7 +348,6 @@ func (r *ProfileReconciler) updateMaps(profileScope *scope.ProfileScope) { getConsumersForEntry(r.SetMap, setInfo).Insert(profileInfo) } - r.ProfileMap[*profileInfo] = currentClusters r.Profiles[*profileInfo] = profileScope.GetSpec().ClusterSelector } diff --git a/controllers/profile_controller_test.go b/controllers/profile_controller_test.go index beb8510c..17a1d3b8 100644 --- a/controllers/profile_controller_test.go +++ b/controllers/profile_controller_test.go @@ -112,7 +112,6 @@ var _ = Describe("Profile Controller", func() { Client: c, Scheme: scheme, ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ProfileMap: make(map[corev1.ObjectReference]*libsveltosset.Set), Profiles: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), ClusterLabels: make(map[corev1.ObjectReference]map[string]string), Mux: sync.Mutex{}, @@ -191,7 +190,6 @@ var _ = Describe("Profile Controller", func() { Scheme: scheme, SetMap: make(map[corev1.ObjectReference]*libsveltosset.Set), ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ProfileMap: make(map[corev1.ObjectReference]*libsveltosset.Set), Profiles: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), ClusterLabels: make(map[corev1.ObjectReference]map[string]string), Mux: sync.Mutex{}, diff --git a/controllers/profile_transformation_common.go b/controllers/profile_transformation_common.go index 4bc3da1e..6aa55ce9 100644 --- a/controllers/profile_transformation_common.go +++ b/controllers/profile_transformation_common.go @@ -48,6 +48,8 @@ func requeueForCluster(cluster client.Object, profileCurrentlyMatching := getConsumersForEntry(clusterMap, &clusterInfo) + logger.V(logs.LogInfo).Info(fmt.Sprintf("MGIANLUC %d", profileCurrentlyMatching.Len())) + clusterLabels[clusterInfo] = cluster.GetLabels() // Get all (Cluster)Profiles previously matching this cluster and reconcile those @@ -59,7 +61,8 @@ func requeueForCluster(cluster client.Object, l.V(logs.LogDebug).Info(fmt.Sprintf("queuing %s", kindType)) requests[i] = ctrl.Request{ NamespacedName: client.ObjectKey{ - Name: consumers[i].Name, + Namespace: consumers[i].Namespace, + Name: consumers[i].Name, }, } } @@ -123,7 +126,8 @@ func requeueForMachine(machine client.Object, for i := range consumers { requests[i] = ctrl.Request{ NamespacedName: client.ObjectKey{ - Name: consumers[i].Name, + Namespace: consumers[i].Namespace, + Name: consumers[i].Name, }, } } diff --git a/controllers/profile_transformations_test.go b/controllers/profile_transformations_test.go index d7f0fae7..0571d1a0 100644 --- a/controllers/profile_transformations_test.go +++ b/controllers/profile_transformations_test.go @@ -59,6 +59,8 @@ var _ = Describe("Profile Transformations", func() { }, } + Expect(addTypeInformationToObject(scheme, cluster)).To(BeNil()) + matchingProfile := &configv1alpha1.ClusterProfile{ ObjectMeta: metav1.ObjectMeta{ Name: clusterProfileNamePrefix + randomString(), @@ -72,7 +74,8 @@ var _ = Describe("Profile Transformations", func() { nonMatchingProfile := &configv1alpha1.ClusterProfile{ ObjectMeta: metav1.ObjectMeta{ - Name: clusterProfileNamePrefix + randomString(), + Name: clusterProfileNamePrefix + randomString(), + Namespace: cluster.Namespace, }, Spec: configv1alpha1.Spec{ ClusterSelector: libsveltosv1alpha1.Selector( @@ -88,61 +91,45 @@ var _ = Describe("Profile Transformations", func() { c := fake.NewClientBuilder().WithScheme(scheme).WithObjects(initObjects...).Build() - reconciler := &controllers.ClusterProfileReconciler{ - Client: c, - Scheme: scheme, - ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterProfileMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ClusterProfiles: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), - ClusterLabels: make(map[corev1.ObjectReference]map[string]string), - Mux: sync.Mutex{}, + reconciler := &controllers.ProfileReconciler{ + Client: c, + Scheme: scheme, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + Profiles: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), + ClusterLabels: make(map[corev1.ObjectReference]map[string]string), + Mux: sync.Mutex{}, } By("Setting ProfileReconciler internal structures") matchingInfo := corev1.ObjectReference{APIVersion: cluster.APIVersion, - Kind: configv1alpha1.ClusterProfileKind, Name: matchingProfile.Name} - reconciler.ClusterProfiles[matchingInfo] = matchingProfile.Spec.ClusterSelector + Kind: configv1alpha1.ProfileKind, Namespace: matchingProfile.Namespace, Name: matchingProfile.Name} nonMatchingInfo := corev1.ObjectReference{APIVersion: cluster.APIVersion, - Kind: configv1alpha1.ClusterProfileKind, Name: nonMatchingProfile.Name} - reconciler.ClusterProfiles[nonMatchingInfo] = nonMatchingProfile.Spec.ClusterSelector + Kind: configv1alpha1.ProfileKind, Namespace: nonMatchingProfile.Namespace, Name: nonMatchingProfile.Name} // ClusterMap contains, per ClusterName, list of ClusterProfiles matching it. - clusterProfileSet := &libsveltosset.Set{} - clusterProfileSet.Insert(&matchingInfo) + profileSet := &libsveltosset.Set{} + profileSet.Insert(&matchingInfo) clusterInfo := corev1.ObjectReference{APIVersion: cluster.APIVersion, Kind: cluster.Kind, Namespace: cluster.Namespace, Name: cluster.Name} - reconciler.ClusterMap[clusterInfo] = clusterProfileSet - - // ProfileMap contains, per Profile, list of matched Clusters. - clusterSet1 := &libsveltosset.Set{} - reconciler.ClusterProfileMap[nonMatchingInfo] = clusterSet1 - - clusterSet2 := &libsveltosset.Set{} - clusterSet2.Insert(&clusterInfo) - reconciler.ClusterProfileMap[matchingInfo] = clusterSet2 + reconciler.ClusterMap[clusterInfo] = profileSet By("Expect only matchingProfile to be requeued") - requests := controllers.RequeueClusterProfileForCluster(reconciler, context.TODO(), cluster) - expected := reconcile.Request{NamespacedName: types.NamespacedName{Name: matchingProfile.Name}} + requests := controllers.RequeueProfileForCluster(reconciler, context.TODO(), cluster) + expected := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: matchingProfile.Namespace, Name: matchingProfile.Name}} Expect(requests).To(ContainElement(expected)) By("Changing Profile ClusterSelector again to have two ClusterProfiles match") nonMatchingProfile.Spec.ClusterSelector = matchingProfile.Spec.ClusterSelector Expect(c.Update(context.TODO(), nonMatchingProfile)).To(Succeed()) - reconciler.ClusterProfiles[nonMatchingInfo] = nonMatchingProfile.Spec.ClusterSelector - - clusterSet1.Insert(&clusterInfo) - reconciler.ClusterProfileMap[nonMatchingInfo] = clusterSet1 - - clusterProfileSet.Insert(&nonMatchingInfo) - reconciler.ClusterMap[clusterInfo] = clusterProfileSet + profileSet.Insert(&nonMatchingInfo) + reconciler.ClusterMap[clusterInfo] = profileSet - requests = controllers.RequeueClusterProfileForCluster(reconciler, context.TODO(), cluster) - expected = reconcile.Request{NamespacedName: types.NamespacedName{Name: matchingProfile.Name}} + requests = controllers.RequeueProfileForCluster(reconciler, context.TODO(), cluster) + expected = reconcile.Request{NamespacedName: types.NamespacedName{Namespace: matchingProfile.Namespace, Name: matchingProfile.Name}} Expect(requests).To(ContainElement(expected)) - expected = reconcile.Request{NamespacedName: types.NamespacedName{Name: nonMatchingProfile.Name}} + expected = reconcile.Request{NamespacedName: types.NamespacedName{Namespace: nonMatchingProfile.Namespace, Name: nonMatchingProfile.Name}} Expect(requests).To(ContainElement(expected)) }) @@ -206,7 +193,6 @@ var _ = Describe("Profile Transformations", func() { Client: c, Scheme: scheme, ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), - ProfileMap: make(map[corev1.ObjectReference]*libsveltosset.Set), Profiles: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector), ClusterLabels: make(map[corev1.ObjectReference]map[string]string), Mux: sync.Mutex{}, @@ -232,15 +218,6 @@ var _ = Describe("Profile Transformations", func() { Kind: cluster.Kind, Namespace: cluster.Namespace, Name: cluster.Name} reconciler.ClusterMap[clusterInfo] = profileSet - // ProfileMap contains, per Profile, list of matched Clusters. - clusterSet1 := &libsveltosset.Set{} - reconciler.ProfileMap[nonMatchingInfo1] = clusterSet1 - reconciler.ProfileMap[nonMatchingInfo2] = clusterSet1 - - clusterSet2 := &libsveltosset.Set{} - clusterSet2.Insert(&clusterInfo) - reconciler.ProfileMap[matchingInfo] = clusterSet2 - By("Expect only matchingProfile to be requeued") requests := controllers.RequeueProfileForCluster(reconciler, context.TODO(), cluster) expected := reconcile.Request{NamespacedName: types.NamespacedName{ @@ -257,9 +234,6 @@ var _ = Describe("Profile Transformations", func() { reconciler.Profiles[nonMatchingInfo1] = nonMatchingProfile1.Spec.ClusterSelector reconciler.Profiles[nonMatchingInfo2] = nonMatchingProfile2.Spec.ClusterSelector - clusterSet1.Insert(&clusterInfo) - reconciler.ProfileMap[nonMatchingInfo1] = clusterSet1 - profileSet.Insert(&nonMatchingInfo1) reconciler.ClusterMap[clusterInfo] = profileSet From 2cfeed7aec97ec00e477225fd90479abd80223af Mon Sep 17 00:00:00 2001 From: mgianluc Date: Wed, 27 Mar 2024 14:52:42 +0100 Subject: [PATCH 07/10] Add pprof handlers --- cmd/main.go | 11 +++++++++++ controllers/handlers_helm.go | 16 +++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 8aaf7d86..9bb6771f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -20,6 +20,8 @@ import ( "context" "flag" "fmt" + "net/http" + "net/http/pprof" "os" "sync" "syscall" @@ -462,6 +464,15 @@ func getDiagnosticsOptions() metricsserver.Options { BindAddress: diagnosticsAddress, SecureServing: true, FilterProvider: filters.WithAuthenticationAndAuthorization, + ExtraHandlers: map[string]http.Handler{ + // Add pprof handler. + "/debug/pprof/": http.HandlerFunc(pprof.Index), + "/debug/pprof/cmdline": http.HandlerFunc(pprof.Cmdline), + "/debug/pprof/profile": http.HandlerFunc(pprof.Profile), + "/debug/pprof/symbol": http.HandlerFunc(pprof.Symbol), + "/debug/pprof/trace": http.HandlerFunc(pprof.Trace), + "/debug/pprof/heap": pprof.Handler("heap"), + }, } } diff --git a/controllers/handlers_helm.go b/controllers/handlers_helm.go index f1336e62..546a595d 100644 --- a/controllers/handlers_helm.go +++ b/controllers/handlers_helm.go @@ -682,7 +682,8 @@ func repoAddOrUpdate(settings *cli.EnvSettings, name, url string, logger logr.Lo // installRelease installs helm release in the CAPI cluster. // No action in DryRun mode. -func installRelease(clusterSummary *configv1alpha1.ClusterSummary, settings *cli.EnvSettings, requestedChart *configv1alpha1.HelmChart, +func installRelease(ctx context.Context, clusterSummary *configv1alpha1.ClusterSummary, + settings *cli.EnvSettings, requestedChart *configv1alpha1.HelmChart, kubeconfig string, values map[string]interface{}, logger logr.Logger) error { // No-op in DryRun mode @@ -741,7 +742,7 @@ func installRelease(clusterSummary *configv1alpha1.ClusterSummary, settings *cli } installClient.DryRun = false - _, err = installClient.Run(chartRequested, values) + _, err = installClient.RunWithContext(ctx, chartRequested, values) if err != nil { return err } @@ -810,7 +811,8 @@ func uninstallRelease(clusterSummary *configv1alpha1.ClusterSummary, // upgradeRelease upgrades helm release in managed cluster. // No action in DryRun mode. -func upgradeRelease(clusterSummary *configv1alpha1.ClusterSummary, settings *cli.EnvSettings, requestedChart *configv1alpha1.HelmChart, +func upgradeRelease(ctx context.Context, clusterSummary *configv1alpha1.ClusterSummary, + settings *cli.EnvSettings, requestedChart *configv1alpha1.HelmChart, kubeconfig string, values map[string]interface{}, logger logr.Logger) error { // No-op in DryRun mode @@ -864,7 +866,7 @@ func upgradeRelease(clusterSummary *configv1alpha1.ClusterSummary, settings *cli hisClient.Max = 1 _, err = hisClient.Run(requestedChart.ReleaseName) if errors.Is(err, driver.ErrReleaseNotFound) { - err = upgradeRelease(clusterSummary, settings, requestedChart, kubeconfig, values, logger) + err = upgradeRelease(ctx, clusterSummary, settings, requestedChart, kubeconfig, values, logger) if err != nil { return err } @@ -874,7 +876,7 @@ func upgradeRelease(clusterSummary *configv1alpha1.ClusterSummary, settings *cli } upgradeClient.DryRun = false - _, err = upgradeClient.Run(requestedChart.ReleaseName, chartRequested, values) + _, err = upgradeClient.RunWithContext(ctx, requestedChart.ReleaseName, chartRequested, values) if err != nil { return err } @@ -1058,7 +1060,7 @@ func doInstallRelease(ctx context.Context, clusterSummary *configv1alpha1.Cluste return err } - err = installRelease(clusterSummary, settings, requestedChart, kubeconfig, values, logger) + err = installRelease(ctx, clusterSummary, settings, requestedChart, kubeconfig, values, logger) if err != nil { return err } @@ -1115,7 +1117,7 @@ func doUpgradeRelease(ctx context.Context, clusterSummary *configv1alpha1.Cluste return err } - err = upgradeRelease(clusterSummary, settings, requestedChart, kubeconfig, values, logger) + err = upgradeRelease(ctx, clusterSummary, settings, requestedChart, kubeconfig, values, logger) if err != nil { return err } From 5918df28a78842c37affc2b0c255bb1ebfc7be58 Mon Sep 17 00:00:00 2001 From: mgianluc Date: Thu, 28 Mar 2024 15:09:03 +0100 Subject: [PATCH 08/10] Print memory usage --- Makefile | 2 +- api/v1alpha1/spec.go | 5 ++ cmd/main.go | 34 +++++++++++-- ...fig.projectsveltos.io_clusterprofiles.yaml | 6 +++ ...ig.projectsveltos.io_clustersummaries.yaml | 6 +++ .../config.projectsveltos.io_profiles.yaml | 6 +++ config/manager/manager.yaml | 5 +- controllers/chartmanager/chartmanager.go | 2 +- controllers/handlers_helm.go | 50 +++++++++++++------ controllers/profile_transformation_common.go | 2 - manifest/deployment-agentless.yaml | 3 ++ manifest/deployment-shard.yaml | 3 ++ manifest/manifest.yaml | 21 ++++++++ test/kind-cluster.yaml | 7 +++ 14 files changed, 127 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index 86fca4fc..68b2e534 100644 --- a/Makefile +++ b/Makefile @@ -259,7 +259,7 @@ create-control-cluster: $(KIND) $(CLUSTERCTL) $(KUBECTL) sed -e "s/K8S_VERSION/$(K8S_VERSION)/g" test/$(KIND_CONFIG) > test/$(KIND_CONFIG).tmp $(KIND) create cluster --name=$(CONTROL_CLUSTER_NAME) --config test/$(KIND_CONFIG).tmp @echo "Create control cluster with docker as infrastructure provider" - CLUSTER_TOPOLOGY=true $(CLUSTERCTL) init --infrastructure docker + CLUSTER_TOPOLOGY=true $(CLUSTERCTL) init --core cluster-api --bootstrap kubeadm --control-plane kubeadm --infrastructure docker @echo wait for capd-system pod $(KUBECTL) wait --for=condition=Available deployment/capd-controller-manager -n capd-system --timeout=$(TIMEOUT) diff --git a/api/v1alpha1/spec.go b/api/v1alpha1/spec.go index aedbbda4..992fc40c 100644 --- a/api/v1alpha1/spec.go +++ b/api/v1alpha1/spec.go @@ -189,6 +189,11 @@ type HelmOptions struct { // Labels that would be added to release metadata. // +optional Labels map[string]string `json:"labels,omitempty"` + + // EnableClientCache is a flag to enable Helm client cache. If it is not specified, it will be set to false. + // +kubebuilder:default=false + // +optional + EnableClientCache bool `json:"enableClientCache,omitempty"` } type HelmChart struct { diff --git a/cmd/main.go b/cmd/main.go index 9bb6771f..a6b59223 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -23,6 +23,8 @@ import ( "net/http" "net/http/pprof" "os" + "runtime" + "runtime/debug" "sync" "syscall" "time" @@ -58,6 +60,7 @@ import ( "github.com/projectsveltos/libsveltos/lib/crd" "github.com/projectsveltos/libsveltos/lib/deployer" "github.com/projectsveltos/libsveltos/lib/logsettings" + logs "github.com/projectsveltos/libsveltos/lib/logsettings" libsveltosset "github.com/projectsveltos/libsveltos/lib/set" //+kubebuilder:scaffold:imports ) @@ -86,6 +89,8 @@ const ( defaultReconcilers = 10 defaultWorkers = 20 defaulReportMode = int(controllers.CollectFromManagementCluster) + mebibytes_bytes = 1 << 20 + gibibytes_per_bytes = 1 << 30 ) // Add RBAC for the authorized diagnostics endpoint. @@ -108,7 +113,6 @@ func main() { reportMode = controllers.ReportMode(tmpReportMode) ctrl.SetLogger(klog.Background()) - ctrlOptions := ctrl.Options{ Scheme: scheme, Metrics: getDiagnosticsOptions(), @@ -135,13 +139,15 @@ func main() { // Setup the context that's going to be used in controllers and for the manager. ctx := ctrl.SetupSignalHandler() - controllers.SetManagementClusterAccess(mgr.GetClient(), mgr.GetConfig()) - logsettings.RegisterForLogSettings(ctx, + logs.RegisterForLogSettings(ctx, libsveltosv1alpha1.ComponentAddonManager, ctrl.Log.WithName("log-setter"), ctrl.GetConfigOrDie()) + debug.SetMemoryLimit(gibibytes_per_bytes) + go printMemUsage(ctrl.Log.WithName("memory-usage")) + startControllersAndWatchers(ctx, mgr) setupChecks(mgr) @@ -170,7 +176,7 @@ func initFlags(fs *pflag.FlagSet) { fs.StringVar(&diagnosticsAddress, "diagnostics-address", ":8443", "The address the diagnostics endpoint binds to. Per default metrics are served via https and with"+ "authentication/authorization. To serve via http and without authentication/authorization set --insecure-diagnostics."+ - "If --insecure-diagnostics is not set the diagnostics endpoint also serves pprof endpoints and an endpoint to change the log level.") + "If --insecure-diagnostics is not set the diagnostics endpoint also serves pprof endpoints") fs.BoolVar(&insecureDiagnostics, "insecure-diagnostics", false, "Enable insecure diagnostics serving. For more details see the description of --diagnostics-address.") @@ -545,3 +551,23 @@ func startControllersAndWatchers(ctx context.Context, mgr manager.Manager) { startWatchers(ctx, mgr, watchersForCAPI, watchersForFlux) } + +// printMemUsage memory stats. Call GC +func printMemUsage(logger logr.Logger) { + for { + time.Sleep(time.Minute) + var m runtime.MemStats + runtime.ReadMemStats(&m) + // For info on each, see: /pkg/runtime/#MemStats + l := logger.WithValues("Alloc (MiB)", bToMb(m.Alloc)). + WithValues("TotalAlloc (MiB)", bToMb(m.TotalAlloc)). + WithValues("Sys (MiB)", bToMb(m.Sys)). + WithValues("NumGC", m.NumGC) + l.V(logs.LogInfo).Info("memory stats") + runtime.GC() + } +} + +func bToMb(b uint64) uint64 { + return b / mebibytes_bytes +} diff --git a/config/crd/bases/config.projectsveltos.io_clusterprofiles.yaml b/config/crd/bases/config.projectsveltos.io_clusterprofiles.yaml index 1bca6acc..91e737d3 100644 --- a/config/crd/bases/config.projectsveltos.io_clusterprofiles.yaml +++ b/config/crd/bases/config.projectsveltos.io_clusterprofiles.yaml @@ -187,6 +187,12 @@ spec: if set, the installation process will not validate rendered templates against the Kubernetes OpenAPI Schema Default to false type: boolean + enableClientCache: + default: false + description: EnableClientCache is a flag to enable Helm + client cache. If it is not specified, it will be set to + false. + type: boolean labels: additionalProperties: type: string diff --git a/config/crd/bases/config.projectsveltos.io_clustersummaries.yaml b/config/crd/bases/config.projectsveltos.io_clustersummaries.yaml index aaf1fc62..cfd20412 100644 --- a/config/crd/bases/config.projectsveltos.io_clustersummaries.yaml +++ b/config/crd/bases/config.projectsveltos.io_clustersummaries.yaml @@ -203,6 +203,12 @@ spec: if set, the installation process will not validate rendered templates against the Kubernetes OpenAPI Schema Default to false type: boolean + enableClientCache: + default: false + description: EnableClientCache is a flag to enable Helm + client cache. If it is not specified, it will be set + to false. + type: boolean labels: additionalProperties: type: string diff --git a/config/crd/bases/config.projectsveltos.io_profiles.yaml b/config/crd/bases/config.projectsveltos.io_profiles.yaml index e2f538da..e2c7dce0 100644 --- a/config/crd/bases/config.projectsveltos.io_profiles.yaml +++ b/config/crd/bases/config.projectsveltos.io_profiles.yaml @@ -187,6 +187,12 @@ spec: if set, the installation process will not validate rendered templates against the Kubernetes OpenAPI Schema Default to false type: boolean + enableClientCache: + default: false + description: EnableClientCache is a flag to enable Helm + client cache. If it is not specified, it will be set to + false. + type: boolean labels: additionalProperties: type: string diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 03588056..899d3372 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -69,7 +69,10 @@ spec: periodSeconds: 10 volumeMounts: - mountPath: /tmp - name: tmp + name: tmp + resources: + requests: + memory: 256Mi serviceAccountName: controller terminationGracePeriodSeconds: 10 volumes: diff --git a/controllers/chartmanager/chartmanager.go b/controllers/chartmanager/chartmanager.go index ea5c568b..0cd64ed7 100644 --- a/controllers/chartmanager/chartmanager.go +++ b/controllers/chartmanager/chartmanager.go @@ -367,7 +367,7 @@ func (m *instance) getClusterSummaryKey(clusterSummaryName string) string { return clusterSummaryName } -// getReleaseInfoFromKey returns helm release given a key +// getReleaseInfoFromKey returns helm release for given a key func getReleaseInfoFromKey(releaseKey string) *HelmReleaseInfo { info := strings.Split(releaseKey, keySeparator) return &HelmReleaseInfo{ diff --git a/controllers/handlers_helm.go b/controllers/handlers_helm.go index 546a595d..f821c99f 100644 --- a/controllers/handlers_helm.go +++ b/controllers/handlers_helm.go @@ -19,7 +19,6 @@ package controllers import ( "context" "crypto/sha256" - "errors" "fmt" "os" "strconv" @@ -29,6 +28,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/gdexlab/go-render/render" "github.com/go-logr/logr" + "github.com/pkg/errors" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chart/loader" @@ -579,7 +579,7 @@ func handleChart(ctx context.Context, clusterSummary *configv1alpha1.ClusterSumm kubeconfig string, logger logr.Logger) (*releaseInfo, *configv1alpha1.ReleaseReport, error) { currentRelease, err := getReleaseInfo(currentChart.ReleaseName, - currentChart.ReleaseNamespace, kubeconfig) + currentChart.ReleaseNamespace, kubeconfig, getEnableClientCacheValue(currentChart.Options)) if err != nil && !errors.Is(err, driver.ErrReleaseNotFound) { return nil, nil, err } @@ -638,7 +638,7 @@ func handleChart(ctx context.Context, clusterSummary *configv1alpha1.ClusterSumm report.Message = "Already managing this helm release and specified version already installed" } - currentRelease, err = getReleaseInfo(currentChart.ReleaseName, currentChart.ReleaseNamespace, kubeconfig) + currentRelease, err = getReleaseInfo(currentChart.ReleaseName, currentChart.ReleaseNamespace, kubeconfig, getEnableClientCacheValue(currentChart.Options)) if err != nil && !errors.Is(err, driver.ErrReleaseNotFound) { return nil, nil, err } @@ -672,6 +672,7 @@ func repoAddOrUpdate(settings *cli.EnvSettings, name, url string, logger logr.Lo storage.Update(entry) const permissions = 0o644 + err = storage.WriteFile(settings.RepositoryConfig, permissions) if err != nil { return err @@ -748,6 +749,7 @@ func installRelease(ctx context.Context, clusterSummary *configv1alpha1.ClusterS } logger.V(logs.LogDebug).Info("installing release done") + return nil } @@ -780,7 +782,7 @@ func checkDependencies(chartRequested *chart.Chart, installClient *action.Instal // uninstallRelease removes helm release from a CAPI Cluster. // No action in DryRun mode. func uninstallRelease(clusterSummary *configv1alpha1.ClusterSummary, - releaseName, releaseNamespace, kubeconfig string, logger logr.Logger) error { + releaseName, releaseNamespace, kubeconfig string, helmChart *configv1alpha1.HelmChart, logger logr.Logger) error { // No-op in DryRun mode if clusterSummary.Spec.ClusterProfileSpec.SyncMode == configv1alpha1.SyncModeDryRun { @@ -790,7 +792,12 @@ func uninstallRelease(clusterSummary *configv1alpha1.ClusterSummary, logger = logger.WithValues("release", releaseName, "releaseNamespace", releaseNamespace) logger.V(logs.LogDebug).Info("uninstalling release") - actionConfig, err := actionConfigInit(releaseNamespace, kubeconfig) + enableClientCache := false + if helmChart != nil { + enableClientCache = getEnableClientCacheValue(helmChart.Options) + } + + actionConfig, err := actionConfigInit(releaseNamespace, kubeconfig, enableClientCache) if err != nil { return err } @@ -799,6 +806,7 @@ func uninstallRelease(clusterSummary *configv1alpha1.ClusterSummary, uninstallClient.DryRun = false uninstallClient.Wait = false uninstallClient.DisableHooks = false + uninstallClient.KeepHistory = false _, err = uninstallClient.Run(releaseName) if err != nil { @@ -806,6 +814,7 @@ func uninstallRelease(clusterSummary *configv1alpha1.ClusterSummary, } logger.V(logs.LogDebug).Info("uninstalling release done") + return nil } @@ -835,7 +844,7 @@ func upgradeRelease(ctx context.Context, clusterSummary *configv1alpha1.ClusterS chartName = defaultUploadPath + "/" + chartName } - actionConfig, err := actionConfigInit(requestedChart.ReleaseNamespace, kubeconfig) + actionConfig, err := actionConfigInit(requestedChart.ReleaseNamespace, kubeconfig, getEnableClientCacheValue(requestedChart.Options)) if err != nil { return err } @@ -882,6 +891,7 @@ func upgradeRelease(ctx context.Context, clusterSummary *configv1alpha1.ClusterS } logger.V(logs.LogDebug).Info("upgrading release done") + return nil } @@ -889,7 +899,7 @@ func debugf(format string, v ...interface{}) { helmLogger.V(logs.LogDebug).Info(fmt.Sprintf(format, v...)) } -func actionConfigInit(namespace, kubeconfig string) (*action.Configuration, error) { +func actionConfigInit(namespace, kubeconfig string, enableClientCache bool) (*action.Configuration, error) { settings := getSettings(namespace) actionConfig := new(action.Configuration) @@ -902,7 +912,7 @@ func actionConfigInit(namespace, kubeconfig string) (*action.Configuration, erro registryClient, err := registry.NewClient( registry.ClientOptDebug(settings.Debug), - registry.ClientOptEnableCache(true), + registry.ClientOptEnableCache(enableClientCache), ) if err != nil { return nil, err @@ -931,8 +941,8 @@ func isChartInstallable(ch *chart.Chart) bool { return false } -func getReleaseInfo(releaseName, releaseNamespace, kubeconfig string) (*releaseInfo, error) { - actionConfig, err := actionConfigInit(releaseNamespace, kubeconfig) +func getReleaseInfo(releaseName, releaseNamespace, kubeconfig string, enableClientCache bool) (*releaseInfo, error) { + actionConfig, err := actionConfigInit(releaseNamespace, kubeconfig, enableClientCache) if err != nil { return nil, err @@ -1084,7 +1094,7 @@ func doUninstallRelease(clusterSummary *configv1alpha1.ClusterSummary, requested requestedChart.RepositoryName)) return uninstallRelease(clusterSummary, requestedChart.ReleaseName, requestedChart.ReleaseNamespace, - kubeconfig, logger) + kubeconfig, requestedChart, logger) } // doUpgradeRelease upgrades helm release in the CAPI Cluster. @@ -1172,7 +1182,7 @@ func undeployStaleReleases(ctx context.Context, c client.Client, clusterSummary managedHelmReleases[i].Name, managedHelmReleases[i].Namespace)) _, err := getReleaseInfo(managedHelmReleases[i].Name, - managedHelmReleases[i].Namespace, kubeconfig) + managedHelmReleases[i].Namespace, kubeconfig, false) if err != nil { if errors.Is(err, driver.ErrReleaseNotFound) { continue @@ -1181,7 +1191,7 @@ func undeployStaleReleases(ctx context.Context, c client.Client, clusterSummary } if err := uninstallRelease(clusterSummary, managedHelmReleases[i].Name, managedHelmReleases[i].Namespace, - kubeconfig, logger); err != nil { + kubeconfig, nil, logger); err != nil { return nil, err } @@ -1449,7 +1459,7 @@ func collectResourcesFromManagedHelmCharts(ctx context.Context, c client.Client, l := logger.WithValues("chart", currentChart.ChartName, "releaseNamespace", currentChart.ReleaseNamespace) l.V(logs.LogDebug).Info("collecting resources for helm chart") if chartManager.CanManageChart(clusterSummary, currentChart) { - actionConfig, err := actionConfigInit(currentChart.ReleaseNamespace, kubeconfig) + actionConfig, err := actionConfigInit(currentChart.ReleaseNamespace, kubeconfig, getEnableClientCacheValue(currentChart.Options)) if err != nil { return nil, err @@ -1532,6 +1542,14 @@ func getSettings(namespace string) *cli.EnvSettings { return settings } +func getEnableClientCacheValue(options *configv1alpha1.HelmOptions) bool { + if options != nil { + return options.EnableClientCache + } + + return false +} + func getWaitHelmValue(options *configv1alpha1.HelmOptions) bool { if options != nil { return options.Wait @@ -1612,7 +1630,7 @@ func getLabelsValue(options *configv1alpha1.HelmOptions) map[string]string { } func getHelmInstallClient(requestedChart *configv1alpha1.HelmChart, kubeconfig string) (*action.Install, error) { - actionConfig, err := actionConfigInit(requestedChart.ReleaseNamespace, kubeconfig) + actionConfig, err := actionConfigInit(requestedChart.ReleaseNamespace, kubeconfig, getEnableClientCacheValue(requestedChart.Options)) if err != nil { return nil, err } @@ -1680,7 +1698,7 @@ func addExtraMetadata(ctx context.Context, requestedChart *configv1alpha1.HelmCh // Current hash of current metadata (extraLabels and extraAnnotations) metadataHash := getMetadataHash(clusterSummary) - actionConfig, err := actionConfigInit(requestedChart.ReleaseNamespace, kubeconfig) + actionConfig, err := actionConfigInit(requestedChart.ReleaseNamespace, kubeconfig, getEnableClientCacheValue(requestedChart.Options)) if err != nil { return err } diff --git a/controllers/profile_transformation_common.go b/controllers/profile_transformation_common.go index 6aa55ce9..e89aa82f 100644 --- a/controllers/profile_transformation_common.go +++ b/controllers/profile_transformation_common.go @@ -48,8 +48,6 @@ func requeueForCluster(cluster client.Object, profileCurrentlyMatching := getConsumersForEntry(clusterMap, &clusterInfo) - logger.V(logs.LogInfo).Info(fmt.Sprintf("MGIANLUC %d", profileCurrentlyMatching.Len())) - clusterLabels[clusterInfo] = cluster.GetLabels() // Get all (Cluster)Profiles previously matching this cluster and reconcile those diff --git a/manifest/deployment-agentless.yaml b/manifest/deployment-agentless.yaml index c72be7c6..37ec7798 100644 --- a/manifest/deployment-agentless.yaml +++ b/manifest/deployment-agentless.yaml @@ -51,6 +51,9 @@ spec: scheme: HTTP initialDelaySeconds: 5 periodSeconds: 10 + resources: + requests: + memory: 256Mi securityContext: allowPrivilegeEscalation: false capabilities: diff --git a/manifest/deployment-shard.yaml b/manifest/deployment-shard.yaml index 5bf3de4f..4e8e638b 100644 --- a/manifest/deployment-shard.yaml +++ b/manifest/deployment-shard.yaml @@ -51,6 +51,9 @@ spec: scheme: HTTP initialDelaySeconds: 5 periodSeconds: 10 + resources: + requests: + memory: 256Mi securityContext: allowPrivilegeEscalation: false capabilities: diff --git a/manifest/manifest.yaml b/manifest/manifest.yaml index 5394e38b..b39633df 100644 --- a/manifest/manifest.yaml +++ b/manifest/manifest.yaml @@ -564,6 +564,12 @@ spec: if set, the installation process will not validate rendered templates against the Kubernetes OpenAPI Schema Default to false type: boolean + enableClientCache: + default: false + description: EnableClientCache is a flag to enable Helm + client cache. If it is not specified, it will be set to + false. + type: boolean labels: additionalProperties: type: string @@ -1690,6 +1696,12 @@ spec: if set, the installation process will not validate rendered templates against the Kubernetes OpenAPI Schema Default to false type: boolean + enableClientCache: + default: false + description: EnableClientCache is a flag to enable Helm + client cache. If it is not specified, it will be set + to false. + type: boolean labels: additionalProperties: type: string @@ -2374,6 +2386,12 @@ spec: if set, the installation process will not validate rendered templates against the Kubernetes OpenAPI Schema Default to false type: boolean + enableClientCache: + default: false + description: EnableClientCache is a flag to enable Helm + client cache. If it is not specified, it will be set to + false. + type: boolean labels: additionalProperties: type: string @@ -3454,6 +3472,9 @@ spec: scheme: HTTP initialDelaySeconds: 5 periodSeconds: 10 + resources: + requests: + memory: 256Mi securityContext: allowPrivilegeEscalation: false capabilities: diff --git a/test/kind-cluster.yaml b/test/kind-cluster.yaml index fd123049..7b904c11 100644 --- a/test/kind-cluster.yaml +++ b/test/kind-cluster.yaml @@ -24,3 +24,10 @@ nodes: containerPath: /var/run/docker.sock - hostPath: /usr/share/zoneinfo containerPath: /usr/share/zoneinfo +- role: worker + image: kindest/node:K8S_VERSION + extraMounts: + - hostPath: /var/run/docker.sock + containerPath: /var/run/docker.sock + - hostPath: /usr/share/zoneinfo + containerPath: /usr/share/zoneinfo From b7b798987996e82b3361488c641cf5afe8b0b88e Mon Sep 17 00:00:00 2001 From: mgianluc Date: Thu, 4 Apr 2024 14:57:30 +0200 Subject: [PATCH 09/10] Prepare for release v0.27.0 --- Dockerfile | 5 ++- Makefile | 39 ++++++++++++++----- config/default/manager_auth_proxy_patch.yaml | 2 +- config/default/manager_image_patch.yaml | 2 +- go.mod | 6 +-- go.sum | 12 +++--- hack/tools/go.mod | 8 +--- hack/tools/go.sum | 21 +--------- hack/tools/tools.go | 1 - manifest/deployment-agentless.yaml | 4 +- manifest/deployment-shard.yaml | 4 +- manifest/manifest.yaml | 4 +- ...drift-detection-manager-in-mgmt-cluster.go | 2 +- ...ift-detection-manager-in-mgmt-cluster.yaml | 2 +- .../drift-detection-manager.go | 2 +- .../drift-detection-manager.yaml | 2 +- 16 files changed, 58 insertions(+), 58 deletions(-) diff --git a/Dockerfile b/Dockerfile index c1124326..1a6f2622 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,9 @@ # Build the manager binary FROM golang:1.21 as builder +ARG BUILDOS +ARG TARGETARCH + WORKDIR /workspace # Copy the Go Modules manifests COPY go.mod go.mod @@ -17,7 +20,7 @@ COPY pkg/ pkg/ COPY internal/ internal/ # Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager cmd/main.go +RUN CGO_ENABLED=0 GOOS=$BUILDOS GOARCH=$TARGETARCH go build -a -o manager cmd/main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details diff --git a/Makefile b/Makefile index 68b2e534..e24f5b65 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ ARCH ?= amd64 OS ?= $(shell uname -s | tr A-Z a-z) K8S_LATEST_VER ?= $(shell curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt) export CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME) -TAG ?= dev +TAG ?= v0.27.0 .PHONY: all all: build @@ -72,6 +72,25 @@ KUBECTL := $(TOOLS_BIN_DIR)/kubectl GOLANGCI_LINT_VERSION := "v1.55.2" CLUSTERCTL_VERSION := "v1.6.3" +KUSTOMIZE_VER := v4.5.2 +KUSTOMIZE_BIN := kustomize +KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/$(KUSTOMIZE_BIN)-$(KUSTOMIZE_VER)) +KUSTOMIZE_PKG := sigs.k8s.io/kustomize/kustomize/v4 +$(KUSTOMIZE): # Build kustomize from tools folder. + CGO_ENABLED=0 GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(KUSTOMIZE_PKG) $(KUSTOMIZE_BIN) $(KUSTOMIZE_VER) + +SETUP_ENVTEST_VER := v0.0.0-20240215143116-d0396a3d6f9f +SETUP_ENVTEST_BIN := setup-envtest +SETUP_ENVTEST := $(abspath $(TOOLS_BIN_DIR)/$(SETUP_ENVTEST_BIN)-$(SETUP_ENVTEST_VER)) +SETUP_ENVTEST_PKG := sigs.k8s.io/controller-runtime/tools/setup-envtest +setup-envtest: $(SETUP_ENVTEST) ## Set up envtest (download kubebuilder assets) + @echo KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) + +$(SETUP_ENVTEST_BIN): $(SETUP_ENVTEST) ## Build a local copy of setup-envtest. + +$(SETUP_ENVTEST): # Build setup-envtest from tools folder. + GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(SETUP_ENVTEST_PKG) $(SETUP_ENVTEST_BIN) $(SETUP_ENVTEST_VER) + $(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod # Build controller-gen from tools folder. cd $(TOOLS_DIR); $(GOBUILD) -tags=tools -o $(subst $(TOOLS_DIR)/hack/tools/,,$@) sigs.k8s.io/controller-tools/cmd/controller-gen @@ -81,9 +100,6 @@ $(ENVSUBST): $(TOOLS_DIR)/go.mod # Build envsubst from tools folder. $(GOLANGCI_LINT): # Build golangci-lint from tools folder. cd $(TOOLS_DIR); ./get-golangci-lint.sh $(GOLANGCI_LINT_VERSION) -$(SETUP_ENVTEST): $(TOOLS_DIR)/go.mod # Build setup-envtest from tools folder. - cd $(TOOLS_DIR); $(GOBUILD) -tags=tools -o $(subst $(TOOLS_DIR)/hack/tools/,,$@) sigs.k8s.io/controller-runtime/tools/setup-envtest - $(GOIMPORTS): cd $(TOOLS_DIR); $(GOBUILD) -tags=tools -o $(subst $(TOOLS_DIR)/hack/tools/,,$@) golang.org/x/tools/cmd/goimports @@ -121,7 +137,7 @@ clean: ## Remove all built tools .PHONY: manifests manifests: $(CONTROLLER_GEN) $(KUSTOMIZE) $(ENVSUBST) fmt generate ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. $(CONTROLLER_GEN) rbac:roleName=controller-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases - MANIFEST_IMG=$(CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) $(MAKE) set-manifest-image + MANIFEST_IMG=$(CONTROLLER_IMG) MANIFEST_TAG=$(TAG) $(MAKE) set-manifest-image $(KUSTOMIZE) build config/default | $(ENVSUBST) > manifest/manifest.yaml ./scripts/extract_deployment-shard.sh manifest/manifest.yaml manifest/deployment-shard.yaml ./scripts/extract_deployment-agentless.sh manifest/manifest.yaml manifest/deployment-agentless.yaml @@ -343,17 +359,22 @@ run: manifests generate fmt vet ## Run a controller from your host. .PHONY: docker-build docker-build: ## Build docker image with the manager. go generate - docker build -t $(CONTROLLER_IMG)-$(ARCH):$(TAG) . - MANIFEST_IMG=$(CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) $(MAKE) set-manifest-image + docker build --build-arg BUILDOS=linux --build-arg TARGETARCH=amd64 -t $(CONTROLLER_IMG):$(TAG) . + MANIFEST_IMG=$(CONTROLLER_IMG) MANIFEST_TAG=$(TAG) $(MAKE) set-manifest-image $(MAKE) set-manifest-pull-policy .PHONY: docker-push docker-push: ## Push docker image with the manager. - docker push $(CONTROLLER_IMG)-$(ARCH):$(TAG) + docker push $(CONTROLLER_IMG):$(TAG) + +.PHONY: docker-buildx +docker-buildx: ## docker build for multiple arch and push to docker hub + docker buildx build --push --platform linux/amd64,linux/arm64 -t $(CONTROLLER_IMG):$(TAG) . + .PHONY: load-image load-image: docker-build $(KIND) - $(KIND) load docker-image $(CONTROLLER_IMG)-$(ARCH):$(TAG) --name $(CONTROL_CLUSTER_NAME) + $(KIND) load docker-image $(CONTROLLER_IMG):$(TAG) --name $(CONTROL_CLUSTER_NAME) ##@ Deployment diff --git a/config/default/manager_auth_proxy_patch.yaml b/config/default/manager_auth_proxy_patch.yaml index c20df17e..25b0e09a 100644 --- a/config/default/manager_auth_proxy_patch.yaml +++ b/config/default/manager_auth_proxy_patch.yaml @@ -15,4 +15,4 @@ spec: - "--report-mode=0" - --shard-key= - "--v=5" - - "--version=dev" + - "--version=v0.27.0" diff --git a/config/default/manager_image_patch.yaml b/config/default/manager_image_patch.yaml index 69525b25..33a71480 100644 --- a/config/default/manager_image_patch.yaml +++ b/config/default/manager_image_patch.yaml @@ -8,5 +8,5 @@ spec: spec: containers: # Change the value of image field below to your controller image URL - - image: projectsveltos/addon-controller-amd64:dev + - image: projectsveltos/addon-controller:v0.27.0 name: controller diff --git a/go.mod b/go.mod index 707a7002..a4f062ec 100644 --- a/go.mod +++ b/go.mod @@ -12,10 +12,10 @@ require ( github.com/fluxcd/source-controller/api v1.2.4 github.com/gdexlab/go-render v1.0.1 github.com/go-logr/logr v1.4.1 - github.com/onsi/ginkgo/v2 v2.17.0 + github.com/onsi/ginkgo/v2 v2.17.1 github.com/onsi/gomega v1.32.0 github.com/pkg/errors v0.9.1 - github.com/projectsveltos/libsveltos v0.26.1-0.20240315101738-cf8cc0af064f + github.com/projectsveltos/libsveltos v0.27.0 github.com/prometheus/client_golang v1.19.0 github.com/spf13/pflag v1.0.5 github.com/yuin/gopher-lua v1.1.1 @@ -178,7 +178,7 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/apiserver v0.29.3 // indirect k8s.io/kube-openapi v0.0.0-20240103195357-a9f8850cb432 // indirect - k8s.io/kubectl v0.29.1 // indirect + k8s.io/kubectl v0.29.3 // indirect oras.land/oras-go v1.2.4 // indirect sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.0 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect diff --git a/go.sum b/go.sum index f97e6252..42cd747f 100644 --- a/go.sum +++ b/go.sum @@ -312,8 +312,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= -github.com/onsi/ginkgo/v2 v2.17.0 h1:kdnunFXpBjbzN56hcJHrXZ8M+LOkenKA7NnBzTNigTI= -github.com/onsi/ginkgo/v2 v2.17.0/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs= +github.com/onsi/ginkgo/v2 v2.17.1 h1:V++EzdbhI4ZV4ev0UTIj0PzhzOcReJFyJaLjtSF55M8= +github.com/onsi/ginkgo/v2 v2.17.1/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs= github.com/onsi/gomega v1.32.0 h1:JRYU78fJ1LPxlckP6Txi/EYqJvjtMrDC04/MM5XRHPk= github.com/onsi/gomega v1.32.0/go.mod h1:a4x4gW6Pz2yK1MAmvluYme5lvYTn61afQ2ETw/8n4Lg= github.com/opencontainers/go-digest v1.0.1-0.20220411205349-bde1400a84be h1:f2PlhC9pm5sqpBZFvnAoKj+KzXRzbjFMA+TqXfJdgho= @@ -333,8 +333,8 @@ 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/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY= github.com/poy/onpar v1.1.2/go.mod h1:6X8FLNoxyr9kkmnlqpK6LSoiOtrO6MICtWwEuWkLjzg= -github.com/projectsveltos/libsveltos v0.26.1-0.20240315101738-cf8cc0af064f h1:sgLZf350i4S18n2mb7SixnDZFrfFyScPj5wmprxZx+I= -github.com/projectsveltos/libsveltos v0.26.1-0.20240315101738-cf8cc0af064f/go.mod h1:RP3Omk5oY0w8sCbhZInVJuLdu+/dUS2Q/Knk6la8Hu4= +github.com/projectsveltos/libsveltos v0.27.0 h1:67fetkwg5toyu/GiOMjfXug13DAnxAcemClWtTcAw9Q= +github.com/projectsveltos/libsveltos v0.27.0/go.mod h1:Uq3KYj5LKQYttA3yVb0O/V5Uvi2Qy7B23tnB5fBAMFg= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g= @@ -583,8 +583,8 @@ k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw= k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= k8s.io/kube-openapi v0.0.0-20240103195357-a9f8850cb432 h1:+XYBQU3ZKUu60H6fEnkitTTabGoKfIG8zczhZBENu9o= k8s.io/kube-openapi v0.0.0-20240103195357-a9f8850cb432/go.mod h1:Pa1PvrP7ACSkuX6I7KYomY6cmMA0Tx86waBhDUgoKPw= -k8s.io/kubectl v0.29.1 h1:rWnW3hi/rEUvvg7jp4iYB68qW5un/urKbv7fu3Vj0/s= -k8s.io/kubectl v0.29.1/go.mod h1:SZzvLqtuOJYSvZzPZR9weSuP0wDQ+N37CENJf0FhDF4= +k8s.io/kubectl v0.29.3 h1:RuwyyIU42MAISRIePaa8Q7A3U74Q9P4MoJbDFz9o3us= +k8s.io/kubectl v0.29.3/go.mod h1:yCxfY1dbwgVdEt2zkJ6d5NNLOhhWgTyrqACIoFhpdd4= k8s.io/utils v0.0.0-20240310230437-4693a0247e57 h1:gbqbevonBh57eILzModw6mrkbwM0gQBEuevE/AaBsHY= k8s.io/utils v0.0.0-20240310230437-4693a0247e57/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= oras.land/oras-go v1.2.4 h1:djpBY2/2Cs1PV87GSJlxv4voajVOMZxqqtq9AB8YNvY= diff --git a/hack/tools/go.mod b/hack/tools/go.mod index 07e894ee..913b438a 100644 --- a/hack/tools/go.mod +++ b/hack/tools/go.mod @@ -4,10 +4,9 @@ go 1.21 require ( github.com/a8m/envsubst v1.4.2 - github.com/onsi/ginkgo/v2 v2.17.0 + github.com/onsi/ginkgo/v2 v2.17.1 golang.org/x/oauth2 v0.18.0 k8s.io/client-go v0.29.3 - sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20240313184151-cb5107b36b64 sigs.k8s.io/controller-tools v0.14.0 sigs.k8s.io/kind v0.22.0 ) @@ -21,7 +20,6 @@ require ( github.com/evanphx/json-patch/v5 v5.8.0 // indirect github.com/fatih/color v1.16.0 // indirect github.com/go-logr/logr v1.4.1 // indirect - github.com/go-logr/zapr v1.3.0 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/gobuffalo/flect v1.0.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect @@ -37,12 +35,8 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml v1.9.4 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/spf13/afero v1.6.0 // indirect github.com/spf13/cobra v1.8.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - go.uber.org/goleak v1.3.0 // indirect - go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.26.0 // indirect golang.org/x/mod v0.14.0 // indirect golang.org/x/net v0.22.0 // indirect golang.org/x/sys v0.18.0 // indirect diff --git a/hack/tools/go.sum b/hack/tools/go.sum index ca0319e9..53087691 100644 --- a/hack/tools/go.sum +++ b/hack/tools/go.sum @@ -28,8 +28,6 @@ github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyT github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= 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/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ= -github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg= github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= @@ -70,7 +68,6 @@ 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/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -97,8 +94,8 @@ github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.17.0 h1:kdnunFXpBjbzN56hcJHrXZ8M+LOkenKA7NnBzTNigTI= -github.com/onsi/ginkgo/v2 v2.17.0/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs= +github.com/onsi/ginkgo/v2 v2.17.1 h1:V++EzdbhI4ZV4ev0UTIj0PzhzOcReJFyJaLjtSF55M8= +github.com/onsi/ginkgo/v2 v2.17.1/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs= github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM= @@ -106,14 +103,11 @@ github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCko github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= 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/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY= -github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g= github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= @@ -123,7 +117,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= @@ -132,14 +125,7 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 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= -go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= -go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= -go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= -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-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 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/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= @@ -200,7 +186,6 @@ gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= @@ -221,8 +206,6 @@ k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/A k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA= k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI= k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20240313184151-cb5107b36b64 h1:CxmsLoKUF1PCEoAXrbXzNud5EtSxQAdo9zbYMkY4Jko= -sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20240313184151-cb5107b36b64/go.mod h1:TF/lVLWS+JNNaVqJuDDictY2hZSXSsIHCx4FClMvqFg= sigs.k8s.io/controller-tools v0.14.0 h1:rnNoCC5wSXlrNoBKKzL70LNJKIQKEzT6lloG6/LF73A= sigs.k8s.io/controller-tools v0.14.0/go.mod h1:TV7uOtNNnnR72SpzhStvPkoS/U5ir0nMudrkrC4M9Sc= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= diff --git a/hack/tools/tools.go b/hack/tools/tools.go index 4a81af71..946f3cbf 100644 --- a/hack/tools/tools.go +++ b/hack/tools/tools.go @@ -26,7 +26,6 @@ import ( _ "github.com/onsi/ginkgo/v2/ginkgo" _ "golang.org/x/oauth2/google" _ "k8s.io/client-go/plugin/pkg/client/auth/azure" - _ "sigs.k8s.io/controller-runtime/tools/setup-envtest" _ "sigs.k8s.io/controller-tools/cmd/controller-gen" _ "sigs.k8s.io/kind" ) diff --git a/manifest/deployment-agentless.yaml b/manifest/deployment-agentless.yaml index 37ec7798..3c3a42d1 100644 --- a/manifest/deployment-agentless.yaml +++ b/manifest/deployment-agentless.yaml @@ -23,10 +23,10 @@ spec: - --report-mode=0 - --agent-in-mgmt-cluster - --v=5 - - --version=dev + - --version=v0.27.0 command: - /manager - image: projectsveltos/addon-controller-amd64:dev + image: projectsveltos/addon-controller:v0.27.0 livenessProbe: failureThreshold: 3 httpGet: diff --git a/manifest/deployment-shard.yaml b/manifest/deployment-shard.yaml index 4e8e638b..de1fa635 100644 --- a/manifest/deployment-shard.yaml +++ b/manifest/deployment-shard.yaml @@ -23,10 +23,10 @@ spec: - --report-mode=0 - --shard-key={{.SHARD}} - --v=5 - - --version=dev + - --version=v0.27.0 command: - /manager - image: projectsveltos/addon-controller-amd64:dev + image: projectsveltos/addon-controller:v0.27.0 livenessProbe: failureThreshold: 3 httpGet: diff --git a/manifest/manifest.yaml b/manifest/manifest.yaml index b39633df..8433f2f0 100644 --- a/manifest/manifest.yaml +++ b/manifest/manifest.yaml @@ -3444,10 +3444,10 @@ spec: - --report-mode=0 - --shard-key= - --v=5 - - --version=dev + - --version=v0.27.0 command: - /manager - image: projectsveltos/addon-controller-amd64:dev + image: projectsveltos/addon-controller:v0.27.0 livenessProbe: failureThreshold: 3 httpGet: diff --git a/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.go b/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.go index a96e1794..2220fe79 100644 --- a/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.go +++ b/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.go @@ -46,7 +46,7 @@ spec: - --run-mode=do-not-send-updates command: - /manager - image: projectsveltos/drift-detection-manager-amd64:main + image: projectsveltos/drift-detection-manager:v0.27.0 livenessProbe: failureThreshold: 3 httpGet: diff --git a/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.yaml b/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.yaml index 110ae1e0..5a9a2adf 100644 --- a/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.yaml +++ b/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.yaml @@ -28,7 +28,7 @@ spec: - --run-mode=do-not-send-updates command: - /manager - image: projectsveltos/drift-detection-manager-amd64:main + image: projectsveltos/drift-detection-manager:v0.27.0 livenessProbe: failureThreshold: 3 httpGet: diff --git a/pkg/drift-detection/drift-detection-manager.go b/pkg/drift-detection/drift-detection-manager.go index edc74d1d..0b31836e 100644 --- a/pkg/drift-detection/drift-detection-manager.go +++ b/pkg/drift-detection/drift-detection-manager.go @@ -130,7 +130,7 @@ spec: - --run-mode=do-not-send-updates command: - /manager - image: projectsveltos/drift-detection-manager-amd64:main + image: projectsveltos/drift-detection-manager:v0.27.0 livenessProbe: failureThreshold: 3 httpGet: diff --git a/pkg/drift-detection/drift-detection-manager.yaml b/pkg/drift-detection/drift-detection-manager.yaml index 3cf2cacd..bd655f94 100644 --- a/pkg/drift-detection/drift-detection-manager.yaml +++ b/pkg/drift-detection/drift-detection-manager.yaml @@ -112,7 +112,7 @@ spec: - --run-mode=do-not-send-updates command: - /manager - image: projectsveltos/drift-detection-manager-amd64:main + image: projectsveltos/drift-detection-manager:v0.27.0 livenessProbe: failureThreshold: 3 httpGet: From 90c0dd647cdb086c4adfa3164eb6f46024eba6a6 Mon Sep 17 00:00:00 2001 From: mgianluc Date: Fri, 5 Apr 2024 17:55:23 +0200 Subject: [PATCH 10/10] Prepare dev to main merge Post release v0.27.0 --- Makefile | 10 +--------- config/default/manager_auth_proxy_patch.yaml | 2 +- config/default/manager_image_patch.yaml | 2 +- go.mod | 2 +- go.sum | 4 ++-- manifest/deployment-agentless.yaml | 4 ++-- manifest/deployment-shard.yaml | 4 ++-- manifest/manifest.yaml | 4 ++-- .../drift-detection-manager-in-mgmt-cluster.go | 2 +- .../drift-detection-manager-in-mgmt-cluster.yaml | 2 +- pkg/drift-detection/drift-detection-manager.go | 2 +- pkg/drift-detection/drift-detection-manager.yaml | 2 +- 12 files changed, 16 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index e24f5b65..47c0e854 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ ARCH ?= amd64 OS ?= $(shell uname -s | tr A-Z a-z) K8S_LATEST_VER ?= $(shell curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt) export CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME) -TAG ?= v0.27.0 +TAG ?= main .PHONY: all all: build @@ -62,7 +62,6 @@ CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen ENVSUBST := $(TOOLS_BIN_DIR)/envsubst GOIMPORTS := $(TOOLS_BIN_DIR)/goimports GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint -KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize GINKGO := $(TOOLS_BIN_DIR)/ginkgo SETUP_ENVTEST := $(TOOLS_BIN_DIR)/setup_envs CLUSTERCTL := $(TOOLS_BIN_DIR)/clusterctl @@ -117,13 +116,6 @@ $(KUBECTL): curl -L https://storage.googleapis.com/kubernetes-release/release/$(K8S_LATEST_VER)/bin/$(OS)/$(ARCH)/kubectl -o $@ chmod +x $@ -KUSTOMIZE_VER := v4.5.2 -KUSTOMIZE_BIN := kustomize -KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/$(KUSTOMIZE_BIN)-$(KUSTOMIZE_VER)) -KUSTOMIZE_PKG := sigs.k8s.io/kustomize/kustomize/v4 -$(KUSTOMIZE): # Build kustomize from tools folder. - CGO_ENABLED=0 GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(KUSTOMIZE_PKG) $(KUSTOMIZE_BIN) $(KUSTOMIZE_VER) - .PHONY: tools tools: $(CONTROLLER_GEN) $(ENVSUBST) $(KUSTOMIZE) $(SETUP_ENVTEST) $(GOLANGCI_LINT) $(GOIMPORTS) $(GINKGO) $(CLUSTERCTL) $(KIND) $(KUBECTL) ## build all tools diff --git a/config/default/manager_auth_proxy_patch.yaml b/config/default/manager_auth_proxy_patch.yaml index 25b0e09a..a03918f5 100644 --- a/config/default/manager_auth_proxy_patch.yaml +++ b/config/default/manager_auth_proxy_patch.yaml @@ -15,4 +15,4 @@ spec: - "--report-mode=0" - --shard-key= - "--v=5" - - "--version=v0.27.0" + - "--version=main" diff --git a/config/default/manager_image_patch.yaml b/config/default/manager_image_patch.yaml index 33a71480..1b408a59 100644 --- a/config/default/manager_image_patch.yaml +++ b/config/default/manager_image_patch.yaml @@ -8,5 +8,5 @@ spec: spec: containers: # Change the value of image field below to your controller image URL - - image: projectsveltos/addon-controller:v0.27.0 + - image: projectsveltos/addon-controller:main name: controller diff --git a/go.mod b/go.mod index a4f062ec..3c1e1b91 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/onsi/ginkgo/v2 v2.17.1 github.com/onsi/gomega v1.32.0 github.com/pkg/errors v0.9.1 - github.com/projectsveltos/libsveltos v0.27.0 + github.com/projectsveltos/libsveltos v0.27.1-0.20240405132615-9e1a36ca5c8f github.com/prometheus/client_golang v1.19.0 github.com/spf13/pflag v1.0.5 github.com/yuin/gopher-lua v1.1.1 diff --git a/go.sum b/go.sum index 42cd747f..954b33c1 100644 --- a/go.sum +++ b/go.sum @@ -333,8 +333,8 @@ 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/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY= github.com/poy/onpar v1.1.2/go.mod h1:6X8FLNoxyr9kkmnlqpK6LSoiOtrO6MICtWwEuWkLjzg= -github.com/projectsveltos/libsveltos v0.27.0 h1:67fetkwg5toyu/GiOMjfXug13DAnxAcemClWtTcAw9Q= -github.com/projectsveltos/libsveltos v0.27.0/go.mod h1:Uq3KYj5LKQYttA3yVb0O/V5Uvi2Qy7B23tnB5fBAMFg= +github.com/projectsveltos/libsveltos v0.27.1-0.20240405132615-9e1a36ca5c8f h1:FCmjCYxO/5irmocHXcuVfg9fT74NoN1G4k64/SwWdMo= +github.com/projectsveltos/libsveltos v0.27.1-0.20240405132615-9e1a36ca5c8f/go.mod h1:Uq3KYj5LKQYttA3yVb0O/V5Uvi2Qy7B23tnB5fBAMFg= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g= diff --git a/manifest/deployment-agentless.yaml b/manifest/deployment-agentless.yaml index 3c3a42d1..b92d27f0 100644 --- a/manifest/deployment-agentless.yaml +++ b/manifest/deployment-agentless.yaml @@ -23,10 +23,10 @@ spec: - --report-mode=0 - --agent-in-mgmt-cluster - --v=5 - - --version=v0.27.0 + - --version=main command: - /manager - image: projectsveltos/addon-controller:v0.27.0 + image: projectsveltos/addon-controller:main livenessProbe: failureThreshold: 3 httpGet: diff --git a/manifest/deployment-shard.yaml b/manifest/deployment-shard.yaml index de1fa635..4c9eed16 100644 --- a/manifest/deployment-shard.yaml +++ b/manifest/deployment-shard.yaml @@ -23,10 +23,10 @@ spec: - --report-mode=0 - --shard-key={{.SHARD}} - --v=5 - - --version=v0.27.0 + - --version=main command: - /manager - image: projectsveltos/addon-controller:v0.27.0 + image: projectsveltos/addon-controller:main livenessProbe: failureThreshold: 3 httpGet: diff --git a/manifest/manifest.yaml b/manifest/manifest.yaml index 8433f2f0..9a4bf482 100644 --- a/manifest/manifest.yaml +++ b/manifest/manifest.yaml @@ -3444,10 +3444,10 @@ spec: - --report-mode=0 - --shard-key= - --v=5 - - --version=v0.27.0 + - --version=main command: - /manager - image: projectsveltos/addon-controller:v0.27.0 + image: projectsveltos/addon-controller:main livenessProbe: failureThreshold: 3 httpGet: diff --git a/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.go b/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.go index 2220fe79..92b349e3 100644 --- a/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.go +++ b/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.go @@ -46,7 +46,7 @@ spec: - --run-mode=do-not-send-updates command: - /manager - image: projectsveltos/drift-detection-manager:v0.27.0 + image: projectsveltos/drift-detection-manager:main livenessProbe: failureThreshold: 3 httpGet: diff --git a/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.yaml b/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.yaml index 5a9a2adf..8903ca69 100644 --- a/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.yaml +++ b/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.yaml @@ -28,7 +28,7 @@ spec: - --run-mode=do-not-send-updates command: - /manager - image: projectsveltos/drift-detection-manager:v0.27.0 + image: projectsveltos/drift-detection-manager:main livenessProbe: failureThreshold: 3 httpGet: diff --git a/pkg/drift-detection/drift-detection-manager.go b/pkg/drift-detection/drift-detection-manager.go index 0b31836e..e1a12ba6 100644 --- a/pkg/drift-detection/drift-detection-manager.go +++ b/pkg/drift-detection/drift-detection-manager.go @@ -130,7 +130,7 @@ spec: - --run-mode=do-not-send-updates command: - /manager - image: projectsveltos/drift-detection-manager:v0.27.0 + image: projectsveltos/drift-detection-manager:main livenessProbe: failureThreshold: 3 httpGet: diff --git a/pkg/drift-detection/drift-detection-manager.yaml b/pkg/drift-detection/drift-detection-manager.yaml index bd655f94..3f46e6ea 100644 --- a/pkg/drift-detection/drift-detection-manager.yaml +++ b/pkg/drift-detection/drift-detection-manager.yaml @@ -112,7 +112,7 @@ spec: - --run-mode=do-not-send-updates command: - /manager - image: projectsveltos/drift-detection-manager:v0.27.0 + image: projectsveltos/drift-detection-manager:main livenessProbe: failureThreshold: 3 httpGet: