Skip to content

Commit c8a1e41

Browse files
committed
refactor: make commands and pull secrets maps
1 parent d68f5ba commit c8a1e41

File tree

42 files changed

+693
-550
lines changed

Some content is hidden

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

42 files changed

+693
-550
lines changed

cmd/deploy.go

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ package cmd
33
import (
44
"context"
55
"fmt"
6+
"github.com/loft-sh/devspace/cmd/flags"
7+
"github.com/loft-sh/devspace/pkg/devspace/analyze"
68
"github.com/loft-sh/devspace/pkg/devspace/build"
79
"github.com/loft-sh/devspace/pkg/devspace/config/loader"
810
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
911
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
12+
"github.com/loft-sh/devspace/pkg/devspace/dependency"
1013
"github.com/loft-sh/devspace/pkg/devspace/dependency/registry"
1114
"github.com/loft-sh/devspace/pkg/devspace/deploy"
1215
"github.com/loft-sh/devspace/pkg/devspace/dev"
@@ -18,19 +21,14 @@ import (
1821
"github.com/loft-sh/devspace/pkg/devspace/plugin"
1922
"github.com/loft-sh/devspace/pkg/devspace/server"
2023
"github.com/loft-sh/devspace/pkg/devspace/upgrade"
21-
"github.com/sirupsen/logrus"
22-
"gopkg.in/yaml.v3"
23-
"k8s.io/client-go/kubernetes/fake"
24-
"time"
25-
26-
"github.com/loft-sh/devspace/cmd/flags"
27-
"github.com/loft-sh/devspace/pkg/devspace/analyze"
28-
"github.com/loft-sh/devspace/pkg/devspace/dependency"
2924
"github.com/loft-sh/devspace/pkg/util/factory"
3025
logpkg "github.com/loft-sh/devspace/pkg/util/log"
3126
"github.com/loft-sh/devspace/pkg/util/message"
3227
"github.com/pkg/errors"
28+
"github.com/sirupsen/logrus"
3329
"github.com/spf13/cobra"
30+
"gopkg.in/yaml.v3"
31+
"k8s.io/client-go/kubernetes/fake"
3432
)
3533

3634
// DeployCmd holds the required data for the down cmd
@@ -234,12 +232,6 @@ func runPipeline(ctx *devspacecontext.Context, f factory.Factory, options *Pipel
234232
}
235233
}
236234

