Skip to content
Permalink
Browse files
feat(external-deps): external dependencies now available for werf helm
Signed-off-by: Ilya Lesikov <ilya@lesikov.com>
  • Loading branch information
ilya-lesikov committed Jun 16, 2022
1 parent 1c607aa commit c968c08ddc05bcd546ff07482a8a67447809d645
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 39 deletions.
@@ -214,14 +214,9 @@ func runApply() error {
ChartExtender: bundle,
}

stagesExternalDepsGenerator, err := helm.NewStagesExternalDepsGenerator(actionConfig.RESTClientGetter)
if err != nil {
return fmt.Errorf("error creating external deps generator: %w", err)
}

helmUpgradeCmd, _ := helm_v3.NewUpgradeCmd(actionConfig, logboek.Context(ctx).OutStream(), helm_v3.UpgradeCmdOptions{
StagesSplitter: helm.NewStagesSplitter(),
StagesExternalDepsGenerator: stagesExternalDepsGenerator,
StagesExternalDepsGenerator: helm.NewStagesExternalDepsGenerator(&actionConfig.RESTClientGetter),
ChainPostRenderer: bundle.ChainPostRenderer,
ValueOpts: &values.Options{
ValueFiles: common.GetValues(&commonCmdData),
@@ -444,14 +444,9 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
return err
}

stagesExternalDepsGenerator, err := helm.NewStagesExternalDepsGenerator(actionConfig.RESTClientGetter)
if err != nil {
return fmt.Errorf("error creating external deps generator: %w", err)
}

helmUpgradeCmd, _ := helm_v3.NewUpgradeCmd(actionConfig, logboek.OutStream(), helm_v3.UpgradeCmdOptions{
StagesSplitter: helm.NewStagesSplitter(),
StagesExternalDepsGenerator: stagesExternalDepsGenerator,
StagesExternalDepsGenerator: helm.NewStagesExternalDepsGenerator(&actionConfig.RESTClientGetter),
ChainPostRenderer: wc.ChainPostRenderer,
ValueOpts: valueOpts,
CreateNamespace: common.NewBool(true),
@@ -80,9 +80,8 @@ func NewCmd() *cobra.Command {
NewTemplateCmd(actionConfig, wc),
helm_v3.NewRepoCmd(os.Stdout),
helm_v3.NewRollbackCmd(actionConfig, os.Stdout, helm_v3.RollbackCmdOptions{
StagesSplitter: helm.NewStagesSplitter(),
// TODO: actionConfig.RESTClientGetter not initialized at this point, but we need it.
StagesExternalDepsGenerator: nil,
StagesSplitter: helm.NewStagesSplitter(),
StagesExternalDepsGenerator: helm.NewStagesExternalDepsGenerator(&actionConfig.RESTClientGetter),
}),
NewInstallCmd(actionConfig, wc),
NewUpgradeCmd(actionConfig, wc),
@@ -19,9 +19,8 @@ var installCmdData common.CmdData

func NewInstallCmd(actionConfig *action.Configuration, wc *chart_extender.WerfChartStub) *cobra.Command {
cmd, helmAction := helm_v3.NewInstallCmd(actionConfig, os.Stdout, helm_v3.InstallCmdOptions{
StagesSplitter: helm.NewStagesSplitter(),
// TODO: actionConfig.RESTClientGetter not initialized at this point, but we need it.
StagesExternalDepsGenerator: nil,
StagesSplitter: helm.NewStagesSplitter(),
StagesExternalDepsGenerator: helm.NewStagesExternalDepsGenerator(&actionConfig.RESTClientGetter),
ChainPostRenderer: wc.ChainPostRenderer,
})
SetupRenderRelatedWerfChartParams(cmd, &installCmdData)
@@ -17,9 +17,8 @@ var templateCmdData common.CmdData

func NewTemplateCmd(actionConfig *action.Configuration, wc *chart_extender.WerfChartStub) *cobra.Command {
cmd, _ := helm_v3.NewTemplateCmd(actionConfig, os.Stdout, helm_v3.TemplateCmdOptions{
StagesSplitter: helm.NewStagesSplitter(),
// TODO: actionConfig.RESTClientGetter not initialized at this point, but we need it.
StagesExternalDepsGenerator: nil,
StagesSplitter: helm.NewStagesSplitter(),
StagesExternalDepsGenerator: helm.NewStagesExternalDepsGenerator(&actionConfig.RESTClientGetter),
ChainPostRenderer: wc.ChainPostRenderer,
})
SetupRenderRelatedWerfChartParams(cmd, &templateCmdData)
@@ -19,9 +19,8 @@ var upgradeCmdData common.CmdData

func NewUpgradeCmd(actionConfig *action.Configuration, wc *chart_extender.WerfChartStub) *cobra.Command {
cmd, _ := helm_v3.NewUpgradeCmd(actionConfig, os.Stdout, helm_v3.UpgradeCmdOptions{
StagesSplitter: helm.NewStagesSplitter(),
// TODO: actionConfig.RESTClientGetter not initialized at this point, but we need it.
StagesExternalDepsGenerator: nil,
StagesSplitter: helm.NewStagesSplitter(),
StagesExternalDepsGenerator: helm.NewStagesExternalDepsGenerator(&actionConfig.RESTClientGetter),
ChainPostRenderer: wc.ChainPostRenderer,
})
SetupRenderRelatedWerfChartParams(cmd, &upgradeCmdData)
@@ -13,33 +13,49 @@ import (
"k8s.io/client-go/restmapper"
)

func NewStagesExternalDepsGenerator(restClient action.RESTClientGetter) (*StagesExternalDepsGenerator, error) {
mapper, err := restClient.ToRESTMapper()
if err != nil {
return nil, fmt.Errorf("error getting REST mapper: %w", err)
}

discoveryClient, err := restClient.ToDiscoveryClient()
if err != nil {
return nil, fmt.Errorf("error getting discovery client: %w", err)
}

gvkBuilder := NewGVKBuilder(scheme.Scheme, restmapper.NewShortcutExpander(mapper, discoveryClient))

func NewStagesExternalDepsGenerator(restClient *action.RESTClientGetter) *StagesExternalDepsGenerator {
return &StagesExternalDepsGenerator{
restClient: restClient,
metaAccessor: metadataAccessor,
scheme: scheme.Scheme,
gvkBuilder: gvkBuilder,
}, nil
}
}

type StagesExternalDepsGenerator struct {
restClient *action.RESTClientGetter
gvkBuilder externaldeps.GVKBuilder
metaAccessor meta.MetadataAccessor
scheme *runtime.Scheme
initialized bool
}

func (s *StagesExternalDepsGenerator) init() error {
if s.initialized {
return nil
}

mapper, err := (*s.restClient).ToRESTMapper()
if err != nil {
return fmt.Errorf("error getting REST mapper: %w", err)
}

discoveryClient, err := (*s.restClient).ToDiscoveryClient()
if err != nil {
return fmt.Errorf("error getting discovery client: %w", err)
}

s.gvkBuilder = NewGVKBuilder(scheme.Scheme, restmapper.NewShortcutExpander(mapper, discoveryClient))

s.initialized = true

return nil
}

func (s *StagesExternalDepsGenerator) Generate(stages stages.SortedStageList) error {
if err := s.init(); err != nil {
return fmt.Errorf("error initializing external dependencies generator: %w", err)
}

for _, stage := range stages {
if err := stage.DesiredResources.Visit(func(resInfo *resource.Info, err error) error {
if err != nil {

0 comments on commit c968c08

Please sign in to comment.