Skip to content

Commit

Permalink
[V3] (Part 1) Refactor schema "latest" to "latest/v1" (#5728)
Browse files Browse the repository at this point in the history
See details in [doc](https://docs.google.com/document/d/1GFy_5ya-ajjSVe1t6f7IWUlAQu35eTHAZZ1GkJBiqcA/edit?resourcekey=0-sKE-yXjuymQ0w2qqNXnTzw#heading=h.az97ji6gorca)

- In pkg/skaffold/schema, move ./latest/* to ./latest/v1/* (so as later on once we add v2, v1 and v2 can both be imported as latest)
- Update the reference of "latest" to "latest_v1" (pkg/ cmd/ integration/)
- Fix build.ArtifactDependencies reference in pkg/build/maven.

Note: We use alias `latest_v1` instead of `v1` to import package pkg/skaffold/schema/latest/v1.
The "latest" prefix is to distinguish another "v1" package which is also under pkg/skaffold/schema

Next: some latest_v1 reference may be bisected for v2 package.
  • Loading branch information
yuwenma authored Apr 28, 2021
1 parent 41ce1f5 commit d38ab4d
Show file tree
Hide file tree
Showing 252 changed files with 2,932 additions and 2,929 deletions.
4 changes: 2 additions & 2 deletions cmd/skaffold/app/cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
latest_v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
)

// NewCmdApply describes the CLI command to apply manifests to a cluster.
Expand All @@ -53,7 +53,7 @@ func doApply(ctx context.Context, out io.Writer, args []string) error {
if err := validateManifests(args); err != nil {
return err
}
return withRunner(ctx, out, func(r runner.Runner, configs []*latest.SkaffoldConfig) error {
return withRunner(ctx, out, func(r runner.Runner, configs []*latest_v1.SkaffoldConfig) error {
return r.Apply(ctx, out)
})
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/skaffold/app/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/flags"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
latest_v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
)

var (
Expand Down Expand Up @@ -67,7 +67,7 @@ func doBuild(ctx context.Context, out io.Writer) error {
buildOut = ioutil.Discard
}

return withRunner(ctx, out, func(r runner.Runner, configs []*latest.SkaffoldConfig) error {
return withRunner(ctx, out, func(r runner.Runner, configs []*latest_v1.SkaffoldConfig) error {
bRes, err := r.Build(ctx, buildOut, targetArtifacts(opts, configs))

if quietFlag || buildOutputFlag != "" {
Expand All @@ -94,8 +94,8 @@ func doBuild(ctx context.Context, out io.Writer) error {
})
}

func targetArtifacts(opts config.SkaffoldOptions, configs []*latest.SkaffoldConfig) []*latest.Artifact {
var targetArtifacts []*latest.Artifact
func targetArtifacts(opts config.SkaffoldOptions, configs []*latest_v1.SkaffoldConfig) []*latest_v1.Artifact {
var targetArtifacts []*latest_v1.Artifact
for _, cfg := range configs {
for _, artifact := range cfg.Build.Artifacts {
if opts.IsTargetImage(artifact) {
Expand Down
24 changes: 12 additions & 12 deletions cmd/skaffold/app/cmd/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
latest_v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
"github.com/GoogleContainerTools/skaffold/testutil"
)

type mockRunner struct {
runner.Runner
}

func (r *mockRunner) Build(ctx context.Context, out io.Writer, artifacts []*latest.Artifact) ([]graph.Artifact, error) {
func (r *mockRunner) Build(ctx context.Context, out io.Writer, artifacts []*latest_v1.Artifact) ([]graph.Artifact, error) {
out.Write([]byte("Build Completed"))
return []graph.Artifact{{
ImageName: "gcr.io/skaffold/example",
Expand All @@ -50,8 +50,8 @@ func (r *mockRunner) Stop() error {
}

func TestTagFlag(t *testing.T) {
mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, *runcontext.RunContext, error) {
return &mockRunner{}, []*latest.SkaffoldConfig{{}}, nil, nil
mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest_v1.SkaffoldConfig, *runcontext.RunContext, error) {
return &mockRunner{}, []*latest_v1.SkaffoldConfig{{}}, nil, nil
}

testutil.Run(t, "override tag with argument", func(t *testutil.T) {
Expand All @@ -69,8 +69,8 @@ func TestTagFlag(t *testing.T) {
}

func TestQuietFlag(t *testing.T) {
mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, *runcontext.RunContext, error) {
return &mockRunner{}, []*latest.SkaffoldConfig{{}}, nil, nil
mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest_v1.SkaffoldConfig, *runcontext.RunContext, error) {
return &mockRunner{}, []*latest_v1.SkaffoldConfig{{}}, nil, nil
}

tests := []struct {
Expand Down Expand Up @@ -115,8 +115,8 @@ func TestQuietFlag(t *testing.T) {
}

func TestFileOutputFlag(t *testing.T) {
mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, *runcontext.RunContext, error) {
return &mockRunner{}, []*latest.SkaffoldConfig{{}}, nil, nil
mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest_v1.SkaffoldConfig, *runcontext.RunContext, error) {
return &mockRunner{}, []*latest_v1.SkaffoldConfig{{}}, nil, nil
}

tests := []struct {
Expand Down Expand Up @@ -178,16 +178,16 @@ func TestFileOutputFlag(t *testing.T) {
}

func TestRunBuild(t *testing.T) {
errRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, *runcontext.RunContext, error) {
errRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest_v1.SkaffoldConfig, *runcontext.RunContext, error) {
return nil, nil, nil, errors.New("some error")
}
mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, *runcontext.RunContext, error) {
return &mockRunner{}, []*latest.SkaffoldConfig{{}}, nil, nil
mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest_v1.SkaffoldConfig, *runcontext.RunContext, error) {
return &mockRunner{}, []*latest_v1.SkaffoldConfig{{}}, nil, nil
}

tests := []struct {
description string
mock func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, *runcontext.RunContext, error)
mock func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest_v1.SkaffoldConfig, *runcontext.RunContext, error)
shouldErr bool
}{
{
Expand Down
6 changes: 3 additions & 3 deletions cmd/skaffold/app/cmd/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
latest_v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
"github.com/GoogleContainerTools/skaffold/testutil"
)

Expand All @@ -49,8 +49,8 @@ func TestNewCmdDebug(t *testing.T) {
func TestDebugIndependentFromDev(t *testing.T) {
mockRunner := &mockDevRunner{}
testutil.Run(t, "DevDebug", func(t *testutil.T) {
t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, *runcontext.RunContext, error) {
return mockRunner, []*latest.SkaffoldConfig{{}}, nil, nil
t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest_v1.SkaffoldConfig, *runcontext.RunContext, error) {
return mockRunner, []*latest_v1.SkaffoldConfig{{}}, nil, nil
})
t.Override(&opts, config.SkaffoldOptions{})
t.Override(&doDev, func(context.Context, io.Writer) error {
Expand Down
4 changes: 2 additions & 2 deletions cmd/skaffold/app/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/spf13/cobra"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
latest_v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
)

// NewCmdDelete describes the CLI command to delete deployed resources.
Expand All @@ -35,7 +35,7 @@ func NewCmdDelete() *cobra.Command {
}

func doDelete(ctx context.Context, out io.Writer) error {
return withRunner(ctx, out, func(r runner.Runner, _ []*latest.SkaffoldConfig) error {
return withRunner(ctx, out, func(r runner.Runner, _ []*latest_v1.SkaffoldConfig) error {
return r.Cleanup(ctx, out)
})
}
6 changes: 3 additions & 3 deletions cmd/skaffold/app/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/tips"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
latest_v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
)

var (
Expand All @@ -51,11 +51,11 @@ func NewCmdDeploy() *cobra.Command {
}

func doDeploy(ctx context.Context, out io.Writer) error {
return withRunner(ctx, out, func(r runner.Runner, configs []*latest.SkaffoldConfig) error {
return withRunner(ctx, out, func(r runner.Runner, configs []*latest_v1.SkaffoldConfig) error {
if opts.SkipRender {
return r.DeployAndLog(ctx, out, []graph.Artifact{})
}
var artifacts []*latest.Artifact
var artifacts []*latest_v1.Artifact
for _, cfg := range configs {
artifacts = append(artifacts, cfg.Build.Artifacts...)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/skaffold/app/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/spf13/cobra"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
latest_v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
)

// for testing
Expand Down Expand Up @@ -60,8 +60,8 @@ func runDev(ctx context.Context, out io.Writer) error {
case <-ctx.Done():
return nil
default:
err := withRunner(ctx, out, func(r runner.Runner, configs []*latest.SkaffoldConfig) error {
var artifacts []*latest.Artifact
err := withRunner(ctx, out, func(r runner.Runner, configs []*latest_v1.SkaffoldConfig) error {
var artifacts []*latest_v1.Artifact
for _, cfg := range configs {
artifacts = append(artifacts, cfg.Build.Artifacts...)
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/skaffold/app/cmd/dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
latest_v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
"github.com/GoogleContainerTools/skaffold/testutil"
)

Expand All @@ -37,7 +37,7 @@ type mockDevRunner struct {
calls []string
}

func (r *mockDevRunner) Dev(context.Context, io.Writer, []*latest.Artifact) error {
func (r *mockDevRunner) Dev(context.Context, io.Writer, []*latest_v1.Artifact) error {
r.calls = append(r.calls, "Dev")
return r.errDev
}
Expand Down Expand Up @@ -96,8 +96,8 @@ func TestDoDev(t *testing.T) {
hasDeployed: test.hasDeployed,
errDev: context.Canceled,
}
t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, *runcontext.RunContext, error) {
return mockRunner, []*latest.SkaffoldConfig{{}}, nil, nil
t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest_v1.SkaffoldConfig, *runcontext.RunContext, error) {
return mockRunner, []*latest_v1.SkaffoldConfig{{}}, nil, nil
})
t.Override(&opts, config.SkaffoldOptions{
Cleanup: true,
Expand All @@ -117,7 +117,7 @@ type mockConfigChangeRunner struct {
cycles int
}

func (m *mockConfigChangeRunner) Dev(context.Context, io.Writer, []*latest.Artifact) error {
func (m *mockConfigChangeRunner) Dev(context.Context, io.Writer, []*latest_v1.Artifact) error {
m.cycles++
if m.cycles == 1 {
// pass through the first cycle with a config reload
Expand Down Expand Up @@ -146,8 +146,8 @@ func TestDevConfigChange(t *testing.T) {
testutil.Run(t, "test config change", func(t *testutil.T) {
mockRunner := &mockConfigChangeRunner{}

t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, *runcontext.RunContext, error) {
return mockRunner, []*latest.SkaffoldConfig{{}}, nil, nil
t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest_v1.SkaffoldConfig, *runcontext.RunContext, error) {
return mockRunner, []*latest_v1.SkaffoldConfig{{}}, nil, nil
})
t.Override(&opts, config.SkaffoldOptions{
Cleanup: true,
Expand Down
6 changes: 3 additions & 3 deletions cmd/skaffold/app/cmd/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/manifest"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
latest_v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
)

// for tests
Expand Down Expand Up @@ -58,7 +58,7 @@ func NewCmdFilter() *cobra.Command {
// runFilter loads the Kubernetes manifests from stdin and applies the debug transformations.
// Unlike `skaffold debug`, this filtering affects all images and not just the built artifacts.
func runFilter(ctx context.Context, out io.Writer, debuggingFilters bool, buildArtifacts []graph.Artifact) error {
return withRunner(ctx, out, func(r runner.Runner, configs []*latest.SkaffoldConfig) error {
return withRunner(ctx, out, func(r runner.Runner, configs []*latest_v1.SkaffoldConfig) error {
manifestList, err := manifest.Load(os.Stdin)
if err != nil {
return fmt.Errorf("loading manifests: %w", err)
Expand Down Expand Up @@ -87,7 +87,7 @@ func runFilter(ctx context.Context, out io.Writer, debuggingFilters bool, buildA
})
}

func getInsecureRegistries(opts config.SkaffoldOptions, configs []*latest.SkaffoldConfig) (map[string]bool, error) {
func getInsecureRegistries(opts config.SkaffoldOptions, configs []*latest_v1.SkaffoldConfig) (map[string]bool, error) {
cfgRegistries, err := config.GetInsecureRegistries(opts.GlobalConfig)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions cmd/skaffold/app/cmd/find_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
latest_v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/walk"
)

Expand Down Expand Up @@ -66,7 +66,7 @@ func doFindConfigs(_ context.Context, out io.Writer) error {
pathOutLen, versionOutLen := 70, 30
for p, v := range pathToVersion {
c := color.Default
if v != latest.Version {
if v != latest_v1.Version {
c = color.Green
}
c.Fprintf(out, fmt.Sprintf("%%-%ds\t%%-%ds\n", pathOutLen, versionOutLen), p, v)
Expand Down
10 changes: 5 additions & 5 deletions cmd/skaffold/app/cmd/find_configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"testing"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
latest_v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1beta7"
"github.com/GoogleContainerTools/skaffold/testutil"
)
Expand All @@ -32,22 +32,22 @@ func TestFindConfigs(t *testing.T) {
}{
{
files: map[string]string{
"valid.yml": validYaml(latest.Version),
"valid.yml": validYaml(latest_v1.Version),
"upgradeable.yaml": validYaml(v1beta7.Version),
"invalid.yaml": invalidYaml(),
},
expected: map[string]string{
"valid.yml": latest.Version,
"valid.yml": latest_v1.Version,
"upgradeable.yaml": v1beta7.Version,
},
},
{
files: map[string]string{
"valid.yaml": validYaml(latest.Version),
"valid.yaml": validYaml(latest_v1.Version),
"invalid.yaml": invalidYaml(),
},
expected: map[string]string{
"valid.yaml": latest.Version,
"valid.yaml": latest_v1.Version,
},
},
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/skaffold/app/cmd/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
latest_v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/validation"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml"
)
Expand All @@ -41,7 +41,7 @@ func NewCmdFix() *cobra.Command {
WithCommonFlags().
WithFlags([]*Flag{
{Value: &overwrite, Name: "overwrite", DefValue: false, Usage: "Overwrite original config with fixed config"},
{Value: &toVersion, Name: "version", DefValue: latest.Version, Usage: "Target schema version to upgrade to"},
{Value: &toVersion, Name: "version", DefValue: latest_v1.Version, Usage: "Target schema version to upgrade to"},
}).
NoArgs(doFix)
}
Expand Down Expand Up @@ -74,10 +74,10 @@ func fix(out io.Writer, configFile string, toVersion string, overwrite bool) err

// TODO(dgageot): We should be able run validations on any schema version
// but that's not the case. They can only run on the latest version for now.
if toVersion == latest.Version {
var cfgs []*latest.SkaffoldConfig
if toVersion == latest_v1.Version {
var cfgs []*latest_v1.SkaffoldConfig
for _, cfg := range versionedCfgs {
cfgs = append(cfgs, cfg.(*latest.SkaffoldConfig))
cfgs = append(cfgs, cfg.(*latest_v1.SkaffoldConfig))
}
if err := validation.Process(cfgs); err != nil {
return fmt.Errorf("validating upgraded config: %w", err)
Expand Down
Loading

0 comments on commit d38ab4d

Please sign in to comment.