Skip to content

Commit d673fe7

Browse files
authored
Merge pull request #2183 from FabianKramm/print-feat
Default alwaysResolve to true
2 parents 8fa52db + 9677a6e commit d673fe7

File tree

11 files changed

+113
-28
lines changed

11 files changed

+113
-28
lines changed

pkg/devspace/config/loader/variable/resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (r *resolver) findVariablesInclude(haystack interface{}, include []*regexp.
144144

145145
// add always resolve variables
146146
for _, v := range r.vars {
147-
if v.AlwaysResolve {
147+
if v.AlwaysResolve == nil || *v.AlwaysResolve {
148148
varsUsed[v.Name] = true
149149
}
150150
}

pkg/devspace/config/versions/latest/schema.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,8 +1494,8 @@ type Variable struct {
14941494
// system.
14951495
Commands []VariableCommand `yaml:"commands,omitempty" json:"commands,omitempty" jsonschema_extras:"group=execution" jsonschema_description:"Commands are additional commands that can be used to run a different command on a different operating system."`
14961496

1497-
// AlwaysResolve makes sure this variable will always be resolved and not only if it is used somewhere
1498-
AlwaysResolve bool `yaml:"alwaysResolve,omitempty" json:"alwaysResolve,omitempty" jsonschema_description:"AlwaysResolve makes sure this variable will always be resolved and not only if it is used somewhere."`
1497+
// AlwaysResolve makes sure this variable will always be resolved and not only if it is used somewhere. Defaults to true.
1498+
AlwaysResolve *bool `yaml:"alwaysResolve,omitempty" json:"alwaysResolve,omitempty" jsonschema_description:"AlwaysResolve makes sure this variable will always be resolved and not only if it is used somewhere."`
14991499

15001500
// Source defines where the variable should be taken from
15011501
Source VariableSource `yaml:"source,omitempty" json:"source,omitempty" jsonschema_description:"Source defines where the variable should be taken from." jsonschema:"enum=all,enum=env,enum=input,enum=command,enum=none"`

pkg/devspace/config/versions/v1beta11/upgrade.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ func (c *Config) Upgrade(log log.Logger) (config.Config, error) {
7474
// convert vars
7575
if len(c.Vars) > 0 {
7676
nextConfig.Vars = map[string]*next.Variable{}
77-
for _, v := range c.Vars {
77+
for _, variable := range c.Vars {
78+
v := variable
7879
nextConfig.Vars[v.Name] = &next.Variable{
7980
Name: v.Name,
8081
Question: v.Question,
@@ -83,7 +84,7 @@ func (c *Config) Upgrade(log log.Logger) (config.Config, error) {
8384
ValidationPattern: v.ValidationPattern,
8485
ValidationMessage: v.ValidationMessage,
8586
NoCache: v.NoCache,
86-
AlwaysResolve: v.AlwaysResolve,
87+
AlwaysResolve: &v.AlwaysResolve,
8788
Value: v.Value,
8889
Default: v.Default,
8990
Source: next.VariableSource(v.Source),
@@ -104,7 +105,10 @@ func (c *Config) Upgrade(log log.Logger) (config.Config, error) {
104105
if nextConfig.Vars == nil {
105106
nextConfig.Vars = map[string]*next.Variable{}
106107
}
107-
nextConfig.Vars["DEVSPACE_ENV_FILE"] = &next.Variable{Value: ".env"}
108+
nextConfig.Vars["DEVSPACE_ENV_FILE"] = &next.Variable{
109+
Value: ".env",
110+
AlwaysResolve: ptr.Bool(false),
111+
}
108112

109113
deployPipeline := ""
110114
buildPipeline := ""

pkg/devspace/kubectl/portforward/portforward.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,20 @@ func (pf *PortForwarder) getListener(protocol string, hostname string, port *For
326326
// the background.
327327
func (pf *PortForwarder) waitForConnection(listener net.Listener, port ForwardedPort) {
328328
for {
329-
conn, err := listener.Accept()
330-
if err != nil {
331-
// TODO consider using something like https://github.com/hydrogen18/stoppableListener?
332-
if !strings.Contains(strings.ToLower(err.Error()), "use of closed network connection") {
333-
pf.raiseError(fmt.Errorf("error accepting connection on port %d: %v", port.Local, err))
334-
}
329+
select {
330+
case <-pf.streamConn.CloseChan():
335331
return
332+
default:
333+
conn, err := listener.Accept()
334+
if err != nil {
335+
// TODO consider using something like https://github.com/hydrogen18/stoppableListener?
336+
if !strings.Contains(strings.ToLower(err.Error()), "use of closed network connection") {
337+
pf.raiseError(fmt.Errorf("error accepting connection on port %d: %v", port.Local, err))
338+
}
339+
return
340+
}
341+
go pf.handleConnection(conn, port)
336342
}
337-
go pf.handleConnection(conn, port)
338343
}
339344
}
340345

pkg/devspace/pipeline/engine/pipelinehandler/commands/build_images.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package commands
22

33
import (
44
"fmt"
5+
"github.com/loft-sh/devspace/pkg/util/stringutil"
56
"strings"
67

78
flags "github.com/jessevdk/go-flags"
@@ -15,7 +16,8 @@ import (
1516
type BuildImagesOptions struct {
1617
build.Options
1718

18-
All bool `long:"all" description:"Build all images"`
19+
All bool `long:"all" description:"Build all images"`
20+
Except []string `long:"except" description:"If used with --all, will exclude the following images"`
1921

2022
Set []string `long:"set" description:"Set configuration"`
2123
SetString []string `long:"set-string" description:"Set configuration as string"`
@@ -42,13 +44,21 @@ func BuildImages(ctx devspacecontext.Context, pipeline types.Pipeline, args []st
4244
}
4345

4446
if options.All {
45-
images := ctx.Config().Config().Images
46-
for image := range images {
47+
args = []string{}
48+
for image := range ctx.Config().Config().Images {
49+
if stringutil.Contains(options.Except, image) {
50+
continue
51+
}
52+
53+
args = append(args, image)
4754
ctx, err = applySetValues(ctx, "images", image, options.Set, options.SetString, options.From, options.FromFile)
4855
if err != nil {
4956
return err
5057
}
5158
}
59+
if len(args) == 0 {
60+
return nil
61+
}
5262
} else if len(args) > 0 {
5363
for _, image := range args {
5464
ctx, err = applySetValues(ctx, "images", image, options.Set, options.SetString, options.From, options.FromFile)

pkg/devspace/pipeline/engine/pipelinehandler/commands/create_deployments.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
1010
"github.com/loft-sh/devspace/pkg/devspace/deploy"
1111
"github.com/loft-sh/devspace/pkg/devspace/pipeline/types"
12+
"github.com/loft-sh/devspace/pkg/util/stringutil"
1213
"github.com/loft-sh/devspace/pkg/util/strvals"
1314
"github.com/loft-sh/devspace/pkg/util/yamlutil"
1415
"github.com/pkg/errors"
@@ -26,7 +27,8 @@ type CreateDeploymentsOptions struct {
2627
From []string `long:"from" description:"Reuse an existing configuration"`
2728
FromFile []string `long:"from-file" description:"Reuse an existing configuration from a file"`
2829

29-
All bool `long:"all" description:"Deploy all deployments"`
30+
All bool `long:"all" description:"Deploy all deployments"`
31+
Except []string `long:"except" description:"If used with --all, will exclude the following deployments"`
3032
}
3133

3234
const ErrMsg = "Please make sure you have an existing valid kube config. You might want to check one of the following things:\n\n* Make sure you can use 'kubectl get namespaces' locally\n* If you are using Loft, you might want to run 'devspace create space' or 'loft create space'\n"
@@ -49,13 +51,21 @@ func CreateDeployments(ctx devspacecontext.Context, pipeline types.Pipeline, arg
4951
}
5052

5153
if options.All {
52-
deployments := ctx.Config().Config().Deployments
53-
for deployment := range deployments {
54+
args = []string{}
55+
for deployment := range ctx.Config().Config().Deployments {
56+
if stringutil.Contains(options.Except, deployment) {
57+
continue
58+
}
59+
60+
args = append(args, deployment)
5461
ctx, err = applySetValues(ctx, "deployments", deployment, options.Set, options.SetString, options.From, options.FromFile)
5562
if err != nil {
5663
return err
5764
}
5865
}
66+
if len(args) == 0 {
67+
return nil
68+
}
5969
} else if len(args) > 0 {
6070
for _, deployment := range args {
6171
ctx, err = applySetValues(ctx, "deployments", deployment, options.Set, options.SetString, options.From, options.FromFile)

pkg/devspace/pipeline/engine/pipelinehandler/commands/ensure_pull_secrets.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/loft-sh/devspace/pkg/devspace/docker"
88
"github.com/loft-sh/devspace/pkg/devspace/pipeline/types"
99
"github.com/loft-sh/devspace/pkg/devspace/pullsecrets"
10+
"github.com/loft-sh/devspace/pkg/util/stringutil"
1011
"github.com/pkg/errors"
1112
"strings"
1213
)
@@ -18,7 +19,8 @@ type EnsurePullSecretsOptions struct {
1819
From []string `long:"from" description:"Reuse an existing configuration"`
1920
FromFile []string `long:"from-file" description:"Reuse an existing configuration from a file"`
2021

21-
All bool `long:"all" description:"Ensure all pull secrets"`
22+
All bool `long:"all" description:"Ensure all pull secrets"`
23+
Except []string `long:"except" description:"If used with --all, will exclude the following pull secrets"`
2224
}
2325

2426
func EnsurePullSecrets(ctx devspacecontext.Context, pipeline types.Pipeline, args []string) error {
@@ -37,17 +39,25 @@ func EnsurePullSecrets(ctx devspacecontext.Context, pipeline types.Pipeline, arg
3739
}
3840

3941
if options.All {
40-
pullSecrets := ctx.Config().Config().PullSecrets
41-
if len(pullSecrets) == 0 {
42+
if len(ctx.Config().Config().PullSecrets) == 0 {
4243
return nil
4344
}
4445

45-
for pullSecret := range pullSecrets {
46+
args = []string{}
47+
for pullSecret := range ctx.Config().Config().PullSecrets {
48+
if stringutil.Contains(options.Except, pullSecret) {
49+
continue
50+
}
51+
52+
args = append(args, pullSecret)
4653
ctx, err = applySetValues(ctx, "pullSecrets", pullSecret, options.Set, options.SetString, options.From, options.FromFile)
4754
if err != nil {
4855
return err
4956
}
5057
}
58+
if len(args) == 0 {
59+
return nil
60+
}
5161
} else if len(args) > 0 {
5262
for _, pullSecret := range args {
5363
ctx, err = applySetValues(ctx, "pullSecrets", pullSecret, options.Set, options.SetString, options.From, options.FromFile)

pkg/devspace/pipeline/engine/pipelinehandler/commands/purge_deployments.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
77
"github.com/loft-sh/devspace/pkg/devspace/deploy"
88
"github.com/loft-sh/devspace/pkg/devspace/pipeline/types"
9+
"github.com/loft-sh/devspace/pkg/util/stringutil"
910
"github.com/pkg/errors"
1011
"strings"
1112
)
@@ -14,7 +15,8 @@ import (
1415
type PurgeDeploymentsOptions struct {
1516
deploy.PurgeOptions
1617

17-
All bool `long:"all" description:"Deploy all deployments"`
18+
All bool `long:"all" description:"Deploy all deployments"`
19+
Except []string `long:"except" description:"If used with --all, will exclude the following deployments"`
1820

1921
Sequential bool `long:"sequential" description:"Sequentially purges the deployments"`
2022

@@ -40,6 +42,18 @@ func PurgeDeployments(ctx devspacecontext.Context, pipeline types.Pipeline, args
4042

4143
if !options.All && len(args) == 0 {
4244
return fmt.Errorf("either specify 'purge_deployments --all' or 'purge_deployments deployment1 deployment2'")
45+
} else if options.All {
46+
args = []string{}
47+
for _, d := range ctx.Config().RemoteCache().ListDeployments() {
48+
if stringutil.Contains(options.Except, d.Name) {
49+
continue
50+
}
51+
52+
args = append(args, d.Name)
53+
}
54+
if len(args) == 0 {
55+
return nil
56+
}
4357
}
4458

4559
return deploy.NewController().Purge(ctx, args, &options.PurgeOptions)

pkg/devspace/pipeline/engine/pipelinehandler/commands/run_dependency_pipelines.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
types2 "github.com/loft-sh/devspace/pkg/devspace/dependency/types"
88
"github.com/loft-sh/devspace/pkg/devspace/hook"
99
"github.com/loft-sh/devspace/pkg/devspace/pipeline/types"
10+
"github.com/loft-sh/devspace/pkg/util/stringutil"
1011
"github.com/pkg/errors"
1112
"strings"
1213
)
@@ -15,7 +16,8 @@ import (
1516
type RunDependencyPipelinesOptions struct {
1617
types.DependencyOptions
1718

18-
All bool `long:"all" description:"Deploy all dependencies"`
19+
All bool `long:"all" description:"Deploy all dependencies"`
20+
Except []string `long:"except" description:"If used with --all, will exclude the following dependencies"`
1921
}
2022

2123
func RunDependencyPipelines(ctx devspacecontext.Context, pipeline types.Pipeline, args []string) error {
@@ -36,7 +38,16 @@ func RunDependencyPipelines(ctx devspacecontext.Context, pipeline types.Pipeline
3638
duplicates := map[string]bool{}
3739
deployDependencies := []types2.Dependency{}
3840
if options.All {
39-
deployDependencies = ctx.Dependencies()
41+
for _, dependency := range ctx.Dependencies() {
42+
if stringutil.Contains(options.Except, dependency.Name()) {
43+
continue
44+
}
45+
46+
deployDependencies = append(deployDependencies, dependency)
47+
}
48+
if len(deployDependencies) == 0 {
49+
return nil
50+
}
4051
} else if len(args) > 0 {
4152
for _, arg := range args {
4253
if duplicates[arg] {

pkg/devspace/pipeline/engine/pipelinehandler/commands/start_dev.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/loft-sh/devspace/pkg/devspace/devpod"
88
"github.com/loft-sh/devspace/pkg/devspace/pipeline/types"
99
logpkg "github.com/loft-sh/devspace/pkg/util/log"
10+
"github.com/loft-sh/devspace/pkg/util/stringutil"
1011
"github.com/pkg/errors"
1112
"strings"
1213
)
@@ -20,7 +21,8 @@ type StartDevOptions struct {
2021
From []string `long:"from" description:"Reuse an existing configuration"`
2122
FromFile []string `long:"from-file" description:"Reuse an existing configuration from a file"`
2223

23-
All bool `long:"all" description:"Start all dev configurations"`
24+
All bool `long:"all" description:"Start all dev configurations"`
25+
Except []string `long:"except" description:"If used with --all, will exclude the following dev configs"`
2426
}
2527

2628
func StartDev(ctx devspacecontext.Context, pipeline types.Pipeline, args []string) error {
@@ -41,12 +43,21 @@ func StartDev(ctx devspacecontext.Context, pipeline types.Pipeline, args []strin
4143
}
4244

4345
if options.All {
46+
args = []string{}
4447
for devConfig := range ctx.Config().Config().Dev {
48+
if stringutil.Contains(options.Except, devConfig) {
49+
continue
50+
}
51+
52+
args = append(args, devConfig)
4553
ctx, err = applySetValues(ctx, "dev", devConfig, options.Set, options.SetString, options.From, options.FromFile)
4654
if err != nil {
4755
return err
4856
}
4957
}
58+
if len(args) == 0 {
59+
return nil
60+
}
5061
} else if len(args) > 0 {
5162
for _, devConfig := range args {
5263
ctx, err = applySetValues(ctx, "dev", devConfig, options.Set, options.SetString, options.From, options.FromFile)

0 commit comments

Comments
 (0)