Skip to content

Commit

Permalink
Add StatusCheck field to skaffold.yaml (GoogleContainerTools#4904)
Browse files Browse the repository at this point in the history
  • Loading branch information
maggieneterval committed Apr 28, 2021
1 parent d38ab4d commit 1aea5ca
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 27 deletions.
3 changes: 3 additions & 0 deletions cmd/skaffold/app/cmd/fix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ deploy:
kubectl:
manifests:
- k8s/deployment.yaml
statusCheck: true
`, latest_v1.Version),
},
{
Expand Down Expand Up @@ -97,6 +98,7 @@ deploy:
kubectl:
manifests:
- k8s/deployment.yaml
statusCheck: true
`, latest_v1.Version),
},
{
Expand Down Expand Up @@ -197,6 +199,7 @@ deploy:
kubectl:
manifests:
- k8s/deployment.yaml
statusCheck: true
`, latest_v1.Version)

testutil.Run(t, "", func(t *testutil.T) {
Expand Down
5 changes: 3 additions & 2 deletions docs/content/en/docs/workflows/ci-cd.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ This feature can be very useful in Continuous Delivery pipelines to ensure that
healthy before proceeding with the next steps in the pipeline.

{{<alert title="Note">}}
`healthcheck` is enabled by default; it can be disabled with the `--status-check=false` flag.
`healthcheck` is enabled by default; it can be disabled with the `--status-check=false`
flag, or by setting the `statusCheck` field of the deployment config stanza in
the `skaffold.yaml` to false.
{{</alert>}}

To determine if a `Deployment` resource is up and running, Skaffold relies on `kubectl rollout status` to obtain its status.
Expand All @@ -59,7 +61,6 @@ the time specified by [`progressDeadlineSeconds`](https://kubernetes.io/docs/con
from the deployment configuration.

If the `Deployment.spec.progressDeadlineSeconds` is not set, Skaffold will either wait for

the time specified in the `statusCheckDeadlineSeconds` field of the deployment config stanza in the `skaffold.yaml`, or
default to 10 minutes if this is not specified.

Expand Down
7 changes: 7 additions & 0 deletions docs/content/en/schemas/v2beta15.json
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,12 @@
"description": "configures how container logs are printed as a result of a deployment.",
"x-intellij-html-description": "configures how container logs are printed as a result of a deployment."
},
"statusCheck": {
"type": "boolean",
"description": "*beta* enables waiting for deployments to stabilize.",
"x-intellij-html-description": "<em>beta</em> enables waiting for deployments to stabilize.",
"default": "false"
},
"statusCheckDeadlineSeconds": {
"type": "integer",
"description": "*beta* deadline for deployments to stabilize in seconds.",
Expand All @@ -1058,6 +1064,7 @@
"kpt",
"kubectl",
"kustomize",
"statusCheck",
"statusCheckDeadlineSeconds",
"kubeContext",
"logs"
Expand Down
63 changes: 42 additions & 21 deletions pkg/skaffold/runner/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,54 @@ import (
func TestDeploy(t *testing.T) {
expectedOutput := "Waiting for deployments to stabilize..."
tests := []struct {
description string
testBench *TestBench
statusCheck config.BoolOrUndefined
shouldErr bool
shouldWait bool
description string
testBench *TestBench
statusCheckCLI config.BoolOrUndefined // --status-check CLI flag
statusCheck bool // skaffold.yaml Deploy.StatusCheck field
shouldErr bool
shouldWait bool
}{
{
description: "deploy shd perform status check",
testBench: &TestBench{},
statusCheck: config.NewBoolOrUndefined(nil),
shouldWait: true,
description: "deploy shd perform status check when statusCheckCLI true, statusCheck true",
testBench: &TestBench{},
statusCheckCLI: config.NewBoolOrUndefined(util.BoolPtr(true)),
statusCheck: true,
shouldWait: true,
},
{
description: "deploy shd perform status check",
testBench: &TestBench{},
statusCheck: config.NewBoolOrUndefined(util.BoolPtr(true)),
shouldWait: true,
description: "deploy shd perform status check when statusCheckCLI true, statusCheck false",
testBench: &TestBench{},
statusCheckCLI: config.NewBoolOrUndefined(util.BoolPtr(true)),
shouldWait: true,
},
{
description: "deploy shd not perform status check",
testBench: &TestBench{},
statusCheck: config.NewBoolOrUndefined(util.BoolPtr(false)),
description: "deploy shd not perform status check when statusCheckCLI false, statusCheck true",
testBench: &TestBench{},
statusCheckCLI: config.NewBoolOrUndefined(util.BoolPtr(false)),
statusCheck: true,
},
{
description: "deploy shd not perform status check when statusCheckCLI false, statusCheck false",
testBench: &TestBench{},
statusCheckCLI: config.NewBoolOrUndefined(util.BoolPtr(false)),
},
{
description: "deploy shd perform status check when statusCheckCLI nil, statusCheck true",
testBench: &TestBench{},
statusCheckCLI: config.NewBoolOrUndefined(nil),
statusCheck: true,
shouldWait: true,
},
{
description: "deploy shd not perform status check when statusCheckCLI nil, statusCheck false",
testBench: &TestBench{},
statusCheckCLI: config.NewBoolOrUndefined(nil),
},
{
description: "deploy shd not perform status check when deployer is in error",
testBench: &TestBench{deployErrors: []error{errors.New("deploy error")}},
shouldErr: true,
statusCheck: config.NewBoolOrUndefined(util.BoolPtr(true)),
description: "deploy shd not perform status check when deployer is in error",
testBench: &TestBench{deployErrors: []error{errors.New("deploy error")}},
shouldErr: true,
statusCheckCLI: config.NewBoolOrUndefined(util.BoolPtr(true)),
},
}

Expand All @@ -82,7 +102,8 @@ func TestDeploy(t *testing.T) {
})

runner := createRunner(t, test.testBench, nil, []*latest_v1.Artifact{{ImageName: "img1"}, {ImageName: "img2"}}, nil)
runner.runCtx.Opts.StatusCheck = test.statusCheck
runner.runCtx.Opts.StatusCheck = test.statusCheckCLI
runner.runCtx.Pipelines.All()[0].Deploy.StatusCheck = test.statusCheck
out := new(bytes.Buffer)

err := runner.Deploy(context.Background(), out, []graph.Artifact{
Expand Down
20 changes: 16 additions & 4 deletions pkg/skaffold/runner/runcontext/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ func (ps Pipelines) TestCases() []*latest_v1.TestCase {
return tests
}

func (ps Pipelines) StatusCheck() bool {
var sc bool
// set the group status check to enabled if any pipeline has it enabled
for _, p := range ps.pipelines {
if p.Deploy.StatusCheck {
sc = true
}
}
return sc
}

func (ps Pipelines) StatusCheckDeadlineSeconds() int {
c := 0
// set the group status check deadline to maximum of any individually specified value
Expand Down Expand Up @@ -147,11 +158,12 @@ func (rc *RunContext) Deployers() []latest_v1.DeployType { return rc.Pipelines.D
func (rc *RunContext) TestCases() []*latest_v1.TestCase { return rc.Pipelines.TestCases() }

func (rc *RunContext) StatusCheck() bool {
sc := rc.Opts.StatusCheck.Value()
if sc == nil {
return true
scOpts := rc.Opts.StatusCheck.Value()
scPipelines := rc.Pipelines.StatusCheck()
if scOpts == nil {
return scPipelines
}
return *sc
return *scOpts
}

func (rc *RunContext) StatusCheckDeadlineSeconds() int {
Expand Down
3 changes: 3 additions & 0 deletions pkg/skaffold/schema/latest/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,9 @@ type TestCase struct {
type DeployConfig struct {
DeployType `yaml:",inline"`

// StatusCheck *beta* enables waiting for deployments to stabilize.
StatusCheck bool `yaml:"statusCheck,omitempty"`

// StatusCheckDeadlineSeconds *beta* is the deadline for deployments to stabilize in seconds.
StatusCheckDeadlineSeconds int `yaml:"statusCheckDeadlineSeconds,omitempty"`

Expand Down
2 changes: 2 additions & 0 deletions pkg/skaffold/schema/v2beta14/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

// Upgrade upgrades a configuration to the next version.
// Config changes from v2beta14 to v2beta15
// 1. Additions: `Deploy.StatusCheck` (defaults to true)
func (c *SkaffoldConfig) Upgrade() (util.VersionedConfig, error) {
var newConfig next.SkaffoldConfig
pkgutil.CloneThroughJSON(c, &newConfig)
Expand All @@ -34,5 +35,6 @@ func (c *SkaffoldConfig) Upgrade() (util.VersionedConfig, error) {
}

func upgradeOnePipeline(oldPipeline, newPipeline interface{}) error {
newPipeline.(*next.Pipeline).Deploy.StatusCheck = true
return nil
}
3 changes: 3 additions & 0 deletions pkg/skaffold/schema/v2beta14/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ deploy:
kustomize:
paths:
- kustomization-main
statusCheck: true
portForward:
- resourceType: deployment
resourceName: leeroy-app
Expand Down Expand Up @@ -163,6 +164,7 @@ profiles:
kustomize:
paths:
- kustomization-test
statusCheck: true
- name: test local
build:
artifacts:
Expand All @@ -176,6 +178,7 @@ profiles:
manifests:
- k8s-*
kustomize: {}
statusCheck: true
`
verifyUpgrade(t, yaml, expected)
}
Expand Down

0 comments on commit 1aea5ca

Please sign in to comment.