Skip to content

Commit 66934bd

Browse files
committed
Merge branch 'master' into v6-docs
2 parents a70ccf0 + b08646b commit 66934bd

316 files changed

Lines changed: 7584 additions & 6374 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: golangci-lint
2222
uses: golangci/golangci-lint-action@v2
2323
with:
24-
version: v1.29
24+
version: v1.45.2
2525
args:
2626
-v
2727
--config=.golangci.yml

cmd/attach.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,7 @@ func (cmd *AttachCmd) Run(f factory.Factory, cobraCmd *cobra.Command, args []str
9696
}
9797

9898
// create the context
99-
ctx := &devspacecontext.Context{
100-
Context: context.Background(),
101-
KubeClient: client,
102-
Log: log,
103-
}
99+
ctx := devspacecontext.NewContext(context.Background(), nil, log).WithKubeClient(client)
104100

105101
// Execute plugin hook
106102
err = hook.ExecuteHooks(ctx, nil, "attach")

cmd/build.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package cmd
22

33
import (
44
"github.com/loft-sh/devspace/cmd/flags"
5+
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
56
"github.com/loft-sh/devspace/pkg/util/factory"
67
"github.com/spf13/cobra"
78
)
89

910
// NewBuildCmd creates a new devspace build command
10-
func NewBuildCmd(f factory.Factory, globalFlags *flags.GlobalFlags) *cobra.Command {
11+
func NewBuildCmd(f factory.Factory, globalFlags *flags.GlobalFlags, rawConfig *RawConfig) *cobra.Command {
1112
cmd := &RunPipelineCmd{
1213
GlobalFlags: globalFlags,
1314
Pipeline: "build",
@@ -23,10 +24,14 @@ func NewBuildCmd(f factory.Factory, globalFlags *flags.GlobalFlags) *cobra.Comma
2324
Builds all defined images and pushes them
2425
#######################################################`,
2526
RunE: func(cobraCmd *cobra.Command, args []string) error {
26-
return cmd.Run(cobraCmd, args, f, "build", "buildCommand")
27+
return cmd.Run(cobraCmd, args, f, "buildCommand")
2728
},
2829
}
2930

30-
cmd.AddFlags(buildCmd)
31+
var pipeline *latest.Pipeline
32+
if rawConfig != nil && rawConfig.Config != nil && rawConfig.Config.Pipelines != nil {
33+
pipeline = rawConfig.Config.Pipelines["build"]
34+
}
35+
cmd.AddPipelineFlags(f, buildCmd, pipeline)
3136
return buildCmd
3237
}

cmd/deploy.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package cmd
22

33
import (
44
"github.com/loft-sh/devspace/cmd/flags"
5+
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
56
"github.com/loft-sh/devspace/pkg/util/factory"
67
"github.com/spf13/cobra"
78
)
89

910
// NewDeployCmd creates a new deploy command
10-
func NewDeployCmd(f factory.Factory, globalFlags *flags.GlobalFlags) *cobra.Command {
11+
func NewDeployCmd(f factory.Factory, globalFlags *flags.GlobalFlags, rawConfig *RawConfig) *cobra.Command {
1112
cmd := &RunPipelineCmd{
1213
GlobalFlags: globalFlags,
1314
SkipPushLocalKubernetes: true,
@@ -29,10 +30,14 @@ devspace deploy --kube-context=deploy-context
2930
#######################################################`,
3031
Args: cobra.NoArgs,
3132
RunE: func(cobraCmd *cobra.Command, args []string) error {
32-
return cmd.Run(cobraCmd, args, f, "deploy", "deployCommand")
33+
return cmd.Run(cobraCmd, args, f, "deployCommand")
3334
},
3435
}
3536

36-
cmd.AddFlags(deployCmd)
37+
var pipeline *latest.Pipeline
38+
if rawConfig != nil && rawConfig.Config != nil && rawConfig.Config.Pipelines != nil {
39+
pipeline = rawConfig.Config.Pipelines["deploy"]
40+
}
41+
cmd.AddPipelineFlags(f, deployCmd, pipeline)
3742
return deployCmd
3843
}

cmd/dev.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package cmd
22

33
import (
44
"github.com/loft-sh/devspace/cmd/flags"
5+
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
56
"github.com/loft-sh/devspace/pkg/util/factory"
67
"github.com/spf13/cobra"
78
)
89

910
// NewDevCmd creates a new devspace dev command
10-
func NewDevCmd(f factory.Factory, globalFlags *flags.GlobalFlags) *cobra.Command {
11+
func NewDevCmd(f factory.Factory, globalFlags *flags.GlobalFlags, rawConfig *RawConfig) *cobra.Command {
1112
cmd := &RunPipelineCmd{
1213
GlobalFlags: globalFlags,
1314
SkipPushLocalKubernetes: true,
@@ -24,10 +25,14 @@ Starts your project in development mode
2425
#######################################################`,
2526
Args: cobra.NoArgs,
2627
RunE: func(cobraCmd *cobra.Command, args []string) error {
27-
return cmd.Run(cobraCmd, args, f, "dev", "devCommand")
28+
return cmd.Run(cobraCmd, args, f, "devCommand")
2829
},
2930
}
3031

31-
cmd.AddFlags(devCmd)
32+
var pipeline *latest.Pipeline
33+
if rawConfig != nil && rawConfig.Config != nil && rawConfig.Config.Pipelines != nil {
34+
pipeline = rawConfig.Config.Pipelines["dev"]
35+
}
36+
cmd.AddPipelineFlags(f, devCmd, pipeline)
3237
return devCmd
3338
}

cmd/enter.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,7 @@ func (cmd *EnterCmd) Run(f factory.Factory, args []string) error {
123123
}
124124

125125
// create the context
126-
ctx := &devspacecontext.Context{
127-
Context: context.Background(),
128-
KubeClient: client,
129-
Log: logger,
130-
}
126+
ctx := devspacecontext.NewContext(context.Background(), nil, logger).WithKubeClient(client)
131127

132128
// Execute plugin hook
133129
err = hook.ExecuteHooks(ctx, nil, "enter")

cmd/flags/flags.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ type GlobalFlags struct {
1515
Namespace string
1616
KubeContext string
1717
Profiles []string
18-
ProfileRefresh bool
1918
DisableProfileActivation bool
2019
SwitchContext bool
2120
ConfigPath string
@@ -33,7 +32,6 @@ func (gf *GlobalFlags) ToConfigOptions() *loader.ConfigOptions {
3332
return &loader.ConfigOptions{
3433
OverrideName: gf.OverrideName,
3534
Profiles: profiles,
36-
ProfileRefresh: gf.ProfileRefresh,
3735
DisableProfileActivation: gf.DisableProfileActivation,
3836
Vars: gf.Vars,
3937
}
@@ -51,15 +49,36 @@ func SetGlobalFlags(flags *flag.FlagSet) *GlobalFlags {
5149
flags.BoolVar(&globalFlags.Debug, "debug", false, "Prints the stack trace if an error occurs")
5250
flags.BoolVar(&globalFlags.Silent, "silent", false, "Run in silent mode and prevents any devspace log output except panics & fatals")
5351

54-
flags.StringVar(&globalFlags.ConfigPath, "config", "", "The devspace config file to use")
5552
flags.StringSliceVarP(&globalFlags.Profiles, "profile", "p", []string{}, "The DevSpace profiles to apply. Multiple profiles are applied in the order they are specified")
56-
flags.BoolVar(&globalFlags.ProfileRefresh, "profile-refresh", false, "If true will pull and re-download profile parent sources")
5753
flags.BoolVar(&globalFlags.DisableProfileActivation, "disable-profile-activation", false, "If true will ignore all profile activations")
5854
flags.BoolVarP(&globalFlags.SwitchContext, "switch-context", "s", false, "Switches and uses the last kube context and namespace that was used to deploy the DevSpace project")
5955
flags.StringVarP(&globalFlags.Namespace, "namespace", "n", "", "The kubernetes namespace to use")
6056
flags.StringVar(&globalFlags.KubeContext, "kube-context", "", "The kubernetes context to use")
6157
flags.StringSliceVar(&globalFlags.Vars, "var", []string{}, "Variables to override during execution (e.g. --var=MYVAR=MYVALUE)")
6258

6359
flags.IntVar(&globalFlags.InactivityTimeout, "inactivity-timeout", 0, "Minutes the current user is inactive (no mouse or keyboard interaction) until DevSpace will exit automatically. 0 to disable. Only supported on windows and mac operating systems")
60+
flags.AddFlag(&flag.Flag{
61+
Name: "config",
62+
Usage: "DEPRECATED: please use the DEVSPACE_CONFIG environment variable instead",
63+
Hidden: true,
64+
Value: NewStringValue("", &globalFlags.ConfigPath),
65+
})
6466
return globalFlags
6567
}
68+
69+
type StringValue string
70+
71+
func NewStringValue(val string, p *string) *StringValue {
72+
*p = val
73+
return (*StringValue)(p)
74+
}
75+
76+
func (s *StringValue) Set(val string) error {
77+
*s = StringValue(val)
78+
return nil
79+
}
80+
func (s *StringValue) Type() string {
81+
return "string"
82+
}
83+
84+
func (s *StringValue) String() string { return string(*s) }

cmd/flags/flags_test.go

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,71 +3,18 @@ package flags
33
import (
44
"testing"
55

6-
"github.com/loft-sh/devspace/pkg/devspace/config/localcache"
7-
"github.com/loft-sh/devspace/pkg/util/log"
8-
96
"gotest.tools/assert"
107
)
118

12-
type useLastContextTestCase struct {
13-
name string
14-
15-
globalFlags GlobalFlags
16-
generatedConfig *localcache.Config
17-
18-
expectedErr string
19-
}
20-
21-
func TestUseLastContext(t *testing.T) {
22-
testCases := []useLastContextTestCase{
23-
{
24-
name: "Switch context to existent",
25-
globalFlags: GlobalFlags{
26-
SwitchContext: true,
27-
},
28-
generatedConfig: &localcache.Config{
29-
ActiveProfile: "someProfile",
30-
Profiles: map[string]*localcache.CacheConfig{
31-
"someProfile": {
32-
LastContext: &localcache.LastContextConfig{
33-
Context: "myKubeContext",
34-
Namespace: "myNamespace",
35-
},
36-
},
37-
},
38-
},
39-
},
40-
{
41-
name: "Nothing happens",
42-
globalFlags: GlobalFlags{},
43-
},
44-
}
45-
46-
for _, testCase := range testCases {
47-
testUseLastContext(t, testCase)
48-
}
49-
}
50-
51-
func testUseLastContext(t *testing.T, testCase useLastContextTestCase) {
52-
err := testCase.globalFlags.UseLastContext(testCase.generatedConfig, &log.DiscardLogger{})
53-
54-
if testCase.expectedErr == "" {
55-
assert.NilError(t, err, "Unexpected error in testCase %s.", testCase.name)
56-
} else {
57-
assert.Error(t, err, testCase.expectedErr, "Wrong or no error in testCase %s.", testCase.name)
58-
}
59-
}
60-
619
func TestToConfigOptions(t *testing.T) {
6210
configOptions := (&GlobalFlags{
6311
Profiles: []string{"myProfile2", "myProfile"},
6412
KubeContext: "myKubeContext",
6513
Vars: []string{"var1", "var2"},
66-
}).ToConfigOptions(log.Discard)
14+
}).ToConfigOptions()
6715

6816
assert.Equal(t, configOptions.Profiles[0], "myProfile2", "ConfigOptions has wrong profiles")
6917
assert.Equal(t, configOptions.Profiles[1], "myProfile", "ConfigOptions has wrong profiles")
70-
assert.Equal(t, configOptions.KubeContext, "myKubeContext", "ConfigOptions has wrong kube context")
7118
assert.Equal(t, len(configOptions.Vars), 2, "ConfigOptions has wrong vars")
7219
assert.Equal(t, configOptions.Vars[0], "var1", "ConfigOptions has wrong vars")
7320
assert.Equal(t, configOptions.Vars[1], "var2", "ConfigOptions has wrong vars")

0 commit comments

Comments
 (0)