Skip to content

Automatically fix old configs by default #1259

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 7 commits into from
Nov 14, 2018
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
2 changes: 1 addition & 1 deletion cmd/skaffold/app/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func runBuild(out io.Writer) error {
defer cancel()
catchCtrlC(cancel)

runner, config, err := newRunner(opts)
runner, config, err := newRunner(out, opts)
if err != nil {
return errors.Wrap(err, "creating runner")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/skaffold/app/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func delete(out io.Writer) error {
defer cancel()
catchCtrlC(cancel)

runner, _, err := newRunner(opts)
runner, _, err := newRunner(out, opts)
if err != nil {
return errors.Wrap(err, "creating runner")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/skaffold/app/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func runDeploy(out io.Writer) error {
defer cancel()
catchCtrlC(cancel)

r, config, err := newRunner(opts)
r, config, err := newRunner(out, opts)
if err != nil {
return errors.Wrap(err, "creating runner")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/skaffold/app/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func dev(out io.Writer) error {
case <-ctx.Done():
return nil
default:
r, config, err := newRunner(opts)
r, config, err := newRunner(out, opts)
if err != nil {
return errors.Wrap(err, "creating runner")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/skaffold/app/cmd/diagnose.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewCmdDiagnose(out io.Writer) *cobra.Command {
}

func doDiagnose(out io.Writer) error {
_, config, err := newRunner(opts)
_, config, err := newRunner(out, opts)
if err != nil {
return errors.Wrap(err, "creating runner")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/skaffold/app/cmd/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewCmdFix(out io.Writer) *cobra.Command {
}

func runFix(out io.Writer, cfg schemautil.VersionedConfig) error {
cfg, err := schema.UpgradeToLatest(cfg)
cfg, err := schema.UpgradeToLatest(out, cfg)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/skaffold/app/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func run(out io.Writer) error {
defer cancel()
catchCtrlC(cancel)

runner, config, err := newRunner(opts)
runner, config, err := newRunner(out, opts)
if err != nil {
return errors.Wrap(err, "creating runner")
}
Expand Down
8 changes: 6 additions & 2 deletions cmd/skaffold/app/cmd/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package cmd

import (
"io"

configutil "github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/config"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
Expand All @@ -27,13 +29,15 @@ import (
)

// newRunner creates a SkaffoldRunner and returns the SkaffoldPipeline associated with it.
func newRunner(opts *config.SkaffoldOptions) (*runner.SkaffoldRunner, *latest.SkaffoldPipeline, error) {
func newRunner(out io.Writer, opts *config.SkaffoldOptions) (*runner.SkaffoldRunner, *latest.SkaffoldPipeline, error) {
parsed, err := schema.ParseConfig(opts.ConfigurationFile, true)
if err != nil {
return nil, nil, errors.Wrap(err, "parsing skaffold config")
}

if err := schema.CheckVersionIsLatest(parsed.GetVersion()); err != nil {
// automatically upgrade older config
parsed, err = schema.UpgradeToLatest(out, parsed)
if err != nil {
return nil, nil, errors.Wrap(err, "invalid config")
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ limitations under the License.
package latest

import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/apiversion"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util"
"github.com/blang/semver"
"github.com/pkg/errors"
yaml "gopkg.in/yaml.v2"
)

const Version string = "skaffold/v1alpha5"

func Semver() semver.Version {
return apiversion.MustParse(Version)
}

// NewSkaffoldPipeline creates a SkaffoldPipeline
func NewSkaffoldPipeline() util.VersionedConfig {
return new(SkaffoldPipeline)
Expand Down
127 changes: 127 additions & 0 deletions pkg/skaffold/schema/v1alpha1/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
Copyright 2018 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 v1alpha1

import (
"testing"

next "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha2"
"github.com/GoogleContainerTools/skaffold/testutil"
)

func TestPipelineUpgrade(t *testing.T) {
tests := []struct {
name string
yaml string
expected *next.SkaffoldPipeline
}{
{
name: "git tagger",
yaml: `apiVersion: skaffold/v1alpha1
kind: Config
build:
tagPolicy: gitCommit
`,
expected: &next.SkaffoldPipeline{
APIVersion: next.Version,
Kind: "Config",
Build: next.BuildConfig{
TagPolicy: next.TagPolicy{
GitTagger: &next.GitTagger{},
},
Artifacts: []*next.Artifact{},
},
},
},
{
name: "sha tagger",
yaml: `apiVersion: skaffold/v1alpha1
kind: Config
build:
tagPolicy: sha256
`,
expected: &next.SkaffoldPipeline{
APIVersion: next.Version,
Kind: "Config",
Build: next.BuildConfig{
TagPolicy: next.TagPolicy{
ShaTagger: &next.ShaTagger{},
},
Artifacts: []*next.Artifact{},
},
},
},
{
name: "normal skaffold yaml",
yaml: `apiVersion: skaffold/v1alpha1
kind: Config
build:
artifacts:
- imageName: gcr.io/k8s-skaffold/skaffold-example
deploy:
kubectl:
manifests:
- paths:
- k8s-*
`,
expected: &next.SkaffoldPipeline{
APIVersion: next.Version,
Kind: "Config",
Build: next.BuildConfig{
TagPolicy: next.TagPolicy{
GitTagger: &next.GitTagger{},
},
Artifacts: []*next.Artifact{
{
ImageName: "gcr.io/k8s-skaffold/skaffold-example",
ArtifactType: next.ArtifactType{
DockerArtifact: &next.DockerArtifact{},
},
},
},
},
Deploy: next.DeployConfig{
DeployType: next.DeployType{
KubectlDeploy: &next.KubectlDeploy{
Manifests: []string{
"k8s-*",
},
},
},
},
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pipeline := NewSkaffoldPipeline()
err := pipeline.Parse([]byte(tt.yaml), true)
if err != nil {
t.Fatalf("unexpected error during parsing old config: %v", err)
}

upgraded, err := pipeline.Upgrade()
if err != nil {
t.Errorf("unexpected error during upgrade: %v", err)
}

upgradedPipeline := upgraded.(*next.SkaffoldPipeline)
testutil.CheckDeepEqual(t, tt.expected, upgradedPipeline)
})
}
}
157 changes: 157 additions & 0 deletions pkg/skaffold/schema/v1alpha2/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*
Copyright 2018 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 v1alpha2

import (
"testing"

next "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha3"
"github.com/GoogleContainerTools/skaffold/testutil"
)

func TestPipelineUpgrade(t *testing.T) {
tests := []struct {
name string
yaml string
expected *next.SkaffoldPipeline
}{
{
name: "helm release values file",
yaml: `apiVersion: skaffold/v1alpha2
kind: Config
deploy:
helm:
releases:
- name: test release
valuesFilePath: values.yaml
`,
expected: &next.SkaffoldPipeline{
APIVersion: next.Version,
Kind: "Config",
Deploy: next.DeployConfig{
DeployType: next.DeployType{
HelmDeploy: &next.HelmDeploy{
Releases: []next.HelmRelease{
{
Name: "test release",
ValuesFiles: []string{"values.yaml"},
},
},
},
},
},
},
},
{
name: "normal skaffold yaml with kaniko",
yaml: `apiVersion: skaffold/v1alpha2
kind: Config
build:
artifacts:
- imageName: gcr.io/k8s-skaffold/skaffold-example
kaniko:
gcsBucket: k8s-skaffold
pullSecret: /a/secret/path/kaniko.json
deploy:
kubectl:
manifests:
- k8s-*
profiles:
- name: test profile
build:
artifacts:
- imageName: gcr.io/k8s-skaffold/skaffold-example
deploy:
kubectl:
manifests:
- k8s-*
`,
expected: &next.SkaffoldPipeline{
APIVersion: next.Version,
Kind: "Config",
Build: next.BuildConfig{
TagPolicy: next.TagPolicy{},
Artifacts: []*next.Artifact{
{
ImageName: "gcr.io/k8s-skaffold/skaffold-example",
ArtifactType: next.ArtifactType{},
},
},
BuildType: next.BuildType{
KanikoBuild: &next.KanikoBuild{
PullSecret: "/a/secret/path/kaniko.json",
BuildContext: next.KanikoBuildContext{
GCSBucket: "k8s-skaffold",
},
},
},
},
Deploy: next.DeployConfig{
DeployType: next.DeployType{
KubectlDeploy: &next.KubectlDeploy{
Manifests: []string{
"k8s-*",
},
},
},
},
Profiles: []next.Profile{
{
Name: "test profile",
Build: next.BuildConfig{
TagPolicy: next.TagPolicy{},
Artifacts: []*next.Artifact{
{
ImageName: "gcr.io/k8s-skaffold/skaffold-example",
ArtifactType: next.ArtifactType{},
},
},
},
Deploy: next.DeployConfig{
DeployType: next.DeployType{
KubectlDeploy: &next.KubectlDeploy{
Manifests: []string{
"k8s-*",
},
},
},
},
},
},
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pipeline := NewSkaffoldPipeline()
err := pipeline.Parse([]byte(tt.yaml), true)
if err != nil {
t.Fatalf("unexpected error during parsing old config: %v", err)
}

upgraded, err := pipeline.Upgrade()
if err != nil {
t.Errorf("unexpected error during upgrade: %v", err)
}

upgradedPipeline := upgraded.(*next.SkaffoldPipeline)
tt.expected.SetDefaultValues()
testutil.CheckDeepEqual(t, tt.expected, upgradedPipeline)
})
}
}
Loading