Skip to content

Commit 9677a6e

Browse files
committed
feat: add --except to pipeline functions
1 parent 8999afd commit 9677a6e

File tree

7 files changed

+91
-15
lines changed

7 files changed

+91
-15
lines changed

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)

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

Lines changed: 11 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 StopDevOptions struct {
1516
deploy.PurgeOptions
1617

17-
All bool `long:"all" description:"Stop all dev configurations"`
18+
All bool `long:"all" description:"Stop all dev configurations"`
19+
Except []string `long:"except" description:"If used with --all, will exclude the following dev configs"`
1820
}
1921

2022
func StopDev(ctx devspacecontext.Context, pipeline types.Pipeline, args []string) error {
@@ -38,6 +40,10 @@ func StopDev(ctx devspacecontext.Context, pipeline types.Pipeline, args []string
3840
if options.All {
3941
// loop over all pods in dev manager
4042
for _, a := range devManager.List() {
43+
if stringutil.Contains(options.Except, a) {
44+
continue
45+
}
46+
4147
ctx = ctx.WithLogger(ctx.Log().WithPrefix("dev:" + a + " "))
4248
ctx.Log().Infof("Stopping dev %s", a)
4349
err = devManager.Reset(ctx, a, &options.PurgeOptions)
@@ -48,6 +54,10 @@ func StopDev(ctx devspacecontext.Context, pipeline types.Pipeline, args []string
4854

4955
// loop over all in cache
5056
for _, a := range ctx.Config().RemoteCache().ListDevPods() {
57+
if stringutil.Contains(options.Except, a.Name) {
58+
continue
59+
}
60+
5161
ctx = ctx.WithLogger(ctx.Log().WithPrefix("dev:" + a.Name + " "))
5262
ctx.Log().Infof("Stopping dev %s", a.Name)
5363
err = devManager.Reset(ctx, a.Name, &options.PurgeOptions)

0 commit comments

Comments
 (0)