Skip to content

Commit

Permalink
Merge pull request #989 from FabianKramm/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
FabianKramm authored Mar 2, 2020
2 parents b69206a + 655d1cb commit a33d043
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 26 deletions.
10 changes: 8 additions & 2 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,14 @@ func (cmd *BuildCmd) Run(f factory.Factory, cobraCmd *cobra.Command, args []stri
}
}

// Create kubectl client and switch context if specified
client, err := f.NewKubeClientFromContext(cmd.KubeContext, cmd.Namespace, cmd.SwitchContext)
if err != nil {
return errors.Errorf("Unable to create new kubectl client: %v", err)
}

// Create Dependencymanager
manager, err := f.NewDependencyManager(config, generatedConfig, nil, cmd.AllowCyclicDependencies, configOptions, log)
manager, err := f.NewDependencyManager(config, generatedConfig, client, cmd.AllowCyclicDependencies, configOptions, log)
if err != nil {
return errors.Wrap(err, "new manager")
}
Expand All @@ -116,7 +122,7 @@ func (cmd *BuildCmd) Run(f factory.Factory, cobraCmd *cobra.Command, args []stri
}

// Build images if necessary
builtImages, err := f.NewBuildController(config, generatedConfig.GetActive(), nil).Build(&build.Options{
builtImages, err := f.NewBuildController(config, generatedConfig.GetActive(), client).Build(&build.Options{
SkipPush: cmd.SkipPush,
IsDev: true,
ForceRebuild: cmd.ForceBuild,
Expand Down
26 changes: 15 additions & 11 deletions cmd/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ func (cmd *RenderCmd) Run(f factory.Factory, cobraCmd *cobra.Command, args []str
configExists, err := configLoader.SetDevSpaceRoot()
if err != nil {
return err
}
if !configExists {
} else if !configExists {
return errors.New(message.ConfigNotFound)
}

Expand All @@ -106,6 +105,11 @@ func (cmd *RenderCmd) Run(f factory.Factory, cobraCmd *cobra.Command, args []str
// Get the config
config, err := configLoader.Load()
if err != nil {
cause := errors.Cause(err)
if _, ok := cause.(logpkg.SurveyError); ok {
return errors.New("Cannot load config, because questions for variables are not possible in silent mode. Please set '--show-logs' to true to disable silent mode")
}

return err
}

Expand All @@ -116,9 +120,15 @@ func (cmd *RenderCmd) Run(f factory.Factory, cobraCmd *cobra.Command, args []str
}
}

// Create kubectl client and switch context if specified
client, err := f.NewKubeClientFromContext(cmd.KubeContext, cmd.Namespace, cmd.SwitchContext)
if err != nil {
return errors.Errorf("Unable to create new kubectl client: %v", err)
}

// Create Dependencymanager
if cmd.SkipDependencies == false {
// Create Dependencymanager
manager, err := f.NewDependencyManager(config, generatedConfig, nil, cmd.AllowCyclicDependencies, configOptions, log)
manager, err := f.NewDependencyManager(config, generatedConfig, client, cmd.AllowCyclicDependencies, configOptions, log)
if err != nil {
return errors.Wrap(err, "new manager")
}
Expand All @@ -143,7 +153,7 @@ func (cmd *RenderCmd) Run(f factory.Factory, cobraCmd *cobra.Command, args []str
// Build images if necessary
builtImages := map[string]string{}
if cmd.SkipBuild == false {
builtImages, err = f.NewBuildController(config, generatedConfig.GetActive(), nil).Build(&build.Options{
builtImages, err = f.NewBuildController(config, generatedConfig.GetActive(), client).Build(&build.Options{
SkipPush: cmd.SkipPush,
IsDev: true,
ForceRebuild: cmd.ForceBuild,
Expand Down Expand Up @@ -179,12 +189,6 @@ func (cmd *RenderCmd) Run(f factory.Factory, cobraCmd *cobra.Command, args []str
}
}

// Create kubectl client
client, err := f.NewKubeClientFromContext(cmd.KubeContext, cmd.Namespace, cmd.SwitchContext)
if err != nil {
return errors.Errorf("Unable to create new kubectl client: %v", err)
}

// Deploy all defined deployments
err = f.NewDeployController(config, generatedConfig.GetActive(), client).Render(&deploy.Options{
BuiltImages: builtImages,
Expand Down
3 changes: 3 additions & 0 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ go run . test --test=deploy,init
=== ONLY RUN SPECIFIC SUB TESTS FOR A SPECIFIC TEST SUITE ===
go run . test --test-deploy=default,deploy
go run . test --test-init=use_chart,use_dockerfile


go run . test
25 changes: 16 additions & 9 deletions pkg/devspace/dependency/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,29 @@ func (m *manager) handleDependencies(filterDependencies []string, reverse, updat
i = len(dependencies) - 1
}

executed := 0
m.log.StartWait(fmt.Sprintf("%s %d dependencies", actionName, len(dependencies)))
for i >= 0 && i < len(dependencies) {
var (
dependency = dependencies[i]
buff = &bytes.Buffer{}
dependencyLogger = m.log
)

// Increase / Decrease counter
if reverse {
i--
} else {
i++
}

// Check if we should act on this dependency
if foundDependency(dependency.DependencyConfig.Name, filterDependencies) == false {
continue
}

// If not verbose log to a stream
if verbose == false {
m.log.StartWait(fmt.Sprintf("%s %d dependencies", actionName, i+1))
dependencyLogger = log.NewStreamLogger(buff, logrus.InfoLevel)
}

Expand All @@ -186,17 +194,16 @@ func (m *manager) handleDependencies(filterDependencies []string, reverse, updat
return errors.Errorf("%s dependency %s error: %s %v", actionName, dependency.ID, buff.String(), err)
}

executed++
m.log.Donef("%s dependency %s completed", actionName, dependency.ID)

if reverse {
i--
} else {
i++
}
}

m.log.StopWait()
m.log.Donef("Successfully executed %d dependencies", len(dependencies))

if executed > 0 {
m.log.Donef("Successfully processed %d dependencies", executed)
} else {
m.log.Done("No dependency processed")
}

return nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/devspace/helm/v2cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func (c *client) InstallChart(releaseName string, releaseNamespace string, value
for {
result, err = c.exec(c.helmPath, args).CombinedOutput()
if err != nil {
if strings.HasSuffix(string(result), "could not find a ready tiller pod") {
time.Sleep(time.Second * 2)
if strings.Index(string(result), "could not find a ready tiller pod") != -1 {
time.Sleep(time.Second * 3)
err = c.ensureTiller()
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions pkg/devspace/kubectl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func NewClientFromContext(context, namespace string, switchContext bool, kubeLoa
return nil, err
}

if len(kubeConfig.Clusters) == 0 {
return nil, errors.Errorf("kube config is invalid: please make sure you have an existing valid kube config")
}

// If we should use a certain kube context use that
var (
activeContext = kubeConfig.CurrentContext
Expand Down
11 changes: 9 additions & 2 deletions pkg/util/log/discard_logger.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package log

import (
"errors"
"fmt"
"os"

Expand Down Expand Up @@ -106,5 +105,13 @@ func (d *DiscardLogger) WriteString(message string) {}

// Question asks a new question
func (d *DiscardLogger) Question(params *survey.QuestionOptions) (string, error) {
return "", errors.New("Questions in discard logger not supported")
return "", SurveyError{}
}

// SurveyError is used to identify errors where questions were asked in the discard logger
type SurveyError struct{}

// Error implements error interface
func (s SurveyError) Error() string {
return "Asking questions is not possible in silenced mode"
}

0 comments on commit a33d043

Please sign in to comment.