From 6dc89d85f3f270130233c218922ebe987ae0ea7c Mon Sep 17 00:00:00 2001 From: Yuwen Ma Date: Tue, 22 Jun 2021 22:52:41 -0700 Subject: [PATCH] [v2] Decouple the runner creation from v1 schema but using schema interface util.VersionedConfig. --- cmd/skaffold/app/cmd/apply.go | 4 +- cmd/skaffold/app/cmd/build.go | 7 +- cmd/skaffold/app/cmd/build_test.go | 21 ++- cmd/skaffold/app/cmd/debug_test.go | 5 +- cmd/skaffold/app/cmd/delete.go | 4 +- cmd/skaffold/app/cmd/deploy.go | 5 +- cmd/skaffold/app/cmd/dev.go | 7 +- cmd/skaffold/app/cmd/dev_test.go | 9 +- cmd/skaffold/app/cmd/diagnose.go | 8 +- cmd/skaffold/app/cmd/diagnose_test.go | 11 +- cmd/skaffold/app/cmd/filter.go | 7 +- cmd/skaffold/app/cmd/generate_pipeline.go | 4 +- cmd/skaffold/app/cmd/render.go | 4 +- cmd/skaffold/app/cmd/run.go | 4 +- cmd/skaffold/app/cmd/run_test.go | 23 ++- cmd/skaffold/app/cmd/runner.go | 35 ++-- cmd/skaffold/app/cmd/test.go | 5 +- pkg/skaffold/parser/config.go | 6 +- pkg/skaffold/parser/config_test.go | 191 +++++++++++--------- pkg/skaffold/runner/runcontext/context.go | 5 +- pkg/skaffold/runner/runner.go | 3 +- pkg/skaffold/runner/v1/generate_pipeline.go | 5 +- pkg/skaffold/runner/v2/generate_pipeline.go | 4 +- 23 files changed, 214 insertions(+), 163 deletions(-) diff --git a/cmd/skaffold/app/cmd/apply.go b/cmd/skaffold/app/cmd/apply.go index a961ef94b8d..c8111ba516e 100644 --- a/cmd/skaffold/app/cmd/apply.go +++ b/cmd/skaffold/app/cmd/apply.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) // NewCmdApply describes the CLI command to apply manifests to a cluster. @@ -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 []*latestV1.SkaffoldConfig) error { + return withRunner(ctx, out, func(r runner.Runner, configs []util.VersionedConfig) error { return r.Apply(ctx, out) }) } diff --git a/cmd/skaffold/app/cmd/build.go b/cmd/skaffold/app/cmd/build.go index b35f94eea11..435fca9810e 100644 --- a/cmd/skaffold/app/cmd/build.go +++ b/cmd/skaffold/app/cmd/build.go @@ -29,6 +29,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) var ( @@ -67,7 +68,7 @@ func doBuild(ctx context.Context, out io.Writer) error { buildOut = ioutil.Discard } - return withRunner(ctx, out, func(r runner.Runner, configs []*latestV1.SkaffoldConfig) error { + return withRunner(ctx, out, func(r runner.Runner, configs []util.VersionedConfig) error { bRes, err := r.Build(ctx, buildOut, targetArtifacts(opts, configs)) if quietFlag || buildOutputFlag != "" { @@ -94,10 +95,10 @@ func doBuild(ctx context.Context, out io.Writer) error { }) } -func targetArtifacts(opts config.SkaffoldOptions, configs []*latestV1.SkaffoldConfig) []*latestV1.Artifact { +func targetArtifacts(opts config.SkaffoldOptions, configs []util.VersionedConfig) []*latestV1.Artifact { var targetArtifacts []*latestV1.Artifact for _, cfg := range configs { - for _, artifact := range cfg.Build.Artifacts { + for _, artifact := range cfg.(*latestV1.SkaffoldConfig).Build.Artifacts { if opts.IsTargetImage(artifact) { targetArtifacts = append(targetArtifacts, artifact) } diff --git a/cmd/skaffold/app/cmd/build_test.go b/cmd/skaffold/app/cmd/build_test.go index 39e0f46ba65..406b61d46cc 100644 --- a/cmd/skaffold/app/cmd/build_test.go +++ b/cmd/skaffold/app/cmd/build_test.go @@ -30,6 +30,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext" latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -50,8 +51,8 @@ func (r *mockRunner) Stop() error { } func TestTagFlag(t *testing.T) { - mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latestV1.SkaffoldConfig, *runcontext.RunContext, error) { - return &mockRunner{}, []*latestV1.SkaffoldConfig{{}}, nil, nil + mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []util.VersionedConfig, *runcontext.RunContext, error) { + return &mockRunner{}, []util.VersionedConfig{&latestV1.SkaffoldConfig{}}, nil, nil } testutil.Run(t, "override tag with argument", func(t *testutil.T) { @@ -69,8 +70,8 @@ func TestTagFlag(t *testing.T) { } func TestQuietFlag(t *testing.T) { - mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latestV1.SkaffoldConfig, *runcontext.RunContext, error) { - return &mockRunner{}, []*latestV1.SkaffoldConfig{{}}, nil, nil + mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []util.VersionedConfig, *runcontext.RunContext, error) { + return &mockRunner{}, []util.VersionedConfig{&latestV1.SkaffoldConfig{}}, nil, nil } tests := []struct { @@ -115,8 +116,8 @@ func TestQuietFlag(t *testing.T) { } func TestFileOutputFlag(t *testing.T) { - mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latestV1.SkaffoldConfig, *runcontext.RunContext, error) { - return &mockRunner{}, []*latestV1.SkaffoldConfig{{}}, nil, nil + mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []util.VersionedConfig, *runcontext.RunContext, error) { + return &mockRunner{}, []util.VersionedConfig{&latestV1.SkaffoldConfig{}}, nil, nil } tests := []struct { @@ -178,16 +179,16 @@ func TestFileOutputFlag(t *testing.T) { } func TestRunBuild(t *testing.T) { - errRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latestV1.SkaffoldConfig, *runcontext.RunContext, error) { + errRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []util.VersionedConfig, *runcontext.RunContext, error) { return nil, nil, nil, errors.New("some error") } - mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latestV1.SkaffoldConfig, *runcontext.RunContext, error) { - return &mockRunner{}, []*latestV1.SkaffoldConfig{{}}, nil, nil + mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []util.VersionedConfig, *runcontext.RunContext, error) { + return &mockRunner{}, []util.VersionedConfig{&latestV1.SkaffoldConfig{}}, nil, nil } tests := []struct { description string - mock func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latestV1.SkaffoldConfig, *runcontext.RunContext, error) + mock func(io.Writer, config.SkaffoldOptions) (runner.Runner, []util.VersionedConfig, *runcontext.RunContext, error) shouldErr bool }{ { diff --git a/cmd/skaffold/app/cmd/debug_test.go b/cmd/skaffold/app/cmd/debug_test.go index 801eb0e3950..b030714284f 100644 --- a/cmd/skaffold/app/cmd/debug_test.go +++ b/cmd/skaffold/app/cmd/debug_test.go @@ -25,6 +25,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext" latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -49,8 +50,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, []*latestV1.SkaffoldConfig, *runcontext.RunContext, error) { - return mockRunner, []*latestV1.SkaffoldConfig{{}}, nil, nil + t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, []util.VersionedConfig, *runcontext.RunContext, error) { + return mockRunner, []util.VersionedConfig{&latestV1.SkaffoldConfig{}}, nil, nil }) t.Override(&opts, config.SkaffoldOptions{}) t.Override(&doDev, func(context.Context, io.Writer) error { diff --git a/cmd/skaffold/app/cmd/delete.go b/cmd/skaffold/app/cmd/delete.go index ef763af46fc..6c0f5e2f836 100644 --- a/cmd/skaffold/app/cmd/delete.go +++ b/cmd/skaffold/app/cmd/delete.go @@ -23,7 +23,7 @@ import ( "github.com/spf13/cobra" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) // NewCmdDelete describes the CLI command to delete deployed resources. @@ -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, _ []*latestV1.SkaffoldConfig) error { + return withRunner(ctx, out, func(r runner.Runner, _ []util.VersionedConfig) error { return r.Cleanup(ctx, out) }) } diff --git a/cmd/skaffold/app/cmd/deploy.go b/cmd/skaffold/app/cmd/deploy.go index 60375a06002..eb9a34153e3 100644 --- a/cmd/skaffold/app/cmd/deploy.go +++ b/cmd/skaffold/app/cmd/deploy.go @@ -27,6 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) var ( @@ -51,13 +52,13 @@ func NewCmdDeploy() *cobra.Command { } func doDeploy(ctx context.Context, out io.Writer) error { - return withRunner(ctx, out, func(r runner.Runner, configs []*latestV1.SkaffoldConfig) error { + return withRunner(ctx, out, func(r runner.Runner, configs []util.VersionedConfig) error { if opts.SkipRender { return r.DeployAndLog(ctx, out, []graph.Artifact{}) } var artifacts []*latestV1.Artifact for _, cfg := range configs { - artifacts = append(artifacts, cfg.Build.Artifacts...) + artifacts = append(artifacts, cfg.(*latestV1.SkaffoldConfig).Build.Artifacts...) } buildArtifacts, err := getBuildArtifactsAndSetTags(artifacts, r.ApplyDefaultRepo) if err != nil { diff --git a/cmd/skaffold/app/cmd/dev.go b/cmd/skaffold/app/cmd/dev.go index bc6f1e56ad9..34111c3b1ec 100644 --- a/cmd/skaffold/app/cmd/dev.go +++ b/cmd/skaffold/app/cmd/dev.go @@ -26,6 +26,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) // for testing @@ -60,10 +61,12 @@ func runDev(ctx context.Context, out io.Writer) error { case <-ctx.Done(): return nil default: - err := withRunner(ctx, out, func(r runner.Runner, configs []*latestV1.SkaffoldConfig) error { + // Note: The latestV1.SkaffoldConfig is used for both latestV1 schema and latestV2 schema because + // the latestV1 and latestV2 use the same Build struct. Ideally they should be separated. + err := withRunner(ctx, out, func(r runner.Runner, configs []util.VersionedConfig) error { var artifacts []*latestV1.Artifact for _, cfg := range configs { - artifacts = append(artifacts, cfg.Build.Artifacts...) + artifacts = append(artifacts, cfg.(*latestV1.SkaffoldConfig).Build.Artifacts...) } err := r.Dev(ctx, out, artifacts) diff --git a/cmd/skaffold/app/cmd/dev_test.go b/cmd/skaffold/app/cmd/dev_test.go index 6a2e3a50a63..d542ffed01e 100644 --- a/cmd/skaffold/app/cmd/dev_test.go +++ b/cmd/skaffold/app/cmd/dev_test.go @@ -26,6 +26,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext" latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -96,8 +97,8 @@ func TestDoDev(t *testing.T) { hasDeployed: test.hasDeployed, errDev: context.Canceled, } - t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latestV1.SkaffoldConfig, *runcontext.RunContext, error) { - return mockRunner, []*latestV1.SkaffoldConfig{{}}, nil, nil + t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, []util.VersionedConfig, *runcontext.RunContext, error) { + return mockRunner, []util.VersionedConfig{&latestV1.SkaffoldConfig{}}, nil, nil }) t.Override(&opts, config.SkaffoldOptions{ Cleanup: true, @@ -146,8 +147,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, []*latestV1.SkaffoldConfig, *runcontext.RunContext, error) { - return mockRunner, []*latestV1.SkaffoldConfig{{}}, nil, nil + t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, []util.VersionedConfig, *runcontext.RunContext, error) { + return mockRunner, []util.VersionedConfig{&latestV1.SkaffoldConfig{}}, nil, nil }) t.Override(&opts, config.SkaffoldOptions{ Cleanup: true, diff --git a/cmd/skaffold/app/cmd/diagnose.go b/cmd/skaffold/app/cmd/diagnose.go index 10f674dc967..695f30d95bf 100644 --- a/cmd/skaffold/app/cmd/diagnose.go +++ b/cmd/skaffold/app/cmd/diagnose.go @@ -28,6 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext" latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + schemaUtil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/version" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml" @@ -66,7 +67,7 @@ func doDiagnose(ctx context.Context, out io.Writer) error { } // remove the dependency config references since they have already been imported and will be marshalled together. for i := range configs { - configs[i].Dependencies = nil + configs[i].(*latestV1.SkaffoldConfig).Dependencies = nil } buf, err := yaml.MarshalWithSeparator(configs) if err != nil { @@ -77,12 +78,13 @@ func doDiagnose(ctx context.Context, out io.Writer) error { return nil } -func printArtifactDiagnostics(ctx context.Context, out io.Writer, configs []*latestV1.SkaffoldConfig) error { +func printArtifactDiagnostics(ctx context.Context, out io.Writer, configs []schemaUtil.VersionedConfig) error { runCtx, err := getRunContext(opts, configs) if err != nil { return fmt.Errorf("getting run context: %w", err) } - for _, config := range configs { + for _, c := range configs { + config := c.(*latestV1.SkaffoldConfig) fmt.Fprintln(out, "Skaffold version:", version.Get().GitCommit) fmt.Fprintln(out, "Configuration version:", config.APIVersion) fmt.Fprintln(out, "Number of artifacts:", len(config.Build.Artifacts)) diff --git a/cmd/skaffold/app/cmd/diagnose_test.go b/cmd/skaffold/app/cmd/diagnose_test.go index cdb31e651f2..fe07d92d93f 100644 --- a/cmd/skaffold/app/cmd/diagnose_test.go +++ b/cmd/skaffold/app/cmd/diagnose_test.go @@ -25,6 +25,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext" latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -57,20 +58,20 @@ metadata: for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - t.Override(&getRunContext, func(config.SkaffoldOptions, []*latestV1.SkaffoldConfig) (*runcontext.RunContext, error) { + t.Override(&getRunContext, func(config.SkaffoldOptions, []util.VersionedConfig) (*runcontext.RunContext, error) { return nil, fmt.Errorf("cannot get the runtime context") }) t.Override(&yamlOnly, test.yamlOnly) - t.Override(&getCfgs, func(opts config.SkaffoldOptions) ([]*latestV1.SkaffoldConfig, error) { - return []*latestV1.SkaffoldConfig{ - { + t.Override(&getCfgs, func(opts config.SkaffoldOptions) ([]util.VersionedConfig, error) { + return []util.VersionedConfig{ + &latestV1.SkaffoldConfig{ APIVersion: "testVersion", Kind: "Config", Metadata: latestV1.Metadata{ Name: "config1", }, }, - { + &latestV1.SkaffoldConfig{ APIVersion: "testVersion", Kind: "Config", Metadata: latestV1.Metadata{ diff --git a/cmd/skaffold/app/cmd/filter.go b/cmd/skaffold/app/cmd/filter.go index d056de18ea1..b8231e6e14b 100644 --- a/cmd/skaffold/app/cmd/filter.go +++ b/cmd/skaffold/app/cmd/filter.go @@ -31,6 +31,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/manifest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) // for tests @@ -58,7 +59,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 []*latestV1.SkaffoldConfig) error { + return withRunner(ctx, out, func(r runner.Runner, configs []util.VersionedConfig) error { manifestList, err := manifest.Load(os.Stdin) if err != nil { return fmt.Errorf("loading manifests: %w", err) @@ -87,7 +88,7 @@ func runFilter(ctx context.Context, out io.Writer, debuggingFilters bool, buildA }) } -func getInsecureRegistries(opts config.SkaffoldOptions, configs []*latestV1.SkaffoldConfig) (map[string]bool, error) { +func getInsecureRegistries(opts config.SkaffoldOptions, configs []util.VersionedConfig) (map[string]bool, error) { cfgRegistries, err := config.GetInsecureRegistries(opts.GlobalConfig) if err != nil { return nil, err @@ -96,7 +97,7 @@ func getInsecureRegistries(opts config.SkaffoldOptions, configs []*latestV1.Skaf regList = append(regList, opts.InsecureRegistries...) for _, cfg := range configs { - regList = append(regList, cfg.Build.InsecureRegistries...) + regList = append(regList, cfg.(*latestV1.SkaffoldConfig).Build.InsecureRegistries...) } regList = append(regList, cfgRegistries...) insecureRegistries := make(map[string]bool, len(regList)) diff --git a/cmd/skaffold/app/cmd/generate_pipeline.go b/cmd/skaffold/app/cmd/generate_pipeline.go index c6dd86cf24d..369b69093db 100644 --- a/cmd/skaffold/app/cmd/generate_pipeline.go +++ b/cmd/skaffold/app/cmd/generate_pipeline.go @@ -25,7 +25,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) var ( @@ -44,7 +44,7 @@ func NewCmdGeneratePipeline() *cobra.Command { } func doGeneratePipeline(ctx context.Context, out io.Writer) error { - return withRunner(ctx, out, func(r runner.Runner, configs []*latestV1.SkaffoldConfig) error { + return withRunner(ctx, out, func(r runner.Runner, configs []util.VersionedConfig) error { if err := r.GeneratePipeline(ctx, out, configs, configFiles, "pipeline.yaml"); err != nil { return fmt.Errorf("generating : %w", err) } diff --git a/cmd/skaffold/app/cmd/render.go b/cmd/skaffold/app/cmd/render.go index 66e12a92ffd..633cda6bec6 100644 --- a/cmd/skaffold/app/cmd/render.go +++ b/cmd/skaffold/app/cmd/render.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/flags" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) var ( @@ -60,7 +60,7 @@ func doRender(ctx context.Context, out io.Writer) error { buildOut = out } - return withRunner(ctx, out, func(r runner.Runner, configs []*latestV1.SkaffoldConfig) error { + return withRunner(ctx, out, func(r runner.Runner, configs []util.VersionedConfig) error { var bRes []graph.Artifact if renderFromBuildOutputFile.String() != "" { diff --git a/cmd/skaffold/app/cmd/run.go b/cmd/skaffold/app/cmd/run.go index d62e2c2d241..ea228b50fc4 100644 --- a/cmd/skaffold/app/cmd/run.go +++ b/cmd/skaffold/app/cmd/run.go @@ -25,7 +25,7 @@ import ( "github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/tips" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) // NewCmdRun describes the CLI command to run a pipeline. @@ -41,7 +41,7 @@ func NewCmdRun() *cobra.Command { } func doRun(ctx context.Context, out io.Writer) error { - return withRunner(ctx, out, func(r runner.Runner, configs []*latestV1.SkaffoldConfig) error { + return withRunner(ctx, out, func(r runner.Runner, configs []util.VersionedConfig) error { bRes, err := r.Build(ctx, out, targetArtifacts(opts, configs)) if err != nil { return fmt.Errorf("failed to build: %w", err) diff --git a/cmd/skaffold/app/cmd/run_test.go b/cmd/skaffold/app/cmd/run_test.go index f0606604bd2..9bd4a5bc117 100644 --- a/cmd/skaffold/app/cmd/run_test.go +++ b/cmd/skaffold/app/cmd/run_test.go @@ -27,6 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext" latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -92,19 +93,21 @@ func TestDoRun(t *testing.T) { for _, test := range tests { testutil.Run(t, "", func(t *testutil.T) { mockRunner := &mockRunRunner{} - t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latestV1.SkaffoldConfig, *runcontext.RunContext, error) { - return mockRunner, []*latestV1.SkaffoldConfig{{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ - {ImageName: "first"}, - {ImageName: "second-test"}, - {ImageName: "test"}, - {ImageName: "aaabbbccc"}, + t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, []util.VersionedConfig, *runcontext.RunContext, error) { + return mockRunner, []util.VersionedConfig{ + &latestV1.SkaffoldConfig{ + Pipeline: latestV1.Pipeline{ + Build: latestV1.BuildConfig{ + Artifacts: []*latestV1.Artifact{ + {ImageName: "first"}, + {ImageName: "second-test"}, + {ImageName: "test"}, + {ImageName: "aaabbbccc"}, + }, }, }, }, - }}, nil, nil + }, nil, nil }) t.Override(&opts, config.SkaffoldOptions{ TargetImages: []string{"test"}, diff --git a/cmd/skaffold/app/cmd/runner.go b/cmd/skaffold/app/cmd/runner.go index f442d16e829..fe984dc2973 100644 --- a/cmd/skaffold/app/cmd/runner.go +++ b/cmd/skaffold/app/cmd/runner.go @@ -38,6 +38,7 @@ import ( v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/v1" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/defaults" latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/validation" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/update" "github.com/GoogleContainerTools/skaffold/proto/v1" @@ -46,7 +47,7 @@ import ( // For tests var createRunner = createNewRunner -func withRunner(ctx context.Context, out io.Writer, action func(runner.Runner, []*latestV1.SkaffoldConfig) error) error { +func withRunner(ctx context.Context, out io.Writer, action func(runner.Runner, []util.VersionedConfig) error) error { runner, config, runCtx, err := createRunner(out, opts) if err != nil { return err @@ -58,13 +59,18 @@ func withRunner(ctx context.Context, out io.Writer, action func(runner.Runner, [ } // createNewRunner creates a Runner and returns the SkaffoldConfig associated with it. -func createNewRunner(out io.Writer, opts config.SkaffoldOptions) (runner.Runner, []*latestV1.SkaffoldConfig, *runcontext.RunContext, error) { +func createNewRunner(out io.Writer, opts config.SkaffoldOptions) (runner.Runner, []util.VersionedConfig, *runcontext.RunContext, error) { runCtx, configs, err := runContext(out, opts) if err != nil { return nil, nil, nil, err } - instrumentation.Init(configs, opts.User) + // TODO yuwen Check v1 or v2. + var v1Configs []*latestV1.SkaffoldConfig + for _, c := range configs { + v1Configs = append(v1Configs, c.(*latestV1.SkaffoldConfig)) + } + instrumentation.Init(v1Configs, opts.User) runner, err := v1.NewForConfig(runCtx) if err != nil { event.InititializationFailed(err) @@ -73,20 +79,24 @@ func createNewRunner(out io.Writer, opts config.SkaffoldOptions) (runner.Runner, return runner, configs, runCtx, nil } -func runContext(out io.Writer, opts config.SkaffoldOptions) (*runcontext.RunContext, []*latestV1.SkaffoldConfig, error) { +func runContext(out io.Writer, opts config.SkaffoldOptions) (*runcontext.RunContext, []util.VersionedConfig, error) { configs, err := withFallbackConfig(out, opts, parser.GetAllConfigs) if err != nil { return nil, nil, err } - setDefaultDeployer(configs) + // TODO: yuwen Check v1 or v2. + var v1Configs []*latestV1.SkaffoldConfig + for _, c := range configs { + v1Configs = append(v1Configs, c.(*latestV1.SkaffoldConfig)) + } + setDefaultDeployer(configs) // TODO: Should support per-config kubecontext. Right now we constrain all configs to define the same kubecontext. - kubectx.ConfigureKubeConfig(opts.KubeConfig, opts.KubeContext, configs[0].Deploy.KubeContext) + kubectx.ConfigureKubeConfig(opts.KubeConfig, opts.KubeContext, v1Configs[0].Deploy.KubeContext) - if err := validation.Process(configs); err != nil { + if err := validation.Process(v1Configs); err != nil { return nil, nil, fmt.Errorf("invalid skaffold config: %w", err) } - runCtx, err := runcontext.GetRunContext(opts, configs) if err != nil { return nil, nil, fmt.Errorf("getting run context: %w", err) @@ -100,7 +110,7 @@ func runContext(out io.Writer, opts config.SkaffoldOptions) (*runcontext.RunCont } // withFallbackConfig will try to automatically generate a config if root `skaffold.yaml` file does not exist. -func withFallbackConfig(out io.Writer, opts config.SkaffoldOptions, getCfgs func(opts config.SkaffoldOptions) ([]*latestV1.SkaffoldConfig, error)) ([]*latestV1.SkaffoldConfig, error) { +func withFallbackConfig(out io.Writer, opts config.SkaffoldOptions, getCfgs func(opts config.SkaffoldOptions) ([]util.VersionedConfig, error)) ([]util.VersionedConfig, error) { configs, err := getCfgs(opts) if err == nil { return configs, nil @@ -119,7 +129,7 @@ func withFallbackConfig(out io.Writer, opts config.SkaffoldOptions, getCfgs func defaults.Set(config) - return []*latestV1.SkaffoldConfig{config}, nil + return []util.VersionedConfig{config}, nil } return nil, fmt.Errorf("skaffold config file %s not found - check your current working directory, or try running `skaffold init`", opts.ConfigurationFile) @@ -132,13 +142,14 @@ func withFallbackConfig(out io.Writer, opts config.SkaffoldOptions, getCfgs func return nil, fmt.Errorf("parsing skaffold config: %w", err) } -func setDefaultDeployer(configs []*latestV1.SkaffoldConfig) { +func setDefaultDeployer(configs []util.VersionedConfig) { // do not set a default deployer in a multi-config application. if len(configs) > 1 { return } // there always exists at least one config - defaults.SetDefaultDeployer(configs[0]) + // TODO: yuwen determine defualt deploeyr for v2 + defaults.SetDefaultDeployer(configs[0].(*latestV1.SkaffoldConfig)) } func warnIfUpdateIsAvailable() { diff --git a/cmd/skaffold/app/cmd/test.go b/cmd/skaffold/app/cmd/test.go index 002ea10f3f0..b4735d2b75a 100644 --- a/cmd/skaffold/app/cmd/test.go +++ b/cmd/skaffold/app/cmd/test.go @@ -25,6 +25,7 @@ import ( "github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/tips" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) // NewCmdTest describes the CLI command to test artifacts. @@ -39,10 +40,10 @@ func NewCmdTest() *cobra.Command { } func doTest(ctx context.Context, out io.Writer) error { - return withRunner(ctx, out, func(r runner.Runner, configs []*latestV1.SkaffoldConfig) error { + return withRunner(ctx, out, func(r runner.Runner, configs []util.VersionedConfig) error { var artifacts []*latestV1.Artifact for _, c := range configs { - artifacts = append(artifacts, c.Build.Artifacts...) + artifacts = append(artifacts, c.(*latestV1.SkaffoldConfig).Build.Artifacts...) } buildArtifacts, err := getBuildArtifactsAndSetTags(artifacts, r.ApplyDefaultRepo) if err != nil { diff --git a/pkg/skaffold/parser/config.go b/pkg/skaffold/parser/config.go index 6b1a71433b7..2faccf6654a 100644 --- a/pkg/skaffold/parser/config.go +++ b/pkg/skaffold/parser/config.go @@ -32,6 +32,8 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/defaults" sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/errors" latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + schemaUtil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/tags" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -61,12 +63,12 @@ func newRecord() *record { } // GetAllConfigs returns the list of all skaffold configurations parsed from the target config file in addition to all resolved dependency configs. -func GetAllConfigs(opts config.SkaffoldOptions) ([]*latestV1.SkaffoldConfig, error) { +func GetAllConfigs(opts config.SkaffoldOptions) ([]schemaUtil.VersionedConfig, error) { set, err := GetConfigSet(opts) if err != nil { return nil, err } - var cfgs []*latestV1.SkaffoldConfig + var cfgs []schemaUtil.VersionedConfig for _, cfg := range set { cfgs = append(cfgs, cfg.SkaffoldConfig) } diff --git a/pkg/skaffold/parser/config_test.go b/pkg/skaffold/parser/config_test.go index 62e4d76942e..790a02a9b8c 100644 --- a/pkg/skaffold/parser/config_test.go +++ b/pkg/skaffold/parser/config_test.go @@ -27,6 +27,7 @@ import ( sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/git" latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + schemaUtil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/proto/v1" "github.com/GoogleContainerTools/skaffold/testutil" @@ -93,28 +94,34 @@ func TestGetAllConfigs(t *testing.T) { makePathsAbsolute *bool errCode proto.StatusCode applyProfilesRecursively bool - expected func(base string) []*latestV1.SkaffoldConfig + expected func(base string) []schemaUtil.VersionedConfig }{ { description: "makePathsAbsolute unspecified; no dependencies", documents: []document{{path: "skaffold.yaml", configs: []mockCfg{{name: "cfg00", requiresStanza: ""}}}}, - expected: func(string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{createCfg("cfg00", "image00", ".", nil)} + expected: func(string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ + createCfg("cfg00", "image00", ".", nil), + } }, }, { description: "makePathsAbsolute unspecified; no dependencies, config flag", documents: []document{{path: "skaffold.yaml", configs: []mockCfg{{name: "cfg00", requiresStanza: ""}, {name: "cfg01", requiresStanza: ""}}}}, - expected: func(string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{createCfg("cfg01", "image01", ".", nil)} + expected: func(string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ + createCfg("cfg01", "image01", ".", nil), + } }, configFilter: []string{"cfg01"}, }, { description: "makePathsAbsolute unspecified; no dependencies, config flag, profiles flag", documents: []document{{path: "skaffold.yaml", configs: []mockCfg{{name: "cfg00", requiresStanza: ""}, {name: "cfg01", requiresStanza: ""}}}}, - expected: func(string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{createCfg("cfg01", "pf0image01", ".", nil)} + expected: func(string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ + createCfg("cfg01", "pf0image01", ".", nil), + } }, configFilter: []string{"cfg01"}, profiles: []string{"pf0"}, @@ -132,8 +139,8 @@ requires: {path: "doc1/skaffold.yaml", configs: []mockCfg{{name: "cfg10", requiresStanza: ""}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg10", "image10", filepath.Join(base, "doc1"), nil), createCfg("cfg21", "image21", filepath.Join(base, "doc2"), nil), createCfg("cfg00", "image00", ".", []latestV1.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}, {Path: "doc2", Names: []string{"cfg21"}}}), @@ -156,8 +163,8 @@ requires: `}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "image21", filepath.Join(base, "doc2"), nil), createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), createCfg("cfg00", "image00", ".", []latestV1.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}}), @@ -177,8 +184,8 @@ requires: {path: "doc1/skaffold.yaml", configs: []mockCfg{{name: "cfg10", requiresStanza: ""}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg01", "image01", ".", nil), createCfg("cfg21", "image21", filepath.Join(base, "doc2"), nil), createCfg("cfg00", "image00", ".", []latestV1.ConfigDependency{{Names: []string{"cfg01"}}, {Path: "doc2", Names: []string{"cfg21"}}}), @@ -197,8 +204,8 @@ requires: - configs: [cfg11] `}, {name: "cfg11", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg11", "image11", filepath.Join(base, "doc1"), nil), createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{Names: []string{"cfg11"}}}), createCfg("cfg00", "image00", ".", []latestV1.ConfigDependency{{Path: "doc1"}}), @@ -224,8 +231,8 @@ requires: configs: [cfg00] `}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "image21", filepath.Join(base, "doc2"), []latestV1.ConfigDependency{{Path: base, Names: []string{"cfg00"}}}), createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), createCfg("cfg00", "image00", ".", []latestV1.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}}), @@ -249,8 +256,8 @@ requires: `}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "image21", filepath.Join(base, "doc2"), nil), createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), createCfg("cfg00", "pf0image00", ".", []latestV1.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}}), @@ -280,8 +287,8 @@ requires: `}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "pf0image21", filepath.Join(base, "doc2"), nil), createCfg("cfg10", "pf0image10", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}, ActiveProfiles: []latestV1.ProfileDependency{{Name: "pf0", ActivatedBy: []string{"pf0"}}}}}), createCfg("cfg00", "pf0image00", ".", []latestV1.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}, ActiveProfiles: []latestV1.ProfileDependency{{Name: "pf0", ActivatedBy: []string{"pf0"}}}}}), @@ -308,8 +315,8 @@ requires: `}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "pf1image21", filepath.Join(base, "doc2"), nil), createCfg("cfg10", "pf0image10", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}, ActiveProfiles: []latestV1.ProfileDependency{{Name: "pf1"}}}}), createCfg("cfg00", "image00", ".", []latestV1.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}, ActiveProfiles: []latestV1.ProfileDependency{{Name: "pf0"}}}}), @@ -365,8 +372,8 @@ requires: `}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "image21", filepath.Join(base, "doc2"), nil), createCfg("cfg11", "image11", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), } @@ -444,8 +451,8 @@ requires: `}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "image21", filepath.Join(base, "doc2"), nil), createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{GitRepo: &latestV1.GitInfo{Repo: "doc2", Path: "skaffold.yaml", Ref: "main"}, Names: []string{"cfg21"}}}), createCfg("cfg11", "image11", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{GitRepo: &latestV1.GitInfo{Repo: "doc2", Ref: "main"}, Names: []string{"cfg21"}}}), @@ -458,16 +465,20 @@ requires: description: "makePathsAbsolute false; no dependencies", makePathsAbsolute: util.BoolPtr(false), documents: []document{{path: "skaffold.yaml", configs: []mockCfg{{name: "cfg00", requiresStanza: ""}}}}, - expected: func(string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{createCfg("cfg00", "image00", ".", nil)} + expected: func(string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ + createCfg("cfg00", "image00", ".", nil), + } }, }, { description: "makePathsAbsolute false; no dependencies, config flag", makePathsAbsolute: util.BoolPtr(false), documents: []document{{path: "skaffold.yaml", configs: []mockCfg{{name: "cfg00", requiresStanza: ""}, {name: "cfg01", requiresStanza: ""}}}}, - expected: func(string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{createCfg("cfg01", "image01", ".", nil)} + expected: func(string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ + createCfg("cfg01", "image01", ".", nil), + } }, configFilter: []string{"cfg01"}, }, @@ -475,8 +486,10 @@ requires: description: "makePathsAbsolute false; no dependencies, config flag, profiles flag", makePathsAbsolute: util.BoolPtr(false), documents: []document{{path: "skaffold.yaml", configs: []mockCfg{{name: "cfg00", requiresStanza: ""}, {name: "cfg01", requiresStanza: ""}}}}, - expected: func(string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{createCfg("cfg01", "pf0image01", ".", nil)} + expected: func(string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ + createCfg("cfg01", "pf0image01", ".", nil), + } }, configFilter: []string{"cfg01"}, profiles: []string{"pf0"}, @@ -495,8 +508,8 @@ requires: {path: "doc1/skaffold.yaml", configs: []mockCfg{{name: "cfg10", requiresStanza: ""}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg10", "image10", ".", nil), createCfg("cfg21", "image21", ".", nil), createCfg("cfg00", "image00", ".", []latestV1.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}, {Path: "doc2", Names: []string{"cfg21"}}}), @@ -520,8 +533,8 @@ requires: `}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "image21", ".", nil), createCfg("cfg10", "image10", ".", []latestV1.ConfigDependency{{Path: "../doc2", Names: []string{"cfg21"}}}), createCfg("cfg00", "image00", ".", []latestV1.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}}), @@ -542,8 +555,8 @@ requires: {path: "doc1/skaffold.yaml", configs: []mockCfg{{name: "cfg10", requiresStanza: ""}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg01", "image01", ".", nil), createCfg("cfg21", "image21", ".", nil), createCfg("cfg00", "image00", ".", []latestV1.ConfigDependency{{Names: []string{"cfg01"}}, {Path: "doc2", Names: []string{"cfg21"}}}), @@ -563,8 +576,8 @@ requires: - configs: [cfg11] `}, {name: "cfg11", requiresStanza: ""}}}, }, - expected: func(string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg11", "image11", ".", nil), createCfg("cfg10", "image10", ".", []latestV1.ConfigDependency{{Names: []string{"cfg11"}}}), createCfg("cfg00", "image00", ".", []latestV1.ConfigDependency{{Path: "doc1"}}), @@ -591,8 +604,8 @@ requires: configs: [cfg00] `}}}, }, - expected: func(string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "image21", ".", []latestV1.ConfigDependency{{Path: "../", Names: []string{"cfg00"}}}), createCfg("cfg10", "image10", ".", []latestV1.ConfigDependency{{Path: "../doc2", Names: []string{"cfg21"}}}), createCfg("cfg00", "image00", ".", []latestV1.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}}), @@ -617,8 +630,8 @@ requires: `}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "image21", ".", nil), createCfg("cfg10", "image10", ".", []latestV1.ConfigDependency{{Path: "../doc2", Names: []string{"cfg21"}}}), createCfg("cfg00", "pf0image00", ".", []latestV1.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}}), @@ -649,8 +662,8 @@ requires: `}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "pf0image21", ".", nil), createCfg("cfg10", "pf0image10", ".", []latestV1.ConfigDependency{{Path: "../doc2", Names: []string{"cfg21"}, ActiveProfiles: []latestV1.ProfileDependency{{Name: "pf0", ActivatedBy: []string{"pf0"}}}}}), createCfg("cfg00", "pf0image00", ".", []latestV1.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}, ActiveProfiles: []latestV1.ProfileDependency{{Name: "pf0", ActivatedBy: []string{"pf0"}}}}}), @@ -678,8 +691,8 @@ requires: `}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "pf1image21", ".", nil), createCfg("cfg10", "pf0image10", ".", []latestV1.ConfigDependency{{Path: "../doc2", Names: []string{"cfg21"}, ActiveProfiles: []latestV1.ProfileDependency{{Name: "pf1"}}}}), createCfg("cfg00", "image00", ".", []latestV1.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}, ActiveProfiles: []latestV1.ProfileDependency{{Name: "pf0"}}}}), @@ -737,8 +750,8 @@ requires: `}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "image21", ".", nil), createCfg("cfg11", "image11", ".", []latestV1.ConfigDependency{{Path: "../doc2", Names: []string{"cfg21"}}}), } @@ -820,8 +833,8 @@ requires: `}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "image21", ".", nil), createCfg("cfg10", "image10", ".", []latestV1.ConfigDependency{{GitRepo: &latestV1.GitInfo{Repo: "doc2", Path: "skaffold.yaml", Ref: "main"}, Names: []string{"cfg21"}}}), createCfg("cfg11", "image11", ".", []latestV1.ConfigDependency{{GitRepo: &latestV1.GitInfo{Repo: "doc2", Ref: "main"}, Names: []string{"cfg21"}}}), @@ -834,16 +847,20 @@ requires: description: "makePathsAbsolute true; no dependencies", makePathsAbsolute: util.BoolPtr(true), documents: []document{{path: "skaffold.yaml", configs: []mockCfg{{name: "cfg00", requiresStanza: ""}}}}, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{createCfg("cfg00", "image00", base, nil)} + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ + createCfg("cfg00", "image00", base, nil), + } }, }, { description: "makePathsAbsolute true; no dependencies, config flag", makePathsAbsolute: util.BoolPtr(true), documents: []document{{path: "skaffold.yaml", configs: []mockCfg{{name: "cfg00", requiresStanza: ""}, {name: "cfg01", requiresStanza: ""}}}}, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{createCfg("cfg01", "image01", base, nil)} + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ + createCfg("cfg01", "image01", base, nil), + } }, configFilter: []string{"cfg01"}, }, @@ -851,8 +868,10 @@ requires: description: "makePathsAbsolute true; no dependencies, config flag, profiles flag", makePathsAbsolute: util.BoolPtr(true), documents: []document{{path: "skaffold.yaml", configs: []mockCfg{{name: "cfg00", requiresStanza: ""}, {name: "cfg01", requiresStanza: ""}}}}, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{createCfg("cfg01", "pf0image01", base, nil)} + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ + createCfg("cfg01", "pf0image01", base, nil), + } }, configFilter: []string{"cfg01"}, profiles: []string{"pf0"}, @@ -871,8 +890,8 @@ requires: {path: "doc1/skaffold.yaml", configs: []mockCfg{{name: "cfg10", requiresStanza: ""}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg10", "image10", filepath.Join(base, "doc1"), nil), createCfg("cfg21", "image21", filepath.Join(base, "doc2"), nil), createCfg("cfg00", "image00", base, []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc1"), Names: []string{"cfg10"}}, {Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), @@ -896,8 +915,8 @@ requires: `}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "image21", filepath.Join(base, "doc2"), nil), createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), createCfg("cfg00", "image00", base, []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc1"), Names: []string{"cfg10"}}}), @@ -918,8 +937,8 @@ requires: {path: "doc1/skaffold.yaml", configs: []mockCfg{{name: "cfg10", requiresStanza: ""}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg01", "image01", base, nil), createCfg("cfg21", "image21", filepath.Join(base, "doc2"), nil), createCfg("cfg00", "image00", base, []latestV1.ConfigDependency{{Names: []string{"cfg01"}}, {Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), @@ -939,8 +958,8 @@ requires: - configs: [cfg11] `}, {name: "cfg11", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg11", "image11", filepath.Join(base, "doc1"), nil), createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{Names: []string{"cfg11"}}}), createCfg("cfg00", "image00", base, []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc1")}}), @@ -967,8 +986,8 @@ requires: configs: [cfg00] `}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "image21", filepath.Join(base, "doc2"), []latestV1.ConfigDependency{{Path: base, Names: []string{"cfg00"}}}), createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), createCfg("cfg00", "image00", base, []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc1"), Names: []string{"cfg10"}}}), @@ -993,8 +1012,8 @@ requires: `}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "image21", filepath.Join(base, "doc2"), nil), createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), createCfg("cfg00", "pf0image00", base, []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc1"), Names: []string{"cfg10"}}}), @@ -1025,8 +1044,8 @@ requires: `}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "pf0image21", filepath.Join(base, "doc2"), nil), createCfg("cfg10", "pf0image10", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}, ActiveProfiles: []latestV1.ProfileDependency{{Name: "pf0", ActivatedBy: []string{"pf0"}}}}}), createCfg("cfg00", "pf0image00", base, []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc1"), Names: []string{"cfg10"}, ActiveProfiles: []latestV1.ProfileDependency{{Name: "pf0", ActivatedBy: []string{"pf0"}}}}}), @@ -1054,8 +1073,8 @@ requires: `}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "pf1image21", filepath.Join(base, "doc2"), nil), createCfg("cfg10", "pf0image10", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}, ActiveProfiles: []latestV1.ProfileDependency{{Name: "pf1"}}}}), createCfg("cfg00", "image00", base, []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc1"), Names: []string{"cfg10"}, ActiveProfiles: []latestV1.ProfileDependency{{Name: "pf0"}}}}), @@ -1113,8 +1132,8 @@ requires: `}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "image21", filepath.Join(base, "doc2"), nil), createCfg("cfg11", "image11", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), } @@ -1196,8 +1215,8 @@ requires: `}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "image21", filepath.Join(base, "doc2"), nil), createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{GitRepo: &latestV1.GitInfo{Repo: "doc2", Path: "skaffold.yaml", Ref: "main"}, Names: []string{"cfg21"}}}), createCfg("cfg11", "image11", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{GitRepo: &latestV1.GitInfo{Repo: "doc2", Ref: "main"}, Names: []string{"cfg21"}}}), @@ -1223,8 +1242,8 @@ requires: `}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "pf0image21", filepath.Join(base, "doc2"), nil), createCfg("cfg10", "pf0image10", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), createCfg("cfg00", "pf0image00", ".", []latestV1.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}}), @@ -1250,8 +1269,8 @@ requires: `}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "pf0image21", ".", nil), createCfg("cfg10", "pf0image10", ".", []latestV1.ConfigDependency{{Path: "../doc2", Names: []string{"cfg21"}}}), createCfg("cfg00", "pf0image00", ".", []latestV1.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}}), @@ -1277,8 +1296,8 @@ requires: `}, {name: "cfg11", requiresStanza: ""}}}, {path: "doc2/skaffold.yaml", configs: []mockCfg{{name: "cfg20", requiresStanza: ""}, {name: "cfg21", requiresStanza: ""}}}, }, - expected: func(base string) []*latestV1.SkaffoldConfig { - return []*latestV1.SkaffoldConfig{ + expected: func(base string) []schemaUtil.VersionedConfig { + return []schemaUtil.VersionedConfig{ createCfg("cfg21", "pf0image21", filepath.Join(base, "doc2"), nil), createCfg("cfg10", "pf0image10", filepath.Join(base, "doc1"), []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), createCfg("cfg00", "pf0image00", base, []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc1"), Names: []string{"cfg10"}}}), @@ -1300,7 +1319,7 @@ requires: tmpDir.Write(d.path, strings.Join(cfgs, "\n---\n")) } tmpDir.Chdir() - var expected []*latestV1.SkaffoldConfig + var expected []schemaUtil.VersionedConfig if test.expected != nil { wd, _ := util.RealWorkDir() expected = test.expected(wd) diff --git a/pkg/skaffold/runner/runcontext/context.go b/pkg/skaffold/runner/runcontext/context.go index 7dd827e7787..219cfe315af 100644 --- a/pkg/skaffold/runner/runcontext/context.go +++ b/pkg/skaffold/runner/runcontext/context.go @@ -27,6 +27,7 @@ import ( kubectx "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context" runnerutil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/util" latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + schemaUtil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -234,11 +235,11 @@ func (rc *RunContext) BuildConcurrency() int { return rc func (rc *RunContext) IsMultiConfig() bool { return rc.Pipelines.IsMultiPipeline() } func (rc *RunContext) GetRunID() string { return rc.RunID } -func GetRunContext(opts config.SkaffoldOptions, configs []*latestV1.SkaffoldConfig) (*RunContext, error) { +func GetRunContext(opts config.SkaffoldOptions, configs []schemaUtil.VersionedConfig) (*RunContext, error) { var pipelines []latestV1.Pipeline for _, cfg := range configs { if cfg != nil { - pipelines = append(pipelines, cfg.Pipeline) + pipelines = append(pipelines, cfg.(*latestV1.SkaffoldConfig).Pipeline) } } kubeConfig, err := kubectx.CurrentConfig() diff --git a/pkg/skaffold/runner/runner.go b/pkg/skaffold/runner/runner.go index 7a17b6f7771..551a817d34e 100644 --- a/pkg/skaffold/runner/runner.go +++ b/pkg/skaffold/runner/runner.go @@ -23,6 +23,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) const ( @@ -43,7 +44,7 @@ type Runner interface { Dev(context.Context, io.Writer, []*latestV1.Artifact) error Deploy(context.Context, io.Writer, []graph.Artifact) error DeployAndLog(context.Context, io.Writer, []graph.Artifact) error - GeneratePipeline(context.Context, io.Writer, []*latestV1.SkaffoldConfig, []string, string) error + GeneratePipeline(context.Context, io.Writer, []util.VersionedConfig, []string, string) error HasBuilt() bool HasDeployed() bool Prune(context.Context, io.Writer) error diff --git a/pkg/skaffold/runner/v1/generate_pipeline.go b/pkg/skaffold/runner/v1/generate_pipeline.go index 9137ac0a116..767063536f1 100644 --- a/pkg/skaffold/runner/v1/generate_pipeline.go +++ b/pkg/skaffold/runner/v1/generate_pipeline.go @@ -27,16 +27,17 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/defaults" latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) -func (r *SkaffoldRunner) GeneratePipeline(ctx context.Context, out io.Writer, configs []*latestV1.SkaffoldConfig, configPaths []string, fileOut string) error { +func (r *SkaffoldRunner) GeneratePipeline(ctx context.Context, out io.Writer, configs []util.VersionedConfig, configPaths []string, fileOut string) error { // Keep track of files, configs, and profiles. This will be used to know which files to write // profiles to and what flags to add to task commands var baseConfig []*pipeline.ConfigFile for _, config := range configs { cfgFile := &pipeline.ConfigFile{ Path: r.runCtx.ConfigurationFile(), - Config: config, + Config: config.(*latestV1.SkaffoldConfig), Profile: nil, } baseConfig = append(baseConfig, cfgFile) diff --git a/pkg/skaffold/runner/v2/generate_pipeline.go b/pkg/skaffold/runner/v2/generate_pipeline.go index decb9c2ce2a..c512d45ed09 100644 --- a/pkg/skaffold/runner/v2/generate_pipeline.go +++ b/pkg/skaffold/runner/v2/generate_pipeline.go @@ -20,9 +20,9 @@ import ( "fmt" "io" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) -func (r *SkaffoldRunner) GeneratePipeline(ctx context.Context, out io.Writer, configs []*latestV1.SkaffoldConfig, configPaths []string, fileOut string) error { +func (r *SkaffoldRunner) GeneratePipeline(ctx context.Context, out io.Writer, configs []util.VersionedConfig, configPaths []string, fileOut string) error { return fmt.Errorf("not implemented error: SkaffoldRunner(v2).GeneratePipeline") }