diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..0abe32d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,50 @@ +name: Release + +on: + workflow_dispatch: + inputs: + image_tag: + type: string + description: "image_tag" + required: true + default: "" + + push: + +permissions: + contents: read + packages: write + +jobs: + build-image: + runs-on: ubuntu-latest + name: plugin/helm-charts image + steps: + - uses: actions/checkout@v4 + + - uses: kloudlite/actions/setup-cache-go@v1 + with: + cache_key: "run-${{ matrix.platform }}-${{ matrix.arch }}" + working_directory: . + + - uses: kloudlite/actions/generate-image-tag@v1 + + - uses: kloudlite/actions/setup-nix-cachix@v1 + with: + flake_lock: "./flake.lock" + nix_develop_arguments: ".#default" + cachix_cache_name: ${{ secrets.CACHIX_CACHE_NAME }} + cachix_auth_token: ${{ secrets.CACHIX_AUTH_TOKEN }} + + - uses: kloudlite/actions/setup-docker@v1 + with: + docker_registry: "ghcr.io" + docker_username: ${{ github.actor }} + docker_password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build Binary + shell: bash + env: + IMAGE: "ghcr.io/${{ github.repository }}:$IMAGE_TAG" + run: |+ + run build image=$IMAGE diff --git a/Runfile.yml b/Runfile.yml index 0d36e7a..a182f2f 100644 --- a/Runfile.yml +++ b/Runfile.yml @@ -59,7 +59,8 @@ tasks: env: CGO_ENABLED: 0 GOARCH: - required: true + default: + sh: "go env GOARCH" cmd: - go build -ldflags='-s -w' -o ./bin/plugin-helm-controller-$GOARCH ./cmd @@ -69,8 +70,8 @@ tasks: image: required: true cmd: - - GOARCH=amd64 run2 go:build || echo "hi" - - GOARCH=arm64 run2 go:build || echo "hello" + - GOARCH=amd64 run go:build || echo "hi" + - GOARCH=arm64 run go:build || echo "hello" - docker buildx build -t "$image" --output=type=image,compression=zstd,force-compression=true,compression-level=12,push=true --platform linux/amd64,linux/arm64 --build-arg BINARY=./bin/plugin-helm-controller . diff --git a/api/v1/helmchart_types.go b/api/v1/helmchart_types.go index f1b5d54..9825894 100644 --- a/api/v1/helmchart_types.go +++ b/api/v1/helmchart_types.go @@ -17,9 +17,9 @@ limitations under the License. package v1 import ( - ct "github.com/kloudlite/operator/apis/common-types" - rApi "github.com/kloudlite/operator/pkg/operator" - "github.com/kloudlite/operator/pkg/plugin" + "github.com/kloudlite/operator/toolkit/plugin" + rApi "github.com/kloudlite/operator/toolkit/reconciler" + types "github.com/kloudlite/operator/toolkit/types" corev1 "k8s.io/api/core/v1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -36,7 +36,7 @@ type HelmJobVars struct { Tolerations []corev1.Toleration `json:"tolerations,omitempty"` Affinity *corev1.Affinity `json:"affinity,omitempty"` - Resources ct.Resources `json:"resources"` + Resource types.Resource `json:"resource"` } // HelmChartSpec defines the desired state of HelmChart. @@ -73,7 +73,7 @@ type HelmChart struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec HelmChartSpec `json:"spec,omitempty"` + Spec HelmChartSpec `json:"spec,omitempty"` Export plugin.Export `json:"export,omitempty"` Status HelmChartStatus `json:"status,omitempty"` diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index bf854f7..d8a3e17 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -167,7 +167,7 @@ func (in *HelmJobVars) DeepCopyInto(out *HelmJobVars) { *out = new(corev1.Affinity) (*in).DeepCopyInto(*out) } - in.Resources.DeepCopyInto(&out.Resources) + in.Resource.DeepCopyInto(&out.Resource) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HelmJobVars. diff --git a/config/crd/bases/plugin-helm-chart.kloudlite.github.com_helmcharts.yaml b/config/crd/bases/plugin-helm-chart.kloudlite.github.com_helmcharts.yaml index f4fa0c8..fc8c3f1 100644 --- a/config/crd/bases/plugin-helm-chart.kloudlite.github.com_helmcharts.yaml +++ b/config/crd/bases/plugin-helm-chart.kloudlite.github.com_helmcharts.yaml @@ -1010,7 +1010,7 @@ spec: additionalProperties: type: string type: object - resources: + resource: properties: cpu: properties: @@ -1036,19 +1036,6 @@ spec: - max - min type: object - storage: - properties: - size: - pattern: '[\d]+(M|G)i$' - type: string - storageClass: - type: string - required: - - size - type: object - required: - - cpu - - memory type: object tolerations: items: @@ -1089,7 +1076,7 @@ spec: type: object type: array required: - - resources + - resource type: object postInstall: type: string @@ -1157,9 +1144,6 @@ spec: lastReconcileTime: format: date-time type: string - message: - type: object - x-kubernetes-preserve-unknown-fields: true releaseNotes: type: string releaseStatus: diff --git a/constants/constants.go b/constants/constants.go index ddac021..8f8efde 100644 --- a/constants/constants.go +++ b/constants/constants.go @@ -3,3 +3,7 @@ package constants const ( ProjectDomain string = "plugin-helm-charts.kloudlite.github.com" ) + +const ( + ForceReconcile string = "plugin-helm-chart.kloudlite.github.com/force-reconcile" +) diff --git a/flake.nix b/flake.nix index 9a6f32a..6cb21a8 100644 --- a/flake.nix +++ b/flake.nix @@ -34,8 +34,8 @@ name = "run"; pname = "run"; src = fetchurl { - url = "https://github.com/nxtcoder17/Runfile/releases/download/nightly/run-linux-amd64"; - sha256 = "sha256-H6On0hZrPjm679mSb2gdcj++aQjLPo9Z7F1m/PDsBTo="; + url = "https://github.com/nxtcoder17/Runfile/releases/download/v1.1.2/run-linux-amd64"; + sha256 = "sha256-vAnENb2BhIKHSkx19pTytlv03RIOzUxoxn2nRrk6Zd8="; }; unpackPhase = ":"; buildInputs = [ curl ]; diff --git a/go.mod b/go.mod index 89c3921..04257f7 100644 --- a/go.mod +++ b/go.mod @@ -4,15 +4,14 @@ go 1.23.0 require ( github.com/codingconcepts/env v0.0.0-20200821220118-a8fbf8d84482 - github.com/kloudlite/operator v1.1.1 + github.com/kloudlite/operator/toolkit v0.0.0-20241213022814-9012d5473c3d github.com/onsi/ginkgo/v2 v2.19.0 github.com/onsi/gomega v1.33.1 - github.com/valyala/fasttemplate v1.2.2 - k8s.io/api v0.31.0 + k8s.io/api v0.31.3 k8s.io/apiextensions-apiserver v0.31.0 - k8s.io/apimachinery v0.31.0 + k8s.io/apimachinery v0.31.3 k8s.io/client-go v0.31.0 - sigs.k8s.io/controller-runtime v0.19.0 + sigs.k8s.io/controller-runtime v0.19.2 sigs.k8s.io/yaml v1.4.0 ) @@ -27,12 +26,13 @@ require ( github.com/blang/semver/v4 v4.0.0 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/charmbracelet/lipgloss v0.10.0 // indirect + github.com/charmbracelet/lipgloss v1.0.0 // indirect github.com/charmbracelet/log v0.4.0 // indirect + github.com/charmbracelet/x/ansi v0.4.2 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/evanphx/json-patch/v5 v5.9.0 // indirect - github.com/fatih/color v1.15.0 // indirect + github.com/fatih/color v1.18.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/fxamacker/cbor/v2 v2.7.0 // indirect @@ -60,6 +60,7 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect + github.com/kloudlite/operator v1.1.2-0.20241202071018-cd50cb6011cd // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/matoous/go-nanoid/v2 v2.0.0 // indirect @@ -70,7 +71,6 @@ require ( github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/muesli/reflow v0.3.0 // indirect github.com/muesli/termenv v0.15.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pkg/errors v0.9.1 // indirect @@ -84,7 +84,6 @@ require ( github.com/spf13/cobra v1.8.1 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/stoewer/go-strcase v1.2.0 // indirect - github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/x448/float16 v0.8.4 // indirect github.com/yext/yerrors v0.0.0-20230716030415-7ebf68e23868 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect @@ -96,18 +95,18 @@ require ( go.opentelemetry.io/otel/trace v1.28.0 // indirect go.opentelemetry.io/proto/otlp v1.3.1 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.26.0 // indirect + go.uber.org/zap v1.27.0 // indirect golang.org/x/crypto v0.24.0 // indirect golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect golang.org/x/net v0.26.0 // indirect golang.org/x/oauth2 v0.21.0 // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.21.0 // indirect + golang.org/x/sys v0.25.0 // indirect golang.org/x/term v0.21.0 // indirect golang.org/x/text v0.16.0 // indirect golang.org/x/time v0.5.0 // indirect golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect - golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect + golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect @@ -125,5 +124,3 @@ require ( sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect ) - -// replace github.com/kloudlite/operator => /home/nxtcoder17/workspace/kloudlite/operator diff --git a/go.sum b/go.sum index 9f963db..c9df46f 100644 --- a/go.sum +++ b/go.sum @@ -19,10 +19,12 @@ github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK3 github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMtwg/AFW3s= -github.com/charmbracelet/lipgloss v0.10.0/go.mod h1:Wig9DSfvANsxqkRsqj6x87irdy123SR4dOXlKa91ciE= +github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg= +github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo= github.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8ZM= github.com/charmbracelet/log v0.4.0/go.mod h1:63bXt/djrizTec0l11H20t8FDSvA4CRZJ1KH22MdptM= +github.com/charmbracelet/x/ansi v0.4.2 h1:0JM6Aj/g/KC154/gOP4vfxun0ff6itogDYk41kof+qk= +github.com/charmbracelet/x/ansi v0.4.2/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= github.com/codingconcepts/env v0.0.0-20200821220118-a8fbf8d84482 h1:5/aEFreBh9hH/0G+33xtczJCvMaulqsm9nDuu2BZUEo= github.com/codingconcepts/env v0.0.0-20200821220118-a8fbf8d84482/go.mod h1:TM9ug+H/2cI3EjyIDr5xKCkFGyNE59URgH1wu5NyU8E= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= @@ -37,8 +39,8 @@ github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ github.com/evanphx/json-patch v5.7.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg= github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= -github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= -github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= +github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= +github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= @@ -104,6 +106,12 @@ 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/kloudlite/operator v1.1.2-0.20241202071018-cd50cb6011cd h1:mQD6D6YvHrwf3jjrmdjXRn7oVwkJP7YgZ80dkWpIE9w= +github.com/kloudlite/operator v1.1.2-0.20241202071018-cd50cb6011cd/go.mod h1:S6HRSjbED7FH0/sncXt2zxpfVjh/KROhdfFYY/mkf0s= +github.com/kloudlite/operator/toolkit v0.0.0-20241202071018-cd50cb6011cd h1:r31ZS81lcpkY1RsrdQi9zoN88PXPYujotJI6ntL3b4w= +github.com/kloudlite/operator/toolkit v0.0.0-20241202071018-cd50cb6011cd/go.mod h1:O38D51XS/ugqMOkoR+sAworO6DpVyWli5GOGZ9F4/6g= +github.com/kloudlite/operator/toolkit v0.0.0-20241213022814-9012d5473c3d h1:l1umRsYqmN2f4+fpKziz3zJfzxnMW+4YO8QIhYE3jkE= +github.com/kloudlite/operator/toolkit v0.0.0-20241213022814-9012d5473c3d/go.mod h1:2oy4q08iYDKoYtAPFBeRupw4yfqqBlFPGgaA33vfyxw= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= @@ -123,7 +131,6 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= @@ -137,8 +144,6 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= -github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo= github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= @@ -160,7 +165,6 @@ github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= -github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= @@ -191,10 +195,6 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= -github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= -github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/yext/yerrors v0.0.0-20230716030415-7ebf68e23868 h1:WHNghr01OczJetcg4v+Znzb1GhGsocXm+bMjRMhRv1c= @@ -222,8 +222,8 @@ 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= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -263,8 +263,8 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= @@ -289,8 +289,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= -golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= +golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= +golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw= gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY= google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 h1:7whR9kGa5LUwFtpLm2ArCEejtnxlGeLbAyjFY8sGNFw= @@ -317,12 +317,12 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0/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.31.0 h1:b9LiSjR2ym/SzTOlfMHm1tr7/21aD7fSkqgD/CVJBCo= -k8s.io/api v0.31.0/go.mod h1:0YiFF+JfFxMM6+1hQei8FY8M7s1Mth+z/q7eF1aJkTE= +k8s.io/api v0.31.3 h1:umzm5o8lFbdN/hIXbrK9oRpOproJO62CV1zqxXrLgk8= +k8s.io/api v0.31.3/go.mod h1:UJrkIp9pnMOI9K2nlL6vwpxRzzEX5sWgn8kGQe92kCE= k8s.io/apiextensions-apiserver v0.31.0 h1:fZgCVhGwsclj3qCw1buVXCV6khjRzKC5eCFt24kyLSk= k8s.io/apiextensions-apiserver v0.31.0/go.mod h1:b9aMDEYaEe5sdK+1T0KU78ApR/5ZVp4i56VacZYEHxk= -k8s.io/apimachinery v0.31.0 h1:m9jOiSr3FoSSL5WO9bjm1n6B9KROYYgNZOb4tyZ1lBc= -k8s.io/apimachinery v0.31.0/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo= +k8s.io/apimachinery v0.31.3 h1:6l0WhcYgasZ/wk9ktLq5vLaoXJJr5ts6lkaQzgeYPq4= +k8s.io/apimachinery v0.31.3/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo= k8s.io/apiserver v0.31.0 h1:p+2dgJjy+bk+B1Csz+mc2wl5gHwvNkC9QJV+w55LVrY= k8s.io/apiserver v0.31.0/go.mod h1:KI9ox5Yu902iBnnyMmy7ajonhKnkeZYJhTZ/YI+WEMk= k8s.io/client-go v0.31.0 h1:QqEJzNjbN2Yv1H79SsS+SWnXkBgVu4Pj3CJQgbx0gI8= @@ -337,8 +337,8 @@ k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1 k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 h1:2770sDpzrjjsAtVhSeUFseziht227YAWYHLGNM8QPwY= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3/go.mod h1:Ve9uj1L+deCXFrPOk1LpFXqTg7LCFzFso6PA48q/XZw= -sigs.k8s.io/controller-runtime v0.19.0 h1:nWVM7aq+Il2ABxwiCizrVDSlmDcshi9llbaFbC0ji/Q= -sigs.k8s.io/controller-runtime v0.19.0/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4= +sigs.k8s.io/controller-runtime v0.19.2 h1:3sPrF58XQEPzbE8T81TN6selQIMGbtYwuaJ6eDssDF8= +sigs.k8s.io/controller-runtime v0.19.2/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4= diff --git a/internal/controller/helmchart_controller.go b/internal/controller/helmchart_controller.go index aa54136..4a2eaf2 100644 --- a/internal/controller/helmchart_controller.go +++ b/internal/controller/helmchart_controller.go @@ -18,18 +18,18 @@ package controller import ( "context" + "encoding/json" "fmt" "slices" "strings" "time" - "github.com/kloudlite/operator/pkg/constants" - "github.com/kloudlite/operator/pkg/errors" - "github.com/kloudlite/operator/pkg/logging" - rApi "github.com/kloudlite/operator/pkg/operator" - stepResult "github.com/kloudlite/operator/pkg/operator/step-result" - "github.com/kloudlite/operator/pkg/plugin" - constants2 "github.com/kloudlite/plugin-helm-chart/constants" + "github.com/kloudlite/operator/toolkit/errors" + "github.com/kloudlite/operator/toolkit/logging" + "github.com/kloudlite/operator/toolkit/plugin" + rApi "github.com/kloudlite/operator/toolkit/reconciler" + stepResult "github.com/kloudlite/operator/toolkit/reconciler/step-result" + "github.com/kloudlite/plugin-helm-chart/constants" "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -37,9 +37,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/yaml" - fn "github.com/kloudlite/operator/pkg/functions" - job_manager "github.com/kloudlite/operator/pkg/job-helper" - "github.com/kloudlite/operator/pkg/kubectl" + fn "github.com/kloudlite/operator/toolkit/functions" + job_manager "github.com/kloudlite/operator/toolkit/job-helper" + "github.com/kloudlite/operator/toolkit/kubectl" v1 "github.com/kloudlite/plugin-helm-chart/api/v1" "github.com/kloudlite/plugin-helm-chart/internal/controller/templates" "github.com/kloudlite/plugin-helm-chart/internal/env" @@ -116,7 +116,7 @@ func (r *HelmChartReconciler) Reconcile(ctx context.Context, request ctrl.Reques return step.ReconcilerResponse() } - if step := req.EnsureFinalizers(constants.CommonFinalizer); !step.ShouldProceed() { + if step := req.EnsureFinalizers(rApi.CommonFinalizer); !step.ShouldProceed() { return step.ReconcilerResponse() } @@ -175,7 +175,7 @@ func (r *HelmChartReconciler) ensureJobRBAC(req *rApi.Request[*v1.HelmChart]) st if jobSvcAcc.Annotations == nil { jobSvcAcc.Annotations = make(map[string]string, 1) } - jobSvcAcc.Annotations[constants.DescriptionKey] = "Service account used by helm charts to run helm release jobs" + jobSvcAcc.Annotations[rApi.AnnotationDescriptionKey] = "Service account used by helm charts to run helm release jobs" return nil }); err != nil { return check.Failed(err) @@ -186,7 +186,7 @@ func (r *HelmChartReconciler) ensureJobRBAC(req *rApi.Request[*v1.HelmChart]) st if crb.Annotations == nil { crb.Annotations = make(map[string]string, 1) } - crb.Annotations[constants.DescriptionKey] = "Cluster role binding used by helm charts to run helm release jobs" + crb.Annotations[rApi.AnnotationDescriptionKey] = "Cluster role binding used by helm charts to run helm release jobs" crb.RoleRef = rbacv1.RoleRef{ APIGroup: "rbac.authorization.k8s.io", @@ -241,9 +241,9 @@ func getJobName(suffix string) string { } const ( - LabelHelmJobType string = constants2.ProjectDomain + "/helm.job-type" - LabelHelmChartName string = constants2.ProjectDomain + "/helm.chart-name" - LabelResourceGeneration string = constants2.ProjectDomain + "/helm.resource-generation" + LabelHelmJobType string = constants.ProjectDomain + "/helm.job-type" + LabelHelmChartName string = constants.ProjectDomain + "/helm.chart-name" + LabelResourceGeneration string = constants.ProjectDomain + "/helm.resource-generation" ) func (r *HelmChartReconciler) startInstallJob(req *rApi.Request[*v1.HelmChart]) stepResult.Result { @@ -258,9 +258,25 @@ func (r *HelmChartReconciler) startInstallJob(req *rApi.Request[*v1.HelmChart]) job = nil } - values, err := valuesToYaml(obj.Spec.HelmValues) + helmValues := obj.Spec.HelmValues + + if v, ok := obj.GetAnnotations()[constants.ForceReconcile]; ok && v == "true" { + if helmValues == nil { + helmValues = make(map[string]apiextensionsv1.JSON, 1) + } + b, _ := json.Marshal(map[string]any{"time": time.Now().Format(time.RFC3339)}) + helmValues["force-reconciled-at"] = apiextensionsv1.JSON{Raw: b} + ann := obj.GetAnnotations() + delete(ann, constants.ForceReconcile) + obj.SetAnnotations(ann) + if err := r.Update(ctx, obj); err != nil { + return check.StillRunning(fmt.Errorf("waiting for reconcilation")) + } + } + + values, err := valuesToYaml(helmValues) if err != nil { - return check.Failed(err) + return check.Failed(errors.NewEf(err, "converting helm values to YAML")) } if job == nil { @@ -508,8 +524,15 @@ func (r *HelmChartReconciler) startUninstallJob(req *rApi.Request[*v1.HelmChart] func (r *HelmChartReconciler) SetupWithManager(mgr ctrl.Manager) error { r.Client = mgr.GetClient() r.Scheme = mgr.GetScheme() - r.logger = logging.NewOrDie(&logging.Options{Name: "plugin-helm-chart.kloudlite"}) - r.yamlClient = kubectl.NewYAMLClientOrDie(mgr.GetConfig(), kubectl.YAMLClientOpts{Logger: r.logger}) + r.logger = logging.NewOrDie(&logging.Options{ + Prefix: "plugin-helm-chart.kloudlite", + ShowTimestamp: false, + ShowCaller: true, + ShowDebugLogs: false, + DevelopmentMode: false, + }) + // r.logger = logging.NewOrDie(&logging.Options{Name: "plugin-helm-chart.kloudlite"}) + r.yamlClient = kubectl.NewYAMLClientOrDie(mgr.GetConfig(), kubectl.YAMLClientOpts{}) var err error @@ -526,22 +549,8 @@ func (r *HelmChartReconciler) SetupWithManager(mgr ctrl.Manager) error { r.Env, err = env.LoadEnv() builder := ctrl.NewControllerManagedBy(mgr).For(&v1.HelmChart{}).Named("plugin-helm-chart") - - // builder.Watches( - // &batchv1.Job{}, - // handler.EnqueueRequestsFromMapFunc( - // func(_ context.Context, o client.Object) []reconcile.Request { - // if v, ok := o.GetLabels()[LabelHelmChartName]; ok { - // return []reconcile.Request{{NamespacedName: fn.NN(o.GetNamespace(), v)}} - // } - // return nil - // }), - // ) - + builder.Owns(&batchv1.Job{}) builder.WithOptions(controller.Options{MaxConcurrentReconciles: r.Env.MaxConcurrentReconciles}) + builder.WithEventFilter(rApi.ReconcileFilter()) return builder.Complete(r) - // return ctrl.NewControllerManagedBy(mgr). - // For(&v1.HelmChart{}). - // Named("helmchart"). - // Complete(r) } diff --git a/internal/controller/templates/embed.go b/internal/controller/templates/embed.go index 5c13736..7f8c4de 100644 --- a/internal/controller/templates/embed.go +++ b/internal/controller/templates/embed.go @@ -4,7 +4,7 @@ import ( "embed" "path/filepath" - operator_templates "github.com/kloudlite/operator/pkg/templates" + operator_templates "github.com/kloudlite/operator/toolkit/templates" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/internal/controller/templates/helm-install-job.yml.tpl b/internal/controller/templates/helm-install-job.yml.tpl index bb0213e..33d90af 100644 --- a/internal/controller/templates/helm-install-job.yml.tpl +++ b/internal/controller/templates/helm-install-job.yml.tpl @@ -47,7 +47,7 @@ spec: version_args+=("--version" "{{.ChartVersion}}") fi - helm upgrade --install {{.ReleaseName}} helm-repo/{{.ChartName}} --namespace {{.ReleaseNamespace}} ${version_args[@]} --values values.yml 2>&1 | tee /dev/termination-log + helm upgrade --wait --install {{.ReleaseName}} helm-repo/{{.ChartName}} --namespace {{.ReleaseNamespace}} ${version_args[@]} --values values.yml 2>&1 | tee /dev/termination-log {{- if .PostInstall }} echo "running post-install job script"