-
Notifications
You must be signed in to change notification settings - Fork 21
Add Helm template storage backend logic #685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package helmstoragebackend | ||
|
|
||
| import ( | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/status" | ||
| ) | ||
|
|
||
| func gRPCInternalError(err error) error { | ||
| if err == nil { | ||
| return nil | ||
| } | ||
| return status.Error(codes.Internal, err.Error()) | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| package helmstoragebackend | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/pkg/errors" | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/status" | ||
| "helm.sh/helm/v3/pkg/action" | ||
| "helm.sh/helm/v3/pkg/release" | ||
| "helm.sh/helm/v3/pkg/storage/driver" | ||
| "k8s.io/cli-runtime/pkg/genericclioptions" | ||
|
|
||
| "capact.io/capact/internal/ptr" | ||
| ) | ||
|
|
||
| const defaultHelmDriver = "secrets" | ||
|
|
||
| type ( | ||
| // HelmRelease holds details about Helm release. | ||
| HelmRelease struct { | ||
| // Name specifies Helm release name for a given request. | ||
| Name string `json:"name"` | ||
| // Namespace specifies in which Kubernetes Namespace Helm release is located. | ||
| Namespace string `json:"namespace"` | ||
| // Driver specifies drivers used for storing the Helm release. | ||
| Driver *string `json:"driver,omitempty"` | ||
| } | ||
|
|
||
| actionConfigurationProducerFn func(flags *genericclioptions.ConfigFlags, driver string, ns string) (*action.Configuration, error) | ||
| ) | ||
|
|
||
| // HelmReleaseFetcher provides functionality to fetch Helm release. | ||
| type HelmReleaseFetcher struct { | ||
| helmCfgFlags *genericclioptions.ConfigFlags | ||
| actionConfigurationProducer actionConfigurationProducerFn | ||
| } | ||
|
|
||
| // NewHelmReleaseFetcher returns a new HelmReleaseFetcher instance. | ||
| func NewHelmReleaseFetcher(flags *genericclioptions.ConfigFlags) *HelmReleaseFetcher { | ||
| return &HelmReleaseFetcher{helmCfgFlags: flags, actionConfigurationProducer: actionConfigurationProducer} | ||
| } | ||
|
|
||
| // FetchHelmRelease returns a given Helm release. It already handles the gRPC errors properly. | ||
| func (f *HelmReleaseFetcher) FetchHelmRelease(tiID string, helmRelease HelmRelease) (*release.Release, error) { | ||
| cfg, err := f.actionConfigurationProducer(f.helmCfgFlags, *helmRelease.Driver, helmRelease.Namespace) | ||
| if err != nil { | ||
| return nil, gRPCInternalError(errors.Wrap(err, "while creating Helm get release client")) | ||
| } | ||
|
|
||
| helmGet := action.NewGet(cfg) | ||
|
|
||
| // NOTE: req.resourceVersion is ignored on purpose. | ||
| // Based on our contract we always return the latest Helm release revision. | ||
| helmGet.Version = latestRevisionIndicator | ||
|
|
||
| rel, err := helmGet.Run(helmRelease.Name) | ||
| switch { | ||
| case err == nil: | ||
| case errors.Is(err, driver.ErrReleaseNotFound): | ||
| return nil, status.Error(codes.NotFound, fmt.Sprintf("Helm release '%s/%s' for TypeInstance '%s' was not found", helmRelease.Namespace, helmRelease.Name, tiID)) | ||
| default: | ||
| return nil, gRPCInternalError(errors.Wrap(err, "while fetching Helm release")) | ||
| } | ||
|
|
||
| return rel, nil | ||
| } | ||
|
|
||
| // actionConfigurationProducer returns Configuration with a given input settings. | ||
| func actionConfigurationProducer(flags *genericclioptions.ConfigFlags, driver, ns string) (*action.Configuration, error) { | ||
| actionConfig := new(action.Configuration) | ||
| helmCfg := &genericclioptions.ConfigFlags{ | ||
| APIServer: flags.APIServer, | ||
| Insecure: flags.Insecure, | ||
| CAFile: flags.CAFile, | ||
| BearerToken: flags.BearerToken, | ||
| Namespace: ptr.String(ns), | ||
| } | ||
|
|
||
| debugLog := func(format string, v ...interface{}) { | ||
| // noop | ||
| } | ||
|
|
||
| err := actionConfig.Init(helmCfg, ns, driver, debugLog) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "while initializing Helm configuration") | ||
| } | ||
|
|
||
| return actionConfig, nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.