Skip to content

Add status check flag #2338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cmd/skaffold/app/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ var FlagRegistry = []Flag{
FlagAddMethod: "BoolVar",
DefinedOn: []string{"dev", "debug"},
},
{
Name: "status-check",
Usage: "Wait for deployed resources to stabilize",
Value: &opts.StatusCheck,
DefValue: true,
FlagAddMethod: "BoolVar",
DefinedOn: []string{"dev", "debug", "deploy"},
},
}

var commandFlags []*pflag.Flag
Expand Down Expand Up @@ -256,6 +264,7 @@ func AddFlags(fs *pflag.FlagSet, cmdName string) {
fs.AddFlag(f)
}
}
fs.MarkHidden("status-check")
}

func hasCmdAnnotation(cmdName string, annotations []string) bool {
Expand Down
4 changes: 3 additions & 1 deletion cmd/skaffold/man/man.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ func printCommand(out io.Writer, command *cobra.Command) {
fmt.Fprint(out, "Env vars:\n\n")

command.LocalFlags().VisitAll(func(flag *pflag.Flag) {
fmt.Fprintf(out, "* `%s` (same as `--%s`)\n", cmd.FlagToEnvVarName(flag), flag.Name)
if !flag.Hidden {
fmt.Fprintf(out, "* `%s` (same as `--%s`)\n", cmd.FlagToEnvVarName(flag), flag.Name)
}
})
}

Expand Down
1 change: 0 additions & 1 deletion docs/content/en/docs/references/cli/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ Use "skaffold [command] --help" for more information about a command.
Env vars:

* `SKAFFOLD_COLOR` (same as `--color`)
* `SKAFFOLD_FORCE_COLORS` (same as `--force-colors`)
* `SKAFFOLD_VERBOSITY` (same as `--verbosity`)

### skaffold build
Expand Down
1 change: 1 addition & 0 deletions pkg/skaffold/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type SkaffoldOptions struct {
ForceDev bool
NoPrune bool
NoPruneChildren bool
StatusCheck bool
PortForward PortForwardOptions
CustomTag string
Namespace string
Expand Down
74 changes: 74 additions & 0 deletions pkg/skaffold/runner/deploy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copyright 2019 The Skaffold Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package runner

import (
"bytes"
"context"
"errors"
"strings"
"testing"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
"github.com/GoogleContainerTools/skaffold/testutil"
)

func TestDeploy(t *testing.T) {
expectedOutput := "Waiting for deployments to stabilize"
var tests = []struct {
description string
testBench *TestBench
statusCheck bool
shouldErr bool
shouldWait bool
}{
{
description: "deploy shd perform status check",
testBench: &TestBench{},
statusCheck: true,
shouldWait: true,
},
{
description: "deploy shd not perform status check",
testBench: &TestBench{},
},
{
description: "deploy shd not perform status check when deployer is in error",
shouldErr: true,
statusCheck: true,
testBench: &TestBench{deployErrors: []error{errors.New("deploy error")}},
},
}

for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {

runner := createRunner(t, test.testBench)
runner.runCtx.Opts.StatusCheck = test.statusCheck
out := new(bytes.Buffer)

err := runner.Deploy(context.Background(), out, []build.Artifact{
{ImageName: "img1", Tag: "img1:tag1"},
{ImageName: "img2", Tag: "img2:tag2"},
})
t.CheckError(test.shouldErr, err)
if strings.Contains(out.String(), expectedOutput) != test.shouldWait {
t.Errorf("expected %s to contain %s %t. But found %t", out.String(), expectedOutput, test.shouldWait, !test.shouldWait)
}
})
}
}
14 changes: 13 additions & 1 deletion pkg/skaffold/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,19 @@ func (r *SkaffoldRunner) Deploy(ctx context.Context, out io.Writer, artifacts []

err := r.Deployer.Deploy(ctx, out, artifacts, r.labellers)
r.hasDeployed = true
return err
if err != nil {
return err
}
return r.performStatusCheck(out)
}

func (r *SkaffoldRunner) performStatusCheck(out io.Writer) error {
// Check if we need to perform deploy status
if r.runCtx.Opts.StatusCheck {
fmt.Fprintln(out, "Waiting for deployments to stabilize")
// TODO : Actually perform status check
}
return nil
}

// HasDeployed returns true if this runner has deployed something.
Expand Down