Skip to content

Commit cf1cb71

Browse files
authored
Merge pull request #1969 from FabianKramm/master
refactor: improve logging
2 parents b85b2d9 + 87df387 commit cf1cb71

8 files changed

Lines changed: 113 additions & 195 deletions

File tree

cmd/enter.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ type EnterCmd struct {
3232
Pick bool
3333
Wait bool
3434
Reconnect bool
35+
Screen bool
36+
ScreenSession string
3537

3638
WorkingDirectory string
3739

@@ -79,6 +81,8 @@ devspace enter bash --image-selector "${runtime.images.app.image}:${runtime.imag
7981
enterCmd.Flags().BoolVar(&cmd.Pick, "pick", true, "Select a pod / container if multiple are found")
8082
enterCmd.Flags().BoolVar(&cmd.Wait, "wait", false, "Wait for the pod(s) to start if they are not running")
8183
enterCmd.Flags().BoolVar(&cmd.Reconnect, "reconnect", false, "Will reconnect the terminal if an unexpected return code is encountered")
84+
enterCmd.Flags().BoolVar(&cmd.Screen, "screen", false, "Use a screen session to connect")
85+
enterCmd.Flags().StringVar(&cmd.ScreenSession, "screen-session", "enter", "The screen session to create or connect to")
8286

8387
return enterCmd
8488
}
@@ -158,7 +162,7 @@ func (cmd *EnterCmd) Run(f factory.Factory, args []string) error {
158162

159163
// Start terminal
160164
stdout, stderr, stdin := defaultStdStreams(cmd.Stdout, cmd.Stderr, cmd.Stdin)
161-
exitCode, err := terminal.StartTerminalFromCMD(ctx, targetselector.NewTargetSelector(selectorOptions), command, cmd.Wait, cmd.Reconnect, stdout, stderr, stdin)
165+
exitCode, err := terminal.StartTerminalFromCMD(ctx, targetselector.NewTargetSelector(selectorOptions), command, cmd.Wait, cmd.Reconnect, cmd.Screen, cmd.ScreenSession, stdout, stderr, stdin)
162166
if err != nil {
163167
return err
164168
} else if exitCode != 0 {

pkg/devspace/deploy/deploy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
helmclient "github.com/loft-sh/devspace/pkg/devspace/helm"
1111
"github.com/loft-sh/devspace/pkg/devspace/hook"
1212
kubectlclient "github.com/loft-sh/devspace/pkg/devspace/kubectl"
13+
"github.com/mgutz/ansi"
1314
"github.com/pkg/errors"
1415
"io"
1516
"sort"
@@ -249,7 +250,7 @@ func (c *controller) deployOne(ctx *devspacecontext.Context, deployConfig *lates
249250
}
250251

251252
if wasDeployed {
252-
ctx.Log.Donef("Successfully deployed %s with %s", deployConfig.Name, method)
253+
ctx.Log.Donef("Successfully deployed %s with %s", ansi.Color(deployConfig.Name, "white+b"), ansi.Color(method, "white+b"))
253254
// Execute after deployment deploy hook
254255
err = hook.ExecuteHooks(ctx, map[string]interface{}{
255256
"DEPLOY_NAME": deployConfig.Name,

pkg/devspace/helm/generic/generic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (c *client) Exec(ctx *devspacecontext.Context, args []string) ([]byte, erro
7878

7979
// disable log for list, because it prints same command multiple times if we've multiple deployments.
8080
if args[0] != "list" {
81-
c.log.Infof("Execute '%s %s'", c.helmPath, strings.Join(args, " "))
81+
c.log.Debugf("Execute '%s %s'", c.helmPath, strings.Join(args, " "))
8282
}
8383
result, err := command.Output(ctx.Context, ctx.WorkingDir, c.helmPath, args...)
8484
if err != nil {

pkg/devspace/kubectl/client.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ package kubectl
22

33
import (
44
"context"
5+
"fmt"
56
"github.com/loft-sh/devspace/pkg/devspace/config/localcache"
7+
"github.com/loft-sh/devspace/pkg/devspace/kubectl/util"
8+
"github.com/loft-sh/devspace/pkg/devspace/upgrade"
69
"io"
710
"net"
811
"net/url"
912
"os"
1013
"sort"
11-
"time"
12-
13-
"github.com/loft-sh/devspace/pkg/devspace/kubectl/util"
14-
"github.com/loft-sh/devspace/pkg/devspace/upgrade"
1514

1615
"github.com/loft-sh/devspace/pkg/util/kubeconfig"
1716
"github.com/loft-sh/devspace/pkg/util/log"
@@ -176,7 +175,7 @@ func NewClientBySelect(allowPrivate bool, switchContext bool, kubeLoader kubecon
176175
}
177176
}
178177

179-
// Returns the underlying kube client config
178+
// ClientConfig returns the underlying kube client config
180179
func (client *client) ClientConfig() clientcmd.ClientConfig {
181180
return client.clientConfig
182181
}
@@ -273,12 +272,25 @@ func CheckKubeContext(client Client, localCache localcache.Cache, noWarning, aut
273272
}
274273

275274
// Warn if using default namespace unless previous deployment was also to default namespace
276-
if log.GetLevel() >= logrus.InfoLevel && currentConfigContext.Namespace == metav1.NamespaceDefault &&
277-
(lastConfigContext == nil ||
278-
lastConfigContext.Namespace != metav1.NamespaceDefault) {
279-
log.Warn("Deploying into the 'default' namespace is usually not a good idea as this namespace cannot be deleted\n")
280-
log.Info("Will continue in 5 seconds...")
281-
time.Sleep(5 * time.Second)
275+
if isTerminalIn &&
276+
log.GetLevel() >= logrus.InfoLevel &&
277+
currentConfigContext.Namespace == metav1.NamespaceDefault &&
278+
(lastConfigContext == nil || lastConfigContext.Namespace != metav1.NamespaceDefault) {
279+
log.Warn("Deploying into the 'default' namespace is usually not a good idea as this namespace cannot be deleted")
280+
log.Warn("Please use 'devspace use namespace my-namespace' to select a different one\n")
281+
useDefault, err := log.Question(&survey.QuestionOptions{
282+
Question: "Are you sure you want to use the 'default' namespace?",
283+
DefaultValue: "No",
284+
Options: []string{
285+
"No",
286+
"Yes",
287+
},
288+
})
289+
if err != nil {
290+
return client, err
291+
} else if useDefault == "No" {
292+
return nil, fmt.Errorf("please run 'devspace use namespace my-namespace' to select a different namespace before rerunning")
293+
}
282294
}
283295
}
284296

pkg/devspace/kubectl/helper/helper.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

pkg/devspace/kubectl/loader/loader.go

Lines changed: 0 additions & 104 deletions
This file was deleted.

pkg/devspace/services/inject/inject.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ func downloadSyncHelper(ctx context.Context, helperName, syncBinaryFolder, versi
191191
if err == nil {
192192
// make sure the sha is correct, but skip for latest because that is development
193193
if version == "latest" {
194+
log.Debugf("Use development devspacehelper found at %s", filepath)
194195
return nil
195196
}
196197

@@ -221,6 +222,7 @@ func downloadSyncHelper(ctx context.Context, helperName, syncBinaryFolder, versi
221222

222223
// the file is correct we skip downloading
223224
if fileHash == strings.Split(string(shaHash), " ")[0] {
225+
log.Debugf("Use local devspacehelper found at %s", filepath)
224226
return nil
225227
}
226228

0 commit comments

Comments
 (0)