237-
// create docker client
238-
dockerClient, err := f.NewDockerClient(ctx.Log)
239-
if err != nil {
240-
dockerClient = nil
241-
}
242-
243235
// deploy dependencies
244236
dependencies, err := f.NewDependencyManager(ctx, options.ConfigOptions).ResolveAll(ctx, dependency.ResolveOptions{
245237
SkipDependencies: options.DependencyOptions.Exclude,
@@ -262,12 +254,6 @@ func runPipeline(ctx *devspacecontext.Context, f factory.Factory, options *Pipel
262254
return err
263255
}
264256

265-
// create pull secrets if necessary
266-
err = f.NewPullSecretClient(dockerClient).EnsurePullSecrets(ctx, ctx.KubeClient.Namespace())
267-
if err != nil {
268-
ctx.Log.Warn(err)
269-
}
270-
271257
// update last used kube context & save generated yaml
272258
err = updateLastKubeContext(ctx)
273259
if err != nil {
@@ -339,24 +325,5 @@ func startServices(ctx *devspacecontext.Context, uiPort int) (*server.Server, er
339325
return nil, err
340326
}
341327

342-
// Run dev.open configs
343-
for _, openConfig := range ctx.Config.Config().Open {
344-
if openConfig.URL != "" {
345-
maxWait := 4 * time.Minute
346-
ctx.Log.Infof("Opening '%s' as soon as application will be started (timeout: %s)", openConfig.URL, maxWait)
347-
348-
go func(url string) {
349-
// Use DiscardLogger as we do not want to print warnings about failed HTTP requests
350-
err := openURL(url, nil, "", logpkg.Discard, maxWait)
351-
if err != nil {
352-
// Use warn instead of fatal to prevent exit
353-
// Do not print warning
354-
// log.Warn(err)
355-
_ = err // just to avoid empty branch (SA9003) lint error
356-
}
357-
}(openConfig.URL)
358-
}
359-
}
360-
361328
return serv, nil
362329
}

cmd/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ func (cmd *InitCmd) addDevConfig(config *latest.Config, imageName, image string,
515515
config.Dev["default"].Forward = portMappings
516516

517517
// Add dev.open config
518-
config.Open = []*latest.OpenConfig{
518+
config.Dev["default"].Open = []*latest.OpenConfig{
519519
{
520520
URL: "http://localhost:" + strconv.Itoa(localPort),
521521
},

cmd/open.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/loft-sh/devspace/pkg/devspace/services/portforwarding"
1010
"github.com/loft-sh/devspace/pkg/devspace/services/targetselector"
1111
"github.com/sirupsen/logrus"
12+
networkingv1 "k8s.io/api/networking/v1"
1213
"k8s.io/apimachinery/pkg/labels"
1314
"net/http"
1415
"os"
@@ -38,9 +39,7 @@ import (
3839
"github.com/skratchdot/open-golang/open"
3940
"github.com/spf13/cobra"
4041
v1 "k8s.io/api/core/v1"
41-
"k8s.io/api/extensions/v1beta1"
4242
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
43-
"k8s.io/apimachinery/pkg/util/intstr"
4443
)
4544

4645
const (
@@ -194,19 +193,23 @@ func (cmd *OpenCmd) RunOpen(f factory.Factory) error {
194193
domainHash := hash.String(domain)
195194

196195
ingressName := "devspace-ingress-" + domainHash[:10]
197-
_, err = client.KubeClient().ExtensionsV1beta1().Ingresses(namespace).Create(context.TODO(), &v1beta1.Ingress{
196+
_, err = client.KubeClient().NetworkingV1().Ingresses(namespace).Create(context.TODO(), &networkingv1.Ingress{
198197
ObjectMeta: metav1.ObjectMeta{Name: ingressName},
199-
Spec: v1beta1.IngressSpec{
200-
Rules: []v1beta1.IngressRule{
198+
Spec: networkingv1.IngressSpec{
199+
Rules: []networkingv1.IngressRule{
201200
{
202201
Host: domain,
203-
IngressRuleValue: v1beta1.IngressRuleValue{
204-
HTTP: &v1beta1.HTTPIngressRuleValue{
205-
Paths: []v1beta1.HTTPIngressPath{
202+
IngressRuleValue: networkingv1.IngressRuleValue{
203+
HTTP: &networkingv1.HTTPIngressRuleValue{
204+
Paths: []networkingv1.HTTPIngressPath{
206205
{
207-
Backend: v1beta1.IngressBackend{
208-
ServiceName: serviceName,
209-
ServicePort: intstr.FromInt(servicePort),
206+
Backend: networkingv1.IngressBackend{
207+
Service: &networkingv1.IngressServiceBackend{
208+
Name: serviceName,
209+
Port: networkingv1.ServiceBackendPort{
210+
Number: int32(servicePort),
211+
},
212+
},
210213
},
211214
},
212215
},
@@ -326,7 +329,7 @@ func (cmd *OpenCmd) openLocal(ctx *devspacecontext.Context, domain string) error
326329
},
327330
}
328331

329-
devSpaceConfig := config.Ensure(config.NewConfig(nil, fakeConfig, nil, nil, nil, constants.DefaultConfigPath))
332+
devSpaceConfig := config.Ensure(config.NewConfig(nil, nil, fakeConfig, nil, nil, nil, constants.DefaultConfigPath))
330333
ctx = ctx.WithConfig(devSpaceConfig)
331334
options := targetselector.NewEmptyOptions().
332335
WithLabelSelector(labels.Set(labelSelector).String()).
@@ -440,7 +443,7 @@ func (cmd *OpenCmd) findDomain(client kubectl.Client, namespace, host string) (s
440443
cmd.log.Info("Retrieve ingresses...")
441444

442445
// List all ingresses and only create one if there is none already
443-
ingressList, err := client.KubeClient().ExtensionsV1beta1().Ingresses(namespace).List(context.TODO(), metav1.ListOptions{})
446+
ingressList, err := client.KubeClient().NetworkingV1().Ingresses(namespace).List(context.TODO(), metav1.ListOptions{})
444447
if err != nil {
445448
return "", false, errors.Errorf("Error listing ingresses: %v", err)
446449
}

cmd/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func (cmd *RunCmd) RunRun(f factory.Factory, args []string) error {
204204
return dependency.ExecuteCommand(ctx.Context, commands, args[0], args[1:], ctx.WorkingDir, cmd.Stdout, cmd.Stderr, os.Stdin)
205205
}
206206

207-
func getCommands(f factory.Factory) ([]*latest.CommandConfig, error) {
207+
func getCommands(f factory.Factory) (map[string]*latest.CommandConfig, error) {
208208
// get current working dir
209209
cwd, err := os.Getwd()
210210
if err != nil {

cmd/set/var.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ type variableParser struct {
128128
Used map[string]bool
129129
}
130130

131-
func (v *variableParser) Parse(ctx context.Context, originalRawConfig map[string]interface{}, rawConfig map[string]interface{}, resolver variable.Resolver, log log.Logger) (*latest.Config, error) {
131+
func (v *variableParser) Parse(ctx context.Context, originalRawConfig map[string]interface{}, rawConfig map[string]interface{}, resolver variable.Resolver, log log.Logger) (*latest.Config, map[string]interface{}, error) {
132132
// Find out what vars are really used
133133
varsUsed, err := resolver.FindVariables(rawConfig)
134134
if err != nil {
135-
return nil, err
135+
return nil, nil, err
136136
}
137137

138138
v.Definitions = resolver.DefinedVars()
139139
v.Used = varsUsed
140-
return latest.NewRaw(), nil
140+
return latest.NewRaw(), map[string]interface{}{}, nil
141141
}

examples/kustomize/devspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ vars:
44
value: yourusername/devspace
55
images:
66
default:
7-
image: ${IMAGE}
7+
image: loft-sh/vcluster
88
deployments:
99
- name: devspace-app
1010
kubectl:

examples/pipelines/devspace.yaml

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
version: v2beta1
22
name: pipelines
33

4-
commands:
5-
- name: dev
6-
command: |-
7-
devspace --config dep1/dependency.yaml run dev
8-
9-
dependencies:
10-
- source:
11-
path: dep1/dependency.yaml
12-
134
pipelines:
5+
helper:
6+
steps:
7+
- run: |-
8+
echo "Hello World!"
149
dev:
1510
steps:
1611
- run: |-
17-
run_dependencies_pipelines --all
18-
19-
export IMAGE=testfabi
12+
export TEST=$(run_pipelines helper)
13+
echo $TEST > swag.txt
2014
21-
build_images test --set image=${IMAGE}
15+
#build_images test --set image=${IMAGE}
2216
23-
# Deploy test here
24-
create_deployments test --set helm.componentChart=true \
25-
--set helm.values.containers[0].image=${runtime.images.test}
17+
#create_deployments test2
2618
2719
# Start development mode for test here
28-
start_dev test --set imageSelector=${runtime.images.test} \
29-
--set terminal.command=sh
20+
#start_dev test --set imageSelector=${runtime.images.test} \
21+
# --set terminal.command=sh

pkg/devspace/build/builder/kaniko/kaniko.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (b *Builder) createPullSecret(ctx *devspacecontext.Context) error {
145145
password = authConfig.IdentityToken
146146
}
147147

148-
return pullsecrets.NewClient(b.dockerClient).CreatePullSecret(ctx, &pullsecrets.PullSecretOptions{
148+
return pullsecrets.NewClient().CreatePullSecret(ctx, &pullsecrets.PullSecretOptions{
149149
Namespace: b.BuildNamespace,
150150
RegistryURL: registryURL,
151151
Username: username,

pkg/devspace/build/create_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (c *controller) createBuilder(ctx *devspacecontext.Context, imageConfigName
9797

9898
dockerClient, err := dockerclient.NewClient(ctx.Log)
9999
if err == nil {
100-
err = pullsecrets.NewClient(dockerClient).EnsurePullSecret(ctx, ctx.KubeClient.Namespace(), registryURL)
100+
err = pullsecrets.NewClient().EnsurePullSecret(ctx, dockerClient, ctx.KubeClient.Namespace(), registryURL)
101101
if err != nil {
102102
ctx.Log.Errorf("error ensuring pull secret for registry %s: %v", registryURL, err)
103103
}

pkg/devspace/command/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
// ExecuteCommand executes a command from the config
17-
func ExecuteCommand(ctx context.Context, commands []*latest.CommandConfig, name string, args []string, dir string, stdout io.Writer, stderr io.Writer, stdin io.Reader) error {
17+
func ExecuteCommand(ctx context.Context, commands map[string]*latest.CommandConfig, name string, args []string, dir string, stdout io.Writer, stderr io.Writer, stdin io.Reader) error {
1818
shellCommand := ""
1919
var shellArgs []string
2020
var appendArgs bool

0 commit comments

Comments
 (0)