Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(exp-engine): use new History api
Signed-off-by: Ilya Lesikov <ilya@lesikov.com>
  • Loading branch information
ilya-lesikov committed Jul 20, 2023
1 parent 6199052 commit 1ca6109
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
34 changes: 13 additions & 21 deletions cmd/werf/converge/converge.go
Expand Up @@ -20,12 +20,11 @@ import (
"helm.sh/helm/v3/pkg/postrender"
"helm.sh/helm/v3/pkg/registry"
"helm.sh/helm/v3/pkg/release"
"helm.sh/helm/v3/pkg/storage/driver"
helmchart "helm.sh/helm/v3/pkg/werf/chart"
"helm.sh/helm/v3/pkg/werf/history"
"helm.sh/helm/v3/pkg/werf/log"
"helm.sh/helm/v3/pkg/werf/mutator"
"helm.sh/helm/v3/pkg/werf/plan"
helmrelease "helm.sh/helm/v3/pkg/werf/release"
helmresource "helm.sh/helm/v3/pkg/werf/resource"
"helm.sh/helm/v3/pkg/werf/resourcebuilder"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -561,14 +560,13 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
return fmt.Errorf("error initializing deferred kube client: %w", err)
}

history, err := actionConfig.Releases.History(releaseName)
if err != nil && err != driver.ErrReleaseNotFound {
return fmt.Errorf("error getting history for release %q: %w", releaseName, err)
hist, err := history.NewHistory(releaseName, releaseNamespace, actionConfig.Releases.Driver)
if err != nil {
return fmt.Errorf("error building history for release %q: %w", releaseName, err)
}
historyAnalyzer := helmrelease.NewHistoryAnalyzer(history)
deployType := historyAnalyzer.DeployTypeForNewRelease()
revision := historyAnalyzer.RevisionForNewRelease()
prevRelease := historyAnalyzer.LastRelease()
prevRelease := hist.LastRelease()
deployType := hist.DeployTypeForNextRelease()
revision := hist.RevisionForNextRelease()

chartTree, err := helmchart.NewChartTree(chartDir, releaseName, releaseNamespace, revision, deployType, actionConfig, helmchart.NewChartTreeOptions{
Logger: logger,
Expand Down Expand Up @@ -753,22 +751,16 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
helmResources = append(helmResources, res.Local)
}

deployReleaseBuilder := helmrelease.NewDeployReleaseBuilder(deployType, releaseName, releaseNamespace.Name(), chartTree.LegacyChart(), chartTree.ReleaseValues(), revision).
WithHelmHooks(helmHooks).
WithHelmResources(helmResources).
WithNotes(chartTree.Notes()).
WithPrevRelease(prevRelease)

rel, err := deployReleaseBuilder.BuildPendingRelease()
rel, err := hist.BuildNextRelease(helmHooks, helmResources, chartTree.Notes(), chartTree.LegacyChart(), chartTree.ReleaseValues())
if err != nil {
return fmt.Errorf("error building release: %w", err)
return fmt.Errorf("error building next release: %w", err)
}

succeededRel := deployReleaseBuilder.PromotePendingReleaseToSucceeded(rel)
succeededRel := hist.PromoteReleaseToSucceeded(rel)

var supersededRel *release.Release
if prevRelease != nil {
supersededRel = deployReleaseBuilder.PromotePreviousReleaseToSuperseded(prevRelease)
supersededRel = hist.PromoteReleaseToSuperseded(prevRelease)
}

deployPlan, referencesToCleanupOnFailure, err := plan.
Expand All @@ -778,7 +770,7 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
WithHelmResources(resources.HelmResources).
WithPreviousReleaseHelmResources(resources.PrevReleaseHelmResources).
WithSupersededPreviousRelease(supersededRel).
WithPreviousReleaseDeployed(historyAnalyzer.LastReleaseDeployed()).
WithPreviousReleaseDeployed(hist.LastReleaseIsDeployed()).
Build(ctx)
if err != nil {
return fmt.Errorf("error building deploy plan: %w", err)
Expand Down Expand Up @@ -849,7 +841,7 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
fmt.Fprintf(errStream, "\nRelease %q in namespace %q failed.\n", releaseName, releaseNamespace)
}()

rel = deployReleaseBuilder.PromotePendingReleaseToFailed(rel)
rel = hist.PromoteReleaseToFailed(rel)

finalizeFailedDeployPlan := plan.
NewFinalizeFailedDeployPlanBuilder(rel).
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -347,6 +347,6 @@ replace (
github.com/helm/helm-2to3 => github.com/werf/3p-helm-2to3 v0.0.0-20230313155428-cf9dd655c0e3 // switch back to upstream when merged: https://github.com/helm/helm-2to3/pull/224
github.com/jaguilar/vt100 => github.com/tonistiigi/vt100 v0.0.0-20190402012908-ad4c4a574305 // upstream not maintained
github.com/maorfr/helm-plugin-utils => github.com/werf/3p-helm-plugin-utils v0.6.1-0.20230313152239-057595ce9d57 // switch back to upstream when merged: https://github.com/maorfr/helm-plugin-utils/pull/17
helm.sh/helm/v3 => github.com/werf/3p-helm/v3 v3.0.0-20230718201902-55c2c531045a
helm.sh/helm/v3 => github.com/werf/3p-helm/v3 v3.0.0-20230720150643-13bccc57bd78
k8s.io/helm => github.com/werf/helm v0.0.0-20210202111118-81e74d46da0f
)
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -1740,8 +1740,8 @@ github.com/weppos/publicsuffix-go v0.5.0/go.mod h1:z3LCPQ38eedDQSwmsSRW4Y7t2L8Ln
github.com/weppos/publicsuffix-go v0.20.1-0.20221209102050-40d9c30084b3 h1:ypyhoprZWFzU0ydOBv3I5SS7/jLFJ+ujPAU+BD/EVFM=
github.com/werf/3p-helm-2to3 v0.0.0-20230313155428-cf9dd655c0e3 h1:pdKLiuiUoOFswc0HV6GX1+JHgP14HqE035xl2DQJi8A=
github.com/werf/3p-helm-2to3 v0.0.0-20230313155428-cf9dd655c0e3/go.mod h1:lTSQBLomjl67m4HQMbg3BHKWes3pOmjNBg8yygXYugk=
github.com/werf/3p-helm/v3 v3.0.0-20230718201902-55c2c531045a h1:wGj5JvWqWFLJTtLEN9l6I598AG0oxSJXz1AbTkO5xtQ=
github.com/werf/3p-helm/v3 v3.0.0-20230718201902-55c2c531045a/go.mod h1:vH6ckglZT6mhJefVLbUM9759Zt/wQnqqRe0BY4jmmHM=
github.com/werf/3p-helm/v3 v3.0.0-20230720150643-13bccc57bd78 h1:ZuW0Ljr9SatWfJV7XU1k6ebVHVNUCCcWOh5O+eKr0g0=
github.com/werf/3p-helm/v3 v3.0.0-20230720150643-13bccc57bd78/go.mod h1:vH6ckglZT6mhJefVLbUM9759Zt/wQnqqRe0BY4jmmHM=
github.com/werf/copy-recurse v0.2.7 h1:3FTOarbJ9uhFLi75oeUCioK9zxZwuV7o28kuUBPDZPM=
github.com/werf/copy-recurse v0.2.7/go.mod h1:6Ypb+qN+hRBJgoCgEkX1vpbqcQ+8q69BQ3hi8s8Y6Qc=
github.com/werf/helm v0.0.0-20210202111118-81e74d46da0f h1:81YscYTF9mmTf0ULOsCmm42YWQp+qWDzWi1HjWniZrg=
Expand Down

0 comments on commit 1ca6109

Please sign in to comment.