Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(exp-engine): "werf plan" command, "werf converge" improvements
Signed-off-by: Ilya Lesikov <ilya@lesikov.com>
  • Loading branch information
ilya-lesikov committed Sep 15, 2023
1 parent ba71df4 commit f3a2b0b
Show file tree
Hide file tree
Showing 8 changed files with 838 additions and 32 deletions.
28 changes: 13 additions & 15 deletions cmd/werf/converge/converge.go
Expand Up @@ -9,19 +9,16 @@ import (
"regexp"
"time"

"github.com/gookit/color"
"github.com/samber/lo"
"github.com/spf13/cobra"
helm_v3 "helm.sh/helm/v3/cmd/helm"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/cli/values"
kubefake "helm.sh/helm/v3/pkg/kube/fake"
"helm.sh/helm/v3/pkg/postrender"
"helm.sh/helm/v3/pkg/registry"
"helm.sh/helm/v3/pkg/storage"
"helm.sh/helm/v3/pkg/storage/driver"
"helm.sh/helm/v3/pkg/werf/chrttree"
helmcommon "helm.sh/helm/v3/pkg/werf/common"
"helm.sh/helm/v3/pkg/werf/kubeclnt"
Expand Down Expand Up @@ -566,16 +563,17 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
chartPathOptions := action.ChartPathOptions{}
chartPathOptions.SetRegistryClient(actionConfig.RegistryClient)

// FIXME(ilya-lesikov): allow local mode
// TODO(ilya-lesikov): allow specifying kube version and additional capabilities manually
actionConfig.Releases.MaxHistory = *commonCmdData.ReleasesHistoryMax
if false {
actionConfig.Capabilities = chartutil.DefaultCapabilities.Copy()
actionConfig.KubeClient = &kubefake.PrintingKubeClient{Out: ioutil.Discard}
mem := driver.NewMemory()
mem.SetNamespace(releaseNamespace.Name())
actionConfig.Releases = storage.Init(mem)
}

// FIXME(ilya-lesikov): for local commands (lint, ...)
// if false {
// // allow specifying kube version and additional capabilities manually
// actionConfig.Capabilities = chartutil.DefaultCapabilities.Copy()
// actionConfig.KubeClient = &kubefake.PrintingKubeClient{Out: ioutil.Discard}
// mem := driver.NewMemory()
// mem.SetNamespace(releaseNamespace.Name())
// actionConfig.Releases = storage.Init(mem)
// }

tracker := resrctracker.NewResourceTracker(clientFactory.Static(), clientFactory.Dynamic(), clientFactory.Discovery(), clientFactory.Mapper())

Expand Down Expand Up @@ -727,7 +725,7 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
if useless, err := plan.Useless(); err != nil {
return fmt.Errorf("error checking if deploy plan will do nothing useful: %w", err)
} else if useless {
log.Default.Info(ctx, "Skipped release %q in namespace %q: cluster resources already as desired.", releaseName, releaseNamespace.Name())
log.Default.Info(ctx, color.Style{color.Bold, color.Green}.Render("Skipped release")+" %q (namespace: %q): cluster resources already as desired", releaseName, releaseNamespace.Name())
return nil
}

Expand Down Expand Up @@ -855,7 +853,7 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
} else if len(finalErrs) > 0 {
return utls.Multierrorf("succeeded release %q (namespace: %q), but errors encountered", finalErrs, releaseName, releaseNamespace.Name())
} else {
log.Default.Info(ctx, "Succeeded release %q (namespace: %q)", releaseName, releaseNamespace.Name())
log.Default.Info(ctx, color.Style{color.Bold, color.Green}.Render("Succeeded release")+" %q (namespace: %q)", releaseName, releaseNamespace.Name())
return nil
}
})
Expand Down
26 changes: 20 additions & 6 deletions cmd/werf/main.go
Expand Up @@ -43,13 +43,15 @@ import (
managed_images_add "github.com/werf/werf/cmd/werf/managed_images/add"
managed_images_ls "github.com/werf/werf/cmd/werf/managed_images/ls"
managed_images_rm "github.com/werf/werf/cmd/werf/managed_images/rm"
"github.com/werf/werf/cmd/werf/plan"
"github.com/werf/werf/cmd/werf/purge"
"github.com/werf/werf/cmd/werf/render"
"github.com/werf/werf/cmd/werf/run"
"github.com/werf/werf/cmd/werf/slugify"
stage_image "github.com/werf/werf/cmd/werf/stage/image"
"github.com/werf/werf/cmd/werf/synchronization"
"github.com/werf/werf/cmd/werf/version"
dhelm "github.com/werf/werf/pkg/deploy/helm"
"github.com/werf/werf/pkg/process_exterminator"
"github.com/werf/werf/pkg/telemetry"
)
Expand Down Expand Up @@ -114,15 +116,27 @@ Find more information at https://werf.io`),
SilenceErrors: true,
})

var deliveryCmds []*cobra.Command
if dhelm.IsExperimentalEngine() {
deliveryCmds = []*cobra.Command{
converge.NewCmd(ctx),
plan.NewCmd(ctx),
dismiss.NewCmd(ctx),
bundleCmd(ctx),
}
} else {
deliveryCmds = []*cobra.Command{
converge.NewCmd(ctx),
dismiss.NewCmd(ctx),
bundleCmd(ctx),
}
}

groups := &templates.CommandGroups{}
*groups = append(*groups, templates.CommandGroups{
{
Message: "Delivery commands",
Commands: []*cobra.Command{
converge.NewCmd(ctx),
dismiss.NewCmd(ctx),
bundleCmd(ctx),
},
Message: "Delivery commands",
Commands: deliveryCmds,
},
{
Message: "Cleaning commands",
Expand Down

0 comments on commit f3a2b0b

Please sign in to comment.