From 124bf3930f26cb11f73934c7b195b749abf1c1db Mon Sep 17 00:00:00 2001 From: David Desmarais-Michaud Date: Wed, 8 May 2024 13:58:38 -0400 Subject: [PATCH] feat(PL-2701): update joy to unify schema values --- Dockerfile | 4 +- chart/templates/deployment.yaml | 13 ++ chart/templates/secret.yaml | 15 ++- .../with-google-credentials/expected.yaml | 124 ++++++++++++++++++ .../tests/with-google-credentials/values.yaml | 20 +++ cmd/server/api_get_params_test.go | 25 +++- cmd/server/config.go | 26 ++++ cmd/server/main.go | 33 ++++- go.mod | 18 +-- go.sum | 66 +++++++--- internal/generator/generator.go | 34 ++++- internal/generator/generator_test.go | 6 +- 12 files changed, 341 insertions(+), 43 deletions(-) create mode 100644 chart/tests/with-google-credentials/expected.yaml create mode 100644 chart/tests/with-google-credentials/values.yaml diff --git a/Dockerfile b/Dockerfile index 2080715..ca690f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,12 +25,14 @@ COPY --chown=golang:root internal ./internal RUN go build -v -o joy-generator ./cmd/server -FROM scratch AS prod +FROM alpine AS prod COPY --from=build /etc/passwd /etc/group /etc/ COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=build --chown=golang:root /app/joy-generator /app/ +RUN apk add helm + USER golang:root EXPOSE 8080 diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml index 8e0228c..495abed 100644 --- a/chart/templates/deployment.yaml +++ b/chart/templates/deployment.yaml @@ -34,6 +34,11 @@ spec: secret: secretName: {{ include "joy-generator.fullname" . }}-github-app-key {{- end }} + {{- if .Values.googleCredentials }} + - name: google-credentials + secret: + secretName: {{ include "joy-generator.fullname" .}}-google-credentials + {{- end }} containers: - name: {{ .Chart.Name }} securityContext: @@ -47,6 +52,10 @@ spec: - mountPath: /etc/joy/config name: github-app-private-key {{- end }} + {{- if .Values.googleCredentials }} + - mountPath: /etc/joy/secrets + name: google-credentials + {{- end }} env: {{- range $key, $value := .Values.env }} {{- if $value }} @@ -58,6 +67,10 @@ spec: - name: GH_APP_PRIVATE_KEY_PATH value: /etc/joy/config/githubApp.pem {{- end }} + {{- if .Values.googleCredentials }} + - name: GOOGLE_CREDENTIALS_FILE + value: /etc/joy/secrets/credentials.json + {{- end }} envFrom: - secretRef: name: {{ include "joy-generator.fullname" . }}-config diff --git a/chart/templates/secret.yaml b/chart/templates/secret.yaml index 90fbee5..872da16 100644 --- a/chart/templates/secret.yaml +++ b/chart/templates/secret.yaml @@ -25,9 +25,8 @@ stringData: {{ toYaml .Values.secretEnv.values | indent 2 }} {{- end }} ---- - {{- if .Values.env.GH_APP_ID }} +--- {{- and (required ".Values.env.GH_APP_INSTALLATION_ID is required" .Values.env.GH_APP_INSTALLATION_ID) "" | -}} {{- and (required ".Values.githubAppPrivateKey is required" .Values.githubAppPrivateKey) "" -}} {{- if $sealedSecret }} @@ -54,3 +53,15 @@ stringData: {{ .Values.githubAppPrivateKey | indent 4 }} {{- end }} {{- end }} + + +{{- if .Values.googleCredentials }} +--- +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "joy-generator.fullname" . }}-google-credentials +stringData: + credentials.json: | +{{ .Values.googleCredentials | indent 4 }} +{{- end }} \ No newline at end of file diff --git a/chart/tests/with-google-credentials/expected.yaml b/chart/tests/with-google-credentials/expected.yaml new file mode 100644 index 0000000..bcc1c99 --- /dev/null +++ b/chart/tests/with-google-credentials/expected.yaml @@ -0,0 +1,124 @@ +--- +# Source: joy-generator/templates/secret.yaml +apiVersion: v1 +kind: Secret +metadata: + name: my-release-joy-generator-config +stringData: + GH_TOKEN: "12312312312312" + PLUGIN_TOKEN: '@very!l0ngands3curet0ken' +--- +# Source: joy-generator/templates/secret.yaml +apiVersion: v1 +kind: Secret +metadata: + name: my-release-joy-generator-google-credentials +stringData: + credentials.json: | + { + "credentials": "from google!" + } +--- +# Source: joy-generator/templates/argocd-config.yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: my-release-joy-generator-config +data: + token: "$my-release-joy-generator-config:PLUGIN_TOKEN" + baseUrl: "http://my-release-joy-generator" +--- +# Source: joy-generator/templates/service.yaml +apiVersion: v1 +kind: Service +metadata: + name: my-release-joy-generator + labels: + helm.sh/chart: joy-generator-1.0.0 + app.kubernetes.io/name: joy-generator + app.kubernetes.io/instance: my-release + app.kubernetes.io/version: "1.0.0" + app.kubernetes.io/managed-by: Helm +spec: + type: ClusterIP + ports: + - port: 80 + targetPort: http + protocol: TCP + name: http + selector: + app.kubernetes.io/name: joy-generator + app.kubernetes.io/instance: my-release +--- +# Source: joy-generator/templates/deployment.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-release-joy-generator + labels: + helm.sh/chart: joy-generator-1.0.0 + app.kubernetes.io/name: joy-generator + app.kubernetes.io/instance: my-release + app.kubernetes.io/version: "1.0.0" + app.kubernetes.io/managed-by: Helm +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: joy-generator + app.kubernetes.io/instance: my-release + template: + metadata: + labels: + app.kubernetes.io/name: joy-generator + app.kubernetes.io/instance: my-release + spec: + securityContext: + {} + volumes: + - name: catalog-dir + emptyDir: {} + - name: google-credentials + secret: + secretName: my-release-joy-generator-google-credentials + containers: + - name: joy-generator + securityContext: + {} + image: "ghcr.io/nestoca/joy-generator:0.1.2" + imagePullPolicy: IfNotPresent + volumeMounts: + - mountPath: /tmp/catalog + name: catalog-dir + - mountPath: /etc/joy/secrets + name: google-credentials + env: + - name: CATALOG_DIR + value: "/tmp/catalog" + - name: CATALOG_URL + value: "https://github.com/example/foobar.git" + - name: GH_USER + value: "username" + - name: GRACE_PERIOD + value: "10s" + - name: PORT + value: ":8080" + - name: GOOGLE_CREDENTIALS_FILE + value: /etc/joy/secrets/credentials.json + envFrom: + - secretRef: + name: my-release-joy-generator-config + ports: + - name: http + containerPort: 8080 + protocol: TCP + livenessProbe: + httpGet: + path: /api/v1/health + port: http + readinessProbe: + httpGet: + path: /api/v1/readiness + port: http + resources: + {} diff --git a/chart/tests/with-google-credentials/values.yaml b/chart/tests/with-google-credentials/values.yaml new file mode 100644 index 0000000..a99c74c --- /dev/null +++ b/chart/tests/with-google-credentials/values.yaml @@ -0,0 +1,20 @@ +# Default values for joy-generator. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +env: + CATALOG_URL: https://github.com/example/foobar.git + GH_USER: username + +secretEnv: + values: + PLUGIN_TOKEN: "@very!l0ngands3curet0ken" + GH_TOKEN: "12312312312312" + +image: + tag: 0.1.2 + +googleCredentials: | + { + "credentials": "from google!" + } diff --git a/cmd/server/api_get_params_test.go b/cmd/server/api_get_params_test.go index 857ab90..045383e 100644 --- a/cmd/server/api_get_params_test.go +++ b/cmd/server/api_get_params_test.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "context" "encoding/json" "fmt" "io" @@ -27,10 +28,14 @@ func TestGetParamsE2E(t *testing.T) { } var ( - user github.User - catalog github.RepoMetadata + user github.User + catalog github.RepoMetadata + registry string + credentials []byte ) + conf.Var(conf.Environ, ®istry, "REGISTRY", conf.Required[string](true)) + conf.Var(conf.Environ, &credentials, "CREDENTIALS", conf.Required[[]byte](true)) conf.Var(conf.Environ, &catalog.Path, "CATALOG_PATH", conf.Default(filepath.Join(os.TempDir(), "catalog"))) conf.Var(conf.Environ, &catalog.URL, "CATALOG_URL", conf.Required[string](true)) conf.Var(conf.Environ, &catalog.TargetRevision, "CATALOG_REVISION", conf.Default("master")) @@ -39,6 +44,8 @@ func TestGetParamsE2E(t *testing.T) { require.NoError(t, conf.Environ.Parse()) + require.NoError(t, AuthenticateHelm(context.Background(), registry, credentials)) + require.NoError(t, os.RemoveAll(catalog.Path)) repo, err := user.NewRepo(catalog) @@ -49,13 +56,20 @@ func TestGetParamsE2E(t *testing.T) { repo = repo.WithLogger(logger) + cacheDir, err := os.MkdirTemp("", "joy-cache-*") + require.NoError(t, err) + + t.Logf("cache dir: %s", cacheDir) + handler := Handler(HandlerParams{ pluginToken: "test-token", logger: logger, repo: repo, generator: &generator.Generator{ + CacheRoot: cacheDir, LoadJoyContext: generator.RepoLoader(repo), Logger: logger, + ChartPuller: generator.ChartPuller{}, }, }) @@ -79,7 +93,6 @@ func TestGetParamsE2E(t *testing.T) { var response generator.GetParamsResponse require.NoError(t, json.Unmarshal(body.Bytes(), &response)) - require.Greater(t, len(response.Output.Parameters), 0) for _, result := range response.Output.Parameters { @@ -92,8 +105,12 @@ func TestGetParamsE2E(t *testing.T) { require.Greater(t, len(logs.Records), 0) for _, record := range logs.Records { require.NotEmpty(t, record["level"]) - require.NotEqual(t, "error", record["level"]) + require.NotEqualf(t, "error", record["level"], "unexpected error log: %+v", record) } + + entries, err := os.ReadDir(cacheDir) + require.NoError(t, err) + require.Greater(t, len(entries), 0) } type TestLogOutputs struct { diff --git a/cmd/server/config.go b/cmd/server/config.go index 9da331e..1df8a54 100644 --- a/cmd/server/config.go +++ b/cmd/server/config.go @@ -18,6 +18,14 @@ type Config struct { Catalog github.RepoMetadata + CacheRoot string + + Google struct { + Repository string + CredentialsFilePath string + RawCredentials []byte + } + Github struct { User github.User App github.App @@ -27,19 +35,37 @@ type Config struct { func GetConfig() Config { var cfg Config + home, err := os.UserHomeDir() + if err != nil { + panic(err) + } + + conf.Var(conf.Environ, &cfg.CacheRoot, "CACHE_ROOT", conf.Default(filepath.Join(home, ".cache", "joy"))) conf.Var(conf.Environ, &cfg.Port, "PORT", conf.Default(":8080")) conf.Var(conf.Environ, &cfg.GracePeriod, "GRACE_PERIOD", conf.Default(10*time.Second)) conf.Var(conf.Environ, &cfg.PluginToken, "PLUGIN_TOKEN") + conf.Var(conf.Environ, &cfg.Catalog.URL, "CATALOG_URL") conf.Var(conf.Environ, &cfg.Catalog.Path, "CATALOG_DIR", conf.Default(filepath.Join(os.TempDir(), "catalog"))) conf.Var(conf.Environ, &cfg.Catalog.TargetRevision, "CATALOG_REVISION") + conf.Var(conf.Environ, &cfg.Github.User.Token, "GH_TOKEN") conf.Var(conf.Environ, &cfg.Github.User.Name, "GH_USER") conf.Var(conf.Environ, &cfg.Github.App.ID, "GH_APP_ID") conf.Var(conf.Environ, &cfg.Github.App.InstallationID, "GH_APP_INSTALLATION_ID") conf.Var(conf.Environ, &cfg.Github.App.PrivateKeyPath, "GH_APP_PRIVATE_KEY_PATH") + conf.Var(conf.Environ, &cfg.Google.CredentialsFilePath, "GOOGLE_CREDENTIALS_FILE") + conf.Var(conf.Environ, &cfg.Google.Repository, "GOOGLE_ARTIFACT_REPOSITORY") + conf.Environ.MustParse() + if path := cfg.Google.CredentialsFilePath; path != "" { + fs := conf.MakeParser(conf.FileSystem(conf.FileSystemOptions{})) + defer fs.MustParse() + + conf.Var(fs, &cfg.Google.RawCredentials, path, conf.Required[[]byte](true)) + } + return cfg } diff --git a/cmd/server/main.go b/cmd/server/main.go index f403aec..441a4e0 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -1,11 +1,13 @@ package main import ( + "bytes" "context" "errors" "fmt" "net/http" "os" + "os/exec" "reflect" "syscall" "time" @@ -32,6 +34,15 @@ func run() error { cfg := GetConfig() + ctx, stop := xcontext.WithSignalCancelation(context.Background(), syscall.SIGINT, syscall.SIGTERM) + defer stop() + + if len(cfg.Google.RawCredentials) > 0 { + if err := AuthenticateHelm(ctx, cfg.Google.Repository, cfg.Google.RawCredentials); err != nil { + return fmt.Errorf("failed to authenticate to helm: %w", err) + } + } + repo, err := func() (*github.Repo, error) { if !reflect.ValueOf(cfg.Github.App).IsZero() { return cfg.Github.App.NewRepo(cfg.Catalog) @@ -53,8 +64,10 @@ func run() error { logger: logger, repo: repo, generator: &generator.Generator{ - Logger: logger, + CacheRoot: cfg.CacheRoot, LoadJoyContext: generator.RepoLoader(repo), + Logger: logger, + ChartPuller: generator.ChartPuller{}, }, }), ReadHeaderTimeout: 5 * time.Second, @@ -69,9 +82,6 @@ func run() error { } }() - ctx, stop := xcontext.WithSignalCancelation(context.Background(), syscall.SIGINT, syscall.SIGTERM) - defer stop() - select { case err := <-errChan: return fmt.Errorf("failed to listen and serve: %w", err) @@ -89,3 +99,18 @@ func run() error { return nil } + +func AuthenticateHelm(ctx context.Context, registry string, credentials []byte) error { + login := exec.CommandContext(ctx, "helm", "registry", "login", "-u", "_json_key", "--password-stdin", registry) + + var buffer bytes.Buffer + login.Stdout = &buffer + login.Stderr = &buffer + login.Stdin = bytes.NewReader(credentials) + + if err := login.Run(); err != nil { + return fmt.Errorf("%w: %q", err, &buffer) + } + + return nil +} diff --git a/go.mod b/go.mod index 484ca5d..2bb959f 100644 --- a/go.mod +++ b/go.mod @@ -8,13 +8,14 @@ require ( github.com/davidmdm/x/xcontext v0.0.2 github.com/gin-gonic/gin v1.9.1 github.com/go-git/go-git/v5 v5.12.0 - github.com/nestoca/joy v0.50.0 + github.com/nestoca/joy v0.50.2-0.20240509193533-0a31215bc158 github.com/rs/zerolog v1.32.0 github.com/stretchr/testify v1.9.0 gopkg.in/yaml.v3 v3.0.1 ) require ( + cuelang.org/go v0.8.2 // indirect dario.cat/mergo v1.0.0 // indirect github.com/Masterminds/goutils v1.1.1 // indirect github.com/Masterminds/semver/v3 v3.2.1 // indirect @@ -27,6 +28,7 @@ require ( github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect github.com/chenzhuoyu/iasm v0.9.1 // indirect github.com/cloudflare/circl v1.3.7 // indirect + github.com/cockroachdb/apd/v3 v3.2.1 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/davidmdm/x/xerr v0.0.3 // indirect @@ -67,7 +69,7 @@ require ( github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect - github.com/shopspring/decimal v1.3.1 // indirect + github.com/shopspring/decimal v1.4.0 // indirect github.com/skeema/knownhosts v1.2.2 // indirect github.com/spf13/cast v1.6.0 // indirect github.com/spf13/cobra v1.8.0 // indirect @@ -76,12 +78,12 @@ require ( github.com/ugorji/go/codec v1.2.12 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect golang.org/x/arch v0.7.0 // indirect - golang.org/x/crypto v0.21.0 // indirect - golang.org/x/mod v0.16.0 // indirect - golang.org/x/net v0.22.0 // indirect - golang.org/x/sys v0.18.0 // indirect - golang.org/x/term v0.18.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/crypto v0.23.0 // indirect + golang.org/x/mod v0.17.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/term v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect golang.org/x/tools v0.19.0 // indirect google.golang.org/protobuf v1.33.0 // indirect gopkg.in/godo.v2 v2.0.9 // indirect diff --git a/go.sum b/go.sum index 6c0289c..a1fbe3f 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,7 @@ +cuelabs.dev/go/oci/ociregistry v0.0.0-20240314152124-224736b49f2e h1:GwCVItFUPxwdsEYnlUcJ6PJxOjTeFFCKOh6QWg4oAzQ= +cuelabs.dev/go/oci/ociregistry v0.0.0-20240314152124-224736b49f2e/go.mod h1:ApHceQLLwcOkCEXM1+DyCXTHEJhNGDpJ2kmV6axsx24= +cuelang.org/go v0.8.2 h1:vWfHI1kQlBvwkna7ktAqXjV5LUEAgU6vyMlJjvZZaDw= +cuelang.org/go v0.8.2/go.mod h1:CoDbYolfMms4BhWUlhD+t5ORnihR7wvjcfgyO9lL5FI= dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= @@ -39,6 +43,8 @@ github.com/chenzhuoyu/iasm v0.9.1/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLI github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= +github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg= +github.com/cockroachdb/apd/v3 v3.2.1/go.mod h1:klXJcjp+FffLTHlhIG69tezTDvdP065naDsHzKhYSqc= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI= @@ -58,8 +64,12 @@ github.com/davidmdm/x/xfs v0.0.4 h1:7g0ue0Gfs5mrIaV8QGA03hgIPm3tJvHUVdsr6obQTt4= github.com/davidmdm/x/xfs v0.0.4/go.mod h1:Mpo/6dE+3m6XNFPqai975wPt/XundxCW4cErGpvUSdc= github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU= github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM= +github.com/emicklei/proto v1.10.0 h1:pDGyFRVV5RvV+nkBK9iy3q67FBy9Xa7vwrOTE+g5aGw= +github.com/emicklei/proto v1.10.0/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= @@ -84,6 +94,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4= github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI= +github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= @@ -91,6 +103,8 @@ github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOW github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +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/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -133,6 +147,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= +github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= @@ -149,6 +165,8 @@ github.com/mgutz/str v1.2.0/go.mod h1:w1v0ofgLaJdoD0HpQ3fycxKD1WtxpjSo151pK/31q6 github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= +github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= +github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= @@ -157,14 +175,16 @@ 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/nestoca/joy v0.49.4 h1:KHHy95mTjnkGEUFvJ2euQULVLpaZ3m+x58hNZiFGhEM= -github.com/nestoca/joy v0.49.4/go.mod h1:AYgZ15OI1+9WtkXsa5ubhRO4S/CBiBmRPBDPp6aICLQ= -github.com/nestoca/joy v0.50.0 h1:/AnIbxSaahb7DnBSAHZiT4NOuLeXLlf47BNOXrDcFL4= -github.com/nestoca/joy v0.50.0/go.mod h1:AYgZ15OI1+9WtkXsa5ubhRO4S/CBiBmRPBDPp6aICLQ= +github.com/nestoca/joy v0.50.2-0.20240509193533-0a31215bc158 h1:F6ontCAzfYNW2DSef50/pHhKUr+4r/ZrYMasn4lLXIE= +github.com/nestoca/joy v0.50.2-0.20240509193533-0a31215bc158/go.mod h1:W9pyrK+2Sezc5aB/3OVk3UpqzBddu/86bLPlIOxHtMo= github.com/nestoca/survey/v2 v2.0.0 h1:orM/TXtBSQJCPiZy9N51hcwH0WzFjQJ7TQKCfMTnGoQ= github.com/nestoca/survey/v2 v2.0.0/go.mod h1:QfmcQfCRtqsiBpePFhHEW0MY9QH7lSpw3CQinsdC/dc= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= +github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= +github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug= +github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= github.com/pelletier/go-toml/v2 v2.2.0 h1:QLgLl2yMN7N+ruc31VynXs1vhMZa7CeHHejIeBAsoHo= github.com/pelletier/go-toml/v2 v2.2.0/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= @@ -173,8 +193,10 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0 h1:sadMIsgmHpEOGbUs6VtHBXRR1OHevnj7hLx9ZcdNGW4= +github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0/go.mod h1:jgxiZysxFPM+iWKwQwPR+y+Jvo54ARd4EisXxKYpB5c= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= @@ -182,8 +204,8 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= -github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= +github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k= +github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A= github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= @@ -226,12 +248,12 @@ golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= -golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic= -golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -239,8 +261,10 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= -golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= -golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI= +golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -262,15 +286,15 @@ golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.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= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= -golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= -golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= +golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -278,8 +302,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= @@ -288,6 +312,8 @@ golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw= golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/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.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= diff --git a/internal/generator/generator.go b/internal/generator/generator.go index c9494d1..5826fde 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -1,6 +1,8 @@ package generator import ( + "bytes" + "context" "fmt" "github.com/rs/zerolog" @@ -9,13 +11,34 @@ import ( "github.com/nestoca/joy/api/v1alpha1" joy "github.com/nestoca/joy/pkg" "github.com/nestoca/joy/pkg/catalog" + "github.com/nestoca/joy/pkg/helm" "github.com/nestoca/joy-generator/internal/github" ) type Generator struct { + CacheRoot string LoadJoyContext JoyLoaderFunc Logger zerolog.Logger + ChartPuller helm.Puller +} + +type ChartPuller struct{} + +func (puller ChartPuller) Pull(ctx context.Context, opts helm.PullOptions) error { + var buffer bytes.Buffer + + cli := helm.CLI{ + IO: joy.IO{ + Out: &buffer, + Err: &buffer, + }, + } + + if err := cli.Pull(ctx, opts); err != nil { + return fmt.Errorf("%w: %q", err, &buffer) + } + return nil } type Result struct { @@ -67,6 +90,13 @@ func (generator *Generator) Run() ([]Result, error) { return nil, fmt.Errorf("loading joy context: %w", err) } + cache := helm.ChartCache{ + Root: generator.CacheRoot, + Puller: generator.ChartPuller, + Refs: joyctx.Config.Charts, + DefaultChartRef: joyctx.Config.DefaultChartRef, + } + var reconciledReleases []Result for _, crossRelease := range joyctx.Catalog.Releases.Items { for _, release := range crossRelease.Releases { @@ -80,7 +110,7 @@ func (generator *Generator) Run() ([]Result, error) { Str("environment", release.Environment.Name). Msg("processing release") - chart, err := joy.ChartFromRelease(release, joyctx.Config.Charts, joyctx.Config.DefaultChartRef) + chart, err := cache.GetReleaseChartFS(context.TODO(), release) if err != nil { generator.Logger. Error(). @@ -94,7 +124,7 @@ func (generator *Generator) Run() ([]Result, error) { release.Spec.Chart.Name = chart.Name release.Spec.Chart.Version = chart.Version - values, err := joy.ReleaseValues(release, joyctx.Config.ValueMapping) + values, err := joy.ComputeReleaseValues(release, chart, joyctx.Config.ValueMapping) if err != nil { generator.Logger. Error(). diff --git a/internal/generator/generator_test.go b/internal/generator/generator_test.go index e859a66..b0b368c 100644 --- a/internal/generator/generator_test.go +++ b/internal/generator/generator_test.go @@ -8,10 +8,11 @@ import ( "github.com/nestoca/joy/api/v1alpha1" joy "github.com/nestoca/joy/pkg" "github.com/nestoca/joy/pkg/catalog" + "github.com/nestoca/joy/pkg/helm" ) func TestGenerator(t *testing.T) { - baseCharts := map[string]joy.HelmChart{ + baseCharts := map[string]helm.Chart{ "default": { RepoURL: "test", Name: "chart", @@ -28,7 +29,7 @@ func TestGenerator(t *testing.T) { Name string Release *v1alpha1.Release DefaultChartRef string - Charts map[string]joy.HelmChart + Charts map[string]helm.Chart ValueMapping *joy.ValueMapping ExpectedRelease *v1alpha1.Release ExpectedValues string @@ -148,6 +149,7 @@ func TestGenerator(t *testing.T) { for _, tc := range cases { t.Run(tc.Name, func(t *testing.T) { generator := Generator{ + ChartPuller: &helm.PullRendererMock{}, LoadJoyContext: func() (*JoyContext, error) { return &JoyContext{ Catalog: BuildCatalogFromRelease(tc.Release),