Skip to content

Commit 9f66823

Browse files
committed
Eagerly replace all variables during devspace print execution
1 parent 1d04779 commit 9f66823

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

cmd/print.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"github.com/loft-sh/devspace/pkg/devspace/config"
7+
"github.com/loft-sh/devspace/pkg/devspace/config/loader"
78
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
89
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
910
"github.com/loft-sh/devspace/pkg/devspace/dependency"
@@ -87,8 +88,13 @@ func (cmd *PrintCmd) Run(f factory.Factory) error {
8788
log.Warnf("Unable to create new kubectl client: %v", err)
8889
}
8990

91+
localCache, err := configLoader.LoadLocalCache()
92+
if err != nil {
93+
return err
94+
}
95+
9096
// load config
91-
config, err := configLoader.Load(context.Background(), client, configOptions, log)
97+
config, err := configLoader.LoadWithParser(context.Background(), localCache, client, loader.NewEagerParser(), configOptions, log)
9298
if err != nil {
9399
return err
94100
}

pkg/devspace/config/loader/parser.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type defaultParser struct{}
2929

3030
func (d *defaultParser) Parse(ctx context.Context, originalRawConfig map[string]interface{}, rawConfig map[string]interface{}, resolver variable.Resolver, log log.Logger) (*latest.Config, map[string]interface{}, error) {
3131
// delete the commands, since we don't need it in a normal scenario
32-
return fillVariablesAndParse(ctx, resolver, rawConfig, log)
32+
return fillVariablesExcludeAndParse(ctx, resolver, rawConfig, log)
3333
}
3434

3535
func NewCommandsPipelinesParser() Parser {
@@ -45,7 +45,7 @@ func (c *commandsPipelinesParser) Parse(ctx context.Context, originalRawConfig m
4545
return nil, nil, err
4646
}
4747

48-
return fillVariablesAndParse(ctx, resolver, preparedConfig, log)
48+
return fillVariablesExcludeAndParse(ctx, resolver, preparedConfig, log)
4949
}
5050

5151
func NewCommandsParser() Parser {
@@ -61,7 +61,7 @@ func (c *commandsParser) Parse(ctx context.Context, originalRawConfig map[string
6161
return nil, nil, err
6262
}
6363

64-
return fillVariablesAndParse(ctx, resolver, preparedConfig, log)
64+
return fillVariablesExcludeAndParse(ctx, resolver, preparedConfig, log)
6565
}
6666

6767
func NewProfilesParser() Parser {
@@ -106,9 +106,27 @@ func (p *profilesParser) Parse(ctx context.Context, originalRawConfig map[string
106106
return retConfig, rawMap, nil
107107
}
108108

109-
func fillVariablesAndParse(ctx context.Context, resolver variable.Resolver, preparedConfig map[string]interface{}, log log.Logger) (*latest.Config, map[string]interface{}, error) {
109+
func NewEagerParser() Parser {
110+
return &eagerParser{}
111+
}
112+
113+
type eagerParser struct{}
114+
115+
func (e *eagerParser) Parse(ctx context.Context, originalRawConfig map[string]interface{}, rawConfig map[string]interface{}, resolver variable.Resolver, log log.Logger) (*latest.Config, map[string]interface{}, error) {
116+
return fillAllVariablesAndParse(ctx, resolver, rawConfig, log)
117+
}
118+
119+
func fillAllVariablesAndParse(ctx context.Context, resolver variable.Resolver, preparedConfig map[string]interface{}, log log.Logger) (*latest.Config, map[string]interface{}, error) {
120+
return fillVariablesAndParse(ctx, resolver, preparedConfig, log)
121+
}
122+
123+
func fillVariablesExcludeAndParse(ctx context.Context, resolver variable.Resolver, preparedConfig map[string]interface{}, log log.Logger) (*latest.Config, map[string]interface{}, error) {
124+
return fillVariablesAndParse(ctx, resolver, preparedConfig, log, runtime.Locations...)
125+
}
126+
127+
func fillVariablesAndParse(ctx context.Context, resolver variable.Resolver, preparedConfig map[string]interface{}, log log.Logger, excludedPaths ...string) (*latest.Config, map[string]interface{}, error) {
110128
// fill in variables and expressions (leave out
111-
preparedConfigInterface, err := resolver.FillVariablesExclude(ctx, preparedConfig, runtime.Locations)
129+
preparedConfigInterface, err := resolver.FillVariablesExclude(ctx, preparedConfig, excludedPaths)
112130
if err != nil {
113131
return nil, nil, err
114132
}

0 commit comments

Comments
 (0)