Skip to content
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

[V1] refactor: rename helm.Deployer to helm.Deployer3 to prepare for helm31Deployer #7415

Merged
merged 1 commit into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/skaffold/deploy/helm/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func getArgs(releaseName string, namespace string) []string {
}

// installArgs calculates the correct arguments to "helm install"
func (h *Deployer) installArgs(r latest.HelmRelease, builds []graph.Artifact, valuesSet map[string]bool, o installOpts) ([]string, error) {
func (h *Deployer3) installArgs(r latest.HelmRelease, builds []graph.Artifact, valuesSet map[string]bool, o installOpts) ([]string, error) {
var args []string
if o.upgrade {
args = append(args, "upgrade", o.releaseName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ var (
osExecutable = os.Executable
)

// Deployer deploys workflows using the helm CLI
type Deployer struct {
// Deployer3 deploys workflows using the helm CLI 3.0.0
type Deployer3 struct {
*latest.HelmDeploy

accessor access.Accessor
Expand Down Expand Up @@ -128,8 +128,8 @@ type Config interface {
JSONParseConfig() latest.JSONParseConfig
}

// NewDeployer returns a configured Deployer. Returns an error if current version of helm is less than 3.0.0.
func NewDeployer(ctx context.Context, cfg Config, labeller *label.DefaultLabeller, h *latest.HelmDeploy) (*Deployer, error) {
// NewDeployer returns a configured Deployer3. Returns an error if current version of helm is less than 3.0.0.
func NewDeployer(ctx context.Context, cfg Config, labeller *label.DefaultLabeller, h *latest.HelmDeploy) (*Deployer3, error) {
hv, err := binVer(ctx)
if err != nil {
return nil, versionGetErr(err)
Expand All @@ -155,7 +155,7 @@ func NewDeployer(ctx context.Context, cfg Config, labeller *label.DefaultLabelle
olog.Entry(context.TODO()).Warn("unable to parse namespaces - deploy might not work correctly!")
}
logger := component.NewLogger(cfg, kubectl, podSelector, &namespaces)
return &Deployer{
return &Deployer3{
HelmDeploy: h,
podSelector: podSelector,
namespaces: &namespaces,
Expand All @@ -179,41 +179,41 @@ func NewDeployer(ctx context.Context, cfg Config, labeller *label.DefaultLabelle
}, nil
}

func (h *Deployer) trackNamespaces(namespaces []string) {
func (h *Deployer3) trackNamespaces(namespaces []string) {
*h.namespaces = deployutil.ConsolidateNamespaces(*h.namespaces, namespaces)
}

func (h *Deployer) GetAccessor() access.Accessor {
func (h *Deployer3) GetAccessor() access.Accessor {
return h.accessor
}

func (h *Deployer) GetDebugger() debug.Debugger {
func (h *Deployer3) GetDebugger() debug.Debugger {
return h.debugger
}

func (h *Deployer) GetLogger() log.Logger {
func (h *Deployer3) GetLogger() log.Logger {
return h.logger
}

func (h *Deployer) GetStatusMonitor() status.Monitor {
func (h *Deployer3) GetStatusMonitor() status.Monitor {
return h.statusMonitor
}

func (h *Deployer) GetSyncer() sync.Syncer {
func (h *Deployer3) GetSyncer() sync.Syncer {
return h.syncer
}

func (h *Deployer) RegisterLocalImages(images []graph.Artifact) {
func (h *Deployer3) RegisterLocalImages(images []graph.Artifact) {
h.localImages = images
}

func (h *Deployer) TrackBuildArtifacts(artifacts []graph.Artifact) {
func (h *Deployer3) TrackBuildArtifacts(artifacts []graph.Artifact) {
deployutil.AddTagsToPodSelector(artifacts, h.originalImages, h.podSelector)
h.logger.RegisterArtifacts(artifacts)
}

// Deploy deploys the build results to the Kubernetes cluster
func (h *Deployer) Deploy(ctx context.Context, out io.Writer, builds []graph.Artifact) error {
func (h *Deployer3) Deploy(ctx context.Context, out io.Writer, builds []graph.Artifact) error {
ctx, endTrace := instrumentation.StartTrace(ctx, "Deploy", map[string]string{
"DeployerType": "helm",
})
Expand Down Expand Up @@ -287,7 +287,7 @@ func (h *Deployer) Deploy(ctx context.Context, out io.Writer, builds []graph.Art
}

// Dependencies returns a list of files that the deployer depends on.
func (h *Deployer) Dependencies() ([]string, error) {
func (h *Deployer3) Dependencies() ([]string, error) {
var deps []string

for _, release := range h.Releases {
Expand Down Expand Up @@ -346,7 +346,7 @@ func (h *Deployer) Dependencies() ([]string, error) {
}

// Cleanup deletes what was deployed by calling Deploy.
func (h *Deployer) Cleanup(ctx context.Context, out io.Writer, dryRun bool) error {
func (h *Deployer3) Cleanup(ctx context.Context, out io.Writer, dryRun bool) error {
instrumentation.AddAttributesToCurrentSpanFromContext(ctx, map[string]string{
"DeployerType": "helm",
})
Expand Down Expand Up @@ -385,7 +385,7 @@ func (h *Deployer) Cleanup(ctx context.Context, out io.Writer, dryRun bool) erro
}

// Render generates the Kubernetes manifests and writes them out
func (h *Deployer) Render(ctx context.Context, out io.Writer, builds []graph.Artifact, offline bool, filepath string) error {
func (h *Deployer3) Render(ctx context.Context, out io.Writer, builds []graph.Artifact, offline bool, filepath string) error {
instrumentation.AddAttributesToCurrentSpanFromContext(ctx, map[string]string{
"DeployerType": "helm",
})
Expand Down Expand Up @@ -448,11 +448,11 @@ func (h *Deployer) Render(ctx context.Context, out io.Writer, builds []graph.Art
return manifest.Write(renderedManifests.String(), filepath, out)
}

func (h *Deployer) HasRunnableHooks() bool {
func (h *Deployer3) HasRunnableHooks() bool {
return len(h.HelmDeploy.LifecycleHooks.PreHooks) > 0 || len(h.HelmDeploy.LifecycleHooks.PostHooks) > 0
}

func (h *Deployer) PreDeployHooks(ctx context.Context, out io.Writer) error {
func (h *Deployer3) PreDeployHooks(ctx context.Context, out io.Writer) error {
childCtx, endTrace := instrumentation.StartTrace(ctx, "Deploy_PreHooks")
if err := h.hookRunner.RunPreHooks(childCtx, out); err != nil {
endTrace(instrumentation.TraceEndError(err))
Expand All @@ -462,7 +462,7 @@ func (h *Deployer) PreDeployHooks(ctx context.Context, out io.Writer) error {
return nil
}

func (h *Deployer) PostDeployHooks(ctx context.Context, out io.Writer) error {
func (h *Deployer3) PostDeployHooks(ctx context.Context, out io.Writer) error {
childCtx, endTrace := instrumentation.StartTrace(ctx, "Deploy_PostHooks")
if err := h.hookRunner.RunPostHooks(childCtx, out); err != nil {
endTrace(instrumentation.TraceEndError(err))
Expand All @@ -473,7 +473,7 @@ func (h *Deployer) PostDeployHooks(ctx context.Context, out io.Writer) error {
}

// deployRelease deploys a single release
func (h *Deployer) deployRelease(ctx context.Context, out io.Writer, releaseName string, r latest.HelmRelease, builds []graph.Artifact, valuesSet map[string]bool, helmVersion semver.Version, chartVersion string) ([]types.Artifact, error) {
func (h *Deployer3) deployRelease(ctx context.Context, out io.Writer, releaseName string, r latest.HelmRelease, builds []graph.Artifact, valuesSet map[string]bool, helmVersion semver.Version, chartVersion string) ([]types.Artifact, error) {
var err error
opts := installOpts{
releaseName: releaseName,
Expand Down Expand Up @@ -590,7 +590,7 @@ func (h *Deployer) deployRelease(ctx context.Context, out io.Writer, releaseName
}

// getReleaseManifest confirms that a release is visible to helm and returns the release manifest
func (h *Deployer) getReleaseManifest(ctx context.Context, releaseName string, namespace string) (bytes.Buffer, error) {
func (h *Deployer3) getReleaseManifest(ctx context.Context, releaseName string, namespace string) (bytes.Buffer, error) {
// Retry, because sometimes a release may not be immediately visible
opts := backoff.NewExponentialBackOff()
opts.MaxElapsedTime = 4 * time.Second
Expand All @@ -614,7 +614,7 @@ func (h *Deployer) getReleaseManifest(ctx context.Context, releaseName string, n
}

// packageChart packages the chart and returns the path to the resulting chart archive
func (h *Deployer) packageChart(ctx context.Context, r latest.HelmRelease) (string, error) {
func (h *Deployer3) packageChart(ctx context.Context, r latest.HelmRelease) (string, error) {
// Allow a test to sneak a predictable path in
tmpDir := h.pkgTmpDir

Expand Down
6 changes: 3 additions & 3 deletions pkg/skaffold/deploy/helm/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ func TestHelmDeploy(t *testing.T) {
env []string
helm latest.HelmDeploy
namespace string
configure func(*Deployer)
configure func(*Deployer3)
builds []graph.Artifact
force bool
shouldErr bool
Expand Down Expand Up @@ -1015,7 +1015,7 @@ func TestHelmDeploy(t *testing.T) {
shouldErr: true,
helm: testDeployConfig,
builds: testBuilds,
configure: func(deployer *Deployer) { deployer.enableDebug = true },
configure: func(deployer *Deployer3) { deployer.enableDebug = true },
expectedNamespaces: []string{""},
},
{
Expand All @@ -1029,7 +1029,7 @@ func TestHelmDeploy(t *testing.T) {
AndRunWithOutput("helm --kube-context kubecontext get all skaffold-helm --template {{.Release.Manifest}} --kubeconfig kubeconfig", validDeployYaml),
helm: testDeployConfig,
builds: testBuilds,
configure: func(deployer *Deployer) { deployer.enableDebug = true },
configure: func(deployer *Deployer3) { deployer.enableDebug = true },
expectedNamespaces: []string{""},
},
{
Expand Down
6 changes: 3 additions & 3 deletions pkg/skaffold/deploy/helm/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func pairParamsToArtifacts(builds []graph.Artifact, params map[string]string) (m
return paramToBuildResult, nil
}

func (h *Deployer) generateSkaffoldDebugFilter(buildsFile string) []string {
func (h *Deployer3) generateSkaffoldDebugFilter(buildsFile string) []string {
args := []string{"filter", "--debugging", "--kube-context", h.kubeContext}
if len(buildsFile) > 0 {
args = append(args, "--build-artifacts", buildsFile)
Expand All @@ -153,7 +153,7 @@ func (h *Deployer) generateSkaffoldDebugFilter(buildsFile string) []string {
return args
}

func (h *Deployer) releaseNamespace(r latest.HelmRelease) (string, error) {
func (h *Deployer3) releaseNamespace(r latest.HelmRelease) (string, error) {
if h.namespace != "" {
return h.namespace, nil
} else if r.Namespace != "" {
Expand Down Expand Up @@ -199,7 +199,7 @@ func envVarForImage(imageName string, digest string) map[string]string {
}

// exec executes the helm command, writing combined stdout/stderr to the provided writer
func (h *Deployer) exec(ctx context.Context, out io.Writer, useSecrets bool, env []string, args ...string) error {
func (h *Deployer3) exec(ctx context.Context, out io.Writer, useSecrets bool, env []string, args ...string) error {
args = append([]string{"--kube-context", h.kubeContext}, args...)
args = append(args, h.Flags.Global...)

Expand Down
4 changes: 2 additions & 2 deletions pkg/skaffold/runner/deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestGetDeployer(tOuter *testing.T) {
description: "helm deployer with 3.0.0 version",
cfg: latest.DeployType{HelmDeploy: &latest.HelmDeploy{}},
helmVersion: `version.BuildInfo{Version:"v3.0.0"}`,
expected: deploy.NewDeployerMux([]deploy.Deployer{&helm.Deployer{}}, false),
expected: deploy.NewDeployerMux([]deploy.Deployer{&helm.Deployer3{}}, false),
},
{
description: "helm deployer with less than 3.0.0 version",
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestGetDeployer(tOuter *testing.T) {
},
helmVersion: `version.BuildInfo{Version:"v3.0.0"}`,
expected: deploy.NewDeployerMux([]deploy.Deployer{
&helm.Deployer{},
&helm.Deployer3{},
&kpt.Deployer{},
}, false),
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/runner/v1/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ func TestNewForConfig(t *testing.T) {
},
expectedTester: &test.FullTester{},
expectedDeployer: deploy.NewDeployerMux([]deploy.Deployer{
&helm.Deployer{},
&helm.Deployer3{},
&kubectl.Deployer{},
&kustomize.Deployer{},
}, false),
Expand Down