From 81611087df42b37234d91ae3d121d9fa92293bee Mon Sep 17 00:00:00 2001 From: Gaurav Date: Tue, 12 Apr 2022 11:26:42 +0000 Subject: [PATCH] chore: remove `v1` config package and move it to `latest` package. --- DEVELOPMENT.md | 2 +- cmd/skaffold/app/cmd/build.go | 8 +- cmd/skaffold/app/cmd/build_test.go | 12 +- cmd/skaffold/app/cmd/debug_test.go | 4 +- cmd/skaffold/app/cmd/deploy.go | 6 +- cmd/skaffold/app/cmd/dev.go | 10 +- cmd/skaffold/app/cmd/dev_test.go | 10 +- cmd/skaffold/app/cmd/diagnose.go | 6 +- cmd/skaffold/app/cmd/diagnose_test.go | 10 +- cmd/skaffold/app/cmd/filter.go | 4 +- cmd/skaffold/app/cmd/find_configs.go | 4 +- cmd/skaffold/app/cmd/find_configs_test.go | 10 +- cmd/skaffold/app/cmd/fix.go | 8 +- cmd/skaffold/app/cmd/fix_test.go | 22 +- cmd/skaffold/app/cmd/run_test.go | 12 +- cmd/skaffold/app/cmd/runner.go | 6 +- cmd/skaffold/app/cmd/runner_test.go | 4 +- cmd/skaffold/app/cmd/schema/list_test.go | 6 +- cmd/skaffold/app/cmd/test.go | 6 +- cmd/skaffold/app/cmd/util.go | 6 +- cmd/skaffold/app/cmd/util_test.go | 22 +- .../tutorials/skaffold-resource-selector.md | 2 +- .../configurable-transformable-allowlist.md | 2 +- docs/design_proposals/ko-builder.md | 2 +- hack/release/changelog/main.go | 8 +- hack/schemas/main.go | 2 +- .../cmd/new/templates/upgrade.template | 2 +- .../cmd/new/templates/upgrade_test.template | 2 +- hack/versions/cmd/new/version.go | 4 +- hack/versions/pkg/schema/version.go | 8 +- integration/ko_test.go | 8 +- integration/render_test.go | 38 +- pkg/skaffold/build/bazel/build.go | 10 +- pkg/skaffold/build/bazel/build_test.go | 16 +- pkg/skaffold/build/bazel/dependencies.go | 4 +- pkg/skaffold/build/bazel/dependencies_test.go | 4 +- pkg/skaffold/build/build.go | 6 +- pkg/skaffold/build/builder_mux.go | 10 +- pkg/skaffold/build/builder_mux_test.go | 36 +- pkg/skaffold/build/buildpacks/build.go | 4 +- pkg/skaffold/build/buildpacks/build_test.go | 40 +- pkg/skaffold/build/buildpacks/dependencies.go | 4 +- .../build/buildpacks/dependencies_test.go | 6 +- pkg/skaffold/build/buildpacks/env.go | 6 +- pkg/skaffold/build/buildpacks/init.go | 8 +- pkg/skaffold/build/buildpacks/init_test.go | 8 +- pkg/skaffold/build/buildpacks/lifecycle.go | 14 +- .../build/buildpacks/lifecycle_test.go | 16 +- pkg/skaffold/build/buildpacks/metadata.go | 8 +- .../build/buildpacks/metadata_test.go | 6 +- pkg/skaffold/build/cache/cache.go | 10 +- pkg/skaffold/build/cache/hash.go | 16 +- pkg/skaffold/build/cache/hash_test.go | 176 +++---- pkg/skaffold/build/cache/lookup.go | 8 +- pkg/skaffold/build/cache/lookup_test.go | 10 +- pkg/skaffold/build/cache/retrieve.go | 8 +- pkg/skaffold/build/cache/retrieve_test.go | 46 +- pkg/skaffold/build/cache/types.go | 8 +- pkg/skaffold/build/cluster/cluster.go | 8 +- pkg/skaffold/build/cluster/cluster_test.go | 8 +- pkg/skaffold/build/cluster/kaniko.go | 6 +- pkg/skaffold/build/cluster/kaniko_test.go | 8 +- pkg/skaffold/build/cluster/pod.go | 10 +- pkg/skaffold/build/cluster/pod_test.go | 52 +- pkg/skaffold/build/cluster/secret_test.go | 10 +- pkg/skaffold/build/cluster/types.go | 6 +- pkg/skaffold/build/cluster/types_test.go | 10 +- pkg/skaffold/build/custom/build.go | 4 +- pkg/skaffold/build/custom/dependencies.go | 6 +- .../build/custom/dependencies_test.go | 16 +- pkg/skaffold/build/custom/script.go | 8 +- pkg/skaffold/build/custom/script_test.go | 24 +- pkg/skaffold/build/docker/docker.go | 10 +- pkg/skaffold/build/docker/docker_test.go | 46 +- pkg/skaffold/build/docker/errors_test.go | 8 +- pkg/skaffold/build/docker/types.go | 4 +- pkg/skaffold/build/gcb/buildpacks.go | 6 +- pkg/skaffold/build/gcb/buildpacks_test.go | 32 +- pkg/skaffold/build/gcb/cloud_build.go | 6 +- pkg/skaffold/build/gcb/docker.go | 10 +- pkg/skaffold/build/gcb/docker_test.go | 62 +-- pkg/skaffold/build/gcb/jib.go | 4 +- pkg/skaffold/build/gcb/jib_test.go | 20 +- pkg/skaffold/build/gcb/kaniko.go | 4 +- pkg/skaffold/build/gcb/kaniko_test.go | 88 ++-- pkg/skaffold/build/gcb/spec.go | 6 +- pkg/skaffold/build/gcb/spec_test.go | 14 +- pkg/skaffold/build/gcb/types.go | 6 +- pkg/skaffold/build/jib/build.go | 4 +- pkg/skaffold/build/jib/gradle.go | 18 +- pkg/skaffold/build/jib/gradle_test.go | 110 ++--- pkg/skaffold/build/jib/init.go | 8 +- pkg/skaffold/build/jib/init_test.go | 12 +- pkg/skaffold/build/jib/jib.go | 14 +- pkg/skaffold/build/jib/jib_test.go | 18 +- pkg/skaffold/build/jib/maven.go | 18 +- pkg/skaffold/build/jib/maven_test.go | 108 ++--- pkg/skaffold/build/jib/sync.go | 10 +- pkg/skaffold/build/jib/sync_test.go | 22 +- pkg/skaffold/build/kaniko/args.go | 4 +- pkg/skaffold/build/kaniko/args_test.go | 70 +-- pkg/skaffold/build/ko/build.go | 8 +- pkg/skaffold/build/ko/build_test.go | 40 +- pkg/skaffold/build/ko/builder.go | 12 +- pkg/skaffold/build/ko/builder_test.go | 22 +- pkg/skaffold/build/ko/dependencies.go | 8 +- pkg/skaffold/build/ko/dependencies_test.go | 6 +- pkg/skaffold/build/local/local.go | 8 +- pkg/skaffold/build/local/local_test.go | 120 ++--- pkg/skaffold/build/local/types.go | 10 +- pkg/skaffold/build/local/types_test.go | 10 +- pkg/skaffold/build/logfile.go | 4 +- pkg/skaffold/build/logfile_test.go | 8 +- pkg/skaffold/build/misc/artifact_type.go | 6 +- pkg/skaffold/build/misc/artifact_type_test.go | 38 +- pkg/skaffold/build/model.go | 4 +- pkg/skaffold/build/result.go | 10 +- pkg/skaffold/build/scheduler.go | 12 +- pkg/skaffold/build/scheduler_test.go | 58 +-- pkg/skaffold/config/options.go | 4 +- pkg/skaffold/config/options_test.go | 4 +- pkg/skaffold/constants/constants.go | 6 +- .../component/kubernetes/accessor_test.go | 4 +- pkg/skaffold/deploy/deploy_mux_test.go | 12 +- pkg/skaffold/deploy/deploy_problems_test.go | 36 +- pkg/skaffold/deploy/docker/deploy.go | 8 +- pkg/skaffold/deploy/docker/port.go | 4 +- pkg/skaffold/deploy/docker/port_test.go | 14 +- pkg/skaffold/deploy/helm/args.go | 6 +- pkg/skaffold/deploy/helm/deploy.go | 14 +- pkg/skaffold/deploy/helm/helm_test.go | 152 +++--- pkg/skaffold/deploy/helm/util.go | 6 +- pkg/skaffold/deploy/kpt/kpt.go | 10 +- pkg/skaffold/deploy/kpt/kpt_test.go | 168 +++---- pkg/skaffold/deploy/kubectl/cli.go | 12 +- pkg/skaffold/deploy/kubectl/kubectl.go | 10 +- pkg/skaffold/deploy/kubectl/kubectl_test.go | 92 ++-- pkg/skaffold/deploy/kustomize/kustomize.go | 10 +- .../deploy/kustomize/kustomize_test.go | 62 +-- pkg/skaffold/deploy/types/types.go | 8 +- pkg/skaffold/deploy/util/namespaces.go | 6 +- pkg/skaffold/deploy/util/namespaces_test.go | 18 +- pkg/skaffold/deploy/util/util.go | 14 +- pkg/skaffold/deploy/util/util_test.go | 60 +-- pkg/skaffold/diagnose/diagnose.go | 14 +- pkg/skaffold/diagnose/diagnose_test.go | 26 +- pkg/skaffold/docker/build_args.go | 4 +- pkg/skaffold/docker/build_args_test.go | 12 +- pkg/skaffold/docker/context_test.go | 4 +- pkg/skaffold/docker/docker_init.go | 8 +- pkg/skaffold/docker/docker_init_test.go | 16 +- pkg/skaffold/docker/image.go | 10 +- pkg/skaffold/docker/image_test.go | 56 +-- pkg/skaffold/event/config.go | 6 +- pkg/skaffold/event/event_test.go | 68 +-- pkg/skaffold/event/util.go | 8 +- pkg/skaffold/event/util_test.go | 60 +-- .../event/v2/application_logs_test.go | 4 +- pkg/skaffold/event/v2/config.go | 6 +- pkg/skaffold/event/v2/debugging_test.go | 4 +- pkg/skaffold/event/v2/deploy_test.go | 4 +- pkg/skaffold/event/v2/event_test.go | 18 +- pkg/skaffold/event/v2/logger_test.go | 4 +- pkg/skaffold/event/v2/metadata.go | 8 +- pkg/skaffold/event/v2/metadata_test.go | 60 +-- pkg/skaffold/event/v2/render_test.go | 4 +- pkg/skaffold/event/v2/state_test.go | 4 +- pkg/skaffold/event/v2/status_check_test.go | 8 +- pkg/skaffold/event/v2/tester_test.go | 4 +- .../generate_pipeline/generate_pipeline.go | 6 +- pkg/skaffold/generate_pipeline/profile.go | 18 +- .../generate_pipeline/profile_test.go | 94 ++-- pkg/skaffold/generate_pipeline/tasks_test.go | 86 ++-- pkg/skaffold/git/errors.go | 4 +- pkg/skaffold/git/gitutil.go | 6 +- pkg/skaffold/git/gitutil_test.go | 28 +- pkg/skaffold/graph/artifact_graph.go | 14 +- pkg/skaffold/graph/artifact_graph_test.go | 8 +- pkg/skaffold/graph/dependencies.go | 12 +- pkg/skaffold/graph/dependencies_test.go | 20 +- pkg/skaffold/hooks/build.go | 10 +- pkg/skaffold/hooks/build_test.go | 36 +- pkg/skaffold/hooks/container.go | 4 +- pkg/skaffold/hooks/container_test.go | 12 +- pkg/skaffold/hooks/deploy.go | 10 +- pkg/skaffold/hooks/deploy_test.go | 26 +- pkg/skaffold/hooks/host.go | 4 +- pkg/skaffold/hooks/host_test.go | 10 +- pkg/skaffold/hooks/sync.go | 10 +- pkg/skaffold/hooks/sync_test.go | 24 +- pkg/skaffold/initializer/build/builders.go | 14 +- pkg/skaffold/initializer/build/cli.go | 10 +- pkg/skaffold/initializer/build/init.go | 10 +- pkg/skaffold/initializer/build/util.go | 10 +- pkg/skaffold/initializer/config.go | 12 +- pkg/skaffold/initializer/config_test.go | 58 +-- pkg/skaffold/initializer/deploy/init.go | 16 +- pkg/skaffold/initializer/deploy/kubectl.go | 10 +- .../initializer/deploy/kubectl_test.go | 8 +- pkg/skaffold/initializer/deploy/kustomize.go | 32 +- .../initializer/deploy/kustomize_test.go | 42 +- pkg/skaffold/initializer/init.go | 6 +- pkg/skaffold/initializer/prompt/prompt.go | 4 +- .../initializer/prompt/prompt_test.go | 26 +- pkg/skaffold/initializer/transparent.go | 4 +- pkg/skaffold/initializer/transparent_test.go | 6 +- pkg/skaffold/initializer/util/util.go | 6 +- pkg/skaffold/initializer/util/util_test.go | 36 +- pkg/skaffold/inspect/buildEnv/add_cluster.go | 16 +- .../inspect/buildEnv/add_cluster_test.go | 38 +- pkg/skaffold/inspect/buildEnv/add_gcb.go | 14 +- pkg/skaffold/inspect/buildEnv/add_gcb_test.go | 38 +- pkg/skaffold/inspect/buildEnv/add_local.go | 12 +- .../inspect/buildEnv/add_local_test.go | 38 +- pkg/skaffold/inspect/buildEnv/list_test.go | 22 +- .../inspect/buildEnv/modify_gcb_test.go | 30 +- pkg/skaffold/inspect/modules/list_test.go | 18 +- pkg/skaffold/inspect/profiles/list_test.go | 42 +- pkg/skaffold/inspect/tests/list.go | 4 +- pkg/skaffold/inspect/tests/list_test.go | 22 +- pkg/skaffold/inspect/types.go | 4 +- pkg/skaffold/instrumentation/meter.go | 4 +- pkg/skaffold/instrumentation/new.go | 4 +- pkg/skaffold/kubernetes/logger/formatter.go | 6 +- .../kubernetes/logger/formatter_test.go | 22 +- pkg/skaffold/kubernetes/logger/log.go | 8 +- pkg/skaffold/kubernetes/manifest/images.go | 8 +- pkg/skaffold/kubernetes/manifest/labels.go | 8 +- .../kubernetes/manifest/labels_test.go | 4 +- .../kubernetes/manifest/namespaces.go | 2 +- pkg/skaffold/kubernetes/manifest/visitor.go | 6 +- .../portforward/entry_manager_test.go | 8 +- .../portforward/forwarder_manager.go | 6 +- .../portforward/kubectl_forwarder_test.go | 18 +- .../kubernetes/portforward/pod_forwarder.go | 6 +- .../portforward/pod_forwarder_test.go | 20 +- .../portforward/port_forward_entry.go | 6 +- .../portforward/port_forward_entry_test.go | 10 +- .../portforward/port_forward_integration.go | 4 +- .../portforward/resource_forwarder.go | 28 +- .../portforward/resource_forwarder_test.go | 58 +-- .../status/resource/deployment_test.go | 4 +- .../kubernetes/status/status_check_test.go | 8 +- pkg/skaffold/lint/dockerfiles_test.go | 10 +- pkg/skaffold/lint/k8smanifests_test.go | 14 +- pkg/skaffold/lint/skaffoldyamls_test.go | 8 +- pkg/skaffold/log/formatter.go | 4 +- pkg/skaffold/log/formatter_test.go | 14 +- pkg/skaffold/parser/config.go | 16 +- pkg/skaffold/parser/config_test.go | 152 +++--- .../parser/configlocations/configlocations.go | 6 +- pkg/skaffold/parser/types.go | 4 +- pkg/skaffold/platform/resolver.go | 4 +- pkg/skaffold/platform/resolver_test.go | 28 +- pkg/skaffold/runner/build.go | 12 +- pkg/skaffold/runner/builder.go | 4 +- pkg/skaffold/runner/changeset.go | 16 +- pkg/skaffold/runner/deployer.go | 16 +- pkg/skaffold/runner/deployer_test.go | 138 +++--- pkg/skaffold/runner/listen_test.go | 6 +- pkg/skaffold/runner/runcontext/context.go | 74 +-- pkg/skaffold/runner/runner.go | 6 +- pkg/skaffold/runner/timings.go | 4 +- pkg/skaffold/runner/timings_test.go | 4 +- pkg/skaffold/runner/v1/build_test.go | 26 +- pkg/skaffold/runner/v1/deploy_test.go | 4 +- pkg/skaffold/runner/v1/dev.go | 10 +- pkg/skaffold/runner/v1/dev_test.go | 18 +- pkg/skaffold/runner/v1/generate_pipeline.go | 6 +- pkg/skaffold/runner/v1/new.go | 6 +- pkg/skaffold/runner/v1/new_test.go | 12 +- pkg/skaffold/runner/v1/runner_test.go | 170 +++---- pkg/skaffold/runner/v2/dev.go | 4 +- pkg/skaffold/schema/defaults/defaults.go | 90 ++-- pkg/skaffold/schema/defaults/defaults_test.go | 228 ++++----- pkg/skaffold/schema/latest/{v1 => }/config.go | 2 +- .../schema/latest/{v1 => }/upgrade.go | 2 +- pkg/skaffold/schema/profiles.go | 14 +- pkg/skaffold/schema/profiles_test.go | 250 +++++----- pkg/skaffold/schema/v2beta27/upgrade.go | 2 +- pkg/skaffold/schema/v2beta27/upgrade_test.go | 2 +- .../schema/validation/samples_test.go | 6 +- pkg/skaffold/schema/validation/validation.go | 36 +- .../schema/validation/validation_test.go | 454 +++++++++--------- pkg/skaffold/schema/versions.go | 6 +- pkg/skaffold/schema/versions_test.go | 162 +++---- pkg/skaffold/sources/upload.go | 4 +- pkg/skaffold/survey/config.go | 4 +- pkg/skaffold/sync/docker_test.go | 8 +- pkg/skaffold/sync/sync.go | 18 +- pkg/skaffold/sync/sync_test.go | 206 ++++---- pkg/skaffold/sync/types.go | 4 +- pkg/skaffold/tag/custom.go | 4 +- pkg/skaffold/tag/custom_template.go | 6 +- pkg/skaffold/tag/custom_template_test.go | 4 +- pkg/skaffold/tag/custom_test.go | 4 +- pkg/skaffold/tag/date_time.go | 4 +- pkg/skaffold/tag/date_time_test.go | 4 +- pkg/skaffold/tag/env_template.go | 4 +- pkg/skaffold/tag/env_template_test.go | 4 +- pkg/skaffold/tag/git_commit.go | 4 +- pkg/skaffold/tag/git_commit_test.go | 12 +- pkg/skaffold/tag/input_digest.go | 4 +- pkg/skaffold/tag/sha256.go | 4 +- pkg/skaffold/tag/sha256_test.go | 4 +- pkg/skaffold/tag/tag.go | 6 +- pkg/skaffold/tag/tag_test.go | 4 +- pkg/skaffold/tag/tagger_mux.go | 8 +- pkg/skaffold/tag/tagger_mux_test.go | 38 +- pkg/skaffold/tags/paths_test.go | 42 +- pkg/skaffold/tags/paths_windows_test.go | 42 +- pkg/skaffold/test/custom/custom.go | 6 +- pkg/skaffold/test/custom/custom_test.go | 64 +-- pkg/skaffold/test/structure/structure.go | 4 +- pkg/skaffold/test/structure/structure_test.go | 22 +- pkg/skaffold/test/test_factory.go | 8 +- pkg/skaffold/test/test_factory_test.go | 28 +- pkg/skaffold/test/types.go | 4 +- pkg/skaffold/trigger/triggers.go | 4 +- pkg/skaffold/trigger/triggers_test.go | 12 +- pkg/skaffold/util/util_test.go | 10 +- pkg/skaffold/version/version.go | 4 +- pkg/skaffold/yamltags/tags.go | 2 +- testutil/event/config.go | 18 +- 324 files changed, 3591 insertions(+), 3595 deletions(-) rename pkg/skaffold/schema/latest/{v1 => }/config.go (99%) rename pkg/skaffold/schema/latest/{v1 => }/upgrade.go (98%) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 140cbd517ba..581685d2ebb 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -70,7 +70,7 @@ to be submitted. Some changes to the skaffold code require a change to the skaffold config. These changes require a few extra steps: -* Open the latest Config at [pkg/skaffold/schema/latest/v1/config.go](https://github.com/GoogleContainerTools/skaffold/blob/main/pkg/skaffold/schema/latest/v1/config.go) and inspect the comment at [L28](https://github.com/GoogleContainerTools/skaffold/blob/main/pkg/skaffold/schema/latest/v1/config.go#L28) +* Open the latest Config at [pkg/skaffold/schema/latest/config.go](https://github.com/GoogleContainerTools/skaffold/blob/main/pkg/skaffold/schema/latest/config.go) and inspect the comment at [L28](https://github.com/GoogleContainerTools/skaffold/blob/main/pkg/skaffold/schema/latest/config.go#L28) * If the line mentions the config version is not released, proceed making your changes. ``` // This config version is not yet released, it is SAFE TO MODIFY the structs in this file. diff --git a/cmd/skaffold/app/cmd/build.go b/cmd/skaffold/app/cmd/build.go index 435fca9810e..3253632d7a4 100644 --- a/cmd/skaffold/app/cmd/build.go +++ b/cmd/skaffold/app/cmd/build.go @@ -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" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) @@ -95,10 +95,10 @@ func doBuild(ctx context.Context, out io.Writer) error { }) } -func targetArtifacts(opts config.SkaffoldOptions, configs []util.VersionedConfig) []*latestV1.Artifact { - var targetArtifacts []*latestV1.Artifact +func targetArtifacts(opts config.SkaffoldOptions, configs []util.VersionedConfig) []*latest.Artifact { + var targetArtifacts []*latest.Artifact for _, cfg := range configs { - for _, artifact := range cfg.(*latestV1.SkaffoldConfig).Build.Artifacts { + for _, artifact := range cfg.(*latest.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 5b88ef7e4a9..7ad2289f4a7 100644 --- a/cmd/skaffold/app/cmd/build_test.go +++ b/cmd/skaffold/app/cmd/build_test.go @@ -29,7 +29,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -38,7 +38,7 @@ type mockRunner struct { runner.Runner } -func (r *mockRunner) Build(ctx context.Context, out io.Writer, artifacts []*latestV1.Artifact) ([]graph.Artifact, error) { +func (r *mockRunner) Build(ctx context.Context, out io.Writer, artifacts []*latest.Artifact) ([]graph.Artifact, error) { out.Write([]byte("Build Completed")) return []graph.Artifact{{ ImageName: "gcr.io/skaffold/example", @@ -52,7 +52,7 @@ func (r *mockRunner) Stop() error { func TestTagFlag(t *testing.T) { mockCreateRunner := func(context.Context, io.Writer, config.SkaffoldOptions) (runner.Runner, []util.VersionedConfig, *runcontext.RunContext, error) { - return &mockRunner{}, []util.VersionedConfig{&latestV1.SkaffoldConfig{}}, nil, nil + return &mockRunner{}, []util.VersionedConfig{&latest.SkaffoldConfig{}}, nil, nil } testutil.Run(t, "override tag with argument", func(t *testutil.T) { @@ -71,7 +71,7 @@ func TestTagFlag(t *testing.T) { func TestQuietFlag(t *testing.T) { mockCreateRunner := func(context.Context, io.Writer, config.SkaffoldOptions) (runner.Runner, []util.VersionedConfig, *runcontext.RunContext, error) { - return &mockRunner{}, []util.VersionedConfig{&latestV1.SkaffoldConfig{}}, nil, nil + return &mockRunner{}, []util.VersionedConfig{&latest.SkaffoldConfig{}}, nil, nil } tests := []struct { @@ -117,7 +117,7 @@ func TestQuietFlag(t *testing.T) { func TestFileOutputFlag(t *testing.T) { mockCreateRunner := func(context.Context, io.Writer, config.SkaffoldOptions) (runner.Runner, []util.VersionedConfig, *runcontext.RunContext, error) { - return &mockRunner{}, []util.VersionedConfig{&latestV1.SkaffoldConfig{}}, nil, nil + return &mockRunner{}, []util.VersionedConfig{&latest.SkaffoldConfig{}}, nil, nil } tests := []struct { @@ -183,7 +183,7 @@ func TestRunBuild(t *testing.T) { return nil, nil, nil, errors.New("some error") } mockCreateRunner := func(context.Context, io.Writer, config.SkaffoldOptions) (runner.Runner, []util.VersionedConfig, *runcontext.RunContext, error) { - return &mockRunner{}, []util.VersionedConfig{&latestV1.SkaffoldConfig{}}, nil, nil + return &mockRunner{}, []util.VersionedConfig{&latest.SkaffoldConfig{}}, nil, nil } tests := []struct { diff --git a/cmd/skaffold/app/cmd/debug_test.go b/cmd/skaffold/app/cmd/debug_test.go index 246973be15a..9fd4bdb6e0e 100644 --- a/cmd/skaffold/app/cmd/debug_test.go +++ b/cmd/skaffold/app/cmd/debug_test.go @@ -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" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -50,7 +50,7 @@ func TestDebugIndependentFromDev(t *testing.T) { mockRunner := &mockDevRunner{} testutil.Run(t, "DevDebug", func(t *testutil.T) { t.Override(&createRunner, func(context.Context, io.Writer, config.SkaffoldOptions) (runner.Runner, []util.VersionedConfig, *runcontext.RunContext, error) { - return mockRunner, []util.VersionedConfig{&latestV1.SkaffoldConfig{}}, nil, nil + return mockRunner, []util.VersionedConfig{&latest.SkaffoldConfig{}}, nil, nil }) t.Override(&opts, config.SkaffoldOptions{}) t.Override(&doDev, func(context.Context, io.Writer) error { diff --git a/cmd/skaffold/app/cmd/deploy.go b/cmd/skaffold/app/cmd/deploy.go index c20326cecb3..441929249d4 100644 --- a/cmd/skaffold/app/cmd/deploy.go +++ b/cmd/skaffold/app/cmd/deploy.go @@ -25,7 +25,7 @@ import ( "github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/tips" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) @@ -50,9 +50,9 @@ func doDeploy(ctx context.Context, out io.Writer) error { if opts.SkipRender { return r.DeployAndLog(ctx, out, []graph.Artifact{}) } - var artifacts []*latestV1.Artifact + var artifacts []*latest.Artifact for _, cfg := range configs { - artifacts = append(artifacts, cfg.(*latestV1.SkaffoldConfig).Build.Artifacts...) + artifacts = append(artifacts, cfg.(*latest.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 967eff46aa5..e036318e577 100644 --- a/cmd/skaffold/app/cmd/dev.go +++ b/cmd/skaffold/app/cmd/dev.go @@ -25,7 +25,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) @@ -61,12 +61,12 @@ func runDev(ctx context.Context, out io.Writer) error { case <-ctx.Done(): return nil default: - // 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. + // Note: The latest.SkaffoldConfig is used for both latest schema and latestV2 schema because + // the latest 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 + var artifacts []*latest.Artifact for _, cfg := range configs { - artifacts = append(artifacts, cfg.(*latestV1.SkaffoldConfig).Build.Artifacts...) + artifacts = append(artifacts, cfg.(*latest.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 21ebcd2ffbd..e0347ad5fea 100644 --- a/cmd/skaffold/app/cmd/dev_test.go +++ b/cmd/skaffold/app/cmd/dev_test.go @@ -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" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -38,7 +38,7 @@ type mockDevRunner struct { calls []string } -func (r *mockDevRunner) Dev(context.Context, io.Writer, []*latestV1.Artifact) error { +func (r *mockDevRunner) Dev(context.Context, io.Writer, []*latest.Artifact) error { r.calls = append(r.calls, "Dev") return r.errDev } @@ -98,7 +98,7 @@ func TestDoDev(t *testing.T) { errDev: context.Canceled, } t.Override(&createRunner, func(context.Context, io.Writer, config.SkaffoldOptions) (runner.Runner, []util.VersionedConfig, *runcontext.RunContext, error) { - return mockRunner, []util.VersionedConfig{&latestV1.SkaffoldConfig{}}, nil, nil + return mockRunner, []util.VersionedConfig{&latest.SkaffoldConfig{}}, nil, nil }) t.Override(&opts, config.SkaffoldOptions{ Cleanup: true, @@ -118,7 +118,7 @@ type mockConfigChangeRunner struct { cycles int } -func (m *mockConfigChangeRunner) Dev(context.Context, io.Writer, []*latestV1.Artifact) error { +func (m *mockConfigChangeRunner) Dev(context.Context, io.Writer, []*latest.Artifact) error { m.cycles++ if m.cycles == 1 { // pass through the first cycle with a config reload @@ -148,7 +148,7 @@ func TestDevConfigChange(t *testing.T) { mockRunner := &mockConfigChangeRunner{} t.Override(&createRunner, func(context.Context, io.Writer, config.SkaffoldOptions) (runner.Runner, []util.VersionedConfig, *runcontext.RunContext, error) { - return mockRunner, []util.VersionedConfig{&latestV1.SkaffoldConfig{}}, nil, nil + return mockRunner, []util.VersionedConfig{&latest.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 0650b9196b9..aa846ab42aa 100644 --- a/cmd/skaffold/app/cmd/diagnose.go +++ b/cmd/skaffold/app/cmd/diagnose.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "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" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" schemaUtil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/version" @@ -67,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].(*latestV1.SkaffoldConfig).Dependencies = nil + configs[i].(*latest.SkaffoldConfig).Dependencies = nil } buf, err := yaml.MarshalWithSeparator(configs) if err != nil { @@ -84,7 +84,7 @@ func printArtifactDiagnostics(ctx context.Context, out io.Writer, configs []sche return fmt.Errorf("getting run context: %w", err) } for _, c := range configs { - config := c.(*latestV1.SkaffoldConfig) + config := c.(*latest.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 e658e9836b9..5c709ec7e9f 100644 --- a/cmd/skaffold/app/cmd/diagnose_test.go +++ b/cmd/skaffold/app/cmd/diagnose_test.go @@ -24,7 +24,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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -64,17 +64,17 @@ metadata: t.Override(&yamlOnly, test.yamlOnly) t.Override(&getCfgs, func(context.Context, config.SkaffoldOptions) ([]util.VersionedConfig, error) { return []util.VersionedConfig{ - &latestV1.SkaffoldConfig{ + &latest.SkaffoldConfig{ APIVersion: "testVersion", Kind: "Config", - Metadata: latestV1.Metadata{ + Metadata: latest.Metadata{ Name: "config1", }, }, - &latestV1.SkaffoldConfig{ + &latest.SkaffoldConfig{ APIVersion: "testVersion", Kind: "Config", - Metadata: latestV1.Metadata{ + Metadata: latest.Metadata{ Name: "config2", }, }, diff --git a/cmd/skaffold/app/cmd/filter.go b/cmd/skaffold/app/cmd/filter.go index 87a71e59183..c8ae6509057 100644 --- a/cmd/skaffold/app/cmd/filter.go +++ b/cmd/skaffold/app/cmd/filter.go @@ -30,7 +30,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/debugging" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) @@ -97,7 +97,7 @@ func getInsecureRegistries(opts config.SkaffoldOptions, configs []util.Versioned regList = append(regList, opts.InsecureRegistries...) for _, cfg := range configs { - regList = append(regList, cfg.(*latestV1.SkaffoldConfig).Build.InsecureRegistries...) + regList = append(regList, cfg.(*latest.SkaffoldConfig).Build.InsecureRegistries...) } regList = append(regList, cfgRegistries...) insecureRegistries := make(map[string]bool, len(regList)) diff --git a/cmd/skaffold/app/cmd/find_configs.go b/cmd/skaffold/app/cmd/find_configs.go index b05b75111bb..e1129c1eec4 100644 --- a/cmd/skaffold/app/cmd/find_configs.go +++ b/cmd/skaffold/app/cmd/find_configs.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/walk" ) @@ -67,7 +67,7 @@ func doFindConfigs(ctx context.Context, out io.Writer) error { pathOutLen, versionOutLen := 70, 30 for p, v := range pathToVersion { c := output.Default - if v != latestV1.Version { + if v != latest.Version { c = output.Green } c.Fprintf(out, fmt.Sprintf("%%-%ds\t%%-%ds\n", pathOutLen, versionOutLen), p, v) diff --git a/cmd/skaffold/app/cmd/find_configs_test.go b/cmd/skaffold/app/cmd/find_configs_test.go index 4f57973e22e..174008d3dc4 100644 --- a/cmd/skaffold/app/cmd/find_configs_test.go +++ b/cmd/skaffold/app/cmd/find_configs_test.go @@ -21,7 +21,7 @@ import ( "fmt" "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1beta7" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -33,22 +33,22 @@ func TestFindConfigs(t *testing.T) { }{ { files: map[string]string{ - "valid.yml": validYaml(latestV1.Version), + "valid.yml": validYaml(latest.Version), "upgradeable.yaml": validYaml(v1beta7.Version), "invalid.yaml": invalidYaml(), }, expected: map[string]string{ - "valid.yml": latestV1.Version, + "valid.yml": latest.Version, "upgradeable.yaml": v1beta7.Version, }, }, { files: map[string]string{ - "valid.yaml": validYaml(latestV1.Version), + "valid.yaml": validYaml(latest.Version), "invalid.yaml": invalidYaml(), }, expected: map[string]string{ - "valid.yaml": latestV1.Version, + "valid.yaml": latest.Version, }, }, } diff --git a/cmd/skaffold/app/cmd/fix.go b/cmd/skaffold/app/cmd/fix.go index ecbd445e0e0..196f5b80ce5 100644 --- a/cmd/skaffold/app/cmd/fix.go +++ b/cmd/skaffold/app/cmd/fix.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/validation" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml" ) @@ -47,7 +47,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: latestV1.Version, Usage: "Target schema version to upgrade to"}, + {Value: &toVersion, Name: "version", DefValue: latest.Version, Usage: "Target schema version to upgrade to"}, {Value: &fixOutputPath, Name: "output", Shorthand: "o", DefValue: "", Usage: "File to write the changed config (instead of standard output)"}, }). NoArgs(doFix) @@ -96,11 +96,11 @@ func fix(out io.Writer, configFile, outFile string, toVersion string) error { // 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 == latestV1.Version { + if toVersion == latest.Version { var cfgs parser.SkaffoldConfigSet for _, cfg := range versionedCfgs { cfgs = append(cfgs, &parser.SkaffoldConfigEntry{ - SkaffoldConfig: cfg.(*latestV1.SkaffoldConfig), + SkaffoldConfig: cfg.(*latest.SkaffoldConfig), SourceFile: configFile, IsRootConfig: true}) } diff --git a/cmd/skaffold/app/cmd/fix_test.go b/cmd/skaffold/app/cmd/fix_test.go index dc9e1937185..a5ca666db27 100644 --- a/cmd/skaffold/app/cmd/fix_test.go +++ b/cmd/skaffold/app/cmd/fix_test.go @@ -22,7 +22,7 @@ import ( "io/ioutil" "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -37,7 +37,7 @@ func TestFix(t *testing.T) { }{ { description: "v1alpha4 to latest", - targetVersion: latestV1.Version, + targetVersion: latest.Version, inputYaml: `apiVersion: skaffold/v1alpha4 kind: Config build: @@ -69,11 +69,11 @@ deploy: kubectl: manifests: - k8s/deployment.yaml -`, latestV1.Version), +`, latest.Version), }, { description: "v1alpha1 to latest", - targetVersion: latestV1.Version, + targetVersion: latest.Version, inputYaml: `apiVersion: skaffold/v1alpha1 kind: Config build: @@ -97,7 +97,7 @@ deploy: kubectl: manifests: - k8s/deployment.yaml -`, latestV1.Version), +`, latest.Version), }, { description: "v1alpha1 to v1", @@ -129,11 +129,11 @@ deploy: }, { description: "already target version", - targetVersion: latestV1.Version, + targetVersion: latest.Version, inputYaml: fmt.Sprintf(`apiVersion: %s kind: Config -`, latestV1.Version), - output: "config is already version " + latestV1.Version + "\n", +`, latest.Version), + output: "config is already version " + latest.Version + "\n", }, { description: "invalid input", @@ -142,7 +142,7 @@ kind: Config }, { description: "validation fails", - targetVersion: latestV1.Version, + targetVersion: latest.Version, inputYaml: `apiVersion: skaffold/v1alpha1 kind: Config build: @@ -197,13 +197,13 @@ deploy: kubectl: manifests: - k8s/deployment.yaml -`, latestV1.Version) +`, latest.Version) testutil.Run(t, "", func(t *testutil.T) { cfgFile := t.TempFile("config", []byte(inputYaml)) var b bytes.Buffer - err := fix(&b, cfgFile, cfgFile, latestV1.Version) + err := fix(&b, cfgFile, cfgFile, latest.Version) output, _ := ioutil.ReadFile(cfgFile) diff --git a/cmd/skaffold/app/cmd/run_test.go b/cmd/skaffold/app/cmd/run_test.go index f846970e921..12831297bc8 100644 --- a/cmd/skaffold/app/cmd/run_test.go +++ b/cmd/skaffold/app/cmd/run_test.go @@ -26,7 +26,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -53,7 +53,7 @@ type mockRunRunner struct { artifactImageNames []string } -func (r *mockRunRunner) Build(_ context.Context, _ io.Writer, artifacts []*latestV1.Artifact) ([]graph.Artifact, error) { +func (r *mockRunRunner) Build(_ context.Context, _ io.Writer, artifacts []*latest.Artifact) ([]graph.Artifact, error) { var result []graph.Artifact for _, artifact := range artifacts { imageName := artifact.ImageName @@ -95,10 +95,10 @@ func TestDoRun(t *testing.T) { mockRunner := &mockRunRunner{} t.Override(&createRunner, func(context.Context, 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{ + &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ {ImageName: "first"}, {ImageName: "second-test"}, {ImageName: "test"}, diff --git a/cmd/skaffold/app/cmd/runner.go b/cmd/skaffold/app/cmd/runner.go index 0b39fcd54b5..70430518ef7 100644 --- a/cmd/skaffold/app/cmd/runner.go +++ b/cmd/skaffold/app/cmd/runner.go @@ -36,7 +36,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext" 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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/validation" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/update" @@ -64,9 +64,9 @@ func createNewRunner(ctx context.Context, out io.Writer, opts config.SkaffoldOpt return nil, nil, nil, err } - var v1Configs []*latestV1.SkaffoldConfig + var v1Configs []*latest.SkaffoldConfig for _, c := range configs { - v1Configs = append(v1Configs, c.(*latestV1.SkaffoldConfig)) + v1Configs = append(v1Configs, c.(*latest.SkaffoldConfig)) } instrumentation.Init(v1Configs, opts.User, runCtx.GetKubeContext()) hooks.SetupStaticEnvOptions(runCtx) diff --git a/cmd/skaffold/app/cmd/runner_test.go b/cmd/skaffold/app/cmd/runner_test.go index 718ce213fdd..3dc8b6894d6 100644 --- a/cmd/skaffold/app/cmd/runner_test.go +++ b/cmd/skaffold/app/cmd/runner_test.go @@ -26,7 +26,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/validation" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/update" "github.com/GoogleContainerTools/skaffold/testutil" @@ -99,7 +99,7 @@ func TestCreateNewRunner(t *testing.T) { return semver.Version{}, semver.Version{}, nil }) t.NewTempDir(). - Write("skaffold.yaml", fmt.Sprintf("apiVersion: %s\nkind: Config\n%s", latestV1.Version, test.config)). + Write("skaffold.yaml", fmt.Sprintf("apiVersion: %s\nkind: Config\n%s", latest.Version, test.config)). Chdir() _, _, _, err := createNewRunner(context.Background(), ioutil.Discard, test.options) diff --git a/cmd/skaffold/app/cmd/schema/list_test.go b/cmd/skaffold/app/cmd/schema/list_test.go index 8194f35934e..007ff25952f 100644 --- a/cmd/skaffold/app/cmd/schema/list_test.go +++ b/cmd/skaffold/app/cmd/schema/list_test.go @@ -22,7 +22,7 @@ import ( "strings" "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -34,7 +34,7 @@ func TestListPlain(t *testing.T) { t.CheckNoError(err) versions := out.String() - t.CheckTrue(strings.HasSuffix(versions, latestV1.Version+"\n")) + t.CheckTrue(strings.HasSuffix(versions, latest.Version+"\n")) t.CheckTrue(strings.HasPrefix(versions, `skaffold/v1alpha1 skaffold/v1alpha2 skaffold/v1alpha3 @@ -71,7 +71,7 @@ func TestListJson(t *testing.T) { versions := out.String() t.CheckTrue(strings.HasPrefix(versions, `{"versions":["skaffold/v1alpha1","skaffold/v1alpha2",`)) - t.CheckTrue(strings.HasSuffix(versions, fmt.Sprintf(",\"%s\"]}\n", latestV1.Version))) + t.CheckTrue(strings.HasSuffix(versions, fmt.Sprintf(",\"%s\"]}\n", latest.Version))) }) } diff --git a/cmd/skaffold/app/cmd/test.go b/cmd/skaffold/app/cmd/test.go index b4735d2b75a..41519defc33 100644 --- a/cmd/skaffold/app/cmd/test.go +++ b/cmd/skaffold/app/cmd/test.go @@ -24,7 +24,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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) @@ -41,9 +41,9 @@ func NewCmdTest() *cobra.Command { func doTest(ctx context.Context, out io.Writer) error { return withRunner(ctx, out, func(r runner.Runner, configs []util.VersionedConfig) error { - var artifacts []*latestV1.Artifact + var artifacts []*latest.Artifact for _, c := range configs { - artifacts = append(artifacts, c.(*latestV1.SkaffoldConfig).Build.Artifacts...) + artifacts = append(artifacts, c.(*latest.SkaffoldConfig).Build.Artifacts...) } buildArtifacts, err := getBuildArtifactsAndSetTags(artifacts, r.ApplyDefaultRepo) if err != nil { diff --git a/cmd/skaffold/app/cmd/util.go b/cmd/skaffold/app/cmd/util.go index d77638e7a48..ee6c3095647 100644 --- a/cmd/skaffold/app/cmd/util.go +++ b/cmd/skaffold/app/cmd/util.go @@ -21,7 +21,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" tag "github.com/GoogleContainerTools/skaffold/pkg/skaffold/tag/util" ) @@ -29,7 +29,7 @@ import ( // no default repo is specified. type DefaultRepoFn func(string) (string, error) -func getBuildArtifactsAndSetTags(artifacts []*latestV1.Artifact, defaulterFn DefaultRepoFn) ([]graph.Artifact, error) { +func getBuildArtifactsAndSetTags(artifacts []*latest.Artifact, defaulterFn DefaultRepoFn) ([]graph.Artifact, error) { buildArtifacts, err := mergeBuildArtifacts(fromBuildOutputFile.BuildArtifacts(), preBuiltImages.Artifacts(), artifacts) if err != nil { return nil, err @@ -50,7 +50,7 @@ func applyDefaultRepoToArtifacts(artifacts []graph.Artifact, defaulterFn Default return artifacts, nil } -func mergeBuildArtifacts(fromFile, fromCLI []graph.Artifact, artifacts []*latestV1.Artifact) ([]graph.Artifact, error) { +func mergeBuildArtifacts(fromFile, fromCLI []graph.Artifact, artifacts []*latest.Artifact) ([]graph.Artifact, error) { var buildArtifacts []graph.Artifact for _, artifact := range artifacts { buildArtifacts = append(buildArtifacts, graph.Artifact{ diff --git a/cmd/skaffold/app/cmd/util_test.go b/cmd/skaffold/app/cmd/util_test.go index 960a187994b..24a1b8f6862 100644 --- a/cmd/skaffold/app/cmd/util_test.go +++ b/cmd/skaffold/app/cmd/util_test.go @@ -22,14 +22,14 @@ import ( "testing" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) func TestGetArtifacts(t *testing.T) { tests := []struct { description string - artifacts []*latestV1.Artifact + artifacts []*latest.Artifact fromFile []graph.Artifact fromCLI []graph.Artifact expected []graph.Artifact @@ -45,48 +45,48 @@ func TestGetArtifacts(t *testing.T) { }, { description: "from file", - artifacts: []*latestV1.Artifact{{ImageName: "image"}}, + artifacts: []*latest.Artifact{{ImageName: "image"}}, fromFile: []graph.Artifact{{ImageName: "image", Tag: "image:tag"}}, fromCLI: nil, expected: []graph.Artifact{{ImageName: "image", Tag: "image:tag"}}, }, { description: "from CLI", - artifacts: []*latestV1.Artifact{{ImageName: "image"}}, + artifacts: []*latest.Artifact{{ImageName: "image"}}, fromFile: nil, fromCLI: []graph.Artifact{{ImageName: "image", Tag: "image:tag"}}, expected: []graph.Artifact{{ImageName: "image", Tag: "image:tag"}}, }, { description: "one from file, one from CLI", - artifacts: []*latestV1.Artifact{{ImageName: "image1"}, {ImageName: "image2"}}, + artifacts: []*latest.Artifact{{ImageName: "image1"}, {ImageName: "image2"}}, fromFile: []graph.Artifact{{ImageName: "image1", Tag: "image1:tag"}}, fromCLI: []graph.Artifact{{ImageName: "image2", Tag: "image2:tag"}}, expected: []graph.Artifact{{ImageName: "image1", Tag: "image1:tag"}, {ImageName: "image2", Tag: "image2:tag"}}, }, { description: "file takes precedence on CLI", - artifacts: []*latestV1.Artifact{{ImageName: "image1"}, {ImageName: "image2"}}, + artifacts: []*latest.Artifact{{ImageName: "image1"}, {ImageName: "image2"}}, fromFile: []graph.Artifact{{ImageName: "image1", Tag: "image1:tag"}, {ImageName: "image2", Tag: "image2:tag"}}, fromCLI: []graph.Artifact{{ImageName: "image1", Tag: "image1:ignored"}}, expected: []graph.Artifact{{ImageName: "image1", Tag: "image1:tag"}, {ImageName: "image2", Tag: "image2:tag"}}, }, { description: "provide tag for non-artifact", - artifacts: []*latestV1.Artifact{}, + artifacts: []*latest.Artifact{}, fromCLI: []graph.Artifact{{ImageName: "busybox", Tag: "busybox:v1"}}, expected: []graph.Artifact{{ImageName: "busybox", Tag: "busybox:v1"}}, }, { description: "missing tag", - artifacts: []*latestV1.Artifact{{ImageName: "image1"}, {ImageName: "image2"}}, + artifacts: []*latest.Artifact{{ImageName: "image1"}, {ImageName: "image2"}}, fromFile: nil, fromCLI: nil, shouldErr: true, }, { description: "override tag", - artifacts: []*latestV1.Artifact{{ImageName: "image1"}, {ImageName: "image2"}}, + artifacts: []*latest.Artifact{{ImageName: "image1"}, {ImageName: "image2"}}, fromFile: []graph.Artifact{{ImageName: "image1", Tag: "image1:tag"}}, fromCLI: []graph.Artifact{{ImageName: "image2", Tag: "image2:tag"}}, expected: []graph.Artifact{{ImageName: "image1", Tag: "image1:test"}, {ImageName: "image2", Tag: "image2:test"}}, @@ -94,7 +94,7 @@ func TestGetArtifacts(t *testing.T) { }, { description: "override missing tag", - artifacts: []*latestV1.Artifact{{ImageName: "image1"}, {ImageName: "image2"}}, + artifacts: []*latest.Artifact{{ImageName: "image1"}, {ImageName: "image2"}}, fromFile: nil, fromCLI: nil, expected: []graph.Artifact{{ImageName: "image1", Tag: "image1:test"}, {ImageName: "image2", Tag: "image2:test"}}, @@ -102,7 +102,7 @@ func TestGetArtifacts(t *testing.T) { }, { description: "apply tags to no artifacts", - artifacts: []*latestV1.Artifact{}, + artifacts: []*latest.Artifact{}, fromFile: nil, fromCLI: nil, expected: []graph.Artifact(nil), diff --git a/docs/content/en/docs/tutorials/skaffold-resource-selector.md b/docs/content/en/docs/tutorials/skaffold-resource-selector.md index 9eedb37b70a..51757f0705b 100644 --- a/docs/content/en/docs/tutorials/skaffold-resource-selector.md +++ b/docs/content/en/docs/tutorials/skaffold-resource-selector.md @@ -48,7 +48,7 @@ _* *.image (changes `image:` value to be the skaffold built image ONLY IF skaffo The GroupKind's that Skaffold manages (via resource field overwriting) are user configurable via the `resourceSelector:` top level configuration. The `resourceSelector` configuration allows users to modify and extend which resources and what fields of those resources skaffold modifies. Currently skaffold only supports `label:` and `.metadata.labels` related modifications. (TODO add `resourceSelector` schema overview and allowable inputs) -`resourceSelector` spec (from `pkg/skaffold/schema/latest/v1/config.go`) +`resourceSelector` spec (from `pkg/skaffold/schema/latest/config.go`) ``` // ResourceSelector describes user defined filters describing how skaffold should treat objects/fields during rendering. ResourceSelector ResourceSelectorConfig `yaml:"resourceSelector,omitempty"` diff --git a/docs/design_proposals/configurable-transformable-allowlist.md b/docs/design_proposals/configurable-transformable-allowlist.md index 9aaa9045ca8..a0f7ae7d5ea 100644 --- a/docs/design_proposals/configurable-transformable-allowlist.md +++ b/docs/design_proposals/configurable-transformable-allowlist.md @@ -71,7 +71,7 @@ Is there any need to work out a deny list? ## Implementation plan -1. `pkg/skaffold/schema/latest/v1/config.go` - Add config option +1. `pkg/skaffold/schema/latest/config.go` - Add config option `transformableAllowList` to `DeployConfig`. 2. `pkg/skaffold/kubernetes/manifest/visitor.go` - Refactor allowlist and add new parameter `transformableAllowList` to `*ManifestList.Visit()` by appending diff --git a/docs/design_proposals/ko-builder.md b/docs/design_proposals/ko-builder.md index 8ea9e4fceb5..74258c977d1 100644 --- a/docs/design_proposals/ko-builder.md +++ b/docs/design_proposals/ko-builder.md @@ -163,7 +163,7 @@ If `main` is a relative path (and it will be most of the time), it is relative to the current [`context`](https://skaffold.dev/docs/references/yaml/#build-artifacts-context) (a.k.a. -[`Workspace`](https://github.com/GoogleContainerTools/skaffold/blob/v1.27.0/pkg/skaffold/schema/latest/v1/config.go#L832)) +[`Workspace`](https://github.com/GoogleContainerTools/skaffold/blob/v1.27.0/pkg/skaffold/schema/latest/config.go#L832)) directory. For example, to build Skaffold itself, with `package main` in the diff --git a/hack/release/changelog/main.go b/hack/release/changelog/main.go index a87ae69cd4e..f02afd0a7cc 100644 --- a/hack/release/changelog/main.go +++ b/hack/release/changelog/main.go @@ -30,7 +30,7 @@ import ( "github.com/blang/semver" "github.com/GoogleContainerTools/skaffold/hack/versions/pkg/schema" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) type changelogData struct { @@ -65,13 +65,13 @@ func getChangelogData(schemaIsReleased func(string) (bool, error)) (changelogDat data.Date = currentTime.Format("01/02/2006") // Add extra string if new schema version is being released - latest := path.Join("pkg", "skaffold", "schema", "latest", "v1", "config.go") - released, err := schemaIsReleased(latest) + schema := path.Join("pkg", "skaffold", "schema", "latest", "v1", "config.go") + released, err := schemaIsReleased(schema) if err != nil { return changelogData{}, fmt.Errorf("checking if schema is released: %w", err) } if !released { - schemaVersion := strings.TrimPrefix(latestV1.Version, "skaffold/") + schemaVersion := strings.TrimPrefix(latest.Version, "skaffold/") data.SchemaString = fmt.Sprintf("\nNote: This release comes with a new config version, `%s`. To upgrade your skaffold.yaml, use `skaffold fix`. If you choose not to upgrade, skaffold will auto-upgrade as best as it can.\n", schemaVersion) } diff --git a/hack/schemas/main.go b/hack/schemas/main.go index c62681eed7b..6ab162f57e6 100644 --- a/hack/schemas/main.go +++ b/hack/schemas/main.go @@ -134,7 +134,7 @@ func generateV1Schema(root string, dryRun bool, version schema.Version) (bool, e folder := apiVersion strict := false if version.APIVersion == schema.SchemaVersionsV1[len(schema.SchemaVersionsV1)-1].APIVersion { - folder = "latest/v1" + folder = "latest" strict = true } diff --git a/hack/versions/cmd/new/templates/upgrade.template b/hack/versions/cmd/new/templates/upgrade.template index 865544081d0..77d1b92a96d 100755 --- a/hack/versions/cmd/new/templates/upgrade.template +++ b/hack/versions/cmd/new/templates/upgrade.template @@ -17,7 +17,7 @@ limitations under the License. package %PREV_VERSION% import ( - next "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + next "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" pkgutil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) diff --git a/hack/versions/cmd/new/templates/upgrade_test.template b/hack/versions/cmd/new/templates/upgrade_test.template index 3b13d9e0568..af044eb82fd 100755 --- a/hack/versions/cmd/new/templates/upgrade_test.template +++ b/hack/versions/cmd/new/templates/upgrade_test.template @@ -19,7 +19,7 @@ package %PREV_VERSION% import ( "testing" - next "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + next "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml" "github.com/GoogleContainerTools/skaffold/testutil" ) diff --git a/hack/versions/cmd/new/version.go b/hack/versions/cmd/new/version.go index 6d192f13651..5c1fcf58d24 100644 --- a/hack/versions/cmd/new/version.go +++ b/hack/versions/cmd/new/version.go @@ -71,8 +71,8 @@ func main() { sed(path(current, "upgrade_test.go"), "%PREV_VERSION%", current) // Previous version now upgrades to current instead of latest - sed(path(prev, "upgrade.go"), "latest/v1", current) - sed(path(prev, "upgrade_test.go"), "latest/v1", current) + sed(path(prev, "upgrade.go"), "latest", current) + sed(path(prev, "upgrade_test.go"), "latest", current) // Latest uses the new version sed(path("latest", "v1", "config.go"), current, next) diff --git a/hack/versions/pkg/schema/version.go b/hack/versions/pkg/schema/version.go index a915d3d12fa..4f57793ff02 100644 --- a/hack/versions/pkg/schema/version.go +++ b/hack/versions/pkg/schema/version.go @@ -25,15 +25,15 @@ import ( "github.com/sirupsen/logrus" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/update" ) func GetLatestVersion() (string, bool) { - current := strings.TrimPrefix(latestV1.Version, "skaffold/") + current := strings.TrimPrefix(latest.Version, "skaffold/") logrus.Debugf("Current Skaffold version: %s", current) - config, err := ioutil.ReadFile("pkg/skaffold/schema/latest/v1/config.go") + config, err := ioutil.ReadFile("pkg/skaffold/schema/latest/config.go") if err != nil { logrus.Fatalf("failed to read latest config: %s", err) } @@ -58,7 +58,7 @@ func getLastReleasedConfigVersion() string { logrus.Infof("last release tag: %s", lastTag) // we split the config in v1.25.0 for _, url := range []string{ - fmt.Sprintf("https://raw.githubusercontent.com/GoogleContainerTools/skaffold/%s/pkg/skaffold/schema/latest/v1/config.go", lastTag), + fmt.Sprintf("https://raw.githubusercontent.com/GoogleContainerTools/skaffold/%s/pkg/skaffold/schema/latest/config.go", lastTag), fmt.Sprintf("https://raw.githubusercontent.com/GoogleContainerTools/skaffold/%s/pkg/skaffold/schema/latest/config.go", lastTag), } { resp, err := http.Get(url) diff --git a/integration/ko_test.go b/integration/ko_test.go index 4f2e9195799..fc6949150c9 100644 --- a/integration/ko_test.go +++ b/integration/ko_test.go @@ -33,7 +33,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/ko" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) func TestBuildAndPushKoImageProgrammatically(t *testing.T) { @@ -58,9 +58,9 @@ func TestBuildAndPushKoImageProgrammatically(t *testing.T) { // Build the artifact b := ko.NewArtifactBuilder(nil, true, config.RunModes.Build, nil) - artifact := &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - KoArtifact: &latestV1.KoArtifact{ + artifact := &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + KoArtifact: &latest.KoArtifact{ BaseImage: baseImage, }, }, diff --git a/integration/render_test.go b/integration/render_test.go index 0db9ad02055..d208faa545e 100644 --- a/integration/render_test.go +++ b/integration/render_test.go @@ -34,7 +34,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/label" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "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/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -79,16 +79,16 @@ spec: Chdir() deployer, err := kubectl.NewDeployer(&runcontext.RunContext{ WorkingDir: ".", - Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{{ - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{ + Pipelines: runcontext.NewPipelines([]latest.Pipeline{{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{ Manifests: []string{"deployment.yaml"}, }, }, }, }}), - }, &label.DefaultLabeller{}, &latestV1.KubectlDeploy{ + }, &label.DefaultLabeller{}, &latest.KubectlDeploy{ Manifests: []string{"deployment.yaml"}, }) t.RequireNoError(err) @@ -236,17 +236,17 @@ spec: deployer, err := kubectl.NewDeployer(&runcontext.RunContext{ WorkingDir: ".", - Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{{ - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{ + Pipelines: runcontext.NewPipelines([]latest.Pipeline{{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{ Manifests: []string{"deployment.yaml"}, }, }, }, }}), Opts: config.SkaffoldOptions{}, - }, &label.DefaultLabeller{}, &latestV1.KubectlDeploy{ + }, &label.DefaultLabeller{}, &latest.KubectlDeploy{ Manifests: []string{"deployment.yaml"}, }) t.RequireNoError(err) @@ -265,7 +265,7 @@ func TestHelmRender(t *testing.T) { tests := []struct { description string builds []graph.Artifact - helmReleases []latestV1.HelmRelease + helmReleases []latest.HelmRelease expectedOut string }{ { @@ -276,7 +276,7 @@ func TestHelmRender(t *testing.T) { Tag: "gke-loadbalancer:test", }, }, - helmReleases: []latestV1.HelmRelease{{ + helmReleases: []latest.HelmRelease{{ Name: "gke-loadbalancer", ChartPath: "testdata/gke_loadbalancer/loadbalancer-helm", ArtifactOverrides: map[string]string{ @@ -334,7 +334,7 @@ spec: Tag: "gcr.io/k8s-skaffold/skaffold-helm:sha256-nonsenslettersandnumbers", }, }, - helmReleases: []latestV1.HelmRelease{{ + helmReleases: []latest.HelmRelease{{ Name: "skaffold-helm", ChartPath: "testdata/helm/skaffold-helm", ArtifactOverrides: map[string]string{ @@ -423,16 +423,16 @@ spec: for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { deployer, err := helm.NewDeployer(context.Background(), &runcontext.RunContext{ - Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{{ - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - HelmDeploy: &latestV1.HelmDeploy{ + Pipelines: runcontext.NewPipelines([]latest.Pipeline{{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + HelmDeploy: &latest.HelmDeploy{ Releases: test.helmReleases, }, }, }, }}), - }, &label.DefaultLabeller{}, &latestV1.HelmDeploy{ + }, &label.DefaultLabeller{}, &latest.HelmDeploy{ Releases: test.helmReleases, }) t.RequireNoError(err) diff --git a/pkg/skaffold/build/bazel/build.go b/pkg/skaffold/build/bazel/build.go index 12eceb865be..64a642037e9 100644 --- a/pkg/skaffold/build/bazel/build.go +++ b/pkg/skaffold/build/bazel/build.go @@ -29,12 +29,12 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) // Build builds an artifact with Bazel. -func (b *Builder) Build(ctx context.Context, out io.Writer, artifact *latestV1.Artifact, tag string, matcher platform.Matcher) (string, error) { +func (b *Builder) Build(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string, matcher platform.Matcher) (string, error) { // TODO: Implement building multi-platform images if matcher.IsMultiPlatform() { log.Entry(ctx).Warnf("multiple target platforms %q found for artifact %q. Skaffold doesn't yet support multi-platform builds for the bazel builder. Consider specifying a single target platform explicitly. See https://skaffold.dev/docs/pipeline-stages/builders/#cross-platform-build-support", matcher.String(), artifact.ImageName) @@ -55,7 +55,7 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, artifact *latestV1.A func (b *Builder) SupportedPlatforms() platform.Matcher { return platform.All } -func (b *Builder) buildTar(ctx context.Context, out io.Writer, workspace string, a *latestV1.BazelArtifact) (string, error) { +func (b *Builder) buildTar(ctx context.Context, out io.Writer, workspace string, a *latest.BazelArtifact) (string, error) { if !strings.HasSuffix(a.BuildTarget, ".tar") { return "", errors.New("the bazel build target should end with .tar, see https://github.com/bazelbuild/rules_docker#using-with-docker-locally") } @@ -87,7 +87,7 @@ func (b *Builder) buildTar(ctx context.Context, out io.Writer, workspace string, return tarPath, nil } -func (b *Builder) loadImage(ctx context.Context, out io.Writer, tarPath string, a *latestV1.BazelArtifact, tag string) (string, error) { +func (b *Builder) loadImage(ctx context.Context, out io.Writer, tarPath string, a *latest.BazelArtifact, tag string) (string, error) { imageTar, err := os.Open(tarPath) if err != nil { return "", fmt.Errorf("opening image tarball: %w", err) @@ -107,7 +107,7 @@ func (b *Builder) loadImage(ctx context.Context, out io.Writer, tarPath string, return imageID, nil } -func bazelTarPath(ctx context.Context, workspace string, a *latestV1.BazelArtifact) (string, error) { +func bazelTarPath(ctx context.Context, workspace string, a *latest.BazelArtifact) (string, error) { args := []string{ "cquery", a.BuildTarget, diff --git a/pkg/skaffold/build/bazel/build_test.go b/pkg/skaffold/build/bazel/build_test.go index 915676a8cf0..5e376582a5d 100644 --- a/pkg/skaffold/build/bazel/build_test.go +++ b/pkg/skaffold/build/bazel/build_test.go @@ -23,7 +23,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -36,10 +36,10 @@ func TestBuildBazel(t *testing.T) { "bin/app.tar")) testutil.CreateFakeImageTar("bazel:app", "bin/app.tar") - artifact := &latestV1.Artifact{ + artifact := &latest.Artifact{ Workspace: ".", - ArtifactType: latestV1.ArtifactType{ - BazelArtifact: &latestV1.BazelArtifact{ + ArtifactType: latest.ArtifactType{ + BazelArtifact: &latest.BazelArtifact{ BuildTarget: "//:app.tar", }, }, @@ -54,9 +54,9 @@ func TestBuildBazel(t *testing.T) { func TestBuildBazelFailInvalidTarget(t *testing.T) { testutil.Run(t, "", func(t *testutil.T) { - artifact := &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - BazelArtifact: &latestV1.BazelArtifact{ + artifact := &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + BazelArtifact: &latest.BazelArtifact{ BuildTarget: "//:invalid-target", }, }, @@ -76,7 +76,7 @@ func TestBazelTarPath(t *testing.T) { "/absolute/path/bin\n", )) - bazelBin, err := bazelTarPath(context.Background(), ".", &latestV1.BazelArtifact{ + bazelBin, err := bazelTarPath(context.Background(), ".", &latest.BazelArtifact{ BuildArgs: []string{"--arg1", "--arg2"}, BuildTarget: "//:skaffold_example.tar", }) diff --git a/pkg/skaffold/build/bazel/dependencies.go b/pkg/skaffold/build/bazel/dependencies.go index 14768720e44..c2459bd2a61 100644 --- a/pkg/skaffold/build/bazel/dependencies.go +++ b/pkg/skaffold/build/bazel/dependencies.go @@ -28,7 +28,7 @@ import ( "time" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -42,7 +42,7 @@ var once sync.Once // GetDependencies finds the sources dependencies for the given bazel artifact. // All paths are relative to the workspace. -func GetDependencies(ctx context.Context, dir string, a *latestV1.BazelArtifact) ([]string, error) { +func GetDependencies(ctx context.Context, dir string, a *latest.BazelArtifact) ([]string, error) { timer := time.NewTimer(1 * time.Second) defer timer.Stop() diff --git a/pkg/skaffold/build/bazel/dependencies_test.go b/pkg/skaffold/build/bazel/dependencies_test.go index 4ed04bef9e7..74b7594bb98 100644 --- a/pkg/skaffold/build/bazel/dependencies_test.go +++ b/pkg/skaffold/build/bazel/dependencies_test.go @@ -21,7 +21,7 @@ import ( "path/filepath" "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -82,7 +82,7 @@ func TestGetDependencies(t *testing.T) { )) t.NewTempDir().WriteFiles(test.files).Chdir() - deps, err := GetDependencies(context.Background(), test.workspace, &latestV1.BazelArtifact{ + deps, err := GetDependencies(context.Background(), test.workspace, &latest.BazelArtifact{ BuildTarget: test.target, }) diff --git a/pkg/skaffold/build/build.go b/pkg/skaffold/build/build.go index 676f0400a88..5c413afd9b6 100644 --- a/pkg/skaffold/build/build.go +++ b/pkg/skaffold/build/build.go @@ -22,7 +22,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/tag" ) @@ -31,7 +31,7 @@ import ( // This could include pushing to a authorized repository or loading the nodes with the image. // If artifacts is supplied, the builder should only rebuild those artifacts. type Builder interface { - Build(ctx context.Context, out io.Writer, tags tag.ImageTags, platforms platform.Resolver, artifacts []*latestV1.Artifact) ([]graph.Artifact, error) + Build(ctx context.Context, out io.Writer, tags tag.ImageTags, platforms platform.Resolver, artifacts []*latest.Artifact) ([]graph.Artifact, error) // Prune removes images built with Skaffold Prune(context.Context, io.Writer) error @@ -45,7 +45,7 @@ type PipelineBuilder interface { PreBuild(ctx context.Context, out io.Writer) error // Build returns the `ArtifactBuilder` based on this build pipeline type - Build(ctx context.Context, out io.Writer, artifact *latestV1.Artifact) ArtifactBuilder + Build(ctx context.Context, out io.Writer, artifact *latest.Artifact) ArtifactBuilder // PostBuild executes any one-time teardown required after all builds on this builder are complete PostBuild(ctx context.Context, out io.Writer) error diff --git a/pkg/skaffold/build/builder_mux.go b/pkg/skaffold/build/builder_mux.go index c079acaa182..cb97222030c 100644 --- a/pkg/skaffold/build/builder_mux.go +++ b/pkg/skaffold/build/builder_mux.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/hooks" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/tag" ) @@ -41,7 +41,7 @@ type BuilderMux struct { // Config represents an interface for getting all config pipelines. type Config interface { - GetPipelines() []latestV1.Pipeline + GetPipelines() []latest.Pipeline DefaultRepo() *string MultiLevelRepo() *bool GlobalConfig() string @@ -49,7 +49,7 @@ type Config interface { } // NewBuilderMux returns an implementation of `build.BuilderMux`. -func NewBuilderMux(cfg Config, store ArtifactStore, builder func(p latestV1.Pipeline) (PipelineBuilder, error)) (*BuilderMux, error) { +func NewBuilderMux(cfg Config, store ArtifactStore, builder func(p latest.Pipeline) (PipelineBuilder, error)) (*BuilderMux, error) { pipelines := cfg.GetPipelines() m := make(map[string]PipelineBuilder) var pbs []PipelineBuilder @@ -68,7 +68,7 @@ func NewBuilderMux(cfg Config, store ArtifactStore, builder func(p latestV1.Pipe } // Build executes the specific image builder for each artifact in the given artifact slice. -func (b *BuilderMux) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, resolver platform.Resolver, artifacts []*latestV1.Artifact) ([]graph.Artifact, error) { +func (b *BuilderMux) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, resolver platform.Resolver, artifacts []*latest.Artifact) ([]graph.Artifact, error) { m := make(map[PipelineBuilder]bool) for _, a := range artifacts { m[b.byImageName[a.ImageName]] = true @@ -80,7 +80,7 @@ func (b *BuilderMux) Build(ctx context.Context, out io.Writer, tags tag.ImageTag } } - builderF := func(ctx context.Context, out io.Writer, artifact *latestV1.Artifact, tag string, platforms platform.Matcher) (string, error) { + builderF := func(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string, platforms platform.Matcher) (string, error) { p := b.byImageName[artifact.ImageName] pl, err := filterBuildEnvSupportedPlatforms(p.SupportedPlatforms(), platforms) if err != nil { diff --git a/pkg/skaffold/build/builder_mux_test.go b/pkg/skaffold/build/builder_mux_test.go index f79b17d9879..c61c9b2f3b7 100644 --- a/pkg/skaffold/build/builder_mux_test.go +++ b/pkg/skaffold/build/builder_mux_test.go @@ -23,7 +23,7 @@ import ( "testing" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -31,16 +31,16 @@ import ( func TestNewBuilderMux(t *testing.T) { tests := []struct { description string - pipelines []latestV1.Pipeline - pipeBuilder func(latestV1.Pipeline) (PipelineBuilder, error) + pipelines []latest.Pipeline + pipeBuilder func(latest.Pipeline) (PipelineBuilder, error) shouldErr bool expectedBuilders []string expectedConcurrency int }{ { description: "only local builder", - pipelines: []latestV1.Pipeline{ - {Build: latestV1.BuildConfig{BuildType: latestV1.BuildType{LocalBuild: &latestV1.LocalBuild{Concurrency: util.IntPtr(1)}}}}, + pipelines: []latest.Pipeline{ + {Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{Concurrency: util.IntPtr(1)}}}}, }, pipeBuilder: newMockPipelineBuilder, expectedBuilders: []string{"local"}, @@ -48,26 +48,26 @@ func TestNewBuilderMux(t *testing.T) { }, { description: "only cluster builder", - pipelines: []latestV1.Pipeline{ - {Build: latestV1.BuildConfig{BuildType: latestV1.BuildType{Cluster: &latestV1.ClusterDetails{}}}}, + pipelines: []latest.Pipeline{ + {Build: latest.BuildConfig{BuildType: latest.BuildType{Cluster: &latest.ClusterDetails{}}}}, }, pipeBuilder: newMockPipelineBuilder, expectedBuilders: []string{"cluster"}, }, { description: "only gcb builder", - pipelines: []latestV1.Pipeline{ - {Build: latestV1.BuildConfig{BuildType: latestV1.BuildType{GoogleCloudBuild: &latestV1.GoogleCloudBuild{}}}}, + pipelines: []latest.Pipeline{ + {Build: latest.BuildConfig{BuildType: latest.BuildType{GoogleCloudBuild: &latest.GoogleCloudBuild{}}}}, }, pipeBuilder: newMockPipelineBuilder, expectedBuilders: []string{"gcb"}, }, { description: "min non-zero concurrency", - pipelines: []latestV1.Pipeline{ - {Build: latestV1.BuildConfig{BuildType: latestV1.BuildType{LocalBuild: &latestV1.LocalBuild{Concurrency: util.IntPtr(0)}}}}, - {Build: latestV1.BuildConfig{BuildType: latestV1.BuildType{LocalBuild: &latestV1.LocalBuild{Concurrency: util.IntPtr(3)}}}}, - {Build: latestV1.BuildConfig{BuildType: latestV1.BuildType{Cluster: &latestV1.ClusterDetails{Concurrency: 2}}}}, + pipelines: []latest.Pipeline{ + {Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{Concurrency: util.IntPtr(0)}}}}, + {Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{Concurrency: util.IntPtr(3)}}}}, + {Build: latest.BuildConfig{BuildType: latest.BuildType{Cluster: &latest.ClusterDetails{Concurrency: 2}}}}, }, pipeBuilder: newMockPipelineBuilder, expectedBuilders: []string{"local", "local", "cluster"}, @@ -180,12 +180,12 @@ func TestGetConcurrency(t *testing.T) { } type mockConfig struct { - pipelines []latestV1.Pipeline + pipelines []latest.Pipeline optRepo string } -func (m *mockConfig) GetPipelines() []latestV1.Pipeline { return m.pipelines } -func (m *mockConfig) GlobalConfig() string { return "" } +func (m *mockConfig) GetPipelines() []latest.Pipeline { return m.pipelines } +func (m *mockConfig) GlobalConfig() string { return "" } func (m *mockConfig) DefaultRepo() *string { if m.optRepo != "" { return &m.optRepo @@ -202,7 +202,7 @@ type mockPipelineBuilder struct { func (m *mockPipelineBuilder) PreBuild(ctx context.Context, out io.Writer) error { return nil } -func (m *mockPipelineBuilder) Build(ctx context.Context, out io.Writer, artifact *latestV1.Artifact) ArtifactBuilder { +func (m *mockPipelineBuilder) Build(ctx context.Context, out io.Writer, artifact *latest.Artifact) ArtifactBuilder { return nil } @@ -216,7 +216,7 @@ func (m *mockPipelineBuilder) PushImages() bool { return false } func (m *mockPipelineBuilder) SupportedPlatforms() platform.Matcher { return platform.All } -func newMockPipelineBuilder(p latestV1.Pipeline) (PipelineBuilder, error) { +func newMockPipelineBuilder(p latest.Pipeline) (PipelineBuilder, error) { switch { case p.Build.BuildType.LocalBuild != nil: return &mockPipelineBuilder{builderType: "local", concurrency: p.Build.LocalBuild.Concurrency}, nil diff --git a/pkg/skaffold/build/buildpacks/build.go b/pkg/skaffold/build/buildpacks/build.go index b0de050b3fe..f489e025c7e 100644 --- a/pkg/skaffold/build/buildpacks/build.go +++ b/pkg/skaffold/build/buildpacks/build.go @@ -25,12 +25,12 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // Build builds an artifact with Cloud Native Buildpacks: // https://buildpacks.io/ -func (b *Builder) Build(ctx context.Context, out io.Writer, artifact *latestV1.Artifact, tag string, matcher platform.Matcher) (string, error) { +func (b *Builder) Build(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string, matcher platform.Matcher) (string, error) { if matcher.IsMultiPlatform() { // TODO: Implement building multiplatform images log.Entry(ctx).Warnf("multiple target platforms %q found for artifact %q. Skaffold doesn't yet support multi-platform builds for the buildpacks builder. Consider specifying a single target platform explicitly. See https://skaffold.dev/docs/pipeline-stages/builders/#cross-platform-build-support", matcher.String(), artifact.ImageName) diff --git a/pkg/skaffold/build/buildpacks/build_test.go b/pkg/skaffold/build/buildpacks/build_test.go index 7531eb1f19e..117cb92726e 100644 --- a/pkg/skaffold/build/buildpacks/build_test.go +++ b/pkg/skaffold/build/buildpacks/build_test.go @@ -30,7 +30,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -47,7 +47,7 @@ func (f *fakePack) runPack(_ context.Context, _ io.Writer, _ docker.LocalDaemon, func TestBuild(t *testing.T) { tests := []struct { description string - artifact *latestV1.Artifact + artifact *latest.Artifact tag string api *testutil.FakeAPIClient files map[string]string @@ -197,7 +197,7 @@ value = "VALUE2" }, { description: "dev mode", - artifact: withSync(&latestV1.Sync{Auto: util.BoolPtr(true)}, buildpacksArtifact("another/builder", "another/run")), + artifact: withSync(&latest.Sync{Auto: util.BoolPtr(true)}, buildpacksArtifact("another/builder", "another/run")), tag: "img:tag", api: &testutil.FakeAPIClient{}, resolver: mockArtifactResolver{}, @@ -292,7 +292,7 @@ value = "VALUE2" func TestBuildWithArtifactDependencies(t *testing.T) { tests := []struct { description string - artifact *latestV1.Artifact + artifact *latest.Artifact tag string api *testutil.FakeAPIClient files map[string]string @@ -304,7 +304,7 @@ func TestBuildWithArtifactDependencies(t *testing.T) { }{ { description: "custom builder image only with no push", - artifact: withRequiredArtifacts([]*latestV1.ArtifactDependency{{ImageName: "builder-image", Alias: "BUILDER_IMAGE"}}, buildpacksArtifact("BUILDER_IMAGE", "my/run")), + artifact: withRequiredArtifacts([]*latest.ArtifactDependency{{ImageName: "builder-image", Alias: "BUILDER_IMAGE"}}, buildpacksArtifact("BUILDER_IMAGE", "my/run")), tag: "img:tag", pushImages: false, mode: config.RunModes.Build, @@ -321,7 +321,7 @@ func TestBuildWithArtifactDependencies(t *testing.T) { }, { description: "custom run image only with no push", - artifact: withRequiredArtifacts([]*latestV1.ArtifactDependency{{ImageName: "run-image", Alias: "RUN_IMAGE"}}, buildpacksArtifact("my/builder", "RUN_IMAGE")), + artifact: withRequiredArtifacts([]*latest.ArtifactDependency{{ImageName: "run-image", Alias: "RUN_IMAGE"}}, buildpacksArtifact("my/builder", "RUN_IMAGE")), tag: "img:tag", pushImages: false, mode: config.RunModes.Build, @@ -338,7 +338,7 @@ func TestBuildWithArtifactDependencies(t *testing.T) { }, { description: "custom builder image only with push", - artifact: withRequiredArtifacts([]*latestV1.ArtifactDependency{{ImageName: "builder-image", Alias: "BUILDER_IMAGE"}}, buildpacksArtifact("BUILDER_IMAGE", "my/run")), + artifact: withRequiredArtifacts([]*latest.ArtifactDependency{{ImageName: "builder-image", Alias: "BUILDER_IMAGE"}}, buildpacksArtifact("BUILDER_IMAGE", "my/run")), tag: "img:tag", pushImages: true, mode: config.RunModes.Build, @@ -355,7 +355,7 @@ func TestBuildWithArtifactDependencies(t *testing.T) { }, { description: "custom run image only with push", - artifact: withRequiredArtifacts([]*latestV1.ArtifactDependency{{ImageName: "run-image", Alias: "RUN_IMAGE"}}, buildpacksArtifact("my/builder", "RUN_IMAGE")), + artifact: withRequiredArtifacts([]*latest.ArtifactDependency{{ImageName: "run-image", Alias: "RUN_IMAGE"}}, buildpacksArtifact("my/builder", "RUN_IMAGE")), tag: "img:tag", pushImages: true, mode: config.RunModes.Build, @@ -372,7 +372,7 @@ func TestBuildWithArtifactDependencies(t *testing.T) { }, { description: "custom run image and custom builder image with push", - artifact: withRequiredArtifacts([]*latestV1.ArtifactDependency{{ImageName: "run-image", Alias: "RUN_IMAGE"}, {ImageName: "builder-image", Alias: "BUILDER_IMAGE"}}, buildpacksArtifact("BUILDER_IMAGE", "RUN_IMAGE")), + artifact: withRequiredArtifacts([]*latest.ArtifactDependency{{ImageName: "run-image", Alias: "RUN_IMAGE"}, {ImageName: "builder-image", Alias: "BUILDER_IMAGE"}}, buildpacksArtifact("BUILDER_IMAGE", "RUN_IMAGE")), tag: "img:tag", pushImages: true, mode: config.RunModes.Build, @@ -389,7 +389,7 @@ func TestBuildWithArtifactDependencies(t *testing.T) { }, { description: "custom run image and custom builder image with no push", - artifact: withRequiredArtifacts([]*latestV1.ArtifactDependency{{ImageName: "run-image", Alias: "RUN_IMAGE"}, {ImageName: "builder-image", Alias: "BUILDER_IMAGE"}}, buildpacksArtifact("BUILDER_IMAGE", "RUN_IMAGE")), + artifact: withRequiredArtifacts([]*latest.ArtifactDependency{{ImageName: "run-image", Alias: "RUN_IMAGE"}, {ImageName: "builder-image", Alias: "BUILDER_IMAGE"}}, buildpacksArtifact("BUILDER_IMAGE", "RUN_IMAGE")), tag: "img:tag", pushImages: false, mode: config.RunModes.Build, @@ -429,15 +429,15 @@ func TestBuildWithArtifactDependencies(t *testing.T) { }) } } -func buildpacksArtifact(builder, runImage string) *latestV1.Artifact { - return &latestV1.Artifact{ +func buildpacksArtifact(builder, runImage string) *latest.Artifact { + return &latest.Artifact{ Workspace: ".", - ArtifactType: latestV1.ArtifactType{ - BuildpackArtifact: &latestV1.BuildpackArtifact{ + ArtifactType: latest.ArtifactType{ + BuildpackArtifact: &latest.BuildpackArtifact{ Builder: builder, RunImage: runImage, ProjectDescriptor: "project.toml", - Dependencies: &latestV1.BuildpackDependencies{ + Dependencies: &latest.BuildpackDependencies{ Paths: []string{"."}, }, }, @@ -445,27 +445,27 @@ func buildpacksArtifact(builder, runImage string) *latestV1.Artifact { } } -func withEnv(env []string, artifact *latestV1.Artifact) *latestV1.Artifact { +func withEnv(env []string, artifact *latest.Artifact) *latest.Artifact { artifact.BuildpackArtifact.Env = env return artifact } -func withSync(sync *latestV1.Sync, artifact *latestV1.Artifact) *latestV1.Artifact { +func withSync(sync *latest.Sync, artifact *latest.Artifact) *latest.Artifact { artifact.Sync = sync return artifact } -func withTrustedBuilder(artifact *latestV1.Artifact) *latestV1.Artifact { +func withTrustedBuilder(artifact *latest.Artifact) *latest.Artifact { artifact.BuildpackArtifact.TrustBuilder = true return artifact } -func withRequiredArtifacts(deps []*latestV1.ArtifactDependency, artifact *latestV1.Artifact) *latestV1.Artifact { +func withRequiredArtifacts(deps []*latest.ArtifactDependency, artifact *latest.Artifact) *latest.Artifact { artifact.Dependencies = deps return artifact } -func withBuildpacks(buildpacks []string, artifact *latestV1.Artifact) *latestV1.Artifact { +func withBuildpacks(buildpacks []string, artifact *latest.Artifact) *latest.Artifact { artifact.BuildpackArtifact.Buildpacks = buildpacks return artifact } diff --git a/pkg/skaffold/build/buildpacks/dependencies.go b/pkg/skaffold/build/buildpacks/dependencies.go index cb06fb528fb..512bdb17a37 100644 --- a/pkg/skaffold/build/buildpacks/dependencies.go +++ b/pkg/skaffold/build/buildpacks/dependencies.go @@ -20,11 +20,11 @@ import ( "context" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/list" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // GetDependencies returns dependencies listed for a buildpack artifact -func GetDependencies(ctx context.Context, workspace string, a *latestV1.BuildpackArtifact) ([]string, error) { +func GetDependencies(ctx context.Context, workspace string, a *latest.BuildpackArtifact) ([]string, error) { // TODO(dgageot): Support project.toml include/exclude. return list.Files(workspace, a.Dependencies.Paths, a.Dependencies.Ignore) } diff --git a/pkg/skaffold/build/buildpacks/dependencies_test.go b/pkg/skaffold/build/buildpacks/dependencies_test.go index a48aa329843..9a53bdaf870 100644 --- a/pkg/skaffold/build/buildpacks/dependencies_test.go +++ b/pkg/skaffold/build/buildpacks/dependencies_test.go @@ -21,7 +21,7 @@ import ( "path/filepath" "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -68,8 +68,8 @@ func TestGetDependencies(t *testing.T) { tmpDir := t.NewTempDir(). Touch("foo", "bar", "baz/file") - deps, err := GetDependencies(context.Background(), tmpDir.Root(), &latestV1.BuildpackArtifact{ - Dependencies: &latestV1.BuildpackDependencies{ + deps, err := GetDependencies(context.Background(), tmpDir.Root(), &latest.BuildpackArtifact{ + Dependencies: &latest.BuildpackDependencies{ Paths: test.paths, Ignore: test.ignore, }, diff --git a/pkg/skaffold/build/buildpacks/env.go b/pkg/skaffold/build/buildpacks/env.go index e076297fd23..e170b8eb81e 100644 --- a/pkg/skaffold/build/buildpacks/env.go +++ b/pkg/skaffold/build/buildpacks/env.go @@ -25,11 +25,11 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/misc" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) -func GetEnv(a *latestV1.Artifact, mode config.RunMode) (map[string]string, error) { +func GetEnv(a *latest.Artifact, mode config.RunMode) (map[string]string, error) { artifact := a.BuildpackArtifact workspace := a.Workspace @@ -45,7 +45,7 @@ func GetEnv(a *latestV1.Artifact, mode config.RunMode) (map[string]string, error return env(a, mode, projectDescriptor) } -func env(a *latestV1.Artifact, mode config.RunMode, projectDescriptor types.Descriptor) (map[string]string, error) { +func env(a *latest.Artifact, mode config.RunMode, projectDescriptor types.Descriptor) (map[string]string, error) { envVars, err := misc.EvaluateEnv(a.BuildpackArtifact.Env) if err != nil { return nil, fmt.Errorf("unable to evaluate env variables: %w", err) diff --git a/pkg/skaffold/build/buildpacks/init.go b/pkg/skaffold/build/buildpacks/init.go index a6762d3443e..343ec8c07f3 100644 --- a/pkg/skaffold/build/buildpacks/init.go +++ b/pkg/skaffold/build/buildpacks/init.go @@ -22,7 +22,7 @@ import ( "path/filepath" "strings" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // For testing @@ -50,9 +50,9 @@ func (c ArtifactConfig) Describe() string { } // ArtifactType returns the type of the artifact to be built. -func (c ArtifactConfig) ArtifactType(_ string) latestV1.ArtifactType { - return latestV1.ArtifactType{ - BuildpackArtifact: &latestV1.BuildpackArtifact{ +func (c ArtifactConfig) ArtifactType(_ string) latest.ArtifactType { + return latest.ArtifactType{ + BuildpackArtifact: &latest.BuildpackArtifact{ Builder: c.Builder, }, } diff --git a/pkg/skaffold/build/buildpacks/init_test.go b/pkg/skaffold/build/buildpacks/init_test.go index c5cb36b5cd3..6f0aa9a280d 100644 --- a/pkg/skaffold/build/buildpacks/init_test.go +++ b/pkg/skaffold/build/buildpacks/init_test.go @@ -20,7 +20,7 @@ import ( "path/filepath" "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -137,7 +137,7 @@ func TestArtifactType(t *testing.T) { var tests = []struct { description string config ArtifactConfig - expectedType latestV1.ArtifactType + expectedType latest.ArtifactType }{ { description: "buildpacks - NodeJS", @@ -145,8 +145,8 @@ func TestArtifactType(t *testing.T) { File: filepath.Join("path", "to", "package.json"), Builder: "some/builder", }, - expectedType: latestV1.ArtifactType{ - BuildpackArtifact: &latestV1.BuildpackArtifact{ + expectedType: latest.ArtifactType{ + BuildpackArtifact: &latest.BuildpackArtifact{ Builder: "some/builder", }, }, diff --git a/pkg/skaffold/build/buildpacks/lifecycle.go b/pkg/skaffold/build/buildpacks/lifecycle.go index def4c7cde2a..9e3fe44deaf 100644 --- a/pkg/skaffold/build/buildpacks/lifecycle.go +++ b/pkg/skaffold/build/buildpacks/lifecycle.go @@ -33,7 +33,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // For testing @@ -46,7 +46,7 @@ var ( // to pull the images that are already pulled. var images pulledImages -func (b *Builder) build(ctx context.Context, out io.Writer, a *latestV1.Artifact, tag string) (string, error) { +func (b *Builder) build(ctx context.Context, out io.Writer, a *latest.Artifact, tag string) (string, error) { artifact := a.BuildpackArtifact workspace := a.Workspace @@ -176,7 +176,7 @@ func envMap(env []string) map[string]string { // resolveDependencyImages replaces the provided builder and run images with built images from the required artifacts if specified. // The return values are builder image, run image, and if remote pull is required. -func resolveDependencyImages(artifact *latestV1.BuildpackArtifact, r ArtifactResolver, deps []*latestV1.ArtifactDependency, pushImages bool) (string, string, packimg.PullPolicy) { +func resolveDependencyImages(artifact *latest.BuildpackArtifact, r ArtifactResolver, deps []*latest.ArtifactDependency, pushImages bool) (string, string, packimg.PullPolicy) { builderImage, runImage := artifact.Builder, artifact.RunImage builderImageLocal, runImageLocal := false, false @@ -211,12 +211,12 @@ func resolveDependencyImages(artifact *latestV1.BuildpackArtifact, r ArtifactRes // if only one of builder or run image is built locally, we can enable remote image pull only if that image is also pushed to remote. pullPolicy = packimg.PullIfNotPresent - // if remote image pull is disabled then the image that is not fetched from the required artifacts might not be latestV1. + // if remote image pull is disabled then the image that is not fetched from the required artifacts might not be latest. if !pushImages && builderImageLocal { - log.Entry(context.TODO()).Warn("Disabled remote image pull since builder image is built locally. Buildpacks run image may not be latestV1.") + log.Entry(context.TODO()).Warn("Disabled remote image pull since builder image is built locally. Buildpacks run image may not be latest.") } if !pushImages && runImageLocal { - log.Entry(context.TODO()).Warn("Disabled remote image pull since run image is built locally. Buildpacks builder image may not be latestV1.") + log.Entry(context.TODO()).Warn("Disabled remote image pull since run image is built locally. Buildpacks builder image may not be latest.") } } @@ -228,7 +228,7 @@ func resolveDependencyImages(artifact *latestV1.BuildpackArtifact, r ArtifactRes return builderImage, runImage, pullPolicy } -func containerConfig(artifact *latestV1.BuildpackArtifact) (pack.ContainerConfig, error) { +func containerConfig(artifact *latest.BuildpackArtifact) (pack.ContainerConfig, error) { var vols []string if artifact.Volumes != nil { for _, v := range *artifact.Volumes { diff --git a/pkg/skaffold/build/buildpacks/lifecycle_test.go b/pkg/skaffold/build/buildpacks/lifecycle_test.go index 5d71e2bd495..cb6b273f7e3 100644 --- a/pkg/skaffold/build/buildpacks/lifecycle_test.go +++ b/pkg/skaffold/build/buildpacks/lifecycle_test.go @@ -24,7 +24,7 @@ import ( lifecycle "github.com/buildpacks/lifecycle/cmd" pack "github.com/buildpacks/pack/pkg/client" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -58,23 +58,23 @@ func TestLifecycleStatusCode(t *testing.T) { func TestContainerConfig(t *testing.T) { tests := []struct { description string - volumes []latestV1.BuildpackVolume + volumes []latest.BuildpackVolume shouldErr bool expected pack.ContainerConfig }{ { description: "single volume with no options", - volumes: []latestV1.BuildpackVolume{{Host: "/foo", Target: "/bar"}}, + volumes: []latest.BuildpackVolume{{Host: "/foo", Target: "/bar"}}, expected: pack.ContainerConfig{Volumes: []string{"/foo:/bar"}}, }, { description: "single volume with options", - volumes: []latestV1.BuildpackVolume{{Host: "/foo", Target: "/bar", Options: "rw"}}, + volumes: []latest.BuildpackVolume{{Host: "/foo", Target: "/bar", Options: "rw"}}, expected: pack.ContainerConfig{Volumes: []string{"/foo:/bar:rw"}}, }, { description: "multiple volumes", - volumes: []latestV1.BuildpackVolume{ + volumes: []latest.BuildpackVolume{ {Host: "/foo", Target: "/bar", Options: "rw"}, {Host: "/bat", Target: "/baz", Options: "ro"}, }, @@ -82,19 +82,19 @@ func TestContainerConfig(t *testing.T) { }, { description: "missing host is skipped", - volumes: []latestV1.BuildpackVolume{{Host: "", Target: "/bar"}}, + volumes: []latest.BuildpackVolume{{Host: "", Target: "/bar"}}, shouldErr: true, }, { description: "missing target is skipped", - volumes: []latestV1.BuildpackVolume{{Host: "/foo", Target: ""}}, + volumes: []latest.BuildpackVolume{{Host: "/foo", Target: ""}}, shouldErr: true, }, } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - artifact := latestV1.BuildpackArtifact{ + artifact := latest.BuildpackArtifact{ Volumes: &test.volumes, } result, err := containerConfig(&artifact) diff --git a/pkg/skaffold/build/buildpacks/metadata.go b/pkg/skaffold/build/buildpacks/metadata.go index 58512d315a3..21c8621e98f 100644 --- a/pkg/skaffold/build/buildpacks/metadata.go +++ b/pkg/skaffold/build/buildpacks/metadata.go @@ -19,7 +19,7 @@ package buildpacks import ( "encoding/json" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) type buildMetadata struct { @@ -40,7 +40,7 @@ type syncRule struct { } // $ docker inspect demo/buildpacks | jq -r '.[].Config.Labels["io.buildpacks.build.metadata"] | fromjson.bom[].metadata["devmode.sync"]' -func SyncRules(labels map[string]string) ([]*latestV1.SyncRule, error) { +func SyncRules(labels map[string]string) ([]*latest.SyncRule, error) { metadataJSON, present := labels["io.buildpacks.build.metadata"] if !present { return nil, nil @@ -51,11 +51,11 @@ func SyncRules(labels map[string]string) ([]*latestV1.SyncRule, error) { return nil, err } - var rules []*latestV1.SyncRule + var rules []*latest.SyncRule for _, b := range m.Bom { for _, sync := range b.Metadata.Sync { - rules = append(rules, &latestV1.SyncRule{ + rules = append(rules, &latest.SyncRule{ Src: sync.Src, Dest: sync.Dest, }) diff --git a/pkg/skaffold/build/buildpacks/metadata_test.go b/pkg/skaffold/build/buildpacks/metadata_test.go index beb33955e8a..1b73f7e7cc2 100644 --- a/pkg/skaffold/build/buildpacks/metadata_test.go +++ b/pkg/skaffold/build/buildpacks/metadata_test.go @@ -19,7 +19,7 @@ package buildpacks import ( "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -27,7 +27,7 @@ func TestSyncRules(t *testing.T) { tests := []struct { description string labels map[string]string - expectedRules []*latestV1.SyncRule + expectedRules []*latest.SyncRule shouldErr bool }{ { @@ -55,7 +55,7 @@ func TestSyncRules(t *testing.T) { }] }`, }, - expectedRules: []*latestV1.SyncRule{ + expectedRules: []*latest.SyncRule{ {Src: "src-value1", Dest: "dest-value1"}, {Src: "src-value2", Dest: "dest-value2"}, }, diff --git a/pkg/skaffold/build/cache/cache.go b/pkg/skaffold/build/cache/cache.go index 8f12f2f932c..272f8f8b79a 100644 --- a/pkg/skaffold/build/cache/cache.go +++ b/pkg/skaffold/build/cache/cache.go @@ -31,7 +31,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml" ) @@ -60,13 +60,13 @@ type cache struct { } // DependencyLister fetches a list of dependencies for an artifact -type DependencyLister func(ctx context.Context, artifact *latestV1.Artifact) ([]string, error) +type DependencyLister func(ctx context.Context, artifact *latest.Artifact) ([]string, error) type Config interface { docker.Config - PipelineForImage(imageName string) (latestV1.Pipeline, bool) - GetPipelines() []latestV1.Pipeline - DefaultPipeline() latestV1.Pipeline + PipelineForImage(imageName string) (latest.Pipeline, bool) + GetPipelines() []latest.Pipeline + DefaultPipeline() latest.Pipeline GetCluster() config.Cluster CacheArtifacts() bool CacheFile() string diff --git a/pkg/skaffold/build/cache/hash.go b/pkg/skaffold/build/cache/hash.go index fd30feeac7d..a0f1b7d8a04 100644 --- a/pkg/skaffold/build/cache/hash.go +++ b/pkg/skaffold/build/cache/hash.go @@ -34,7 +34,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/instrumentation" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -46,7 +46,7 @@ var ( ) type artifactHasher interface { - hash(context.Context, *latestV1.Artifact, platform.Resolver) (string, error) + hash(context.Context, *latest.Artifact, platform.Resolver) (string, error) } type artifactHasherImpl struct { @@ -66,7 +66,7 @@ func newArtifactHasher(artifacts graph.ArtifactGraph, lister DependencyLister, m } } -func (h *artifactHasherImpl) hash(ctx context.Context, a *latestV1.Artifact, platforms platform.Resolver) (string, error) { +func (h *artifactHasherImpl) hash(ctx context.Context, a *latest.Artifact, platforms platform.Resolver) (string, error) { ctx, endTrace := instrumentation.StartTrace(ctx, "hash_GenerateHashOneArtifact", map[string]string{ "ImageName": instrumentation.PII(a.ImageName), }) @@ -93,7 +93,7 @@ func (h *artifactHasherImpl) hash(ctx context.Context, a *latestV1.Artifact, pla return encode(hashes) } -func (h *artifactHasherImpl) safeHash(ctx context.Context, a *latestV1.Artifact, platforms platform.Matcher) (string, error) { +func (h *artifactHasherImpl) safeHash(ctx context.Context, a *latest.Artifact, platforms platform.Matcher) (string, error) { val := h.syncStore.Exec(a.ImageName, func() interface{} { hash, err := singleArtifactHash(ctx, h.lister, a, h.mode, platforms) @@ -113,7 +113,7 @@ func (h *artifactHasherImpl) safeHash(ctx context.Context, a *latestV1.Artifact, } // singleArtifactHash calculates the hash for a single artifact, and ignores its required artifacts. -func singleArtifactHash(ctx context.Context, depLister DependencyLister, a *latestV1.Artifact, mode config.RunMode, m platform.Matcher) (string, error) { +func singleArtifactHash(ctx context.Context, depLister DependencyLister, a *latest.Artifact, mode config.RunMode, m platform.Matcher) (string, error) { var inputs []string // Append the artifact's configuration @@ -174,7 +174,7 @@ func encode(inputs []string) (string, error) { } // TODO(dgageot): when the buildpacks builder image digest changes, we need to change the hash -func artifactConfig(a *latestV1.Artifact) (string, error) { +func artifactConfig(a *latest.Artifact) (string, error) { buf, err := json.Marshal(a.ArtifactType) if err != nil { return "", fmt.Errorf("marshalling the artifact's configuration for %q: %w", a.ImageName, err) @@ -182,7 +182,7 @@ func artifactConfig(a *latestV1.Artifact) (string, error) { return string(buf), nil } -func hashBuildArgs(artifact *latestV1.Artifact, mode config.RunMode) ([]string, error) { +func hashBuildArgs(artifact *latest.Artifact, mode config.RunMode) ([]string, error) { // only one of args or env is ever populated var args map[string]*string var env map[string]string @@ -235,7 +235,7 @@ func fileHasher(p string) (string, error) { } // sortedDependencies returns the dependencies' corresponding Artifacts as sorted by their image name. -func sortedDependencies(a *latestV1.Artifact, artifacts graph.ArtifactGraph) []*latestV1.Artifact { +func sortedDependencies(a *latest.Artifact, artifacts graph.ArtifactGraph) []*latest.Artifact { sl := artifacts.Dependencies(a) sort.Slice(sl, func(i, j int) bool { ia, ja := sl[i], sl[j] diff --git a/pkg/skaffold/build/cache/hash_test.go b/pkg/skaffold/build/cache/hash_test.go index 429c0586421..9df01bfb1bb 100644 --- a/pkg/skaffold/build/cache/hash_test.go +++ b/pkg/skaffold/build/cache/hash_test.go @@ -24,13 +24,13 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) func stubDependencyLister(dependencies []string) DependencyLister { - return func(context.Context, *latestV1.Artifact) ([]string, error) { + return func(context.Context, *latest.Artifact) ([]string, error) { return dependencies, nil } } @@ -42,7 +42,7 @@ var mockCacheHasher = func(s string) (string, error) { return s, nil } -var fakeArtifactConfig = func(a *latestV1.Artifact) (string, error) { +var fakeArtifactConfig = func(a *latest.Artifact) (string, error) { if a.ArtifactType.DockerArtifact != nil { return "docker/target=" + a.ArtifactType.DockerArtifact.Target, nil } @@ -55,7 +55,7 @@ func TestGetHashForArtifact(t *testing.T) { tests := []struct { description string dependencies []string - artifact *latestV1.Artifact + artifact *latest.Artifact mode config.RunMode platforms platform.Resolver expected string @@ -63,35 +63,35 @@ func TestGetHashForArtifact(t *testing.T) { { description: "hash for artifact", dependencies: []string{"a", "b"}, - artifact: &latestV1.Artifact{}, + artifact: &latest.Artifact{}, mode: config.RunModes.Dev, expected: "d99ab295a682897269b4db0fe7c136ea1ecd542150fa224ee03155b4e3e995d9", }, { description: "ignore file not found", dependencies: []string{"a", "b", "not-found"}, - artifact: &latestV1.Artifact{}, + artifact: &latest.Artifact{}, mode: config.RunModes.Dev, expected: "d99ab295a682897269b4db0fe7c136ea1ecd542150fa224ee03155b4e3e995d9", }, { description: "dependencies in different orders", dependencies: []string{"b", "a"}, - artifact: &latestV1.Artifact{}, + artifact: &latest.Artifact{}, mode: config.RunModes.Dev, expected: "d99ab295a682897269b4db0fe7c136ea1ecd542150fa224ee03155b4e3e995d9", }, { description: "no dependencies", - artifact: &latestV1.Artifact{}, + artifact: &latest.Artifact{}, mode: config.RunModes.Dev, expected: "7c077ca2308714493d07163e1033c4282bd869ff6d477b3e77408587f95e2930", }, { description: "docker target", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ Target: "target", }, }, @@ -101,9 +101,9 @@ func TestGetHashForArtifact(t *testing.T) { }, { description: "different docker target", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ Target: "other", }, }, @@ -114,9 +114,9 @@ func TestGetHashForArtifact(t *testing.T) { { description: "build args", dependencies: []string{"a", "b"}, - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ BuildArgs: map[string]*string{ "key": util.StringPtr("value"), }, @@ -129,9 +129,9 @@ func TestGetHashForArtifact(t *testing.T) { { description: "buildpack in dev mode", dependencies: []string{"a", "b"}, - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - BuildpackArtifact: &latestV1.BuildpackArtifact{}, + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + BuildpackArtifact: &latest.BuildpackArtifact{}, }, }, mode: config.RunModes.Dev, @@ -140,9 +140,9 @@ func TestGetHashForArtifact(t *testing.T) { { description: "buildpack in debug mode", dependencies: []string{"a", "b"}, - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - BuildpackArtifact: &latestV1.BuildpackArtifact{}, + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + BuildpackArtifact: &latest.BuildpackArtifact{}, }, }, mode: config.RunModes.Debug, @@ -172,18 +172,18 @@ func TestGetHashForArtifact(t *testing.T) { func TestGetHashForArtifactWithDependencies(t *testing.T) { tests := []struct { description string - artifacts []*latestV1.Artifact + artifacts []*latest.Artifact fileDeps map[string][]string // keyed on artifact ImageName, returns a list of mock file dependencies. mode config.RunMode expected string }{ { description: "hash for artifact with two dependencies", - artifacts: []*latestV1.Artifact{ - {ImageName: "img1", Dependencies: []*latestV1.ArtifactDependency{{ImageName: "img2"}, {ImageName: "img3"}}}, - {ImageName: "img2", Dependencies: []*latestV1.ArtifactDependency{{ImageName: "img4"}}, ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{Target: "target2"}}}, - {ImageName: "img3", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{Target: "target3"}}}, - {ImageName: "img4", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{Target: "target4"}}}, + artifacts: []*latest.Artifact{ + {ImageName: "img1", Dependencies: []*latest.ArtifactDependency{{ImageName: "img2"}, {ImageName: "img3"}}}, + {ImageName: "img2", Dependencies: []*latest.ArtifactDependency{{ImageName: "img4"}}, ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{Target: "target2"}}}, + {ImageName: "img3", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{Target: "target3"}}}, + {ImageName: "img4", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{Target: "target4"}}}, }, fileDeps: map[string][]string{"img1": {"a"}, "img2": {"b"}, "img3": {"c"}, "img4": {"d"}}, mode: config.RunModes.Dev, @@ -191,11 +191,11 @@ func TestGetHashForArtifactWithDependencies(t *testing.T) { }, { description: "hash for artifact with two dependencies in different order", - artifacts: []*latestV1.Artifact{ - {ImageName: "img1", Dependencies: []*latestV1.ArtifactDependency{{ImageName: "img3"}, {ImageName: "img2"}}}, - {ImageName: "img2", Dependencies: []*latestV1.ArtifactDependency{{ImageName: "img4"}}, ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{Target: "target2"}}}, - {ImageName: "img3", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{Target: "target3"}}}, - {ImageName: "img4", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{Target: "target4"}}}, + artifacts: []*latest.Artifact{ + {ImageName: "img1", Dependencies: []*latest.ArtifactDependency{{ImageName: "img3"}, {ImageName: "img2"}}}, + {ImageName: "img2", Dependencies: []*latest.ArtifactDependency{{ImageName: "img4"}}, ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{Target: "target2"}}}, + {ImageName: "img3", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{Target: "target3"}}}, + {ImageName: "img4", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{Target: "target4"}}}, }, fileDeps: map[string][]string{"img1": {"a"}, "img2": {"b"}, "img3": {"c"}, "img4": {"d"}}, mode: config.RunModes.Dev, @@ -203,11 +203,11 @@ func TestGetHashForArtifactWithDependencies(t *testing.T) { }, { description: "hash for artifact with different dependencies (img4 builder changed)", - artifacts: []*latestV1.Artifact{ - {ImageName: "img1", Dependencies: []*latestV1.ArtifactDependency{{ImageName: "img2"}, {ImageName: "img3"}}}, - {ImageName: "img2", Dependencies: []*latestV1.ArtifactDependency{{ImageName: "img4"}}, ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{Target: "target2"}}}, - {ImageName: "img3", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{Target: "target3"}}}, - {ImageName: "img4", ArtifactType: latestV1.ArtifactType{BuildpackArtifact: &latestV1.BuildpackArtifact{Builder: "builder"}}}, + artifacts: []*latest.Artifact{ + {ImageName: "img1", Dependencies: []*latest.ArtifactDependency{{ImageName: "img2"}, {ImageName: "img3"}}}, + {ImageName: "img2", Dependencies: []*latest.ArtifactDependency{{ImageName: "img4"}}, ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{Target: "target2"}}}, + {ImageName: "img3", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{Target: "target3"}}}, + {ImageName: "img4", ArtifactType: latest.ArtifactType{BuildpackArtifact: &latest.BuildpackArtifact{Builder: "builder"}}}, }, fileDeps: map[string][]string{"img1": {"a"}, "img2": {"b"}, "img3": {"c"}, "img4": {"d"}}, mode: config.RunModes.Dev, @@ -215,11 +215,11 @@ func TestGetHashForArtifactWithDependencies(t *testing.T) { }, { description: "hash for artifact with different dependencies (img4 files changed)", - artifacts: []*latestV1.Artifact{ - {ImageName: "img1", Dependencies: []*latestV1.ArtifactDependency{{ImageName: "img2"}, {ImageName: "img3"}}}, - {ImageName: "img2", Dependencies: []*latestV1.ArtifactDependency{{ImageName: "img4"}}, ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{Target: "target2"}}}, - {ImageName: "img3", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{Target: "target3"}}}, - {ImageName: "img4", ArtifactType: latestV1.ArtifactType{BuildpackArtifact: &latestV1.BuildpackArtifact{}}}, + artifacts: []*latest.Artifact{ + {ImageName: "img1", Dependencies: []*latest.ArtifactDependency{{ImageName: "img2"}, {ImageName: "img3"}}}, + {ImageName: "img2", Dependencies: []*latest.ArtifactDependency{{ImageName: "img4"}}, ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{Target: "target2"}}}, + {ImageName: "img3", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{Target: "target3"}}}, + {ImageName: "img4", ArtifactType: latest.ArtifactType{BuildpackArtifact: &latest.BuildpackArtifact{}}}, }, fileDeps: map[string][]string{"img1": {"a"}, "img2": {"b"}, "img3": {"c"}, "img4": {"e"}}, mode: config.RunModes.Dev, @@ -241,7 +241,7 @@ func TestGetHashForArtifactWithDependencies(t *testing.T) { } } - depLister := func(_ context.Context, a *latestV1.Artifact) ([]string, error) { + depLister := func(_ context.Context, a *latest.Artifact) ([]string, error) { return test.fileDeps[a.ImageName], nil } @@ -255,18 +255,18 @@ func TestGetHashForArtifactWithDependencies(t *testing.T) { func TestArtifactConfig(t *testing.T) { testutil.Run(t, "", func(t *testutil.T) { - config1, err := artifactConfig(&latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + config1, err := artifactConfig(&latest.Artifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ Target: "target", }, }, }) t.CheckNoError(err) - config2, err := artifactConfig(&latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + config2, err := artifactConfig(&latest.Artifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ Target: "other", }, }, @@ -297,10 +297,10 @@ func TestBuildArgs(t *testing.T) { testutil.Run(t, "", func(t *testutil.T) { tmpDir := t.NewTempDir() tmpDir.Write("./Dockerfile", "ARG SKAFFOLD_GO_GCFLAGS\nFROM foo") - artifact := &latestV1.Artifact{ + artifact := &latest.Artifact{ Workspace: tmpDir.Path("."), - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: Dockerfile, BuildArgs: map[string]*string{"one": util.StringPtr("1"), "two": util.StringPtr("2")}, }, @@ -341,10 +341,10 @@ func TestBuildArgsEnvSubstitution(t *testing.T) { } tmpDir := t.NewTempDir() tmpDir.Write("./Dockerfile", "ARG SKAFFOLD_GO_GCFLAGS\nFROM foo") - artifact := &latestV1.Artifact{ + artifact := &latest.Artifact{ Workspace: tmpDir.Path("."), - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ BuildArgs: map[string]*string{"env": util.StringPtr("${{.FOO}}")}, DockerfilePath: Dockerfile, }, @@ -422,7 +422,7 @@ func TestCacheHasher(t *testing.T) { path := originalFile depLister := stubDependencyLister([]string{tmpDir.Path(originalFile)}) - oldHash, err := newArtifactHasher(nil, depLister, config.RunModes.Build).hash(context.Background(), &latestV1.Artifact{}, platform.Resolver{}) + oldHash, err := newArtifactHasher(nil, depLister, config.RunModes.Build).hash(context.Background(), &latest.Artifact{}, platform.Resolver{}) t.CheckNoError(err) test.update(originalFile, tmpDir) @@ -431,7 +431,7 @@ func TestCacheHasher(t *testing.T) { } depLister = stubDependencyLister([]string{tmpDir.Path(path)}) - newHash, err := newArtifactHasher(nil, depLister, config.RunModes.Build).hash(context.Background(), &latestV1.Artifact{}, platform.Resolver{}) + newHash, err := newArtifactHasher(nil, depLister, config.RunModes.Build).hash(context.Background(), &latest.Artifact{}, platform.Resolver{}) t.CheckNoError(err) t.CheckFalse(test.differentHash && oldHash == newHash) @@ -443,14 +443,14 @@ func TestCacheHasher(t *testing.T) { func TestHashBuildArgs(t *testing.T) { tests := []struct { description string - artifactType latestV1.ArtifactType + artifactType latest.ArtifactType expected []string mode config.RunMode }{ { description: "docker artifact with build args for dev", - artifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + artifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ BuildArgs: map[string]*string{ "foo": util.StringPtr("bar"), }, @@ -460,8 +460,8 @@ func TestHashBuildArgs(t *testing.T) { expected: []string{"foo=bar"}, }, { description: "docker artifact with build args for debug", - artifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + artifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ BuildArgs: map[string]*string{ "foo": util.StringPtr("bar"), }, @@ -471,34 +471,34 @@ func TestHashBuildArgs(t *testing.T) { expected: []string{"SKAFFOLD_GO_GCFLAGS=all=-N -l", "foo=bar"}, }, { description: "docker artifact without build args for debug", - artifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, + artifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, }, mode: config.RunModes.Debug, expected: []string{"SKAFFOLD_GO_GCFLAGS=all=-N -l"}, }, { description: "docker artifact without build args for dev", - artifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, + artifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, }, mode: config.RunModes.Dev, }, { description: "kaniko artifact with build args", - artifactType: latestV1.ArtifactType{ - KanikoArtifact: &latestV1.KanikoArtifact{ + artifactType: latest.ArtifactType{ + KanikoArtifact: &latest.KanikoArtifact{ BuildArgs: map[string]*string{}, }, }, expected: nil, }, { description: "kaniko artifact without build args", - artifactType: latestV1.ArtifactType{ - KanikoArtifact: &latestV1.KanikoArtifact{}, + artifactType: latest.ArtifactType{ + KanikoArtifact: &latest.KanikoArtifact{}, }, }, { description: "buildpacks artifact with env for dev", - artifactType: latestV1.ArtifactType{ - BuildpackArtifact: &latestV1.BuildpackArtifact{ + artifactType: latest.ArtifactType{ + BuildpackArtifact: &latest.BuildpackArtifact{ Env: []string{"foo=bar"}, }, }, @@ -506,14 +506,14 @@ func TestHashBuildArgs(t *testing.T) { expected: []string{"foo=bar"}, }, { description: "buildpacks artifact without env for dev", - artifactType: latestV1.ArtifactType{ - BuildpackArtifact: &latestV1.BuildpackArtifact{}, + artifactType: latest.ArtifactType{ + BuildpackArtifact: &latest.BuildpackArtifact{}, }, mode: config.RunModes.Dev, }, { description: "buildpacks artifact with env for debug", - artifactType: latestV1.ArtifactType{ - BuildpackArtifact: &latestV1.BuildpackArtifact{ + artifactType: latest.ArtifactType{ + BuildpackArtifact: &latest.BuildpackArtifact{ Env: []string{"foo=bar"}, }, }, @@ -521,17 +521,17 @@ func TestHashBuildArgs(t *testing.T) { expected: []string{"GOOGLE_GOGCFLAGS=all=-N -l", "foo=bar"}, }, { description: "buildpacks artifact without env for debug", - artifactType: latestV1.ArtifactType{ - BuildpackArtifact: &latestV1.BuildpackArtifact{}, + artifactType: latest.ArtifactType{ + BuildpackArtifact: &latest.BuildpackArtifact{}, }, mode: config.RunModes.Debug, expected: []string{"GOOGLE_GOGCFLAGS=all=-N -l"}, }, { description: "custom artifact, dockerfile dependency, with build args", - artifactType: latestV1.ArtifactType{ - CustomArtifact: &latestV1.CustomArtifact{ - Dependencies: &latestV1.CustomDependencies{ - Dockerfile: &latestV1.DockerfileDependency{ + artifactType: latest.ArtifactType{ + CustomArtifact: &latest.CustomArtifact{ + Dependencies: &latest.CustomDependencies{ + Dockerfile: &latest.DockerfileDependency{ BuildArgs: map[string]*string{}, }, }, @@ -540,9 +540,9 @@ func TestHashBuildArgs(t *testing.T) { expected: nil, }, { description: "custom artifact, no dockerfile dependency", - artifactType: latestV1.ArtifactType{ - CustomArtifact: &latestV1.CustomArtifact{ - Dependencies: &latestV1.CustomDependencies{}, + artifactType: latest.ArtifactType{ + CustomArtifact: &latest.CustomArtifact{ + Dependencies: &latest.CustomDependencies{}, }, }, }, @@ -550,7 +550,7 @@ func TestHashBuildArgs(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - a := &latestV1.Artifact{ + a := &latest.Artifact{ ArtifactType: test.artifactType, } if test.artifactType.DockerArtifact != nil { diff --git a/pkg/skaffold/build/cache/lookup.go b/pkg/skaffold/build/cache/lookup.go index 9bf534f1522..1cd308f27a1 100644 --- a/pkg/skaffold/build/cache/lookup.go +++ b/pkg/skaffold/build/cache/lookup.go @@ -26,11 +26,11 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/instrumentation" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/tag" ) -func (c *cache) lookupArtifacts(ctx context.Context, tags tag.ImageTags, platforms platform.Resolver, artifacts []*latestV1.Artifact) []cacheDetails { +func (c *cache) lookupArtifacts(ctx context.Context, tags tag.ImageTags, platforms platform.Resolver, artifacts []*latest.Artifact) []cacheDetails { details := make([]cacheDetails, len(artifacts)) // Create a new `artifactHasher` on every new dev loop. // This way every artifact hash is calculated at most once in a single dev loop, and recalculated on every dev loop. @@ -53,7 +53,7 @@ func (c *cache) lookupArtifacts(ctx context.Context, tags tag.ImageTags, platfor return details } -func (c *cache) lookup(ctx context.Context, a *latestV1.Artifact, tag string, platforms platform.Resolver, h artifactHasher) cacheDetails { +func (c *cache) lookup(ctx context.Context, a *latest.Artifact, tag string, platforms platform.Resolver, h artifactHasher) cacheDetails { ctx, endTrace := instrumentation.StartTrace(ctx, "lookup_CacheLookupOneArtifact", map[string]string{ "ImageName": instrumentation.PII(a.ImageName), }) @@ -131,7 +131,7 @@ func (c *cache) lookupRemote(ctx context.Context, hash, tag string, entry ImageD return needsBuilding{hash: hash} } -func (c *cache) tryImport(ctx context.Context, a *latestV1.Artifact, tag string, hash string) (ImageDetails, error) { +func (c *cache) tryImport(ctx context.Context, a *latest.Artifact, tag string, hash string) (ImageDetails, error) { entry := ImageDetails{} if importMissing, err := c.importMissingImage(a.ImageName); err != nil { diff --git a/pkg/skaffold/build/cache/lookup_test.go b/pkg/skaffold/build/cache/lookup_test.go index 62da311f420..16931decfb6 100644 --- a/pkg/skaffold/build/cache/lookup_test.go +++ b/pkg/skaffold/build/cache/lookup_test.go @@ -30,7 +30,7 @@ import ( sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/proto/v1" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -127,7 +127,7 @@ func TestLookupLocal(t *testing.T) { } t.Override(&newArtifactHasherFunc, func(_ graph.ArtifactGraph, _ DependencyLister, _ config.RunMode) artifactHasher { return test.hasher }) - details := cache.lookupArtifacts(context.Background(), map[string]string{"artifact": "tag"}, platform.Resolver{}, []*latestV1.Artifact{{ + details := cache.lookupArtifacts(context.Background(), map[string]string{"artifact": "tag"}, platform.Resolver{}, []*latest.Artifact{{ ImageName: "artifact", }}) @@ -215,7 +215,7 @@ func TestLookupRemote(t *testing.T) { cfg: &mockConfig{mode: config.RunModes.Build}, } t.Override(&newArtifactHasherFunc, func(_ graph.ArtifactGraph, _ DependencyLister, _ config.RunMode) artifactHasher { return test.hasher }) - details := cache.lookupArtifacts(context.Background(), map[string]string{"artifact": "tag"}, platform.Resolver{}, []*latestV1.Artifact{{ + details := cache.lookupArtifacts(context.Background(), map[string]string{"artifact": "tag"}, platform.Resolver{}, []*latest.Artifact{{ ImageName: "artifact", }}) @@ -231,7 +231,7 @@ type mockHasher struct { val string } -func (m mockHasher) hash(context.Context, *latestV1.Artifact, platform.Resolver) (string, error) { +func (m mockHasher) hash(context.Context, *latest.Artifact, platform.Resolver) (string, error) { return m.val, nil } @@ -239,7 +239,7 @@ type failingHasher struct { err error } -func (f failingHasher) hash(context.Context, *latestV1.Artifact, platform.Resolver) (string, error) { +func (f failingHasher) hash(context.Context, *latest.Artifact, platform.Resolver) (string, error) { return "", f.err } diff --git a/pkg/skaffold/build/cache/retrieve.go b/pkg/skaffold/build/cache/retrieve.go index 691ac75460e..7671c615eed 100644 --- a/pkg/skaffold/build/cache/retrieve.go +++ b/pkg/skaffold/build/cache/retrieve.go @@ -32,12 +32,12 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/tag" timeutil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/time" ) -func (c *cache) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latestV1.Artifact, platforms platform.Resolver, buildAndTest BuildAndTestFn) ([]graph.Artifact, error) { +func (c *cache) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latest.Artifact, platforms platform.Resolver, buildAndTest BuildAndTestFn) ([]graph.Artifact, error) { ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -58,7 +58,7 @@ func (c *cache) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, ar } hashByName := make(map[string]string) - var needToBuild []*latestV1.Artifact + var needToBuild []*latest.Artifact var alreadyBuilt []graph.Artifact for i, artifact := range artifacts { eventV2.CacheCheckInProgress(artifact.ImageName) @@ -160,7 +160,7 @@ func (c *cache) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, ar return maintainArtifactOrder(append(bRes, alreadyBuilt...), artifacts), err } -func maintainArtifactOrder(built []graph.Artifact, artifacts []*latestV1.Artifact) []graph.Artifact { +func maintainArtifactOrder(built []graph.Artifact, artifacts []*latest.Artifact) []graph.Artifact { byName := make(map[string]graph.Artifact) for _, build := range built { byName[build.ImageName] = build diff --git a/pkg/skaffold/build/cache/retrieve_test.go b/pkg/skaffold/build/cache/retrieve_test.go index 73e8bc75ac4..104591e5ea5 100644 --- a/pkg/skaffold/build/cache/retrieve_test.go +++ b/pkg/skaffold/build/cache/retrieve_test.go @@ -31,13 +31,13 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/tag" "github.com/GoogleContainerTools/skaffold/testutil" ) func depLister(files map[string][]string) DependencyLister { - return func(_ context.Context, artifact *latestV1.Artifact) ([]string, error) { + return func(_ context.Context, artifact *latest.Artifact) ([]string, error) { list, found := files[artifact.ImageName] if !found { return nil, errors.New("unknown artifact") @@ -49,19 +49,19 @@ func depLister(files map[string][]string) DependencyLister { type mockArtifactStore map[string]string func (m mockArtifactStore) GetImageTag(imageName string) (string, bool) { return m[imageName], true } -func (m mockArtifactStore) Record(a *latestV1.Artifact, tag string) { m[a.ImageName] = tag } -func (m mockArtifactStore) GetArtifacts([]*latestV1.Artifact) ([]graph.Artifact, error) { +func (m mockArtifactStore) Record(a *latest.Artifact, tag string) { m[a.ImageName] = tag } +func (m mockArtifactStore) GetArtifacts([]*latest.Artifact) ([]graph.Artifact, error) { return nil, nil } type mockBuilder struct { - built []*latestV1.Artifact + built []*latest.Artifact push bool dockerDaemon docker.LocalDaemon store build.ArtifactStore } -func (b *mockBuilder) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latestV1.Artifact, _ platform.Resolver) ([]graph.Artifact, error) { +func (b *mockBuilder) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latest.Artifact, _ platform.Resolver) ([]graph.Artifact, error) { var built []graph.Artifact for _, artifact := range artifacts { @@ -116,9 +116,9 @@ func TestCacheBuildLocal(t *testing.T) { "artifact1": "artifact1:tag1", "artifact2": "artifact2:tag2", } - artifacts := []*latestV1.Artifact{ - {ImageName: "artifact1", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{}}}, - {ImageName: "artifact2", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{}}}, + artifacts := []*latest.Artifact{ + {ImageName: "artifact1", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, + {ImageName: "artifact2", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, } deps := depLister(map[string][]string{ "artifact1": {"dep1", "dep2"}, @@ -139,7 +139,7 @@ func TestCacheBuildLocal(t *testing.T) { // Create cache cfg := &mockConfig{ - pipeline: latestV1.Pipeline{Build: latestV1.BuildConfig{BuildType: latestV1.BuildType{LocalBuild: &latestV1.LocalBuild{TryImportMissing: false}}}}, + pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{TryImportMissing: false}}}}, cacheFile: tmpDir.Path("cache"), } store := make(mockArtifactStore) @@ -203,9 +203,9 @@ func TestCacheBuildRemote(t *testing.T) { "artifact1": "artifact1:tag1", "artifact2": "artifact2:tag2", } - artifacts := []*latestV1.Artifact{ - {ImageName: "artifact1", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{}}}, - {ImageName: "artifact2", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{}}}, + artifacts := []*latest.Artifact{ + {ImageName: "artifact1", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, + {ImageName: "artifact2", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, } deps := depLister(map[string][]string{ "artifact1": {"dep1", "dep2"}, @@ -236,7 +236,7 @@ func TestCacheBuildRemote(t *testing.T) { // Create cache cfg := &mockConfig{ - pipeline: latestV1.Pipeline{Build: latestV1.BuildConfig{BuildType: latestV1.BuildType{LocalBuild: &latestV1.LocalBuild{TryImportMissing: false}}}}, + pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{TryImportMissing: false}}}}, cacheFile: tmpDir.Path("cache"), } artifactCache, err := NewCache(context.Background(), cfg, func(imageName string) (bool, error) { return false, nil }, deps, graph.ToArtifactGraph(artifacts), make(mockArtifactStore)) @@ -288,9 +288,9 @@ func TestCacheFindMissing(t *testing.T) { "artifact1": "artifact1:tag1", "artifact2": "artifact2:tag2", } - artifacts := []*latestV1.Artifact{ - {ImageName: "artifact1", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{}}}, - {ImageName: "artifact2", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{}}}, + artifacts := []*latest.Artifact{ + {ImageName: "artifact1", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, + {ImageName: "artifact2", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, } deps := depLister(map[string][]string{ "artifact1": {"dep1", "dep2"}, @@ -321,7 +321,7 @@ func TestCacheFindMissing(t *testing.T) { // Create cache cfg := &mockConfig{ - pipeline: latestV1.Pipeline{Build: latestV1.BuildConfig{BuildType: latestV1.BuildType{LocalBuild: &latestV1.LocalBuild{TryImportMissing: true}}}}, + pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{TryImportMissing: true}}}}, cacheFile: tmpDir.Path("cache"), } artifactCache, err := NewCache(context.Background(), cfg, func(imageName string) (bool, error) { return false, nil }, deps, graph.ToArtifactGraph(artifacts), make(mockArtifactStore)) @@ -344,10 +344,10 @@ type mockConfig struct { runcontext.RunContext // Embedded to provide the default values. cacheFile string mode config.RunMode - pipeline latestV1.Pipeline + pipeline latest.Pipeline } -func (c *mockConfig) CacheArtifacts() bool { return true } -func (c *mockConfig) CacheFile() string { return c.cacheFile } -func (c *mockConfig) Mode() config.RunMode { return c.mode } -func (c *mockConfig) PipelineForImage(string) (latestV1.Pipeline, bool) { return c.pipeline, true } +func (c *mockConfig) CacheArtifacts() bool { return true } +func (c *mockConfig) CacheFile() string { return c.cacheFile } +func (c *mockConfig) Mode() config.RunMode { return c.mode } +func (c *mockConfig) PipelineForImage(string) (latest.Pipeline, bool) { return c.pipeline, true } diff --git a/pkg/skaffold/build/cache/types.go b/pkg/skaffold/build/cache/types.go index 4440361deb8..276c106ee32 100644 --- a/pkg/skaffold/build/cache/types.go +++ b/pkg/skaffold/build/cache/types.go @@ -22,18 +22,18 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/tag" ) -type BuildAndTestFn func(context.Context, io.Writer, tag.ImageTags, []*latestV1.Artifact, platform.Resolver) ([]graph.Artifact, error) +type BuildAndTestFn func(context.Context, io.Writer, tag.ImageTags, []*latest.Artifact, platform.Resolver) ([]graph.Artifact, error) type Cache interface { - Build(context.Context, io.Writer, tag.ImageTags, []*latestV1.Artifact, platform.Resolver, BuildAndTestFn) ([]graph.Artifact, error) + Build(context.Context, io.Writer, tag.ImageTags, []*latest.Artifact, platform.Resolver, BuildAndTestFn) ([]graph.Artifact, error) } type noCache struct{} -func (n *noCache) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latestV1.Artifact, platforms platform.Resolver, buildAndTest BuildAndTestFn) ([]graph.Artifact, error) { +func (n *noCache) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latest.Artifact, platforms platform.Resolver, buildAndTest BuildAndTestFn) ([]graph.Artifact, error) { return buildAndTest(ctx, out, tags, artifacts, platforms) } diff --git a/pkg/skaffold/build/cluster/cluster.go b/pkg/skaffold/build/cluster/cluster.go index 242abf2ab72..224bb1037be 100644 --- a/pkg/skaffold/build/cluster/cluster.go +++ b/pkg/skaffold/build/cluster/cluster.go @@ -27,12 +27,12 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) // Build builds a list of artifacts with Kaniko. -func (b *Builder) Build(ctx context.Context, out io.Writer, artifact *latestV1.Artifact) build.ArtifactBuilder { +func (b *Builder) Build(ctx context.Context, out io.Writer, artifact *latest.Artifact) build.ArtifactBuilder { builder := build.WithLogFile(b.buildArtifact, b.cfg.Muted()) return builder } @@ -61,7 +61,7 @@ func (b *Builder) PostBuild(_ context.Context, _ io.Writer) error { return nil } -func (b *Builder) buildArtifact(ctx context.Context, out io.Writer, artifact *latestV1.Artifact, tag string, m platform.Matcher) (string, error) { +func (b *Builder) buildArtifact(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string, m platform.Matcher) (string, error) { digest, err := b.runBuildForArtifact(ctx, out, artifact, tag, m) if err != nil { return "", err @@ -74,7 +74,7 @@ func (b *Builder) Concurrency() *int { return util.IntPtr(b.ClusterDetails.Concurrency) } -func (b *Builder) runBuildForArtifact(ctx context.Context, out io.Writer, a *latestV1.Artifact, tag string, platforms platform.Matcher) (string, error) { +func (b *Builder) runBuildForArtifact(ctx context.Context, out io.Writer, a *latest.Artifact, tag string, platforms platform.Matcher) (string, error) { // required artifacts as build-args requiredImages := docker.ResolveDependencyImages(a.Dependencies, b.artifactStore, true) switch { diff --git a/pkg/skaffold/build/cluster/cluster_test.go b/pkg/skaffold/build/cluster/cluster_test.go index 88fe3d10ff9..b225cb3a953 100644 --- a/pkg/skaffold/build/cluster/cluster_test.go +++ b/pkg/skaffold/build/cluster/cluster_test.go @@ -19,7 +19,7 @@ package cluster import ( "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -27,10 +27,10 @@ func TestRetrieveEnv(t *testing.T) { builder, err := NewBuilder(&mockBuilderContext{ kubeContext: "kubecontext", namespace: "test-namespace", - }, &latestV1.ClusterDetails{ + }, &latest.ClusterDetails{ Namespace: "namespace", PullSecretName: "pullSecret", - DockerConfig: &latestV1.DockerConfig{ + DockerConfig: &latest.DockerConfig{ SecretName: "dockerconfig", }, Timeout: "2m", @@ -43,7 +43,7 @@ func TestRetrieveEnv(t *testing.T) { } func TestRetrieveEnvMinimal(t *testing.T) { - builder, err := NewBuilder(&mockBuilderContext{}, &latestV1.ClusterDetails{ + builder, err := NewBuilder(&mockBuilderContext{}, &latest.ClusterDetails{ Timeout: "20m", }) testutil.CheckError(t, false, err) diff --git a/pkg/skaffold/build/cluster/kaniko.go b/pkg/skaffold/build/cluster/kaniko.go index 7446a63dfa1..9129018fa95 100644 --- a/pkg/skaffold/build/cluster/kaniko.go +++ b/pkg/skaffold/build/cluster/kaniko.go @@ -32,13 +32,13 @@ import ( kubernetesclient "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) const initContainer = "kaniko-init-container" -func (b *Builder) buildWithKaniko(ctx context.Context, out io.Writer, workspace string, artifactName string, artifact *latestV1.KanikoArtifact, tag string, requiredImages map[string]*string, platforms platform.Matcher) (string, error) { +func (b *Builder) buildWithKaniko(ctx context.Context, out io.Writer, workspace string, artifactName string, artifact *latest.KanikoArtifact, tag string, requiredImages map[string]*string, platforms platform.Matcher) (string, error) { // TODO: Implement building multi-platform images for cluster builder if platforms.IsMultiPlatform() { log.Entry(ctx).Warnf("multiple target platforms %q found for artifact %q. Skaffold doesn't yet support multi-platform builds for the docker builder. Consider specifying a single target platform explicitly. See https://skaffold.dev/docs/pipeline-stages/builders/#cross-platform-build-support", platforms.String(), artifactName) @@ -103,7 +103,7 @@ func (b *Builder) buildWithKaniko(ctx context.Context, out io.Writer, workspace // first copy over the buildcontext tarball into the init container tmp dir via kubectl cp // Via kubectl exec, we extract the tarball to the empty dir // Then, via kubectl exec, create the /tmp/complete file via kubectl exec to complete the init container -func (b *Builder) copyKanikoBuildContext(ctx context.Context, workspace string, artifactName string, artifact *latestV1.KanikoArtifact, pods corev1.PodInterface, podName string) error { +func (b *Builder) copyKanikoBuildContext(ctx context.Context, workspace string, artifactName string, artifact *latest.KanikoArtifact, pods corev1.PodInterface, podName string) error { if err := kubernetes.WaitForPodInitialized(ctx, pods, podName); err != nil { return fmt.Errorf("waiting for pod to initialize: %w", err) } diff --git a/pkg/skaffold/build/cluster/kaniko_test.go b/pkg/skaffold/build/cluster/kaniko_test.go index 1c6bf03a361..750aabf0902 100644 --- a/pkg/skaffold/build/cluster/kaniko_test.go +++ b/pkg/skaffold/build/cluster/kaniko_test.go @@ -21,13 +21,13 @@ import ( v1 "k8s.io/api/core/v1" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) func TestEnvInterpolation(t *testing.T) { imageStr := "why.com/is/this/such/a/long/repo/name/testimage:testtag" - artifact := &latestV1.KanikoArtifact{ + artifact := &latest.KanikoArtifact{ Env: []v1.EnvVar{{Name: "hui", Value: "buh"}}, } generatedEnvs, err := generateEnvFromImage(imageStr) @@ -51,7 +51,7 @@ func TestEnvInterpolation(t *testing.T) { func TestEnvInterpolation_IPPort(t *testing.T) { imageStr := "10.10.10.10:1000/is/this/such/a/long/repo/name/testimage:testtag" - artifact := &latestV1.KanikoArtifact{ + artifact := &latest.KanikoArtifact{ Env: []v1.EnvVar{{Name: "hui", Value: "buh"}}, } generatedEnvs, err := generateEnvFromImage(imageStr) @@ -75,7 +75,7 @@ func TestEnvInterpolation_IPPort(t *testing.T) { func TestEnvInterpolation_Latest(t *testing.T) { imageStr := "why.com/is/this/such/a/long/repo/name/testimage" - artifact := &latestV1.KanikoArtifact{ + artifact := &latest.KanikoArtifact{ Env: []v1.EnvVar{{Name: "hui", Value: "buh"}}, } generatedEnvs, err := generateEnvFromImage(imageStr) diff --git a/pkg/skaffold/build/cluster/pod.go b/pkg/skaffold/build/cluster/pod.go index 76d1dbad842..ed2c954ba23 100644 --- a/pkg/skaffold/build/cluster/pod.go +++ b/pkg/skaffold/build/cluster/pod.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/kaniko" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/version" ) @@ -38,7 +38,7 @@ const ( nodeArchitectureLabel = "kubernetes.io/arch" ) -func (b *Builder) kanikoPodSpec(artifact *latestV1.KanikoArtifact, tag string, platforms platform.Matcher) (*v1.Pod, error) { +func (b *Builder) kanikoPodSpec(artifact *latest.KanikoArtifact, tag string, platforms platform.Matcher) (*v1.Pod, error) { args, err := kanikoArgs(artifact, tag, b.cfg.GetInsecureRegistries()) if err != nil { return nil, fmt.Errorf("building args list: %w", err) @@ -148,7 +148,7 @@ func (b *Builder) kanikoPodSpec(artifact *latestV1.KanikoArtifact, tag string, p return pod, nil } -func (b *Builder) env(artifact *latestV1.KanikoArtifact, httpProxy, httpsProxy string) []v1.EnvVar { +func (b *Builder) env(artifact *latest.KanikoArtifact, httpProxy, httpsProxy string) []v1.EnvVar { env := []v1.EnvVar{{ // This should be same https://github.com/GoogleContainerTools/kaniko/blob/77cfb912f3483c204bfd09e1ada44fd200b15a78/pkg/executor/push.go#L49 Name: "UPSTREAM_CLIENT_TYPE", @@ -222,7 +222,7 @@ func addHostPathVolume(pod *v1.Pod, name, mountPath, path string) { }) } -func resourceRequirements(rr *latestV1.ResourceRequirements) v1.ResourceRequirements { +func resourceRequirements(rr *latest.ResourceRequirements) v1.ResourceRequirements { req := v1.ResourceRequirements{} if rr != nil { @@ -265,7 +265,7 @@ func resourceRequirements(rr *latestV1.ResourceRequirements) v1.ResourceRequirem return req } -func kanikoArgs(artifact *latestV1.KanikoArtifact, tag string, insecureRegistries map[string]bool) ([]string, error) { +func kanikoArgs(artifact *latest.KanikoArtifact, tag string, insecureRegistries map[string]bool) ([]string, error) { for reg := range insecureRegistries { artifact.InsecureRegistry = append(artifact.InsecureRegistry, reg) } diff --git a/pkg/skaffold/build/cluster/pod_test.go b/pkg/skaffold/build/cluster/pod_test.go index ce35f4cf0ff..c9d03bf7a81 100644 --- a/pkg/skaffold/build/cluster/pod_test.go +++ b/pkg/skaffold/build/cluster/pod_test.go @@ -26,7 +26,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/kaniko" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -34,7 +34,7 @@ import ( func TestKanikoArgs(t *testing.T) { tests := []struct { description string - artifact *latestV1.KanikoArtifact + artifact *latest.KanikoArtifact insecureRegistries map[string]bool tag string shouldErr bool @@ -42,24 +42,24 @@ func TestKanikoArgs(t *testing.T) { }{ { description: "simple build", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", }, expectedArgs: []string{}, }, { description: "cache layers", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", - Cache: &latestV1.KanikoCache{}, + Cache: &latest.KanikoCache{}, }, expectedArgs: []string{kaniko.CacheFlag}, }, { description: "cache layers to specific repo", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", - Cache: &latestV1.KanikoCache{ + Cache: &latest.KanikoCache{ Repo: "repo", }, }, @@ -67,9 +67,9 @@ func TestKanikoArgs(t *testing.T) { }, { description: "cache path", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", - Cache: &latestV1.KanikoCache{ + Cache: &latest.KanikoCache{ HostPath: "/cache", }, }, @@ -79,7 +79,7 @@ func TestKanikoArgs(t *testing.T) { }, { description: "target", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", Target: "target", }, @@ -87,7 +87,7 @@ func TestKanikoArgs(t *testing.T) { }, { description: "reproducible", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", Reproducible: true, }, @@ -95,7 +95,7 @@ func TestKanikoArgs(t *testing.T) { }, { description: "build args", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", BuildArgs: map[string]*string{ "nil_key": nil, @@ -110,7 +110,7 @@ func TestKanikoArgs(t *testing.T) { }, { description: "invalid build args", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", BuildArgs: map[string]*string{ "invalid": util.StringPtr("{{Invalid"), @@ -120,7 +120,7 @@ func TestKanikoArgs(t *testing.T) { }, { description: "insecure registries", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", }, insecureRegistries: map[string]bool{"localhost:4000": true}, @@ -128,7 +128,7 @@ func TestKanikoArgs(t *testing.T) { }, { description: "skip tls", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", SkipTLS: true, }, @@ -139,7 +139,7 @@ func TestKanikoArgs(t *testing.T) { }, { description: "invalid registry", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", SkipTLS: true, }, @@ -166,7 +166,7 @@ func TestKanikoArgs(t *testing.T) { } func TestKanikoPodSpec(t *testing.T) { - artifact := &latestV1.KanikoArtifact{ + artifact := &latest.KanikoArtifact{ Image: "image", DockerfilePath: "Dockerfile", InitImage: "init/image", @@ -194,7 +194,7 @@ func TestKanikoPodSpec(t *testing.T) { builder := &Builder{ cfg: &mockBuilderContext{}, - ClusterDetails: &latestV1.ClusterDetails{ + ClusterDetails: &latest.ClusterDetails{ Namespace: "ns", PullSecretName: "secret", PullSecretPath: "kaniko-secret.json", @@ -203,11 +203,11 @@ func TestKanikoPodSpec(t *testing.T) { HTTPSProxy: "https://proxy", ServiceAccountName: "aVerySpecialSA", RunAsUser: &runAsUser, - Resources: &latestV1.ResourceRequirements{ - Requests: &latestV1.ResourceRequirement{ + Resources: &latest.ResourceRequirements{ + Requests: &latest.ResourceRequirement{ CPU: "0.1", }, - Limits: &latestV1.ResourceRequirement{ + Limits: &latest.ResourceRequirement{ CPU: "0.5", }, }, @@ -391,24 +391,24 @@ func TestKanikoPodSpec(t *testing.T) { func TestResourceRequirements(t *testing.T) { tests := []struct { description string - initial *latestV1.ResourceRequirements + initial *latest.ResourceRequirements expected v1.ResourceRequirements }{ { description: "no resource specified", - initial: &latestV1.ResourceRequirements{}, + initial: &latest.ResourceRequirements{}, expected: v1.ResourceRequirements{}, }, { description: "with resource specified", - initial: &latestV1.ResourceRequirements{ - Requests: &latestV1.ResourceRequirement{ + initial: &latest.ResourceRequirements{ + Requests: &latest.ResourceRequirement{ CPU: "0.5", Memory: "1000", ResourceStorage: "1000", EphemeralStorage: "1000", }, - Limits: &latestV1.ResourceRequirement{ + Limits: &latest.ResourceRequirement{ CPU: "1.0", Memory: "2000", ResourceStorage: "1000", diff --git a/pkg/skaffold/build/cluster/secret_test.go b/pkg/skaffold/build/cluster/secret_test.go index 7c7dce5bddb..994a3cc9d4b 100644 --- a/pkg/skaffold/build/cluster/secret_test.go +++ b/pkg/skaffold/build/cluster/secret_test.go @@ -27,7 +27,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -39,7 +39,7 @@ func TestCreateSecret(t *testing.T) { return fakeKubernetesclient, nil }) - builder, err := NewBuilder(&mockBuilderContext{}, &latestV1.ClusterDetails{ + builder, err := NewBuilder(&mockBuilderContext{}, &latest.ClusterDetails{ Timeout: "20m", PullSecretName: "kaniko-secret", PullSecretPath: tmpDir.Path("secret.json"), @@ -70,7 +70,7 @@ func TestExistingSecretNotFound(t *testing.T) { return fake.NewSimpleClientset(), nil }) - builder, err := NewBuilder(&mockBuilderContext{}, &latestV1.ClusterDetails{ + builder, err := NewBuilder(&mockBuilderContext{}, &latest.ClusterDetails{ Timeout: "20m", PullSecretName: "kaniko-secret", }) @@ -93,7 +93,7 @@ func TestExistingSecret(t *testing.T) { }), nil }) - builder, err := NewBuilder(&mockBuilderContext{}, &latestV1.ClusterDetails{ + builder, err := NewBuilder(&mockBuilderContext{}, &latest.ClusterDetails{ Timeout: "20m", PullSecretName: "kaniko-secret", }) @@ -113,7 +113,7 @@ func TestSkipSecretCreation(t *testing.T) { return nil, nil }) - builder, err := NewBuilder(&mockBuilderContext{}, &latestV1.ClusterDetails{ + builder, err := NewBuilder(&mockBuilderContext{}, &latest.ClusterDetails{ Timeout: "20m", }) t.CheckNoError(err) diff --git a/pkg/skaffold/build/cluster/types.go b/pkg/skaffold/build/cluster/types.go index 562247dfb43..fdd65f0154b 100644 --- a/pkg/skaffold/build/cluster/types.go +++ b/pkg/skaffold/build/cluster/types.go @@ -27,12 +27,12 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // Builder builds docker artifacts on Kubernetes. type Builder struct { - *latestV1.ClusterDetails + *latest.ClusterDetails cfg Config kubectlcli *kubectl.CLI @@ -59,7 +59,7 @@ type BuilderContext interface { } // NewBuilder creates a new Builder that builds artifacts on cluster. -func NewBuilder(bCtx BuilderContext, buildCfg *latestV1.ClusterDetails) (*Builder, error) { +func NewBuilder(bCtx BuilderContext, buildCfg *latest.ClusterDetails) (*Builder, error) { timeout, err := time.ParseDuration(buildCfg.Timeout) if err != nil { return nil, fmt.Errorf("parsing timeout: %w", err) diff --git a/pkg/skaffold/build/cluster/types_test.go b/pkg/skaffold/build/cluster/types_test.go index fcc9a97daff..429f6e699fe 100644 --- a/pkg/skaffold/build/cluster/types_test.go +++ b/pkg/skaffold/build/cluster/types_test.go @@ -23,7 +23,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" "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/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -37,12 +37,12 @@ func TestNewBuilder(t *testing.T) { description string shouldErr bool bCtx BuilderContext - cluster *latestV1.ClusterDetails + cluster *latest.ClusterDetails }{ { description: "failed to parse cluster build timeout", bCtx: &mockBuilderContext{}, - cluster: &latestV1.ClusterDetails{ + cluster: &latest.ClusterDetails{ Timeout: "illegal", }, shouldErr: true, @@ -53,7 +53,7 @@ func TestNewBuilder(t *testing.T) { kubeContext: kubeContext, namespace: namespace, }, - cluster: &latestV1.ClusterDetails{ + cluster: &latest.ClusterDetails{ Timeout: "100s", Namespace: "test-ns", }, @@ -65,7 +65,7 @@ func TestNewBuilder(t *testing.T) { namespace: namespace, insecureRegistries: map[string]bool{"insecure-reg1": true}, }, - cluster: &latestV1.ClusterDetails{ + cluster: &latest.ClusterDetails{ Timeout: "100s", Namespace: "test-ns", }, diff --git a/pkg/skaffold/build/custom/build.go b/pkg/skaffold/build/custom/build.go index 81474dcab95..da892605fd0 100644 --- a/pkg/skaffold/build/custom/build.go +++ b/pkg/skaffold/build/custom/build.go @@ -24,11 +24,11 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/instrumentation" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // Build builds an artifact using a custom script -func (b *Builder) Build(ctx context.Context, out io.Writer, artifact *latestV1.Artifact, tag string, platforms platform.Matcher) (string, error) { +func (b *Builder) Build(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string, platforms platform.Matcher) (string, error) { instrumentation.AddAttributesToCurrentSpanFromContext(ctx, map[string]string{ "BuildType": "custom", "Context": instrumentation.PII(artifact.Workspace), diff --git a/pkg/skaffold/build/custom/dependencies.go b/pkg/skaffold/build/custom/dependencies.go index 1aa4f9750ef..66e16a372c4 100644 --- a/pkg/skaffold/build/custom/dependencies.go +++ b/pkg/skaffold/build/custom/dependencies.go @@ -25,12 +25,12 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/list" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) // GetDependencies returns dependencies listed for a custom artifact -func GetDependencies(ctx context.Context, workspace string, artifactName string, a *latestV1.CustomArtifact, cfg docker.Config) ([]string, error) { +func GetDependencies(ctx context.Context, workspace string, artifactName string, a *latest.CustomArtifact, cfg docker.Config) ([]string, error) { switch { case a.Dependencies.Dockerfile != nil: return docker.GetDependencies(ctx, getDockerBuildConfig(workspace, artifactName, a), cfg) @@ -54,7 +54,7 @@ func GetDependencies(ctx context.Context, workspace string, artifactName string, } } -func getDockerBuildConfig(ws string, artifact string, a *latestV1.CustomArtifact) docker.BuildConfig { +func getDockerBuildConfig(ws string, artifact string, a *latest.CustomArtifact) docker.BuildConfig { dockerfile := a.Dependencies.Dockerfile return docker.NewBuildConfig(ws, artifact, dockerfile.Path, dockerfile.BuildArgs) } diff --git a/pkg/skaffold/build/custom/dependencies_test.go b/pkg/skaffold/build/custom/dependencies_test.go index ad332a8f3d9..f1bd06c4020 100644 --- a/pkg/skaffold/build/custom/dependencies_test.go +++ b/pkg/skaffold/build/custom/dependencies_test.go @@ -21,7 +21,7 @@ import ( "path/filepath" "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -38,9 +38,9 @@ func TestGetDependenciesDockerfile(t *testing.T) { tmpDir.Touch("foo", "bar", "baz/file") tmpDir.Write("Dockerfile", "FROM scratch \n ARG file \n COPY $file baz/file .") - customArtifact := &latestV1.CustomArtifact{ - Dependencies: &latestV1.CustomDependencies{ - Dockerfile: &latestV1.DockerfileDependency{ + customArtifact := &latest.CustomArtifact{ + Dependencies: &latest.CustomDependencies{ + Dockerfile: &latest.DockerfileDependency{ Path: "Dockerfile", BuildArgs: map[string]*string{ "file": util.StringPtr("foo"), @@ -65,8 +65,8 @@ func TestGetDependenciesCommand(t *testing.T) { "[\"file1\",\"file2\",\"file3\"]", )) - customArtifact := &latestV1.CustomArtifact{ - Dependencies: &latestV1.CustomDependencies{ + customArtifact := &latest.CustomArtifact{ + Dependencies: &latest.CustomDependencies{ Command: "echo [\"file1\",\"file2\",\"file3\"]", }, } @@ -122,8 +122,8 @@ func TestGetDependenciesPaths(t *testing.T) { tmpDir := t.NewTempDir(). Touch("foo", "bar", "baz/file") - deps, err := GetDependencies(context.Background(), tmpDir.Root(), "test", &latestV1.CustomArtifact{ - Dependencies: &latestV1.CustomDependencies{ + deps, err := GetDependencies(context.Background(), tmpDir.Root(), "test", &latest.CustomArtifact{ + Dependencies: &latest.CustomDependencies{ Paths: test.paths, Ignore: test.ignore, }, diff --git a/pkg/skaffold/build/custom/script.go b/pkg/skaffold/build/custom/script.go index 1c661e92c30..7f0ada5dba2 100644 --- a/pkg/skaffold/build/custom/script.go +++ b/pkg/skaffold/build/custom/script.go @@ -29,7 +29,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -38,7 +38,7 @@ var ( buildContext = retrieveBuildContext ) -func (b *Builder) runBuildScript(ctx context.Context, out io.Writer, a *latestV1.Artifact, tag string, platforms platform.Matcher) error { +func (b *Builder) runBuildScript(ctx context.Context, out io.Writer, a *latest.Artifact, tag string, platforms platform.Matcher) error { cmd, err := b.retrieveCmd(ctx, out, a, tag, platforms) if err != nil { return fmt.Errorf("retrieving cmd: %w", err) @@ -52,7 +52,7 @@ func (b *Builder) runBuildScript(ctx context.Context, out io.Writer, a *latestV1 return misc.HandleGracefulTermination(ctx, cmd) } -func (b *Builder) retrieveCmd(ctx context.Context, out io.Writer, a *latestV1.Artifact, tag string, platforms platform.Matcher) (*exec.Cmd, error) { +func (b *Builder) retrieveCmd(ctx context.Context, out io.Writer, a *latest.Artifact, tag string, platforms platform.Matcher) (*exec.Cmd, error) { artifact := a.CustomArtifact // Expand command @@ -87,7 +87,7 @@ func (b *Builder) retrieveCmd(ctx context.Context, out io.Writer, a *latestV1.Ar return cmd, nil } -func (b *Builder) retrieveEnv(a *latestV1.Artifact, tag string, platforms platform.Matcher) ([]string, error) { +func (b *Builder) retrieveEnv(a *latest.Artifact, tag string, platforms platform.Matcher) ([]string, error) { buildContext, err := buildContext(a.Workspace) if err != nil { return nil, fmt.Errorf("getting absolute path for artifact build context: %w", err) diff --git a/pkg/skaffold/build/custom/script_test.go b/pkg/skaffold/build/custom/script_test.go index 87012c498e6..dbc5e466afb 100644 --- a/pkg/skaffold/build/custom/script_test.go +++ b/pkg/skaffold/build/custom/script_test.go @@ -26,7 +26,7 @@ import ( v1 "github.com/opencontainers/image-spec/specs-go/v1" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -81,7 +81,7 @@ func TestRetrieveEnv(t *testing.T) { t.Override(&buildContext, func(string) (string, error) { return test.buildContext, nil }) builder := NewArtifactBuilder(nil, nil, test.pushImages, false, test.additionalEnv) - actual, err := builder.retrieveEnv(&latestV1.Artifact{}, test.tag, test.platforms) + actual, err := builder.retrieveEnv(&latest.Artifact{}, test.tag, test.platforms) t.CheckNoError(err) t.CheckDeepEqual(test.expected, actual) @@ -92,7 +92,7 @@ func TestRetrieveEnv(t *testing.T) { func TestRetrieveCmd(t *testing.T) { tests := []struct { description string - artifact *latestV1.Artifact + artifact *latest.Artifact tag string env []string expected *exec.Cmd @@ -100,10 +100,10 @@ func TestRetrieveCmd(t *testing.T) { }{ { description: "artifact with workspace set", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ Workspace: "workspace", - ArtifactType: latestV1.ArtifactType{ - CustomArtifact: &latestV1.CustomArtifact{ + ArtifactType: latest.ArtifactType{ + CustomArtifact: &latest.CustomArtifact{ BuildCommand: "./build.sh", }, }, @@ -114,9 +114,9 @@ func TestRetrieveCmd(t *testing.T) { }, { description: "buildcommand with multiple args", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - CustomArtifact: &latestV1.CustomArtifact{ + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + CustomArtifact: &latest.CustomArtifact{ BuildCommand: "./build.sh --flag=$IMAGES --anotherflag", }, }, @@ -127,9 +127,9 @@ func TestRetrieveCmd(t *testing.T) { }, { description: "buildcommand with go template", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - CustomArtifact: &latestV1.CustomArtifact{ + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + CustomArtifact: &latest.CustomArtifact{ BuildCommand: "./build.sh --flag={{ .FLAG }}", }, }, diff --git a/pkg/skaffold/build/docker/docker.go b/pkg/skaffold/build/docker/docker.go index 5bbe8f09ed0..843f1bbba1c 100644 --- a/pkg/skaffold/build/docker/docker.go +++ b/pkg/skaffold/build/docker/docker.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/warnings" @@ -38,7 +38,7 @@ func (b *Builder) SupportedPlatforms() platform.Matcher { return platform.All } -func (b *Builder) Build(ctx context.Context, out io.Writer, a *latestV1.Artifact, tag string, matcher platform.Matcher) (string, error) { +func (b *Builder) Build(ctx context.Context, out io.Writer, a *latest.Artifact, tag string, matcher platform.Matcher) (string, error) { a = adjustCacheFrom(a, tag) instrumentation.AddAttributesToCurrentSpanFromContext(ctx, map[string]string{ "BuildType": "docker", @@ -84,7 +84,7 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, a *latestV1.Artifact return imageID, nil } -func (b *Builder) dockerCLIBuild(ctx context.Context, out io.Writer, name string, workspace string, dockerfilePath string, a *latestV1.DockerArtifact, opts docker.BuildOptions, matcher platform.Matcher) (string, error) { +func (b *Builder) dockerCLIBuild(ctx context.Context, out io.Writer, name string, workspace string, dockerfilePath string, a *latest.DockerArtifact, opts docker.BuildOptions, matcher platform.Matcher) (string, error) { if matcher.IsMultiPlatform() { // TODO: implement multi platform build log.Entry(ctx).Warnf("multiple target platforms %q found for artifact %q. Skaffold doesn't yet support multi-platform builds for the docker builder. Consider specifying a single target platform explicitly. See https://skaffold.dev/docs/pipeline-stages/builders/#cross-platform-build-support", matcher.String(), name) @@ -131,7 +131,7 @@ func (b *Builder) dockerCLIBuild(ctx context.Context, out io.Writer, name string return b.localDocker.ImageID(ctx, opts.Tag) } -func (b *Builder) pullCacheFromImages(ctx context.Context, out io.Writer, a *latestV1.DockerArtifact) error { +func (b *Builder) pullCacheFromImages(ctx context.Context, out io.Writer, a *latest.DockerArtifact) error { if len(a.CacheFrom) == 0 { return nil } @@ -155,7 +155,7 @@ func (b *Builder) pullCacheFromImages(ctx context.Context, out io.Writer, a *lat } // adjustCacheFrom returns an artifact where any cache references from the artifactImage is changed to the tagged built image name instead. -func adjustCacheFrom(a *latestV1.Artifact, artifactTag string) *latestV1.Artifact { +func adjustCacheFrom(a *latest.Artifact, artifactTag string) *latest.Artifact { if os.Getenv("SKAFFOLD_DISABLE_DOCKER_CACHE_ADJUSTMENT") != "" { // allow this behaviour to be disabled return a diff --git a/pkg/skaffold/build/docker/docker_test.go b/pkg/skaffold/build/docker/docker_test.go index aececff3386..ed65bde8d80 100644 --- a/pkg/skaffold/build/docker/docker_test.go +++ b/pkg/skaffold/build/docker/docker_test.go @@ -32,7 +32,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/proto/v1" "github.com/GoogleContainerTools/skaffold/testutil" @@ -41,7 +41,7 @@ import ( func TestDockerCLIBuild(t *testing.T) { tests := []struct { description string - localBuild latestV1.LocalBuild + localBuild latest.LocalBuild cliFlags []string cfg mockConfig extraEnv []string @@ -53,39 +53,39 @@ func TestDockerCLIBuild(t *testing.T) { }{ { description: "docker build", - localBuild: latestV1.LocalBuild{}, + localBuild: latest.LocalBuild{}, cfg: mockConfig{runMode: config.RunModes.Dev}, expectedEnv: []string{"KEY=VALUE"}, }, { description: "extra env", - localBuild: latestV1.LocalBuild{}, + localBuild: latest.LocalBuild{}, extraEnv: []string{"OTHER=VALUE"}, expectedEnv: []string{"KEY=VALUE", "OTHER=VALUE"}, }, { description: "buildkit", - localBuild: latestV1.LocalBuild{UseBuildkit: util.BoolPtr(true)}, + localBuild: latest.LocalBuild{UseBuildkit: util.BoolPtr(true)}, wantDockerCLI: true, expectedEnv: []string{"KEY=VALUE", "DOCKER_BUILDKIT=1"}, }, { description: "cliFlags", cliFlags: []string{"--platform", "linux/amd64"}, - localBuild: latestV1.LocalBuild{}, + localBuild: latest.LocalBuild{}, wantDockerCLI: true, expectedEnv: []string{"KEY=VALUE"}, }, { description: "buildkit and extra env", - localBuild: latestV1.LocalBuild{UseBuildkit: util.BoolPtr(true)}, + localBuild: latest.LocalBuild{UseBuildkit: util.BoolPtr(true)}, wantDockerCLI: true, extraEnv: []string{"OTHER=VALUE"}, expectedEnv: []string{"KEY=VALUE", "OTHER=VALUE", "DOCKER_BUILDKIT=1"}, }, { description: "env var collisions", - localBuild: latestV1.LocalBuild{UseBuildkit: util.BoolPtr(true)}, + localBuild: latest.LocalBuild{UseBuildkit: util.BoolPtr(true)}, wantDockerCLI: true, extraEnv: []string{"KEY=OTHER_VALUE", "DOCKER_BUILDKIT=0"}, // DOCKER_BUILDKIT should be overridden @@ -93,13 +93,13 @@ func TestDockerCLIBuild(t *testing.T) { }, { description: "docker build internal error", - localBuild: latestV1.LocalBuild{UseDockerCLI: true}, + localBuild: latest.LocalBuild{UseDockerCLI: true}, err: errdefs.Cancelled(fmt.Errorf("cancelled")), expectedErr: newBuildError(errdefs.Cancelled(fmt.Errorf("cancelled")), mockConfig{runMode: config.RunModes.Dev}), }, { description: "docker build no space left error with prune for dev", - localBuild: latestV1.LocalBuild{UseDockerCLI: true}, + localBuild: latest.LocalBuild{UseDockerCLI: true}, cfg: mockConfig{runMode: config.RunModes.Dev, prune: false}, err: errdefs.System(fmt.Errorf("no space left")), expectedErr: fmt.Errorf("Docker ran out of memory. Please run 'docker system prune' to removed unused docker data or Run skaffold dev with --cleanup=true to clean up images built by skaffold"), @@ -107,7 +107,7 @@ func TestDockerCLIBuild(t *testing.T) { }, { description: "docker build no space left error with prune for build", - localBuild: latestV1.LocalBuild{UseDockerCLI: true}, + localBuild: latest.LocalBuild{UseDockerCLI: true}, cfg: mockConfig{runMode: config.RunModes.Build, prune: false}, err: errdefs.System(fmt.Errorf("no space left")), expectedErr: fmt.Errorf("no space left. Docker ran out of memory. Please run 'docker system prune' to removed unused docker data"), @@ -115,7 +115,7 @@ func TestDockerCLIBuild(t *testing.T) { }, { description: "docker build no space left error with prune true", - localBuild: latestV1.LocalBuild{UseDockerCLI: true}, + localBuild: latest.LocalBuild{UseDockerCLI: true}, cfg: mockConfig{prune: true}, err: errdefs.System(fmt.Errorf("no space left")), expectedErr: fmt.Errorf("no space left. Docker ran out of memory. Please run 'docker system prune' to removed unused docker data"), @@ -123,7 +123,7 @@ func TestDockerCLIBuild(t *testing.T) { }, { description: "docker build system error", - localBuild: latestV1.LocalBuild{UseDockerCLI: true}, + localBuild: latest.LocalBuild{UseDockerCLI: true}, err: errdefs.System(fmt.Errorf("something else")), expectedErr: fmt.Errorf("something else"), expectedErrCode: proto.StatusCode_BUILD_DOCKER_SYSTEM_ERR, @@ -163,10 +163,10 @@ func TestDockerCLIBuild(t *testing.T) { builder := NewArtifactBuilder(fakeLocalDaemonWithExtraEnv(test.extraEnv), test.cfg, test.localBuild.UseDockerCLI, test.localBuild.UseBuildkit, false, mockArtifactResolver{make(map[string]string)}, nil) - artifact := &latestV1.Artifact{ + artifact := &latest.Artifact{ Workspace: ".", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: "Dockerfile", CliFlags: test.cliFlags, }, @@ -193,16 +193,16 @@ func TestDockerCLIBuild(t *testing.T) { func TestDockerCLICheckCacheFromArgs(t *testing.T) { tests := []struct { description string - artifact *latestV1.Artifact + artifact *latest.Artifact tag string expectedCacheFrom []string }{ { description: "multiple cache-from images", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "gcr.io/k8s-skaffold/test", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ CacheFrom: []string{"from/image1", "from/image2"}, }, }, @@ -212,10 +212,10 @@ func TestDockerCLICheckCacheFromArgs(t *testing.T) { }, { description: "cache-from self uses tagged image", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "gcr.io/k8s-skaffold/test", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ CacheFrom: []string{"gcr.io/k8s-skaffold/test"}, }, }, diff --git a/pkg/skaffold/build/docker/errors_test.go b/pkg/skaffold/build/docker/errors_test.go index cddc38e55a3..4d31a16c71d 100644 --- a/pkg/skaffold/build/docker/errors_test.go +++ b/pkg/skaffold/build/docker/errors_test.go @@ -25,7 +25,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -62,11 +62,11 @@ Refer https://skaffold.dev/docs/references/yaml/#build-artifacts-docker for deta t.Override(&docker.DefaultAuthHelper, stubAuth{}) builder := NewArtifactBuilder(fakeLocalDaemonWithExtraEnv([]string{}), mockConfig{}, true, nil, false, mockArtifactResolver{make(map[string]string)}, nil) - artifact := &latestV1.Artifact{ + artifact := &latest.Artifact{ ImageName: "test-image", Workspace: ".", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: test.dockerfilepath, }, }, diff --git a/pkg/skaffold/build/docker/types.go b/pkg/skaffold/build/docker/types.go index e16dab63b90..a261f237ff0 100644 --- a/pkg/skaffold/build/docker/types.go +++ b/pkg/skaffold/build/docker/types.go @@ -20,7 +20,7 @@ import ( "context" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // Builder is an artifact builder that uses docker @@ -41,7 +41,7 @@ type ArtifactResolver interface { // TransitiveSourceDependenciesResolver provides an interface to to evaluate the source dependencies for artifacts. type TransitiveSourceDependenciesResolver interface { - TransitiveArtifactDependencies(ctx context.Context, a *latestV1.Artifact) ([]string, error) + TransitiveArtifactDependencies(ctx context.Context, a *latest.Artifact) ([]string, error) } // NewBuilder returns an new instance of a docker builder diff --git a/pkg/skaffold/build/gcb/buildpacks.go b/pkg/skaffold/build/gcb/buildpacks.go index 4a02916af67..9de0cf2d850 100644 --- a/pkg/skaffold/build/gcb/buildpacks.go +++ b/pkg/skaffold/build/gcb/buildpacks.go @@ -26,10 +26,10 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) -func (b *Builder) buildpackBuildSpec(artifact *latestV1.BuildpackArtifact, tag string, deps []*latestV1.ArtifactDependency) (cloudbuild.Build, error) { +func (b *Builder) buildpackBuildSpec(artifact *latest.BuildpackArtifact, tag string, deps []*latest.ArtifactDependency) (cloudbuild.Build, error) { args := []string{"pack", "build", tag, "--builder", fromRequiredArtifacts(artifact.Builder, b.artifactStore, deps)} if artifact.ProjectDescriptor != constants.DefaultProjectDescriptor { @@ -67,7 +67,7 @@ func (b *Builder) buildpackBuildSpec(artifact *latestV1.BuildpackArtifact, tag s } // fromRequiredArtifacts replaces the provided image name with image from the required artifacts if matched. -func fromRequiredArtifacts(imageName string, r docker.ArtifactResolver, deps []*latestV1.ArtifactDependency) string { +func fromRequiredArtifacts(imageName string, r docker.ArtifactResolver, deps []*latest.ArtifactDependency) string { for _, d := range deps { if imageName == d.Alias { image, found := r.GetImageTag(d.ImageName) diff --git a/pkg/skaffold/build/gcb/buildpacks_test.go b/pkg/skaffold/build/gcb/buildpacks_test.go index dcaced50e9a..a2806151d3c 100644 --- a/pkg/skaffold/build/gcb/buildpacks_test.go +++ b/pkg/skaffold/build/gcb/buildpacks_test.go @@ -23,7 +23,7 @@ import ( "google.golang.org/api/cloudbuild/v1" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -31,13 +31,13 @@ import ( func TestBuildpackBuildSpec(t *testing.T) { tests := []struct { description string - artifact *latestV1.BuildpackArtifact + artifact *latest.BuildpackArtifact expected cloudbuild.Build shouldErr bool }{ { description: "default run image", - artifact: &latestV1.BuildpackArtifact{ + artifact: &latest.BuildpackArtifact{ Builder: "builder", ProjectDescriptor: "project.toml", }, @@ -51,7 +51,7 @@ func TestBuildpackBuildSpec(t *testing.T) { }, { description: "env variables", - artifact: &latestV1.BuildpackArtifact{ + artifact: &latest.BuildpackArtifact{ Builder: "builder", Env: []string{"KEY=VALUE", "FOO={{.BAR}}"}, ProjectDescriptor: "project.toml", @@ -66,7 +66,7 @@ func TestBuildpackBuildSpec(t *testing.T) { }, { description: "run image", - artifact: &latestV1.BuildpackArtifact{ + artifact: &latest.BuildpackArtifact{ Builder: "otherbuilder", RunImage: "run/image", ProjectDescriptor: "project.toml", @@ -81,7 +81,7 @@ func TestBuildpackBuildSpec(t *testing.T) { }, { description: "custom build image", - artifact: &latestV1.BuildpackArtifact{ + artifact: &latest.BuildpackArtifact{ Builder: "img2", RunImage: "run/image", ProjectDescriptor: "project.toml", @@ -96,7 +96,7 @@ func TestBuildpackBuildSpec(t *testing.T) { }, { description: "custom run image", - artifact: &latestV1.BuildpackArtifact{ + artifact: &latest.BuildpackArtifact{ Builder: "otherbuilder", RunImage: "img3", ProjectDescriptor: "project.toml", @@ -111,7 +111,7 @@ func TestBuildpackBuildSpec(t *testing.T) { }, { description: "custom build and run image", - artifact: &latestV1.BuildpackArtifact{ + artifact: &latest.BuildpackArtifact{ Builder: "img2", RunImage: "img3", ProjectDescriptor: "project.toml", @@ -126,7 +126,7 @@ func TestBuildpackBuildSpec(t *testing.T) { }, { description: "invalid env", - artifact: &latestV1.BuildpackArtifact{ + artifact: &latest.BuildpackArtifact{ Builder: "builder", Env: []string{"FOO={{INVALID}}"}, }, @@ -134,7 +134,7 @@ func TestBuildpackBuildSpec(t *testing.T) { }, { description: "buildpacks list", - artifact: &latestV1.BuildpackArtifact{ + artifact: &latest.BuildpackArtifact{ Builder: "builder", Buildpacks: []string{"buildpack1", "buildpack2"}, ProjectDescriptor: "project.toml", @@ -149,7 +149,7 @@ func TestBuildpackBuildSpec(t *testing.T) { }, { description: "trusted builder", - artifact: &latestV1.BuildpackArtifact{ + artifact: &latest.BuildpackArtifact{ Builder: "builder", ProjectDescriptor: "project.toml", TrustBuilder: true, @@ -164,7 +164,7 @@ func TestBuildpackBuildSpec(t *testing.T) { }, { description: "project descriptor", - artifact: &latestV1.BuildpackArtifact{ + artifact: &latest.BuildpackArtifact{ Builder: "builder", ProjectDescriptor: "non-default.toml", }, @@ -181,18 +181,18 @@ func TestBuildpackBuildSpec(t *testing.T) { testutil.Run(t, test.description, func(t *testutil.T) { t.Override(&util.OSEnviron, func() []string { return []string{"BAR=bar"} }) - artifact := &latestV1.Artifact{ + artifact := &latest.Artifact{ ImageName: "img", - ArtifactType: latestV1.ArtifactType{ + ArtifactType: latest.ArtifactType{ BuildpackArtifact: test.artifact, }, - Dependencies: []*latestV1.ArtifactDependency{{ImageName: "img2", Alias: "img2"}, {ImageName: "img3", Alias: "img3"}}, + Dependencies: []*latest.ArtifactDependency{{ImageName: "img2", Alias: "img2"}, {ImageName: "img3", Alias: "img3"}}, } store := mockArtifactStore{ "img2": "img2:tag", "img3": "img3:tag", } - builder := NewBuilder(&mockBuilderContext{artifactStore: store}, &latestV1.GoogleCloudBuild{ + builder := NewBuilder(&mockBuilderContext{artifactStore: store}, &latest.GoogleCloudBuild{ PackImage: "pack/image", }) buildSpec, err := builder.buildSpec(context.Background(), artifact, "img", platform.Matcher{}, "bucket", "object") diff --git a/pkg/skaffold/build/gcb/cloud_build.go b/pkg/skaffold/build/gcb/cloud_build.go index 174d3468ac3..e7350a98f18 100644 --- a/pkg/skaffold/build/gcb/cloud_build.go +++ b/pkg/skaffold/build/gcb/cloud_build.go @@ -41,14 +41,14 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/sources" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/proto/v1" ) // Build builds a list of artifacts with Google Cloud Build. -func (b *Builder) Build(ctx context.Context, out io.Writer, artifact *latestV1.Artifact) build.ArtifactBuilder { +func (b *Builder) Build(ctx context.Context, out io.Writer, artifact *latest.Artifact) build.ArtifactBuilder { instrumentation.AddAttributesToCurrentSpanFromContext(ctx, map[string]string{ "BuildType": "gcb", "Context": instrumentation.PII(artifact.Workspace), @@ -69,7 +69,7 @@ func (b *Builder) Concurrency() *int { return util.IntPtr(b.GoogleCloudBuild.Concurrency) } -func (b *Builder) buildArtifactWithCloudBuild(ctx context.Context, out io.Writer, artifact *latestV1.Artifact, tag string, platform platform.Matcher) (string, error) { +func (b *Builder) buildArtifactWithCloudBuild(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string, platform platform.Matcher) (string, error) { instrumentation.AddAttributesToCurrentSpanFromContext(ctx, map[string]string{ "Destination": instrumentation.PII(tag), }) diff --git a/pkg/skaffold/build/gcb/docker.go b/pkg/skaffold/build/gcb/docker.go index 6ec54b79ac7..b70fc9f2cfa 100644 --- a/pkg/skaffold/build/gcb/docker.go +++ b/pkg/skaffold/build/gcb/docker.go @@ -25,12 +25,12 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" ) // dockerBuildSpec lists the build steps required to build a docker image. -func (b *Builder) dockerBuildSpec(a *latestV1.Artifact, tag string, platforms platform.Matcher) (cloudbuild.Build, error) { +func (b *Builder) dockerBuildSpec(a *latest.Artifact, tag string, platforms platform.Matcher) (cloudbuild.Build, error) { a = adjustCacheFrom(a, tag) args, err := b.dockerBuildArgs(a, tag, a.Dependencies, platforms) @@ -55,7 +55,7 @@ func (b *Builder) dockerBuildSpec(a *latestV1.Artifact, tag string, platforms pl } // cacheFromSteps pulls images used by `--cache-from`. -func (b *Builder) cacheFromSteps(artifact *latestV1.DockerArtifact, platforms platform.Matcher) []*cloudbuild.BuildStep { +func (b *Builder) cacheFromSteps(artifact *latest.DockerArtifact, platforms platform.Matcher) []*cloudbuild.BuildStep { var steps []*cloudbuild.BuildStep argFmt := "docker pull %s || true" if platforms.IsNotEmpty() { @@ -73,7 +73,7 @@ func (b *Builder) cacheFromSteps(artifact *latestV1.DockerArtifact, platforms pl } // dockerBuildArgs lists the arguments passed to `docker` to build a given image. -func (b *Builder) dockerBuildArgs(a *latestV1.Artifact, tag string, deps []*latestV1.ArtifactDependency, platforms platform.Matcher) ([]string, error) { +func (b *Builder) dockerBuildArgs(a *latest.Artifact, tag string, deps []*latest.ArtifactDependency, platforms platform.Matcher) ([]string, error) { d := a.DockerArtifact // TODO(nkubala): remove when buildkit is supported in GCB (#4773) if len(d.Secrets) > 0 || d.SSH != "" { @@ -101,7 +101,7 @@ func (b *Builder) dockerBuildArgs(a *latestV1.Artifact, tag string, deps []*late } // adjustCacheFrom returns an artifact where any cache references from the artifactImage is changed to the tagged built image name instead. -func adjustCacheFrom(a *latestV1.Artifact, artifactTag string) *latestV1.Artifact { +func adjustCacheFrom(a *latest.Artifact, artifactTag string) *latest.Artifact { if os.Getenv("SKAFFOLD_DISABLE_GCB_CACHE_ADJUSTMENT") != "" { // allow this behaviour to be disabled return a diff --git a/pkg/skaffold/build/gcb/docker_test.go b/pkg/skaffold/build/gcb/docker_test.go index 28fb9df3e4d..ad5994b13f0 100644 --- a/pkg/skaffold/build/gcb/docker_test.go +++ b/pkg/skaffold/build/gcb/docker_test.go @@ -26,7 +26,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -34,16 +34,16 @@ import ( func TestDockerBuildSpec(t *testing.T) { tests := []struct { description string - artifact *latestV1.Artifact + artifact *latest.Artifact platforms platform.Matcher expected cloudbuild.Build shouldErr bool }{ { description: "normal docker build", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: "Dockerfile", BuildArgs: map[string]*string{ "arg1": util.StringPtr("value1"), @@ -74,10 +74,10 @@ func TestDockerBuildSpec(t *testing.T) { }, { description: "docker build with artifact dependencies", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "img1", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: "Dockerfile", BuildArgs: map[string]*string{ "arg1": util.StringPtr("value1"), @@ -85,7 +85,7 @@ func TestDockerBuildSpec(t *testing.T) { }, }, }, - Dependencies: []*latestV1.ArtifactDependency{{ImageName: "img2", Alias: "IMG2"}, {ImageName: "img3", Alias: "IMG3"}}, + Dependencies: []*latest.ArtifactDependency{{ImageName: "img2", Alias: "IMG2"}, {ImageName: "img3", Alias: "IMG3"}}, }, expected: cloudbuild.Build{ LogsBucket: "bucket", @@ -109,11 +109,11 @@ func TestDockerBuildSpec(t *testing.T) { }, { description: "buildkit `secret` option not supported in GCB", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: "Dockerfile", - Secrets: []*latestV1.DockerSecret{ + Secrets: []*latest.DockerSecret{ {ID: "secret"}, }, }, @@ -123,9 +123,9 @@ func TestDockerBuildSpec(t *testing.T) { }, { description: "buildkit `ssh` option not supported in GCB", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: "Dockerfile", SSH: "default", }, @@ -136,9 +136,9 @@ func TestDockerBuildSpec(t *testing.T) { { description: "cross-platform build", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: "Dockerfile", BuildArgs: map[string]*string{ "arg1": util.StringPtr("value1"), @@ -189,7 +189,7 @@ func TestDockerBuildSpec(t *testing.T) { "img3": "img3:tag", } - builder := NewBuilder(&mockBuilderContext{artifactStore: store}, &latestV1.GoogleCloudBuild{ + builder := NewBuilder(&mockBuilderContext{artifactStore: store}, &latest.GoogleCloudBuild{ DockerImage: "docker/docker", DiskSizeGb: 100, MachineType: "n1-standard-1", @@ -205,7 +205,7 @@ func TestDockerBuildSpec(t *testing.T) { func TestPullCacheFrom(t *testing.T) { tests := []struct { description string - artifact *latestV1.Artifact + artifact *latest.Artifact tag string platforms platform.Matcher expected []*cloudbuild.BuildStep @@ -213,9 +213,9 @@ func TestPullCacheFrom(t *testing.T) { }{ { description: "multiple cache-from images", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: "Dockerfile", CacheFrom: []string{"from/image1", "from/image2"}, }, @@ -237,10 +237,10 @@ func TestPullCacheFrom(t *testing.T) { }, { description: "cache-from self uses tagged image", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "gcr.io/k8s-skaffold/test", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: "Dockerfile", CacheFrom: []string{"gcr.io/k8s-skaffold/test"}, }, @@ -258,9 +258,9 @@ func TestPullCacheFrom(t *testing.T) { }, { description: "cross-platform cache-from images", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: "Dockerfile", CacheFrom: []string{"from/image1", "from/image2"}, }, @@ -289,7 +289,7 @@ func TestPullCacheFrom(t *testing.T) { t.Override(&docker.EvalBuildArgs, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string) (map[string]*string, error) { return args, nil }) - builder := NewBuilder(&mockBuilderContext{}, &latestV1.GoogleCloudBuild{ + builder := NewBuilder(&mockBuilderContext{}, &latest.GoogleCloudBuild{ DockerImage: "docker/docker", }) desc, err := builder.dockerBuildSpec(test.artifact, test.tag, test.platforms) diff --git a/pkg/skaffold/build/gcb/jib.go b/pkg/skaffold/build/gcb/jib.go index 7c53d7fbd30..3c0fa1cda19 100644 --- a/pkg/skaffold/build/gcb/jib.go +++ b/pkg/skaffold/build/gcb/jib.go @@ -27,11 +27,11 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/jib" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) -func (b *Builder) jibBuildSpec(ctx context.Context, artifact *latestV1.Artifact, tag string, platforms platform.Matcher) (cloudbuild.Build, error) { +func (b *Builder) jibBuildSpec(ctx context.Context, artifact *latest.Artifact, tag string, platforms platform.Matcher) (cloudbuild.Build, error) { t, err := jib.DeterminePluginType(ctx, artifact.Workspace, artifact.JibArtifact) if err != nil { return cloudbuild.Build{}, err diff --git a/pkg/skaffold/build/gcb/jib_test.go b/pkg/skaffold/build/gcb/jib_test.go index 6ea0f6d447b..c552bb02557 100644 --- a/pkg/skaffold/build/gcb/jib_test.go +++ b/pkg/skaffold/build/gcb/jib_test.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/jib" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -80,11 +80,11 @@ func TestJibMavenBuildSpec(t *testing.T) { } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - artifact := &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - JibArtifact: &latestV1.JibArtifact{Type: string(jib.JibMaven), BaseImage: test.baseImage}, + artifact := &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + JibArtifact: &latest.JibArtifact{Type: string(jib.JibMaven), BaseImage: test.baseImage}, }, - Dependencies: []*latestV1.ArtifactDependency{ + Dependencies: []*latest.ArtifactDependency{ {ImageName: "img2", Alias: "img2"}, {ImageName: "img3", Alias: "img3"}, }, @@ -94,7 +94,7 @@ func TestJibMavenBuildSpec(t *testing.T) { "img2": "img2:tag", "img3": "img3:tag", } - builder := NewBuilder(&mockBuilderContext{artifactStore: store}, &latestV1.GoogleCloudBuild{ + builder := NewBuilder(&mockBuilderContext{artifactStore: store}, &latest.GoogleCloudBuild{ MavenImage: "maven:3.6.0", }) builder.skipTests = test.skipTests @@ -144,13 +144,13 @@ func TestJibGradleBuildSpec(t *testing.T) { } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - artifact := &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - JibArtifact: &latestV1.JibArtifact{Type: string(jib.JibGradle)}, + artifact := &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + JibArtifact: &latest.JibArtifact{Type: string(jib.JibGradle)}, }, } - builder := NewBuilder(&mockBuilderContext{}, &latestV1.GoogleCloudBuild{ + builder := NewBuilder(&mockBuilderContext{}, &latest.GoogleCloudBuild{ GradleImage: "gradle:5.1.1", }) builder.skipTests = test.skipTests diff --git a/pkg/skaffold/build/gcb/kaniko.go b/pkg/skaffold/build/gcb/kaniko.go index 00bfbbbbac9..237a9103f9e 100644 --- a/pkg/skaffold/build/gcb/kaniko.go +++ b/pkg/skaffold/build/gcb/kaniko.go @@ -25,10 +25,10 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/kaniko" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/misc" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) -func (b *Builder) kanikoBuildSpec(a *latestV1.Artifact, tag string) (cloudbuild.Build, error) { +func (b *Builder) kanikoBuildSpec(a *latest.Artifact, tag string) (cloudbuild.Build, error) { k := a.KanikoArtifact requiredImages := docker.ResolveDependencyImages(a.Dependencies, b.artifactStore, true) // add required artifacts as build args diff --git a/pkg/skaffold/build/gcb/kaniko_test.go b/pkg/skaffold/build/gcb/kaniko_test.go index 87b556f5e7d..995eef29dc8 100644 --- a/pkg/skaffold/build/gcb/kaniko_test.go +++ b/pkg/skaffold/build/gcb/kaniko_test.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -36,20 +36,20 @@ import ( func TestKanikoBuildSpec(t *testing.T) { tests := []struct { description string - artifact *latestV1.KanikoArtifact + artifact *latest.KanikoArtifact expectedArgs []string expectedEnv []string }{ { description: "simple build", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", }, expectedArgs: []string{}, }, { description: "with BuildArgs", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", BuildArgs: map[string]*string{ "arg1": util.StringPtr("value1"), @@ -63,7 +63,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with Env", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", Env: []kv1.EnvVar{{Name: "KEY1", Value: "VALUE1"}, {Name: "KEY2", Value: "VALUE2"}}, }, @@ -71,9 +71,9 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with Cache", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", - Cache: &latestV1.KanikoCache{}, + Cache: &latest.KanikoCache{}, }, expectedArgs: []string{ kaniko.CacheFlag, @@ -81,9 +81,9 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with Cache Copy Layers", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", - Cache: &latestV1.KanikoCache{CacheCopyLayers: true}, + Cache: &latest.KanikoCache{CacheCopyLayers: true}, }, expectedArgs: []string{ kaniko.CacheFlag, @@ -92,7 +92,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with Cleanup", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", Cleanup: true, }, @@ -102,7 +102,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with DigestFile", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", DigestFile: "/tmp/digest", }, @@ -112,7 +112,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with Force", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", Force: true, }, @@ -122,7 +122,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with ImageFSExtractRetry", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", ImageFSExtractRetry: "5", }, @@ -132,7 +132,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with ImageNameWithDigestFile", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", ImageNameWithDigestFile: "/tmp/imageName", }, @@ -142,7 +142,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with Insecure", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", Insecure: true, }, @@ -152,7 +152,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with InsecurePull", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", InsecurePull: true, }, @@ -162,7 +162,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with InsecureRegistry", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", InsecureRegistry: []string{ "s1.registry.url:5000", @@ -176,7 +176,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with LogFormat", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", LogFormat: "json", }, @@ -186,7 +186,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with LogTimestamp", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", LogTimestamp: true, }, @@ -196,7 +196,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with NoPush", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", NoPush: true, }, @@ -206,7 +206,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with OCILayoutPath", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", OCILayoutPath: "/tmp/builtImage", }, @@ -216,7 +216,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with RegistryCertificate", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", RegistryCertificate: map[string]*string{ "s1.registry.url": util.StringPtr("/etc/certs/certificate1.cert"), @@ -230,7 +230,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with RegistryMirror", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", RegistryMirror: "mirror.gcr.io", }, @@ -240,7 +240,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with Reproducible", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", Reproducible: true, }, @@ -250,7 +250,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with SingleSnapshot", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", SingleSnapshot: true, }, @@ -260,7 +260,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with SkipTLS", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", SkipTLS: true, }, @@ -271,7 +271,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with SkipTLSVerifyPull", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", SkipTLSVerifyPull: true, }, @@ -281,7 +281,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with SkipTLSVerifyRegistry", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", SkipTLSVerifyRegistry: []string{ "s1.registry.url:5000", @@ -295,7 +295,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with SkipUnusedStages", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", SkipUnusedStages: true, }, @@ -305,7 +305,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with Target", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", Target: "builder", }, @@ -315,7 +315,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with SnapshotMode", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", SnapshotMode: "redo", }, @@ -325,7 +325,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with PushRetry", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", PushRetry: "9", }, @@ -335,7 +335,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with TarPath", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", TarPath: "/workspace/tars", }, @@ -345,7 +345,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with UseNewRun", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", UseNewRun: true, }, @@ -355,7 +355,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with Verbosity", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", Verbosity: "trace", }, @@ -365,7 +365,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with WhitelistVarRun", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", WhitelistVarRun: true, }, @@ -375,7 +375,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with WhitelistVarRun", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", WhitelistVarRun: true, }, @@ -385,7 +385,7 @@ func TestKanikoBuildSpec(t *testing.T) { }, { description: "with Labels", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", Label: map[string]*string{ "label1": util.StringPtr("value1"), @@ -402,7 +402,7 @@ func TestKanikoBuildSpec(t *testing.T) { "img2": "img2:tag", "img3": "img3:tag", } - builder := NewBuilder(&mockBuilderContext{artifactStore: store}, &latestV1.GoogleCloudBuild{ + builder := NewBuilder(&mockBuilderContext{artifactStore: store}, &latest.GoogleCloudBuild{ KanikoImage: "gcr.io/kaniko-project/executor", DiskSizeGb: 100, MachineType: "n1-standard-1", @@ -416,12 +416,12 @@ func TestKanikoBuildSpec(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - artifact := &latestV1.Artifact{ + artifact := &latest.Artifact{ ImageName: "img1", - ArtifactType: latestV1.ArtifactType{ + ArtifactType: latest.ArtifactType{ KanikoArtifact: test.artifact, }, - Dependencies: []*latestV1.ArtifactDependency{ + Dependencies: []*latest.ArtifactDependency{ {ImageName: "img2", Alias: "IMG2"}, {ImageName: "img3", Alias: "IMG3"}, }, @@ -470,7 +470,7 @@ func TestKanikoBuildSpec(t *testing.T) { type mockArtifactStore map[string]string func (m mockArtifactStore) GetImageTag(imageName string) (string, bool) { return m[imageName], true } -func (m mockArtifactStore) Record(a *latestV1.Artifact, tag string) { m[a.ImageName] = tag } -func (m mockArtifactStore) GetArtifacts([]*latestV1.Artifact) ([]graph.Artifact, error) { +func (m mockArtifactStore) Record(a *latest.Artifact, tag string) { m[a.ImageName] = tag } +func (m mockArtifactStore) GetArtifacts([]*latest.Artifact) ([]graph.Artifact, error) { return nil, nil } diff --git a/pkg/skaffold/build/gcb/spec.go b/pkg/skaffold/build/gcb/spec.go index aff80a03e02..cf51f9f9663 100644 --- a/pkg/skaffold/build/gcb/spec.go +++ b/pkg/skaffold/build/gcb/spec.go @@ -25,10 +25,10 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/misc" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) -func (b *Builder) buildSpec(ctx context.Context, artifact *latestV1.Artifact, tag string, platforms platform.Matcher, bucket, object string) (cloudbuild.Build, error) { +func (b *Builder) buildSpec(ctx context.Context, artifact *latest.Artifact, tag string, platforms platform.Matcher, bucket, object string) (cloudbuild.Build, error) { // Artifact specific build spec buildSpec, err := b.buildSpecForArtifact(ctx, artifact, tag, platforms) if err != nil { @@ -58,7 +58,7 @@ func (b *Builder) buildSpec(ctx context.Context, artifact *latestV1.Artifact, ta return buildSpec, nil } -func (b *Builder) buildSpecForArtifact(ctx context.Context, a *latestV1.Artifact, tag string, platforms platform.Matcher) (cloudbuild.Build, error) { +func (b *Builder) buildSpecForArtifact(ctx context.Context, a *latest.Artifact, tag string, platforms platform.Matcher) (cloudbuild.Build, error) { switch { case a.KanikoArtifact != nil: return b.kanikoBuildSpec(a, tag) diff --git a/pkg/skaffold/build/gcb/spec_test.go b/pkg/skaffold/build/gcb/spec_test.go index 76a8e0ad039..e4bbea3327a 100644 --- a/pkg/skaffold/build/gcb/spec_test.go +++ b/pkg/skaffold/build/gcb/spec_test.go @@ -24,31 +24,31 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" "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/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) func TestBuildSpecFail(t *testing.T) { tests := []struct { description string - artifact *latestV1.Artifact + artifact *latest.Artifact }{ { description: "bazel", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - BazelArtifact: &latestV1.BazelArtifact{}, + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + BazelArtifact: &latest.BazelArtifact{}, }, }, }, { description: "unknown", - artifact: &latestV1.Artifact{}, + artifact: &latest.Artifact{}, }, } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - builder := NewBuilder(&mockBuilderContext{}, &latestV1.GoogleCloudBuild{}) + builder := NewBuilder(&mockBuilderContext{}, &latest.GoogleCloudBuild{}) _, err := builder.buildSpec(context.Background(), test.artifact, "tag", platform.Matcher{}, "bucket", "object") diff --git a/pkg/skaffold/build/gcb/types.go b/pkg/skaffold/build/gcb/types.go index 7e03bbea4f8..aec17a1b4e1 100644 --- a/pkg/skaffold/build/gcb/types.go +++ b/pkg/skaffold/build/gcb/types.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) const ( @@ -80,7 +80,7 @@ func NewStatusBackoff() *wait.Backoff { // Builder builds artifacts with Google Cloud Build. type Builder struct { - *latestV1.GoogleCloudBuild + *latest.GoogleCloudBuild cfg Config skipTests bool @@ -103,7 +103,7 @@ type BuilderContext interface { } // NewBuilder creates a new Builder that builds artifacts with Google Cloud Build. -func NewBuilder(bCtx BuilderContext, buildCfg *latestV1.GoogleCloudBuild) *Builder { +func NewBuilder(bCtx BuilderContext, buildCfg *latest.GoogleCloudBuild) *Builder { return &Builder{ GoogleCloudBuild: buildCfg, cfg: bCtx, diff --git a/pkg/skaffold/build/jib/build.go b/pkg/skaffold/build/jib/build.go index 2a07756eca4..feb4f89c747 100644 --- a/pkg/skaffold/build/jib/build.go +++ b/pkg/skaffold/build/jib/build.go @@ -22,11 +22,11 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/instrumentation" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // Build builds an artifact with Jib. -func (b *Builder) Build(ctx context.Context, out io.Writer, artifact *latestV1.Artifact, tag string, platforms platform.Matcher) (string, error) { +func (b *Builder) Build(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string, platforms platform.Matcher) (string, error) { instrumentation.AddAttributesToCurrentSpanFromContext(ctx, map[string]string{ "BuildType": "jib", "Context": instrumentation.PII(artifact.Workspace), diff --git a/pkg/skaffold/build/jib/gradle.go b/pkg/skaffold/build/jib/gradle.go index d679b91f922..65bac302b78 100644 --- a/pkg/skaffold/build/jib/gradle.go +++ b/pkg/skaffold/build/jib/gradle.go @@ -26,7 +26,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -44,7 +44,7 @@ const MinimumJibGradleVersionForCrossPlatform = "3.2.0" // GradleCommand stores Gradle executable and wrapper name var GradleCommand = util.CommandWrapper{Executable: "gradle", Wrapper: "gradlew"} -func (b *Builder) buildJibGradleToDocker(ctx context.Context, out io.Writer, workspace string, artifact *latestV1.JibArtifact, deps []*latestV1.ArtifactDependency, tag string, platforms platform.Matcher) (string, error) { +func (b *Builder) buildJibGradleToDocker(ctx context.Context, out io.Writer, workspace string, artifact *latest.JibArtifact, deps []*latest.ArtifactDependency, tag string, platforms platform.Matcher) (string, error) { args := GenerateGradleBuildArgs("jibDockerBuild", tag, artifact, platforms, b.skipTests, b.pushImages, deps, b.artifacts, b.cfg.GetInsecureRegistries(), output.IsColorable(out)) if err := b.runGradleCommand(ctx, out, workspace, args); err != nil { return "", jibToolErr(err) @@ -53,7 +53,7 @@ func (b *Builder) buildJibGradleToDocker(ctx context.Context, out io.Writer, wor return b.localDocker.ImageID(ctx, tag) } -func (b *Builder) buildJibGradleToRegistry(ctx context.Context, out io.Writer, workspace string, artifact *latestV1.JibArtifact, deps []*latestV1.ArtifactDependency, tag string, platforms platform.Matcher) (string, error) { +func (b *Builder) buildJibGradleToRegistry(ctx context.Context, out io.Writer, workspace string, artifact *latest.JibArtifact, deps []*latest.ArtifactDependency, tag string, platforms platform.Matcher) (string, error) { args := GenerateGradleBuildArgs("jib", tag, artifact, platforms, b.skipTests, b.pushImages, deps, b.artifacts, b.cfg.GetInsecureRegistries(), output.IsColorable(out)) if err := b.runGradleCommand(ctx, out, workspace, args); err != nil { return "", jibToolErr(err) @@ -78,7 +78,7 @@ func (b *Builder) runGradleCommand(ctx context.Context, out io.Writer, workspace // getDependenciesGradle finds the source dependencies for the given jib-gradle artifact. // All paths are absolute. -func getDependenciesGradle(ctx context.Context, workspace string, a *latestV1.JibArtifact) ([]string, error) { +func getDependenciesGradle(ctx context.Context, workspace string, a *latest.JibArtifact) ([]string, error) { cmd := getCommandGradle(ctx, workspace, a) deps, err := getDependencies(ctx, workspace, cmd, a) if err != nil { @@ -88,18 +88,18 @@ func getDependenciesGradle(ctx context.Context, workspace string, a *latestV1.Ji return deps, nil } -func getCommandGradle(ctx context.Context, workspace string, a *latestV1.JibArtifact) exec.Cmd { +func getCommandGradle(ctx context.Context, workspace string, a *latest.JibArtifact) exec.Cmd { args := append(gradleArgsFunc(a, "_jibSkaffoldFilesV2", MinimumJibGradleVersion), "-q", "--console=plain") return GradleCommand.CreateCommand(ctx, workspace, args) } -func getSyncMapCommandGradle(ctx context.Context, workspace string, a *latestV1.JibArtifact) *exec.Cmd { +func getSyncMapCommandGradle(ctx context.Context, workspace string, a *latest.JibArtifact) *exec.Cmd { cmd := GradleCommand.CreateCommand(ctx, workspace, gradleBuildArgsFunc("_jibSkaffoldSyncMap", a, true, false, MinimumJibMavenVersionForSync)) return &cmd } // GenerateGradleBuildArgs generates the arguments to Gradle for building the project as an image. -func GenerateGradleBuildArgs(task, imageName string, a *latestV1.JibArtifact, platforms platform.Matcher, skipTests, pushImages bool, deps []*latestV1.ArtifactDependency, r ArtifactResolver, insecureRegistries map[string]bool, showColors bool) []string { +func GenerateGradleBuildArgs(task, imageName string, a *latest.JibArtifact, platforms platform.Matcher, skipTests, pushImages bool, deps []*latest.ArtifactDependency, r ArtifactResolver, insecureRegistries map[string]bool, showColors bool) []string { minVersion := MinimumJibGradleVersion if platforms.IsCrossPlatform() { minVersion = MinimumJibGradleVersionForCrossPlatform @@ -120,7 +120,7 @@ func GenerateGradleBuildArgs(task, imageName string, a *latestV1.JibArtifact, pl } // Do not use directly, use gradleBuildArgsFunc -func gradleBuildArgs(task string, a *latestV1.JibArtifact, skipTests, showColors bool, minimumVersion string) []string { +func gradleBuildArgs(task string, a *latest.JibArtifact, skipTests, showColors bool, minimumVersion string) []string { // Disable jib's rich progress footer on builds. Show colors on normal builds for clearer information, // but use --console=plain for internal goals to avoid formatting issues var args []string @@ -139,7 +139,7 @@ func gradleBuildArgs(task string, a *latestV1.JibArtifact, skipTests, showColors } // Do not use directly, use gradleArgsFunc -func gradleArgs(a *latestV1.JibArtifact, task string, minimumVersion string) []string { +func gradleArgs(a *latest.JibArtifact, task string, minimumVersion string) []string { args := []string{"_skaffoldFailIfJibOutOfDate", "-Djib.requiredVersion=" + minimumVersion} if a.Project == "" { return append(args, ":"+task) diff --git a/pkg/skaffold/build/jib/gradle_test.go b/pkg/skaffold/build/jib/gradle_test.go index 3f8853f6ed9..9ddefea4436 100644 --- a/pkg/skaffold/build/jib/gradle_test.go +++ b/pkg/skaffold/build/jib/gradle_test.go @@ -32,7 +32,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -40,35 +40,35 @@ import ( func TestBuildJibGradleToDocker(t *testing.T) { tests := []struct { description string - artifact *latestV1.JibArtifact + artifact *latest.JibArtifact commands util.Command shouldErr bool expectedError string }{ { description: "build", - artifact: &latestV1.JibArtifact{}, + artifact: &latest.JibArtifact{}, commands: testutil.CmdRun( "gradle fake-gradleBuildArgs-for-jibDockerBuild --image=img:tag", ), }, { description: "build with project", - artifact: &latestV1.JibArtifact{Project: "project"}, + artifact: &latest.JibArtifact{Project: "project"}, commands: testutil.CmdRun( "gradle fake-gradleBuildArgs-for-project-for-jibDockerBuild --image=img:tag", ), }, { description: "build with custom base image", - artifact: &latestV1.JibArtifact{BaseImage: "docker://busybox"}, + artifact: &latest.JibArtifact{BaseImage: "docker://busybox"}, commands: testutil.CmdRun( "gradle fake-gradleBuildArgs-for-jibDockerBuild -Djib.from.image=docker://busybox --image=img:tag", ), }, { description: "fail build", - artifact: &latestV1.JibArtifact{}, + artifact: &latest.JibArtifact{}, commands: testutil.CmdRunErr( "gradle fake-gradleBuildArgs-for-jibDockerBuild --image=img:tag", errors.New("BUG"), @@ -87,8 +87,8 @@ func TestBuildJibGradleToDocker(t *testing.T) { localDocker := fakeLocalDaemon(api) builder := NewArtifactBuilder(localDocker, &mockConfig{}, false, false, nil) - result, err := builder.Build(context.Background(), ioutil.Discard, &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ + result, err := builder.Build(context.Background(), ioutil.Discard, &latest.Artifact{ + ArtifactType: latest.ArtifactType{ JibArtifact: test.artifact, }, }, "img:tag", platform.Matcher{}) @@ -106,35 +106,35 @@ func TestBuildJibGradleToDocker(t *testing.T) { func TestBuildJibGradleToRegistry(t *testing.T) { tests := []struct { description string - artifact *latestV1.JibArtifact + artifact *latest.JibArtifact commands util.Command shouldErr bool expectedError string }{ { description: "remote build", - artifact: &latestV1.JibArtifact{}, + artifact: &latest.JibArtifact{}, commands: testutil.CmdRun( "gradle fake-gradleBuildArgs-for-jib --image=img:tag", ), }, { description: "build with project", - artifact: &latestV1.JibArtifact{Project: "project"}, + artifact: &latest.JibArtifact{Project: "project"}, commands: testutil.CmdRun( "gradle fake-gradleBuildArgs-for-project-for-jib --image=img:tag", ), }, { description: "build with custom base image", - artifact: &latestV1.JibArtifact{BaseImage: "docker://busybox"}, + artifact: &latest.JibArtifact{BaseImage: "docker://busybox"}, commands: testutil.CmdRun( "gradle fake-gradleBuildArgs-for-jib -Djib.from.image=docker://busybox --image=img:tag", ), }, { description: "fail build", - artifact: &latestV1.JibArtifact{}, + artifact: &latest.JibArtifact{}, commands: testutil.CmdRunErr( "gradle fake-gradleBuildArgs-for-jib --image=img:tag", errors.New("BUG"), @@ -158,8 +158,8 @@ func TestBuildJibGradleToRegistry(t *testing.T) { localDocker := fakeLocalDaemon(&testutil.FakeAPIClient{}) builder := NewArtifactBuilder(localDocker, &mockConfig{}, true, false, nil) - result, err := builder.Build(context.Background(), ioutil.Discard, &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ + result, err := builder.Build(context.Background(), ioutil.Discard, &latest.Artifact{ + ArtifactType: latest.ArtifactType{ JibArtifact: test.artifact, }, }, "img:tag", platform.Matcher{}) @@ -229,7 +229,7 @@ func TestGetDependenciesGradle(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { t.Override(&util.DefaultExecCommand, testutil.CmdRunOutErr( - strings.Join(getCommandGradle(ctx, tmpDir.Root(), &latestV1.JibArtifact{Project: "gradle-test"}).Args, " "), + strings.Join(getCommandGradle(ctx, tmpDir.Root(), &latest.JibArtifact{Project: "gradle-test"}).Args, " "), test.stdout, test.err, )) @@ -240,7 +240,7 @@ func TestGetDependenciesGradle(t *testing.T) { } ws := tmpDir.Root() - deps, err := getDependenciesGradle(ctx, ws, &latestV1.JibArtifact{Project: "gradle-test"}) + deps, err := getDependenciesGradle(ctx, ws, &latest.JibArtifact{Project: "gradle-test"}) if test.err != nil { prefix := fmt.Sprintf("could not fetch dependencies for workspace %s: initial Jib dependency refresh failed: failed to get Jib dependencies: ", ws) t.CheckErrorAndDeepEqual(true, err, prefix+test.err.Error(), err.Error()) @@ -256,13 +256,13 @@ func TestGetCommandGradle(t *testing.T) { tests := []struct { description string - jibArtifact latestV1.JibArtifact + jibArtifact latest.JibArtifact filesInWorkspace []string expectedCmd func(workspace string) exec.Cmd }{ { description: "gradle default", - jibArtifact: latestV1.JibArtifact{}, + jibArtifact: latest.JibArtifact{}, filesInWorkspace: []string{}, expectedCmd: func(workspace string) exec.Cmd { return GradleCommand.CreateCommand(ctx, workspace, []string{"_skaffoldFailIfJibOutOfDate", "-Djib.requiredVersion=" + MinimumJibGradleVersion, ":_jibSkaffoldFilesV2", "-q", "--console=plain"}) @@ -270,7 +270,7 @@ func TestGetCommandGradle(t *testing.T) { }, { description: "gradle default with project", - jibArtifact: latestV1.JibArtifact{Project: "project"}, + jibArtifact: latest.JibArtifact{Project: "project"}, filesInWorkspace: []string{}, expectedCmd: func(workspace string) exec.Cmd { return GradleCommand.CreateCommand(ctx, workspace, []string{"_skaffoldFailIfJibOutOfDate", "-Djib.requiredVersion=" + MinimumJibGradleVersion, ":project:_jibSkaffoldFilesV2", "-q", "--console=plain"}) @@ -278,7 +278,7 @@ func TestGetCommandGradle(t *testing.T) { }, { description: "gradle with wrapper", - jibArtifact: latestV1.JibArtifact{}, + jibArtifact: latest.JibArtifact{}, filesInWorkspace: []string{"gradlew", "gradlew.cmd"}, expectedCmd: func(workspace string) exec.Cmd { return GradleCommand.CreateCommand(ctx, workspace, []string{"_skaffoldFailIfJibOutOfDate", "-Djib.requiredVersion=" + MinimumJibGradleVersion, ":_jibSkaffoldFilesV2", "-q", "--console=plain"}) @@ -286,7 +286,7 @@ func TestGetCommandGradle(t *testing.T) { }, { description: "gradle with wrapper and project", - jibArtifact: latestV1.JibArtifact{Project: "project"}, + jibArtifact: latest.JibArtifact{Project: "project"}, filesInWorkspace: []string{"gradlew", "gradlew.cmd"}, expectedCmd: func(workspace string) exec.Cmd { return GradleCommand.CreateCommand(ctx, workspace, []string{"_skaffoldFailIfJibOutOfDate", "-Djib.requiredVersion=" + MinimumJibGradleVersion, ":project:_jibSkaffoldFilesV2", "-q", "--console=plain"}) @@ -313,19 +313,19 @@ func TestGetSyncMapCommandGradle(t *testing.T) { tests := []struct { description string workspace string - jibArtifact latestV1.JibArtifact + jibArtifact latest.JibArtifact expectedCmd func(workspace string) exec.Cmd }{ { description: "single module", - jibArtifact: latestV1.JibArtifact{}, + jibArtifact: latest.JibArtifact{}, expectedCmd: func(workspace string) exec.Cmd { return GradleCommand.CreateCommand(ctx, workspace, []string{"fake-gradleBuildArgs-for-_jibSkaffoldSyncMap-skipTests"}) }, }, { description: "multi module", - jibArtifact: latestV1.JibArtifact{Project: "project"}, + jibArtifact: latest.JibArtifact{Project: "project"}, expectedCmd: func(workspace string) exec.Cmd { return GradleCommand.CreateCommand(ctx, workspace, []string{"fake-gradleBuildArgs-for-project-for-_jibSkaffoldSyncMap-skipTests"}) }, @@ -346,10 +346,10 @@ func TestGetSyncMapCommandGradle(t *testing.T) { func TestGenerateGradleBuildArgs(t *testing.T) { tests := []struct { description string - in latestV1.JibArtifact + in latest.JibArtifact platforms platform.Matcher expectedMinVersion string - deps []*latestV1.ArtifactDependency + deps []*latest.ArtifactDependency image string skipTests bool pushImages bool @@ -359,44 +359,44 @@ func TestGenerateGradleBuildArgs(t *testing.T) { }{ {description: "single module", image: "image", out: []string{"fake-gradleBuildArgs-for-testTask", "--image=image"}}, {description: "single module without tests", image: "image", skipTests: true, out: []string{"fake-gradleBuildArgs-for-testTask-skipTests", "--image=image"}}, - {description: "multi module", in: latestV1.JibArtifact{Project: "project"}, image: "image", out: []string{"fake-gradleBuildArgs-for-project-for-testTask", "--image=image"}}, - {description: "multi module without tests", in: latestV1.JibArtifact{Project: "project"}, image: "image", skipTests: true, out: []string{"fake-gradleBuildArgs-for-project-for-testTask-skipTests", "--image=image"}}, - {description: "multi module without tests with insecure registries", in: latestV1.JibArtifact{Project: "project"}, image: "registry.tld/image", skipTests: true, insecureRegistries: map[string]bool{"registry.tld": true}, out: []string{"fake-gradleBuildArgs-for-project-for-testTask-skipTests", "-Djib.allowInsecureRegistries=true", "--image=registry.tld/image"}}, - {description: "single module with custom base image", in: latestV1.JibArtifact{BaseImage: "docker://busybox"}, image: "image", out: []string{"fake-gradleBuildArgs-for-testTask", "-Djib.from.image=docker://busybox", "--image=image"}}, - {description: "multi module with custom base image", in: latestV1.JibArtifact{Project: "project", BaseImage: "docker://busybox"}, image: "image", out: []string{"fake-gradleBuildArgs-for-project-for-testTask", "-Djib.from.image=docker://busybox", "--image=image"}}, + {description: "multi module", in: latest.JibArtifact{Project: "project"}, image: "image", out: []string{"fake-gradleBuildArgs-for-project-for-testTask", "--image=image"}}, + {description: "multi module without tests", in: latest.JibArtifact{Project: "project"}, image: "image", skipTests: true, out: []string{"fake-gradleBuildArgs-for-project-for-testTask-skipTests", "--image=image"}}, + {description: "multi module without tests with insecure registries", in: latest.JibArtifact{Project: "project"}, image: "registry.tld/image", skipTests: true, insecureRegistries: map[string]bool{"registry.tld": true}, out: []string{"fake-gradleBuildArgs-for-project-for-testTask-skipTests", "-Djib.allowInsecureRegistries=true", "--image=registry.tld/image"}}, + {description: "single module with custom base image", in: latest.JibArtifact{BaseImage: "docker://busybox"}, image: "image", out: []string{"fake-gradleBuildArgs-for-testTask", "-Djib.from.image=docker://busybox", "--image=image"}}, + {description: "multi module with custom base image", in: latest.JibArtifact{Project: "project", BaseImage: "docker://busybox"}, image: "image", out: []string{"fake-gradleBuildArgs-for-project-for-testTask", "-Djib.from.image=docker://busybox", "--image=image"}}, {description: "host platform", image: "image", platforms: platform.Matcher{Platforms: []v1.Platform{{OS: runtime.GOOS, Architecture: runtime.GOARCH}}}, out: []string{"fake-gradleBuildArgs-for-testTask", fmt.Sprintf("-Djib.from.platforms=%s/%s", runtime.GOOS, runtime.GOARCH), "--image=image"}}, {description: "cross-platform", image: "image", platforms: platform.Matcher{Platforms: []v1.Platform{{OS: "freebsd", Architecture: "arm"}}}, out: []string{"fake-gradleBuildArgs-for-testTask", "-Djib.from.platforms=freebsd/arm", "--image=image"}, expectedMinVersion: MinimumJibGradleVersionForCrossPlatform}, {description: "multi-platform", image: "image", platforms: platform.Matcher{Platforms: []v1.Platform{{OS: "linux", Architecture: "amd64"}, {OS: "darwin", Architecture: "arm64"}}}, out: []string{"fake-gradleBuildArgs-for-testTask", "-Djib.from.platforms=linux/amd64,darwin/arm64", "--image=image"}, expectedMinVersion: MinimumJibGradleVersionForCrossPlatform}, { description: "single module with local base image from required artifacts", - in: latestV1.JibArtifact{BaseImage: "alias"}, + in: latest.JibArtifact{BaseImage: "alias"}, image: "image", - deps: []*latestV1.ArtifactDependency{{ImageName: "img", Alias: "alias"}}, + deps: []*latest.ArtifactDependency{{ImageName: "img", Alias: "alias"}}, r: mockArtifactResolver{m: map[string]string{"img": "img:tag"}}, out: []string{"fake-gradleBuildArgs-for-testTask", "-Djib.from.image=docker://img:tag", "--image=image"}, }, { description: "multi module with local base image from required artifacts", - in: latestV1.JibArtifact{Project: "project", BaseImage: "alias"}, + in: latest.JibArtifact{Project: "project", BaseImage: "alias"}, image: "image", - deps: []*latestV1.ArtifactDependency{{ImageName: "img", Alias: "alias"}}, + deps: []*latest.ArtifactDependency{{ImageName: "img", Alias: "alias"}}, r: mockArtifactResolver{m: map[string]string{"img": "img:tag"}}, out: []string{"fake-gradleBuildArgs-for-project-for-testTask", "-Djib.from.image=docker://img:tag", "--image=image"}, }, { description: "single module with remote base image from required artifacts", - in: latestV1.JibArtifact{BaseImage: "alias"}, + in: latest.JibArtifact{BaseImage: "alias"}, image: "image", pushImages: true, - deps: []*latestV1.ArtifactDependency{{ImageName: "img", Alias: "alias"}}, + deps: []*latest.ArtifactDependency{{ImageName: "img", Alias: "alias"}}, r: mockArtifactResolver{m: map[string]string{"img": "img:tag"}}, out: []string{"fake-gradleBuildArgs-for-testTask", "-Djib.from.image=img:tag", "--image=image"}, }, { description: "multi module with remote base image from required artifacts", - in: latestV1.JibArtifact{Project: "project", BaseImage: "alias"}, + in: latest.JibArtifact{Project: "project", BaseImage: "alias"}, image: "image", pushImages: true, - deps: []*latestV1.ArtifactDependency{{ImageName: "img", Alias: "alias"}}, + deps: []*latest.ArtifactDependency{{ImageName: "img", Alias: "alias"}}, r: mockArtifactResolver{m: map[string]string{"img": "img:tag"}}, out: []string{"fake-gradleBuildArgs-for-project-for-testTask", "-Djib.from.image=img:tag", "--image=image"}, }, @@ -417,17 +417,17 @@ func TestGenerateGradleBuildArgs(t *testing.T) { func TestGradleArgs(t *testing.T) { tests := []struct { description string - jibArtifact latestV1.JibArtifact + jibArtifact latest.JibArtifact expected []string }{ { description: "single module", - jibArtifact: latestV1.JibArtifact{}, + jibArtifact: latest.JibArtifact{}, expected: []string{"_skaffoldFailIfJibOutOfDate", "-Djib.requiredVersion=test-version", ":testTask"}, }, { description: "multi module", - jibArtifact: latestV1.JibArtifact{Project: "module"}, + jibArtifact: latest.JibArtifact{Project: "module"}, expected: []string{"_skaffoldFailIfJibOutOfDate", "-Djib.requiredVersion=test-version", ":module:testTask"}, }, } @@ -440,56 +440,56 @@ func TestGradleArgs(t *testing.T) { func TestGradleBuildArgs(t *testing.T) { tests := []struct { description string - jibArtifact latestV1.JibArtifact + jibArtifact latest.JibArtifact skipTests bool showColors bool expected []string }{ { description: "single module", - jibArtifact: latestV1.JibArtifact{}, + jibArtifact: latest.JibArtifact{}, skipTests: false, showColors: true, expected: []string{"-Djib.console=plain", "fake-gradleArgs-for-testTask"}, }, { description: "single module skip tests", - jibArtifact: latestV1.JibArtifact{}, + jibArtifact: latest.JibArtifact{}, skipTests: true, showColors: true, expected: []string{"-Djib.console=plain", "fake-gradleArgs-for-testTask", "-x", "test"}, }, { description: "single module plain console", - jibArtifact: latestV1.JibArtifact{}, + jibArtifact: latest.JibArtifact{}, skipTests: true, showColors: false, expected: []string{"--console=plain", "fake-gradleArgs-for-testTask", "-x", "test"}, }, { description: "single module with extra flags", - jibArtifact: latestV1.JibArtifact{Flags: []string{"--flag1", "--flag2"}}, + jibArtifact: latest.JibArtifact{Flags: []string{"--flag1", "--flag2"}}, skipTests: false, showColors: true, expected: []string{"-Djib.console=plain", "fake-gradleArgs-for-testTask", "--flag1", "--flag2"}, }, { description: "multi module", - jibArtifact: latestV1.JibArtifact{Project: "module"}, + jibArtifact: latest.JibArtifact{Project: "module"}, skipTests: false, showColors: true, expected: []string{"-Djib.console=plain", "fake-gradleArgs-for-module-for-testTask"}, }, { description: "single module skip tests", - jibArtifact: latestV1.JibArtifact{Project: "module"}, + jibArtifact: latest.JibArtifact{Project: "module"}, skipTests: true, showColors: true, expected: []string{"-Djib.console=plain", "fake-gradleArgs-for-module-for-testTask", "-x", "test"}, }, { description: "multi module with extra flags", - jibArtifact: latestV1.JibArtifact{Project: "module", Flags: []string{"--flag1", "--flag2"}}, + jibArtifact: latest.JibArtifact{Project: "module", Flags: []string{"--flag1", "--flag2"}}, skipTests: false, showColors: true, expected: []string{"-Djib.console=plain", "fake-gradleArgs-for-module-for-testTask", "--flag1", "--flag2"}, @@ -504,8 +504,8 @@ func TestGradleBuildArgs(t *testing.T) { } } -func getGradleArgsFuncFake(t *testutil.T, expectedMinimumVersion string) func(*latestV1.JibArtifact, string, string) []string { - return func(a *latestV1.JibArtifact, task string, minimumVersion string) []string { +func getGradleArgsFuncFake(t *testutil.T, expectedMinimumVersion string) func(*latest.JibArtifact, string, string) []string { + return func(a *latest.JibArtifact, task string, minimumVersion string) []string { t.CheckDeepEqual(expectedMinimumVersion, minimumVersion) if a.Project == "" { return []string{"fake-gradleArgs-for-" + task} @@ -515,8 +515,8 @@ func getGradleArgsFuncFake(t *testutil.T, expectedMinimumVersion string) func(*l } // check that parameters are actually passed though -func getGradleBuildArgsFuncFake(t *testutil.T, expectedMinimumVersion string) func(string, *latestV1.JibArtifact, bool, bool, string) []string { - return func(task string, a *latestV1.JibArtifact, skipTests, showColors bool, minimumVersion string) []string { +func getGradleBuildArgsFuncFake(t *testutil.T, expectedMinimumVersion string) func(string, *latest.JibArtifact, bool, bool, string) []string { + return func(task string, a *latest.JibArtifact, skipTests, showColors bool, minimumVersion string) []string { t.CheckDeepEqual(expectedMinimumVersion, minimumVersion) testString := "" diff --git a/pkg/skaffold/build/jib/init.go b/pkg/skaffold/build/jib/init.go index 2867c161534..debbafc1bba 100644 --- a/pkg/skaffold/build/jib/init.go +++ b/pkg/skaffold/build/jib/init.go @@ -28,7 +28,7 @@ import ( "strings" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -59,9 +59,9 @@ func (c ArtifactConfig) Describe() string { } // ArtifactType returns the type of the artifact to be built. -func (c ArtifactConfig) ArtifactType(_ string) latestV1.ArtifactType { - return latestV1.ArtifactType{ - JibArtifact: &latestV1.JibArtifact{ +func (c ArtifactConfig) ArtifactType(_ string) latest.ArtifactType { + return latest.ArtifactType{ + JibArtifact: &latest.JibArtifact{ Project: c.Project, }, } diff --git a/pkg/skaffold/build/jib/init_test.go b/pkg/skaffold/build/jib/init_test.go index 29469a17a66..6ed7df44f2e 100644 --- a/pkg/skaffold/build/jib/init_test.go +++ b/pkg/skaffold/build/jib/init_test.go @@ -21,7 +21,7 @@ import ( "path/filepath" "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -218,27 +218,27 @@ func TestArtifactType(t *testing.T) { var tests = []struct { description string config ArtifactConfig - expectedType latestV1.ArtifactType + expectedType latest.ArtifactType }{ { description: "jib gradle", config: ArtifactConfig{BuilderName: "Jib Gradle Plugin", File: filepath.Join("path", "to", "build.gradle"), Project: "project"}, - expectedType: latestV1.ArtifactType{JibArtifact: &latestV1.JibArtifact{Project: "project"}}, + expectedType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{Project: "project"}}, }, { description: "jib gradle without project", config: ArtifactConfig{BuilderName: "Jib Gradle Plugin", File: filepath.Join("path", "to", "build.gradle")}, - expectedType: latestV1.ArtifactType{JibArtifact: &latestV1.JibArtifact{}}, + expectedType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{}}, }, { description: "jib maven", config: ArtifactConfig{BuilderName: "Jib Maven Plugin", File: filepath.Join("path", "to", "pom.xml"), Project: "project"}, - expectedType: latestV1.ArtifactType{JibArtifact: &latestV1.JibArtifact{Project: "project"}}, + expectedType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{Project: "project"}}, }, { description: "jib maven without project", config: ArtifactConfig{BuilderName: "Jib Maven Plugin", File: filepath.Join("path", "to", "pom.xml")}, - expectedType: latestV1.ArtifactType{JibArtifact: &latestV1.JibArtifact{}}, + expectedType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{}}, }, } for _, test := range tests { diff --git a/pkg/skaffold/build/jib/jib.go b/pkg/skaffold/build/jib/jib.go index 85f9036c691..888ac35722b 100644 --- a/pkg/skaffold/build/jib/jib.go +++ b/pkg/skaffold/build/jib/jib.go @@ -34,7 +34,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/walk" ) @@ -91,16 +91,16 @@ var watchedFiles = map[projectKey]filesLists{} type projectKey string -func getProjectKey(workspace string, a *latestV1.JibArtifact) projectKey { +func getProjectKey(workspace string, a *latest.JibArtifact) projectKey { return projectKey(workspace + "+" + a.Project) } -func GetBuildDefinitions(workspace string, a *latestV1.JibArtifact) []string { +func GetBuildDefinitions(workspace string, a *latest.JibArtifact) []string { return watchedFiles[getProjectKey(workspace, a)].BuildDefinitions } // GetDependencies returns a list of files to watch for changes to rebuild -func GetDependencies(ctx context.Context, workspace string, artifact *latestV1.JibArtifact) ([]string, error) { +func GetDependencies(ctx context.Context, workspace string, artifact *latest.JibArtifact) ([]string, error) { t, err := DeterminePluginType(ctx, workspace, artifact) if err != nil { return nil, unableToDeterminePluginType(workspace, err) @@ -116,7 +116,7 @@ func GetDependencies(ctx context.Context, workspace string, artifact *latestV1.J } // DeterminePluginType tries to determine the Jib plugin type for the given artifact. -func DeterminePluginType(ctx context.Context, workspace string, artifact *latestV1.JibArtifact) (PluginType, error) { +func DeterminePluginType(ctx context.Context, workspace string, artifact *latest.JibArtifact) (PluginType, error) { if !JVMFound(ctx) { return "", errors.New("no working JVM available") } @@ -142,7 +142,7 @@ func DeterminePluginType(ctx context.Context, workspace string, artifact *latest } // getDependencies returns a list of files to watch for changes to rebuild -func getDependencies(ctx context.Context, workspace string, cmd exec.Cmd, a *latestV1.JibArtifact) ([]string, error) { +func getDependencies(ctx context.Context, workspace string, cmd exec.Cmd, a *latest.JibArtifact) ([]string, error) { var dependencyList []string files, ok := watchedFiles[getProjectKey(workspace, a)] if !ok { @@ -331,7 +331,7 @@ func isOnInsecureRegistry(image string, insecureRegistries map[string]bool) (boo } // baseImageArg formats the base image as a build argument. It also replaces the provided base image with an image from the required artifacts if specified. -func baseImageArg(a *latestV1.JibArtifact, r ArtifactResolver, deps []*latestV1.ArtifactDependency, pushImages bool) (string, bool) { +func baseImageArg(a *latest.JibArtifact, r ArtifactResolver, deps []*latest.ArtifactDependency, pushImages bool) (string, bool) { if a.BaseImage == "" { return "", false } diff --git a/pkg/skaffold/build/jib/jib_test.go b/pkg/skaffold/build/jib/jib_test.go index d0e7f3efafc..d519fe9d488 100644 --- a/pkg/skaffold/build/jib/jib_test.go +++ b/pkg/skaffold/build/jib/jib_test.go @@ -26,7 +26,7 @@ import ( "github.com/docker/docker/client" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -107,7 +107,7 @@ func TestGetDependencies(t *testing.T) { test.stdout, )) - results, err := getDependencies(context.Background(), tmpDir.Root(), exec.Cmd{Args: []string{"ignored"}, Dir: tmpDir.Root()}, &latestV1.JibArtifact{Project: util.RandomID()}) + results, err := getDependencies(context.Background(), tmpDir.Root(), exec.Cmd{Args: []string{"ignored"}, Dir: tmpDir.Root()}, &latest.JibArtifact{Project: util.RandomID()}) t.CheckErrorAndDeepEqual(test.shouldErr, err, test.expectedDeps, results) }) @@ -126,7 +126,7 @@ func TestGetUpdatedDependencies(t *testing.T) { ) listCmd := exec.Cmd{Args: []string{"ignored"}, Dir: tmpDir.Root()} - artifact := &latestV1.JibArtifact{Project: util.RandomID()} + artifact := &latest.JibArtifact{Project: util.RandomID()} // List dependencies _, err := getDependencies(context.Background(), tmpDir.Root(), listCmd, artifact) @@ -170,7 +170,7 @@ func TestDeterminePluginType(t *testing.T) { tests := []struct { description string files []string - artifact *latestV1.JibArtifact + artifact *latest.JibArtifact shouldErr bool PluginType PluginType }{ @@ -184,8 +184,8 @@ func TestDeterminePluginType(t *testing.T) { {"maven-1", []string{"pom.xml"}, nil, false, JibMaven}, {"maven-2", []string{".mvn/maven.config"}, nil, false, JibMaven}, {"maven-3", []string{".mvn/extensions.xml"}, nil, false, JibMaven}, - {"gradle override", []string{"pom.xml"}, &latestV1.JibArtifact{Type: string(JibGradle)}, false, JibGradle}, - {"maven override", []string{"build.gradle"}, &latestV1.JibArtifact{Type: string(JibMaven)}, false, JibMaven}, + {"gradle override", []string{"pom.xml"}, &latest.JibArtifact{Type: string(JibGradle)}, false, JibGradle}, + {"maven override", []string{"build.gradle"}, &latest.JibArtifact{Type: string(JibMaven)}, false, JibMaven}, } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { @@ -200,19 +200,19 @@ func TestDeterminePluginType(t *testing.T) { func TestGetProjectKey(t *testing.T) { tests := []struct { description string - artifact *latestV1.JibArtifact + artifact *latest.JibArtifact workspace string expected projectKey }{ { "empty project", - &latestV1.JibArtifact{}, + &latest.JibArtifact{}, "dir", projectKey("dir+"), }, { "non-empty project", - &latestV1.JibArtifact{Project: "project"}, + &latest.JibArtifact{Project: "project"}, "dir", projectKey("dir+project"), }, diff --git a/pkg/skaffold/build/jib/maven.go b/pkg/skaffold/build/jib/maven.go index b7b3c5ca278..c33329e9a38 100644 --- a/pkg/skaffold/build/jib/maven.go +++ b/pkg/skaffold/build/jib/maven.go @@ -26,7 +26,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -44,7 +44,7 @@ const MinimumJibMavenVersionForCrossPlatform = "3.2.0" // MavenCommand stores Maven executable and wrapper name var MavenCommand = util.CommandWrapper{Executable: "mvn", Wrapper: "mvnw"} -func (b *Builder) buildJibMavenToDocker(ctx context.Context, out io.Writer, workspace string, artifact *latestV1.JibArtifact, deps []*latestV1.ArtifactDependency, tag string, platforms platform.Matcher) (string, error) { +func (b *Builder) buildJibMavenToDocker(ctx context.Context, out io.Writer, workspace string, artifact *latest.JibArtifact, deps []*latest.ArtifactDependency, tag string, platforms platform.Matcher) (string, error) { args := GenerateMavenBuildArgs("dockerBuild", tag, artifact, platforms, b.skipTests, b.pushImages, deps, b.artifacts, b.cfg.GetInsecureRegistries(), output.IsColorable(out)) if err := b.runMavenCommand(ctx, out, workspace, args); err != nil { return "", jibToolErr(err) @@ -53,7 +53,7 @@ func (b *Builder) buildJibMavenToDocker(ctx context.Context, out io.Writer, work return b.localDocker.ImageID(ctx, tag) } -func (b *Builder) buildJibMavenToRegistry(ctx context.Context, out io.Writer, workspace string, artifact *latestV1.JibArtifact, deps []*latestV1.ArtifactDependency, tag string, platforms platform.Matcher) (string, error) { +func (b *Builder) buildJibMavenToRegistry(ctx context.Context, out io.Writer, workspace string, artifact *latest.JibArtifact, deps []*latest.ArtifactDependency, tag string, platforms platform.Matcher) (string, error) { args := GenerateMavenBuildArgs("build", tag, artifact, platforms, b.skipTests, b.pushImages, deps, b.artifacts, b.cfg.GetInsecureRegistries(), output.IsColorable(out)) if err := b.runMavenCommand(ctx, out, workspace, args); err != nil { return "", jibToolErr(err) @@ -78,7 +78,7 @@ func (b *Builder) runMavenCommand(ctx context.Context, out io.Writer, workspace // getDependenciesMaven finds the source dependencies for the given jib-maven artifact. // All paths are absolute. -func getDependenciesMaven(ctx context.Context, workspace string, a *latestV1.JibArtifact) ([]string, error) { +func getDependenciesMaven(ctx context.Context, workspace string, a *latest.JibArtifact) ([]string, error) { deps, err := getDependencies(ctx, workspace, getCommandMaven(ctx, workspace, a), a) if err != nil { return nil, dependencyErr(JibMaven, workspace, err) @@ -87,20 +87,20 @@ func getDependenciesMaven(ctx context.Context, workspace string, a *latestV1.Jib return deps, nil } -func getCommandMaven(ctx context.Context, workspace string, a *latestV1.JibArtifact) exec.Cmd { +func getCommandMaven(ctx context.Context, workspace string, a *latest.JibArtifact) exec.Cmd { args := mavenArgsFunc(a, MinimumJibMavenVersion) args = append(args, "jib:_skaffold-files-v2", "--quiet", "--batch-mode") return MavenCommand.CreateCommand(ctx, workspace, args) } -func getSyncMapCommandMaven(ctx context.Context, workspace string, a *latestV1.JibArtifact) *exec.Cmd { +func getSyncMapCommandMaven(ctx context.Context, workspace string, a *latest.JibArtifact) *exec.Cmd { cmd := MavenCommand.CreateCommand(ctx, workspace, mavenBuildArgsFunc("_skaffold-sync-map", a, true, false, MinimumJibMavenVersionForSync)) return &cmd } // GenerateMavenBuildArgs generates the arguments to Maven for building the project as an image. -func GenerateMavenBuildArgs(goal, imageName string, a *latestV1.JibArtifact, platforms platform.Matcher, skipTests, pushImages bool, deps []*latestV1.ArtifactDependency, r ArtifactResolver, insecureRegistries map[string]bool, showColors bool) []string { +func GenerateMavenBuildArgs(goal, imageName string, a *latest.JibArtifact, platforms platform.Matcher, skipTests, pushImages bool, deps []*latest.ArtifactDependency, r ArtifactResolver, insecureRegistries map[string]bool, showColors bool) []string { minVersion := MinimumJibMavenVersion if platforms.IsCrossPlatform() { minVersion = MinimumJibMavenVersionForCrossPlatform @@ -121,7 +121,7 @@ func GenerateMavenBuildArgs(goal, imageName string, a *latestV1.JibArtifact, pla } // Do not use directly, use mavenBuildArgsFunc -func mavenBuildArgs(goal string, a *latestV1.JibArtifact, skipTests, showColors bool, minimumVersion string) []string { +func mavenBuildArgs(goal string, a *latest.JibArtifact, skipTests, showColors bool, minimumVersion string) []string { // Disable jib's rich progress footer on builds. Show colors on normal builds for clearer information, // but use --batch-mode for internal goals to avoid formatting issues var args []string @@ -147,7 +147,7 @@ func mavenBuildArgs(goal string, a *latestV1.JibArtifact, skipTests, showColors } // Do not use directly, use mavenArgsFunc -func mavenArgs(a *latestV1.JibArtifact, minimumVersion string) []string { +func mavenArgs(a *latest.JibArtifact, minimumVersion string) []string { args := []string{"jib:_skaffold-fail-if-jib-out-of-date", "-Djib.requiredVersion=" + minimumVersion} args = append(args, a.Flags...) diff --git a/pkg/skaffold/build/jib/maven_test.go b/pkg/skaffold/build/jib/maven_test.go index ade9a843f8f..95c426f2706 100644 --- a/pkg/skaffold/build/jib/maven_test.go +++ b/pkg/skaffold/build/jib/maven_test.go @@ -32,7 +32,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -40,35 +40,35 @@ import ( func TestBuildJibMavenToDocker(t *testing.T) { tests := []struct { description string - artifact *latestV1.JibArtifact + artifact *latest.JibArtifact commands util.Command shouldErr bool expectedError string }{ { description: "build", - artifact: &latestV1.JibArtifact{}, + artifact: &latest.JibArtifact{}, commands: testutil.CmdRun( "mvn fake-mavenBuildArgs-for-dockerBuild -Dimage=img:tag", ), }, { description: "build with module", - artifact: &latestV1.JibArtifact{Project: "module"}, + artifact: &latest.JibArtifact{Project: "module"}, commands: testutil.CmdRun( "mvn fake-mavenBuildArgs-for-module-for-dockerBuild -Dimage=img:tag", ), }, { description: "build with custom base image", - artifact: &latestV1.JibArtifact{BaseImage: "docker://busybox"}, + artifact: &latest.JibArtifact{BaseImage: "docker://busybox"}, commands: testutil.CmdRun( "mvn fake-mavenBuildArgs-for-dockerBuild -Djib.from.image=docker://busybox -Dimage=img:tag", ), }, { description: "fail build", - artifact: &latestV1.JibArtifact{}, + artifact: &latest.JibArtifact{}, commands: testutil.CmdRunErr( "mvn fake-mavenBuildArgs-for-dockerBuild -Dimage=img:tag", errors.New("BUG"), @@ -87,8 +87,8 @@ func TestBuildJibMavenToDocker(t *testing.T) { localDocker := fakeLocalDaemon(api) builder := NewArtifactBuilder(localDocker, &mockConfig{}, false, false, mockArtifactResolver{}) - result, err := builder.Build(context.Background(), ioutil.Discard, &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ + result, err := builder.Build(context.Background(), ioutil.Discard, &latest.Artifact{ + ArtifactType: latest.ArtifactType{ JibArtifact: test.artifact, }, }, "img:tag", platform.Matcher{}) @@ -106,29 +106,29 @@ func TestBuildJibMavenToDocker(t *testing.T) { func TestBuildJibMavenToRegistry(t *testing.T) { tests := []struct { description string - artifact *latestV1.JibArtifact + artifact *latest.JibArtifact commands util.Command shouldErr bool expectedError string }{ { description: "build", - artifact: &latestV1.JibArtifact{}, + artifact: &latest.JibArtifact{}, commands: testutil.CmdRun("mvn fake-mavenBuildArgs-for-build -Dimage=img:tag"), }, { description: "build with module", - artifact: &latestV1.JibArtifact{Project: "module"}, + artifact: &latest.JibArtifact{Project: "module"}, commands: testutil.CmdRun("mvn fake-mavenBuildArgs-for-module-for-build -Dimage=img:tag"), }, { description: "build with custom base image", - artifact: &latestV1.JibArtifact{BaseImage: "docker://busybox"}, + artifact: &latest.JibArtifact{BaseImage: "docker://busybox"}, commands: testutil.CmdRun("mvn fake-mavenBuildArgs-for-build -Djib.from.image=docker://busybox -Dimage=img:tag"), }, { description: "fail build", - artifact: &latestV1.JibArtifact{}, + artifact: &latest.JibArtifact{}, commands: testutil.CmdRunErr( "mvn fake-mavenBuildArgs-for-build -Dimage=img:tag", errors.New("BUG"), @@ -152,8 +152,8 @@ func TestBuildJibMavenToRegistry(t *testing.T) { localDocker := fakeLocalDaemon(&testutil.FakeAPIClient{}) builder := NewArtifactBuilder(localDocker, &mockConfig{}, true, false, mockArtifactResolver{}) - result, err := builder.Build(context.Background(), ioutil.Discard, &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ + result, err := builder.Build(context.Background(), ioutil.Discard, &latest.Artifact{ + ArtifactType: latest.ArtifactType{ JibArtifact: test.artifact, }, }, "img:tag", platform.Matcher{}) @@ -223,7 +223,7 @@ func TestGetDependenciesMaven(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { t.Override(&util.DefaultExecCommand, testutil.CmdRunOutErr( - strings.Join(getCommandMaven(ctx, tmpDir.Root(), &latestV1.JibArtifact{Project: "maven-test"}).Args, " "), + strings.Join(getCommandMaven(ctx, tmpDir.Root(), &latest.JibArtifact{Project: "maven-test"}).Args, " "), test.stdout, test.err, )) @@ -233,7 +233,7 @@ func TestGetDependenciesMaven(t *testing.T) { t.Fatal(err) } ws := tmpDir.Root() - deps, err := getDependenciesMaven(ctx, ws, &latestV1.JibArtifact{Project: "maven-test"}) + deps, err := getDependenciesMaven(ctx, ws, &latest.JibArtifact{Project: "maven-test"}) if test.err != nil { prefix := fmt.Sprintf("could not fetch dependencies for workspace %s: initial Jib dependency refresh failed: failed to get Jib dependencies: ", ws) t.CheckErrorAndDeepEqual(true, err, prefix+test.err.Error(), err.Error()) @@ -248,13 +248,13 @@ func TestGetCommandMaven(t *testing.T) { ctx := context.Background() tests := []struct { description string - jibArtifact latestV1.JibArtifact + jibArtifact latest.JibArtifact filesInWorkspace []string expectedCmd func(workspace string) exec.Cmd }{ { description: "maven basic", - jibArtifact: latestV1.JibArtifact{}, + jibArtifact: latest.JibArtifact{}, filesInWorkspace: []string{}, expectedCmd: func(workspace string) exec.Cmd { return MavenCommand.CreateCommand(ctx, workspace, []string{"fake-mavenArgs", "jib:_skaffold-files-v2", "--quiet", "--batch-mode"}) @@ -262,7 +262,7 @@ func TestGetCommandMaven(t *testing.T) { }, { description: "maven with wrapper", - jibArtifact: latestV1.JibArtifact{}, + jibArtifact: latest.JibArtifact{}, filesInWorkspace: []string{"mvnw", "mvnw.bat"}, expectedCmd: func(workspace string) exec.Cmd { return MavenCommand.CreateCommand(ctx, workspace, []string{"fake-mavenArgs", "jib:_skaffold-files-v2", "--quiet", "--batch-mode"}) @@ -270,7 +270,7 @@ func TestGetCommandMaven(t *testing.T) { }, { description: "maven with multi-modules", - jibArtifact: latestV1.JibArtifact{Project: "module"}, + jibArtifact: latest.JibArtifact{Project: "module"}, filesInWorkspace: []string{"mvnw", "mvnw.bat"}, expectedCmd: func(workspace string) exec.Cmd { return MavenCommand.CreateCommand(ctx, workspace, []string{"fake-mavenArgs-for-module", "jib:_skaffold-files-v2", "--quiet", "--batch-mode"}) @@ -298,19 +298,19 @@ func TestGetSyncMapCommandMaven(t *testing.T) { tests := []struct { description string workspace string - jibArtifact latestV1.JibArtifact + jibArtifact latest.JibArtifact expectedCmd func(workspace string) exec.Cmd }{ { description: "single module", - jibArtifact: latestV1.JibArtifact{}, + jibArtifact: latest.JibArtifact{}, expectedCmd: func(workspace string) exec.Cmd { return MavenCommand.CreateCommand(ctx, workspace, []string{"fake-mavenBuildArgs-for-_skaffold-sync-map-skipTests"}) }, }, { description: "multi module", - jibArtifact: latestV1.JibArtifact{Project: "module"}, + jibArtifact: latest.JibArtifact{Project: "module"}, expectedCmd: func(workspace string) exec.Cmd { return MavenCommand.CreateCommand(ctx, workspace, []string{"fake-mavenBuildArgs-for-module-for-_skaffold-sync-map-skipTests"}) }, @@ -331,9 +331,9 @@ func TestGetSyncMapCommandMaven(t *testing.T) { func TestGenerateMavenBuildArgs(t *testing.T) { tests := []struct { description string - a latestV1.JibArtifact + a latest.JibArtifact platforms platform.Matcher - deps []*latestV1.ArtifactDependency + deps []*latest.ArtifactDependency image string expectedMinVersion string r ArtifactResolver @@ -344,34 +344,34 @@ func TestGenerateMavenBuildArgs(t *testing.T) { }{ {description: "single module", image: "image", out: []string{"fake-mavenBuildArgs-for-test-goal", "-Dimage=image"}}, {description: "single module without tests", image: "image", skipTests: true, out: []string{"fake-mavenBuildArgs-for-test-goal-skipTests", "-Dimage=image"}}, - {description: "multi module", a: latestV1.JibArtifact{Project: "module"}, image: "image", out: []string{"fake-mavenBuildArgs-for-module-for-test-goal", "-Dimage=image"}}, - {description: "multi module without tests", a: latestV1.JibArtifact{Project: "module"}, image: "image", skipTests: true, out: []string{"fake-mavenBuildArgs-for-module-for-test-goal-skipTests", "-Dimage=image"}}, - {description: "multi module without tests with insecure-registry", a: latestV1.JibArtifact{Project: "module"}, image: "registry.tld/image", skipTests: true, insecureRegistries: map[string]bool{"registry.tld": true}, out: []string{"fake-mavenBuildArgs-for-module-for-test-goal-skipTests", "-Djib.allowInsecureRegistries=true", "-Dimage=registry.tld/image"}}, - {description: "single module with custom base image", a: latestV1.JibArtifact{BaseImage: "docker://busybox"}, image: "image", out: []string{"fake-mavenBuildArgs-for-test-goal", "-Djib.from.image=docker://busybox", "-Dimage=image"}}, - {description: "multi module with custom base image", a: latestV1.JibArtifact{Project: "module", BaseImage: "docker://busybox"}, image: "image", out: []string{"fake-mavenBuildArgs-for-module-for-test-goal", "-Djib.from.image=docker://busybox", "-Dimage=image"}}, + {description: "multi module", a: latest.JibArtifact{Project: "module"}, image: "image", out: []string{"fake-mavenBuildArgs-for-module-for-test-goal", "-Dimage=image"}}, + {description: "multi module without tests", a: latest.JibArtifact{Project: "module"}, image: "image", skipTests: true, out: []string{"fake-mavenBuildArgs-for-module-for-test-goal-skipTests", "-Dimage=image"}}, + {description: "multi module without tests with insecure-registry", a: latest.JibArtifact{Project: "module"}, image: "registry.tld/image", skipTests: true, insecureRegistries: map[string]bool{"registry.tld": true}, out: []string{"fake-mavenBuildArgs-for-module-for-test-goal-skipTests", "-Djib.allowInsecureRegistries=true", "-Dimage=registry.tld/image"}}, + {description: "single module with custom base image", a: latest.JibArtifact{BaseImage: "docker://busybox"}, image: "image", out: []string{"fake-mavenBuildArgs-for-test-goal", "-Djib.from.image=docker://busybox", "-Dimage=image"}}, + {description: "multi module with custom base image", a: latest.JibArtifact{Project: "module", BaseImage: "docker://busybox"}, image: "image", out: []string{"fake-mavenBuildArgs-for-module-for-test-goal", "-Djib.from.image=docker://busybox", "-Dimage=image"}}, {description: "host platform", image: "image", platforms: platform.Matcher{Platforms: []v1.Platform{{OS: runtime.GOOS, Architecture: runtime.GOARCH}}}, out: []string{"fake-mavenBuildArgs-for-test-goal", fmt.Sprintf("-Djib.from.platforms=%s/%s", runtime.GOOS, runtime.GOARCH), "-Dimage=image"}}, {description: "cross-platform", image: "image", platforms: platform.Matcher{Platforms: []v1.Platform{{OS: "freebsd", Architecture: "arm"}}}, out: []string{"fake-mavenBuildArgs-for-test-goal", "-Djib.from.platforms=freebsd/arm", "-Dimage=image"}, expectedMinVersion: MinimumJibMavenVersionForCrossPlatform}, {description: "multi-platform", image: "image", platforms: platform.Matcher{Platforms: []v1.Platform{{OS: "linux", Architecture: "amd64"}, {OS: "darwin", Architecture: "arm64"}}}, out: []string{"fake-mavenBuildArgs-for-test-goal", "-Djib.from.platforms=linux/amd64,darwin/arm64", "-Dimage=image"}, expectedMinVersion: MinimumJibMavenVersionForCrossPlatform}, { description: "single module with local base image from required artifacts", - a: latestV1.JibArtifact{BaseImage: "alias"}, - deps: []*latestV1.ArtifactDependency{{ImageName: "img", Alias: "alias"}}, + a: latest.JibArtifact{BaseImage: "alias"}, + deps: []*latest.ArtifactDependency{{ImageName: "img", Alias: "alias"}}, image: "image", r: mockArtifactResolver{m: map[string]string{"img": "img:tag"}}, out: []string{"fake-mavenBuildArgs-for-test-goal", "-Djib.from.image=docker://img:tag", "-Dimage=image"}, }, { description: "multi module with local base image from required artifacts", - a: latestV1.JibArtifact{Project: "module", BaseImage: "alias"}, - deps: []*latestV1.ArtifactDependency{{ImageName: "img", Alias: "alias"}}, + a: latest.JibArtifact{Project: "module", BaseImage: "alias"}, + deps: []*latest.ArtifactDependency{{ImageName: "img", Alias: "alias"}}, image: "image", r: mockArtifactResolver{m: map[string]string{"img": "img:tag"}}, out: []string{"fake-mavenBuildArgs-for-module-for-test-goal", "-Djib.from.image=docker://img:tag", "-Dimage=image"}, }, { description: "single module with remote base image from required artifacts", - a: latestV1.JibArtifact{BaseImage: "alias"}, - deps: []*latestV1.ArtifactDependency{{ImageName: "img", Alias: "alias"}}, + a: latest.JibArtifact{BaseImage: "alias"}, + deps: []*latest.ArtifactDependency{{ImageName: "img", Alias: "alias"}}, image: "image", pushImages: true, r: mockArtifactResolver{m: map[string]string{"img": "img:tag"}}, @@ -379,8 +379,8 @@ func TestGenerateMavenBuildArgs(t *testing.T) { }, { description: "multi module with remote base image from required artifacts", - a: latestV1.JibArtifact{Project: "module", BaseImage: "alias"}, - deps: []*latestV1.ArtifactDependency{{ImageName: "img", Alias: "alias"}}, + a: latest.JibArtifact{Project: "module", BaseImage: "alias"}, + deps: []*latest.ArtifactDependency{{ImageName: "img", Alias: "alias"}}, image: "image", pushImages: true, r: mockArtifactResolver{m: map[string]string{"img": "img:tag"}}, @@ -403,42 +403,42 @@ func TestGenerateMavenBuildArgs(t *testing.T) { func TestMavenBuildArgs(t *testing.T) { tests := []struct { description string - jibArtifact latestV1.JibArtifact + jibArtifact latest.JibArtifact skipTests bool showColors bool expected []string }{ { description: "single module", - jibArtifact: latestV1.JibArtifact{}, + jibArtifact: latest.JibArtifact{}, skipTests: false, showColors: true, expected: []string{"-Dstyle.color=always", "-Djansi.passthrough=true", "-Djib.console=plain", "fake-mavenArgs", "prepare-package", "jib:test-goal"}, }, { description: "single module skip tests", - jibArtifact: latestV1.JibArtifact{}, + jibArtifact: latest.JibArtifact{}, skipTests: true, showColors: true, expected: []string{"-Dstyle.color=always", "-Djansi.passthrough=true", "-Djib.console=plain", "fake-mavenArgs", "-DskipTests=true", "prepare-package", "jib:test-goal"}, }, { description: "single module plain console", - jibArtifact: latestV1.JibArtifact{}, + jibArtifact: latest.JibArtifact{}, skipTests: true, showColors: false, expected: []string{"--batch-mode", "fake-mavenArgs", "-DskipTests=true", "prepare-package", "jib:test-goal"}, }, { description: "multi module", - jibArtifact: latestV1.JibArtifact{Project: "module"}, + jibArtifact: latest.JibArtifact{Project: "module"}, skipTests: false, showColors: true, expected: []string{"-Dstyle.color=always", "-Djansi.passthrough=true", "-Djib.console=plain", "fake-mavenArgs-for-module", "package", "jib:test-goal", "-Djib.containerize=module"}, }, { description: "single module skip tests", - jibArtifact: latestV1.JibArtifact{Project: "module"}, + jibArtifact: latest.JibArtifact{Project: "module"}, skipTests: true, showColors: true, expected: []string{"-Dstyle.color=always", "-Djansi.passthrough=true", "-Djib.console=plain", "fake-mavenArgs-for-module", "-DskipTests=true", "package", "jib:test-goal", "-Djib.containerize=module"}, @@ -456,29 +456,29 @@ func TestMavenBuildArgs(t *testing.T) { func TestMavenArgs(t *testing.T) { tests := []struct { description string - jibArtifact latestV1.JibArtifact + jibArtifact latest.JibArtifact expected []string }{ { description: "single module", - jibArtifact: latestV1.JibArtifact{}, + jibArtifact: latest.JibArtifact{}, expected: []string{"jib:_skaffold-fail-if-jib-out-of-date", "-Djib.requiredVersion=test-version", "--non-recursive"}, }, { description: "single module with extra flags", - jibArtifact: latestV1.JibArtifact{ + jibArtifact: latest.JibArtifact{ Flags: []string{"--flag1", "--flag2"}, }, expected: []string{"jib:_skaffold-fail-if-jib-out-of-date", "-Djib.requiredVersion=test-version", "--flag1", "--flag2", "--non-recursive"}, }, { description: "multi module", - jibArtifact: latestV1.JibArtifact{Project: "module"}, + jibArtifact: latest.JibArtifact{Project: "module"}, expected: []string{"jib:_skaffold-fail-if-jib-out-of-date", "-Djib.requiredVersion=test-version", "--projects", "module", "--also-make"}, }, { description: "multi module with extra falgs", - jibArtifact: latestV1.JibArtifact{ + jibArtifact: latest.JibArtifact{ Project: "module", Flags: []string{"--flag1", "--flag2"}, }, @@ -491,8 +491,8 @@ func TestMavenArgs(t *testing.T) { } } -func getMavenArgsFuncFake(t *testutil.T, expectedMinimumVersion string) func(*latestV1.JibArtifact, string) []string { - return func(a *latestV1.JibArtifact, minimumVersion string) []string { +func getMavenArgsFuncFake(t *testutil.T, expectedMinimumVersion string) func(*latest.JibArtifact, string) []string { + return func(a *latest.JibArtifact, minimumVersion string) []string { t.CheckDeepEqual(expectedMinimumVersion, minimumVersion) if a.Project == "" { return []string{"fake-mavenArgs"} @@ -501,8 +501,8 @@ func getMavenArgsFuncFake(t *testutil.T, expectedMinimumVersion string) func(*la } } -func getMavenBuildArgsFuncFake(t *testutil.T, expectedMinimumVersion string) func(string, *latestV1.JibArtifact, bool, bool, string) []string { - return func(goal string, a *latestV1.JibArtifact, skipTests, showColors bool, minimumVersion string) []string { +func getMavenBuildArgsFuncFake(t *testutil.T, expectedMinimumVersion string) func(string, *latest.JibArtifact, bool, bool, string) []string { + return func(goal string, a *latest.JibArtifact, skipTests, showColors bool, minimumVersion string) []string { t.CheckDeepEqual(expectedMinimumVersion, minimumVersion) testString := "" if skipTests { diff --git a/pkg/skaffold/build/jib/sync.go b/pkg/skaffold/build/jib/sync.go index 78658c95f92..82ea836f3f4 100644 --- a/pkg/skaffold/build/jib/sync.go +++ b/pkg/skaffold/build/jib/sync.go @@ -29,7 +29,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/filemon" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -55,7 +55,7 @@ type JSONSyncEntry struct { var InitSync = initSync -func initSync(ctx context.Context, workspace string, a *latestV1.JibArtifact) error { +func initSync(ctx context.Context, workspace string, a *latest.JibArtifact) error { syncMap, err := getSyncMapFunc(ctx, workspace, a) if err != nil { return fmt.Errorf("failed to initialize sync state for %q: %w", workspace, err) @@ -67,7 +67,7 @@ func initSync(ctx context.Context, workspace string, a *latestV1.JibArtifact) er var GetSyncDiff = getSyncDiff // returns toCopy, toDelete, error -func getSyncDiff(ctx context.Context, workspace string, a *latestV1.JibArtifact, e filemon.Events) (map[string][]string, map[string][]string, error) { +func getSyncDiff(ctx context.Context, workspace string, a *latest.JibArtifact, e filemon.Events) (map[string][]string, map[string][]string, error) { // no deletions allowed if len(e.Deleted) != 0 { // change into logging @@ -153,7 +153,7 @@ var ( getSyncMapFunc = getSyncMap ) -func getSyncMap(ctx context.Context, workspace string, artifact *latestV1.JibArtifact) (*SyncMap, error) { +func getSyncMap(ctx context.Context, workspace string, artifact *latest.JibArtifact) (*SyncMap, error) { // cmd will hold context that identifies the project cmd, err := getSyncMapCommand(ctx, workspace, artifact) if err != nil { @@ -167,7 +167,7 @@ func getSyncMap(ctx context.Context, workspace string, artifact *latestV1.JibArt return sm, nil } -func getSyncMapCommand(ctx context.Context, workspace string, artifact *latestV1.JibArtifact) (*exec.Cmd, error) { +func getSyncMapCommand(ctx context.Context, workspace string, artifact *latest.JibArtifact) (*exec.Cmd, error) { t, err := DeterminePluginType(ctx, workspace, artifact) if err != nil { return nil, err diff --git a/pkg/skaffold/build/jib/sync_test.go b/pkg/skaffold/build/jib/sync_test.go index 2f7a7a75aac..9757ff07dd0 100644 --- a/pkg/skaffold/build/jib/sync_test.go +++ b/pkg/skaffold/build/jib/sync_test.go @@ -26,7 +26,7 @@ import ( "time" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/filemon" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -156,7 +156,7 @@ func TestGetSyncDiff(t *testing.T) { tests := []struct { description string - artifact *latestV1.JibArtifact + artifact *latest.JibArtifact events filemon.Events buildDefinitions []string nextSyncMap SyncMap @@ -165,7 +165,7 @@ func TestGetSyncDiff(t *testing.T) { }{ { description: "build file changed (nil, nil, nil)", - artifact: &latestV1.JibArtifact{}, + artifact: &latest.JibArtifact{}, events: filemon.Events{Modified: []string{buildFile}}, buildDefinitions: []string{buildFile}, expectedCopy: nil, @@ -173,7 +173,7 @@ func TestGetSyncDiff(t *testing.T) { }, { description: "something is deleted (nil, nil, nil)", - artifact: &latestV1.JibArtifact{}, + artifact: &latest.JibArtifact{}, events: filemon.Events{Deleted: []string{directFile}}, buildDefinitions: []string{}, expectedCopy: nil, @@ -181,7 +181,7 @@ func TestGetSyncDiff(t *testing.T) { }, { description: "only direct sync entries changed", - artifact: &latestV1.JibArtifact{}, + artifact: &latest.JibArtifact{}, events: filemon.Events{Modified: []string{directFile}}, buildDefinitions: []string{}, expectedCopy: map[string][]string{directFile: directTarget}, @@ -189,7 +189,7 @@ func TestGetSyncDiff(t *testing.T) { }, { description: "only generated sync entries changed", - artifact: &latestV1.JibArtifact{}, + artifact: &latest.JibArtifact{}, events: filemon.Events{Modified: []string{generatedFile}}, buildDefinitions: []string{}, nextSyncMap: SyncMap{ @@ -201,7 +201,7 @@ func TestGetSyncDiff(t *testing.T) { }, { description: "generated and direct sync entries changed", - artifact: &latestV1.JibArtifact{}, + artifact: &latest.JibArtifact{}, events: filemon.Events{Modified: []string{directFile, generatedFile}}, buildDefinitions: []string{}, nextSyncMap: SyncMap{ @@ -213,7 +213,7 @@ func TestGetSyncDiff(t *testing.T) { }, { description: "new file created", - artifact: &latestV1.JibArtifact{}, + artifact: &latest.JibArtifact{}, events: filemon.Events{Added: []string{newFile}}, buildDefinitions: []string{}, nextSyncMap: SyncMap{ @@ -228,7 +228,7 @@ func TestGetSyncDiff(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - t.Override(&getSyncMapFunc, func(_ context.Context, _ string, _ *latestV1.JibArtifact) (*SyncMap, error) { + t.Override(&getSyncMapFunc, func(_ context.Context, _ string, _ *latest.JibArtifact) (*SyncMap, error) { return &test.nextSyncMap, nil }) pk := getProjectKey(workspace, test.artifact) @@ -253,7 +253,7 @@ func TestGetSyncDiff_directChecksUpdateFileTime(testing *testing.T) { ctx := context.Background() workspace := "testworkspace" - artifact := &latestV1.JibArtifact{} + artifact := &latest.JibArtifact{} tmpDir.Touch("direct") @@ -267,7 +267,7 @@ func TestGetSyncDiff_directChecksUpdateFileTime(testing *testing.T) { testutil.Run(testing, "Checks on direct files also update file times", func(t *testutil.T) { pk := getProjectKey(workspace, artifact) - t.Override(&getSyncMapFunc, func(_ context.Context, _ string, _ *latestV1.JibArtifact) (*SyncMap, error) { + t.Override(&getSyncMapFunc, func(_ context.Context, _ string, _ *latest.JibArtifact) (*SyncMap, error) { t.Fatal("getSyncMapFunc should not have been called in this test") return nil, nil }) diff --git a/pkg/skaffold/build/kaniko/args.go b/pkg/skaffold/build/kaniko/args.go index 60bd0369124..c7b665a6061 100644 --- a/pkg/skaffold/build/kaniko/args.go +++ b/pkg/skaffold/build/kaniko/args.go @@ -21,12 +21,12 @@ import ( "github.com/google/go-containerregistry/pkg/name" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) // Args returns kaniko command arguments -func Args(artifact *latestV1.KanikoArtifact, tag, context string) ([]string, error) { +func Args(artifact *latest.KanikoArtifact, tag, context string) ([]string, error) { args := []string{ "--destination", tag, "--dockerfile", artifact.DockerfilePath, diff --git a/pkg/skaffold/build/kaniko/args_test.go b/pkg/skaffold/build/kaniko/args_test.go index e0d45f27e34..da4008e4377 100644 --- a/pkg/skaffold/build/kaniko/args_test.go +++ b/pkg/skaffold/build/kaniko/args_test.go @@ -19,7 +19,7 @@ import ( "fmt" "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -27,13 +27,13 @@ import ( func TestArgs(t *testing.T) { tests := []struct { description string - artifact *latestV1.KanikoArtifact + artifact *latest.KanikoArtifact expectedArgs []string wantErr bool }{ { description: "simple build", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", }, expectedArgs: []string{}, @@ -41,7 +41,7 @@ func TestArgs(t *testing.T) { }, { description: "with BuildArgs", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", BuildArgs: map[string]*string{ "arg1": util.StringPtr("value1"), @@ -56,9 +56,9 @@ func TestArgs(t *testing.T) { }, { description: "with Cache", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", - Cache: &latestV1.KanikoCache{}, + Cache: &latest.KanikoCache{}, }, expectedArgs: []string{ CacheFlag, @@ -67,9 +67,9 @@ func TestArgs(t *testing.T) { }, { description: "with Cache Options", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", - Cache: &latestV1.KanikoCache{ + Cache: &latest.KanikoCache{ Repo: "gcr.io/ngnix", HostPath: "/cache", TTL: "2", @@ -85,7 +85,7 @@ func TestArgs(t *testing.T) { }, { description: "with Cleanup", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", Cleanup: true, }, @@ -96,7 +96,7 @@ func TestArgs(t *testing.T) { }, { description: "with DigestFile", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", DigestFile: "/tmp/digest", }, @@ -107,7 +107,7 @@ func TestArgs(t *testing.T) { }, { description: "with Force", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", Force: true, }, @@ -118,7 +118,7 @@ func TestArgs(t *testing.T) { }, { description: "with ImageNameWithDigestFile", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", ImageNameWithDigestFile: "/tmp/imageName", }, @@ -129,7 +129,7 @@ func TestArgs(t *testing.T) { }, { description: "with Insecure", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", Insecure: true, }, @@ -140,7 +140,7 @@ func TestArgs(t *testing.T) { }, { description: "with InsecurePull", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", InsecurePull: true, }, @@ -151,7 +151,7 @@ func TestArgs(t *testing.T) { }, { description: "with InsecureRegistry", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", InsecureRegistry: []string{ "s1.registry.url:5000", @@ -166,7 +166,7 @@ func TestArgs(t *testing.T) { }, { description: "with LogFormat", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", LogFormat: "json", }, @@ -177,7 +177,7 @@ func TestArgs(t *testing.T) { }, { description: "with LogTimestamp", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", LogTimestamp: true, }, @@ -188,7 +188,7 @@ func TestArgs(t *testing.T) { }, { description: "with NoPush", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", NoPush: true, }, @@ -199,7 +199,7 @@ func TestArgs(t *testing.T) { }, { description: "with OCILayoutPath", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", OCILayoutPath: "/tmp/builtImage", }, @@ -210,7 +210,7 @@ func TestArgs(t *testing.T) { }, { description: "with RegistryCertificate", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", RegistryCertificate: map[string]*string{ "s1.registry.url": util.StringPtr("/etc/certs/certificate1.cert"), @@ -225,7 +225,7 @@ func TestArgs(t *testing.T) { }, { description: "with RegistryMirror", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", RegistryMirror: "mirror.gcr.io", }, @@ -236,7 +236,7 @@ func TestArgs(t *testing.T) { }, { description: "with Reproducible", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", Reproducible: true, }, @@ -247,7 +247,7 @@ func TestArgs(t *testing.T) { }, { description: "with SingleSnapshot", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", SingleSnapshot: true, }, @@ -258,7 +258,7 @@ func TestArgs(t *testing.T) { }, { description: "with SkipTLS", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", SkipTLS: true, }, @@ -270,7 +270,7 @@ func TestArgs(t *testing.T) { }, { description: "with SkipTLSVerifyPull", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", SkipTLSVerifyPull: true, }, @@ -281,7 +281,7 @@ func TestArgs(t *testing.T) { }, { description: "with SkipTLSVerifyRegistry", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", SkipTLSVerifyRegistry: []string{ "s1.registry.url:443", @@ -296,7 +296,7 @@ func TestArgs(t *testing.T) { }, { description: "with SkipUnusedStages", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", SkipUnusedStages: true, }, @@ -307,7 +307,7 @@ func TestArgs(t *testing.T) { }, { description: "with Target", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", Target: "builder", }, @@ -318,7 +318,7 @@ func TestArgs(t *testing.T) { }, { description: "with SnapshotMode", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", SnapshotMode: "redo", }, @@ -329,7 +329,7 @@ func TestArgs(t *testing.T) { }, { description: "with TarPath", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", TarPath: "/workspace/tars", }, @@ -340,7 +340,7 @@ func TestArgs(t *testing.T) { }, { description: "with UseNewRun", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", UseNewRun: true, }, @@ -351,7 +351,7 @@ func TestArgs(t *testing.T) { }, { description: "with Verbosity", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", Verbosity: "trace", }, @@ -362,7 +362,7 @@ func TestArgs(t *testing.T) { }, { description: "with WhitelistVarRun", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", WhitelistVarRun: true, }, @@ -373,7 +373,7 @@ func TestArgs(t *testing.T) { }, { description: "with WhitelistVarRun", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", WhitelistVarRun: true, }, @@ -384,7 +384,7 @@ func TestArgs(t *testing.T) { }, { description: "with Labels", - artifact: &latestV1.KanikoArtifact{ + artifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", Label: map[string]*string{ "label1": util.StringPtr("value1"), diff --git a/pkg/skaffold/build/ko/build.go b/pkg/skaffold/build/ko/build.go index 8d047496380..46cf1ff598f 100644 --- a/pkg/skaffold/build/ko/build.go +++ b/pkg/skaffold/build/ko/build.go @@ -29,7 +29,7 @@ import ( "golang.org/x/tools/go/packages" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // Build an artifact using ko, and either push it to an image registry, or @@ -37,7 +37,7 @@ import ( // Build prints the image name to the out io.Writer and returns the image // identifier. The image identifier is the tag or digest for pushed images, or // the docker image ID for sideloaded images. -func (b *Builder) Build(ctx context.Context, out io.Writer, a *latestV1.Artifact, ref string, platforms platform.Matcher) (string, error) { +func (b *Builder) Build(ctx context.Context, out io.Writer, a *latest.Artifact, ref string, platforms platform.Matcher) (string, error) { if b.pushImages && strings.HasPrefix(ref, build.StrictScheme) { return "", fmt.Errorf("default repo must be set when using the 'ko://' prefix and pushing to a registry: %s, see https://skaffold.dev/docs/environment/image-registries/", a.ImageName) } @@ -63,7 +63,7 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, a *latestV1.Artifact func (b *Builder) SupportedPlatforms() platform.Matcher { return platform.All } // buildAndPublish the image using the ko builder and publisher. -func (b *Builder) buildAndPublish(ctx context.Context, a *latestV1.Artifact, koBuilder build.Interface, koPublisher publish.Interface) (name.Reference, error) { +func (b *Builder) buildAndPublish(ctx context.Context, a *latest.Artifact, koBuilder build.Interface, koPublisher publish.Interface) (name.Reference, error) { importpath, err := getImportPath(a) if err != nil { return nil, fmt.Errorf("could not determine Go import path for ko image %q: %w", a.ImageName, err) @@ -90,7 +90,7 @@ func (b *Builder) buildAndPublish(ctx context.Context, a *latestV1.Artifact, koB // // If the image name does _not_ start with `ko://`, determine the Go import // path of the image workspace directory. -func getImportPath(a *latestV1.Artifact) (string, error) { +func getImportPath(a *latest.Artifact) (string, error) { if strings.HasPrefix(a.ImageName, build.StrictScheme) { return a.ImageName, nil } diff --git a/pkg/skaffold/build/ko/build_test.go b/pkg/skaffold/build/ko/build_test.go index 60ea474b5c8..887c2c5ac36 100644 --- a/pkg/skaffold/build/ko/build_test.go +++ b/pkg/skaffold/build/ko/build_test.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -67,9 +67,9 @@ func TestBuild(t *testing.T) { importPath := "ko://github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/ko" // this package b := stubKoArtifactBuilder(test.imageRef, test.expectedImageIdentifier, test.pushImages, importPath) - artifact := &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - KoArtifact: &latestV1.KoArtifact{}, + artifact := &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + KoArtifact: &latest.KoArtifact{}, }, ImageName: importPath, } @@ -83,14 +83,14 @@ func TestBuild(t *testing.T) { func Test_getImportPath(t *testing.T) { tests := []struct { description string - artifact *latestV1.Artifact + artifact *latest.Artifact expectedImportPath string }{ { description: "main is ignored when image name is ko-prefixed full Go import path", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - KoArtifact: &latestV1.KoArtifact{ + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + KoArtifact: &latest.KoArtifact{ Main: "./main-should-be-ignored", }, }, @@ -100,9 +100,9 @@ func Test_getImportPath(t *testing.T) { }, { description: "plain image name", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - KoArtifact: &latestV1.KoArtifact{}, + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + KoArtifact: &latest.KoArtifact{}, }, ImageName: "any-image-name-1", }, @@ -110,9 +110,9 @@ func Test_getImportPath(t *testing.T) { }, { description: "plain image name with workspace directory", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - KoArtifact: &latestV1.KoArtifact{}, + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + KoArtifact: &latest.KoArtifact{}, }, ImageName: "any-image-name-2", Workspace: "./testdata/package-main-in-root", @@ -121,9 +121,9 @@ func Test_getImportPath(t *testing.T) { }, { description: "plain image name with workspace directory and main", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - KoArtifact: &latestV1.KoArtifact{ + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + KoArtifact: &latest.KoArtifact{ Main: "./baz", }, }, @@ -134,9 +134,9 @@ func Test_getImportPath(t *testing.T) { }, { description: "plain image name with workspace directory and main and source directory", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - KoArtifact: &latestV1.KoArtifact{ + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + KoArtifact: &latest.KoArtifact{ Dir: "package-main-not-in-root", Main: "./baz", }, diff --git a/pkg/skaffold/build/ko/builder.go b/pkg/skaffold/build/ko/builder.go index b3a05fe99e3..1bd03f8e750 100644 --- a/pkg/skaffold/build/ko/builder.go +++ b/pkg/skaffold/build/ko/builder.go @@ -28,12 +28,12 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/version" ) -func (b *Builder) newKoBuilder(ctx context.Context, a *latestV1.Artifact, platforms platform.Matcher) (build.Interface, error) { +func (b *Builder) newKoBuilder(ctx context.Context, a *latest.Artifact, platforms platform.Matcher) (build.Interface, error) { bo, err := buildOptions(a, b.runMode, platforms) if err != nil { return nil, fmt.Errorf("could not construct ko build options: %v", err) @@ -41,7 +41,7 @@ func (b *Builder) newKoBuilder(ctx context.Context, a *latestV1.Artifact, platfo return commands.NewBuilder(ctx, bo) } -func buildOptions(a *latestV1.Artifact, runMode config.RunMode, platforms platform.Matcher) (*options.BuildOptions, error) { +func buildOptions(a *latest.Artifact, runMode config.RunMode, platforms platform.Matcher) (*options.BuildOptions, error) { buildconfig, err := buildConfig(a) if err != nil { return nil, fmt.Errorf("could not create ko build config: %v", err) @@ -68,7 +68,7 @@ func buildOptions(a *latestV1.Artifact, runMode config.RunMode, platforms platfo // A map entry is only required if the artifact config specifies fields that need to be part of ko build configs. // If none of these are specified, we can provide an empty `BuildConfigs` map. // In this case, ko falls back to build configs provided in `.ko.yaml`, or to the default zero config. -func buildConfig(a *latestV1.Artifact) (map[string]build.Config, error) { +func buildConfig(a *latest.Artifact) (map[string]build.Config, error) { buildconfigs := map[string]build.Config{} if !koArtifactSpecifiesBuildConfig(*a.KoArtifact) { return buildconfigs, nil @@ -101,7 +101,7 @@ func buildConfig(a *latestV1.Artifact) (map[string]build.Config, error) { return buildconfigs, nil } -func koArtifactSpecifiesBuildConfig(k latestV1.KoArtifact) bool { +func koArtifactSpecifiesBuildConfig(k latest.KoArtifact) bool { if k.Dir != "" && k.Dir != "." { return true } @@ -120,7 +120,7 @@ func koArtifactSpecifiesBuildConfig(k latestV1.KoArtifact) bool { return false } -func labels(a *latestV1.Artifact) ([]string, error) { +func labels(a *latest.Artifact) ([]string, error) { rawLabels := map[string]*string{} for k, v := range a.KoArtifact.Labels { rawLabels[k] = util.StringPtr(v) diff --git a/pkg/skaffold/build/ko/builder_test.go b/pkg/skaffold/build/ko/builder_test.go index 43acb2d7065..e28ac132387 100644 --- a/pkg/skaffold/build/ko/builder_test.go +++ b/pkg/skaffold/build/ko/builder_test.go @@ -29,7 +29,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/version" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -41,7 +41,7 @@ const ( func TestBuildOptions(t *testing.T) { tests := []struct { description string - artifact latestV1.Artifact + artifact latest.Artifact platforms platform.Matcher envVarValue string runMode config.RunMode @@ -49,9 +49,9 @@ func TestBuildOptions(t *testing.T) { }{ { description: "all zero value", - artifact: latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - KoArtifact: &latestV1.KoArtifact{}, + artifact: latest.Artifact{ + ArtifactType: latest.ArtifactType{ + KoArtifact: &latest.KoArtifact{}, }, }, wantBo: options.BuildOptions{ @@ -63,9 +63,9 @@ func TestBuildOptions(t *testing.T) { }, { description: "all options", - artifact: latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - KoArtifact: &latestV1.KoArtifact{ + artifact: latest.Artifact{ + ArtifactType: latest.ArtifactType{ + KoArtifact: &latest.KoArtifact{ BaseImage: "gcr.io/distroless/base:nonroot", Dir: "gomoddir", Env: []string{ @@ -120,9 +120,9 @@ func TestBuildOptions(t *testing.T) { }, { description: "compatibility with ko envvar expansion syntax for flags and ldflags", - artifact: latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - KoArtifact: &latestV1.KoArtifact{ + artifact: latest.Artifact{ + ArtifactType: latest.ArtifactType{ + KoArtifact: &latest.KoArtifact{ Flags: []string{ "-v", fmt.Sprintf("-flag-{{.Env.%s}}", testKoBuildOptionsEnvVar), diff --git a/pkg/skaffold/build/ko/dependencies.go b/pkg/skaffold/build/ko/dependencies.go index 0c843549c3f..01044f7c26d 100644 --- a/pkg/skaffold/build/ko/dependencies.go +++ b/pkg/skaffold/build/ko/dependencies.go @@ -20,11 +20,11 @@ import ( "context" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/list" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // GetDependencies returns a list of files to watch for changes to rebuild. -func GetDependencies(_ context.Context, workspace string, a *latestV1.KoArtifact) ([]string, error) { +func GetDependencies(_ context.Context, workspace string, a *latest.KoArtifact) ([]string, error) { if a.Dependencies == nil || (a.Dependencies.Paths == nil && a.Dependencies.Ignore == nil) { a.Dependencies = defaultKoDependencies() } @@ -32,8 +32,8 @@ func GetDependencies(_ context.Context, workspace string, a *latestV1.KoArtifact } // defaultKoDependencies behavior is to watch all Go files in the context directory and its subdirectories. -func defaultKoDependencies() *latestV1.KoDependencies { - return &latestV1.KoDependencies{ +func defaultKoDependencies() *latest.KoDependencies { + return &latest.KoDependencies{ Paths: []string{"**/*.go"}, Ignore: []string{}, } diff --git a/pkg/skaffold/build/ko/dependencies_test.go b/pkg/skaffold/build/ko/dependencies_test.go index e1fec1257e5..e10937a1bc2 100644 --- a/pkg/skaffold/build/ko/dependencies_test.go +++ b/pkg/skaffold/build/ko/dependencies_test.go @@ -23,7 +23,7 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -97,8 +97,8 @@ func TestGetDependencies(t *testing.T) { } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - deps, err := GetDependencies(context.Background(), tmpDir.Root(), &latestV1.KoArtifact{ - Dependencies: &latestV1.KoDependencies{ + deps, err := GetDependencies(context.Background(), tmpDir.Root(), &latest.KoArtifact{ + Dependencies: &latest.KoDependencies{ Paths: test.paths, Ignore: test.ignore, }, diff --git a/pkg/skaffold/build/local/local.go b/pkg/skaffold/build/local/local.go index bbf40f327af..d0a41469539 100644 --- a/pkg/skaffold/build/local/local.go +++ b/pkg/skaffold/build/local/local.go @@ -26,12 +26,12 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // Build runs a docker build on the host and tags the resulting image with // its checksum. It streams build progress to the writer argument. -func (b *Builder) Build(ctx context.Context, out io.Writer, a *latestV1.Artifact) build.ArtifactBuilder { +func (b *Builder) Build(ctx context.Context, out io.Writer, a *latest.Artifact) build.ArtifactBuilder { if b.prune { b.localPruner.asynchronousCleanupOldImages(ctx, []string{a.ImageName}) } @@ -66,7 +66,7 @@ func (b *Builder) PushImages() bool { func (b *Builder) SupportedPlatforms() platform.Matcher { return platform.All } -func (b *Builder) buildArtifact(ctx context.Context, out io.Writer, a *latestV1.Artifact, tag string, platforms platform.Matcher) (string, error) { +func (b *Builder) buildArtifact(ctx context.Context, out io.Writer, a *latest.Artifact, tag string, platforms platform.Matcher) (string, error) { digestOrImageID, err := b.runBuildForArtifact(ctx, out, a, tag, platforms) if err != nil { return "", err @@ -94,7 +94,7 @@ func (b *Builder) buildArtifact(ctx context.Context, out io.Writer, a *latestV1. return build.TagWithImageID(ctx, tag, imageID, b.localDocker) } -func (b *Builder) runBuildForArtifact(ctx context.Context, out io.Writer, a *latestV1.Artifact, tag string, platforms platform.Matcher) (string, error) { +func (b *Builder) runBuildForArtifact(ctx context.Context, out io.Writer, a *latest.Artifact, tag string, platforms platform.Matcher) (string, error) { if !b.pushImages { // All of the builders will rely on a local Docker: // + Either to build the image, diff --git a/pkg/skaffold/build/local/local_test.go b/pkg/skaffold/build/local/local_test.go index efd1eae6c8c..5cfcac2cf87 100644 --- a/pkg/skaffold/build/local/local_test.go +++ b/pkg/skaffold/build/local/local_test.go @@ -37,7 +37,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/warnings" "github.com/GoogleContainerTools/skaffold/testutil" @@ -58,7 +58,7 @@ func TestLocalRun(t *testing.T) { description string api *testutil.FakeAPIClient tag string - artifact *latestV1.Artifact + artifact *latest.Artifact expected string expectedWarnings []string expectedPushed map[string]string @@ -67,10 +67,10 @@ func TestLocalRun(t *testing.T) { }{ { description: "single build (local)", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "gcr.io/test/image", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, }, }, tag: "gcr.io/test/image:tag", @@ -80,10 +80,10 @@ func TestLocalRun(t *testing.T) { }, { description: "error getting image digest", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "gcr.io/test/image", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, }, }, tag: "gcr.io/test/image:tag", @@ -94,10 +94,10 @@ func TestLocalRun(t *testing.T) { }, { description: "single build (remote)", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "gcr.io/test/image", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, }, }, tag: "gcr.io/test/image:tag", @@ -110,10 +110,10 @@ func TestLocalRun(t *testing.T) { }, { description: "error build", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "gcr.io/test/image", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, }, }, tag: "gcr.io/test/image:tag", @@ -124,10 +124,10 @@ func TestLocalRun(t *testing.T) { }, { description: "Don't push on build error", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "gcr.io/test/image", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, }, }, tag: "gcr.io/test/image:tag", @@ -139,16 +139,16 @@ func TestLocalRun(t *testing.T) { }, { description: "unknown artifact type", - artifact: &latestV1.Artifact{}, + artifact: &latest.Artifact{}, api: &testutil.FakeAPIClient{}, shouldErr: true, }, { description: "cache-from images already pulled", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "gcr.io/test/image", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ CacheFrom: []string{"pull1", "pull2"}, }, }, @@ -159,10 +159,10 @@ func TestLocalRun(t *testing.T) { }, { description: "pull cache-from images", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "gcr.io/test/image", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ CacheFrom: []string{"pull1", "pull2"}, }, }, @@ -173,10 +173,10 @@ func TestLocalRun(t *testing.T) { }, { description: "ignore cache-from pull error", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "gcr.io/test/image", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ CacheFrom: []string{"pull1"}, }, }, @@ -190,10 +190,10 @@ func TestLocalRun(t *testing.T) { }, { description: "error checking cache-from image", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "gcr.io/test/image", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ CacheFrom: []string{"pull"}, }, }, @@ -206,10 +206,10 @@ func TestLocalRun(t *testing.T) { }, { description: "fail fast docker not found", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "gcr.io/test/image", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, }, }, tag: "gcr.io/test/image:tag", @@ -231,15 +231,15 @@ func TestLocalRun(t *testing.T) { t.Override(&docker.EvalBuildArgs, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string) (map[string]*string, error) { return args, nil }) - testEvent.InitializeState([]latestV1.Pipeline{{ - Deploy: latestV1.DeployConfig{}, - Build: latestV1.BuildConfig{ - BuildType: latestV1.BuildType{ - LocalBuild: &latestV1.LocalBuild{}, + testEvent.InitializeState([]latest.Pipeline{{ + Deploy: latest.DeployConfig{}, + Build: latest.BuildConfig{ + BuildType: latest.BuildType{ + LocalBuild: &latest.LocalBuild{}, }, }}}) - builder, err := NewBuilder(context.Background(), &mockBuilderContext{artifactStore: build.NewArtifactStore()}, &latestV1.LocalBuild{ + builder, err := NewBuilder(context.Background(), &mockBuilderContext{artifactStore: build.NewArtifactStore()}, &latest.LocalBuild{ Push: util.BoolPtr(test.pushImages), Concurrency: &constants.DefaultLocalConcurrency, }) @@ -266,7 +266,7 @@ func TestNewBuilder(t *testing.T) { expectedPush bool cluster config.Cluster pushFlag config.BoolOrUndefined - localBuild latestV1.LocalBuild + localBuild latest.LocalBuild localDockerFn func(context.Context, docker.Config) (docker.LocalDaemon, error) }{ { @@ -290,7 +290,7 @@ func TestNewBuilder(t *testing.T) { return dummyDaemon, nil }, cluster: config.Cluster{PushImages: true}, - localBuild: latestV1.LocalBuild{ + localBuild: latest.LocalBuild{ Push: util.BoolPtr(false), }, shouldErr: false, @@ -312,7 +312,7 @@ func TestNewBuilder(t *testing.T) { return dummyDaemon, nil }, pushFlag: config.NewBoolOrUndefined(util.BoolPtr(false)), - localBuild: latestV1.LocalBuild{ + localBuild: latest.LocalBuild{ Push: util.BoolPtr(true), }, shouldErr: false, @@ -342,56 +342,56 @@ func TestNewBuilder(t *testing.T) { func TestGetArtifactBuilder(t *testing.T) { tests := []struct { description string - artifact *latestV1.Artifact + artifact *latest.Artifact expected string shouldErr bool }{ { description: "docker builder", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "gcr.io/test/image", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, }, }, expected: "docker", }, { description: "jib builder", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "gcr.io/test/image", - ArtifactType: latestV1.ArtifactType{ - JibArtifact: &latestV1.JibArtifact{}, + ArtifactType: latest.ArtifactType{ + JibArtifact: &latest.JibArtifact{}, }, }, expected: "jib", }, { description: "buildpacks builder", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "gcr.io/test/image", - ArtifactType: latestV1.ArtifactType{ - BuildpackArtifact: &latestV1.BuildpackArtifact{}, + ArtifactType: latest.ArtifactType{ + BuildpackArtifact: &latest.BuildpackArtifact{}, }, }, expected: "buildpacks", }, { description: "bazel builder", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "gcr.io/test/image", - ArtifactType: latestV1.ArtifactType{ - BazelArtifact: &latestV1.BazelArtifact{}, + ArtifactType: latest.ArtifactType{ + BazelArtifact: &latest.BazelArtifact{}, }, }, expected: "bazel", }, { description: "custom builder", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "gcr.io/test/image", - ArtifactType: latestV1.ArtifactType{ - CustomArtifact: &latestV1.CustomArtifact{}, + ArtifactType: latest.ArtifactType{ + CustomArtifact: &latest.CustomArtifact{}, }, }, expected: "custom", @@ -406,7 +406,7 @@ func TestGetArtifactBuilder(t *testing.T) { return args, nil }) - b, err := NewBuilder(context.Background(), &mockBuilderContext{artifactStore: build.NewArtifactStore()}, &latestV1.LocalBuild{Concurrency: &constants.DefaultLocalConcurrency}) + b, err := NewBuilder(context.Background(), &mockBuilderContext{artifactStore: build.NewArtifactStore()}, &latest.LocalBuild{Concurrency: &constants.DefaultLocalConcurrency}) t.CheckNoError(err) builder, err := newPerArtifactBuilder(b, test.artifact) @@ -434,7 +434,7 @@ func fakeLocalDaemon(api client.CommonAPIClient) docker.LocalDaemon { type mockBuilderContext struct { runcontext.RunContext // Embedded to provide the default values. - local latestV1.LocalBuild + local latest.LocalBuild mode config.RunMode cluster config.Cluster pushFlag config.BoolOrUndefined diff --git a/pkg/skaffold/build/local/types.go b/pkg/skaffold/build/local/types.go index c373caca311..c9107ac7d8b 100644 --- a/pkg/skaffold/build/local/types.go +++ b/pkg/skaffold/build/local/types.go @@ -34,13 +34,13 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) // Builder uses the host docker daemon to build and tag the image. type Builder struct { - local latestV1.LocalBuild + local latest.LocalBuild cfg docker.Config localDocker docker.LocalDaemon @@ -80,7 +80,7 @@ type BuilderContext interface { } // NewBuilder returns an new instance of a local Builder. -func NewBuilder(ctx context.Context, bCtx BuilderContext, buildCfg *latestV1.LocalBuild) (*Builder, error) { +func NewBuilder(ctx context.Context, bCtx BuilderContext, buildCfg *latest.LocalBuild) (*Builder, error) { localDocker, err := docker.NewAPIClient(ctx, bCtx) if err != nil { return nil, fmt.Errorf("getting docker client: %w", err) @@ -140,12 +140,12 @@ func (b *Builder) Prune(ctx context.Context, _ io.Writer) error { // artifactBuilder represents a per artifact builder interface type artifactBuilder interface { - Build(ctx context.Context, out io.Writer, a *latestV1.Artifact, tag string, platforms platform.Matcher) (string, error) + Build(ctx context.Context, out io.Writer, a *latest.Artifact, tag string, platforms platform.Matcher) (string, error) SupportedPlatforms() platform.Matcher } // newPerArtifactBuilder returns an instance of `artifactBuilder` -func newPerArtifactBuilder(b *Builder, a *latestV1.Artifact) (artifactBuilder, error) { +func newPerArtifactBuilder(b *Builder, a *latest.Artifact) (artifactBuilder, error) { switch { case a.DockerArtifact != nil: return dockerbuilder.NewArtifactBuilder(b.localDocker, b.cfg, b.local.UseDockerCLI, b.local.UseBuildkit, b.pushImages, b.artifactStore, b.sourceDependencies), nil diff --git a/pkg/skaffold/build/local/types_test.go b/pkg/skaffold/build/local/types_test.go index 6e8ed34e9b9..54880ad6742 100644 --- a/pkg/skaffold/build/local/types_test.go +++ b/pkg/skaffold/build/local/types_test.go @@ -21,7 +21,7 @@ import ( "testing" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/ko" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -29,15 +29,15 @@ func TestNewPerArtifactBuilder(t *testing.T) { tests := []struct { description string builder *Builder - artifact *latestV1.Artifact + artifact *latest.Artifact expectedBuilder artifactBuilder }{ { description: "ko", builder: &Builder{}, - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - KoArtifact: &latestV1.KoArtifact{}, + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + KoArtifact: &latest.KoArtifact{}, }, }, expectedBuilder: &ko.Builder{}, diff --git a/pkg/skaffold/build/logfile.go b/pkg/skaffold/build/logfile.go index a820375a354..2fb489f2b59 100644 --- a/pkg/skaffold/build/logfile.go +++ b/pkg/skaffold/build/logfile.go @@ -23,7 +23,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/logfile" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) type Muted interface { @@ -36,7 +36,7 @@ func WithLogFile(builder ArtifactBuilder, muted Muted) ArtifactBuilder { return builder } - return func(ctx context.Context, out io.Writer, artifact *latestV1.Artifact, tag string, platforms platform.Matcher) (string, error) { + return func(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string, platforms platform.Matcher) (string, error) { file, err := logfile.Create("build", artifact.ImageName+".log") if err != nil { return "", fmt.Errorf("unable to create log file for %s: %w", artifact.ImageName, err) diff --git a/pkg/skaffold/build/logfile_test.go b/pkg/skaffold/build/logfile_test.go index e26717041bc..800831ec4a5 100644 --- a/pkg/skaffold/build/logfile_test.go +++ b/pkg/skaffold/build/logfile_test.go @@ -28,7 +28,7 @@ import ( "testing" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -88,7 +88,7 @@ func TestWithLogFile(t *testing.T) { var out bytes.Buffer builder := WithLogFile(test.builder, test.muted) - digest, err := builder(context.Background(), &out, &latestV1.Artifact{ImageName: "img"}, "img:123", platform.All) + digest, err := builder(context.Background(), &out, &latest.Artifact{ImageName: "img"}, "img:123", platform.All) t.CheckErrorAndDeepEqual(test.shouldErr, err, test.expectedDigest, digest) for _, found := range test.logsFound { @@ -101,12 +101,12 @@ func TestWithLogFile(t *testing.T) { } } -func fakeBuilder(_ context.Context, out io.Writer, a *latestV1.Artifact, tag string, platforms platform.Matcher) (string, error) { +func fakeBuilder(_ context.Context, out io.Writer, a *latest.Artifact, tag string, platforms platform.Matcher) (string, error) { fmt.Fprintln(out, "building", a.ImageName, "with tag", tag) return "digest", nil } -func fakeFailingBuilder(_ context.Context, out io.Writer, a *latestV1.Artifact, tag string, platforms platform.Matcher) (string, error) { +func fakeFailingBuilder(_ context.Context, out io.Writer, a *latest.Artifact, tag string, platforms platform.Matcher) (string, error) { fmt.Fprintln(out, "failed to build", a.ImageName, "with tag", tag) return "", errors.New("bug") } diff --git a/pkg/skaffold/build/misc/artifact_type.go b/pkg/skaffold/build/misc/artifact_type.go index 7ca3244b51c..0bdd701d55b 100644 --- a/pkg/skaffold/build/misc/artifact_type.go +++ b/pkg/skaffold/build/misc/artifact_type.go @@ -20,7 +20,7 @@ import ( "fmt" "strings" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml" ) @@ -35,7 +35,7 @@ const ( // ArtifactType returns a string representing the type found in an artifact. Used for error messages. // (this would normally be implemented as a String() method on the type, but types are versioned) -func ArtifactType(a *latestV1.Artifact) string { +func ArtifactType(a *latest.Artifact) string { switch { case a.DockerArtifact != nil: return Docker @@ -55,7 +55,7 @@ func ArtifactType(a *latestV1.Artifact) string { } // FormatArtifact returns a string representation of an artifact for usage in error messages -func FormatArtifact(a *latestV1.Artifact) string { +func FormatArtifact(a *latest.Artifact) string { buf, err := yaml.Marshal(a) if err != nil { return fmt.Sprintf("%+v", a) diff --git a/pkg/skaffold/build/misc/artifact_type_test.go b/pkg/skaffold/build/misc/artifact_type_test.go index 8d5927b0fdf..3f8453437d1 100644 --- a/pkg/skaffold/build/misc/artifact_type_test.go +++ b/pkg/skaffold/build/misc/artifact_type_test.go @@ -19,7 +19,7 @@ package misc import ( "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -27,22 +27,22 @@ func TestArtifactType(t *testing.T) { tests := []struct { description string want string - artifact *latestV1.Artifact + artifact *latest.Artifact }{ - {"docker", "docker", &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, + {"docker", "docker", &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, }, }}, - {"kaniko", "kaniko", &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - KanikoArtifact: &latestV1.KanikoArtifact{}, + {"kaniko", "kaniko", &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + KanikoArtifact: &latest.KanikoArtifact{}, }, }}, - {"docker+kaniko", "docker", &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, - KanikoArtifact: &latestV1.KanikoArtifact{}, + {"docker+kaniko", "docker", &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, + KanikoArtifact: &latest.KanikoArtifact{}, }, }}, } @@ -60,16 +60,16 @@ func TestFormatArtifact(t *testing.T) { tests := []struct { description string want string - artifact *latestV1.Artifact + artifact *latest.Artifact }{ - {"docker", "docker: {}", &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, + {"docker", "docker: {}", &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, }, }}, - {"kaniko", "kaniko: {}", &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - KanikoArtifact: &latestV1.KanikoArtifact{}, + {"kaniko", "kaniko: {}", &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + KanikoArtifact: &latest.KanikoArtifact{}, }, }}, } diff --git a/pkg/skaffold/build/model.go b/pkg/skaffold/build/model.go index 936001a1cdc..0886962bf14 100644 --- a/pkg/skaffold/build/model.go +++ b/pkg/skaffold/build/model.go @@ -19,7 +19,7 @@ package build import ( "context" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // node models the artifact dependency graph using a set of channels. @@ -52,7 +52,7 @@ func (a *node) waitForDependencies(ctx context.Context) error { return nil } -func createNodes(artifacts []*latestV1.Artifact) []node { +func createNodes(artifacts []*latest.Artifact) []node { nodeMap := make(map[string]node) for _, a := range artifacts { nodeMap[a.ImageName] = node{ diff --git a/pkg/skaffold/build/result.go b/pkg/skaffold/build/result.go index 2b4cd5bb389..0699316b45d 100644 --- a/pkg/skaffold/build/result.go +++ b/pkg/skaffold/build/result.go @@ -26,7 +26,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) const bufferedLinesPerArtifact = 10000 @@ -136,9 +136,9 @@ func newLogAggregator(out io.Writer, capacity int, concurrency int) logAggregato // ArtifactStore stores the results of each artifact build. type ArtifactStore interface { - Record(a *latestV1.Artifact, tag string) + Record(a *latest.Artifact, tag string) GetImageTag(imageName string) (tag string, found bool) - GetArtifacts(s []*latestV1.Artifact) ([]graph.Artifact, error) + GetArtifacts(s []*latest.Artifact) ([]graph.Artifact, error) } func NewArtifactStore() ArtifactStore { @@ -149,7 +149,7 @@ type artifactStoreImpl struct { m *sync.Map } -func (ba *artifactStoreImpl) Record(a *latestV1.Artifact, tag string) { +func (ba *artifactStoreImpl) Record(a *latest.Artifact, tag string) { ba.m.Store(a.ImageName, tag) } @@ -165,7 +165,7 @@ func (ba *artifactStoreImpl) GetImageTag(imageName string) (string, bool) { return t, true } -func (ba *artifactStoreImpl) GetArtifacts(s []*latestV1.Artifact) ([]graph.Artifact, error) { +func (ba *artifactStoreImpl) GetArtifacts(s []*latest.Artifact) ([]graph.Artifact, error) { var builds []graph.Artifact for _, a := range s { t, found := ba.GetImageTag(a.ImageName) diff --git a/pkg/skaffold/build/scheduler.go b/pkg/skaffold/build/scheduler.go index a48a159d14c..787af82d06c 100644 --- a/pkg/skaffold/build/scheduler.go +++ b/pkg/skaffold/build/scheduler.go @@ -33,14 +33,14 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/instrumentation" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/tag" ) -type ArtifactBuilder func(ctx context.Context, out io.Writer, artifact *latestV1.Artifact, tag string, platforms platform.Matcher) (string, error) +type ArtifactBuilder func(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string, platforms platform.Matcher) (string, error) type scheduler struct { - artifacts []*latestV1.Artifact + artifacts []*latest.Artifact nodes []node // size len(artifacts) artifactBuilder ArtifactBuilder logger logAggregator @@ -49,7 +49,7 @@ type scheduler struct { reportFailure bool } -func newScheduler(artifacts []*latestV1.Artifact, artifactBuilder ArtifactBuilder, concurrency int, out io.Writer, store ArtifactStore) *scheduler { +func newScheduler(artifacts []*latest.Artifact, artifactBuilder ArtifactBuilder, concurrency int, out io.Writer, store ArtifactStore) *scheduler { s := scheduler{ artifacts: artifacts, nodes: createNodes(artifacts), @@ -143,7 +143,7 @@ func (s *scheduler) build(ctx context.Context, tags tag.ImageTags, platforms pla } // InOrder builds a list of artifacts in dependency order. -func InOrder(ctx context.Context, out io.Writer, tags tag.ImageTags, platforms platform.Resolver, artifacts []*latestV1.Artifact, artifactBuilder ArtifactBuilder, concurrency int, store ArtifactStore) ([]graph.Artifact, error) { +func InOrder(ctx context.Context, out io.Writer, tags tag.ImageTags, platforms platform.Resolver, artifacts []*latest.Artifact, artifactBuilder ArtifactBuilder, concurrency int, store ArtifactStore) ([]graph.Artifact, error) { // `concurrency` specifies the max number of builds that can run at any one time. If concurrency is 0, then all builds can run in parallel. if concurrency == 0 { concurrency = len(artifacts) @@ -157,7 +157,7 @@ func InOrder(ctx context.Context, out io.Writer, tags tag.ImageTags, platforms p return s.run(ctx, tags, platforms) } -func performBuild(ctx context.Context, cw io.Writer, tags tag.ImageTags, platforms platform.Resolver, artifact *latestV1.Artifact, build ArtifactBuilder) (string, error) { +func performBuild(ctx context.Context, cw io.Writer, tags tag.ImageTags, platforms platform.Resolver, artifact *latest.Artifact, build ArtifactBuilder) (string, error) { tag, present := tags[artifact.ImageName] if !present { return "", fmt.Errorf("unable to find tag for image %s", artifact.ImageName) diff --git a/pkg/skaffold/build/scheduler_test.go b/pkg/skaffold/build/scheduler_test.go index 1f43ccd9ed4..60d7e3759d7 100644 --- a/pkg/skaffold/build/scheduler_test.go +++ b/pkg/skaffold/build/scheduler_test.go @@ -31,7 +31,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/tag" "github.com/GoogleContainerTools/skaffold/testutil" testEvent "github.com/GoogleContainerTools/skaffold/testutil/event" @@ -48,7 +48,7 @@ func TestGetBuild(t *testing.T) { }{ { description: "build succeeds", - buildArtifact: func(ctx context.Context, out io.Writer, artifact *latestV1.Artifact, tag string, _ platform.Matcher) (string, error) { + buildArtifact: func(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string, _ platform.Matcher) (string, error) { out.Write([]byte("build succeeds")) return fmt.Sprintf("%s@sha256:abac", tag), nil }, @@ -61,7 +61,7 @@ func TestGetBuild(t *testing.T) { }, { description: "tag with ko scheme prefix and Go import path with uppercase characters is sanitized", - buildArtifact: func(ctx context.Context, out io.Writer, artifact *latestV1.Artifact, tag string, _ platform.Matcher) (string, error) { + buildArtifact: func(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string, _ platform.Matcher) (string, error) { out.Write([]byte("build succeeds")) return fmt.Sprintf("%s@sha256:abac", tag), nil }, @@ -73,7 +73,7 @@ func TestGetBuild(t *testing.T) { }, { description: "build fails", - buildArtifact: func(ctx context.Context, out io.Writer, artifact *latestV1.Artifact, tag string, _ platform.Matcher) (string, error) { + buildArtifact: func(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string, _ platform.Matcher) (string, error) { return "", fmt.Errorf("build fails") }, tags: tag.ImageTags{ @@ -93,7 +93,7 @@ func TestGetBuild(t *testing.T) { testutil.Run(t, test.description, func(t *testutil.T) { out := new(bytes.Buffer) - artifact := &latestV1.Artifact{ImageName: "skaffold/image1"} + artifact := &latest.Artifact{ImageName: "skaffold/image1"} got, err := performBuild(context.Background(), out, test.tags, platform.Resolver{}, artifact, test.buildArtifact) t.CheckErrorAndDeepEqual(test.shouldErr, err, test.expectedTag, got) @@ -105,14 +105,14 @@ func TestGetBuild(t *testing.T) { func TestFormatResults(t *testing.T) { tests := []struct { description string - artifacts []*latestV1.Artifact + artifacts []*latest.Artifact expected []graph.Artifact results map[string]interface{} shouldErr bool }{ { description: "all builds completely successfully", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ {ImageName: "skaffold/image1"}, {ImageName: "skaffold/image2"}, }, @@ -127,7 +127,7 @@ func TestFormatResults(t *testing.T) { }, { description: "no build result produced for a build", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ {ImageName: "skaffold/image1"}, {ImageName: "skaffold/image2"}, }, @@ -161,7 +161,7 @@ func TestInOrder(t *testing.T) { { description: "short and nice build log", expected: "Building 2 artifacts in parallel\nBuilding [skaffold/image1]...\nshort\nBuild [skaffold/image1] succeeded\nBuilding [skaffold/image2]...\nshort\nBuild [skaffold/image2] succeeded\n", - buildFunc: func(ctx context.Context, out io.Writer, artifact *latestV1.Artifact, tag string, _ platform.Matcher) (string, error) { + buildFunc: func(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string, _ platform.Matcher) (string, error) { out.Write([]byte("short\n")) return fmt.Sprintf("%s:tag", artifact.ImageName), nil }, @@ -178,7 +178,7 @@ This is a long string more than 10 bytes. And new lines Build [skaffold/image2] succeeded `, - buildFunc: func(ctx context.Context, out io.Writer, artifact *latestV1.Artifact, tag string, _ platform.Matcher) (string, error) { + buildFunc: func(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string, _ platform.Matcher) (string, error) { out.Write([]byte("This is a long string more than 10 bytes.\nAnd new lines\n")) return fmt.Sprintf("%s:tag", artifact.ImageName), nil }, @@ -187,9 +187,9 @@ Build [skaffold/image2] succeeded for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { out := new(bytes.Buffer) - artifacts := []*latestV1.Artifact{ + artifacts := []*latest.Artifact{ {ImageName: "skaffold/image1"}, - {ImageName: "skaffold/image2", Dependencies: []*latestV1.ArtifactDependency{{ImageName: "skaffold/image1"}}}, + {ImageName: "skaffold/image2", Dependencies: []*latest.ArtifactDependency{{ImageName: "skaffold/image1"}}}, } tags := tag.ImageTags{ "skaffold/image1": "skaffold/image1:v0.0.1", @@ -228,20 +228,20 @@ func TestInOrderConcurrency(t *testing.T) { } for _, test := range tests { testutil.Run(t, fmt.Sprintf("%d artifacts, max concurrency=%d", test.artifacts, test.limit), func(t *testutil.T) { - var artifacts []*latestV1.Artifact + var artifacts []*latest.Artifact tags := tag.ImageTags{} for i := 0; i < test.artifacts; i++ { imageName := fmt.Sprintf("skaffold/image%d", i) tag := fmt.Sprintf("skaffold/image%d:tag", i) - artifacts = append(artifacts, &latestV1.Artifact{ImageName: imageName}) + artifacts = append(artifacts, &latest.Artifact{ImageName: imageName}) tags[imageName] = tag } var actualConcurrency int32 - builder := func(_ context.Context, _ io.Writer, _ *latestV1.Artifact, tag string, _ platform.Matcher) (string, error) { + builder := func(_ context.Context, _ io.Writer, _ *latest.Artifact, tag string, _ platform.Matcher) (string, error) { if atomic.AddInt32(&actualConcurrency, 1) > int32(test.maxConcurrency) { return "", fmt.Errorf("only %d build can run at a time", test.maxConcurrency) } @@ -272,7 +272,7 @@ func TestInOrderForArgs(t *testing.T) { }{ { description: "runs in parallel for 2 artifacts with no dependency", - buildArtifact: func(_ context.Context, _ io.Writer, _ *latestV1.Artifact, tag string, _ platform.Matcher) (string, error) { + buildArtifact: func(_ context.Context, _ io.Writer, _ *latest.Artifact, tag string, _ platform.Matcher) (string, error) { return tag, nil }, artifactLen: 2, @@ -283,7 +283,7 @@ func TestInOrderForArgs(t *testing.T) { }, { description: "runs in parallel for 5 artifacts with dependencies", - buildArtifact: func(_ context.Context, _ io.Writer, _ *latestV1.Artifact, tag string, _ platform.Matcher) (string, error) { + buildArtifact: func(_ context.Context, _ io.Writer, _ *latest.Artifact, tag string, _ platform.Matcher) (string, error) { return tag, nil }, dependency: map[int][]int{ @@ -303,7 +303,7 @@ func TestInOrderForArgs(t *testing.T) { }, { description: "runs with max concurrency of 2 for 5 artifacts with dependencies", - buildArtifact: func(_ context.Context, _ io.Writer, _ *latestV1.Artifact, tag string, _ platform.Matcher) (string, error) { + buildArtifact: func(_ context.Context, _ io.Writer, _ *latest.Artifact, tag string, _ platform.Matcher) (string, error) { return tag, nil }, dependency: map[int][]int{ @@ -329,7 +329,7 @@ func TestInOrderForArgs(t *testing.T) { }, { description: "build fails for artifacts without dependencies", - buildArtifact: func(c context.Context, _ io.Writer, a *latestV1.Artifact, tag string, _ platform.Matcher) (string, error) { + buildArtifact: func(c context.Context, _ io.Writer, a *latest.Artifact, tag string, _ platform.Matcher) (string, error) { if a.ImageName == "artifact2" { return "", fmt.Errorf(`some error occurred while building "artifact2"`) } @@ -346,7 +346,7 @@ func TestInOrderForArgs(t *testing.T) { }, { description: "build fails for artifacts with dependencies", - buildArtifact: func(_ context.Context, _ io.Writer, a *latestV1.Artifact, tag string, _ platform.Matcher) (string, error) { + buildArtifact: func(_ context.Context, _ io.Writer, a *latest.Artifact, tag string, _ platform.Matcher) (string, error) { if a.ImageName == "artifact2" { return "", fmt.Errorf(`some error occurred while building "artifact2"`) } @@ -365,11 +365,11 @@ func TestInOrderForArgs(t *testing.T) { } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - artifacts := make([]*latestV1.Artifact, test.artifactLen) + artifacts := make([]*latest.Artifact, test.artifactLen) tags := tag.ImageTags{} for i := 0; i < test.artifactLen; i++ { a := fmt.Sprintf("artifact%d", i+1) - artifacts[i] = &latestV1.Artifact{ImageName: a} + artifacts[i] = &latest.Artifact{ImageName: a} tags[a] = fmt.Sprintf("%s@tag%d", a, i+1) } @@ -390,10 +390,10 @@ func TestInOrderForArgs(t *testing.T) { // 2 : {3}, //} // implies that a[0] artifact depends on a[1] and a[2]; and a[2] depends on a[3]. -func setDependencies(a []*latestV1.Artifact, d map[int][]int) { +func setDependencies(a []*latest.Artifact, d map[int][]int) { for k, dep := range d { for i := range dep { - a[k].Dependencies = append(a[k].Dependencies, &latestV1.ArtifactDependency{ + a[k].Dependencies = append(a[k].Dependencies, &latest.ArtifactDependency{ ImageName: a[dep[i]].ImageName, }) } @@ -401,11 +401,11 @@ func setDependencies(a []*latestV1.Artifact, d map[int][]int) { } func initializeEvents() { - pipes := []latestV1.Pipeline{{ - Deploy: latestV1.DeployConfig{}, - Build: latestV1.BuildConfig{ - BuildType: latestV1.BuildType{ - LocalBuild: &latestV1.LocalBuild{}, + pipes := []latest.Pipeline{{ + Deploy: latest.DeployConfig{}, + Build: latest.BuildConfig{ + BuildType: latest.BuildType{ + LocalBuild: &latest.LocalBuild{}, }, }, }} diff --git a/pkg/skaffold/config/options.go b/pkg/skaffold/config/options.go index d955a8a9384..dfe36507edc 100644 --- a/pkg/skaffold/config/options.go +++ b/pkg/skaffold/config/options.go @@ -20,7 +20,7 @@ import ( "strings" "time" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // WaitForDeletions configures the wait for pending deletions. @@ -141,7 +141,7 @@ func (opts *SkaffoldOptions) Mode() RunMode { return RunMode(opts.Command) } -func (opts *SkaffoldOptions) IsTargetImage(artifact *latestV1.Artifact) bool { +func (opts *SkaffoldOptions) IsTargetImage(artifact *latest.Artifact) bool { if len(opts.TargetImages) == 0 { return true } diff --git a/pkg/skaffold/config/options_test.go b/pkg/skaffold/config/options_test.go index d9f993fd8c0..b407d432ea0 100644 --- a/pkg/skaffold/config/options_test.go +++ b/pkg/skaffold/config/options_test.go @@ -19,7 +19,7 @@ package config import ( "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -61,7 +61,7 @@ func TestIsTargetImage(t *testing.T) { TargetImages: test.targetImages, } - match := opts.IsTargetImage(&latestV1.Artifact{ + match := opts.IsTargetImage(&latest.Artifact{ ImageName: "domain/image", }) diff --git a/pkg/skaffold/constants/constants.go b/pkg/skaffold/constants/constants.go index d9a9b2903d2..b9ae235d3ed 100644 --- a/pkg/skaffold/constants/constants.go +++ b/pkg/skaffold/constants/constants.go @@ -17,7 +17,7 @@ limitations under the License. package constants import ( - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) const ( @@ -77,8 +77,8 @@ const ( type Phase string var ( - Pod latestV1.ResourceType = "pod" - Service latestV1.ResourceType = "service" + Pod latest.ResourceType = "pod" + Service latest.ResourceType = "service" DefaultLocalConcurrency = 1 ) diff --git a/pkg/skaffold/deploy/component/kubernetes/accessor_test.go b/pkg/skaffold/deploy/component/kubernetes/accessor_test.go index bc91ba708ec..d17ad76eb15 100644 --- a/pkg/skaffold/deploy/component/kubernetes/accessor_test.go +++ b/pkg/skaffold/deploy/component/kubernetes/accessor_test.go @@ -25,7 +25,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/label" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/portforward" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -38,7 +38,7 @@ func (m mockAccessConfig) Mode() config.RunMode { return "" } func (m mockAccessConfig) PortForwardOptions() config.PortForwardOptions { return m.opts } -func (m mockAccessConfig) PortForwardResources() []*v1.PortForwardResource { return nil } +func (m mockAccessConfig) PortForwardResources() []*latest.PortForwardResource { return nil } func TestGetAccessor(t *testing.T) { tests := []struct { diff --git a/pkg/skaffold/deploy/deploy_mux_test.go b/pkg/skaffold/deploy/deploy_mux_test.go index 2164617793b..b041215499c 100644 --- a/pkg/skaffold/deploy/deploy_mux_test.go +++ b/pkg/skaffold/deploy/deploy_mux_test.go @@ -29,7 +29,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/debug" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/status" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync" "github.com/GoogleContainerTools/skaffold/testutil" @@ -160,11 +160,11 @@ func TestDeployerMux_Deploy(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - testEvent.InitializeState([]latestV1.Pipeline{{ - Deploy: latestV1.DeployConfig{}, - Build: latestV1.BuildConfig{ - BuildType: latestV1.BuildType{ - LocalBuild: &latestV1.LocalBuild{}, + testEvent.InitializeState([]latest.Pipeline{{ + Deploy: latest.DeployConfig{}, + Build: latest.BuildConfig{ + BuildType: latest.BuildType{ + LocalBuild: &latest.LocalBuild{}, }, }}}) diff --git a/pkg/skaffold/deploy/deploy_problems_test.go b/pkg/skaffold/deploy/deploy_problems_test.go index f7d555cc867..fb3454731fc 100644 --- a/pkg/skaffold/deploy/deploy_problems_test.go +++ b/pkg/skaffold/deploy/deploy_problems_test.go @@ -25,7 +25,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/proto/v1" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -108,20 +108,20 @@ type mockConfig struct { kubeContext string } -func (m mockConfig) MinikubeProfile() string { return m.minikube } -func (m mockConfig) GetPipelines() []latestV1.Pipeline { return []latestV1.Pipeline{} } -func (m mockConfig) GetWorkingDir() string { return "" } -func (m mockConfig) GetNamespace() string { return "" } -func (m mockConfig) GlobalConfig() string { return "" } -func (m mockConfig) ConfigurationFile() string { return "" } -func (m mockConfig) DefaultRepo() *string { return &m.minikube } -func (m mockConfig) MultiLevelRepo() *bool { return nil } -func (m mockConfig) SkipRender() bool { return true } -func (m mockConfig) Prune() bool { return true } -func (m mockConfig) ContainerDebugging() bool { return false } -func (m mockConfig) GetKubeContext() string { return m.kubeContext } -func (m mockConfig) GetInsecureRegistries() map[string]bool { return map[string]bool{} } -func (m mockConfig) Mode() config.RunMode { return config.RunModes.Dev } -func (m mockConfig) TransformAllowList() []latestV1.ResourceFilter { return nil } -func (m mockConfig) TransformDenyList() []latestV1.ResourceFilter { return nil } -func (m mockConfig) TransformRulesFile() string { return "" } +func (m mockConfig) MinikubeProfile() string { return m.minikube } +func (m mockConfig) GetPipelines() []latest.Pipeline { return []latest.Pipeline{} } +func (m mockConfig) GetWorkingDir() string { return "" } +func (m mockConfig) GetNamespace() string { return "" } +func (m mockConfig) GlobalConfig() string { return "" } +func (m mockConfig) ConfigurationFile() string { return "" } +func (m mockConfig) DefaultRepo() *string { return &m.minikube } +func (m mockConfig) MultiLevelRepo() *bool { return nil } +func (m mockConfig) SkipRender() bool { return true } +func (m mockConfig) Prune() bool { return true } +func (m mockConfig) ContainerDebugging() bool { return false } +func (m mockConfig) GetKubeContext() string { return m.kubeContext } +func (m mockConfig) GetInsecureRegistries() map[string]bool { return map[string]bool{} } +func (m mockConfig) Mode() config.RunMode { return config.RunModes.Dev } +func (m mockConfig) TransformAllowList() []latest.ResourceFilter { return nil } +func (m mockConfig) TransformDenyList() []latest.ResourceFilter { return nil } +func (m mockConfig) TransformRulesFile() string { return "" } diff --git a/pkg/skaffold/deploy/docker/deploy.go b/pkg/skaffold/deploy/docker/deploy.go index 544f6504367..89d9e617e39 100644 --- a/pkg/skaffold/deploy/docker/deploy.go +++ b/pkg/skaffold/deploy/docker/deploy.go @@ -40,7 +40,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" olog "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/status" pkgsync "github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" @@ -52,18 +52,18 @@ type Deployer struct { monitor status.Monitor syncer pkgsync.Syncer - cfg *v1.DockerDeploy + cfg *latest.DockerDeploy tracker *tracker.ContainerTracker portManager *PortManager // functions as Accessor client dockerutil.LocalDaemon network string globalConfig string insecureRegistries map[string]bool - resources []*v1.PortForwardResource + resources []*latest.PortForwardResource once sync.Once } -func NewDeployer(ctx context.Context, cfg dockerutil.Config, labeller *label.DefaultLabeller, d *v1.DockerDeploy, resources []*v1.PortForwardResource) (*Deployer, error) { +func NewDeployer(ctx context.Context, cfg dockerutil.Config, labeller *label.DefaultLabeller, d *latest.DockerDeploy, resources []*latest.PortForwardResource) (*Deployer, error) { client, err := dockerutil.NewAPIClient(ctx, cfg) if err != nil { return nil, err diff --git a/pkg/skaffold/deploy/docker/port.go b/pkg/skaffold/deploy/docker/port.go index a2a98057a0f..1e78245fa1a 100644 --- a/pkg/skaffold/deploy/docker/port.go +++ b/pkg/skaffold/deploy/docker/port.go @@ -31,7 +31,7 @@ import ( eventV2 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event/v2" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" schemautil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -81,7 +81,7 @@ func (pm *PortManager) Stop() { These ports are added to the provided container configuration's port set, and the bindings are returned to be passed to ContainerCreate on Deploy to expose container ports on the host. */ -func (pm *PortManager) allocatePorts(containerName string, pf []*v1.PortForwardResource, cfg *container.Config, debugBindings nat.PortMap) (nat.PortMap, error) { +func (pm *PortManager) allocatePorts(containerName string, pf []*latest.PortForwardResource, cfg *container.Config, debugBindings nat.PortMap) (nat.PortMap, error) { pm.lock.Lock() defer pm.lock.Unlock() m := make(nat.PortMap) diff --git a/pkg/skaffold/deploy/docker/port_test.go b/pkg/skaffold/deploy/docker/port_test.go index 8bcec4ee4b2..07e8b67a703 100644 --- a/pkg/skaffold/deploy/docker/port_test.go +++ b/pkg/skaffold/deploy/docker/port_test.go @@ -22,7 +22,7 @@ import ( "github.com/docker/docker/api/types/container" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" schemautil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" @@ -31,11 +31,11 @@ import ( func TestAllocatePorts(t *testing.T) { tests := []struct { name string - resources map[int]*v1.PortForwardResource // we map local port to resources for ease of testing + resources map[int]*latest.PortForwardResource // we map local port to resources for ease of testing }{ { name: "one port, one resource", - resources: map[int]*v1.PortForwardResource{ + resources: map[int]*latest.PortForwardResource{ 9000: { Type: "container", Port: schemautil.IntOrString{ @@ -49,7 +49,7 @@ func TestAllocatePorts(t *testing.T) { }, { name: "two ports, two resources", - resources: map[int]*v1.PortForwardResource{ + resources: map[int]*latest.PortForwardResource{ 1234: { Type: "container", Port: schemautil.IntOrString{ @@ -92,15 +92,15 @@ func TestAllocatePorts(t *testing.T) { } } -func collectResources(resourceMap map[int]*v1.PortForwardResource) []*v1.PortForwardResource { - var resources []*v1.PortForwardResource +func collectResources(resourceMap map[int]*latest.PortForwardResource) []*latest.PortForwardResource { + var resources []*latest.PortForwardResource for _, r := range resourceMap { resources = append(resources, r) } return resources } -func resourceFromContainerPort(resourceMap map[int]*v1.PortForwardResource, containerPort int) *v1.PortForwardResource { +func resourceFromContainerPort(resourceMap map[int]*latest.PortForwardResource, containerPort int) *latest.PortForwardResource { for _, resource := range resourceMap { if resource.Port.IntVal == containerPort { return resource diff --git a/pkg/skaffold/deploy/helm/args.go b/pkg/skaffold/deploy/helm/args.go index 0fbef55c32c..9cd2cc5c099 100644 --- a/pkg/skaffold/deploy/helm/args.go +++ b/pkg/skaffold/deploy/helm/args.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -47,7 +47,7 @@ type installOpts struct { } // constructOverrideArgs creates the command line arguments for overrides -func constructOverrideArgs(r *latestV1.HelmRelease, builds []graph.Artifact, args []string, record func(string)) ([]string, error) { +func constructOverrideArgs(r *latest.HelmRelease, builds []graph.Artifact, args []string, record func(string)) ([]string, error) { for _, k := range sortKeys(r.SetValues) { record(r.SetValues[k]) args = append(args, "--set", fmt.Sprintf("%s=%s", k, r.SetValues[k])) @@ -117,7 +117,7 @@ func getArgs(releaseName string, namespace string) []string { } // installArgs calculates the correct arguments to "helm install" -func (h *Deployer) installArgs(r latestV1.HelmRelease, builds []graph.Artifact, valuesSet map[string]bool, o installOpts) ([]string, error) { +func (h *Deployer) installArgs(r latest.HelmRelease, builds []graph.Artifact, valuesSet map[string]bool, o installOpts) ([]string, error) { var args []string if o.upgrade { args = append(args, "upgrade", o.releaseName) diff --git a/pkg/skaffold/deploy/helm/deploy.go b/pkg/skaffold/deploy/helm/deploy.go index 7471440a19c..563a323c301 100644 --- a/pkg/skaffold/deploy/helm/deploy.go +++ b/pkg/skaffold/deploy/helm/deploy.go @@ -57,7 +57,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" olog "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/status" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" @@ -86,7 +86,7 @@ var ( // Deployer deploys workflows using the helm CLI type Deployer struct { - *latestV1.HelmDeploy + *latest.HelmDeploy accessor access.Accessor debugger debug.Debugger @@ -125,11 +125,11 @@ type Config interface { kloader.Config portforward.Config IsMultiConfig() bool - JSONParseConfig() latestV1.JSONParseConfig + JSONParseConfig() latest.JSONParseConfig } // NewDeployer returns a configured Deployer. Returns an error if current version of helm is less than 3.0.0. -func NewDeployer(ctx context.Context, cfg Config, labeller *label.DefaultLabeller, h *latestV1.HelmDeploy) (*Deployer, error) { +func NewDeployer(ctx context.Context, cfg Config, labeller *label.DefaultLabeller, h *latest.HelmDeploy) (*Deployer, error) { hv, err := binVer(ctx) if err != nil { return nil, versionGetErr(err) @@ -473,7 +473,7 @@ func (h *Deployer) PostDeployHooks(ctx context.Context, out io.Writer) error { } // deployRelease deploys a single release -func (h *Deployer) deployRelease(ctx context.Context, out io.Writer, releaseName string, r latestV1.HelmRelease, builds []graph.Artifact, valuesSet map[string]bool, helmVersion semver.Version, chartVersion string) ([]types.Artifact, error) { +func (h *Deployer) deployRelease(ctx context.Context, out io.Writer, releaseName string, r latest.HelmRelease, builds []graph.Artifact, valuesSet map[string]bool, helmVersion semver.Version, chartVersion string) ([]types.Artifact, error) { var err error opts := installOpts{ releaseName: releaseName, @@ -614,7 +614,7 @@ func (h *Deployer) getReleaseManifest(ctx context.Context, releaseName string, n } // packageChart packages the chart and returns the path to the resulting chart archive -func (h *Deployer) packageChart(ctx context.Context, r latestV1.HelmRelease) (string, error) { +func (h *Deployer) packageChart(ctx context.Context, r latest.HelmRelease) (string, error) { // Allow a test to sneak a predictable path in tmpDir := h.pkgTmpDir @@ -660,7 +660,7 @@ func (h *Deployer) packageChart(ctx context.Context, r latestV1.HelmRelease) (st return output[idx:], nil } -func chartSource(r latestV1.HelmRelease) string { +func chartSource(r latest.HelmRelease) string { if r.RemoteChart != "" { return r.RemoteChart } diff --git a/pkg/skaffold/deploy/helm/helm_test.go b/pkg/skaffold/deploy/helm/helm_test.go index 12152ba9e90..6c924e88161 100644 --- a/pkg/skaffold/deploy/helm/helm_test.go +++ b/pkg/skaffold/deploy/helm/helm_test.go @@ -39,7 +39,7 @@ import ( kubectx "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/logger" "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/latest" schemautil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/warnings" @@ -56,8 +56,8 @@ var testBuildsFoo = []graph.Artifact{{ Tag: "foo:3605e7bc17cf46e53f4d81c4cbc24e5b4c495184", }} -var testDeployConfig = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployConfig = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm", ChartPath: "examples/test", ArtifactOverrides: map[string]string{ @@ -70,8 +70,8 @@ var testDeployConfig = latestV1.HelmDeploy{ }}, } -var testDeployNamespacedConfig = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployNamespacedConfig = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm", ChartPath: "examples/test", ArtifactOverrides: map[string]string{ @@ -85,8 +85,8 @@ var testDeployNamespacedConfig = latestV1.HelmDeploy{ }}, } -var testDeployEnvTemplateNamespacedConfig = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployEnvTemplateNamespacedConfig = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm", ChartPath: "examples/test", ArtifactOverrides: map[string]string{ @@ -100,8 +100,8 @@ var testDeployEnvTemplateNamespacedConfig = latestV1.HelmDeploy{ }}, } -var testDeployConfigRemoteRepo = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployConfigRemoteRepo = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm", ChartPath: "examples/test", ArtifactOverrides: map[string]string{ @@ -115,8 +115,8 @@ var testDeployConfigRemoteRepo = latestV1.HelmDeploy{ }}, } -var testDeployConfigTemplated = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployConfigTemplated = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm", ChartPath: "examples/test", ArtifactOverrides: map[string]string{ @@ -134,8 +134,8 @@ var testDeployConfigTemplated = latestV1.HelmDeploy{ }}, } -var testDeployConfigValuesFilesTemplated = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployConfigValuesFilesTemplated = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm", ChartPath: "examples/test", ArtifactOverrides: map[string]string{ @@ -148,8 +148,8 @@ var testDeployConfigValuesFilesTemplated = latestV1.HelmDeploy{ }}, } -var testDeployConfigVersionTemplated = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployConfigVersionTemplated = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm", ChartPath: "examples/test", ArtifactOverrides: map[string]string{ @@ -159,8 +159,8 @@ var testDeployConfigVersionTemplated = latestV1.HelmDeploy{ }}, } -var testDeployConfigSetFiles = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployConfigSetFiles = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm", ChartPath: "examples/test", ArtifactOverrides: map[string]string{ @@ -174,8 +174,8 @@ var testDeployConfigSetFiles = latestV1.HelmDeploy{ }}, } -var testDeployRecreatePodsConfig = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployRecreatePodsConfig = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm", ChartPath: "examples/test", ArtifactOverrides: map[string]string{ @@ -189,8 +189,8 @@ var testDeployRecreatePodsConfig = latestV1.HelmDeploy{ }}, } -var testDeploySkipBuildDependenciesConfig = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeploySkipBuildDependenciesConfig = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm", ChartPath: "examples/test", ArtifactOverrides: map[string]string{ @@ -204,8 +204,8 @@ var testDeploySkipBuildDependenciesConfig = latestV1.HelmDeploy{ }}, } -var testDeployHelmStyleConfig = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployHelmStyleConfig = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm", ChartPath: "examples/test", ArtifactOverrides: map[string]string{ @@ -215,16 +215,16 @@ var testDeployHelmStyleConfig = latestV1.HelmDeploy{ SetValues: map[string]string{ "some.key": "somevalue", }, - ImageStrategy: latestV1.HelmImageStrategy{ - HelmImageConfig: latestV1.HelmImageConfig{ - HelmConventionConfig: &latestV1.HelmConventionConfig{}, + ImageStrategy: latest.HelmImageStrategy{ + HelmImageConfig: latest.HelmImageConfig{ + HelmConventionConfig: &latest.HelmConventionConfig{}, }, }, }}, } -var testDeployHelmExplicitRegistryStyleConfig = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployHelmExplicitRegistryStyleConfig = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm", ChartPath: "examples/test", ArtifactOverrides: map[string]string{ @@ -234,9 +234,9 @@ var testDeployHelmExplicitRegistryStyleConfig = latestV1.HelmDeploy{ SetValues: map[string]string{ "some.key": "somevalue", }, - ImageStrategy: latestV1.HelmImageStrategy{ - HelmImageConfig: latestV1.HelmImageConfig{ - HelmConventionConfig: &latestV1.HelmConventionConfig{ + ImageStrategy: latest.HelmImageStrategy{ + HelmImageConfig: latest.HelmImageConfig{ + HelmConventionConfig: &latest.HelmConventionConfig{ ExplicitRegistry: true, }, }, @@ -244,8 +244,8 @@ var testDeployHelmExplicitRegistryStyleConfig = latestV1.HelmDeploy{ }}, } -var testDeployConfigParameterUnmatched = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployConfigParameterUnmatched = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm", ChartPath: "examples/test", ArtifactOverrides: map[string]string{ @@ -254,22 +254,22 @@ var testDeployConfigParameterUnmatched = latestV1.HelmDeploy{ }, } -var testDeployFooWithPackaged = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployFooWithPackaged = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "foo", ChartPath: "testdata/foo", ArtifactOverrides: map[string]string{ "image": "foo", }, - Packaged: &latestV1.HelmPackaged{ + Packaged: &latest.HelmPackaged{ Version: "0.1.2", AppVersion: "1.2.3", }, }}, } -var testDeployWithTemplatedName = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployWithTemplatedName = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "{{.USER}}-skaffold-helm", ChartPath: "examples/test", ArtifactOverrides: map[string]string{ @@ -282,8 +282,8 @@ var testDeployWithTemplatedName = latestV1.HelmDeploy{ }, } -var testDeploySkipBuildDependencies = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeploySkipBuildDependencies = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm", ChartPath: "stable/chartmuseum", ArtifactOverrides: map[string]string{ @@ -293,16 +293,16 @@ var testDeploySkipBuildDependencies = latestV1.HelmDeploy{ }}, } -var testDeployRemoteChart = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployRemoteChart = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm-remote", RemoteChart: "stable/chartmuseum", Repo: "https://charts.helm.sh/stable", }}, } -var testDeployRemoteChartVersion = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployRemoteChartVersion = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm-remote", RemoteChart: "stable/chartmuseum", Version: "1.0.0", @@ -311,23 +311,23 @@ var testDeployRemoteChartVersion = latestV1.HelmDeploy{ } var upgradeOnChangeFalse = false -var testDeployUpgradeOnChange = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployUpgradeOnChange = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm-upgradeOnChange", ChartPath: "examples/test", UpgradeOnChange: &upgradeOnChangeFalse, }}, } -var testDeployWithoutTags = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployWithoutTags = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm", ChartPath: "examples/test", }}, } -var testTwoReleases = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testTwoReleases = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "other", ChartPath: "examples/test", }, { @@ -340,8 +340,8 @@ var testTwoReleases = latestV1.HelmDeploy{ } var createNamespaceFlag = true -var testDeployCreateNamespaceConfig = latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ +var testDeployCreateNamespaceConfig = latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm", ChartPath: "examples/test", ArtifactOverrides: map[string]string{ @@ -513,7 +513,7 @@ func TestHelmDeploy(t *testing.T) { description string commands util.Command env []string - helm latestV1.HelmDeploy + helm latest.HelmDeploy namespace string configure func(*Deployer) builds []graph.Artifact @@ -1109,7 +1109,7 @@ func TestHelmCleanup(t *testing.T) { tests := []struct { description string commands util.Command - helm latestV1.HelmDeploy + helm latest.HelmDeploy namespace string builds []graph.Artifact expectedWarnings []string @@ -1279,8 +1279,8 @@ func TestHelmDependencies(t *testing.T) { local = tmpDir.Root() } - deployer, err := NewDeployer(context.Background(), &helmConfig{}, &label.DefaultLabeller{}, &latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{{ + deployer, err := NewDeployer(context.Background(), &helmConfig{}, &label.DefaultLabeller{}, &latest.HelmDeploy{ + Releases: []latest.HelmRelease{{ Name: "skaffold-helm", ChartPath: local, RemoteChart: remote, @@ -1306,7 +1306,7 @@ func TestImageSetFromConfig(t *testing.T) { valueName string tag string expected string - strategy *latestV1.HelmConventionConfig + strategy *latest.HelmConventionConfig shouldErr bool }{ { @@ -1322,7 +1322,7 @@ func TestImageSetFromConfig(t *testing.T) { valueName: "image", tag: "skaffold-helm:1.0.0", expected: "image.repository=skaffold-helm,image.tag=1.0.0", - strategy: &latestV1.HelmConventionConfig{}, + strategy: &latest.HelmConventionConfig{}, shouldErr: false, }, { @@ -1330,7 +1330,7 @@ func TestImageSetFromConfig(t *testing.T) { valueName: "image", tag: "docker.io/skaffold-helm:1.0.0", expected: "image.registry=docker.io,image.repository=skaffold-helm,image.tag=1.0.0", - strategy: &latestV1.HelmConventionConfig{ + strategy: &latest.HelmConventionConfig{ ExplicitRegistry: true, }, shouldErr: false, @@ -1340,7 +1340,7 @@ func TestImageSetFromConfig(t *testing.T) { valueName: "image", tag: "skaffold-helm:1.0.0,0", expected: "", - strategy: &latestV1.HelmConventionConfig{}, + strategy: &latest.HelmConventionConfig{}, shouldErr: true, }, { @@ -1348,7 +1348,7 @@ func TestImageSetFromConfig(t *testing.T) { valueName: "image", tag: "skaffold-helm:1.0.0", expected: "", - strategy: &latestV1.HelmConventionConfig{ + strategy: &latest.HelmConventionConfig{ ExplicitRegistry: true, }, shouldErr: true, @@ -1358,7 +1358,7 @@ func TestImageSetFromConfig(t *testing.T) { valueName: "image", tag: "skaffold-helm:stable@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2", expected: "image.repository=skaffold-helm,image.tag=stable@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2", - strategy: &latestV1.HelmConventionConfig{}, + strategy: &latest.HelmConventionConfig{}, shouldErr: false, }, } @@ -1376,7 +1376,7 @@ func TestHelmRender(t *testing.T) { description string shouldErr bool commands util.Command - helm latestV1.HelmDeploy + helm latest.HelmDeploy env []string outputFile string expected string @@ -1654,7 +1654,7 @@ func TestHelmHooks(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { t.Override(&util.DefaultExecCommand, testutil.CmdRunWithOutput("helm version --client", version31)) - t.Override(&hooks.NewDeployRunner, func(*ctl.CLI, latestV1.DeployHooks, *[]string, logger.Formatter, hooks.DeployEnvOpts) hooks.Runner { + t.Override(&hooks.NewDeployRunner, func(*ctl.CLI, latest.DeployHooks, *[]string, logger.Formatter, hooks.DeployEnvOpts) hooks.Runner { return test.runner }) @@ -1675,34 +1675,34 @@ type helmConfig struct { configFile string } -func (c *helmConfig) ForceDeploy() bool { return c.force } -func (c *helmConfig) GetKubeConfig() string { return kubectl.TestKubeConfig } -func (c *helmConfig) GetKubeContext() string { return kubectl.TestKubeContext } -func (c *helmConfig) GetKubeNamespace() string { return c.namespace } -func (c *helmConfig) ConfigurationFile() string { return c.configFile } -func (c *helmConfig) PortForwardResources() []*latestV1.PortForwardResource { return nil } +func (c *helmConfig) ForceDeploy() bool { return c.force } +func (c *helmConfig) GetKubeConfig() string { return kubectl.TestKubeConfig } +func (c *helmConfig) GetKubeContext() string { return kubectl.TestKubeContext } +func (c *helmConfig) GetKubeNamespace() string { return c.namespace } +func (c *helmConfig) ConfigurationFile() string { return c.configFile } +func (c *helmConfig) PortForwardResources() []*latest.PortForwardResource { return nil } func TestHasRunnableHooks(t *testing.T) { tests := []struct { description string - cfg latestV1.HelmDeploy + cfg latest.HelmDeploy expected bool }{ { description: "no hooks defined", - cfg: latestV1.HelmDeploy{}, + cfg: latest.HelmDeploy{}, }, { description: "has pre-deploy hook defined", - cfg: latestV1.HelmDeploy{ - LifecycleHooks: latestV1.DeployHooks{PreHooks: []latestV1.DeployHookItem{{}}}, + cfg: latest.HelmDeploy{ + LifecycleHooks: latest.DeployHooks{PreHooks: []latest.DeployHookItem{{}}}, }, expected: true, }, { description: "has post-deploy hook defined", - cfg: latestV1.HelmDeploy{ - LifecycleHooks: latestV1.DeployHooks{PostHooks: []latestV1.DeployHookItem{{}}}, + cfg: latest.HelmDeploy{ + LifecycleHooks: latest.DeployHooks{PostHooks: []latest.DeployHookItem{{}}}, }, expected: true, }, diff --git a/pkg/skaffold/deploy/helm/util.go b/pkg/skaffold/deploy/helm/util.go index 5934169bd1c..a06bba04d30 100644 --- a/pkg/skaffold/deploy/helm/util.go +++ b/pkg/skaffold/deploy/helm/util.go @@ -34,7 +34,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -92,7 +92,7 @@ func binVer(ctx context.Context) (semver.Version, error) { } // imageSetFromConfig calculates the --set-string value from the helm config -func imageSetFromConfig(cfg *latestV1.HelmConventionConfig, valueName string, tag string) (string, error) { +func imageSetFromConfig(cfg *latest.HelmConventionConfig, valueName string, tag string) (string, error) { if cfg == nil { return fmt.Sprintf("%s=%s", valueName, tag), nil } @@ -153,7 +153,7 @@ func (h *Deployer) generateSkaffoldDebugFilter(buildsFile string) []string { return args } -func (h *Deployer) releaseNamespace(r latestV1.HelmRelease) (string, error) { +func (h *Deployer) releaseNamespace(r latest.HelmRelease) (string, error) { if h.namespace != "" { return h.namespace, nil } else if r.Namespace != "" { diff --git a/pkg/skaffold/deploy/kpt/kpt.go b/pkg/skaffold/deploy/kpt/kpt.go index f2a6b2fc7d5..7447d14207e 100644 --- a/pkg/skaffold/deploy/kpt/kpt.go +++ b/pkg/skaffold/deploy/kpt/kpt.go @@ -54,7 +54,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" olog "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/status" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" @@ -79,7 +79,7 @@ const ( // Deployer deploys workflows with kpt CLI type Deployer struct { - *latestV1.KptDeploy + *latest.KptDeploy accessor access.Accessor logger log.Logger @@ -102,8 +102,8 @@ type Deployer struct { namespaces *[]string - transformableAllowlist map[apimachinery.GroupKind]latestV1.ResourceFilter - transformableDenylist map[apimachinery.GroupKind]latestV1.ResourceFilter + transformableAllowlist map[apimachinery.GroupKind]latest.ResourceFilter + transformableDenylist map[apimachinery.GroupKind]latest.ResourceFilter } type Config interface { @@ -114,7 +114,7 @@ type Config interface { } // NewDeployer generates a new Deployer object contains the kptDeploy schema. -func NewDeployer(cfg Config, labeller *label.DefaultLabeller, d *latestV1.KptDeploy) (*Deployer, error) { +func NewDeployer(cfg Config, labeller *label.DefaultLabeller, d *latest.KptDeploy) (*Deployer, error) { podSelector := kubernetes.NewImageList() kubectl := pkgkubectl.NewCLI(cfg, cfg.GetKubeNamespace()) namespaces, err := deployutil.GetAllPodNamespaces(cfg.GetNamespace(), cfg.GetPipelines()) diff --git a/pkg/skaffold/deploy/kpt/kpt_test.go b/pkg/skaffold/deploy/kpt/kpt_test.go index 8d9ee193c10..32a32801202 100644 --- a/pkg/skaffold/deploy/kpt/kpt_test.go +++ b/pkg/skaffold/deploy/kpt/kpt_test.go @@ -34,7 +34,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/manifest" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -63,7 +63,7 @@ func TestKpt_Deploy(t *testing.T) { tests := []struct { description string builds []graph.Artifact - kpt latestV1.KptDeploy + kpt latest.KptDeploy hasKustomization func(string) bool commands util.Command expected []string @@ -71,7 +71,7 @@ func TestKpt_Deploy(t *testing.T) { }{ { description: "no manifest", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", }, commands: testutil. @@ -81,7 +81,7 @@ func TestKpt_Deploy(t *testing.T) { }, { description: "invalid manifest", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", }, commands: testutil. @@ -93,10 +93,10 @@ func TestKpt_Deploy(t *testing.T) { }, { description: "invalid user specified applyDir", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", - Live: latestV1.KptLive{ - Apply: latestV1.KptApplyInventory{ + Live: latest.KptLive{ + Apply: latest.KptApplyInventory{ Dir: "invalid_path", }, }, @@ -111,11 +111,11 @@ func TestKpt_Deploy(t *testing.T) { { description: "kustomization and specified kpt fn", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", - Fn: latestV1.KptFn{FnPath: "kpt-func.yaml"}, - Live: latestV1.KptLive{ - Apply: latestV1.KptApplyInventory{ + Fn: latest.KptFn{FnPath: "kpt-func.yaml"}, + Live: latest.KptLive{ + Apply: latest.KptApplyInventory{ Dir: "valid_path", }, }, @@ -131,7 +131,7 @@ func TestKpt_Deploy(t *testing.T) { }, { description: "kpt live apply fails", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", }, commands: testutil. @@ -145,13 +145,13 @@ func TestKpt_Deploy(t *testing.T) { }, { description: "user specifies reconcile timeout and poll period", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", - Live: latestV1.KptLive{ - Apply: latestV1.KptApplyInventory{ + Live: latest.KptLive{ + Apply: latest.KptApplyInventory{ Dir: "valid_path", }, - Options: latestV1.KptApplyOptions{ + Options: latest.KptApplyOptions{ PollPeriod: "5s", ReconcileTimeout: "2m", }, @@ -166,13 +166,13 @@ func TestKpt_Deploy(t *testing.T) { }, { description: "user specifies invalid reconcile timeout and poll period", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", - Live: latestV1.KptLive{ - Apply: latestV1.KptApplyInventory{ + Live: latest.KptLive{ + Apply: latest.KptApplyInventory{ Dir: "valid_path", }, - Options: latestV1.KptApplyOptions{ + Options: latest.KptApplyOptions{ PollPeriod: "foo", ReconcileTimeout: "bar", }, @@ -187,13 +187,13 @@ func TestKpt_Deploy(t *testing.T) { }, { description: "user specifies prune propagation policy and prune timeout", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", - Live: latestV1.KptLive{ - Apply: latestV1.KptApplyInventory{ + Live: latest.KptLive{ + Apply: latest.KptApplyInventory{ Dir: "valid_path", }, - Options: latestV1.KptApplyOptions{ + Options: latest.KptApplyOptions{ PrunePropagationPolicy: "Orphan", PruneTimeout: "2m", }, @@ -208,13 +208,13 @@ func TestKpt_Deploy(t *testing.T) { }, { description: "user specifies invalid prune propagation policy and prune timeout", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", - Live: latestV1.KptLive{ - Apply: latestV1.KptApplyInventory{ + Live: latest.KptLive{ + Apply: latest.KptApplyInventory{ Dir: "valid_path", }, - Options: latestV1.KptApplyOptions{ + Options: latest.KptApplyOptions{ PrunePropagationPolicy: "foo", PruneTimeout: "bar", }, @@ -258,7 +258,7 @@ func TestKpt_Deploy(t *testing.T) { func TestKpt_Dependencies(t *testing.T) { tests := []struct { description string - kpt latestV1.KptDeploy + kpt latest.KptDeploy createFiles map[string]string kustomizations map[string]string expected []string @@ -266,20 +266,20 @@ func TestKpt_Dependencies(t *testing.T) { }{ { description: "bad dir", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: "invalid_path", }, shouldErr: true, }, { description: "empty dir and unspecified fnPath", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", }, }, { description: "dir", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", }, createFiles: map[string]string{ @@ -290,7 +290,7 @@ func TestKpt_Dependencies(t *testing.T) { }, { description: "dir with subdirs and file path variants", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", }, createFiles: map[string]string{ @@ -303,9 +303,9 @@ func TestKpt_Dependencies(t *testing.T) { }, { description: "fnpath inside directory", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", - Fn: latestV1.KptFn{FnPath: "."}, + Fn: latest.KptFn{FnPath: "."}, }, createFiles: map[string]string{ "./kpt-func.yaml": "", @@ -314,9 +314,9 @@ func TestKpt_Dependencies(t *testing.T) { }, { description: "fnpath outside directory", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: "./config", - Fn: latestV1.KptFn{FnPath: "./kpt-fn"}, + Fn: latest.KptFn{FnPath: "./kpt-fn"}, }, createFiles: map[string]string{ "./config/deployment.yaml": "", @@ -327,9 +327,9 @@ func TestKpt_Dependencies(t *testing.T) { { description: "fnpath and dir and kustomization", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", - Fn: latestV1.KptFn{FnPath: "./kpt-fn"}, + Fn: latest.KptFn{FnPath: "./kpt-fn"}, }, createFiles: map[string]string{ "./kpt-fn/func.yaml": "", @@ -340,7 +340,7 @@ func TestKpt_Dependencies(t *testing.T) { }, { description: "dependencies that can only be detected as a kustomization", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", }, kustomizations: map[string]string{"kustomization.yaml": `configMapGenerator: @@ -349,7 +349,7 @@ func TestKpt_Dependencies(t *testing.T) { }, { description: "kustomization.yml variant", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", }, kustomizations: map[string]string{"kustomization.yml": `configMapGenerator: @@ -358,7 +358,7 @@ func TestKpt_Dependencies(t *testing.T) { }, { description: "Kustomization variant", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", }, kustomizations: map[string]string{"Kustomization": `configMapGenerator: @@ -367,7 +367,7 @@ func TestKpt_Dependencies(t *testing.T) { }, { description: "incorrectly named kustomization", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", }, kustomizations: map[string]string{"customization": `configMapGenerator: @@ -437,9 +437,9 @@ func TestKpt_Cleanup(t *testing.T) { k, err := NewDeployer(&kptConfig{ workingDir: ".", - }, &label.DefaultLabeller{}, &latestV1.KptDeploy{ - Live: latestV1.KptLive{ - Apply: latestV1.KptApplyInventory{ + }, &label.DefaultLabeller{}, &latest.KptDeploy{ + Live: latest.KptLive{ + Apply: latest.KptApplyInventory{ Dir: test.applyDir, }, }, @@ -503,7 +503,7 @@ spec: description string builds []graph.Artifact labels []string - kpt latestV1.KptDeploy + kpt latest.KptDeploy commands util.Command hasKustomization func(string) bool expected string @@ -517,7 +517,7 @@ spec: Tag: "gcr.io/project/image1:tag1", }, }, - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", }, commands: testutil. @@ -548,9 +548,9 @@ spec: }, }, labels: []string{"user/label=test"}, - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: "test", - Fn: latestV1.KptFn{FnPath: "kpt-func.yaml"}, + Fn: latest.KptFn{FnPath: "kpt-func.yaml"}, }, commands: testutil. CmdRunOut("kpt fn source test", ``). @@ -592,9 +592,9 @@ spec: Tag: "gcr.io/project/image2:tag2", }, }, - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", - Fn: latestV1.KptFn{Image: "gcr.io/example.com/my-fn:v1.0.0 -- foo=bar"}, + Fn: latest.KptFn{Image: "gcr.io/example.com/my-fn:v1.0.0 -- foo=bar"}, }, commands: testutil. CmdRunOut("kpt fn source .", ``). @@ -622,7 +622,7 @@ spec: }, }, labels: []string{"user/label=test"}, - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", }, commands: testutil. @@ -634,9 +634,9 @@ spec: }, { description: "both fnPath and image specified", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", - Fn: latestV1.KptFn{ + Fn: latest.KptFn{ FnPath: "kpt-func.yaml", Image: "gcr.io/example.com/my-fn:v1.0.0 -- foo=bar"}, }, @@ -656,7 +656,7 @@ spec: Tag: "gcr.io/project/image1:tag1", }, }, - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", }, commands: testutil. @@ -677,7 +677,7 @@ spec: }, { description: "reading configs from sourceDir fails", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", }, commands: testutil. @@ -689,7 +689,7 @@ spec: }, { description: "outputting configs to sinkDir fails", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", }, commands: testutil. @@ -707,7 +707,7 @@ spec: Tag: "gcr.io/project/image1:tag1", }, }, - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", }, commands: testutil. @@ -720,7 +720,7 @@ spec: }, { description: "kpt fn run fails", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", }, commands: testutil. @@ -731,9 +731,9 @@ spec: }, { description: "kpt fn run with --global-scope", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", - Fn: latestV1.KptFn{ + Fn: latest.KptFn{ Image: "gcr.io/example.com/my-fn:v1.0.0 -- foo=bar", GlobalScope: true, }, @@ -747,9 +747,9 @@ spec: }, { description: "kpt fn run with --mount arguments", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", - Fn: latestV1.KptFn{ + Fn: latest.KptFn{ Image: "gcr.io/example.com/my-fn:v1.0.0 -- foo=bar", Mount: []string{"type=bind", "src=$(pwd)", "dst=/source"}, }, @@ -763,9 +763,9 @@ spec: }, { description: "kpt fn run with invalid --mount arguments", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", - Fn: latestV1.KptFn{ + Fn: latest.KptFn{ Image: "gcr.io/example.com/my-fn:v1.0.0 -- foo=bar", Mount: []string{"foo", "", "bar"}, }, @@ -779,9 +779,9 @@ spec: }, { description: "kpt fn run flag with --network and --network-name arguments", - kpt: latestV1.KptDeploy{ + kpt: latest.KptDeploy{ Dir: ".", - Fn: latestV1.KptFn{ + Fn: latest.KptFn{ Image: "gcr.io/example.com/my-fn:v1.0.0 -- foo=bar", Network: true, NetworkName: "foo", @@ -822,15 +822,15 @@ spec: func TestKpt_GetApplyDir(t *testing.T) { tests := []struct { description string - live latestV1.KptLive + live latest.KptLive expected string commands util.Command shouldErr bool }{ { description: "specified an invalid applyDir", - live: latestV1.KptLive{ - Apply: latestV1.KptApplyInventory{ + live: latest.KptLive{ + Apply: latest.KptApplyInventory{ Dir: "invalid_path", }, }, @@ -838,8 +838,8 @@ func TestKpt_GetApplyDir(t *testing.T) { }, { description: "specified a valid applyDir", - live: latestV1.KptLive{ - Apply: latestV1.KptApplyInventory{ + live: latest.KptLive{ + Apply: latest.KptApplyInventory{ Dir: "valid_path", }, }, @@ -852,8 +852,8 @@ func TestKpt_GetApplyDir(t *testing.T) { }, { description: "unspecified applyDir with specified inventory-id and namespace", - live: latestV1.KptLive{ - Apply: latestV1.KptApplyInventory{ + live: latest.KptLive{ + Apply: latest.KptApplyInventory{ InventoryID: "1a23bcde-4f56-7891-a2bc-de34fabcde5f6", InventoryNamespace: "foo", }, @@ -883,7 +883,7 @@ func TestKpt_GetApplyDir(t *testing.T) { k, err := NewDeployer(&kptConfig{ workingDir: ".", - }, &label.DefaultLabeller{}, &latestV1.KptDeploy{ + }, &label.DefaultLabeller{}, &latest.KptDeploy{ Live: test.live, }) if err != nil { @@ -1196,10 +1196,10 @@ func TestNonEmptyKubeconfig(t *testing.T) { testutil.Run(t, "", func(t *testutil.T) { t.Override(&util.DefaultExecCommand, commands) t.Override(&client.Client, deployutil.MockK8sClient) - k, err := NewDeployer(&kptConfig{config: "testConfigPath"}, &label.DefaultLabeller{}, &latestV1.KptDeploy{ + k, err := NewDeployer(&kptConfig{config: "testConfigPath"}, &label.DefaultLabeller{}, &latest.KptDeploy{ Dir: ".", - Live: latestV1.KptLive{ - Apply: latestV1.KptApplyInventory{ + Live: latest.KptLive{ + Apply: latest.KptApplyInventory{ Dir: "valid_path", }, }, @@ -1221,8 +1221,8 @@ type kptConfig struct { config string } -func (c *kptConfig) WorkingDir() string { return c.workingDir } -func (c *kptConfig) GetKubeContext() string { return kubectl.TestKubeContext } -func (c *kptConfig) GetKubeNamespace() string { return kubectl.TestNamespace } -func (c *kptConfig) GetKubeConfig() string { return c.config } -func (c *kptConfig) PortForwardResources() []*latestV1.PortForwardResource { return nil } +func (c *kptConfig) WorkingDir() string { return c.workingDir } +func (c *kptConfig) GetKubeContext() string { return kubectl.TestKubeContext } +func (c *kptConfig) GetKubeNamespace() string { return kubectl.TestNamespace } +func (c *kptConfig) GetKubeConfig() string { return c.config } +func (c *kptConfig) PortForwardResources() []*latest.PortForwardResource { return nil } diff --git a/pkg/skaffold/deploy/kubectl/cli.go b/pkg/skaffold/deploy/kubectl/cli.go index 3306288e496..937235a78fe 100644 --- a/pkg/skaffold/deploy/kubectl/cli.go +++ b/pkg/skaffold/deploy/kubectl/cli.go @@ -34,13 +34,13 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/portforward" kstatus "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/status" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // CLI holds parameters to run kubectl. type CLI struct { *kubectl.CLI - Flags latestV1.KubectlFlags + Flags latest.KubectlFlags forceDeploy bool waitForDeletions config.WaitForDeletions @@ -57,13 +57,13 @@ type Config interface { WaitForDeletions() config.WaitForDeletions Mode() config.RunMode HydratedManifests() []string - DefaultPipeline() latestV1.Pipeline + DefaultPipeline() latest.Pipeline Tail() bool - PipelineForImage(imageName string) (latestV1.Pipeline, bool) - JSONParseConfig() latestV1.JSONParseConfig + PipelineForImage(imageName string) (latest.Pipeline, bool) + JSONParseConfig() latest.JSONParseConfig } -func NewCLI(cfg Config, flags latestV1.KubectlFlags, defaultNamespace string) CLI { +func NewCLI(cfg Config, flags latest.KubectlFlags, defaultNamespace string) CLI { return CLI{ CLI: kubectl.NewCLI(cfg, defaultNamespace), Flags: flags, diff --git a/pkg/skaffold/deploy/kubectl/kubectl.go b/pkg/skaffold/deploy/kubectl/kubectl.go index f4664c00558..e15676074c8 100644 --- a/pkg/skaffold/deploy/kubectl/kubectl.go +++ b/pkg/skaffold/deploy/kubectl/kubectl.go @@ -48,7 +48,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" olog "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/status" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" @@ -57,7 +57,7 @@ import ( // Deployer deploys workflows using kubectl CLI. type Deployer struct { - *latestV1.KubectlDeploy + *latest.KubectlDeploy accessor access.Accessor imageLoader loader.ImageLoader @@ -82,13 +82,13 @@ type Deployer struct { namespaces *[]string - transformableAllowlist map[apimachinery.GroupKind]latestV1.ResourceFilter - transformableDenylist map[apimachinery.GroupKind]latestV1.ResourceFilter + transformableAllowlist map[apimachinery.GroupKind]latest.ResourceFilter + transformableDenylist map[apimachinery.GroupKind]latest.ResourceFilter } // NewDeployer returns a new Deployer for a DeployConfig filled // with the needed configuration for `kubectl apply` -func NewDeployer(cfg Config, labeller *label.DefaultLabeller, d *latestV1.KubectlDeploy) (*Deployer, error) { +func NewDeployer(cfg Config, labeller *label.DefaultLabeller, d *latest.KubectlDeploy) (*Deployer, error) { defaultNamespace := "" if d.DefaultNamespace != nil { var err error diff --git a/pkg/skaffold/deploy/kubectl/kubectl_test.go b/pkg/skaffold/deploy/kubectl/kubectl_test.go index 1cb7eb21a1e..e0b614767a0 100644 --- a/pkg/skaffold/deploy/kubectl/kubectl_test.go +++ b/pkg/skaffold/deploy/kubectl/kubectl_test.go @@ -34,7 +34,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/manifest" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -42,7 +42,7 @@ import ( func TestKubectlDeploy(t *testing.T) { tests := []struct { description string - kubectl latestV1.KubectlDeploy + kubectl latest.KubectlDeploy builds []graph.Artifact commands util.Command shouldErr bool @@ -53,15 +53,15 @@ func TestKubectlDeploy(t *testing.T) { }{ { description: "no manifest", - kubectl: latestV1.KubectlDeploy{}, + kubectl: latest.KubectlDeploy{}, commands: testutil.CmdRunOut("kubectl version --client -ojson", KubectlVersion112), waitForDeletions: true, }, { description: "deploy success (disable validation)", - kubectl: latestV1.KubectlDeploy{ + kubectl: latest.KubectlDeploy{ Manifests: []string{"deployment.yaml"}, - Flags: latestV1.KubectlFlags{ + Flags: latest.KubectlFlags{ DisableValidation: true, }, }, @@ -78,7 +78,7 @@ func TestKubectlDeploy(t *testing.T) { }, { description: "deploy success (forced)", - kubectl: latestV1.KubectlDeploy{ + kubectl: latest.KubectlDeploy{ Manifests: []string{"deployment.yaml"}, }, commands: testutil. @@ -95,7 +95,7 @@ func TestKubectlDeploy(t *testing.T) { }, { description: "deploy success", - kubectl: latestV1.KubectlDeploy{ + kubectl: latest.KubectlDeploy{ Manifests: []string{"deployment.yaml"}, }, commands: testutil. @@ -111,7 +111,7 @@ func TestKubectlDeploy(t *testing.T) { }, { description: "deploy success (kubectl v1.18)", - kubectl: latestV1.KubectlDeploy{ + kubectl: latest.KubectlDeploy{ Manifests: []string{"deployment.yaml"}, }, commands: testutil. @@ -127,7 +127,7 @@ func TestKubectlDeploy(t *testing.T) { }, { description: "deploy success (default namespace)", - kubectl: latestV1.KubectlDeploy{ + kubectl: latest.KubectlDeploy{ Manifests: []string{"deployment.yaml"}, DefaultNamespace: &TestNamespace2, }, @@ -145,7 +145,7 @@ func TestKubectlDeploy(t *testing.T) { }, { description: "deploy success (default namespace with env template)", - kubectl: latestV1.KubectlDeploy{ + kubectl: latest.KubectlDeploy{ Manifests: []string{"deployment.yaml"}, DefaultNamespace: &TestNamespace2FromEnvTemplate, }, @@ -166,7 +166,7 @@ func TestKubectlDeploy(t *testing.T) { }, { description: "http manifest", - kubectl: latestV1.KubectlDeploy{ + kubectl: latest.KubectlDeploy{ Manifests: []string{"deployment.yaml", "http://remote.yaml"}, }, commands: testutil. @@ -182,7 +182,7 @@ func TestKubectlDeploy(t *testing.T) { }, { description: "deploy command error", - kubectl: latestV1.KubectlDeploy{ + kubectl: latest.KubectlDeploy{ Manifests: []string{"deployment.yaml"}, }, commands: testutil. @@ -199,9 +199,9 @@ func TestKubectlDeploy(t *testing.T) { }, { description: "additional flags", - kubectl: latestV1.KubectlDeploy{ + kubectl: latest.KubectlDeploy{ Manifests: []string{"deployment.yaml"}, - Flags: latestV1.KubectlFlags{ + Flags: latest.KubectlFlags{ Global: []string{"-v=0"}, Apply: []string{"--overwrite=true"}, Delete: []string{"ignored"}, @@ -258,14 +258,14 @@ func TestKubectlDeploy(t *testing.T) { func TestKubectlCleanup(t *testing.T) { tests := []struct { description string - kubectl latestV1.KubectlDeploy + kubectl latest.KubectlDeploy commands util.Command shouldErr bool dryRun bool }{ { description: "cleanup dry-run", - kubectl: latestV1.KubectlDeploy{ + kubectl: latest.KubectlDeploy{ Manifests: []string{"deployment.yaml"}, }, commands: testutil. @@ -276,7 +276,7 @@ func TestKubectlCleanup(t *testing.T) { }, { description: "cleanup success", - kubectl: latestV1.KubectlDeploy{ + kubectl: latest.KubectlDeploy{ Manifests: []string{"deployment.yaml"}, }, commands: testutil. @@ -286,7 +286,7 @@ func TestKubectlCleanup(t *testing.T) { }, { description: "cleanup success (kubectl v1.18)", - kubectl: latestV1.KubectlDeploy{ + kubectl: latest.KubectlDeploy{ Manifests: []string{"deployment.yaml"}, }, commands: testutil. @@ -296,7 +296,7 @@ func TestKubectlCleanup(t *testing.T) { }, { description: "cleanup error", - kubectl: latestV1.KubectlDeploy{ + kubectl: latest.KubectlDeploy{ Manifests: []string{"deployment.yaml"}, }, commands: testutil. @@ -307,9 +307,9 @@ func TestKubectlCleanup(t *testing.T) { }, { description: "additional flags", - kubectl: latestV1.KubectlDeploy{ + kubectl: latest.KubectlDeploy{ Manifests: []string{"deployment.yaml"}, - Flags: latestV1.KubectlFlags{ + Flags: latest.KubectlFlags{ Global: []string{"-v=0"}, Apply: []string{"ignored"}, Delete: []string{"--grace-period=1"}, @@ -344,12 +344,12 @@ func TestKubectlCleanup(t *testing.T) { func TestKubectlDeployerRemoteCleanup(t *testing.T) { tests := []struct { description string - kubectl latestV1.KubectlDeploy + kubectl latest.KubectlDeploy commands util.Command }{ { description: "cleanup success", - kubectl: latestV1.KubectlDeploy{ + kubectl: latest.KubectlDeploy{ RemoteManifests: []string{"pod/leeroy-web"}, }, commands: testutil. @@ -359,7 +359,7 @@ func TestKubectlDeployerRemoteCleanup(t *testing.T) { }, { description: "cleanup error", - kubectl: latestV1.KubectlDeploy{ + kubectl: latest.KubectlDeploy{ RemoteManifests: []string{"anotherNamespace:pod/leeroy-web"}, }, commands: testutil. @@ -413,7 +413,7 @@ func TestKubectlRedeploy(t *testing.T) { Enabled: true, Delay: 0 * time.Millisecond, Max: 10 * time.Second}, - }, &label.DefaultLabeller{}, &latestV1.KubectlDeploy{Manifests: []string{tmpDir.Path("deployment-app.yaml"), tmpDir.Path("deployment-web.yaml")}}) + }, &label.DefaultLabeller{}, &latest.KubectlDeploy{Manifests: []string{tmpDir.Path("deployment-app.yaml"), tmpDir.Path("deployment-web.yaml")}}) t.RequireNoError(err) // Deploy one manifest @@ -478,7 +478,7 @@ func TestKubectlWaitForDeletions(t *testing.T) { Delay: 0 * time.Millisecond, Max: 10 * time.Second, }, - }, &label.DefaultLabeller{}, &latestV1.KubectlDeploy{Manifests: []string{tmpDir.Path("deployment-web.yaml")}}) + }, &label.DefaultLabeller{}, &latest.KubectlDeploy{Manifests: []string{tmpDir.Path("deployment-web.yaml")}}) t.RequireNoError(err) var out bytes.Buffer @@ -516,7 +516,7 @@ func TestKubectlWaitForDeletionsFails(t *testing.T) { Delay: 10 * time.Second, Max: 100 * time.Millisecond, }, - }, &label.DefaultLabeller{}, &latestV1.KubectlDeploy{Manifests: []string{tmpDir.Path("deployment-web.yaml")}}) + }, &label.DefaultLabeller{}, &latest.KubectlDeploy{Manifests: []string{tmpDir.Path("deployment-web.yaml")}}) t.RequireNoError(err) err = deployer.Deploy(context.Background(), ioutil.Discard, []graph.Artifact{ @@ -577,7 +577,7 @@ func TestDependencies(t *testing.T) { Touch("00/b.yaml", "00/a.yaml"). Chdir() - k, err := NewDeployer(&kubectlConfig{}, &label.DefaultLabeller{}, &latestV1.KubectlDeploy{Manifests: test.manifests}) + k, err := NewDeployer(&kubectlConfig{}, &label.DefaultLabeller{}, &latest.KubectlDeploy{Manifests: test.manifests}) t.RequireNoError(err) dependencies, err := k.Dependencies() @@ -694,7 +694,7 @@ spec: workingDir: ".", defaultRepo: "gcr.io/project", multiLevelRepo: util.BoolPtr(true), - }, &label.DefaultLabeller{}, &latestV1.KubectlDeploy{ + }, &label.DefaultLabeller{}, &latest.KubectlDeploy{ Manifests: []string{tmpDir.Path("deployment.yaml")}, }) t.RequireNoError(err) @@ -709,14 +709,14 @@ spec: func TestGCSManifests(t *testing.T) { tests := []struct { description string - kubectl latestV1.KubectlDeploy + kubectl latest.KubectlDeploy commands util.Command shouldErr bool skipRender bool }{ { description: "manifest from GCS", - kubectl: latestV1.KubectlDeploy{ + kubectl: latest.KubectlDeploy{ Manifests: []string{"gs://dev/deployment.yaml"}, }, commands: testutil. @@ -753,24 +753,24 @@ func TestGCSManifests(t *testing.T) { func TestHasRunnableHooks(t *testing.T) { tests := []struct { description string - cfg latestV1.KubectlDeploy + cfg latest.KubectlDeploy expected bool }{ { description: "no hooks defined", - cfg: latestV1.KubectlDeploy{}, + cfg: latest.KubectlDeploy{}, }, { description: "has pre-deploy hook defined", - cfg: latestV1.KubectlDeploy{ - LifecycleHooks: latestV1.DeployHooks{PreHooks: []latestV1.DeployHookItem{{}}}, + cfg: latest.KubectlDeploy{ + LifecycleHooks: latest.DeployHooks{PreHooks: []latest.DeployHookItem{{}}}, }, expected: true, }, { description: "has post-deploy hook defined", - cfg: latestV1.KubectlDeploy{ - LifecycleHooks: latestV1.DeployHooks{PostHooks: []latestV1.DeployHookItem{{}}}, + cfg: latest.KubectlDeploy{ + LifecycleHooks: latest.DeployHooks{PostHooks: []latest.DeployHookItem{{}}}, }, expected: true, }, @@ -795,12 +795,12 @@ type kubectlConfig struct { waitForDeletions config.WaitForDeletions } -func (c *kubectlConfig) GetKubeContext() string { return "kubecontext" } -func (c *kubectlConfig) GetKubeNamespace() string { return c.Opts.Namespace } -func (c *kubectlConfig) WorkingDir() string { return c.workingDir } -func (c *kubectlConfig) SkipRender() bool { return c.skipRender } -func (c *kubectlConfig) ForceDeploy() bool { return c.force } -func (c *kubectlConfig) DefaultRepo() *string { return &c.defaultRepo } -func (c *kubectlConfig) MultiLevelRepo() *bool { return c.multiLevelRepo } -func (c *kubectlConfig) WaitForDeletions() config.WaitForDeletions { return c.waitForDeletions } -func (c *kubectlConfig) PortForwardResources() []*latestV1.PortForwardResource { return nil } +func (c *kubectlConfig) GetKubeContext() string { return "kubecontext" } +func (c *kubectlConfig) GetKubeNamespace() string { return c.Opts.Namespace } +func (c *kubectlConfig) WorkingDir() string { return c.workingDir } +func (c *kubectlConfig) SkipRender() bool { return c.skipRender } +func (c *kubectlConfig) ForceDeploy() bool { return c.force } +func (c *kubectlConfig) DefaultRepo() *string { return &c.defaultRepo } +func (c *kubectlConfig) MultiLevelRepo() *bool { return c.multiLevelRepo } +func (c *kubectlConfig) WaitForDeletions() config.WaitForDeletions { return c.waitForDeletions } +func (c *kubectlConfig) PortForwardResources() []*latest.PortForwardResource { return nil } diff --git a/pkg/skaffold/deploy/kustomize/kustomize.go b/pkg/skaffold/deploy/kustomize/kustomize.go index 0bf3bc66e52..956c2733481 100644 --- a/pkg/skaffold/deploy/kustomize/kustomize.go +++ b/pkg/skaffold/deploy/kustomize/kustomize.go @@ -47,7 +47,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" olog "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/status" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" @@ -107,7 +107,7 @@ type secretGenerator struct { // Deployer deploys workflows using kustomize CLI. type Deployer struct { - *latestV1.KustomizeDeploy + *latest.KustomizeDeploy accessor access.Accessor logger log.Logger @@ -129,11 +129,11 @@ type Deployer struct { namespaces *[]string - transformableAllowlist map[apimachinery.GroupKind]latestV1.ResourceFilter - transformableDenylist map[apimachinery.GroupKind]latestV1.ResourceFilter + transformableAllowlist map[apimachinery.GroupKind]latest.ResourceFilter + transformableDenylist map[apimachinery.GroupKind]latest.ResourceFilter } -func NewDeployer(cfg kubectl.Config, labeller *label.DefaultLabeller, d *latestV1.KustomizeDeploy) (*Deployer, error) { +func NewDeployer(cfg kubectl.Config, labeller *label.DefaultLabeller, d *latest.KustomizeDeploy) (*Deployer, error) { defaultNamespace := "" if d.DefaultNamespace != nil { var err error diff --git a/pkg/skaffold/deploy/kustomize/kustomize_test.go b/pkg/skaffold/deploy/kustomize/kustomize_test.go index 1f34b79ee6f..69e11af1202 100644 --- a/pkg/skaffold/deploy/kustomize/kustomize_test.go +++ b/pkg/skaffold/deploy/kustomize/kustomize_test.go @@ -36,7 +36,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/logger" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -44,7 +44,7 @@ import ( func TestKustomizeDeploy(t *testing.T) { tests := []struct { description string - kustomize latestV1.KustomizeDeploy + kustomize latest.KustomizeDeploy builds []graph.Artifact commands util.Command shouldErr bool @@ -55,7 +55,7 @@ func TestKustomizeDeploy(t *testing.T) { }{ { description: "no manifest", - kustomize: latestV1.KustomizeDeploy{ + kustomize: latest.KustomizeDeploy{ KustomizePaths: []string{"."}, }, commands: testutil. @@ -65,7 +65,7 @@ func TestKustomizeDeploy(t *testing.T) { }, { description: "deploy success", - kustomize: latestV1.KustomizeDeploy{ + kustomize: latest.KustomizeDeploy{ KustomizePaths: []string{"."}, }, commands: testutil. @@ -82,7 +82,7 @@ func TestKustomizeDeploy(t *testing.T) { }, { description: "deploy success (default namespace)", - kustomize: latestV1.KustomizeDeploy{ + kustomize: latest.KustomizeDeploy{ KustomizePaths: []string{"."}, DefaultNamespace: &kubectl.TestNamespace2, }, @@ -101,7 +101,7 @@ func TestKustomizeDeploy(t *testing.T) { }, { description: "deploy success (default namespace with env template)", - kustomize: latestV1.KustomizeDeploy{ + kustomize: latest.KustomizeDeploy{ KustomizePaths: []string{"."}, DefaultNamespace: &kubectl.TestNamespace2FromEnvTemplate, }, @@ -123,7 +123,7 @@ func TestKustomizeDeploy(t *testing.T) { }, { description: "deploy success (kustomizePaths with env template)", - kustomize: latestV1.KustomizeDeploy{ + kustomize: latest.KustomizeDeploy{ KustomizePaths: []string{"/a/b/{{ .MYENV }}"}, }, commands: testutil. @@ -143,7 +143,7 @@ func TestKustomizeDeploy(t *testing.T) { }, { description: "deploy success with multiple kustomizations", - kustomize: latestV1.KustomizeDeploy{ + kustomize: latest.KustomizeDeploy{ KustomizePaths: []string{"a", "b"}, }, commands: testutil. @@ -167,7 +167,7 @@ func TestKustomizeDeploy(t *testing.T) { }, { description: "built-in kubectl kustomize", - kustomize: latestV1.KustomizeDeploy{ + kustomize: latest.KustomizeDeploy{ KustomizePaths: []string{"a", "b"}, }, commands: testutil. @@ -228,14 +228,14 @@ func TestKustomizeCleanup(t *testing.T) { tests := []struct { description string - kustomize latestV1.KustomizeDeploy + kustomize latest.KustomizeDeploy commands util.Command shouldErr bool dryRun bool }{ { description: "cleanup dry-run", - kustomize: latestV1.KustomizeDeploy{ + kustomize: latest.KustomizeDeploy{ KustomizePaths: []string{tmpDir.Root()}, }, commands: testutil. @@ -245,7 +245,7 @@ func TestKustomizeCleanup(t *testing.T) { }, { description: "cleanup success", - kustomize: latestV1.KustomizeDeploy{ + kustomize: latest.KustomizeDeploy{ KustomizePaths: []string{tmpDir.Root()}, }, commands: testutil. @@ -254,7 +254,7 @@ func TestKustomizeCleanup(t *testing.T) { }, { description: "cleanup success with multiple kustomizations", - kustomize: latestV1.KustomizeDeploy{ + kustomize: latest.KustomizeDeploy{ KustomizePaths: tmpDir.Paths("a", "b"), }, commands: testutil. @@ -264,7 +264,7 @@ func TestKustomizeCleanup(t *testing.T) { }, { description: "cleanup error", - kustomize: latestV1.KustomizeDeploy{ + kustomize: latest.KustomizeDeploy{ KustomizePaths: []string{tmpDir.Root()}, }, commands: testutil. @@ -274,7 +274,7 @@ func TestKustomizeCleanup(t *testing.T) { }, { description: "fail to read manifests", - kustomize: latestV1.KustomizeDeploy{ + kustomize: latest.KustomizeDeploy{ KustomizePaths: []string{tmpDir.Root()}, }, commands: testutil. @@ -333,7 +333,7 @@ func TestKustomizeHooks(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { t.Override(&KustomizeBinaryCheck, func() bool { return true }) - t.Override(&hooks.NewDeployRunner, func(*ctl.CLI, latestV1.DeployHooks, *[]string, logger.Formatter, hooks.DeployEnvOpts) hooks.Runner { + t.Override(&hooks.NewDeployRunner, func(*ctl.CLI, latest.DeployHooks, *[]string, logger.Formatter, hooks.DeployEnvOpts) hooks.Runner { return test.runner }) @@ -341,7 +341,7 @@ func TestKustomizeHooks(t *testing.T) { workingDir: ".", RunContext: runcontext.RunContext{Opts: config.SkaffoldOptions{ Namespace: kubectl.TestNamespace}}, - }, &label.DefaultLabeller{}, &latestV1.KustomizeDeploy{}) + }, &label.DefaultLabeller{}, &latest.KustomizeDeploy{}) t.RequireNoError(err) err = k.PreDeployHooks(context.Background(), ioutil.Discard) t.CheckError(test.shouldErr, err) @@ -544,7 +544,7 @@ func TestDependenciesForKustomization(t *testing.T) { tmpDir.Write(path, contents) } - k, err := NewDeployer(&kustomizeConfig{}, &label.DefaultLabeller{}, &latestV1.KustomizeDeploy{KustomizePaths: kustomizePaths}) + k, err := NewDeployer(&kustomizeConfig{}, &label.DefaultLabeller{}, &latest.KustomizeDeploy{KustomizePaths: kustomizePaths}) t.RequireNoError(err) deps, err := k.Dependencies() @@ -790,7 +790,7 @@ spec: k, err := NewDeployer(&kustomizeConfig{ workingDir: ".", RunContext: runcontext.RunContext{Opts: config.SkaffoldOptions{Namespace: kubectl.TestNamespace}}, - }, labeller, &latestV1.KustomizeDeploy{ + }, labeller, &latest.KustomizeDeploy{ KustomizePaths: kustomizationPaths, }) t.RequireNoError(err) @@ -806,24 +806,24 @@ spec: func TestHasRunnableHooks(t *testing.T) { tests := []struct { description string - cfg latestV1.KustomizeDeploy + cfg latest.KustomizeDeploy expected bool }{ { description: "no hooks defined", - cfg: latestV1.KustomizeDeploy{}, + cfg: latest.KustomizeDeploy{}, }, { description: "has pre-deploy hook defined", - cfg: latestV1.KustomizeDeploy{ - LifecycleHooks: latestV1.DeployHooks{PreHooks: []latestV1.DeployHookItem{{}}}, + cfg: latest.KustomizeDeploy{ + LifecycleHooks: latest.DeployHooks{PreHooks: []latest.DeployHookItem{{}}}, }, expected: true, }, { description: "has post-deploy hook defined", - cfg: latestV1.KustomizeDeploy{ - LifecycleHooks: latestV1.DeployHooks{PostHooks: []latestV1.DeployHookItem{{}}}, + cfg: latest.KustomizeDeploy{ + LifecycleHooks: latest.DeployHooks{PostHooks: []latest.DeployHookItem{{}}}, }, expected: true, }, @@ -845,9 +845,9 @@ type kustomizeConfig struct { waitForDeletions config.WaitForDeletions } -func (c *kustomizeConfig) ForceDeploy() bool { return c.force } -func (c *kustomizeConfig) WaitForDeletions() config.WaitForDeletions { return c.waitForDeletions } -func (c *kustomizeConfig) WorkingDir() string { return c.workingDir } -func (c *kustomizeConfig) GetKubeContext() string { return kubectl.TestKubeContext } -func (c *kustomizeConfig) GetKubeNamespace() string { return c.Opts.Namespace } -func (c *kustomizeConfig) PortForwardResources() []*latestV1.PortForwardResource { return nil } +func (c *kustomizeConfig) ForceDeploy() bool { return c.force } +func (c *kustomizeConfig) WaitForDeletions() config.WaitForDeletions { return c.waitForDeletions } +func (c *kustomizeConfig) WorkingDir() string { return c.workingDir } +func (c *kustomizeConfig) GetKubeContext() string { return kubectl.TestKubeContext } +func (c *kustomizeConfig) GetKubeNamespace() string { return c.Opts.Namespace } +func (c *kustomizeConfig) PortForwardResources() []*latest.PortForwardResource { return nil } diff --git a/pkg/skaffold/deploy/types/types.go b/pkg/skaffold/deploy/types/types.go index 63545396fd8..00a3d5b57d5 100644 --- a/pkg/skaffold/deploy/types/types.go +++ b/pkg/skaffold/deploy/types/types.go @@ -20,22 +20,22 @@ import ( "k8s.io/apimachinery/pkg/runtime" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) type Config interface { docker.Config GetNamespace() string - GetPipelines() []latestV1.Pipeline + GetPipelines() []latest.Pipeline GetWorkingDir() string GlobalConfig() string ConfigurationFile() string DefaultRepo() *string MultiLevelRepo() *bool SkipRender() bool - TransformAllowList() []latestV1.ResourceFilter - TransformDenyList() []latestV1.ResourceFilter + TransformAllowList() []latest.ResourceFilter + TransformDenyList() []latest.ResourceFilter TransformRulesFile() string } diff --git a/pkg/skaffold/deploy/util/namespaces.go b/pkg/skaffold/deploy/util/namespaces.go index c54b7776740..3c3ed0ea5ce 100644 --- a/pkg/skaffold/deploy/util/namespaces.go +++ b/pkg/skaffold/deploy/util/namespaces.go @@ -21,7 +21,7 @@ import ( "sort" kubectx "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -29,7 +29,7 @@ import ( // + The namespace passed on the command line // + Current kube context's namespace // + Namespaces referenced in Helm releases -func GetAllPodNamespaces(configNamespace string, pipelines []latestV1.Pipeline) ([]string, error) { +func GetAllPodNamespaces(configNamespace string, pipelines []latest.Pipeline) ([]string, error) { nsMap := make(map[string]bool) if configNamespace == "" { @@ -68,7 +68,7 @@ func GetAllPodNamespaces(configNamespace string, pipelines []latestV1.Pipeline) return namespaces, nil } -func collectHelmReleasesNamespaces(pipelines []latestV1.Pipeline) ([]string, error) { +func collectHelmReleasesNamespaces(pipelines []latest.Pipeline) ([]string, error) { var namespaces []string for _, cfg := range pipelines { if cfg.Deploy.HelmDeploy != nil { diff --git a/pkg/skaffold/deploy/util/namespaces_test.go b/pkg/skaffold/deploy/util/namespaces_test.go index bb74d3c37d8..59afc5a6ba0 100644 --- a/pkg/skaffold/deploy/util/namespaces_test.go +++ b/pkg/skaffold/deploy/util/namespaces_test.go @@ -19,7 +19,7 @@ package util import ( "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -27,14 +27,14 @@ import ( func TestCollectHelmReleasesNamespaces(t *testing.T) { tests := []struct { description string - helmReleases []latestV1.HelmRelease + helmReleases []latest.HelmRelease env []string expected []string shouldErr bool }{ { description: "namspaces are collected correctly", - helmReleases: []latestV1.HelmRelease{ + helmReleases: []latest.HelmRelease{ { Namespace: "foo", }, @@ -49,7 +49,7 @@ func TestCollectHelmReleasesNamespaces(t *testing.T) { }, { description: "namespaces are collected correctly with env expansion", - helmReleases: []latestV1.HelmRelease{ + helmReleases: []latest.HelmRelease{ { Namespace: "{{.FOO}}", }, @@ -65,7 +65,7 @@ func TestCollectHelmReleasesNamespaces(t *testing.T) { }, { description: "should error when template expansion fails", - helmReleases: []latestV1.HelmRelease{ + helmReleases: []latest.HelmRelease{ { Namespace: "{{.DOESNT_EXIST_AND_SHOULD_ERROR_AS_SUCH}}", }, @@ -76,11 +76,11 @@ func TestCollectHelmReleasesNamespaces(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { t.Override(&util.OSEnviron, func() []string { return test.env }) - ns, err := collectHelmReleasesNamespaces([]latestV1.Pipeline{ + ns, err := collectHelmReleasesNamespaces([]latest.Pipeline{ { - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - HelmDeploy: &latestV1.HelmDeploy{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + HelmDeploy: &latest.HelmDeploy{ Releases: test.helmReleases, }, }, diff --git a/pkg/skaffold/deploy/util/util.go b/pkg/skaffold/deploy/util/util.go index 5c5a95fff48..9cf3c8d0f77 100644 --- a/pkg/skaffold/deploy/util/util.go +++ b/pkg/skaffold/deploy/util/util.go @@ -33,7 +33,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/instrumentation" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/manifest" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringset" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml" ) @@ -106,12 +106,12 @@ func GroupVersionResource(disco discovery.DiscoveryInterface, gvk schema.GroupVe return false, schema.GroupVersionResource{}, fmt.Errorf("could not find resource for %s", gvk.String()) } -func ConsolidateTransformConfiguration(cfg types.Config) (map[schema.GroupKind]latestV1.ResourceFilter, map[schema.GroupKind]latestV1.ResourceFilter, error) { +func ConsolidateTransformConfiguration(cfg types.Config) (map[schema.GroupKind]latest.ResourceFilter, map[schema.GroupKind]latest.ResourceFilter, error) { // TODO(aaron-prindle) currently this also modifies the flag & config to support a JSON path syntax for input. // this should be done elsewhere eventually - transformableAllowlist := map[schema.GroupKind]latestV1.ResourceFilter{} - transformableDenylist := map[schema.GroupKind]latestV1.ResourceFilter{} + transformableAllowlist := map[schema.GroupKind]latest.ResourceFilter{} + transformableDenylist := map[schema.GroupKind]latest.ResourceFilter{} // add default values for _, rf := range manifest.TransformAllowlist { groupKind := schema.ParseGroupKind(rf.GroupKind) @@ -143,7 +143,7 @@ func ConsolidateTransformConfiguration(cfg types.Config) (map[schema.GroupKind]l if err != nil { return nil, nil, err } - rsc := latestV1.ResourceSelectorConfig{} + rsc := latest.ResourceSelectorConfig{} err = yaml.Unmarshal(transformRulesFromFile, &rsc) if err != nil { return nil, nil, err @@ -166,8 +166,8 @@ func ConsolidateTransformConfiguration(cfg types.Config) (map[schema.GroupKind]l return transformableAllowlist, transformableDenylist, nil } -func convertJSONPathIndex(rf latestV1.ResourceFilter) latestV1.ResourceFilter { - nrf := latestV1.ResourceFilter{} +func convertJSONPathIndex(rf latest.ResourceFilter) latest.ResourceFilter { + nrf := latest.ResourceFilter{} nrf.GroupKind = rf.GroupKind if len(rf.Labels) > 0 { diff --git a/pkg/skaffold/deploy/util/util_test.go b/pkg/skaffold/deploy/util/util_test.go index dec3f8c7b7f..e737c86e6ce 100644 --- a/pkg/skaffold/deploy/util/util_test.go +++ b/pkg/skaffold/deploy/util/util_test.go @@ -26,7 +26,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/manifest" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -190,63 +190,63 @@ func TestConsolidateTransformConfiguration(t *testing.T) { tests := []struct { description string shouldErr bool - allowSchemaTransforms []latestV1.ResourceFilter - denySchemaTransforms []latestV1.ResourceFilter - flagTransforms latestV1.ResourceSelectorConfig - expected func(map[schema.GroupKind]latestV1.ResourceFilter, map[schema.GroupKind]latestV1.ResourceFilter) (map[schema.GroupKind]latestV1.ResourceFilter, map[schema.GroupKind]latestV1.ResourceFilter) + allowSchemaTransforms []latest.ResourceFilter + denySchemaTransforms []latest.ResourceFilter + flagTransforms latest.ResourceSelectorConfig + expected func(map[schema.GroupKind]latest.ResourceFilter, map[schema.GroupKind]latest.ResourceFilter) (map[schema.GroupKind]latest.ResourceFilter, map[schema.GroupKind]latest.ResourceFilter) }{ { description: "verify schema transform configuration outprioritizes default hardcoded transform configuration", - denySchemaTransforms: []latestV1.ResourceFilter{ + denySchemaTransforms: []latest.ResourceFilter{ { GroupKind: "Deployment.apps", }, }, - expected: func(allow map[schema.GroupKind]latestV1.ResourceFilter, deny map[schema.GroupKind]latestV1.ResourceFilter) (map[schema.GroupKind]latestV1.ResourceFilter, map[schema.GroupKind]latestV1.ResourceFilter) { + expected: func(allow map[schema.GroupKind]latest.ResourceFilter, deny map[schema.GroupKind]latest.ResourceFilter) (map[schema.GroupKind]latest.ResourceFilter, map[schema.GroupKind]latest.ResourceFilter) { // Deployment.apps removed from hardcoded allowlist delete(allow, schema.GroupKind{Group: "apps", Kind: "Deployment"}) // Deployment.apps added to denylist - deny[schema.GroupKind{Group: "apps", Kind: "Deployment"}] = latestV1.ResourceFilter{GroupKind: "Deployment.apps"} + deny[schema.GroupKind{Group: "apps", Kind: "Deployment"}] = latest.ResourceFilter{GroupKind: "Deployment.apps"} return allow, deny }, }, { description: "verify flag transform configuration outprioritizes schema transform configuration", - flagTransforms: latestV1.ResourceSelectorConfig{ - Allow: []latestV1.ResourceFilter{ + flagTransforms: latest.ResourceSelectorConfig{ + Allow: []latest.ResourceFilter{ { GroupKind: "Test.skaffold.dev", }, }, }, - denySchemaTransforms: []latestV1.ResourceFilter{ + denySchemaTransforms: []latest.ResourceFilter{ { GroupKind: "Test.skaffold.dev", }, }, - expected: func(allow map[schema.GroupKind]latestV1.ResourceFilter, deny map[schema.GroupKind]latestV1.ResourceFilter) (map[schema.GroupKind]latestV1.ResourceFilter, map[schema.GroupKind]latestV1.ResourceFilter) { + expected: func(allow map[schema.GroupKind]latest.ResourceFilter, deny map[schema.GroupKind]latest.ResourceFilter) (map[schema.GroupKind]latest.ResourceFilter, map[schema.GroupKind]latest.ResourceFilter) { // Test.skaffold.dev added to allowlist as flag config outprioritizes schema config - allow[schema.GroupKind{Group: "skaffold.dev", Kind: "Test"}] = latestV1.ResourceFilter{GroupKind: "Test.skaffold.dev"} + allow[schema.GroupKind{Group: "skaffold.dev", Kind: "Test"}] = latest.ResourceFilter{GroupKind: "Test.skaffold.dev"} return allow, deny }, }, { description: "verify denylist outprioritizes allowlist transform configuration (for same config input source)", - flagTransforms: latestV1.ResourceSelectorConfig{ - Allow: []latestV1.ResourceFilter{ + flagTransforms: latest.ResourceSelectorConfig{ + Allow: []latest.ResourceFilter{ { GroupKind: "Test.skaffold.dev", }, }, - Deny: []latestV1.ResourceFilter{ + Deny: []latest.ResourceFilter{ { GroupKind: "Test.skaffold.dev", }, }, }, - expected: func(allow map[schema.GroupKind]latestV1.ResourceFilter, deny map[schema.GroupKind]latestV1.ResourceFilter) (map[schema.GroupKind]latestV1.ResourceFilter, map[schema.GroupKind]latestV1.ResourceFilter) { + expected: func(allow map[schema.GroupKind]latest.ResourceFilter, deny map[schema.GroupKind]latest.ResourceFilter) (map[schema.GroupKind]latest.ResourceFilter, map[schema.GroupKind]latest.ResourceFilter) { // Test.skaffold.dev added to denylist as deny config outprioritizes allow config for same priority config source (both flag config) - deny[schema.GroupKind{Group: "skaffold.dev", Kind: "Test"}] = latestV1.ResourceFilter{GroupKind: "Test.skaffold.dev"} + deny[schema.GroupKind{Group: "skaffold.dev", Kind: "Test"}] = latest.ResourceFilter{GroupKind: "Test.skaffold.dev"} return allow, deny }, }, @@ -274,12 +274,12 @@ func TestConsolidateTransformConfiguration(t *testing.T) { allowlist, denylist, err := ConsolidateTransformConfiguration(cfg) t.CheckError(test.shouldErr, err) - copyAllow := map[schema.GroupKind]latestV1.ResourceFilter{} + copyAllow := map[schema.GroupKind]latest.ResourceFilter{} for k, v := range manifest.TransformAllowlist { copyAllow[k] = v } - copyDeny := map[schema.GroupKind]latestV1.ResourceFilter{} + copyDeny := map[schema.GroupKind]latest.ResourceFilter{} for k, v := range manifest.TransformDenylist { copyDeny[k] = v } @@ -292,21 +292,21 @@ func TestConsolidateTransformConfiguration(t *testing.T) { type mockDeployConfig struct { runcontext.RunContext // Embedded to provide the default values. - transformAllowList []latestV1.ResourceFilter - transformDenyList []latestV1.ResourceFilter + transformAllowList []latest.ResourceFilter + transformDenyList []latest.ResourceFilter transformRulesFile string } -func (c *mockDeployConfig) ForceDeploy() bool { return false } -func (c *mockDeployConfig) GetKubeConfig() string { return "" } -func (c *mockDeployConfig) GetKubeContext() string { return "" } -func (c *mockDeployConfig) GetKubeNamespace() string { return "" } -func (c *mockDeployConfig) ConfigurationFile() string { return "" } -func (c *mockDeployConfig) PortForwardResources() []*latestV1.PortForwardResource { return nil } -func (c *mockDeployConfig) TransformAllowList() []latestV1.ResourceFilter { +func (c *mockDeployConfig) ForceDeploy() bool { return false } +func (c *mockDeployConfig) GetKubeConfig() string { return "" } +func (c *mockDeployConfig) GetKubeContext() string { return "" } +func (c *mockDeployConfig) GetKubeNamespace() string { return "" } +func (c *mockDeployConfig) ConfigurationFile() string { return "" } +func (c *mockDeployConfig) PortForwardResources() []*latest.PortForwardResource { return nil } +func (c *mockDeployConfig) TransformAllowList() []latest.ResourceFilter { return c.transformAllowList } -func (c *mockDeployConfig) TransformDenyList() []latestV1.ResourceFilter { +func (c *mockDeployConfig) TransformDenyList() []latest.ResourceFilter { return c.transformDenyList } func (c *mockDeployConfig) TransformRulesFile() string { return c.transformRulesFile } diff --git a/pkg/skaffold/diagnose/diagnose.go b/pkg/skaffold/diagnose/diagnose.go index f7f10aca2e1..2102603f4b4 100644 --- a/pkg/skaffold/diagnose/diagnose.go +++ b/pkg/skaffold/diagnose/diagnose.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/filemon" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync" timeutil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/time" ) @@ -36,8 +36,8 @@ import ( type Config interface { docker.Config - GetPipelines() []latestV1.Pipeline - Artifacts() []*latestV1.Artifact + GetPipelines() []latest.Pipeline + Artifacts() []*latest.Artifact } func CheckArtifacts(ctx context.Context, cfg Config, out io.Writer) error { @@ -99,7 +99,7 @@ func CheckArtifacts(ctx context.Context, cfg Config, out io.Writer) error { return nil } -func typeOfArtifact(a *latestV1.Artifact) string { +func typeOfArtifact(a *latest.Artifact) string { switch { case a.DockerArtifact != nil: return "Docker artifact" @@ -120,7 +120,7 @@ func typeOfArtifact(a *latestV1.Artifact) string { } } -func timeToListDependencies(ctx context.Context, a *latestV1.Artifact, cfg Config) (string, []string, error) { +func timeToListDependencies(ctx context.Context, a *latest.Artifact, cfg Config) (string, []string, error) { start := time.Now() g := graph.ToArtifactGraph(cfg.Artifacts()) sourceDependencies := graph.NewSourceDependenciesCache(cfg, nil, g) @@ -128,7 +128,7 @@ func timeToListDependencies(ctx context.Context, a *latestV1.Artifact, cfg Confi return timeutil.Humanize(time.Since(start)), paths, err } -func timeToConstructSyncMap(ctx context.Context, a *latestV1.Artifact, cfg docker.Config) (string, error) { +func timeToConstructSyncMap(ctx context.Context, a *latest.Artifact, cfg docker.Config) (string, error) { start := time.Now() _, err := sync.SyncMap(ctx, a, cfg) return timeutil.Humanize(time.Since(start)), err @@ -143,7 +143,7 @@ func timeToComputeMTimes(deps []string) (string, error) { return timeutil.Humanize(time.Since(start)), nil } -func sizeOfDockerContext(ctx context.Context, a *latestV1.Artifact, cfg docker.Config) (int64, error) { +func sizeOfDockerContext(ctx context.Context, a *latest.Artifact, cfg docker.Config) (int64, error) { buildCtx, buildCtxWriter := io.Pipe() go func() { err := docker.CreateDockerTarContext(ctx, buildCtxWriter, docker.NewBuildConfig( diff --git a/pkg/skaffold/diagnose/diagnose_test.go b/pkg/skaffold/diagnose/diagnose_test.go index 6bdcd4d21cf..3a4b77bb95b 100644 --- a/pkg/skaffold/diagnose/diagnose_test.go +++ b/pkg/skaffold/diagnose/diagnose_test.go @@ -22,7 +22,7 @@ import ( "testing" "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/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -61,11 +61,11 @@ func TestSizeOfDockerContext(t *testing.T) { Write("Dockerfile", test.DockerfileContents). WriteFiles(test.files) - dummyArtifact := &latestV1.Artifact{ + dummyArtifact := &latest.Artifact{ Workspace: tmpDir.Root(), ImageName: test.artifactName, - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: "Dockerfile", }, }, @@ -82,10 +82,10 @@ func TestCheckArtifacts(t *testing.T) { tmpDir := t.NewTempDir().Write("Dockerfile", "FROM busybox") err := CheckArtifacts(context.Background(), &mockConfig{ - artifacts: []*latestV1.Artifact{{ + artifacts: []*latest.Artifact{{ Workspace: tmpDir.Root(), - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: "Dockerfile", }, }, @@ -98,21 +98,21 @@ func TestCheckArtifacts(t *testing.T) { type mockConfig struct { runcontext.RunContext // Embedded to provide the default values. - artifacts []*latestV1.Artifact + artifacts []*latest.Artifact } -func (c *mockConfig) PipelineForImage() latestV1.Pipeline { - var pipeline latestV1.Pipeline +func (c *mockConfig) PipelineForImage() latest.Pipeline { + var pipeline latest.Pipeline pipeline.Build.Artifacts = c.artifacts return pipeline } -func (c *mockConfig) GetPipelines() []latestV1.Pipeline { - var pipelines []latestV1.Pipeline +func (c *mockConfig) GetPipelines() []latest.Pipeline { + var pipelines []latest.Pipeline pipelines = append(pipelines, c.PipelineForImage()) return pipelines } -func (c *mockConfig) Artifacts() []*latestV1.Artifact { +func (c *mockConfig) Artifacts() []*latest.Artifact { return c.artifacts } diff --git a/pkg/skaffold/docker/build_args.go b/pkg/skaffold/docker/build_args.go index 3d6e730ab12..2dca35729a1 100644 --- a/pkg/skaffold/docker/build_args.go +++ b/pkg/skaffold/docker/build_args.go @@ -23,7 +23,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -96,7 +96,7 @@ type ArtifactResolver interface { // ResolveDependencyImages creates a map of artifact aliases to their built image from a required artifacts slice. // If `missingIsFatal` is false then it is permissive of missing entries in the ArtifactResolver and returns nil for those entries. -func ResolveDependencyImages(deps []*latestV1.ArtifactDependency, r ArtifactResolver, missingIsFatal bool) map[string]*string { +func ResolveDependencyImages(deps []*latest.ArtifactDependency, r ArtifactResolver, missingIsFatal bool) map[string]*string { if r == nil { // `diagnose` is called without an artifact resolver. Return an empty map in this case. return nil diff --git a/pkg/skaffold/docker/build_args_test.go b/pkg/skaffold/docker/build_args_test.go index 120d5b9df0e..927186d52ff 100644 --- a/pkg/skaffold/docker/build_args_test.go +++ b/pkg/skaffold/docker/build_args_test.go @@ -20,7 +20,7 @@ import ( "testing" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -201,7 +201,7 @@ FROM bar1`, for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - artifact := &latestV1.DockerArtifact{ + artifact := &latest.DockerArtifact{ DockerfilePath: "Dockerfile", BuildArgs: test.buildArgs, } @@ -221,20 +221,20 @@ func TestCreateBuildArgsFromArtifacts(t *testing.T) { tests := []struct { description string r ArtifactResolver - deps []*latestV1.ArtifactDependency + deps []*latest.ArtifactDependency args map[string]*string }{ { description: "can resolve artifacts", r: mockArtifactResolver{m: map[string]string{"img1": "tag1", "img2": "tag2", "img3": "tag3", "img4": "tag4"}}, - deps: []*latestV1.ArtifactDependency{{ImageName: "img3", Alias: "alias3"}, {ImageName: "img4", Alias: "alias4"}}, + deps: []*latest.ArtifactDependency{{ImageName: "img3", Alias: "alias3"}, {ImageName: "img4", Alias: "alias4"}}, args: map[string]*string{"alias3": util.StringPtr("tag3"), "alias4": util.StringPtr("tag4")}, }, { description: "cannot resolve artifacts", r: mockArtifactResolver{m: make(map[string]string)}, args: map[string]*string{"alias3": nil, "alias4": nil}, - deps: []*latestV1.ArtifactDependency{{ImageName: "img3", Alias: "alias3"}, {ImageName: "img4", Alias: "alias4"}}, + deps: []*latest.ArtifactDependency{{ImageName: "img3", Alias: "alias3"}, {ImageName: "img4", Alias: "alias4"}}, }, } for _, test := range tests { @@ -265,7 +265,7 @@ func TestBuildArgTemplating(t *testing.T) { testutil.Run(t, "test_templating_from_env_variables", func(t *testutil.T) { t.SetEnvs(envs) - artifact := &latestV1.DockerArtifact{ + artifact := &latest.DockerArtifact{ DockerfilePath: "Dockerfile", BuildArgs: args, } diff --git a/pkg/skaffold/docker/context_test.go b/pkg/skaffold/docker/context_test.go index 020427b022e..bfc59edca2e 100644 --- a/pkg/skaffold/docker/context_test.go +++ b/pkg/skaffold/docker/context_test.go @@ -22,7 +22,7 @@ import ( "io" "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -40,7 +40,7 @@ func TestDockerContext(t *testing.T) { Touch(dir + "/alsoignored.txt"). Chdir() - artifact := &latestV1.DockerArtifact{ + artifact := &latest.DockerArtifact{ DockerfilePath: "Dockerfile", } diff --git a/pkg/skaffold/docker/docker_init.go b/pkg/skaffold/docker/docker_init.go index 707576b5de9..9c561a27f9a 100644 --- a/pkg/skaffold/docker/docker_init.go +++ b/pkg/skaffold/docker/docker_init.go @@ -26,7 +26,7 @@ import ( "github.com/moby/buildkit/frontend/dockerfile/parser" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // For testing @@ -53,7 +53,7 @@ func (c ArtifactConfig) Describe() string { } // ArtifactType returns the type of the artifact to be built. -func (c ArtifactConfig) ArtifactType(workspace string) latestV1.ArtifactType { +func (c ArtifactConfig) ArtifactType(workspace string) latest.ArtifactType { dockerfile := filepath.Base(c.File) if workspace != "" { // attempt to relativize the path @@ -62,8 +62,8 @@ func (c ArtifactConfig) ArtifactType(workspace string) latestV1.ArtifactType { } } - return latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + return latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ // to make skaffold.yaml more portable across OS-es we should always generate /-delimited filePaths DockerfilePath: filepath.ToSlash(dockerfile), }, diff --git a/pkg/skaffold/docker/docker_init_test.go b/pkg/skaffold/docker/docker_init_test.go index 7ba513fe0e1..ca702e02a6f 100644 --- a/pkg/skaffold/docker/docker_init_test.go +++ b/pkg/skaffold/docker/docker_init_test.go @@ -20,7 +20,7 @@ import ( "path/filepath" "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -91,13 +91,13 @@ func TestArtifactType(t *testing.T) { description string workspace string config ArtifactConfig - expectedType latestV1.ArtifactType + expectedType latest.ArtifactType }{ { description: "default filename", config: ArtifactConfig{File: filepath.Join("path", "to", "Dockerfile")}, - expectedType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + expectedType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: "Dockerfile", }, }, @@ -105,8 +105,8 @@ func TestArtifactType(t *testing.T) { { description: "non-default filename", config: ArtifactConfig{File: filepath.Join("path", "to", "Dockerfile1")}, - expectedType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + expectedType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: "Dockerfile1", }, }, @@ -115,8 +115,8 @@ func TestArtifactType(t *testing.T) { description: "with workspace", config: ArtifactConfig{File: filepath.Join("path", "to", "Dockerfile")}, workspace: "path", - expectedType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + expectedType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: "to/Dockerfile", }, }, diff --git a/pkg/skaffold/docker/image.go b/pkg/skaffold/docker/image.go index bbb468970ef..a6980eefd34 100644 --- a/pkg/skaffold/docker/image.go +++ b/pkg/skaffold/docker/image.go @@ -45,7 +45,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/term" ) @@ -83,7 +83,7 @@ type LocalDaemon interface { ContainerExists(ctx context.Context, name string) bool ContainerInspect(ctx context.Context, id string) (types.ContainerJSON, error) ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error) - Build(ctx context.Context, out io.Writer, workspace string, artifact string, a *latestV1.DockerArtifact, opts BuildOptions) (string, error) + Build(ctx context.Context, out io.Writer, workspace string, artifact string, a *latest.DockerArtifact, opts BuildOptions) (string, error) Push(ctx context.Context, out io.Writer, ref string) (string, error) Pull(ctx context.Context, out io.Writer, ref string) error Load(ctx context.Context, out io.Writer, input io.Reader, ref string) (string, error) @@ -295,7 +295,7 @@ func (l *localDaemon) ConfigFile(ctx context.Context, image string) (*v1.ConfigF return cfg, nil } -func (l *localDaemon) CheckCompatible(a *latestV1.DockerArtifact) error { +func (l *localDaemon) CheckCompatible(a *latest.DockerArtifact) error { if len(a.Secrets) > 0 || a.SSH != "" { return fmt.Errorf("docker build options, secrets and ssh, require BuildKit - set `useBuildkit: true` in your config, or run with `DOCKER_BUILDKIT=1`") } @@ -303,7 +303,7 @@ func (l *localDaemon) CheckCompatible(a *latestV1.DockerArtifact) error { } // Build performs a docker build and returns the imageID. -func (l *localDaemon) Build(ctx context.Context, out io.Writer, workspace string, artifact string, a *latestV1.DockerArtifact, opts BuildOptions) (string, error) { +func (l *localDaemon) Build(ctx context.Context, out io.Writer, workspace string, artifact string, a *latest.DockerArtifact, opts BuildOptions) (string, error) { log.Entry(ctx).Debugf("Running docker build: context: %s, dockerfile: %s", workspace, a.DockerfilePath) if err := l.CheckCompatible(a); err != nil { @@ -602,7 +602,7 @@ func (l *localDaemon) DiskUsage(ctx context.Context) (uint64, error) { return uint64(usage.LayersSize), nil } -func ToCLIBuildArgs(a *latestV1.DockerArtifact, evaluatedArgs map[string]*string) ([]string, error) { +func ToCLIBuildArgs(a *latest.DockerArtifact, evaluatedArgs map[string]*string) ([]string, error) { var args []string var keys []string for k := range evaluatedArgs { diff --git a/pkg/skaffold/docker/image_test.go b/pkg/skaffold/docker/image_test.go index 7f3bdcd7bde..f1fa95e28d1 100644 --- a/pkg/skaffold/docker/image_test.go +++ b/pkg/skaffold/docker/image_test.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/proto/v1" "github.com/GoogleContainerTools/skaffold/testutil" @@ -104,7 +104,7 @@ func TestBuild(t *testing.T) { env map[string]string api *testutil.FakeAPIClient workspace string - artifact *latestV1.DockerArtifact + artifact *latest.DockerArtifact expected types.ImageBuildOptions mode config.RunMode shouldErr bool @@ -114,7 +114,7 @@ func TestBuild(t *testing.T) { description: "build", api: &testutil.FakeAPIClient{}, workspace: ".", - artifact: &latestV1.DockerArtifact{}, + artifact: &latest.DockerArtifact{}, expected: types.ImageBuildOptions{ Tags: []string{"finalimage"}, AuthConfigs: allAuthConfig, @@ -128,7 +128,7 @@ func TestBuild(t *testing.T) { "VALUE3": "value3", }, workspace: ".", - artifact: &latestV1.DockerArtifact{ + artifact: &latest.DockerArtifact{ DockerfilePath: "Dockerfile", BuildArgs: map[string]*string{ "k1": nil, @@ -165,7 +165,7 @@ func TestBuild(t *testing.T) { }, mode: config.RunModes.Dev, workspace: ".", - artifact: &latestV1.DockerArtifact{}, + artifact: &latest.DockerArtifact{}, shouldErr: true, expectedError: "docker build", }, @@ -176,13 +176,13 @@ func TestBuild(t *testing.T) { }, workspace: ".", mode: config.RunModes.Dev, - artifact: &latestV1.DockerArtifact{}, + artifact: &latest.DockerArtifact{}, shouldErr: true, expectedError: "unable to stream build output", }, { description: "bad build arg template", - artifact: &latestV1.DockerArtifact{ + artifact: &latest.DockerArtifact{ BuildArgs: map[string]*string{ "key": util.StringPtr("{{INVALID"), }, @@ -270,14 +270,14 @@ func TestImageID(t *testing.T) { func TestGetBuildArgs(t *testing.T) { tests := []struct { description string - artifact *latestV1.DockerArtifact + artifact *latest.DockerArtifact env []string want []string shouldErr bool }{ { description: "build args", - artifact: &latestV1.DockerArtifact{ + artifact: &latest.DockerArtifact{ BuildArgs: map[string]*string{ "key1": util.StringPtr("value1"), "key2": nil, @@ -289,7 +289,7 @@ func TestGetBuildArgs(t *testing.T) { }, { description: "invalid build arg", - artifact: &latestV1.DockerArtifact{ + artifact: &latest.DockerArtifact{ BuildArgs: map[string]*string{ "key": util.StringPtr("{{INVALID"), }, @@ -298,64 +298,64 @@ func TestGetBuildArgs(t *testing.T) { }, { description: "add host", - artifact: &latestV1.DockerArtifact{ + artifact: &latest.DockerArtifact{ AddHost: []string{"1.gcr.io:127.0.0.1", "2.gcr.io:127.0.0.1"}, }, want: []string{"--add-host", "1.gcr.io:127.0.0.1", "--add-host", "2.gcr.io:127.0.0.1"}, }, { description: "cache from", - artifact: &latestV1.DockerArtifact{ + artifact: &latest.DockerArtifact{ CacheFrom: []string{"gcr.io/foo/bar", "baz:latest"}, }, want: []string{"--cache-from", "gcr.io/foo/bar", "--cache-from", "baz:latest"}, }, { description: "additional CLI flags", - artifact: &latestV1.DockerArtifact{ + artifact: &latest.DockerArtifact{ CliFlags: []string{"--foo", "--bar"}, }, want: []string{"--foo", "--bar"}, }, { description: "target", - artifact: &latestV1.DockerArtifact{ + artifact: &latest.DockerArtifact{ Target: "stage1", }, want: []string{"--target", "stage1"}, }, { description: "network mode", - artifact: &latestV1.DockerArtifact{ + artifact: &latest.DockerArtifact{ NetworkMode: "Bridge", }, want: []string{"--network", "bridge"}, }, { description: "no-cache", - artifact: &latestV1.DockerArtifact{ + artifact: &latest.DockerArtifact{ NoCache: true, }, want: []string{"--no-cache"}, }, { description: "pullParent", - artifact: &latestV1.DockerArtifact{ + artifact: &latest.DockerArtifact{ PullParent: true, }, want: []string{"--pull"}, }, { description: "squash", - artifact: &latestV1.DockerArtifact{ + artifact: &latest.DockerArtifact{ Squash: true, }, want: []string{"--squash"}, }, { description: "secret with no source", - artifact: &latestV1.DockerArtifact{ - Secrets: []*latestV1.DockerSecret{ + artifact: &latest.DockerArtifact{ + Secrets: []*latest.DockerSecret{ {ID: "mysecret"}, }, }, @@ -363,8 +363,8 @@ func TestGetBuildArgs(t *testing.T) { }, { description: "secret with file source", - artifact: &latestV1.DockerArtifact{ - Secrets: []*latestV1.DockerSecret{ + artifact: &latest.DockerArtifact{ + Secrets: []*latest.DockerSecret{ {ID: "mysecret", Source: "foo.src"}, }, }, @@ -372,8 +372,8 @@ func TestGetBuildArgs(t *testing.T) { }, { description: "secret with env source", - artifact: &latestV1.DockerArtifact{ - Secrets: []*latestV1.DockerSecret{ + artifact: &latest.DockerArtifact{ + Secrets: []*latest.DockerSecret{ {ID: "mysecret", Env: "FOO"}, }, }, @@ -381,8 +381,8 @@ func TestGetBuildArgs(t *testing.T) { }, { description: "multiple secrets", - artifact: &latestV1.DockerArtifact{ - Secrets: []*latestV1.DockerSecret{ + artifact: &latest.DockerArtifact{ + Secrets: []*latest.DockerSecret{ {ID: "mysecret", Source: "foo.src"}, {ID: "anothersecret", Source: "bar.src"}, }, @@ -391,14 +391,14 @@ func TestGetBuildArgs(t *testing.T) { }, { description: "ssh with no source", - artifact: &latestV1.DockerArtifact{ + artifact: &latest.DockerArtifact{ SSH: "default", }, want: []string{"--ssh", "default"}, }, { description: "all", - artifact: &latestV1.DockerArtifact{ + artifact: &latest.DockerArtifact{ BuildArgs: map[string]*string{ "key1": util.StringPtr("value1"), }, diff --git a/pkg/skaffold/event/config.go b/pkg/skaffold/event/config.go index 8add58a64af..7bcfd390442 100644 --- a/pkg/skaffold/event/config.go +++ b/pkg/skaffold/event/config.go @@ -16,14 +16,12 @@ limitations under the License. package event -import ( - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" -) +import "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" type Config interface { GetKubeContext() string AutoBuild() bool AutoDeploy() bool AutoSync() bool - GetPipelines() []latestV1.Pipeline + GetPipelines() []latest.Pipeline } diff --git a/pkg/skaffold/event/event_test.go b/pkg/skaffold/event/event_test.go index 4ab5b213bf6..f2795d19067 100644 --- a/pkg/skaffold/event/event_test.go +++ b/pkg/skaffold/event/event_test.go @@ -33,7 +33,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" schemautil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/proto/v1" "github.com/GoogleContainerTools/skaffold/testutil" @@ -69,7 +69,7 @@ func TestGetLogEvents(t *testing.T) { func TestGetState(t *testing.T) { ev := newHandler() - ev.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + ev.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) ev.stateLock.Lock() ev.state.BuildState.Artifacts["img"] = Complete @@ -84,7 +84,7 @@ func TestDeployInProgress(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().DeployState.Status == NotStarted }) DeployInProgress() @@ -95,7 +95,7 @@ func TestDeployFailed(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().DeployState.Status == NotStarted }) DeployFailed(errors.New("BUG")) @@ -109,7 +109,7 @@ func TestDeployComplete(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().DeployState.Status == NotStarted }) DeployComplete() @@ -123,7 +123,7 @@ func TestTestInProgress(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().TestState.Status == NotStarted }) TestInProgress() @@ -134,7 +134,7 @@ func TestTestFailed(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().TestState.Status == NotStarted }) TestFailed("img", errors.New("BUG")) @@ -149,7 +149,7 @@ func TestTestComplete(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().TestState.Status == NotStarted }) TestComplete() @@ -160,8 +160,8 @@ func TestBuildInProgress(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{{ + handler.state = emptyState(mockCfg([]latest.Pipeline{{Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{{ ImageName: "img", }}, }}}, "test")) @@ -175,8 +175,8 @@ func TestBuildFailed(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{{ + handler.state = emptyState(mockCfg([]latest.Pipeline{{Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{{ ImageName: "img", }}, }}}, "test")) @@ -193,8 +193,8 @@ func TestBuildComplete(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{{ + handler.state = emptyState(mockCfg([]latest.Pipeline{{Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{{ ImageName: "img", }}, }}}, "test")) @@ -208,7 +208,7 @@ func TestPortForwarded(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().ForwardedPorts[8080] == nil }) PortForwarded(8080, schemautil.FromInt(8888), "pod", "container", "ns", "portname", "resourceType", "resourceName", "127.0.0.1") @@ -227,7 +227,7 @@ func TestPortForwarded_handleNil(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) handler.setState(handler.getState()) if handler.getState().ForwardedPorts != nil { @@ -241,7 +241,7 @@ func TestStatusCheckEventStarted(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) StatusCheckEventStarted() @@ -252,7 +252,7 @@ func TestStatusCheckEventInProgress(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) StatusCheckEventInProgress("[2/5 deployment(s) are still pending]") @@ -263,7 +263,7 @@ func TestStatusCheckEventSucceeded(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) statusCheckEventSucceeded() @@ -274,7 +274,7 @@ func TestStatusCheckEventFailed(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) StatusCheckEventEnded(proto.StatusCode_STATUSCHECK_FAILED_SCHEDULING, errors.New("one or more deployments failed")) @@ -288,7 +288,7 @@ func TestResourceStatusCheckEventUpdated(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) ResourceStatusCheckEventUpdated("ns:pod/foo", &proto.ActionableErr{ @@ -302,7 +302,7 @@ func TestResourceStatusCheckEventSucceeded(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) resourceStatusCheckEventSucceeded("ns:pod/foo") @@ -313,7 +313,7 @@ func TestResourceStatusCheckEventFailed(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) resourceStatusCheckEventFailed("ns:pod/foo", &proto.ActionableErr{ @@ -327,7 +327,7 @@ func TestFileSyncInProgress(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().FileSyncState.Status == NotStarted }) FileSyncInProgress(5, "image") @@ -338,7 +338,7 @@ func TestFileSyncFailed(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().FileSyncState.Status == NotStarted }) FileSyncFailed(5, "image", errors.New("BUG")) @@ -349,7 +349,7 @@ func TestFileSyncSucceeded(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().FileSyncState.Status == NotStarted }) FileSyncSucceeded(5, "image") @@ -360,7 +360,7 @@ func TestDebuggingContainer(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) found := func() bool { for _, dc := range handler.getState().DebuggingContainers { @@ -671,17 +671,17 @@ func TestSaveEventsToFile(t *testing.T) { } type config struct { - pipes []latestV1.Pipeline + pipes []latest.Pipeline kubectx string } -func (c config) GetKubeContext() string { return c.kubectx } -func (c config) AutoBuild() bool { return true } -func (c config) AutoDeploy() bool { return true } -func (c config) AutoSync() bool { return true } -func (c config) GetPipelines() []latestV1.Pipeline { return c.pipes } +func (c config) GetKubeContext() string { return c.kubectx } +func (c config) AutoBuild() bool { return true } +func (c config) AutoDeploy() bool { return true } +func (c config) AutoSync() bool { return true } +func (c config) GetPipelines() []latest.Pipeline { return c.pipes } -func mockCfg(pipes []latestV1.Pipeline, kubectx string) config { +func mockCfg(pipes []latest.Pipeline, kubectx string) config { return config{ pipes: pipes, kubectx: kubectx, diff --git a/pkg/skaffold/event/util.go b/pkg/skaffold/event/util.go index 50b8c9b69ba..09654d14c03 100644 --- a/pkg/skaffold/event/util.go +++ b/pkg/skaffold/event/util.go @@ -19,11 +19,11 @@ package event import ( "strings" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/proto/v1" ) -func initializeMetadata(pipelines []latestV1.Pipeline, kubeContext string) *proto.Metadata { +func initializeMetadata(pipelines []latest.Pipeline, kubeContext string) *proto.Metadata { artifactCount := 0 for _, p := range pipelines { artifactCount += len(p.Build.Artifacts) @@ -67,7 +67,7 @@ func initializeMetadata(pipelines []latestV1.Pipeline, kubeContext string) *prot return m } -func getBuilders(b latestV1.BuildConfig) []*proto.BuildMetadata_ImageBuilder { +func getBuilders(b latest.BuildConfig) []*proto.BuildMetadata_ImageBuilder { m := map[proto.BuilderType]int{} for _, a := range b.Artifacts { switch { @@ -98,7 +98,7 @@ func getBuilders(b latestV1.BuildConfig) []*proto.BuildMetadata_ImageBuilder { return builders } -func getDeploy(d latestV1.DeployConfig) []*proto.DeployMetadata_Deployer { +func getDeploy(d latest.DeployConfig) []*proto.DeployMetadata_Deployer { var deployers []*proto.DeployMetadata_Deployer if d.HelmDeploy != nil { diff --git a/pkg/skaffold/event/util_test.go b/pkg/skaffold/event/util_test.go index 6bc6de8ad15..6f4676a874d 100644 --- a/pkg/skaffold/event/util_test.go +++ b/pkg/skaffold/event/util_test.go @@ -22,7 +22,7 @@ import ( "google.golang.org/protobuf/testing/protocmp" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/proto/v1" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -30,21 +30,21 @@ import ( func TestEmptyState(t *testing.T) { tests := []struct { description string - cfg latestV1.Pipeline + cfg latest.Pipeline cluster string expected *proto.Metadata }{ { description: "one build artifact minikube cluster multiple deployers", - cfg: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - BuildType: latestV1.BuildType{LocalBuild: &latestV1.LocalBuild{}}, - Artifacts: []*latestV1.Artifact{{ImageName: "img", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{}}}}, + cfg: latest.Pipeline{ + Build: latest.BuildConfig{ + BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}, + Artifacts: []*latest.Artifact{{ImageName: "img", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}}, }, - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{}, - HelmDeploy: &latestV1.HelmDeploy{Releases: []latestV1.HelmRelease{{Name: "first"}, {Name: "second"}}}, + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{}, + HelmDeploy: &latest.HelmDeploy{Releases: []latest.HelmRelease{{Name: "first"}, {Name: "second"}}}, }, }, }, @@ -65,18 +65,18 @@ func TestEmptyState(t *testing.T) { }, { description: "multiple artifacts of different types gke cluster 1 deployer ", - cfg: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - BuildType: latestV1.BuildType{Cluster: &latestV1.ClusterDetails{}}, - Artifacts: []*latestV1.Artifact{ - {ImageName: "img1", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{}}}, - {ImageName: "img2", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{}}}, - {ImageName: "img3", ArtifactType: latestV1.ArtifactType{JibArtifact: &latestV1.JibArtifact{}}}, + cfg: latest.Pipeline{ + Build: latest.BuildConfig{ + BuildType: latest.BuildType{Cluster: &latest.ClusterDetails{}}, + Artifacts: []*latest.Artifact{ + {ImageName: "img1", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, + {ImageName: "img2", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, + {ImageName: "img3", ArtifactType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{}}}, }, }, - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KustomizeDeploy: &latestV1.KustomizeDeploy{}, + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KustomizeDeploy: &latest.KustomizeDeploy{}, }, }, }, @@ -97,11 +97,11 @@ func TestEmptyState(t *testing.T) { }, { description: "no deployer, kaniko artifact, GCB build", - cfg: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - BuildType: latestV1.BuildType{GoogleCloudBuild: &latestV1.GoogleCloudBuild{}}, - Artifacts: []*latestV1.Artifact{ - {ImageName: "img1", ArtifactType: latestV1.ArtifactType{KanikoArtifact: &latestV1.KanikoArtifact{}}}, + cfg: latest.Pipeline{ + Build: latest.BuildConfig{ + BuildType: latest.BuildType{GoogleCloudBuild: &latest.GoogleCloudBuild{}}, + Artifacts: []*latest.Artifact{ + {ImageName: "img1", ArtifactType: latest.ArtifactType{KanikoArtifact: &latest.KanikoArtifact{}}}, }, }, }, @@ -117,10 +117,10 @@ func TestEmptyState(t *testing.T) { }, { description: "no build, kustomize deployer other cluster", - cfg: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KustomizeDeploy: &latestV1.KustomizeDeploy{}, + cfg: latest.Pipeline{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KustomizeDeploy: &latest.KustomizeDeploy{}, }, }, }, @@ -137,7 +137,7 @@ func TestEmptyState(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { handler = &eventHandler{ - state: emptyState(mockCfg([]latestV1.Pipeline{test.cfg}, test.cluster)), + state: emptyState(mockCfg([]latest.Pipeline{test.cfg}, test.cluster)), } metadata := handler.state.Metadata builders := metadata.Build.Builders diff --git a/pkg/skaffold/event/v2/application_logs_test.go b/pkg/skaffold/event/v2/application_logs_test.go index c249e0b2f11..71b8289dcf4 100644 --- a/pkg/skaffold/event/v2/application_logs_test.go +++ b/pkg/skaffold/event/v2/application_logs_test.go @@ -19,13 +19,13 @@ package v2 import ( "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" proto "github.com/GoogleContainerTools/skaffold/proto/v2" ) func TestHandleApplicationLogEvent(t *testing.T) { testHandler := newHandler() - testHandler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + testHandler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) messages := []string{ "hi!", diff --git a/pkg/skaffold/event/v2/config.go b/pkg/skaffold/event/v2/config.go index 67058da9a69..73b23689c83 100644 --- a/pkg/skaffold/event/v2/config.go +++ b/pkg/skaffold/event/v2/config.go @@ -16,15 +16,13 @@ limitations under the License. package v2 -import ( - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" -) +import "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" type Config interface { GetKubeContext() string AutoBuild() bool AutoDeploy() bool AutoSync() bool - GetPipelines() []latestV1.Pipeline + GetPipelines() []latest.Pipeline GetRunID() string } diff --git a/pkg/skaffold/event/v2/debugging_test.go b/pkg/skaffold/event/v2/debugging_test.go index e0ccbae1609..af11be7cd88 100644 --- a/pkg/skaffold/event/v2/debugging_test.go +++ b/pkg/skaffold/event/v2/debugging_test.go @@ -19,14 +19,14 @@ package v2 import ( "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) func TestDebuggingContainer(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) found := func() bool { for _, dc := range handler.getState().DebuggingContainers { diff --git a/pkg/skaffold/event/v2/deploy_test.go b/pkg/skaffold/event/v2/deploy_test.go index 160d6d8a1f1..3a0506ae7b9 100644 --- a/pkg/skaffold/event/v2/deploy_test.go +++ b/pkg/skaffold/event/v2/deploy_test.go @@ -23,7 +23,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" proto "github.com/GoogleContainerTools/skaffold/proto/v2" ) @@ -63,7 +63,7 @@ func TestHandleDeploySubtaskEvent(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().DeployState.Status == NotStarted }) handler.handleDeploySubtaskEvent(test.event) diff --git a/pkg/skaffold/event/v2/event_test.go b/pkg/skaffold/event/v2/event_test.go index 0f30bc9f68d..1e89a57ee22 100644 --- a/pkg/skaffold/event/v2/event_test.go +++ b/pkg/skaffold/event/v2/event_test.go @@ -30,7 +30,7 @@ import ( "github.com/golang/protobuf/jsonpb" "github.com/mitchellh/go-homedir" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" proto "github.com/GoogleContainerTools/skaffold/proto/v2" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -234,18 +234,18 @@ func TestLastLogFile(t *testing.T) { } type config struct { - pipes []latestV1.Pipeline + pipes []latest.Pipeline kubectx string } -func (c config) GetKubeContext() string { return c.kubectx } -func (c config) AutoBuild() bool { return true } -func (c config) AutoDeploy() bool { return true } -func (c config) AutoSync() bool { return true } -func (c config) GetPipelines() []latestV1.Pipeline { return c.pipes } -func (c config) GetRunID() string { return "run-id" } +func (c config) GetKubeContext() string { return c.kubectx } +func (c config) AutoBuild() bool { return true } +func (c config) AutoDeploy() bool { return true } +func (c config) AutoSync() bool { return true } +func (c config) GetPipelines() []latest.Pipeline { return c.pipes } +func (c config) GetRunID() string { return "run-id" } -func mockCfg(pipes []latestV1.Pipeline, kubectx string) config { +func mockCfg(pipes []latest.Pipeline, kubectx string) config { return config{ pipes: pipes, kubectx: kubectx, diff --git a/pkg/skaffold/event/v2/logger_test.go b/pkg/skaffold/event/v2/logger_test.go index 90008906a12..7fd715d7c50 100644 --- a/pkg/skaffold/event/v2/logger_test.go +++ b/pkg/skaffold/event/v2/logger_test.go @@ -21,7 +21,7 @@ import ( "github.com/sirupsen/logrus" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/proto/enums" proto "github.com/GoogleContainerTools/skaffold/proto/v2" "github.com/GoogleContainerTools/skaffold/testutil" @@ -29,7 +29,7 @@ import ( func TestHandleSkaffoldLogEvent(t *testing.T) { testHandler := newHandler() - testHandler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + testHandler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) messages := []string{ "hi!", diff --git a/pkg/skaffold/event/v2/metadata.go b/pkg/skaffold/event/v2/metadata.go index f11fdc17b43..e3e56c501d8 100644 --- a/pkg/skaffold/event/v2/metadata.go +++ b/pkg/skaffold/event/v2/metadata.go @@ -20,7 +20,7 @@ import ( "fmt" "strings" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/version" proto "github.com/GoogleContainerTools/skaffold/proto/v2" ) @@ -39,7 +39,7 @@ func LogMetaEvent() { ) } -func initializeMetadata(pipelines []latestV1.Pipeline, kubeContext string, runID string) *proto.Metadata { +func initializeMetadata(pipelines []latest.Pipeline, kubeContext string, runID string) *proto.Metadata { m := &proto.Metadata{ Build: &proto.BuildMetadata{}, Render: &proto.RenderMetadata{}, @@ -80,7 +80,7 @@ func initializeMetadata(pipelines []latestV1.Pipeline, kubeContext string, runID return m } -func getArtifacts(b latestV1.BuildConfig) []*proto.BuildMetadata_Artifact { +func getArtifacts(b latest.BuildConfig) []*proto.BuildMetadata_Artifact { result := []*proto.BuildMetadata_Artifact{} for _, a := range b.Artifacts { artifact := &proto.BuildMetadata_Artifact{ @@ -112,7 +112,7 @@ func getArtifacts(b latestV1.BuildConfig) []*proto.BuildMetadata_Artifact { return result } -func getDeploy(d latestV1.DeployConfig) []*proto.DeployMetadata_Deployer { +func getDeploy(d latest.DeployConfig) []*proto.DeployMetadata_Deployer { var deployers []*proto.DeployMetadata_Deployer if d.HelmDeploy != nil { diff --git a/pkg/skaffold/event/v2/metadata_test.go b/pkg/skaffold/event/v2/metadata_test.go index b2a9de83093..02a998b25b7 100644 --- a/pkg/skaffold/event/v2/metadata_test.go +++ b/pkg/skaffold/event/v2/metadata_test.go @@ -22,7 +22,7 @@ import ( "google.golang.org/protobuf/testing/protocmp" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" proto "github.com/GoogleContainerTools/skaffold/proto/v2" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -30,21 +30,21 @@ import ( func TestEmptyState(t *testing.T) { tests := []struct { description string - cfg latestV1.Pipeline + cfg latest.Pipeline cluster string expected *proto.Metadata }{ { description: "one build artifact minikube cluster multiple deployers", - cfg: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - BuildType: latestV1.BuildType{LocalBuild: &latestV1.LocalBuild{}}, - Artifacts: []*latestV1.Artifact{{ImageName: "docker-artifact-1", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{}}}}, + cfg: latest.Pipeline{ + Build: latest.BuildConfig{ + BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}, + Artifacts: []*latest.Artifact{{ImageName: "docker-artifact-1", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}}, }, - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{}, - HelmDeploy: &latestV1.HelmDeploy{Releases: []latestV1.HelmRelease{{Name: "first"}, {Name: "second"}}}, + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{}, + HelmDeploy: &latest.HelmDeploy{Releases: []latest.HelmRelease{{Name: "first"}, {Name: "second"}}}, }, }, }, @@ -67,18 +67,18 @@ func TestEmptyState(t *testing.T) { }, { description: "multiple artifacts of different types gke cluster 1 deployer ", - cfg: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - BuildType: latestV1.BuildType{Cluster: &latestV1.ClusterDetails{}}, - Artifacts: []*latestV1.Artifact{ - {ImageName: "docker-artifact-1", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{}}}, - {ImageName: "docker-artifact-2", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{}}}, - {ImageName: "jib-artifact-1", ArtifactType: latestV1.ArtifactType{JibArtifact: &latestV1.JibArtifact{}}}, + cfg: latest.Pipeline{ + Build: latest.BuildConfig{ + BuildType: latest.BuildType{Cluster: &latest.ClusterDetails{}}, + Artifacts: []*latest.Artifact{ + {ImageName: "docker-artifact-1", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, + {ImageName: "docker-artifact-2", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, + {ImageName: "jib-artifact-1", ArtifactType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{}}}, }, }, - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KustomizeDeploy: &latestV1.KustomizeDeploy{}, + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KustomizeDeploy: &latest.KustomizeDeploy{}, }, }, }, @@ -102,11 +102,11 @@ func TestEmptyState(t *testing.T) { }, { description: "no deployer, kaniko artifact, GCB build", - cfg: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - BuildType: latestV1.BuildType{GoogleCloudBuild: &latestV1.GoogleCloudBuild{}}, - Artifacts: []*latestV1.Artifact{ - {ImageName: "artifact-1", ArtifactType: latestV1.ArtifactType{KanikoArtifact: &latestV1.KanikoArtifact{}}}, + cfg: latest.Pipeline{ + Build: latest.BuildConfig{ + BuildType: latest.BuildType{GoogleCloudBuild: &latest.GoogleCloudBuild{}}, + Artifacts: []*latest.Artifact{ + {ImageName: "artifact-1", ArtifactType: latest.ArtifactType{KanikoArtifact: &latest.KanikoArtifact{}}}, }, }, }, @@ -123,10 +123,10 @@ func TestEmptyState(t *testing.T) { }, { description: "no build, kustomize deployer other cluster", - cfg: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KustomizeDeploy: &latestV1.KustomizeDeploy{}, + cfg: latest.Pipeline{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KustomizeDeploy: &latest.KustomizeDeploy{}, }, }, }, @@ -145,7 +145,7 @@ func TestEmptyState(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { handler = &eventHandler{ - state: emptyState(mockCfg([]latestV1.Pipeline{test.cfg}, test.cluster)), + state: emptyState(mockCfg([]latest.Pipeline{test.cfg}, test.cluster)), } metadata := handler.state.Metadata artifacts := metadata.Build.Artifacts diff --git a/pkg/skaffold/event/v2/render_test.go b/pkg/skaffold/event/v2/render_test.go index 46bed3b93a6..425d46f54e2 100644 --- a/pkg/skaffold/event/v2/render_test.go +++ b/pkg/skaffold/event/v2/render_test.go @@ -23,7 +23,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" proto "github.com/GoogleContainerTools/skaffold/proto/v2" ) @@ -63,7 +63,7 @@ func TestHandleRenderSubtaskEvent(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().RenderState.Status == NotStarted }) handler.handleRenderSubtaskEvent(test.event) diff --git a/pkg/skaffold/event/v2/state_test.go b/pkg/skaffold/event/v2/state_test.go index e7ac8873797..458a91ab042 100644 --- a/pkg/skaffold/event/v2/state_test.go +++ b/pkg/skaffold/event/v2/state_test.go @@ -23,14 +23,14 @@ import ( "google.golang.org/protobuf/testing/protocmp" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" proto "github.com/GoogleContainerTools/skaffold/proto/v2" "github.com/GoogleContainerTools/skaffold/testutil" ) func TestGetState(t *testing.T) { ev := newHandler() - ev.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + ev.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) ev.stateLock.Lock() ev.state.BuildState.Artifacts["img"] = Complete diff --git a/pkg/skaffold/event/v2/status_check_test.go b/pkg/skaffold/event/v2/status_check_test.go index 0f6f92a3bc2..a2b01b4d496 100644 --- a/pkg/skaffold/event/v2/status_check_test.go +++ b/pkg/skaffold/event/v2/status_check_test.go @@ -19,7 +19,7 @@ package v2 import ( "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" proto "github.com/GoogleContainerTools/skaffold/proto/v2" ) @@ -27,7 +27,7 @@ func TestResourceStatusCheckEventUpdated(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) ResourceStatusCheckEventUpdated("ns:pod/foo", &proto.ActionableErr{ @@ -41,7 +41,7 @@ func TestResourceStatusCheckEventSucceeded(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) resourceStatusCheckEventSucceeded("ns:pod/foo") @@ -52,7 +52,7 @@ func TestResourceStatusCheckEventFailed(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) resourceStatusCheckEventFailed("ns:pod/foo", &proto.ActionableErr{ diff --git a/pkg/skaffold/event/v2/tester_test.go b/pkg/skaffold/event/v2/tester_test.go index 925b69160df..c3910593327 100644 --- a/pkg/skaffold/event/v2/tester_test.go +++ b/pkg/skaffold/event/v2/tester_test.go @@ -23,7 +23,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" proto "github.com/GoogleContainerTools/skaffold/proto/v2" ) @@ -63,7 +63,7 @@ func TestHandleTestSubtaskEvent(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { handler = newHandler() - handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().TestState.Status == NotStarted }) handler.handleTestSubtaskEvent(test.event) diff --git a/pkg/skaffold/generate_pipeline/generate_pipeline.go b/pkg/skaffold/generate_pipeline/generate_pipeline.go index f2edb6f4b03..1704b57b89d 100644 --- a/pkg/skaffold/generate_pipeline/generate_pipeline.go +++ b/pkg/skaffold/generate_pipeline/generate_pipeline.go @@ -30,14 +30,14 @@ import ( tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/pipeline" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // ConfigFile keeps track of config files and their corresponding SkaffoldConfigs and generated Profiles type ConfigFile struct { Path string - Config *latestV1.SkaffoldConfig - Profile *latestV1.Profile + Config *latest.SkaffoldConfig + Profile *latest.Profile } func Yaml(out io.Writer, namespace string, configFiles []*ConfigFile) (*bytes.Buffer, error) { diff --git a/pkg/skaffold/generate_pipeline/profile.go b/pkg/skaffold/generate_pipeline/profile.go index e73bedb7158..c48e9b7444c 100644 --- a/pkg/skaffold/generate_pipeline/profile.go +++ b/pkg/skaffold/generate_pipeline/profile.go @@ -28,7 +28,7 @@ import ( yamlv2 "gopkg.in/yaml.v2" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) func CreateSkaffoldProfile(out io.Writer, namespace string, configFile *ConfigFile) error { @@ -67,7 +67,7 @@ confirmLoop: return fmt.Errorf("generating profile \"oncluster\": %w", err) } - bProfile, err := yamlv2.Marshal([]*latestV1.Profile{profile}) + bProfile, err := yamlv2.Marshal([]*latest.Profile{profile}) if err != nil { return fmt.Errorf("marshaling new profile: %w", err) } @@ -105,16 +105,16 @@ confirmLoop: return nil } -func generateProfile(out io.Writer, namespace string, config *latestV1.SkaffoldConfig) (*latestV1.Profile, error) { +func generateProfile(out io.Writer, namespace string, config *latest.SkaffoldConfig) (*latest.Profile, error) { if len(config.Build.Artifacts) == 0 { return nil, errors.New("no Artifacts to add to profile") } - profile := &latestV1.Profile{ + profile := &latest.Profile{ Name: "oncluster", - Pipeline: latestV1.Pipeline{ + Pipeline: latest.Pipeline{ Build: config.Pipeline.Build, - Deploy: latestV1.DeployConfig{}, + Deploy: latest.DeployConfig{}, }, } @@ -125,20 +125,20 @@ func generateProfile(out io.Writer, namespace string, config *latestV1.SkaffoldC if artifact.DockerArtifact != nil { output.Default.Fprintf(out, "Cannot use Docker to build %s on cluster. Adding config for building with Kaniko.\n", artifact.ImageName) artifact.DockerArtifact = nil - artifact.KanikoArtifact = &latestV1.KanikoArtifact{} + artifact.KanikoArtifact = &latest.KanikoArtifact{} addKaniko = true } } // Add kaniko config to build config if needed if addKaniko { - profile.Build.Cluster = &latestV1.ClusterDetails{ + profile.Build.Cluster = &latest.ClusterDetails{ PullSecretName: "kaniko-secret", } profile.Build.LocalBuild = nil } if namespace != "" { if profile.Build.Cluster == nil { - profile.Build.Cluster = &latestV1.ClusterDetails{} + profile.Build.Cluster = &latest.ClusterDetails{} } profile.Build.Cluster.Namespace = namespace } diff --git a/pkg/skaffold/generate_pipeline/profile_test.go b/pkg/skaffold/generate_pipeline/profile_test.go index 794feb888ee..6a88c16bbc5 100644 --- a/pkg/skaffold/generate_pipeline/profile_test.go +++ b/pkg/skaffold/generate_pipeline/profile_test.go @@ -20,29 +20,29 @@ import ( "io/ioutil" "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) func TestGenerateProfile(t *testing.T) { var tests = []struct { description string - skaffoldConfig *latestV1.SkaffoldConfig - expectedProfile *latestV1.Profile + skaffoldConfig *latest.SkaffoldConfig + expectedProfile *latest.Profile responses []string namespace string shouldErr bool }{ { description: "successful profile generation docker", - skaffoldConfig: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + skaffoldConfig: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ { ImageName: "test", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, }, }, }, @@ -50,20 +50,20 @@ func TestGenerateProfile(t *testing.T) { }, }, namespace: "", - expectedProfile: &latestV1.Profile{ + expectedProfile: &latest.Profile{ Name: "oncluster", - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ { ImageName: "test-pipeline", - ArtifactType: latestV1.ArtifactType{ - KanikoArtifact: &latestV1.KanikoArtifact{}, + ArtifactType: latest.ArtifactType{ + KanikoArtifact: &latest.KanikoArtifact{}, }, }, }, - BuildType: latestV1.BuildType{ - Cluster: &latestV1.ClusterDetails{ + BuildType: latest.BuildType{ + Cluster: &latest.ClusterDetails{ PullSecretName: "kaniko-secret", }, }, @@ -74,14 +74,14 @@ func TestGenerateProfile(t *testing.T) { }, { description: "successful profile generation jib", - skaffoldConfig: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + skaffoldConfig: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ { ImageName: "test", - ArtifactType: latestV1.ArtifactType{ - JibArtifact: &latestV1.JibArtifact{ + ArtifactType: latest.ArtifactType{ + JibArtifact: &latest.JibArtifact{ Project: "test-module", }, DockerArtifact: nil, @@ -92,15 +92,15 @@ func TestGenerateProfile(t *testing.T) { }, }, namespace: "", - expectedProfile: &latestV1.Profile{ + expectedProfile: &latest.Profile{ Name: "oncluster", - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ { ImageName: "test-pipeline", - ArtifactType: latestV1.ArtifactType{ - JibArtifact: &latestV1.JibArtifact{ + ArtifactType: latest.ArtifactType{ + JibArtifact: &latest.JibArtifact{ Project: "test-module", }, }, @@ -113,14 +113,14 @@ func TestGenerateProfile(t *testing.T) { }, { description: "kaniko artifact with namespace", - skaffoldConfig: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + skaffoldConfig: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ { ImageName: "test", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, }, }, }, @@ -128,20 +128,20 @@ func TestGenerateProfile(t *testing.T) { }, }, namespace: "test-ns", - expectedProfile: &latestV1.Profile{ + expectedProfile: &latest.Profile{ Name: "oncluster", - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ { ImageName: "test-pipeline", - ArtifactType: latestV1.ArtifactType{ - KanikoArtifact: &latestV1.KanikoArtifact{}, + ArtifactType: latest.ArtifactType{ + KanikoArtifact: &latest.KanikoArtifact{}, }, }, }, - BuildType: latestV1.BuildType{ - Cluster: &latestV1.ClusterDetails{ + BuildType: latest.BuildType{ + Cluster: &latest.ClusterDetails{ PullSecretName: "kaniko-secret", Namespace: "test-ns", }, @@ -153,10 +153,10 @@ func TestGenerateProfile(t *testing.T) { }, { description: "failed profile generation", - skaffoldConfig: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{}, + skaffoldConfig: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{}, }, }, }, diff --git a/pkg/skaffold/generate_pipeline/tasks_test.go b/pkg/skaffold/generate_pipeline/tasks_test.go index fbc62d3a4c7..9321c53ee38 100644 --- a/pkg/skaffold/generate_pipeline/tasks_test.go +++ b/pkg/skaffold/generate_pipeline/tasks_test.go @@ -23,7 +23,7 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -40,10 +40,10 @@ func TestGenerateBuildTasks(t *testing.T) { configFiles: []*ConfigFile{ { Path: "test1", - Profile: &latestV1.Profile{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + Profile: &latest.Profile{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ { ImageName: "testArtifact1", }, @@ -54,10 +54,10 @@ func TestGenerateBuildTasks(t *testing.T) { }, { Path: "test2", - Profile: &latestV1.Profile{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + Profile: &latest.Profile{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ { ImageName: "testArtifact2", }, @@ -111,10 +111,10 @@ func TestGenerateBuildTasks(t *testing.T) { configFiles: []*ConfigFile{ { Path: "test1", - Profile: &latestV1.Profile{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + Profile: &latest.Profile{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ { ImageName: "testArtifact1", }, @@ -168,13 +168,13 @@ func TestGenerateBuildTasks(t *testing.T) { func TestGenerateBuildTask(t *testing.T) { var tests = []struct { description string - buildConfig latestV1.BuildConfig + buildConfig latest.BuildConfig shouldErr bool }{ { description: "successfully generate build task", - buildConfig: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + buildConfig: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ { ImageName: "testArtifact", }, @@ -184,8 +184,8 @@ func TestGenerateBuildTask(t *testing.T) { }, { description: "fail generating build task", - buildConfig: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{}, + buildConfig: latest.BuildConfig{ + Artifacts: []*latest.Artifact{}, }, shouldErr: true, }, @@ -195,8 +195,8 @@ func TestGenerateBuildTask(t *testing.T) { testutil.Run(t, test.description, func(t *testutil.T) { configFile := &ConfigFile{ Path: "test", - Profile: &latestV1.Profile{ - Pipeline: latestV1.Pipeline{ + Profile: &latest.Profile{ + Pipeline: latest.Pipeline{ Build: test.buildConfig, }, }, @@ -220,11 +220,11 @@ func TestGenerateDeployTasks(t *testing.T) { configFiles: []*ConfigFile{ { Path: "test1", - Config: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - HelmDeploy: &latestV1.HelmDeploy{}, + Config: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + HelmDeploy: &latest.HelmDeploy{}, }, }, }, @@ -232,11 +232,11 @@ func TestGenerateDeployTasks(t *testing.T) { }, { Path: "test2", - Config: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - HelmDeploy: &latestV1.HelmDeploy{}, + Config: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + HelmDeploy: &latest.HelmDeploy{}, }, }, }, @@ -285,11 +285,11 @@ func TestGenerateDeployTasks(t *testing.T) { configFiles: []*ConfigFile{ { Path: "test1", - Config: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - HelmDeploy: &latestV1.HelmDeploy{}, + Config: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + HelmDeploy: &latest.HelmDeploy{}, }, }, }, @@ -337,22 +337,22 @@ func TestGenerateDeployTasks(t *testing.T) { func TestGenerateDeployTask(t *testing.T) { var tests = []struct { description string - deployConfig latestV1.DeployConfig + deployConfig latest.DeployConfig shouldErr bool }{ { description: "successfully generate deploy task", - deployConfig: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - HelmDeploy: &latestV1.HelmDeploy{}, + deployConfig: latest.DeployConfig{ + DeployType: latest.DeployType{ + HelmDeploy: &latest.HelmDeploy{}, }, }, shouldErr: false, }, { description: "fail generating deploy task", - deployConfig: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ + deployConfig: latest.DeployConfig{ + DeployType: latest.DeployType{ HelmDeploy: nil, KubectlDeploy: nil, KustomizeDeploy: nil, @@ -366,8 +366,8 @@ func TestGenerateDeployTask(t *testing.T) { testutil.Run(t, test.description, func(t *testutil.T) { configFile := &ConfigFile{ Path: "test", - Config: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ + Config: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ Deploy: test.deployConfig, }, }, diff --git a/pkg/skaffold/git/errors.go b/pkg/skaffold/git/errors.go index b4bfa7faa7b..2acf265b375 100644 --- a/pkg/skaffold/git/errors.go +++ b/pkg/skaffold/git/errors.go @@ -20,12 +20,12 @@ import ( "fmt" sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/proto/v1" ) // SyncDisabledErr returns error when git repository sync is turned off by the user but the repository clone doesn't exist inside the cache directory. -func SyncDisabledErr(g latestV1.GitInfo, repoCacheDir string) error { +func SyncDisabledErr(g latest.GitInfo, repoCacheDir string) error { msg := fmt.Sprintf("cache directory %q for repository %q at ref %q does not exist, and repository sync is explicitly disabled via flag `--sync-remote-cache`", repoCacheDir, g.Repo, g.Ref) return sErrors.NewError(fmt.Errorf(msg), &proto.ActionableErr{ diff --git a/pkg/skaffold/git/gitutil.go b/pkg/skaffold/git/gitutil.go index 232a52377ee..9c3674309bd 100644 --- a/pkg/skaffold/git/gitutil.go +++ b/pkg/skaffold/git/gitutil.go @@ -31,7 +31,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -81,7 +81,7 @@ func branchExists(ctx context.Context, repo, branch string) (bool, error) { } // getRepoDir returns the cache directory name for a remote repo -func getRepoDir(g latestV1.GitInfo) (string, error) { +func getRepoDir(g latest.GitInfo) (string, error) { inputs := []string{g.Repo, g.Ref} hasher := sha256.New() enc := json.NewEncoder(hasher) @@ -106,7 +106,7 @@ func GetRepoCacheDir(opts config.SkaffoldOptions) (string, error) { return filepath.Join(home, constants.DefaultSkaffoldDir, "repos"), nil } -func syncRepo(ctx context.Context, g latestV1.GitInfo, opts config.SkaffoldOptions) (string, error) { +func syncRepo(ctx context.Context, g latest.GitInfo, opts config.SkaffoldOptions) (string, error) { skaffoldCacheDir, err := GetRepoCacheDir(opts) r := gitCmd{Dir: skaffoldCacheDir} if err != nil { diff --git a/pkg/skaffold/git/gitutil_test.go b/pkg/skaffold/git/gitutil_test.go index 210e8684f11..38a05e7e895 100644 --- a/pkg/skaffold/git/gitutil_test.go +++ b/pkg/skaffold/git/gitutil_test.go @@ -23,7 +23,7 @@ import ( "testing" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -76,7 +76,7 @@ func TestDefaultRef(t *testing.T) { func TestSyncRepo(t *testing.T) { tests := []struct { description string - g latestV1.GitInfo + g latest.GitInfo cmds []cmdResponse syncFlag string existing bool @@ -85,7 +85,7 @@ func TestSyncRepo(t *testing.T) { }{ { description: "first time repo clone succeeds", - g: latestV1.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master"}, + g: latest.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master"}, cmds: []cmdResponse{ {cmd: "git clone http://github.com/foo.git ./iSEL5rQfK5EJ2yLhnW8tUgcVOvDC8Wjl --branch master --depth 1"}, }, @@ -94,7 +94,7 @@ func TestSyncRepo(t *testing.T) { }, { description: "first time repo clone fails", - g: latestV1.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master"}, + g: latest.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master"}, cmds: []cmdResponse{ {cmd: "git clone http://github.com/foo.git ./iSEL5rQfK5EJ2yLhnW8tUgcVOvDC8Wjl --branch master --depth 1", err: errors.New("error")}, }, @@ -103,13 +103,13 @@ func TestSyncRepo(t *testing.T) { }, { description: "first time repo clone with sync off via flag fails", - g: latestV1.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master"}, + g: latest.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master"}, syncFlag: "never", shouldErr: true, }, { description: "existing repo update succeeds", - g: latestV1.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master"}, + g: latest.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master"}, existing: true, cmds: []cmdResponse{ {cmd: "git remote -v", out: "origin git@github.com/foo.git"}, @@ -121,7 +121,7 @@ func TestSyncRepo(t *testing.T) { }, { description: "existing repo update fails on remote check", - g: latestV1.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master"}, + g: latest.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master"}, existing: true, cmds: []cmdResponse{ {cmd: "git remote -v", err: errors.New("error")}, @@ -131,7 +131,7 @@ func TestSyncRepo(t *testing.T) { }, { description: "existing repo with no remotes fails", - g: latestV1.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master"}, + g: latest.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master"}, existing: true, cmds: []cmdResponse{ {cmd: "git remote -v"}, @@ -141,7 +141,7 @@ func TestSyncRepo(t *testing.T) { }, { description: "existing dirty repo with sync off succeeds", - g: latestV1.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master", Sync: util.BoolPtr(false)}, + g: latest.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master", Sync: util.BoolPtr(false)}, existing: true, cmds: []cmdResponse{ {cmd: "git remote -v", out: "origin git@github.com/foo.git"}, @@ -151,7 +151,7 @@ func TestSyncRepo(t *testing.T) { }, { description: "existing dirty repo with sync off via flag succeeds", - g: latestV1.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master"}, + g: latest.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master"}, existing: true, cmds: []cmdResponse{ {cmd: "git remote -v", out: "origin git@github.com/foo.git"}, @@ -161,7 +161,7 @@ func TestSyncRepo(t *testing.T) { }, { description: "existing repo with uncommitted changes and sync on resets", - g: latestV1.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master", Sync: util.BoolPtr(true)}, + g: latest.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master", Sync: util.BoolPtr(true)}, existing: true, cmds: []cmdResponse{ {cmd: "git remote -v", out: "origin git@github.com/foo.git"}, @@ -173,7 +173,7 @@ func TestSyncRepo(t *testing.T) { }, { description: "existing repo with unpushed commits and sync on resets", - g: latestV1.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master", Sync: util.BoolPtr(true)}, + g: latest.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master", Sync: util.BoolPtr(true)}, existing: true, cmds: []cmdResponse{ {cmd: "git remote -v", out: "origin git@github.com/foo.git"}, @@ -185,7 +185,7 @@ func TestSyncRepo(t *testing.T) { }, { description: "existing repo update fails on fetch", - g: latestV1.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master"}, + g: latest.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master"}, existing: true, cmds: []cmdResponse{ {cmd: "git remote -v", out: "origin git@github.com/foo.git"}, @@ -196,7 +196,7 @@ func TestSyncRepo(t *testing.T) { }, { description: "existing repo update fails on reset", - g: latestV1.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master"}, + g: latest.GitInfo{Repo: "http://github.com/foo.git", Path: "bar/skaffold.yaml", Ref: "master"}, existing: true, cmds: []cmdResponse{ {cmd: "git remote -v", out: "origin git@github.com/foo.git"}, diff --git a/pkg/skaffold/graph/artifact_graph.go b/pkg/skaffold/graph/artifact_graph.go index 436c581b7d3..0ff46b1523d 100644 --- a/pkg/skaffold/graph/artifact_graph.go +++ b/pkg/skaffold/graph/artifact_graph.go @@ -16,7 +16,7 @@ limitations under the License. package graph -import latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" +import "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" // Artifact is the result corresponding to each successful build. type Artifact struct { @@ -25,11 +25,11 @@ type Artifact struct { } // ArtifactGraph is a map of [artifact image : artifact definition] -type ArtifactGraph map[string]*latestV1.Artifact +type ArtifactGraph map[string]*latest.Artifact -// ToArtifactGraph creates an instance of `ArtifactGraph` from `[]*latestV1.Artifact` -func ToArtifactGraph(artifacts []*latestV1.Artifact) ArtifactGraph { - m := make(map[string]*latestV1.Artifact) +// ToArtifactGraph creates an instance of `ArtifactGraph` from `[]*latest.Artifact` +func ToArtifactGraph(artifacts []*latest.Artifact) ArtifactGraph { + m := make(map[string]*latest.Artifact) for _, a := range artifacts { m[a.ImageName] = a } @@ -37,8 +37,8 @@ func ToArtifactGraph(artifacts []*latestV1.Artifact) ArtifactGraph { } // Dependencies returns the de-referenced slice of required artifacts for a given artifact -func (g ArtifactGraph) Dependencies(a *latestV1.Artifact) []*latestV1.Artifact { - var sl []*latestV1.Artifact +func (g ArtifactGraph) Dependencies(a *latest.Artifact) []*latest.Artifact { + var sl []*latest.Artifact for _, d := range a.Dependencies { sl = append(sl, g[d.ImageName]) } diff --git a/pkg/skaffold/graph/artifact_graph_test.go b/pkg/skaffold/graph/artifact_graph_test.go index ad524c5b7a2..0d2d70d2dd5 100644 --- a/pkg/skaffold/graph/artifact_graph_test.go +++ b/pkg/skaffold/graph/artifact_graph_test.go @@ -19,13 +19,13 @@ package graph import ( "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) func TestToArtifactGraph_shouldGenerateArtifactGraph(t *testing.T) { testutil.Run(t, "generate artifacts graph", func(t *testutil.T) { - artifacts := []*latestV1.Artifact{ + artifacts := []*latest.Artifact{ { ImageName: "1", }, @@ -43,10 +43,10 @@ func TestToArtifactGraph_shouldGenerateArtifactGraph(t *testing.T) { func TestToArtifactGraph_shouldReturnDependencies(t *testing.T) { testutil.Run(t, "return artifact dependencies", func(t *testutil.T) { - artifacts := []*latestV1.Artifact{ + artifacts := []*latest.Artifact{ { ImageName: "1", - Dependencies: []*latestV1.ArtifactDependency{ + Dependencies: []*latest.ArtifactDependency{ { ImageName: "randomImageName", Alias: "alias", diff --git a/pkg/skaffold/graph/dependencies.go b/pkg/skaffold/graph/dependencies.go index 2759b95f88c..a7ba133d979 100644 --- a/pkg/skaffold/graph/dependencies.go +++ b/pkg/skaffold/graph/dependencies.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/misc" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/instrumentation" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -39,10 +39,10 @@ var getDependenciesFunc = sourceDependenciesForArtifact type SourceDependenciesCache interface { // TransitiveArtifactDependencies returns the source dependencies for the target artifact, including the source dependencies from all other artifacts that are in the transitive closure of its artifact dependencies. // The result (even if an error) is cached so that the function is evaluated only once for every artifact. The cache is reset before the start of the next devloop. - TransitiveArtifactDependencies(ctx context.Context, a *latestV1.Artifact) ([]string, error) + TransitiveArtifactDependencies(ctx context.Context, a *latest.Artifact) ([]string, error) // SingleArtifactDependencies returns the source dependencies for only the target artifact. // The result (even if an error) is cached so that the function is evaluated only once for every artifact. The cache is reset before the start of the next devloop. - SingleArtifactDependencies(ctx context.Context, a *latestV1.Artifact) ([]string, error) + SingleArtifactDependencies(ctx context.Context, a *latest.Artifact) ([]string, error) // Reset removes the cached source dependencies for all artifacts Reset() } @@ -58,7 +58,7 @@ type dependencyResolverImpl struct { cache *util.SyncStore } -func (r *dependencyResolverImpl) TransitiveArtifactDependencies(ctx context.Context, a *latestV1.Artifact) ([]string, error) { +func (r *dependencyResolverImpl) TransitiveArtifactDependencies(ctx context.Context, a *latest.Artifact) ([]string, error) { ctx, endTrace := instrumentation.StartTrace(ctx, "TransitiveArtifactDependencies", map[string]string{ "ArtifactName": instrumentation.PII(a.ImageName), }) @@ -80,7 +80,7 @@ func (r *dependencyResolverImpl) TransitiveArtifactDependencies(ctx context.Cont return deps, nil } -func (r *dependencyResolverImpl) SingleArtifactDependencies(ctx context.Context, a *latestV1.Artifact) ([]string, error) { +func (r *dependencyResolverImpl) SingleArtifactDependencies(ctx context.Context, a *latest.Artifact) ([]string, error) { ctx, endTrace := instrumentation.StartTrace(ctx, "SingleArtifactDependencies", map[string]string{ "ArtifactName": instrumentation.PII(a.ImageName), }) @@ -105,7 +105,7 @@ func (r *dependencyResolverImpl) Reset() { } // sourceDependenciesForArtifact returns the build dependencies for the current artifact. -func sourceDependenciesForArtifact(ctx context.Context, a *latestV1.Artifact, cfg docker.Config, r docker.ArtifactResolver) ([]string, error) { +func sourceDependenciesForArtifact(ctx context.Context, a *latest.Artifact, cfg docker.Config, r docker.ArtifactResolver) ([]string, error) { var ( paths []string err error diff --git a/pkg/skaffold/graph/dependencies_test.go b/pkg/skaffold/graph/dependencies_test.go index fc5e6c88950..e3316855738 100644 --- a/pkg/skaffold/graph/dependencies_test.go +++ b/pkg/skaffold/graph/dependencies_test.go @@ -24,16 +24,16 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) func TestSourceDependenciesCache(t *testing.T) { testutil.Run(t, "TestTransitiveSourceDependenciesCache", func(t *testutil.T) { - g := map[string]*latestV1.Artifact{ - "img1": {ImageName: "img1", Dependencies: []*latestV1.ArtifactDependency{{ImageName: "img2"}}}, - "img2": {ImageName: "img2", Dependencies: []*latestV1.ArtifactDependency{{ImageName: "img3"}, {ImageName: "img4"}}}, - "img3": {ImageName: "img3", Dependencies: []*latestV1.ArtifactDependency{{ImageName: "img4"}}}, + g := map[string]*latest.Artifact{ + "img1": {ImageName: "img1", Dependencies: []*latest.ArtifactDependency{{ImageName: "img2"}}}, + "img2": {ImageName: "img2", Dependencies: []*latest.ArtifactDependency{{ImageName: "img3"}, {ImageName: "img4"}}}, + "img3": {ImageName: "img3", Dependencies: []*latest.ArtifactDependency{{ImageName: "img4"}}}, "img4": {ImageName: "img4"}, } deps := map[string][]string{ @@ -43,7 +43,7 @@ func TestSourceDependenciesCache(t *testing.T) { "img4": {"file41", "file42"}, } counts := map[string]int{"img1": 0, "img2": 0, "img3": 0, "img4": 0} - t.Override(&getDependenciesFunc, func(_ context.Context, a *latestV1.Artifact, _ docker.Config, _ docker.ArtifactResolver) ([]string, error) { + t.Override(&getDependenciesFunc, func(_ context.Context, a *latest.Artifact, _ docker.Config, _ docker.ArtifactResolver) ([]string, error) { counts[a.ImageName]++ return deps[a.ImageName], nil }) @@ -68,16 +68,16 @@ func TestSourceDependenciesForArtifact(t *testing.T) { ) tests := []struct { description string - artifact *latestV1.Artifact + artifact *latest.Artifact dockerConfig docker.Config dockerArtifactResolver docker.ArtifactResolver expectedPaths []string }{ { description: "ko default dependencies", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - KoArtifact: &latestV1.KoArtifact{}, + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + KoArtifact: &latest.KoArtifact{}, }, Workspace: tmpDir.Root(), }, diff --git a/pkg/skaffold/hooks/build.go b/pkg/skaffold/hooks/build.go index 594238149f9..3482d124529 100644 --- a/pkg/skaffold/hooks/build.go +++ b/pkg/skaffold/hooks/build.go @@ -24,16 +24,16 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // BuildRunner creates a new runner for pre-build and post-build lifecycle hooks -func BuildRunner(d v1.BuildHooks, opts BuildEnvOpts) Runner { +func BuildRunner(d latest.BuildHooks, opts BuildEnvOpts) Runner { return buildRunner{BuildHooks: d, opts: opts} } // NewBuildEnvOpts returns `BuildEnvOpts` required to create a `Runner` for build lifecycle hooks -func NewBuildEnvOpts(a *v1.Artifact, image string, pushImage bool) (BuildEnvOpts, error) { +func NewBuildEnvOpts(a *latest.Artifact, image string, pushImage bool) (BuildEnvOpts, error) { ref, err := docker.ParseReference(image) if err != nil { return BuildEnvOpts{}, fmt.Errorf("parsing image %v: %w", image, err) @@ -53,7 +53,7 @@ func NewBuildEnvOpts(a *v1.Artifact, image string, pushImage bool) (BuildEnvOpts } type buildRunner struct { - v1.BuildHooks + latest.BuildHooks opts BuildEnvOpts } @@ -71,7 +71,7 @@ func (r buildRunner) getEnv() []string { return append(common, build...) } -func (r buildRunner) run(ctx context.Context, out io.Writer, hooks []v1.HostHook, phase phase) error { +func (r buildRunner) run(ctx context.Context, out io.Writer, hooks []latest.HostHook, phase phase) error { if len(hooks) > 0 { output.Default.Fprintln(out, fmt.Sprintf("Starting %s hooks...", phase)) } diff --git a/pkg/skaffold/hooks/build_test.go b/pkg/skaffold/hooks/build_test.go index 7f2fad50455..00905d9abf5 100644 --- a/pkg/skaffold/hooks/build_test.go +++ b/pkg/skaffold/hooks/build_test.go @@ -24,7 +24,7 @@ import ( "runtime" "testing" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -32,7 +32,7 @@ func TestBuildHooks(t *testing.T) { workDir, _ := filepath.Abs("./foo") tests := []struct { description string - artifact v1.Artifact + artifact latest.Artifact image string pushImage bool requiresWindowsOS bool @@ -41,17 +41,17 @@ func TestBuildHooks(t *testing.T) { }{ { description: "linux/darwin build hook on matching host", - artifact: v1.Artifact{ + artifact: latest.Artifact{ ImageName: "img1", Workspace: "./foo", - LifecycleHooks: v1.BuildHooks{ - PreHooks: []v1.HostHook{ + LifecycleHooks: latest.BuildHooks{ + PreHooks: []latest.HostHook{ { OS: []string{"linux", "darwin"}, Command: []string{"sh", "-c", "echo pre-hook running with SKAFFOLD_IMAGE=$SKAFFOLD_IMAGE,SKAFFOLD_PUSH_IMAGE=$SKAFFOLD_PUSH_IMAGE,SKAFFOLD_IMAGE_REPO=$SKAFFOLD_IMAGE_REPO,SKAFFOLD_IMAGE_TAG=$SKAFFOLD_IMAGE_TAG,SKAFFOLD_BUILD_CONTEXT=$SKAFFOLD_BUILD_CONTEXT"}, }, }, - PostHooks: []v1.HostHook{ + PostHooks: []latest.HostHook{ { OS: []string{"linux", "darwin"}, Command: []string{"sh", "-c", "echo post-hook running with SKAFFOLD_IMAGE=$SKAFFOLD_IMAGE,SKAFFOLD_PUSH_IMAGE=$SKAFFOLD_PUSH_IMAGE,SKAFFOLD_IMAGE_REPO=$SKAFFOLD_IMAGE_REPO,SKAFFOLD_IMAGE_TAG=$SKAFFOLD_IMAGE_TAG,SKAFFOLD_BUILD_CONTEXT=$SKAFFOLD_BUILD_CONTEXT"}, @@ -67,17 +67,17 @@ func TestBuildHooks(t *testing.T) { { description: "linux/darwin build hook on non-matching host", requiresWindowsOS: true, - artifact: v1.Artifact{ + artifact: latest.Artifact{ ImageName: "img1", Workspace: "./foo", - LifecycleHooks: v1.BuildHooks{ - PreHooks: []v1.HostHook{ + LifecycleHooks: latest.BuildHooks{ + PreHooks: []latest.HostHook{ { OS: []string{"linux", "darwin"}, Command: []string{"sh", "-c", "echo pre-hook running with SKAFFOLD_IMAGE=$SKAFFOLD_IMAGE,SKAFFOLD_PUSH_IMAGE=$SKAFFOLD_PUSH_IMAGE,SKAFFOLD_IMAGE_REPO=$SKAFFOLD_IMAGE_REPO,SKAFFOLD_IMAGE_TAG=$SKAFFOLD_IMAGE_TAG,SKAFFOLD_BUILD_CONTEXT=$SKAFFOLD_BUILD_CONTEXT"}, }, }, - PostHooks: []v1.HostHook{ + PostHooks: []latest.HostHook{ { OS: []string{"linux", "darwin"}, Command: []string{"sh", "-c", "echo post-hook running with SKAFFOLD_IMAGE=$SKAFFOLD_IMAGE,SKAFFOLD_PUSH_IMAGE=$SKAFFOLD_PUSH_IMAGE,SKAFFOLD_IMAGE_REPO=$SKAFFOLD_IMAGE_REPO,SKAFFOLD_IMAGE_TAG=$SKAFFOLD_IMAGE_TAG,SKAFFOLD_BUILD_CONTEXT=$SKAFFOLD_BUILD_CONTEXT"}, @@ -91,17 +91,17 @@ func TestBuildHooks(t *testing.T) { { description: "windows build hook on matching host", requiresWindowsOS: true, - artifact: v1.Artifact{ + artifact: latest.Artifact{ ImageName: "img1", Workspace: "./foo", - LifecycleHooks: v1.BuildHooks{ - PreHooks: []v1.HostHook{ + LifecycleHooks: latest.BuildHooks{ + PreHooks: []latest.HostHook{ { OS: []string{"windows"}, Command: []string{"cmd.exe", "/C", "echo pre-hook running with SKAFFOLD_IMAGE=%SKAFFOLD_IMAGE%,SKAFFOLD_PUSH_IMAGE=%SKAFFOLD_PUSH_IMAGE%,SKAFFOLD_IMAGE_REPO=%SKAFFOLD_IMAGE_REPO%,SKAFFOLD_IMAGE_TAG=%SKAFFOLD_IMAGE_TAG%,SKAFFOLD_BUILD_CONTEXT=%SKAFFOLD_BUILD_CONTEXT%"}, }, }, - PostHooks: []v1.HostHook{ + PostHooks: []latest.HostHook{ { OS: []string{"windows"}, Command: []string{"cmd.exe", "/C", "echo post-hook running with SKAFFOLD_IMAGE=%SKAFFOLD_IMAGE%,SKAFFOLD_PUSH_IMAGE=%SKAFFOLD_PUSH_IMAGE%,SKAFFOLD_IMAGE_REPO=%SKAFFOLD_IMAGE_REPO%,SKAFFOLD_IMAGE_TAG=%SKAFFOLD_IMAGE_TAG%,SKAFFOLD_BUILD_CONTEXT=%SKAFFOLD_BUILD_CONTEXT%"}, @@ -116,17 +116,17 @@ func TestBuildHooks(t *testing.T) { }, { description: "windows build hook on non-matching host", - artifact: v1.Artifact{ + artifact: latest.Artifact{ ImageName: "img1", Workspace: "./foo", - LifecycleHooks: v1.BuildHooks{ - PreHooks: []v1.HostHook{ + LifecycleHooks: latest.BuildHooks{ + PreHooks: []latest.HostHook{ { OS: []string{"windows"}, Command: []string{"cmd.exe", "/C", "echo pre-hook running with SKAFFOLD_IMAGE=%SKAFFOLD_IMAGE%,SKAFFOLD_PUSH_IMAGE=%SKAFFOLD_PUSH_IMAGE%,SKAFFOLD_IMAGE_REPO=%SKAFFOLD_IMAGE_REPO%,SKAFFOLD_IMAGE_TAG=%SKAFFOLD_IMAGE_TAG%,SKAFFOLD_BUILD_CONTEXT=%SKAFFOLD_BUILD_CONTEXT%"}, }, }, - PostHooks: []v1.HostHook{ + PostHooks: []latest.HostHook{ { OS: []string{"windows"}, Command: []string{"cmd.exe", "/C", "echo post-hook running with SKAFFOLD_IMAGE=%SKAFFOLD_IMAGE%,SKAFFOLD_PUSH_IMAGE=%SKAFFOLD_PUSH_IMAGE%,SKAFFOLD_IMAGE_REPO=%SKAFFOLD_IMAGE_REPO%,SKAFFOLD_IMAGE_TAG=%SKAFFOLD_IMAGE_TAG%,SKAFFOLD_BUILD_CONTEXT=%SKAFFOLD_BUILD_CONTEXT%"}, diff --git a/pkg/skaffold/hooks/container.go b/pkg/skaffold/hooks/container.go index a20238a7b0d..e7b05ee41b5 100644 --- a/pkg/skaffold/hooks/container.go +++ b/pkg/skaffold/hooks/container.go @@ -30,7 +30,7 @@ import ( kubernetesclient "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/logger" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/log/stream" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -81,7 +81,7 @@ func namePatternSelector(podName, containerName string) containerSelector { // containerHook represents a lifecycle hook to be executed inside a running container type containerHook struct { - cfg latestV1.ContainerHook + cfg latest.ContainerHook cli *kubectl.CLI selector containerSelector namespaces []string diff --git a/pkg/skaffold/hooks/container_test.go b/pkg/skaffold/hooks/container_test.go index 1a49807dcd1..0061d334db5 100644 --- a/pkg/skaffold/hooks/container_test.go +++ b/pkg/skaffold/hooks/container_test.go @@ -31,7 +31,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl" kubernetesclient "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/log" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -41,7 +41,7 @@ func TestContainerRun(t *testing.T) { description string objects []runtime.Object cmd *testutil.FakeCmd - hook v1.ContainerHook + hook latest.ContainerHook kubeContext string selector containerSelector namespaces []string @@ -55,7 +55,7 @@ func TestContainerRun(t *testing.T) { createPodObject("gcr.io/foo/img2:latest", "pod2", "container2", "np2"), }, cmd: testutil.CmdRunWithOutput("kubectl --context context1 exec pod1 --namespace np1 -c container1 -- foo hook", "hook success"), - hook: v1.ContainerHook{Command: []string{"foo", "hook"}}, + hook: latest.ContainerHook{Command: []string{"foo", "hook"}}, kubeContext: "context1", selector: runningImageSelector("gcr.io/foo/img1:latest"), namespaces: []string{"np1", "np2"}, @@ -66,7 +66,7 @@ func TestContainerRun(t *testing.T) { objects: []runtime.Object{ createPodObject("gcr.io/foo/img2:latest", "pod1", "container1", "np1"), }, - hook: v1.ContainerHook{Command: []string{"foo", "hook"}}, + hook: latest.ContainerHook{Command: []string{"foo", "hook"}}, kubeContext: "context1", selector: runningImageSelector("gcr.io/foo/img1:latest"), namespaces: []string{"np1", "np2"}, @@ -76,7 +76,7 @@ func TestContainerRun(t *testing.T) { objects: []runtime.Object{ createPodObject("gcr.io/foo/img1:latest", "pod1", "container1", "np3"), }, - hook: v1.ContainerHook{Command: []string{"foo", "hook"}}, + hook: latest.ContainerHook{Command: []string{"foo", "hook"}}, kubeContext: "context1", selector: runningImageSelector("gcr.io/foo/img1:latest"), namespaces: []string{"np1", "np2"}, @@ -87,7 +87,7 @@ func TestContainerRun(t *testing.T) { createPodObject("gcr.io/foo/img1:latest", "pod1", "container1", "np1"), }, cmd: testutil.CmdRunErr("kubectl --context context1 exec pod1 --namespace np1 -c container1 -- foo hook", errors.New("error")), - hook: v1.ContainerHook{Command: []string{"foo", "hook"}}, + hook: latest.ContainerHook{Command: []string{"foo", "hook"}}, kubeContext: "context1", selector: runningImageSelector("gcr.io/foo/img1:latest"), namespaces: []string{"np1", "np2"}, diff --git a/pkg/skaffold/hooks/deploy.go b/pkg/skaffold/hooks/deploy.go index 19d107c95c8..0a8760e3fbe 100644 --- a/pkg/skaffold/hooks/deploy.go +++ b/pkg/skaffold/hooks/deploy.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/logger" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // for testing @@ -36,7 +36,7 @@ var ( NewDeployRunner = newDeployRunner ) -func newDeployRunner(cli *kubectl.CLI, d v1.DeployHooks, namespaces *[]string, formatter logger.Formatter, opts DeployEnvOpts) Runner { +func newDeployRunner(cli *kubectl.CLI, d latest.DeployHooks, namespaces *[]string, formatter logger.Formatter, opts DeployEnvOpts) Runner { return deployRunner{d, cli, namespaces, formatter, opts, new(sync.Map)} } @@ -49,7 +49,7 @@ func NewDeployEnvOpts(runID string, kubeContext string, namespaces []string) Dep } type deployRunner struct { - v1.DeployHooks + latest.DeployHooks cli *kubectl.CLI namespaces *[]string formatter logger.Formatter @@ -71,7 +71,7 @@ func (r deployRunner) getEnv() []string { return append(common, deploy...) } -func (r deployRunner) run(ctx context.Context, out io.Writer, hooks []v1.DeployHookItem, phase phase) error { +func (r deployRunner) run(ctx context.Context, out io.Writer, hooks []latest.DeployHookItem, phase phase) error { if len(hooks) > 0 { output.Default.Fprintln(out, fmt.Sprintf("Starting %s hooks...", phase)) } @@ -84,7 +84,7 @@ func (r deployRunner) run(ctx context.Context, out io.Writer, hooks []v1.DeployH } } else if h.ContainerHook != nil { hook := containerHook{ - cfg: v1.ContainerHook{Command: h.ContainerHook.Command}, + cfg: latest.ContainerHook{Command: h.ContainerHook.Command}, cli: r.cli, selector: filterPodsSelector(r.visitedPods, phase, namePatternSelector(h.ContainerHook.PodName, h.ContainerHook.ContainerName)), namespaces: *r.namespaces, diff --git a/pkg/skaffold/hooks/deploy_test.go b/pkg/skaffold/hooks/deploy_test.go index 0f574280357..5a181a7cac4 100644 --- a/pkg/skaffold/hooks/deploy_test.go +++ b/pkg/skaffold/hooks/deploy_test.go @@ -27,30 +27,30 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl" kubernetesclient "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/log" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) func TestDeployHooks(t *testing.T) { testutil.Run(t, "TestDeployHooks", func(t *testutil.T) { - hooks := v1.DeployHooks{ - PreHooks: []v1.DeployHookItem{ + hooks := latest.DeployHooks{ + PreHooks: []latest.DeployHookItem{ { - HostHook: &v1.HostHook{ + HostHook: &latest.HostHook{ OS: []string{"linux", "darwin"}, Command: []string{"sh", "-c", "echo pre-hook running with SKAFFOLD_RUN_ID=$SKAFFOLD_RUN_ID,SKAFFOLD_KUBE_CONTEXT=$SKAFFOLD_KUBE_CONTEXT,SKAFFOLD_NAMESPACES=$SKAFFOLD_NAMESPACES"}, }, }, { - HostHook: &v1.HostHook{ + HostHook: &latest.HostHook{ OS: []string{"windows"}, Command: []string{"cmd.exe", "/C", "echo pre-hook running with SKAFFOLD_RUN_ID=%SKAFFOLD_RUN_ID%,SKAFFOLD_KUBE_CONTEXT=%SKAFFOLD_KUBE_CONTEXT%,SKAFFOLD_NAMESPACES=%SKAFFOLD_NAMESPACES%"}, }, }, { - ContainerHook: &v1.NamedContainerHook{ - ContainerHook: v1.ContainerHook{ + ContainerHook: &latest.NamedContainerHook{ + ContainerHook: latest.ContainerHook{ Command: []string{"foo", "pre-hook"}, }, PodName: "pod1", @@ -58,22 +58,22 @@ func TestDeployHooks(t *testing.T) { }, }, }, - PostHooks: []v1.DeployHookItem{ + PostHooks: []latest.DeployHookItem{ { - HostHook: &v1.HostHook{ + HostHook: &latest.HostHook{ OS: []string{"linux", "darwin"}, Command: []string{"sh", "-c", "echo post-hook running with SKAFFOLD_RUN_ID=$SKAFFOLD_RUN_ID,SKAFFOLD_KUBE_CONTEXT=$SKAFFOLD_KUBE_CONTEXT,SKAFFOLD_NAMESPACES=$SKAFFOLD_NAMESPACES"}, }, }, { - HostHook: &v1.HostHook{ + HostHook: &latest.HostHook{ OS: []string{"windows"}, Command: []string{"cmd.exe", "/C", "echo post-hook running with SKAFFOLD_RUN_ID=%SKAFFOLD_RUN_ID%,SKAFFOLD_KUBE_CONTEXT=%SKAFFOLD_KUBE_CONTEXT%,SKAFFOLD_NAMESPACES=%SKAFFOLD_NAMESPACES%"}, }, }, { - ContainerHook: &v1.NamedContainerHook{ - ContainerHook: v1.ContainerHook{ + ContainerHook: &latest.NamedContainerHook{ + ContainerHook: latest.ContainerHook{ Command: []string{"foo", "post-hook"}, }, PodName: "pod1", @@ -87,7 +87,7 @@ func TestDeployHooks(t *testing.T) { postHostHookOut := "post-hook running with SKAFFOLD_RUN_ID=run_id,SKAFFOLD_KUBE_CONTEXT=context1,SKAFFOLD_NAMESPACES=np1,np2" postContainerHookOut := "container post-hook succeeded" - deployer := v1.KubectlDeploy{ + deployer := latest.KubectlDeploy{ LifecycleHooks: hooks, } namespaces := []string{"np1", "np2"} diff --git a/pkg/skaffold/hooks/host.go b/pkg/skaffold/hooks/host.go index 7338c8b871c..e66709b52c7 100644 --- a/pkg/skaffold/hooks/host.go +++ b/pkg/skaffold/hooks/host.go @@ -26,14 +26,14 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/misc" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" ) // hostHook represents a lifecycle hook to be executed on the host machine type hostHook struct { - cfg v1.HostHook + cfg latest.HostHook env []string // environment variables to set in the hook process } diff --git a/pkg/skaffold/hooks/host_test.go b/pkg/skaffold/hooks/host_test.go index 7e9cc98f770..e6879bb02f9 100644 --- a/pkg/skaffold/hooks/host_test.go +++ b/pkg/skaffold/hooks/host_test.go @@ -22,7 +22,7 @@ import ( "runtime" "testing" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -36,7 +36,7 @@ func TestRun(t *testing.T) { { description: "linux/darwin host hook on matching host", hook: hostHook{ - cfg: v1.HostHook{ + cfg: latest.HostHook{ OS: []string{"linux", "darwin"}, Command: []string{"sh", "-c", "echo FOO=$FOO"}, }, @@ -47,7 +47,7 @@ func TestRun(t *testing.T) { { description: "windows host hook on non-matching host", hook: hostHook{ - cfg: v1.HostHook{ + cfg: latest.HostHook{ OS: []string{"windows"}, Command: []string{"cmd.exe", "/C", "echo FOO=%FOO%"}, }, @@ -58,7 +58,7 @@ func TestRun(t *testing.T) { description: "linux/darwin host hook on non-matching host", requiresWindowsOS: true, hook: hostHook{ - cfg: v1.HostHook{ + cfg: latest.HostHook{ OS: []string{"linux", "darwin"}, Command: []string{"sh", "-c", "echo FOO=$FOO"}, }, @@ -69,7 +69,7 @@ func TestRun(t *testing.T) { description: "windows host hook on matching host", requiresWindowsOS: true, hook: hostHook{ - cfg: v1.HostHook{ + cfg: latest.HostHook{ OS: []string{"windows"}, Command: []string{"cmd.exe", "/C", "echo FOO=%FOO%"}, }, diff --git a/pkg/skaffold/hooks/sync.go b/pkg/skaffold/hooks/sync.go index 0519a8a44d9..25f800bb6c6 100644 --- a/pkg/skaffold/hooks/sync.go +++ b/pkg/skaffold/hooks/sync.go @@ -26,15 +26,15 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/logger" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) -func NewSyncRunner(cli *kubectl.CLI, imageName, imageRef string, namespaces []string, formatter logger.Formatter, d v1.SyncHooks, opts SyncEnvOpts) Runner { +func NewSyncRunner(cli *kubectl.CLI, imageName, imageRef string, namespaces []string, formatter logger.Formatter, d latest.SyncHooks, opts SyncEnvOpts) Runner { return syncRunner{d, cli, imageName, imageRef, namespaces, formatter, opts} } -func NewSyncEnvOpts(a *v1.Artifact, image string, addOrModifyFiles []string, deleteFiles []string, namespaces []string, kubeContext string) (SyncEnvOpts, error) { +func NewSyncEnvOpts(a *latest.Artifact, image string, addOrModifyFiles []string, deleteFiles []string, namespaces []string, kubeContext string) (SyncEnvOpts, error) { workDir, err := filepath.Abs(a.Workspace) if err != nil { return SyncEnvOpts{}, fmt.Errorf("determining build workspace directory for image %v: %w", a.ImageName, err) @@ -50,7 +50,7 @@ func NewSyncEnvOpts(a *v1.Artifact, image string, addOrModifyFiles []string, del } type syncRunner struct { - v1.SyncHooks + latest.SyncHooks cli *kubectl.CLI imageName string imageRef string @@ -73,7 +73,7 @@ func (r syncRunner) getEnv() []string { return append(common, sync...) } -func (r syncRunner) run(ctx context.Context, out io.Writer, hooks []v1.SyncHookItem, phase phase) error { +func (r syncRunner) run(ctx context.Context, out io.Writer, hooks []latest.SyncHookItem, phase phase) error { if len(hooks) > 0 { output.Default.Fprintf(out, "Starting %s hooks for artifact %q...\n", phase, r.imageName) } diff --git a/pkg/skaffold/hooks/sync_test.go b/pkg/skaffold/hooks/sync_test.go index c8df7b97fab..14351c4ab34 100644 --- a/pkg/skaffold/hooks/sync_test.go +++ b/pkg/skaffold/hooks/sync_test.go @@ -33,7 +33,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl" kubernetesclient "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/log" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -41,41 +41,41 @@ import ( func TestSyncHooks(t *testing.T) { testutil.Run(t, "TestSyncHooks", func(t *testutil.T) { workDir, _ := filepath.Abs("./foo") - hooks := v1.SyncHooks{ - PreHooks: []v1.SyncHookItem{ + hooks := latest.SyncHooks{ + PreHooks: []latest.SyncHookItem{ { - HostHook: &v1.HostHook{ + HostHook: &latest.HostHook{ OS: []string{"linux", "darwin"}, Command: []string{"sh", "-c", "echo pre-hook running with SKAFFOLD_IMAGE=$SKAFFOLD_IMAGE,SKAFFOLD_BUILD_CONTEXT=$SKAFFOLD_BUILD_CONTEXT,SKAFFOLD_FILES_ADDED_OR_MODIFIED=$SKAFFOLD_FILES_ADDED_OR_MODIFIED,SKAFFOLD_FILES_DELETED=$SKAFFOLD_FILES_DELETED,SKAFFOLD_KUBE_CONTEXT=$SKAFFOLD_KUBE_CONTEXT,SKAFFOLD_NAMESPACES=$SKAFFOLD_NAMESPACES"}, }, }, { - HostHook: &v1.HostHook{ + HostHook: &latest.HostHook{ OS: []string{"windows"}, Command: []string{"cmd.exe", "/C", "echo pre-hook running with SKAFFOLD_IMAGE=%SKAFFOLD_IMAGE%,SKAFFOLD_BUILD_CONTEXT=%SKAFFOLD_BUILD_CONTEXT%,SKAFFOLD_FILES_ADDED_OR_MODIFIED=%SKAFFOLD_FILES_ADDED_OR_MODIFIED%,SKAFFOLD_FILES_DELETED=%SKAFFOLD_FILES_DELETED%,SKAFFOLD_KUBE_CONTEXT=%SKAFFOLD_KUBE_CONTEXT%,SKAFFOLD_NAMESPACES=%SKAFFOLD_NAMESPACES%"}, }, }, { - ContainerHook: &v1.ContainerHook{ + ContainerHook: &latest.ContainerHook{ Command: []string{"foo", "pre-hook"}, }, }, }, - PostHooks: []v1.SyncHookItem{ + PostHooks: []latest.SyncHookItem{ { - HostHook: &v1.HostHook{ + HostHook: &latest.HostHook{ OS: []string{"linux", "darwin"}, Command: []string{"sh", "-c", "echo post-hook running with SKAFFOLD_IMAGE=$SKAFFOLD_IMAGE,SKAFFOLD_BUILD_CONTEXT=$SKAFFOLD_BUILD_CONTEXT,SKAFFOLD_FILES_ADDED_OR_MODIFIED=$SKAFFOLD_FILES_ADDED_OR_MODIFIED,SKAFFOLD_FILES_DELETED=$SKAFFOLD_FILES_DELETED,SKAFFOLD_KUBE_CONTEXT=$SKAFFOLD_KUBE_CONTEXT,SKAFFOLD_NAMESPACES=$SKAFFOLD_NAMESPACES"}, }, }, { - HostHook: &v1.HostHook{ + HostHook: &latest.HostHook{ OS: []string{"windows"}, Command: []string{"cmd.exe", "/C", "echo post-hook running with SKAFFOLD_IMAGE=%SKAFFOLD_IMAGE%,SKAFFOLD_BUILD_CONTEXT=%SKAFFOLD_BUILD_CONTEXT%,SKAFFOLD_FILES_ADDED_OR_MODIFIED=%SKAFFOLD_FILES_ADDED_OR_MODIFIED%,SKAFFOLD_FILES_DELETED=%SKAFFOLD_FILES_DELETED%,SKAFFOLD_KUBE_CONTEXT=%SKAFFOLD_KUBE_CONTEXT%,SKAFFOLD_NAMESPACES=%SKAFFOLD_NAMESPACES%"}, }, }, { - ContainerHook: &v1.ContainerHook{ + ContainerHook: &latest.ContainerHook{ Command: []string{"foo", "post-hook"}, }, }, @@ -86,10 +86,10 @@ func TestSyncHooks(t *testing.T) { postHostHookOut := fmt.Sprintf("post-hook running with SKAFFOLD_IMAGE=gcr.io/foo/img1:latest,SKAFFOLD_BUILD_CONTEXT=%s,SKAFFOLD_FILES_ADDED_OR_MODIFIED=foo1;bar1,SKAFFOLD_FILES_DELETED=foo2;bar2,SKAFFOLD_KUBE_CONTEXT=context1,SKAFFOLD_NAMESPACES=np1,np2", workDir) postContainerHookOut := "container post-hook succeeded" - artifact := &v1.Artifact{ + artifact := &latest.Artifact{ ImageName: "img1", Workspace: workDir, - Sync: &v1.Sync{ + Sync: &latest.Sync{ LifecycleHooks: hooks, }, } diff --git a/pkg/skaffold/initializer/build/builders.go b/pkg/skaffold/initializer/build/builders.go index 29ff97b4829..c8c25cd57f0 100644 --- a/pkg/skaffold/initializer/build/builders.go +++ b/pkg/skaffold/initializer/build/builders.go @@ -20,7 +20,7 @@ import ( "io" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/config" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // NoBuilder allows users to specify they don't want to build @@ -38,7 +38,7 @@ type InitBuilder interface { // ArtifactType returns the type of the artifact to be built. Paths should be relative to the workspace. // To make skaffold.yaml more portable across OS-es we should always generate /-delimited filepaths. - ArtifactType(workspace string) latestV1.ArtifactType + ArtifactType(workspace string) latest.ArtifactType // ConfiguredImage returns the target image configured by the builder, or an empty string if no image is configured. // This should be a cheap operation. @@ -60,8 +60,8 @@ func (b NoneBuilder) Describe() string { return "" } -func (b NoneBuilder) ArtifactType(string) latestV1.ArtifactType { - return latestV1.ArtifactType{} +func (b NoneBuilder) ArtifactType(string) latest.ArtifactType { + return latest.ArtifactType{} } func (b NoneBuilder) ConfiguredImage() string { @@ -97,7 +97,7 @@ type Initializer interface { // contained in the initializer with the provided images from the deploy initializer ProcessImages([]string) error // BuildConfig returns the processed build config to be written to the skaffold.yaml - BuildConfig() (latestV1.BuildConfig, []*latestV1.PortForwardResource) + BuildConfig() (latest.BuildConfig, []*latest.PortForwardResource) // PrintAnalysis writes the project analysis to the provided out stream PrintAnalysis(io.Writer) error // GenerateManifests generates image names and manifests for all unresolved pairs @@ -111,8 +111,8 @@ func (e *emptyBuildInitializer) ProcessImages([]string) error { return nil } -func (e *emptyBuildInitializer) BuildConfig() (latestV1.BuildConfig, []*latestV1.PortForwardResource) { - return latestV1.BuildConfig{}, nil +func (e *emptyBuildInitializer) BuildConfig() (latest.BuildConfig, []*latest.PortForwardResource) { + return latest.BuildConfig{}, nil } func (e *emptyBuildInitializer) PrintAnalysis(io.Writer) error { diff --git a/pkg/skaffold/initializer/build/cli.go b/pkg/skaffold/initializer/build/cli.go index 5d129046aec..26e29f67110 100644 --- a/pkg/skaffold/initializer/build/cli.go +++ b/pkg/skaffold/initializer/build/cli.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/errors" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/generator" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) @@ -51,13 +51,13 @@ func (c *cliBuildInitializer) ProcessImages(images []string) error { return nil } -func (c *cliBuildInitializer) BuildConfig() (latestV1.BuildConfig, []*latestV1.PortForwardResource) { - pf := []*latestV1.PortForwardResource{} +func (c *cliBuildInitializer) BuildConfig() (latest.BuildConfig, []*latest.PortForwardResource) { + pf := []*latest.PortForwardResource{} for _, manifestInfo := range c.manifests { // Port value is set to 0 if user decides to not port forward service if manifestInfo.Port != 0 { - pf = append(pf, &latestV1.PortForwardResource{ + pf = append(pf, &latest.PortForwardResource{ Type: "service", Name: manifestInfo.Name, Port: util.FromInt(manifestInfo.Port), @@ -65,7 +65,7 @@ func (c *cliBuildInitializer) BuildConfig() (latestV1.BuildConfig, []*latestV1.P } } - return latestV1.BuildConfig{ + return latest.BuildConfig{ Artifacts: Artifacts(c.artifactInfos), }, pf } diff --git a/pkg/skaffold/initializer/build/init.go b/pkg/skaffold/initializer/build/init.go index 6efc4d280fa..de8ceb624d1 100644 --- a/pkg/skaffold/initializer/build/init.go +++ b/pkg/skaffold/initializer/build/init.go @@ -23,7 +23,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/errors" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/prompt" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/generator" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) @@ -55,13 +55,13 @@ func (d *defaultBuildInitializer) ProcessImages(images []string) error { return nil } -func (d *defaultBuildInitializer) BuildConfig() (latestV1.BuildConfig, []*latestV1.PortForwardResource) { - pf := []*latestV1.PortForwardResource{} +func (d *defaultBuildInitializer) BuildConfig() (latest.BuildConfig, []*latest.PortForwardResource) { + pf := []*latest.PortForwardResource{} for _, manifestInfo := range d.manifests { // Port value is set to 0 if user decides to not port forward service if manifestInfo.Port != 0 { - pf = append(pf, &latestV1.PortForwardResource{ + pf = append(pf, &latest.PortForwardResource{ Type: "service", Name: manifestInfo.Name, Port: util.FromInt(manifestInfo.Port), @@ -69,7 +69,7 @@ func (d *defaultBuildInitializer) BuildConfig() (latestV1.BuildConfig, []*latest } } - return latestV1.BuildConfig{ + return latest.BuildConfig{ Artifacts: Artifacts(d.artifactInfos), }, pf } diff --git a/pkg/skaffold/initializer/build/util.go b/pkg/skaffold/initializer/build/util.go index c2164298895..d9e82564bb4 100644 --- a/pkg/skaffold/initializer/build/util.go +++ b/pkg/skaffold/initializer/build/util.go @@ -19,7 +19,7 @@ package build import ( "path/filepath" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" tag "github.com/GoogleContainerTools/skaffold/pkg/skaffold/tag/util" ) @@ -60,9 +60,9 @@ func findExactlyOneMatchingBuilder(builderConfigs []InitBuilder, image string) i return matchingConfigIndex } -// Artifacts takes builder image pairs and workspaces and creates a list of latestV1.Artifacts from the data. -func Artifacts(artifactInfos []ArtifactInfo) []*latestV1.Artifact { - var artifacts []*latestV1.Artifact +// Artifacts takes builder image pairs and workspaces and creates a list of latest.Artifacts from the data. +func Artifacts(artifactInfos []ArtifactInfo) []*latest.Artifact { + var artifacts []*latest.Artifact for _, info := range artifactInfos { // Don't create artifact build config for "None" builder @@ -73,7 +73,7 @@ func Artifacts(artifactInfos []ArtifactInfo) []*latestV1.Artifact { if workspace == "" { workspace = filepath.Dir(info.Builder.Path()) } - artifact := &latestV1.Artifact{ + artifact := &latest.Artifact{ ImageName: info.ImageName, ArtifactType: info.Builder.ArtifactType(workspace), } diff --git a/pkg/skaffold/initializer/config.go b/pkg/skaffold/initializer/config.go index eca947efa21..30838911652 100644 --- a/pkg/skaffold/initializer/config.go +++ b/pkg/skaffold/initializer/config.go @@ -26,7 +26,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/build" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/deploy" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/warnings" ) @@ -35,7 +35,7 @@ var ( getWd = os.Getwd ) -func generateSkaffoldConfig(b build.Initializer, d deploy.Initializer) *latestV1.SkaffoldConfig { +func generateSkaffoldConfig(b build.Initializer, d deploy.Initializer) *latest.SkaffoldConfig { // if we're here, the user has no skaffold yaml so we need to generate one // if the user doesn't have any k8s yamls, generate one for each dockerfile log.Entry(context.TODO()).Info("generating skaffold config") @@ -48,13 +48,13 @@ func generateSkaffoldConfig(b build.Initializer, d deploy.Initializer) *latestV1 deploy, profiles := d.DeployConfig() build, portForward := b.BuildConfig() - return &latestV1.SkaffoldConfig{ - APIVersion: latestV1.Version, + return &latest.SkaffoldConfig{ + APIVersion: latest.Version, Kind: "Config", - Metadata: latestV1.Metadata{ + Metadata: latest.Metadata{ Name: name, }, - Pipeline: latestV1.Pipeline{ + Pipeline: latest.Pipeline{ Build: build, Deploy: deploy, PortForward: portForward, diff --git a/pkg/skaffold/initializer/config_test.go b/pkg/skaffold/initializer/config_test.go index 945699dafe3..defe805dc1e 100644 --- a/pkg/skaffold/initializer/config_test.go +++ b/pkg/skaffold/initializer/config_test.go @@ -24,16 +24,16 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/build" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) type stubDeploymentInitializer struct { - config latestV1.DeployConfig - profiles []latestV1.Profile + config latest.DeployConfig + profiles []latest.Profile } -func (s stubDeploymentInitializer) DeployConfig() (latestV1.DeployConfig, []latestV1.Profile) { +func (s stubDeploymentInitializer) DeployConfig() (latest.DeployConfig, []latest.Profile) { return s.config, s.profiles } @@ -61,8 +61,8 @@ func (s stubBuildInitializer) PrintAnalysis(io.Writer) error { panic("no sir") } -func (s stubBuildInitializer) BuildConfig() (latestV1.BuildConfig, []*latestV1.PortForwardResource) { - return latestV1.BuildConfig{ +func (s stubBuildInitializer) BuildConfig() (latest.BuildConfig, []*latest.PortForwardResource) { + return latest.BuildConfig{ Artifacts: build.Artifacts(s.artifactInfos), }, nil } @@ -74,25 +74,25 @@ func (s stubBuildInitializer) GenerateManifests(io.Writer, bool, bool) (map[buil func TestGenerateSkaffoldConfig(t *testing.T) { tests := []struct { name string - expectedSkaffoldConfig *latestV1.SkaffoldConfig - deployConfig latestV1.DeployConfig - profiles []latestV1.Profile + expectedSkaffoldConfig *latest.SkaffoldConfig + deployConfig latest.DeployConfig + profiles []latest.Profile builderConfigInfos []build.ArtifactInfo getWd func() (string, error) }{ { name: "empty", builderConfigInfos: []build.ArtifactInfo{}, - deployConfig: latestV1.DeployConfig{}, + deployConfig: latest.DeployConfig{}, getWd: func() (s string, err error) { return filepath.Join("rootDir", "testConfig"), nil }, - expectedSkaffoldConfig: &latestV1.SkaffoldConfig{ - APIVersion: latestV1.Version, + expectedSkaffoldConfig: &latest.SkaffoldConfig{ + APIVersion: latest.Version, Kind: "Config", - Metadata: latestV1.Metadata{Name: "testconfig"}, - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{}, + Metadata: latest.Metadata{Name: "testconfig"}, + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{}, }, }, }, @@ -106,41 +106,41 @@ func TestGenerateSkaffoldConfig(t *testing.T) { ImageName: "image1", }, }, - deployConfig: latestV1.DeployConfig{}, + deployConfig: latest.DeployConfig{}, getWd: func() (s string, err error) { return string(filepath.Separator), nil }, - expectedSkaffoldConfig: &latestV1.SkaffoldConfig{ - APIVersion: latestV1.Version, + expectedSkaffoldConfig: &latest.SkaffoldConfig{ + APIVersion: latest.Version, Kind: "Config", - Metadata: latestV1.Metadata{}, - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + Metadata: latest.Metadata{}, + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ { ImageName: "image1", Workspace: "testDir", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{DockerfilePath: "Dockerfile"}, + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{DockerfilePath: "Dockerfile"}, }, }, }, }, - Deploy: latestV1.DeployConfig{}, + Deploy: latest.DeployConfig{}, }, }, }, { name: "error working dir", builderConfigInfos: []build.ArtifactInfo{}, - deployConfig: latestV1.DeployConfig{}, + deployConfig: latest.DeployConfig{}, getWd: func() (s string, err error) { return "", errors.New("testError") }, - expectedSkaffoldConfig: &latestV1.SkaffoldConfig{ - APIVersion: latestV1.Version, + expectedSkaffoldConfig: &latest.SkaffoldConfig{ + APIVersion: latest.Version, Kind: "Config", - Metadata: latestV1.Metadata{}, + Metadata: latest.Metadata{}, }, }, } diff --git a/pkg/skaffold/initializer/deploy/init.go b/pkg/skaffold/initializer/deploy/init.go index cfcf6a6eee0..e7fed9fdba9 100644 --- a/pkg/skaffold/initializer/deploy/init.go +++ b/pkg/skaffold/initializer/deploy/init.go @@ -19,13 +19,13 @@ package deploy import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/errors" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // Initializer detects a deployment type and is able to extract image names from it type Initializer interface { // deployConfig generates Deploy Config for skaffold configuration. - DeployConfig() (latestV1.DeployConfig, []latestV1.Profile) + DeployConfig() (latest.DeployConfig, []latest.Profile) // GetImages fetches all the images defined in the manifest files. GetImages() []string // Validate ensures preconditions are met before generating a skaffold config @@ -38,10 +38,10 @@ type cliDeployInit struct { cliKubernetesManifests []string } -func (c *cliDeployInit) DeployConfig() (latestV1.DeployConfig, []latestV1.Profile) { - return latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{ +func (c *cliDeployInit) DeployConfig() (latest.DeployConfig, []latest.Profile) { + return latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{ Manifests: c.cliKubernetesManifests, }, }, @@ -64,8 +64,8 @@ func (c *cliDeployInit) AddManifestForImage(string, string) {} type emptyDeployInit struct { } -func (e *emptyDeployInit) DeployConfig() (latestV1.DeployConfig, []latestV1.Profile) { - return latestV1.DeployConfig{}, nil +func (e *emptyDeployInit) DeployConfig() (latest.DeployConfig, []latest.Profile) { + return latest.DeployConfig{}, nil } func (e *emptyDeployInit) GetImages() []string { diff --git a/pkg/skaffold/initializer/deploy/kubectl.go b/pkg/skaffold/initializer/deploy/kubectl.go index 47fd7970351..7c732e6b04b 100644 --- a/pkg/skaffold/initializer/deploy/kubectl.go +++ b/pkg/skaffold/initializer/deploy/kubectl.go @@ -19,7 +19,7 @@ package deploy import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/errors" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // kubectl implements deploymentInitializer for the kubectl deployer. @@ -46,10 +46,10 @@ func newKubectlInitializer(potentialConfigs []string) *kubectl { // deployConfig implements the Initializer interface and generates // skaffold kubectl deployment config. -func (k *kubectl) DeployConfig() (latestV1.DeployConfig, []latestV1.Profile) { - return latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{ +func (k *kubectl) DeployConfig() (latest.DeployConfig, []latest.Profile) { + return latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{ Manifests: k.configs, }, }, diff --git a/pkg/skaffold/initializer/deploy/kubectl_test.go b/pkg/skaffold/initializer/deploy/kubectl_test.go index 1cb2d51f304..311a44e1f6d 100644 --- a/pkg/skaffold/initializer/deploy/kubectl_test.go +++ b/pkg/skaffold/initializer/deploy/kubectl_test.go @@ -20,7 +20,7 @@ import ( "testing" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -40,9 +40,9 @@ spec: k := newKubectlInitializer([]string{filename}) - expectedConfig := latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{ + expectedConfig := latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{ Manifests: []string{filename}, }, }, diff --git a/pkg/skaffold/initializer/deploy/kustomize.go b/pkg/skaffold/initializer/deploy/kustomize.go index 2a2e2b1aedb..b3a3aa5f912 100644 --- a/pkg/skaffold/initializer/deploy/kustomize.go +++ b/pkg/skaffold/initializer/deploy/kustomize.go @@ -24,7 +24,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/errors" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // kustomize implements deploymentInitializer for the kustomize deployer. @@ -54,22 +54,22 @@ func newKustomizeInitializer(defaultKustomization string, bases, kustomizations, // deployConfig implements the Initializer interface and generates // a kustomize deployment config. -func (k *kustomize) DeployConfig() (latestV1.DeployConfig, []latestV1.Profile) { - var kustomizeConfig *latestV1.KustomizeDeploy - var profiles []latestV1.Profile +func (k *kustomize) DeployConfig() (latest.DeployConfig, []latest.Profile) { + var kustomizeConfig *latest.KustomizeDeploy + var profiles []latest.Profile // if there's only one kustomize path, either leave it blank (if it's the default path), // or generate a config with that single path and return it if len(k.kustomizations) == 1 { if k.kustomizations[0] == pkgkustomize.DefaultKustomizePath { - kustomizeConfig = &latestV1.KustomizeDeploy{} + kustomizeConfig = &latest.KustomizeDeploy{} } else { - kustomizeConfig = &latestV1.KustomizeDeploy{ + kustomizeConfig = &latest.KustomizeDeploy{ KustomizePaths: k.kustomizations, } } - return latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ + return latest.DeployConfig{ + DeployType: latest.DeployType{ KustomizeDeploy: kustomizeConfig, }, }, nil @@ -105,16 +105,16 @@ func (k *kustomize) DeployConfig() (latestV1.DeployConfig, []latestV1.Profile) { for _, kustomization := range k.kustomizations { if kustomization == defaultKustomization { - kustomizeConfig = &latestV1.KustomizeDeploy{ + kustomizeConfig = &latest.KustomizeDeploy{ KustomizePaths: []string{defaultKustomization}, } } else { - profiles = append(profiles, latestV1.Profile{ + profiles = append(profiles, latest.Profile{ Name: filepath.Base(kustomization), - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KustomizeDeploy: &latestV1.KustomizeDeploy{ + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KustomizeDeploy: &latest.KustomizeDeploy{ KustomizePaths: []string{kustomization}, }, }, @@ -124,8 +124,8 @@ func (k *kustomize) DeployConfig() (latestV1.DeployConfig, []latestV1.Profile) { } } - return latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ + return latest.DeployConfig{ + DeployType: latest.DeployType{ KustomizeDeploy: kustomizeConfig, }, }, profiles diff --git a/pkg/skaffold/initializer/deploy/kustomize_test.go b/pkg/skaffold/initializer/deploy/kustomize_test.go index 123517568b7..27f34f04e29 100644 --- a/pkg/skaffold/initializer/deploy/kustomize_test.go +++ b/pkg/skaffold/initializer/deploy/kustomize_test.go @@ -20,7 +20,7 @@ import ( "path/filepath" "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -71,18 +71,18 @@ func TestGenerateKustomizePipeline(t *testing.T) { base string baseKustomization string overlays []overlay - expectedConfig latestV1.SkaffoldConfig + expectedConfig latest.SkaffoldConfig }{ { description: "single overlay", base: baseDeployment, baseKustomization: baseKustomization, overlays: []overlay{{"dev", overlayDeployment, overlayKustomization}}, - expectedConfig: latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KustomizeDeploy: &latestV1.KustomizeDeploy{ + expectedConfig: latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KustomizeDeploy: &latest.KustomizeDeploy{ KustomizePaths: []string{filepath.Join("overlays", "dev")}, }, }, @@ -99,23 +99,23 @@ func TestGenerateKustomizePipeline(t *testing.T) { {"bar", overlayDeployment, overlayKustomization}, {"baz", overlayDeployment, overlayKustomization}, }, - expectedConfig: latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KustomizeDeploy: &latestV1.KustomizeDeploy{ + expectedConfig: latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KustomizeDeploy: &latest.KustomizeDeploy{ KustomizePaths: []string{filepath.Join("overlays", "foo")}, }, }, }, }, - Profiles: []latestV1.Profile{ + Profiles: []latest.Profile{ { Name: "bar", - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KustomizeDeploy: &latestV1.KustomizeDeploy{ + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KustomizeDeploy: &latest.KustomizeDeploy{ KustomizePaths: []string{filepath.Join("overlays", "bar")}, }, }, @@ -124,10 +124,10 @@ func TestGenerateKustomizePipeline(t *testing.T) { }, { Name: "baz", - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KustomizeDeploy: &latestV1.KustomizeDeploy{ + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KustomizeDeploy: &latest.KustomizeDeploy{ KustomizePaths: []string{filepath.Join("overlays", "baz")}, }, }, diff --git a/pkg/skaffold/initializer/init.go b/pkg/skaffold/initializer/init.go index 027fc369e15..cb61266d2e4 100644 --- a/pkg/skaffold/initializer/init.go +++ b/pkg/skaffold/initializer/init.go @@ -29,7 +29,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/deploy" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/prompt" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml" ) @@ -76,7 +76,7 @@ See https://skaffold.dev/docs/pipeline-stages/deployers/helm/ for a detailed gui // Initialize uses the information gathered by the analyzer to create a skaffold config and generate kubernetes manifests. // The returned map[string][]byte represents a mapping from generated config name to its respective manifest data held in a []byte -func Initialize(out io.Writer, c config.Config, a *analyze.ProjectAnalysis) (*latestV1.SkaffoldConfig, map[string][]byte, error) { +func Initialize(out io.Writer, c config.Config, a *analyze.ProjectAnalysis) (*latest.SkaffoldConfig, map[string][]byte, error) { deployInitializer := deploy.NewInitializer(a.Manifests(), a.KustomizeBases(), a.KustomizePaths(), c) images := deployInitializer.GetImages() @@ -118,7 +118,7 @@ func generateManifests(out io.Writer, c config.Config, bInitializer build.Initia } // WriteData takes the given skaffold config and k8s manifests and writes them out to a file or the given io.Writer -func WriteData(out io.Writer, c config.Config, newConfig *latestV1.SkaffoldConfig, newManifests map[string][]byte) error { +func WriteData(out io.Writer, c config.Config, newConfig *latest.SkaffoldConfig, newManifests map[string][]byte) error { pipeline, err := yaml.Marshal(newConfig) if err != nil { return err diff --git a/pkg/skaffold/initializer/prompt/prompt.go b/pkg/skaffold/initializer/prompt/prompt.go index d50c5df23ab..01ced5b9332 100644 --- a/pkg/skaffold/initializer/prompt/prompt.go +++ b/pkg/skaffold/initializer/prompt/prompt.go @@ -26,7 +26,7 @@ import ( "github.com/AlecAivazis/survey/v2" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/util" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // For testing @@ -121,7 +121,7 @@ func portForwardResource(out io.Writer, imageName string) (int, error) { // ConfirmInitOptions prompts the user to confirm that they are okay with what skaffold will do if they // run with the current config -func ConfirmInitOptions(out io.Writer, config *latestV1.SkaffoldConfig) (bool, error) { +func ConfirmInitOptions(out io.Writer, config *latest.SkaffoldConfig) (bool, error) { builders := strings.Join(util.ListBuilders(&config.Build), ",") deployers := strings.Join(util.ListDeployers(&config.Deploy), ",") diff --git a/pkg/skaffold/initializer/prompt/prompt_test.go b/pkg/skaffold/initializer/prompt/prompt_test.go index ae6aeb8e25d..700e2390586 100644 --- a/pkg/skaffold/initializer/prompt/prompt_test.go +++ b/pkg/skaffold/initializer/prompt/prompt_test.go @@ -23,35 +23,35 @@ import ( "github.com/AlecAivazis/survey/v2" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) func TestWriteSkaffoldConfig(t *testing.T) { tests := []struct { description string - config *latestV1.SkaffoldConfig + config *latest.SkaffoldConfig promptResponse bool expectedDone bool shouldErr bool }{ { description: "yes response", - config: &latestV1.SkaffoldConfig{}, + config: &latest.SkaffoldConfig{}, promptResponse: true, expectedDone: false, shouldErr: false, }, { description: "no response", - config: &latestV1.SkaffoldConfig{}, + config: &latest.SkaffoldConfig{}, promptResponse: false, expectedDone: true, shouldErr: false, }, { description: "error", - config: &latestV1.SkaffoldConfig{}, + config: &latest.SkaffoldConfig{}, promptResponse: false, expectedDone: true, shouldErr: true, @@ -126,28 +126,28 @@ func TestChooseBuilders(t *testing.T) { func TestPortForwardResource(t *testing.T) { tests := []struct { description string - config *latestV1.SkaffoldConfig + config *latest.SkaffoldConfig promptResponse string expected int shouldErr bool }{ { description: "valid response", - config: &latestV1.SkaffoldConfig{}, + config: &latest.SkaffoldConfig{}, promptResponse: "8080", expected: 8080, shouldErr: false, }, { description: "empty response", - config: &latestV1.SkaffoldConfig{}, + config: &latest.SkaffoldConfig{}, promptResponse: "", expected: 0, shouldErr: false, }, { description: "error", - config: &latestV1.SkaffoldConfig{}, + config: &latest.SkaffoldConfig{}, promptResponse: "", expected: 0, shouldErr: true, @@ -174,28 +174,28 @@ func TestPortForwardResource(t *testing.T) { func TestConfirmInitOptions(t *testing.T) { tests := []struct { description string - config *latestV1.SkaffoldConfig + config *latest.SkaffoldConfig promptResponse bool expectedDone bool shouldErr bool }{ { description: "yes response", - config: &latestV1.SkaffoldConfig{}, + config: &latest.SkaffoldConfig{}, promptResponse: true, expectedDone: false, shouldErr: false, }, { description: "no response", - config: &latestV1.SkaffoldConfig{}, + config: &latest.SkaffoldConfig{}, promptResponse: false, expectedDone: true, shouldErr: false, }, { description: "error", - config: &latestV1.SkaffoldConfig{}, + config: &latest.SkaffoldConfig{}, promptResponse: false, expectedDone: true, shouldErr: true, diff --git a/pkg/skaffold/initializer/transparent.go b/pkg/skaffold/initializer/transparent.go index 31b85d063d5..f8d6811c9fe 100644 --- a/pkg/skaffold/initializer/transparent.go +++ b/pkg/skaffold/initializer/transparent.go @@ -23,7 +23,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" initConfig "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/prompt" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) var ( @@ -32,7 +32,7 @@ var ( // Transparent executes the `skaffold init` flow, but always enables the --force flag. // It will also always prompt the user to confirm at the end of the flow. -func Transparent(ctx context.Context, out io.Writer, c initConfig.Config) (*latestV1.SkaffoldConfig, error) { +func Transparent(ctx context.Context, out io.Writer, c initConfig.Config) (*latest.SkaffoldConfig, error) { // we set force to true because we want to have this happen invisibly to the user if possible c.Force = true diff --git a/pkg/skaffold/initializer/transparent_test.go b/pkg/skaffold/initializer/transparent_test.go index 031e6dae02e..7542d47f727 100644 --- a/pkg/skaffold/initializer/transparent_test.go +++ b/pkg/skaffold/initializer/transparent_test.go @@ -24,7 +24,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" initconfig "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/config" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -159,7 +159,7 @@ See https://skaffold.dev/docs/pipeline-stages/deployers/helm/ for a detailed gui testutil.Run(t, test.name, func(t *testutil.T) { t.Chdir(test.dir) - t.Override(&confirmInitOptions, func(_ io.Writer, _ *latestV1.SkaffoldConfig) (bool, error) { + t.Override(&confirmInitOptions, func(_ io.Writer, _ *latest.SkaffoldConfig) (bool, error) { return test.doneResponse, nil }) @@ -170,7 +170,7 @@ See https://skaffold.dev/docs/pipeline-stages/deployers/helm/ for a detailed gui t.CheckErrorContains(test.expectedError, err) t.CheckDeepEqual(exitCode(err), test.expectedExitCode) case test.doneResponse == true: - t.CheckErrorAndDeepEqual(false, err, (*latestV1.SkaffoldConfig)(nil), got) + t.CheckErrorAndDeepEqual(false, err, (*latest.SkaffoldConfig)(nil), got) default: t.CheckNoError(err) checkGeneratedConfig(t, ".") diff --git a/pkg/skaffold/initializer/util/util.go b/pkg/skaffold/initializer/util/util.go index c3f786b077b..ebcc2fa1ed2 100644 --- a/pkg/skaffold/initializer/util/util.go +++ b/pkg/skaffold/initializer/util/util.go @@ -18,13 +18,13 @@ package util import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/misc" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringset" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yamltags" ) // ListBuilders returns a list of builder names being used in the given build config. -func ListBuilders(build *latestV1.BuildConfig) []string { +func ListBuilders(build *latest.BuildConfig) []string { if build == nil { return []string{} } @@ -38,7 +38,7 @@ func ListBuilders(build *latestV1.BuildConfig) []string { } // ListDeployers returns a list of deployer names being used in the given deploy config. -func ListDeployers(deploy *latestV1.DeployConfig) []string { +func ListDeployers(deploy *latest.DeployConfig) []string { if deploy == nil { return []string{} } diff --git a/pkg/skaffold/initializer/util/util_test.go b/pkg/skaffold/initializer/util/util_test.go index d4ad8fbf842..a91cdf85c73 100644 --- a/pkg/skaffold/initializer/util/util_test.go +++ b/pkg/skaffold/initializer/util/util_test.go @@ -19,14 +19,14 @@ package util import ( "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) func TestListBuilders(t *testing.T) { tests := []struct { description string - build *latestV1.BuildConfig + build *latest.BuildConfig expected []string }{ { @@ -36,20 +36,20 @@ func TestListBuilders(t *testing.T) { }, { description: "multiple same builder config", - build: &latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ - {ImageName: "img1", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{}}}, - {ImageName: "img2", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{}}}, + build: &latest.BuildConfig{ + Artifacts: []*latest.Artifact{ + {ImageName: "img1", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, + {ImageName: "img2", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, }, }, expected: []string{"docker"}, }, { description: "different builders config", - build: &latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ - {ImageName: "img1", ArtifactType: latestV1.ArtifactType{DockerArtifact: &latestV1.DockerArtifact{}}}, - {ImageName: "img2", ArtifactType: latestV1.ArtifactType{JibArtifact: &latestV1.JibArtifact{}}}, + build: &latest.BuildConfig{ + Artifacts: []*latest.Artifact{ + {ImageName: "img1", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, + {ImageName: "img2", ArtifactType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{}}}, }, }, expected: []string{"docker", "jib"}, @@ -66,7 +66,7 @@ func TestListBuilders(t *testing.T) { func TestListDeployers(t *testing.T) { tests := []struct { description string - deploy *latestV1.DeployConfig + deploy *latest.DeployConfig expected []string }{ { @@ -76,19 +76,19 @@ func TestListDeployers(t *testing.T) { }, { description: "single deployer config", - deploy: &latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{}, + deploy: &latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{}, }, }, expected: []string{"kubectl"}, }, { description: "multiple deployers config", - deploy: &latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - HelmDeploy: &latestV1.HelmDeploy{}, - KubectlDeploy: &latestV1.KubectlDeploy{}, + deploy: &latest.DeployConfig{ + DeployType: latest.DeployType{ + HelmDeploy: &latest.HelmDeploy{}, + KubectlDeploy: &latest.KubectlDeploy{}, }, }, expected: []string{"helm", "kubectl"}, diff --git a/pkg/skaffold/inspect/buildEnv/add_cluster.go b/pkg/skaffold/inspect/buildEnv/add_cluster.go index 24dd97cec0d..13b1ec4b2f7 100644 --- a/pkg/skaffold/inspect/buildEnv/add_cluster.go +++ b/pkg/skaffold/inspect/buildEnv/add_cluster.go @@ -23,7 +23,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/inspect" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -45,7 +45,7 @@ func AddClusterBuildEnv(ctx context.Context, out io.Writer, opts inspect.Options // for these cases, don't add the new env definition to any configs imported as dependencies. cfgs = cfgs.SelectRootConfigs() for _, cfg := range cfgs { - if cfg.Build.Cluster != nil && !reflect.DeepEqual(cfg.Build.Cluster, &latestV1.ClusterDetails{}) { + if cfg.Build.Cluster != nil && !reflect.DeepEqual(cfg.Build.Cluster, &latest.ClusterDetails{}) { formatter.WriteErr(inspect.BuildEnvAlreadyExists(inspect.BuildEnvs.Cluster, cfg.SourceFile, "")) return err } @@ -64,9 +64,9 @@ func AddClusterBuildEnv(ctx context.Context, out io.Writer, opts inspect.Options } if index < 0 { index = len(cfg.Profiles) - cfg.Profiles = append(cfg.Profiles, latestV1.Profile{Name: opts.Profile}) + cfg.Profiles = append(cfg.Profiles, latest.Profile{Name: opts.Profile}) } - if cfg.Profiles[index].Build.Cluster != nil && !reflect.DeepEqual(cfg.Profiles[index].Build.Cluster, &latestV1.ClusterDetails{}) { + if cfg.Profiles[index].Build.Cluster != nil && !reflect.DeepEqual(cfg.Profiles[index].Build.Cluster, &latest.ClusterDetails{}) { formatter.WriteErr(inspect.BuildEnvAlreadyExists(inspect.BuildEnvs.Cluster, cfg.SourceFile, opts.Profile)) return err } @@ -80,8 +80,8 @@ func AddClusterBuildEnv(ctx context.Context, out io.Writer, opts inspect.Options return inspect.MarshalConfigSet(cfgs) } -func constructClusterDefinition(existing *latestV1.ClusterDetails, opts inspect.BuildEnvOptions) *latestV1.ClusterDetails { - var b latestV1.ClusterDetails +func constructClusterDefinition(existing *latest.ClusterDetails, opts inspect.BuildEnvOptions) *latest.ClusterDetails { + var b latest.ClusterDetails if existing != nil { b = *existing } @@ -99,13 +99,13 @@ func constructClusterDefinition(existing *latestV1.ClusterDetails, opts inspect. } if opts.DockerConfigPath != "" { if b.DockerConfig == nil { - b.DockerConfig = &latestV1.DockerConfig{} + b.DockerConfig = &latest.DockerConfig{} } b.DockerConfig.Path = opts.DockerConfigPath } if opts.DockerConfigSecretName != "" { if b.DockerConfig == nil { - b.DockerConfig = &latestV1.DockerConfig{} + b.DockerConfig = &latest.DockerConfig{} } b.DockerConfig.SecretName = opts.DockerConfigSecretName } diff --git a/pkg/skaffold/inspect/buildEnv/add_cluster_test.go b/pkg/skaffold/inspect/buildEnv/add_cluster_test.go index 2cda6a680bf..3985f83757a 100644 --- a/pkg/skaffold/inspect/buildEnv/add_cluster_test.go +++ b/pkg/skaffold/inspect/buildEnv/add_cluster_test.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/inspect" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser" sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/errors" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml" "github.com/GoogleContainerTools/skaffold/testutil" @@ -315,24 +315,24 @@ profiles: for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { configSet := parser.SkaffoldConfigSet{ - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: "cfg1_0"}, - Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{LocalBuild: &v1.LocalBuild{}}}}, - Profiles: []v1.Profile{ - {Name: "p1", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{Cluster: &v1.ClusterDetails{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: "cfg1_0"}, + Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}}}, + Profiles: []latest.Profile{ + {Name: "p1", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{Cluster: &latest.ClusterDetails{}}}}}, }}, SourceFile: pathToCfg1, IsRootConfig: true, SourceIndex: 0}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: "cfg1_1"}, - Dependencies: []v1.ConfigDependency{{Path: pathToCfg2}}, - Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{LocalBuild: &v1.LocalBuild{}}}}, - Profiles: []v1.Profile{ - {Name: "p1", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{Cluster: &v1.ClusterDetails{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: "cfg1_1"}, + Dependencies: []latest.ConfigDependency{{Path: pathToCfg2}}, + Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}}}, + Profiles: []latest.Profile{ + {Name: "p1", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{Cluster: &latest.ClusterDetails{}}}}}, }}, SourceFile: pathToCfg1, IsRootConfig: true, SourceIndex: 1}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: "cfg2"}, - Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{GoogleCloudBuild: &v1.GoogleCloudBuild{}}}}, - Profiles: []v1.Profile{ - {Name: "p1", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{LocalBuild: &v1.LocalBuild{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: "cfg2"}, + Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{GoogleCloudBuild: &latest.GoogleCloudBuild{}}}}, + Profiles: []latest.Profile{ + {Name: "p1", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}}}}, }}, SourceFile: pathToCfg2, SourceIndex: 0}, } t.Override(&inspect.GetConfigSet, func(ctx context.Context, opts config.SkaffoldOptions) (parser.SkaffoldConfigSet, error) { @@ -353,9 +353,9 @@ profiles: }) t.Override(&inspect.ReadFileFunc, func(filename string) ([]byte, error) { if filename == pathToCfg1 { - return yaml.MarshalWithSeparator([]*v1.SkaffoldConfig{configSet[0].SkaffoldConfig, configSet[1].SkaffoldConfig}) + return yaml.MarshalWithSeparator([]*latest.SkaffoldConfig{configSet[0].SkaffoldConfig, configSet[1].SkaffoldConfig}) } else if filename == pathToCfg2 { - return yaml.MarshalWithSeparator([]*v1.SkaffoldConfig{configSet[2].SkaffoldConfig}) + return yaml.MarshalWithSeparator([]*latest.SkaffoldConfig{configSet[2].SkaffoldConfig}) } t.FailNow() return nil, nil diff --git a/pkg/skaffold/inspect/buildEnv/add_gcb.go b/pkg/skaffold/inspect/buildEnv/add_gcb.go index 7f610321ea6..f3d77a24802 100644 --- a/pkg/skaffold/inspect/buildEnv/add_gcb.go +++ b/pkg/skaffold/inspect/buildEnv/add_gcb.go @@ -23,7 +23,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/inspect" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" ) @@ -45,7 +45,7 @@ func AddGcbBuildEnv(ctx context.Context, out io.Writer, opts inspect.Options) er // for these cases, don't add the new env definition to any configs imported as dependencies. cfgs = cfgs.SelectRootConfigs() for _, cfg := range cfgs { - if cfg.Build.GoogleCloudBuild != nil && (*cfg.Build.GoogleCloudBuild != latestV1.GoogleCloudBuild{}) { + if cfg.Build.GoogleCloudBuild != nil && (*cfg.Build.GoogleCloudBuild != latest.GoogleCloudBuild{}) { formatter.WriteErr(inspect.BuildEnvAlreadyExists(inspect.BuildEnvs.GoogleCloudBuild, cfg.SourceFile, "")) return err } @@ -64,9 +64,9 @@ func AddGcbBuildEnv(ctx context.Context, out io.Writer, opts inspect.Options) er } if index < 0 { index = len(cfg.Profiles) - cfg.Profiles = append(cfg.Profiles, latestV1.Profile{Name: opts.Profile}) + cfg.Profiles = append(cfg.Profiles, latest.Profile{Name: opts.Profile}) } - if cfg.Profiles[index].Build.GoogleCloudBuild != nil && (*cfg.Profiles[index].Build.GoogleCloudBuild != latestV1.GoogleCloudBuild{}) { + if cfg.Profiles[index].Build.GoogleCloudBuild != nil && (*cfg.Profiles[index].Build.GoogleCloudBuild != latest.GoogleCloudBuild{}) { formatter.WriteErr(inspect.BuildEnvAlreadyExists(inspect.BuildEnvs.GoogleCloudBuild, cfg.SourceFile, opts.Profile)) return err } @@ -80,8 +80,8 @@ func AddGcbBuildEnv(ctx context.Context, out io.Writer, opts inspect.Options) er return inspect.MarshalConfigSet(cfgs) } -func constructGcbDefinition(existing *latestV1.GoogleCloudBuild, opts inspect.BuildEnvOptions) *latestV1.GoogleCloudBuild { - var b latestV1.GoogleCloudBuild +func constructGcbDefinition(existing *latest.GoogleCloudBuild, opts inspect.BuildEnvOptions) *latest.GoogleCloudBuild { + var b latest.GoogleCloudBuild if existing != nil { b = *existing } @@ -126,6 +126,6 @@ func addProfileActivationStanza(cfg *parser.SkaffoldConfigEntry, profileName str return } } - cfg.Dependencies[i].ActiveProfiles = append(cfg.Dependencies[i].ActiveProfiles, latestV1.ProfileDependency{Name: profileName, ActivatedBy: []string{profileName}}) + cfg.Dependencies[i].ActiveProfiles = append(cfg.Dependencies[i].ActiveProfiles, latest.ProfileDependency{Name: profileName, ActivatedBy: []string{profileName}}) } } diff --git a/pkg/skaffold/inspect/buildEnv/add_gcb_test.go b/pkg/skaffold/inspect/buildEnv/add_gcb_test.go index f9a1d224fac..922346e5b83 100644 --- a/pkg/skaffold/inspect/buildEnv/add_gcb_test.go +++ b/pkg/skaffold/inspect/buildEnv/add_gcb_test.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/inspect" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser" sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/errors" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml" "github.com/GoogleContainerTools/skaffold/testutil" @@ -320,24 +320,24 @@ profiles: for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { configSet := parser.SkaffoldConfigSet{ - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: "cfg1_0"}, - Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{LocalBuild: &v1.LocalBuild{}}}}, - Profiles: []v1.Profile{ - {Name: "p1", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{Cluster: &v1.ClusterDetails{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: "cfg1_0"}, + Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}}}, + Profiles: []latest.Profile{ + {Name: "p1", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{Cluster: &latest.ClusterDetails{}}}}}, }}, SourceFile: pathToCfg1, IsRootConfig: true, SourceIndex: 0}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: "cfg1_1"}, - Dependencies: []v1.ConfigDependency{{Path: pathToCfg2}}, - Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{LocalBuild: &v1.LocalBuild{}}}}, - Profiles: []v1.Profile{ - {Name: "p1", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{Cluster: &v1.ClusterDetails{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: "cfg1_1"}, + Dependencies: []latest.ConfigDependency{{Path: pathToCfg2}}, + Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}}}, + Profiles: []latest.Profile{ + {Name: "p1", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{Cluster: &latest.ClusterDetails{}}}}}, }}, SourceFile: pathToCfg1, IsRootConfig: true, SourceIndex: 1}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: "cfg2"}, - Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{GoogleCloudBuild: &v1.GoogleCloudBuild{}}}}, - Profiles: []v1.Profile{ - {Name: "p1", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{LocalBuild: &v1.LocalBuild{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: "cfg2"}, + Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{GoogleCloudBuild: &latest.GoogleCloudBuild{}}}}, + Profiles: []latest.Profile{ + {Name: "p1", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}}}}, }}, SourceFile: pathToCfg2, SourceIndex: 0}, } t.Override(&inspect.GetConfigSet, func(ctx context.Context, opts config.SkaffoldOptions) (parser.SkaffoldConfigSet, error) { @@ -358,9 +358,9 @@ profiles: }) t.Override(&inspect.ReadFileFunc, func(filename string) ([]byte, error) { if filename == pathToCfg1 { - return yaml.MarshalWithSeparator([]*v1.SkaffoldConfig{configSet[0].SkaffoldConfig, configSet[1].SkaffoldConfig}) + return yaml.MarshalWithSeparator([]*latest.SkaffoldConfig{configSet[0].SkaffoldConfig, configSet[1].SkaffoldConfig}) } else if filename == pathToCfg2 { - return yaml.MarshalWithSeparator([]*v1.SkaffoldConfig{configSet[2].SkaffoldConfig}) + return yaml.MarshalWithSeparator([]*latest.SkaffoldConfig{configSet[2].SkaffoldConfig}) } t.FailNow() return nil, nil diff --git a/pkg/skaffold/inspect/buildEnv/add_local.go b/pkg/skaffold/inspect/buildEnv/add_local.go index a0873ea441c..3442d13580b 100644 --- a/pkg/skaffold/inspect/buildEnv/add_local.go +++ b/pkg/skaffold/inspect/buildEnv/add_local.go @@ -22,7 +22,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/inspect" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -38,7 +38,7 @@ func AddLocalBuildEnv(ctx context.Context, out io.Writer, opts inspect.Options) // for these cases, don't add the new env definition to any configs imported as dependencies. cfgs = cfgs.SelectRootConfigs() for _, cfg := range cfgs { - if cfg.Build.LocalBuild != nil && (*cfg.Build.LocalBuild != latestV1.LocalBuild{}) { + if cfg.Build.LocalBuild != nil && (*cfg.Build.LocalBuild != latest.LocalBuild{}) { formatter.WriteErr(inspect.BuildEnvAlreadyExists(inspect.BuildEnvs.Local, cfg.SourceFile, "")) return err } @@ -57,9 +57,9 @@ func AddLocalBuildEnv(ctx context.Context, out io.Writer, opts inspect.Options) } if index < 0 { index = len(cfg.Profiles) - cfg.Profiles = append(cfg.Profiles, latestV1.Profile{Name: opts.Profile}) + cfg.Profiles = append(cfg.Profiles, latest.Profile{Name: opts.Profile}) } - if cfg.Profiles[index].Build.LocalBuild != nil && (*cfg.Profiles[index].Build.LocalBuild != latestV1.LocalBuild{}) { + if cfg.Profiles[index].Build.LocalBuild != nil && (*cfg.Profiles[index].Build.LocalBuild != latest.LocalBuild{}) { formatter.WriteErr(inspect.BuildEnvAlreadyExists(inspect.BuildEnvs.Local, cfg.SourceFile, opts.Profile)) return err } @@ -71,8 +71,8 @@ func AddLocalBuildEnv(ctx context.Context, out io.Writer, opts inspect.Options) return inspect.MarshalConfigSet(cfgs) } -func constructLocalDefinition(existing *latestV1.LocalBuild, opts inspect.BuildEnvOptions) *latestV1.LocalBuild { - var b latestV1.LocalBuild +func constructLocalDefinition(existing *latest.LocalBuild, opts inspect.BuildEnvOptions) *latest.LocalBuild { + var b latest.LocalBuild if existing != nil { b = *existing } diff --git a/pkg/skaffold/inspect/buildEnv/add_local_test.go b/pkg/skaffold/inspect/buildEnv/add_local_test.go index 331e18802df..ae0fb8f0d9e 100644 --- a/pkg/skaffold/inspect/buildEnv/add_local_test.go +++ b/pkg/skaffold/inspect/buildEnv/add_local_test.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/inspect" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser" sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/errors" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml" @@ -271,24 +271,24 @@ profiles: for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { configSet := parser.SkaffoldConfigSet{ - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: "cfg1_0"}, - Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{GoogleCloudBuild: &v1.GoogleCloudBuild{}}}}, - Profiles: []v1.Profile{ - {Name: "p1", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{Cluster: &v1.ClusterDetails{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: "cfg1_0"}, + Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{GoogleCloudBuild: &latest.GoogleCloudBuild{}}}}, + Profiles: []latest.Profile{ + {Name: "p1", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{Cluster: &latest.ClusterDetails{}}}}}, }}, SourceFile: pathToCfg1, IsRootConfig: true, SourceIndex: 0}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: "cfg1_1"}, - Dependencies: []v1.ConfigDependency{{Path: pathToCfg2}}, - Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{GoogleCloudBuild: &v1.GoogleCloudBuild{}}}}, - Profiles: []v1.Profile{ - {Name: "p1", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{Cluster: &v1.ClusterDetails{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: "cfg1_1"}, + Dependencies: []latest.ConfigDependency{{Path: pathToCfg2}}, + Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{GoogleCloudBuild: &latest.GoogleCloudBuild{}}}}, + Profiles: []latest.Profile{ + {Name: "p1", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{Cluster: &latest.ClusterDetails{}}}}}, }}, SourceFile: pathToCfg1, IsRootConfig: true, SourceIndex: 1}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: "cfg2"}, - Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{GoogleCloudBuild: &v1.GoogleCloudBuild{}}}}, - Profiles: []v1.Profile{ - {Name: "p1", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{GoogleCloudBuild: &v1.GoogleCloudBuild{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: "cfg2"}, + Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{GoogleCloudBuild: &latest.GoogleCloudBuild{}}}}, + Profiles: []latest.Profile{ + {Name: "p1", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{GoogleCloudBuild: &latest.GoogleCloudBuild{}}}}}, }}, SourceFile: pathToCfg2, SourceIndex: 0}, } t.Override(&inspect.GetConfigSet, func(ctx context.Context, opts config.SkaffoldOptions) (parser.SkaffoldConfigSet, error) { @@ -309,9 +309,9 @@ profiles: }) t.Override(&inspect.ReadFileFunc, func(filename string) ([]byte, error) { if filename == pathToCfg1 { - return yaml.MarshalWithSeparator([]*v1.SkaffoldConfig{configSet[0].SkaffoldConfig, configSet[1].SkaffoldConfig}) + return yaml.MarshalWithSeparator([]*latest.SkaffoldConfig{configSet[0].SkaffoldConfig, configSet[1].SkaffoldConfig}) } else if filename == pathToCfg2 { - return yaml.MarshalWithSeparator([]*v1.SkaffoldConfig{configSet[2].SkaffoldConfig}) + return yaml.MarshalWithSeparator([]*latest.SkaffoldConfig{configSet[2].SkaffoldConfig}) } t.FailNow() return nil, nil diff --git a/pkg/skaffold/inspect/buildEnv/list_test.go b/pkg/skaffold/inspect/buildEnv/list_test.go index 5f9e990f087..e9ee7fea97d 100644 --- a/pkg/skaffold/inspect/buildEnv/list_test.go +++ b/pkg/skaffold/inspect/buildEnv/list_test.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/inspect" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser" sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/errors" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -87,17 +87,17 @@ func TestPrintBuildEnvsList(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { configSet := parser.SkaffoldConfigSet{ - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: "cfg1"}, - Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{LocalBuild: &v1.LocalBuild{}}}}, - Profiles: []v1.Profile{ - {Name: "cluster", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{Cluster: &v1.ClusterDetails{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: "cfg1"}, + Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}}}, + Profiles: []latest.Profile{ + {Name: "cluster", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{Cluster: &latest.ClusterDetails{}}}}}, }}, SourceFile: "path/to/cfg1"}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: "cfg2"}, - Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{GoogleCloudBuild: &v1.GoogleCloudBuild{}}}}, - Profiles: []v1.Profile{ - {Name: "local", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{LocalBuild: &v1.LocalBuild{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: "cfg2"}, + Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{GoogleCloudBuild: &latest.GoogleCloudBuild{}}}}, + Profiles: []latest.Profile{ + {Name: "local", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}}}}, }}, SourceFile: "path/to/cfg2"}, } t.Override(&inspect.GetConfigSet, func(ctx context.Context, opts config.SkaffoldOptions) (parser.SkaffoldConfigSet, error) { diff --git a/pkg/skaffold/inspect/buildEnv/modify_gcb_test.go b/pkg/skaffold/inspect/buildEnv/modify_gcb_test.go index 70dde981946..02903cce48d 100644 --- a/pkg/skaffold/inspect/buildEnv/modify_gcb_test.go +++ b/pkg/skaffold/inspect/buildEnv/modify_gcb_test.go @@ -24,7 +24,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/inspect" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml" "github.com/GoogleContainerTools/skaffold/proto/v1" @@ -227,19 +227,19 @@ profiles: for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { configSet := parser.SkaffoldConfigSet{ - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: "cfg1"}, - Dependencies: []v1.ConfigDependency{{Path: pathToCfg2}}, - Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{GoogleCloudBuild: &v1.GoogleCloudBuild{ProjectID: "project1"}}}}, - Profiles: []v1.Profile{ - {Name: "p1", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{GoogleCloudBuild: &v1.GoogleCloudBuild{ProjectID: "project1"}}}}}, - {Name: "p2", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{Cluster: &v1.ClusterDetails{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: "cfg1"}, + Dependencies: []latest.ConfigDependency{{Path: pathToCfg2}}, + Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{GoogleCloudBuild: &latest.GoogleCloudBuild{ProjectID: "project1"}}}}, + Profiles: []latest.Profile{ + {Name: "p1", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{GoogleCloudBuild: &latest.GoogleCloudBuild{ProjectID: "project1"}}}}}, + {Name: "p2", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{Cluster: &latest.ClusterDetails{}}}}}, }}, SourceFile: pathToCfg1, IsRootConfig: true, SourceIndex: 0}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: "cfg2"}, - Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{LocalBuild: &v1.LocalBuild{}}}}, - Profiles: []v1.Profile{ - {Name: "p1", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{GoogleCloudBuild: &v1.GoogleCloudBuild{ProjectID: "project1"}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: "cfg2"}, + Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}}}, + Profiles: []latest.Profile{ + {Name: "p1", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{GoogleCloudBuild: &latest.GoogleCloudBuild{ProjectID: "project1"}}}}}, }}, SourceFile: pathToCfg2, SourceIndex: 0}, } t.Override(&inspect.GetConfigSet, func(ctx context.Context, opts config.SkaffoldOptions) (parser.SkaffoldConfigSet, error) { @@ -253,9 +253,9 @@ profiles: }) t.Override(&inspect.ReadFileFunc, func(filename string) ([]byte, error) { if filename == pathToCfg1 { - return yaml.MarshalWithSeparator([]*v1.SkaffoldConfig{configSet[0].SkaffoldConfig}) + return yaml.MarshalWithSeparator([]*latest.SkaffoldConfig{configSet[0].SkaffoldConfig}) } else if filename == pathToCfg2 { - return yaml.MarshalWithSeparator([]*v1.SkaffoldConfig{configSet[1].SkaffoldConfig}) + return yaml.MarshalWithSeparator([]*latest.SkaffoldConfig{configSet[1].SkaffoldConfig}) } t.FailNow() return nil, nil diff --git a/pkg/skaffold/inspect/modules/list_test.go b/pkg/skaffold/inspect/modules/list_test.go index ccca143a4be..d213c66ca8d 100644 --- a/pkg/skaffold/inspect/modules/list_test.go +++ b/pkg/skaffold/inspect/modules/list_test.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/inspect" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser" sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/errors" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -43,20 +43,20 @@ func TestPrintModulesList(t *testing.T) { { description: "print modules", configSet: parser.SkaffoldConfigSet{ - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{Metadata: v1.Metadata{Name: ""}}, SourceFile: "path/to/cfg1", SourceIndex: 0, IsRootConfig: true}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{Metadata: v1.Metadata{Name: "cfg1"}}, SourceFile: "path/to/cfg1", SourceIndex: 1, IsRootConfig: true}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{Metadata: v1.Metadata{Name: "cfg2"}}, SourceFile: "path/to/cfg2", SourceIndex: 0, IsRemote: true}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{Metadata: v1.Metadata{Name: ""}}, SourceFile: "path/to/cfg3", SourceIndex: 0}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{Metadata: latest.Metadata{Name: ""}}, SourceFile: "path/to/cfg1", SourceIndex: 0, IsRootConfig: true}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{Metadata: latest.Metadata{Name: "cfg1"}}, SourceFile: "path/to/cfg1", SourceIndex: 1, IsRootConfig: true}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{Metadata: latest.Metadata{Name: "cfg2"}}, SourceFile: "path/to/cfg2", SourceIndex: 0, IsRemote: true}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{Metadata: latest.Metadata{Name: ""}}, SourceFile: "path/to/cfg3", SourceIndex: 0}, }, expected: `{"modules":[{"name":"cfg1","path":"path/to/cfg1","isRoot":true},{"name":"cfg2","path":"path/to/cfg2","isRemote":true}]}` + "\n", }, { description: "print modules; include all", configSet: parser.SkaffoldConfigSet{ - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{Metadata: v1.Metadata{Name: ""}}, SourceFile: "path/to/cfg1", SourceIndex: 0, IsRootConfig: true}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{Metadata: v1.Metadata{Name: "cfg1"}}, SourceFile: "path/to/cfg1", SourceIndex: 1, IsRootConfig: true}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{Metadata: v1.Metadata{Name: "cfg2"}}, SourceFile: "path/to/cfg2", SourceIndex: 0, IsRemote: true}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{Metadata: v1.Metadata{Name: ""}}, SourceFile: "path/to/cfg3", SourceIndex: 0}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{Metadata: latest.Metadata{Name: ""}}, SourceFile: "path/to/cfg1", SourceIndex: 0, IsRootConfig: true}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{Metadata: latest.Metadata{Name: "cfg1"}}, SourceFile: "path/to/cfg1", SourceIndex: 1, IsRootConfig: true}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{Metadata: latest.Metadata{Name: "cfg2"}}, SourceFile: "path/to/cfg2", SourceIndex: 0, IsRemote: true}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{Metadata: latest.Metadata{Name: ""}}, SourceFile: "path/to/cfg3", SourceIndex: 0}, }, includeAll: true, expected: `{"modules":[` + diff --git a/pkg/skaffold/inspect/profiles/list_test.go b/pkg/skaffold/inspect/profiles/list_test.go index b578d12f061..000e140a086 100644 --- a/pkg/skaffold/inspect/profiles/list_test.go +++ b/pkg/skaffold/inspect/profiles/list_test.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/inspect" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser" sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/errors" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -44,16 +44,16 @@ func TestPrintProfilesList(t *testing.T) { { description: "print all profiles", configSet: parser.SkaffoldConfigSet{ - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{Metadata: v1.Metadata{Name: "cfg1"}, Profiles: []v1.Profile{ - {Name: "p1", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{LocalBuild: &v1.LocalBuild{}}}}}, - {Name: "p2", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{Cluster: &v1.ClusterDetails{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{Metadata: latest.Metadata{Name: "cfg1"}, Profiles: []latest.Profile{ + {Name: "p1", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}}}}, + {Name: "p2", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{Cluster: &latest.ClusterDetails{}}}}}, }}, SourceFile: "path/to/cfg1"}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{Metadata: v1.Metadata{Name: "cfg2"}, Profiles: []v1.Profile{ - {Name: "p3", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{LocalBuild: &v1.LocalBuild{}}}}}, - {Name: "p4", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{GoogleCloudBuild: &v1.GoogleCloudBuild{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{Metadata: latest.Metadata{Name: "cfg2"}, Profiles: []latest.Profile{ + {Name: "p3", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}}}}, + {Name: "p4", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{GoogleCloudBuild: &latest.GoogleCloudBuild{}}}}}, }}, SourceFile: "path/to/cfg2"}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{Profiles: []v1.Profile{ - {Name: "p5", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{LocalBuild: &v1.LocalBuild{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{Profiles: []latest.Profile{ + {Name: "p5", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}}}}, }}, SourceFile: "path/to/cfg2"}, }, expected: `{"profiles":[` + @@ -67,13 +67,13 @@ func TestPrintProfilesList(t *testing.T) { { description: "print all profiles for one module", configSet: parser.SkaffoldConfigSet{ - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{Metadata: v1.Metadata{Name: "cfg1"}, Profiles: []v1.Profile{ - {Name: "p1", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{LocalBuild: &v1.LocalBuild{}}}}}, - {Name: "p2", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{Cluster: &v1.ClusterDetails{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{Metadata: latest.Metadata{Name: "cfg1"}, Profiles: []latest.Profile{ + {Name: "p1", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}}}}, + {Name: "p2", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{Cluster: &latest.ClusterDetails{}}}}}, }}, SourceFile: "path/to/cfg1"}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{Metadata: v1.Metadata{Name: "cfg2"}, Profiles: []v1.Profile{ - {Name: "p3", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{LocalBuild: &v1.LocalBuild{}}}}}, - {Name: "p4", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{GoogleCloudBuild: &v1.GoogleCloudBuild{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{Metadata: latest.Metadata{Name: "cfg2"}, Profiles: []latest.Profile{ + {Name: "p3", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}}}}, + {Name: "p4", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{GoogleCloudBuild: &latest.GoogleCloudBuild{}}}}}, }}, SourceFile: "path/to/cfg2"}, }, expected: `{"profiles":[` + @@ -85,13 +85,13 @@ func TestPrintProfilesList(t *testing.T) { { description: "print all profiles for one module and gcb build-env", configSet: parser.SkaffoldConfigSet{ - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{Metadata: v1.Metadata{Name: "cfg1"}, Profiles: []v1.Profile{ - {Name: "p1", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{LocalBuild: &v1.LocalBuild{}}}}}, - {Name: "p2", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{Cluster: &v1.ClusterDetails{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{Metadata: latest.Metadata{Name: "cfg1"}, Profiles: []latest.Profile{ + {Name: "p1", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}}}}, + {Name: "p2", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{Cluster: &latest.ClusterDetails{}}}}}, }}, SourceFile: "path/to/cfg1"}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{Metadata: v1.Metadata{Name: "cfg2"}, Profiles: []v1.Profile{ - {Name: "p3", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{LocalBuild: &v1.LocalBuild{}}}}}, - {Name: "p4", Pipeline: v1.Pipeline{Build: v1.BuildConfig{BuildType: v1.BuildType{GoogleCloudBuild: &v1.GoogleCloudBuild{}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{Metadata: latest.Metadata{Name: "cfg2"}, Profiles: []latest.Profile{ + {Name: "p3", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}}}}, + {Name: "p4", Pipeline: latest.Pipeline{Build: latest.BuildConfig{BuildType: latest.BuildType{GoogleCloudBuild: &latest.GoogleCloudBuild{}}}}}, }}, SourceFile: "path/to/cfg2"}, }, expected: `{"profiles":[` + diff --git a/pkg/skaffold/inspect/tests/list.go b/pkg/skaffold/inspect/tests/list.go index 7949416066d..39814ef50fe 100644 --- a/pkg/skaffold/inspect/tests/list.go +++ b/pkg/skaffold/inspect/tests/list.go @@ -22,7 +22,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/inspect" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) type testList struct { @@ -38,7 +38,7 @@ type structureTestEntry struct { type customTestEntry struct { TestType string `json:"testType"` - latestV1.CustomTest + latest.CustomTest } func PrintTestsList(ctx context.Context, out io.Writer, opts inspect.Options) error { diff --git a/pkg/skaffold/inspect/tests/list_test.go b/pkg/skaffold/inspect/tests/list_test.go index d067796502a..600ad8f676e 100644 --- a/pkg/skaffold/inspect/tests/list_test.go +++ b/pkg/skaffold/inspect/tests/list_test.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/inspect" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser" sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/errors" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -75,17 +75,17 @@ func TestPrintTestsList(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { configSet := parser.SkaffoldConfigSet{ - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: "cfg1"}, - Pipeline: v1.Pipeline{Test: []*v1.TestCase{{StructureTests: []string{"structure-test-default"}}}}, - Profiles: []v1.Profile{ - {Name: "custom-test", Pipeline: v1.Pipeline{Test: []*v1.TestCase{{CustomTests: []v1.CustomTest{{Command: "custom-test-profile"}}}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: "cfg1"}, + Pipeline: latest.Pipeline{Test: []*latest.TestCase{{StructureTests: []string{"structure-test-default"}}}}, + Profiles: []latest.Profile{ + {Name: "custom-test", Pipeline: latest.Pipeline{Test: []*latest.TestCase{{CustomTests: []latest.CustomTest{{Command: "custom-test-profile"}}}}}}}, }, SourceFile: "path/to/cfg1"}, - &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: "cfg2"}, - Pipeline: v1.Pipeline{Test: []*v1.TestCase{{CustomTests: []v1.CustomTest{{Command: "custom-test-default"}}}}}, - Profiles: []v1.Profile{ - {Name: "structure-test", Pipeline: v1.Pipeline{Test: []*v1.TestCase{{StructureTests: []string{"structure-test-profile"}}}}}}, + &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: "cfg2"}, + Pipeline: latest.Pipeline{Test: []*latest.TestCase{{CustomTests: []latest.CustomTest{{Command: "custom-test-default"}}}}}, + Profiles: []latest.Profile{ + {Name: "structure-test", Pipeline: latest.Pipeline{Test: []*latest.TestCase{{StructureTests: []string{"structure-test-profile"}}}}}}, }, SourceFile: "path/to/cfg2"}, } t.Override(&inspect.GetConfigSet, func(_ context.Context, opts config.SkaffoldOptions) (parser.SkaffoldConfigSet, error) { diff --git a/pkg/skaffold/inspect/types.go b/pkg/skaffold/inspect/types.go index 6e644c5d8ea..74381c335f0 100644 --- a/pkg/skaffold/inspect/types.go +++ b/pkg/skaffold/inspect/types.go @@ -18,7 +18,7 @@ package inspect import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // Options holds flag values for the various `skaffold inspect` commands @@ -120,7 +120,7 @@ var ( } ) -func GetBuildEnv(t *latestV1.BuildType) BuildEnv { +func GetBuildEnv(t *latest.BuildType) BuildEnv { switch { case t.Cluster != nil: return BuildEnvs.Cluster diff --git a/pkg/skaffold/instrumentation/meter.go b/pkg/skaffold/instrumentation/meter.go index fe8e74ffa52..1cc05036fdd 100644 --- a/pkg/skaffold/instrumentation/meter.go +++ b/pkg/skaffold/instrumentation/meter.go @@ -24,7 +24,7 @@ import ( flag "github.com/spf13/pflag" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringset" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/version" @@ -82,7 +82,7 @@ func SetOnlineStatus() { }() } -func InitMeterFromConfig(configs []*latestV1.SkaffoldConfig, user, deployCtx string) { +func InitMeterFromConfig(configs []*latest.SkaffoldConfig, user, deployCtx string) { var platforms []string for _, config := range configs { pl := yamltags.GetYamlTag(config.Build.BuildType) diff --git a/pkg/skaffold/instrumentation/new.go b/pkg/skaffold/instrumentation/new.go index 5089a0c3176..064f906ffed 100644 --- a/pkg/skaffold/instrumentation/new.go +++ b/pkg/skaffold/instrumentation/new.go @@ -20,11 +20,11 @@ import ( "context" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // Init initializes the skaffold metrics and trace tooling built on top of open-telemetry (otel) -func Init(configs []*latestV1.SkaffoldConfig, user, deployCtx string, opts ...TraceExporterOption) { +func Init(configs []*latest.SkaffoldConfig, user, deployCtx string, opts ...TraceExporterOption) { InitMeterFromConfig(configs, user, deployCtx) InitTraceFromEnvVar() } diff --git a/pkg/skaffold/kubernetes/logger/formatter.go b/pkg/skaffold/kubernetes/logger/formatter.go index 54c3df37a8e..7a9bb245503 100644 --- a/pkg/skaffold/kubernetes/logger/formatter.go +++ b/pkg/skaffold/kubernetes/logger/formatter.go @@ -26,7 +26,7 @@ import ( eventV2 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event/v2" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" tagutil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/tag/util" ) @@ -35,7 +35,7 @@ type Formatter func(pod v1.Pod, containerStatus v1.ContainerStatus, isMuted func type kubernetesLogFormatter struct { colorPicker output.ColorPicker prefix string - JSONParseConfig latestV1.JSONParseConfig + JSONParseConfig latest.JSONParseConfig pod *v1.Pod container v1.ContainerStatus @@ -92,7 +92,7 @@ func (k *kubernetesLogFormatter) color() output.Color { } func prefix(config Config, pod *v1.Pod, container v1.ContainerStatus) string { - var c latestV1.Pipeline + var c latest.Pipeline var present bool for _, container := range pod.Spec.Containers { if c, present = config.PipelineForImage(tagutil.StripTag(container.Image, false)); present { diff --git a/pkg/skaffold/kubernetes/logger/formatter_test.go b/pkg/skaffold/kubernetes/logger/formatter_test.go index 494c65fdd65..7c5d82031e7 100644 --- a/pkg/skaffold/kubernetes/logger/formatter_test.go +++ b/pkg/skaffold/kubernetes/logger/formatter_test.go @@ -25,7 +25,7 @@ import ( v1 "k8s.io/api/core/v1" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -38,26 +38,26 @@ func (m *mockColorPicker) Pick(image string) output.Color { func (m *mockColorPicker) AddImage(string) {} type mockConfig struct { - log latestV1.LogsConfig + log latest.LogsConfig } func (c *mockConfig) Tail() bool { return true } -func (c *mockConfig) PipelineForImage(string) (latestV1.Pipeline, bool) { - var pipeline latestV1.Pipeline +func (c *mockConfig) PipelineForImage(string) (latest.Pipeline, bool) { + var pipeline latest.Pipeline pipeline.Deploy.Logs = c.log return pipeline, true } -func (c *mockConfig) DefaultPipeline() latestV1.Pipeline { - var pipeline latestV1.Pipeline +func (c *mockConfig) DefaultPipeline() latest.Pipeline { + var pipeline latest.Pipeline pipeline.Deploy.Logs = c.log return pipeline } -func (c *mockConfig) JSONParseConfig() latestV1.JSONParseConfig { +func (c *mockConfig) JSONParseConfig() latest.JSONParseConfig { return c.log.JSONParse } @@ -71,7 +71,7 @@ func TestPrintLogLine(t *testing.T) { groups = 5 ) - f := newKubernetesLogFormatter(&mockConfig{log: latestV1.LogsConfig{Prefix: "none"}}, &mockColorPicker{}, func() bool { return false }, &v1.Pod{}, v1.ContainerStatus{}) + f := newKubernetesLogFormatter(&mockConfig{log: latest.LogsConfig{Prefix: "none"}}, &mockColorPicker{}, func() bool { return false }, &v1.Pod{}, v1.ContainerStatus{}) for i := 0; i < groups; i++ { wg.Add(1) @@ -155,7 +155,7 @@ func TestColorForPod(t *testing.T) { p.AddImage("second") for _, test := range tests { - f := newKubernetesLogFormatter(&mockConfig{log: latestV1.LogsConfig{Prefix: "none"}}, p, func() bool { return false }, test.pod, v1.ContainerStatus{}) + f := newKubernetesLogFormatter(&mockConfig{log: latest.LogsConfig{Prefix: "none"}}, p, func() bool { return false }, test.pod, v1.ContainerStatus{}) testutil.Run(t, test.description, func(t *testutil.T) { color := f.color() @@ -218,7 +218,7 @@ func TestPrefix(t *testing.T) { } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - f := newKubernetesLogFormatter(&mockConfig{log: latestV1.LogsConfig{ + f := newKubernetesLogFormatter(&mockConfig{log: latest.LogsConfig{ Prefix: test.prefix, }}, &mockColorPicker{}, func() bool { return false }, &test.pod, test.container) @@ -245,7 +245,7 @@ func TestPrintline(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { pod := podWithName("hello") - f := newKubernetesLogFormatter(&mockConfig{log: latestV1.LogsConfig{ + f := newKubernetesLogFormatter(&mockConfig{log: latest.LogsConfig{ Prefix: "auto", }}, &mockColorPicker{}, func() bool { return test.isMuted }, &pod, containerWithName("container")) diff --git a/pkg/skaffold/kubernetes/logger/log.go b/pkg/skaffold/kubernetes/logger/log.go index a59d7c57aa0..40ab772ff6f 100644 --- a/pkg/skaffold/kubernetes/logger/log.go +++ b/pkg/skaffold/kubernetes/logger/log.go @@ -34,7 +34,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/log/stream" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" olog "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) type Logger interface { @@ -61,9 +61,9 @@ type LogAggregator struct { type Config interface { Tail() bool - PipelineForImage(imageName string) (latestV1.Pipeline, bool) - DefaultPipeline() latestV1.Pipeline - JSONParseConfig() latestV1.JSONParseConfig + PipelineForImage(imageName string) (latest.Pipeline, bool) + DefaultPipeline() latest.Pipeline + JSONParseConfig() latest.JSONParseConfig } // NewLogAggregator creates a new LogAggregator for a given output. diff --git a/pkg/skaffold/kubernetes/manifest/images.go b/pkg/skaffold/kubernetes/manifest/images.go index 2a4d2044d2b..3d2e1bb740f 100644 --- a/pkg/skaffold/kubernetes/manifest/images.go +++ b/pkg/skaffold/kubernetes/manifest/images.go @@ -26,15 +26,15 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/instrumentation" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) type ResourceSelectorImages struct { - allowlist map[apimachinery.GroupKind]latestV1.ResourceFilter - denylist map[apimachinery.GroupKind]latestV1.ResourceFilter + allowlist map[apimachinery.GroupKind]latest.ResourceFilter + denylist map[apimachinery.GroupKind]latest.ResourceFilter } -func NewResourceSelectorImages(allowlist map[apimachinery.GroupKind]latestV1.ResourceFilter, denylist map[apimachinery.GroupKind]latestV1.ResourceFilter) *ResourceSelectorImages { +func NewResourceSelectorImages(allowlist map[apimachinery.GroupKind]latest.ResourceFilter, denylist map[apimachinery.GroupKind]latest.ResourceFilter) *ResourceSelectorImages { return &ResourceSelectorImages{ allowlist: allowlist, denylist: denylist, diff --git a/pkg/skaffold/kubernetes/manifest/labels.go b/pkg/skaffold/kubernetes/manifest/labels.go index aa9e85b7b52..3b00add074b 100644 --- a/pkg/skaffold/kubernetes/manifest/labels.go +++ b/pkg/skaffold/kubernetes/manifest/labels.go @@ -23,15 +23,15 @@ import ( apimachinery "k8s.io/apimachinery/pkg/runtime/schema" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) type ResourceSelectorLabels struct { - allowlist map[apimachinery.GroupKind]latestV1.ResourceFilter - denylist map[apimachinery.GroupKind]latestV1.ResourceFilter + allowlist map[apimachinery.GroupKind]latest.ResourceFilter + denylist map[apimachinery.GroupKind]latest.ResourceFilter } -func NewResourceSelectorLabels(allowlist map[apimachinery.GroupKind]latestV1.ResourceFilter, denylist map[apimachinery.GroupKind]latestV1.ResourceFilter) *ResourceSelectorLabels { +func NewResourceSelectorLabels(allowlist map[apimachinery.GroupKind]latest.ResourceFilter, denylist map[apimachinery.GroupKind]latest.ResourceFilter) *ResourceSelectorLabels { return &ResourceSelectorLabels{ allowlist: allowlist, denylist: denylist, diff --git a/pkg/skaffold/kubernetes/manifest/labels_test.go b/pkg/skaffold/kubernetes/manifest/labels_test.go index 1dc19ca11fb..5bb363e865d 100644 --- a/pkg/skaffold/kubernetes/manifest/labels_test.go +++ b/pkg/skaffold/kubernetes/manifest/labels_test.go @@ -21,7 +21,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -187,7 +187,7 @@ spec: resultManifest, err := manifests.SetLabels(map[string]string{ "key0": "value0", "key1": "value1", - }, NewResourceSelectorLabels(map[schema.GroupKind]v1.ResourceFilter{ + }, NewResourceSelectorLabels(map[schema.GroupKind]latest.ResourceFilter{ {Group: "apiextensions.k8s.io", Kind: "CustomResourceDefinition"}: { GroupKind: "CustomResourceDefinition.apiextensions.k8s.io", Image: []string{".*"}, diff --git a/pkg/skaffold/kubernetes/manifest/namespaces.go b/pkg/skaffold/kubernetes/manifest/namespaces.go index 2c2e87c2b8f..682898f9553 100644 --- a/pkg/skaffold/kubernetes/manifest/namespaces.go +++ b/pkg/skaffold/kubernetes/manifest/namespaces.go @@ -31,7 +31,7 @@ func (l *ManifestList) CollectNamespaces() ([]string, error) { // TODO(aaron-prindle) make sure this is ok? rs := &ResourceSelectorImages{} if _, err := l.Visit(replacer, rs); err != nil { - // if _, err := l.Visit(replacer, make(map[schema.GroupKind]latestV1.ResourceFilter), make(map[schema.GroupKind]latestV1.ResourceFilter)); err != nil { + // if _, err := l.Visit(replacer, make(map[schema.GroupKind]latest.ResourceFilter), make(map[schema.GroupKind]latest.ResourceFilter)); err != nil { // TODO(aaron-prindle) verify this doesn't need to support allow/deny list, also see if 'nil' is better option for unused inputs return nil, fmt.Errorf("collecting namespaces: %w", err) } diff --git a/pkg/skaffold/kubernetes/manifest/visitor.go b/pkg/skaffold/kubernetes/manifest/visitor.go index a07faf941a3..7ca3ffe853e 100644 --- a/pkg/skaffold/kubernetes/manifest/visitor.go +++ b/pkg/skaffold/kubernetes/manifest/visitor.go @@ -21,7 +21,7 @@ import ( apimachinery "k8s.io/apimachinery/pkg/runtime/schema" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml" ) @@ -33,7 +33,7 @@ type ResourceSelector interface { } // TransformAllowlist is the default allowlist of kinds that can be transformed by Skaffold. -var TransformAllowlist = map[apimachinery.GroupKind]latestV1.ResourceFilter{ +var TransformAllowlist = map[apimachinery.GroupKind]latest.ResourceFilter{ {Group: "", Kind: "Pod"}: { GroupKind: "Pod", Image: []string{".*"}, @@ -162,7 +162,7 @@ var TransformAllowlist = map[apimachinery.GroupKind]latestV1.ResourceFilter{ } // TransformDenylist is the default denylist on the set of kinds that can be transformed by Skaffold. -var TransformDenylist = map[apimachinery.GroupKind]latestV1.ResourceFilter{ +var TransformDenylist = map[apimachinery.GroupKind]latest.ResourceFilter{ {Group: "apps", Kind: "StatefulSet"}: { GroupKind: "StatefulSet.apps", Labels: []string{".spec.volumeClaimTemplates.metadata.labels"}, diff --git a/pkg/skaffold/kubernetes/portforward/entry_manager_test.go b/pkg/skaffold/kubernetes/portforward/entry_manager_test.go index d9329e5bb1a..17586ea083b 100644 --- a/pkg/skaffold/kubernetes/portforward/entry_manager_test.go +++ b/pkg/skaffold/kubernetes/portforward/entry_manager_test.go @@ -25,21 +25,21 @@ import ( "testing" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" testEvent "github.com/GoogleContainerTools/skaffold/testutil/event" ) func TestStop(t *testing.T) { - testEvent.InitializeState([]latestV1.Pipeline{{}}) + testEvent.InitializeState([]latest.Pipeline{{}}) - pfe1 := newPortForwardEntry(0, latestV1.PortForwardResource{ + pfe1 := newPortForwardEntry(0, latest.PortForwardResource{ Type: constants.Pod, Name: "resource", Namespace: "default", }, "", "", "", "", 9000, false) - pfe2 := newPortForwardEntry(0, latestV1.PortForwardResource{ + pfe2 := newPortForwardEntry(0, latest.PortForwardResource{ Type: constants.Pod, Name: "resource2", Namespace: "default", diff --git a/pkg/skaffold/kubernetes/portforward/forwarder_manager.go b/pkg/skaffold/kubernetes/portforward/forwarder_manager.go index a7bd5e7d766..dc494c7edb2 100644 --- a/pkg/skaffold/kubernetes/portforward/forwarder_manager.go +++ b/pkg/skaffold/kubernetes/portforward/forwarder_manager.go @@ -32,14 +32,14 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) type Config interface { kubectl.Config Mode() config.RunMode - PortForwardResources() []*latestV1.PortForwardResource + PortForwardResources() []*latest.PortForwardResource PortForwardOptions() config.PortForwardOptions } @@ -62,7 +62,7 @@ type ForwarderManager struct { // NewForwarderManager returns a new port manager which handles starting and stopping port forwarding func NewForwarderManager(cli *kubectl.CLI, podSelector kubernetes.PodSelector, label string, runMode config.RunMode, namespaces *[]string, - options config.PortForwardOptions, userDefined []*latestV1.PortForwardResource) *ForwarderManager { + options config.PortForwardOptions, userDefined []*latest.PortForwardResource) *ForwarderManager { if !options.Enabled() { return nil } diff --git a/pkg/skaffold/kubernetes/portforward/kubectl_forwarder_test.go b/pkg/skaffold/kubernetes/portforward/kubectl_forwarder_test.go index e3fd8b6c828..46c0dcc89bb 100644 --- a/pkg/skaffold/kubernetes/portforward/kubectl_forwarder_test.go +++ b/pkg/skaffold/kubernetes/portforward/kubectl_forwarder_test.go @@ -37,7 +37,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" schemautil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -68,7 +68,7 @@ func TestUnavailablePort(t *testing.T) { k := KubectlForwarder{ out: &buf, } - pfe := newPortForwardEntry(0, latestV1.PortForwardResource{}, "", "", "", "", 8080, false) + pfe := newPortForwardEntry(0, latest.PortForwardResource{}, "", "", "", "", 8080, false) k.Start(&buf) go k.Forward(context.Background(), pfe) @@ -90,7 +90,7 @@ func TestUnavailablePort(t *testing.T) { func TestTerminate(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) - pfe := newPortForwardEntry(0, latestV1.PortForwardResource{}, "", "", "", "", 8080, false) + pfe := newPortForwardEntry(0, latest.PortForwardResource{}, "", "", "", "", 8080, false) pfe.cancel = cancel k := &KubectlForwarder{} @@ -202,29 +202,29 @@ func TestPortForwardArgs(t *testing.T) { }{ { description: "non-default address", - input: newPortForwardEntry(0, latestV1.PortForwardResource{Type: "pod", Name: "p", Namespace: "ns", Port: schemautil.FromInt(9), Address: "0.0.0.0"}, "", "", "", "", 8080, false), + input: newPortForwardEntry(0, latest.PortForwardResource{Type: "pod", Name: "p", Namespace: "ns", Port: schemautil.FromInt(9), Address: "0.0.0.0"}, "", "", "", "", 8080, false), result: []string{"--pod-running-timeout", "1s", "--namespace", "ns", "pod/p", "8080:9", "--address", "0.0.0.0"}, }, { description: "localhost is the default", - input: newPortForwardEntry(0, latestV1.PortForwardResource{Type: "pod", Name: "p", Namespace: "ns", Port: schemautil.FromInt(9), Address: "127.0.0.1"}, "", "", "", "", 8080, false), + input: newPortForwardEntry(0, latest.PortForwardResource{Type: "pod", Name: "p", Namespace: "ns", Port: schemautil.FromInt(9), Address: "127.0.0.1"}, "", "", "", "", 8080, false), result: []string{"--pod-running-timeout", "1s", "--namespace", "ns", "pod/p", "8080:9"}, }, { description: "no address", - input: newPortForwardEntry(0, latestV1.PortForwardResource{Type: "pod", Name: "p", Namespace: "ns", Port: schemautil.FromInt(9)}, "", "", "", "", 8080, false), + input: newPortForwardEntry(0, latest.PortForwardResource{Type: "pod", Name: "p", Namespace: "ns", Port: schemautil.FromInt(9)}, "", "", "", "", 8080, false), result: []string{"--pod-running-timeout", "1s", "--namespace", "ns", "pod/p", "8080:9"}, }, { description: "service to pod", - input: newPortForwardEntry(0, latestV1.PortForwardResource{Type: "service", Name: "svc", Namespace: "ns", Port: schemautil.FromInt(9)}, "", "", "", "", 8080, false), + input: newPortForwardEntry(0, latest.PortForwardResource{Type: "service", Name: "svc", Namespace: "ns", Port: schemautil.FromInt(9)}, "", "", "", "", 8080, false), servicePod: "servicePod", servicePort: 9999, result: []string{"--pod-running-timeout", "1s", "--namespace", "ns", "pod/servicePod", "8080:9999"}, }, { description: "service could not be mapped to pod", - input: newPortForwardEntry(0, latestV1.PortForwardResource{Type: "service", Name: "svc", Namespace: "ns", Port: schemautil.FromInt(9)}, "", "", "", "", 8080, false), + input: newPortForwardEntry(0, latest.PortForwardResource{Type: "service", Name: "svc", Namespace: "ns", Port: schemautil.FromInt(9)}, "", "", "", "", 8080, false), serviceErr: errors.New("error"), result: []string{"--pod-running-timeout", "1s", "--namespace", "ns", "service/svc", "8080:9"}, }, @@ -488,7 +488,7 @@ func TestForwardReturnsNilOnContextCancelled(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) done := make(chan struct{}, 1) go func() { - pfe := newPortForwardEntry(0, latestV1.PortForwardResource{}, "", "", "", "", 8080, false) + pfe := newPortForwardEntry(0, latest.PortForwardResource{}, "", "", "", "", 8080, false) err := k.Forward(ctx, pfe) if err != nil { t.Errorf("expected nil error, got %+v", err) diff --git a/pkg/skaffold/kubernetes/portforward/pod_forwarder.go b/pkg/skaffold/kubernetes/portforward/pod_forwarder.go index 144867160e2..454771bd4e1 100644 --- a/pkg/skaffold/kubernetes/portforward/pod_forwarder.go +++ b/pkg/skaffold/kubernetes/portforward/pod_forwarder.go @@ -29,7 +29,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" schemautil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) @@ -114,7 +114,7 @@ func (p *WatchingPodForwarder) portForwardPod(ctx context.Context, pod *v1.Pod) for _, c := range pod.Spec.Containers { for _, port := range p.containerPorts(pod, c) { // get current entry for this container - resource := latestV1.PortForwardResource{ + resource := latest.PortForwardResource{ Type: constants.Pod, Name: pod.Name, Namespace: pod.Namespace, @@ -142,7 +142,7 @@ func (p *WatchingPodForwarder) portForwardPod(ctx context.Context, pod *v1.Pod) return nil } -func (p *WatchingPodForwarder) podForwardingEntry(resourceVersion, containerName, portName, ownerReference string, resource latestV1.PortForwardResource) (*portForwardEntry, error) { +func (p *WatchingPodForwarder) podForwardingEntry(resourceVersion, containerName, portName, ownerReference string, resource latest.PortForwardResource) (*portForwardEntry, error) { rv, err := strconv.Atoi(resourceVersion) if err != nil { return nil, fmt.Errorf("converting resource version to integer: %w", err) diff --git a/pkg/skaffold/kubernetes/portforward/pod_forwarder_test.go b/pkg/skaffold/kubernetes/portforward/pod_forwarder_test.go index 64c193bfa5a..0ebd887f95c 100644 --- a/pkg/skaffold/kubernetes/portforward/pod_forwarder_test.go +++ b/pkg/skaffold/kubernetes/portforward/pod_forwarder_test.go @@ -29,7 +29,7 @@ import ( "k8s.io/apimachinery/pkg/watch" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" schemautil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" @@ -55,7 +55,7 @@ func TestAutomaticPortForwardPod(t *testing.T) { resourceVersion: 1, podName: "podname", containerName: "containername", - resource: latestV1.PortForwardResource{ + resource: latest.PortForwardResource{ Type: "pod", Name: "podname", Namespace: "namespace", @@ -100,7 +100,7 @@ func TestAutomaticPortForwardPod(t *testing.T) { "owner-containername-namespace-portname-8080": { resourceVersion: 1, podName: "podname", - resource: latestV1.PortForwardResource{ + resource: latest.PortForwardResource{ Type: "pod", Name: "podname", Namespace: "namespace", @@ -176,7 +176,7 @@ func TestAutomaticPortForwardPod(t *testing.T) { resourceVersion: 1, podName: "podname", containerName: "containername", - resource: latestV1.PortForwardResource{ + resource: latest.PortForwardResource{ Type: "pod", Name: "podname", Namespace: "namespace", @@ -193,7 +193,7 @@ func TestAutomaticPortForwardPod(t *testing.T) { resourceVersion: 1, podName: "podname2", containerName: "containername2", - resource: latestV1.PortForwardResource{ + resource: latest.PortForwardResource{ Type: "pod", Name: "podname2", Namespace: "namespace2", @@ -260,7 +260,7 @@ func TestAutomaticPortForwardPod(t *testing.T) { podName: "podname", containerName: "containername", portName: "portname", - resource: latestV1.PortForwardResource{ + resource: latest.PortForwardResource{ Type: "pod", Name: "podname", Namespace: "namespace", @@ -277,7 +277,7 @@ func TestAutomaticPortForwardPod(t *testing.T) { podName: "podname2", containerName: "containername2", portName: "portname2", - resource: latestV1.PortForwardResource{ + resource: latest.PortForwardResource{ Type: "pod", Name: "podname2", Namespace: "namespace2", @@ -343,7 +343,7 @@ func TestAutomaticPortForwardPod(t *testing.T) { podName: "podname", containerName: "containername", portName: "portname", - resource: latestV1.PortForwardResource{ + resource: latest.PortForwardResource{ Type: "pod", Name: "podname", Namespace: "namespace", @@ -402,7 +402,7 @@ func TestAutomaticPortForwardPod(t *testing.T) { } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - testEvent.InitializeState([]latestV1.Pipeline{{}}) + testEvent.InitializeState([]latest.Pipeline{{}}) taken := map[int]struct{}{} t.Override(&retrieveAvailablePort, mockRetrieveAvailablePort(util.Loopback, taken, test.availablePorts)) t.Override(&topLevelOwnerKey, func(context.Context, metav1.Object, string, string) string { return "owner" }) @@ -479,7 +479,7 @@ func TestStartPodForwarder(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - testEvent.InitializeState([]latestV1.Pipeline{{}}) + testEvent.InitializeState([]latest.Pipeline{{}}) t.Override(&topLevelOwnerKey, func(context.Context, metav1.Object, string, string) string { return "owner" }) t.Override(&newPodWatcher, func(kubernetes.PodSelector) kubernetes.PodWatcher { return &fakePodWatcher{ diff --git a/pkg/skaffold/kubernetes/portforward/port_forward_entry.go b/pkg/skaffold/kubernetes/portforward/port_forward_entry.go index 85839ea1d41..c83b95adf47 100644 --- a/pkg/skaffold/kubernetes/portforward/port_forward_entry.go +++ b/pkg/skaffold/kubernetes/portforward/port_forward_entry.go @@ -22,12 +22,12 @@ import ( "strings" "sync" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) type portForwardEntry struct { resourceVersion int - resource latestV1.PortForwardResource + resource latest.PortForwardResource podName string containerName string portName string @@ -40,7 +40,7 @@ type portForwardEntry struct { } // newPortForwardEntry returns a port forward entry. -func newPortForwardEntry(resourceVersion int, resource latestV1.PortForwardResource, podName, containerName, portName, ownerReference string, localPort int, automaticPodForwarding bool) *portForwardEntry { +func newPortForwardEntry(resourceVersion int, resource latest.PortForwardResource, podName, containerName, portName, ownerReference string, localPort int, automaticPodForwarding bool) *portForwardEntry { return &portForwardEntry{ resourceVersion: resourceVersion, resource: resource, diff --git a/pkg/skaffold/kubernetes/portforward/port_forward_entry_test.go b/pkg/skaffold/kubernetes/portforward/port_forward_entry_test.go index 57396dcec68..1f44f6f0a1c 100644 --- a/pkg/skaffold/kubernetes/portforward/port_forward_entry_test.go +++ b/pkg/skaffold/kubernetes/portforward/port_forward_entry_test.go @@ -20,7 +20,7 @@ import ( "strings" "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" schemautil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -33,7 +33,7 @@ func TestPortForwardEntryKey(t *testing.T) { }{ { description: "entry for pod", - pfe: newPortForwardEntry(0, latestV1.PortForwardResource{ + pfe: newPortForwardEntry(0, latest.PortForwardResource{ Type: "pod", Name: "podName", Namespace: "default", @@ -42,7 +42,7 @@ func TestPortForwardEntryKey(t *testing.T) { expected: "pod-podName-default-8080", }, { description: "entry for deploy", - pfe: newPortForwardEntry(0, latestV1.PortForwardResource{ + pfe: newPortForwardEntry(0, latest.PortForwardResource{ Type: "deployment", Name: "depName", Namespace: "namespace", @@ -51,7 +51,7 @@ func TestPortForwardEntryKey(t *testing.T) { expected: "deployment-depName-namespace-9000", }, { description: "entry for deployment with capital normalization", - pfe: newPortForwardEntry(0, latestV1.PortForwardResource{ + pfe: newPortForwardEntry(0, latest.PortForwardResource{ Type: "Deployment", Name: "depName", Namespace: "namespace", @@ -84,7 +84,7 @@ func TestAutomaticPodForwardingKey(t *testing.T) { }{ { description: "entry for automatically port forwarded pod", - pfe: newPortForwardEntry(0, latestV1.PortForwardResource{ + pfe: newPortForwardEntry(0, latest.PortForwardResource{ Type: "pod", Name: "podName", Namespace: "default", diff --git a/pkg/skaffold/kubernetes/portforward/port_forward_integration.go b/pkg/skaffold/kubernetes/portforward/port_forward_integration.go index de8ff1f18bb..ab98a6b9991 100644 --- a/pkg/skaffold/kubernetes/portforward/port_forward_integration.go +++ b/pkg/skaffold/kubernetes/portforward/port_forward_integration.go @@ -26,7 +26,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" schemautil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -40,7 +40,7 @@ func SimulateDevCycle(t *testing.T, kubectlCLI *kubectl.CLI, namespace string, l portForwardEvent = func(entry *portForwardEntry) {} ctx := context.Background() localPort := retrieveAvailablePort(util.Loopback, 9000, &em.forwardedPorts) - pfe := newPortForwardEntry(0, latestV1.PortForwardResource{ + pfe := newPortForwardEntry(0, latest.PortForwardResource{ Type: "deployment", Name: "leeroy-web", Namespace: namespace, diff --git a/pkg/skaffold/kubernetes/portforward/resource_forwarder.go b/pkg/skaffold/kubernetes/portforward/resource_forwarder.go index d1f6057f031..7cbc4f77660 100644 --- a/pkg/skaffold/kubernetes/portforward/resource_forwarder.go +++ b/pkg/skaffold/kubernetes/portforward/resource_forwarder.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" kubernetesclient "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" schemautil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -39,7 +39,7 @@ type ResourceForwarder struct { entryManager *EntryManager label string kubeContext string - userDefinedResources []*latestV1.PortForwardResource + userDefinedResources []*latest.PortForwardResource services bool } @@ -60,7 +60,7 @@ func NewServicesForwarder(entryManager *EntryManager, kubeContext string, label } // NewUserDefinedForwarder returns a struct that tracks and port-forwards services as they are created and modified -func NewUserDefinedForwarder(entryManager *EntryManager, kubeContext string, userDefinedResources []*latestV1.PortForwardResource) *ResourceForwarder { +func NewUserDefinedForwarder(entryManager *EntryManager, kubeContext string, userDefinedResources []*latest.PortForwardResource) *ResourceForwarder { return &ResourceForwarder{ entryManager: entryManager, kubeContext: kubeContext, @@ -68,7 +68,7 @@ func NewUserDefinedForwarder(entryManager *EntryManager, kubeContext string, use } } -// Start gets a list of services deployed by skaffold as []latestV1.PortForwardResource and +// Start gets a list of services deployed by skaffold as []latest.PortForwardResource and // forwards them. func (p *ResourceForwarder) Start(ctx context.Context, out io.Writer, namespaces []string) error { p.output = out @@ -82,7 +82,7 @@ func (p *ResourceForwarder) Start(ctx context.Context, out io.Writer, namespaces } } } else { - var validResources []*latestV1.PortForwardResource + var validResources []*latest.PortForwardResource for _, pf := range p.userDefinedResources { if pf.Namespace != "" { if err := applyWithTemplate(pf); err != nil { @@ -96,7 +96,7 @@ func (p *ResourceForwarder) Start(ctx context.Context, out io.Writer, namespaces p.userDefinedResources = validResources } - var serviceResources []*latestV1.PortForwardResource + var serviceResources []*latest.PortForwardResource if p.services { found, err := retrieveServices(ctx, p.label, namespaces, p.kubeContext) if err != nil { @@ -108,7 +108,7 @@ func (p *ResourceForwarder) Start(ctx context.Context, out io.Writer, namespaces return nil } -func applyWithTemplate(resource *latestV1.PortForwardResource) error { +func applyWithTemplate(resource *latest.PortForwardResource) error { if resource.Namespace != "" { namespace, err := util.ExpandEnvTemplateOrFail(resource.Namespace, nil) if err != nil { @@ -129,11 +129,11 @@ func (p *ResourceForwarder) Stop() { } // Port forward each resource individually in a goroutine -func (p *ResourceForwarder) portForwardResources(ctx context.Context, resources []*latestV1.PortForwardResource) { +func (p *ResourceForwarder) portForwardResources(ctx context.Context, resources []*latest.PortForwardResource) { var wg sync.WaitGroup for _, r := range resources { wg.Add(1) - go func(r latestV1.PortForwardResource) { + go func(r latest.PortForwardResource) { defer wg.Done() p.portForwardResource(ctx, r) }(*r) @@ -141,14 +141,14 @@ func (p *ResourceForwarder) portForwardResources(ctx context.Context, resources wg.Wait() } -func (p *ResourceForwarder) portForwardResource(ctx context.Context, resource latestV1.PortForwardResource) { +func (p *ResourceForwarder) portForwardResource(ctx context.Context, resource latest.PortForwardResource) { // Get port forward entry for this resource entry := p.getCurrentEntry(resource) // Forward the entry p.entryManager.forwardPortForwardEntry(ctx, p.output, entry) } -func (p *ResourceForwarder) getCurrentEntry(resource latestV1.PortForwardResource) *portForwardEntry { +func (p *ResourceForwarder) getCurrentEntry(resource latest.PortForwardResource) *portForwardEntry { // determine if we have seen this before entry := newPortForwardEntry(0, resource, "", "", "", "", 0, false) @@ -172,13 +172,13 @@ func (p *ResourceForwarder) getCurrentEntry(resource latestV1.PortForwardResourc // retrieveServiceResources retrieves all services in the cluster matching the given label // as a list of PortForwardResources -func retrieveServiceResources(ctx context.Context, label string, namespaces []string, kubeContext string) ([]*latestV1.PortForwardResource, error) { +func retrieveServiceResources(ctx context.Context, label string, namespaces []string, kubeContext string) ([]*latest.PortForwardResource, error) { client, err := kubernetesclient.Client(kubeContext) if err != nil { return nil, fmt.Errorf("getting Kubernetes client: %w", err) } - var resources []*latestV1.PortForwardResource + var resources []*latest.PortForwardResource for _, ns := range namespaces { services, err := client.CoreV1().Services(ns).List(ctx, metav1.ListOptions{ LabelSelector: label, @@ -188,7 +188,7 @@ func retrieveServiceResources(ctx context.Context, label string, namespaces []st } for _, s := range services.Items { for _, p := range s.Spec.Ports { - resources = append(resources, &latestV1.PortForwardResource{ + resources = append(resources, &latest.PortForwardResource{ Type: constants.Service, Name: s.Name, Namespace: s.Namespace, diff --git a/pkg/skaffold/kubernetes/portforward/resource_forwarder_test.go b/pkg/skaffold/kubernetes/portforward/resource_forwarder_test.go index 1aa04d8d821..f00ed254be4 100644 --- a/pkg/skaffold/kubernetes/portforward/resource_forwarder_test.go +++ b/pkg/skaffold/kubernetes/portforward/resource_forwarder_test.go @@ -36,7 +36,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/label" kubernetesclient "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" schemautil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" @@ -86,14 +86,14 @@ func mockRetrieveAvailablePort(_ string, taken map[int]struct{}, availablePorts } func TestStart(t *testing.T) { - svc1 := &latestV1.PortForwardResource{ + svc1 := &latest.PortForwardResource{ Type: constants.Service, Name: "svc1", Namespace: "default", Port: schemautil.FromInt(8080), } - svc2 := &latestV1.PortForwardResource{ + svc2 := &latest.PortForwardResource{ Type: constants.Service, Name: "svc2", Namespace: "default", @@ -102,13 +102,13 @@ func TestStart(t *testing.T) { tests := []struct { description string - resources []*latestV1.PortForwardResource + resources []*latest.PortForwardResource availablePorts []int expected map[string]*portForwardEntry }{ { description: "forward two services", - resources: []*latestV1.PortForwardResource{svc1, svc2}, + resources: []*latest.PortForwardResource{svc1, svc2}, availablePorts: []int{8080, 9000}, expected: map[string]*portForwardEntry{ "service-svc1-default-8080": { @@ -124,9 +124,9 @@ func TestStart(t *testing.T) { } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - testEvent.InitializeState([]latestV1.Pipeline{{}}) + testEvent.InitializeState([]latest.Pipeline{{}}) t.Override(&retrieveAvailablePort, mockRetrieveAvailablePort(util.Loopback, map[int]struct{}{}, test.availablePorts)) - t.Override(&retrieveServices, func(context.Context, string, []string, string) ([]*latestV1.PortForwardResource, error) { + t.Override(&retrieveServices, func(context.Context, string, []string, string) ([]*latest.PortForwardResource, error) { return test.resources, nil }) @@ -154,33 +154,33 @@ func TestGetCurrentEntryFunc(t *testing.T) { description string forwardedResources map[string]*portForwardEntry availablePorts []int - resource latestV1.PortForwardResource + resource latest.PortForwardResource expectedReq int expected *portForwardEntry }{ { description: "port forward service", - resource: latestV1.PortForwardResource{ + resource: latest.PortForwardResource{ Type: "service", Name: "serviceName", Port: schemautil.FromInt(8080), }, availablePorts: []int{8080}, expectedReq: 8080, - expected: newPortForwardEntry(0, latestV1.PortForwardResource{}, "", "", "", "", 8080, false), + expected: newPortForwardEntry(0, latest.PortForwardResource{}, "", "", "", "", 8080, false), }, { description: "should not request system ports (1-1023)", - resource: latestV1.PortForwardResource{ + resource: latest.PortForwardResource{ Type: "service", Name: "serviceName", Port: schemautil.FromInt(80), }, availablePorts: []int{8080}, expectedReq: 0, // no local port requested as port 80 is a system port - expected: newPortForwardEntry(0, latestV1.PortForwardResource{}, "", "", "", "", 8080, false), + expected: newPortForwardEntry(0, latest.PortForwardResource{}, "", "", "", "", 8080, false), }, { description: "port forward existing deployment", - resource: latestV1.PortForwardResource{ + resource: latest.PortForwardResource{ Type: "deployment", Namespace: "default", Name: "depName", @@ -188,7 +188,7 @@ func TestGetCurrentEntryFunc(t *testing.T) { }, forwardedResources: map[string]*portForwardEntry{ "deployment-depName-default-8080": { - resource: latestV1.PortForwardResource{ + resource: latest.PortForwardResource{ Type: "deployment", Namespace: "default", Name: "depName", @@ -198,7 +198,7 @@ func TestGetCurrentEntryFunc(t *testing.T) { }, }, expectedReq: -1, // retrieveAvailablePort should not be called as there is an assigned localPort - expected: newPortForwardEntry(0, latestV1.PortForwardResource{}, "", "", "", "", 9000, false), + expected: newPortForwardEntry(0, latest.PortForwardResource{}, "", "", "", "", 9000, false), }, } @@ -225,7 +225,7 @@ func TestGetCurrentEntryFunc(t *testing.T) { } func TestUserDefinedResources(t *testing.T) { - svc := &latestV1.PortForwardResource{ + svc := &latest.PortForwardResource{ Type: constants.Service, Name: "svc1", Namespace: "test", @@ -234,13 +234,13 @@ func TestUserDefinedResources(t *testing.T) { tests := []struct { description string - userResources []*latestV1.PortForwardResource + userResources []*latest.PortForwardResource namespaces []string expectedResources []string }{ { description: "pod should be found", - userResources: []*latestV1.PortForwardResource{ + userResources: []*latest.PortForwardResource{ {Type: constants.Pod, Name: "pod", Port: schemautil.FromInt(9000)}, }, namespaces: []string{"test"}, @@ -250,14 +250,14 @@ func TestUserDefinedResources(t *testing.T) { }, { description: "pod not available", - userResources: []*latestV1.PortForwardResource{ + userResources: []*latest.PortForwardResource{ {Type: constants.Pod, Name: "pod", Port: schemautil.FromInt(9000)}, }, namespaces: []string{"test", "some"}, expectedResources: []string{}, }, { - userResources: []*latestV1.PortForwardResource{ + userResources: []*latest.PortForwardResource{ {Type: constants.Pod, Name: "pod", Port: schemautil.FromInt(9000)}, {Type: constants.Pod, Name: "pod", Namespace: "some", Port: schemautil.FromInt(9001)}, }, @@ -268,7 +268,7 @@ func TestUserDefinedResources(t *testing.T) { }, { description: "pod should be found with namespace with template", - userResources: []*latestV1.PortForwardResource{ + userResources: []*latest.PortForwardResource{ {Type: constants.Pod, Name: "pod", Namespace: "some-with-template-{{ .FOO }}", Port: schemautil.FromInt(9000)}, }, namespaces: []string{"test"}, @@ -278,7 +278,7 @@ func TestUserDefinedResources(t *testing.T) { }, { description: "pod should be found with namespace with template", - userResources: []*latestV1.PortForwardResource{ + userResources: []*latest.PortForwardResource{ {Type: constants.Pod, Name: "pod", Namespace: "some-with-template-{{ .FOO }}", Port: schemautil.FromInt(9000)}, }, namespaces: []string{"test", "another"}, @@ -288,7 +288,7 @@ func TestUserDefinedResources(t *testing.T) { }, { description: "pod should be found with name with template", - userResources: []*latestV1.PortForwardResource{ + userResources: []*latest.PortForwardResource{ {Type: constants.Pod, Name: "pod-{{ .FOO }}", Port: schemautil.FromInt(9000)}, }, namespaces: []string{"test"}, @@ -298,7 +298,7 @@ func TestUserDefinedResources(t *testing.T) { }, { description: "pod should be found with name with template", - userResources: []*latestV1.PortForwardResource{ + userResources: []*latest.PortForwardResource{ {Type: constants.Pod, Name: "pod-{{ .FOO }}", Namespace: "some-ns", Port: schemautil.FromInt(9000)}, }, namespaces: []string{"test", "another"}, @@ -310,10 +310,10 @@ func TestUserDefinedResources(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - testEvent.InitializeState([]latestV1.Pipeline{{}}) + testEvent.InitializeState([]latest.Pipeline{{}}) t.Override(&retrieveAvailablePort, mockRetrieveAvailablePort(util.Loopback, map[int]struct{}{}, []int{8080, 9000})) - t.Override(&retrieveServices, func(context.Context, string, []string, string) ([]*latestV1.PortForwardResource, error) { - return []*latestV1.PortForwardResource{svc}, nil + t.Override(&retrieveServices, func(context.Context, string, []string, string) ([]*latest.PortForwardResource, error) { + return []*latest.PortForwardResource{svc}, nil }) fakeForwarder := newTestForwarder() @@ -355,7 +355,7 @@ func TestRetrieveServices(t *testing.T) { description string namespaces []string services []*v1.Service - expected []*latestV1.PortForwardResource + expected []*latest.PortForwardResource }{ { description: "multiple services in multiple namespaces", @@ -381,7 +381,7 @@ func TestRetrieveServices(t *testing.T) { Spec: v1.ServiceSpec{Ports: []v1.ServicePort{{Port: 8081}}}, }, }, - expected: []*latestV1.PortForwardResource{{ + expected: []*latest.PortForwardResource{{ Type: constants.Service, Name: "svc1", Namespace: "test", diff --git a/pkg/skaffold/kubernetes/status/resource/deployment_test.go b/pkg/skaffold/kubernetes/status/resource/deployment_test.go index d9e7c39f822..e8c2fcb3eb3 100644 --- a/pkg/skaffold/kubernetes/status/resource/deployment_test.go +++ b/pkg/skaffold/kubernetes/status/resource/deployment_test.go @@ -29,7 +29,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/diag/validator" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/proto/v1" "github.com/GoogleContainerTools/skaffold/testutil" @@ -105,7 +105,7 @@ func TestDeploymentCheckStatus(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { t.Override(&util.DefaultExecCommand, test.commands) - testEvent.InitializeState([]latestV1.Pipeline{{}}) + testEvent.InitializeState([]latest.Pipeline{{}}) r := NewResource("graph", ResourceTypes.Deployment, "test", 0) r.CheckStatus(context.Background(), &statusConfig{}) diff --git a/pkg/skaffold/kubernetes/status/status_check_test.go b/pkg/skaffold/kubernetes/status/status_check_test.go index 2109eea17a3..18a5b8b7e6a 100644 --- a/pkg/skaffold/kubernetes/status/status_check_test.go +++ b/pkg/skaffold/kubernetes/status/status_check_test.go @@ -37,7 +37,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/label" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/status/resource" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/proto/v1" "github.com/GoogleContainerTools/skaffold/testutil" @@ -377,7 +377,7 @@ func TestPrintSummaryStatus(t *testing.T) { out := new(bytes.Buffer) rc := newCounter(10) rc.pending = test.pending - testEvent.InitializeState([]latestV1.Pipeline{{}}) + testEvent.InitializeState([]latest.Pipeline{{}}) r := withStatus(resource.NewResource(test.deployment, resource.ResourceTypes.Deployment, test.namespace, 0), test.ae) // report status once and set it changed to false. r.ReportSinceLastUpdated(false) @@ -467,7 +467,7 @@ func TestPrintStatus(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { out := new(bytes.Buffer) - testEvent.InitializeState([]latestV1.Pipeline{{}}) + testEvent.InitializeState([]latest.Pipeline{{}}) monitor := monitor{labeller: labeller} actual := monitor.printStatus(test.rs, out) t.CheckDeepEqual(test.expectedOut, out.String()) @@ -604,7 +604,7 @@ func TestPollDeployment(t *testing.T) { testutil.Run(t, test.description, func(t *testutil.T) { t.Override(&util.DefaultExecCommand, test.command) t.Override(&defaultPollPeriodInMilliseconds, 100) - testEvent.InitializeState([]latestV1.Pipeline{{}}) + testEvent.InitializeState([]latest.Pipeline{{}}) mockVal := mockValidator{runs: test.runs} dep := test.dep.WithValidator(mockVal) diff --git a/pkg/skaffold/lint/dockerfiles_test.go b/pkg/skaffold/lint/dockerfiles_test.go index 65a60b45788..e2ab4050817 100644 --- a/pkg/skaffold/lint/dockerfiles_test.go +++ b/pkg/skaffold/lint/dockerfiles_test.go @@ -29,7 +29,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -205,10 +205,10 @@ func TestGetDockerfilesLintResults(t *testing.T) { if err != nil { t.Fatalf("error creating Dockerfile %s: %v", dfp, err) } - configSet = append(configSet, &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: module}, - Pipeline: v1.Pipeline{Build: v1.BuildConfig{Artifacts: []*v1.Artifact{{Workspace: "", - ArtifactType: v1.ArtifactType{DockerArtifact: &v1.DockerArtifact{DockerfilePath: dfp}}}}}}, + configSet = append(configSet, &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: module}, + Pipeline: latest.Pipeline{Build: latest.BuildConfig{Artifacts: []*latest.Artifact{{Workspace: "", + ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{DockerfilePath: dfp}}}}}}, }, SourceFile: fp, }) diff --git a/pkg/skaffold/lint/k8smanifests_test.go b/pkg/skaffold/lint/k8smanifests_test.go index 92c25f4f5d5..126afe6f110 100644 --- a/pkg/skaffold/lint/k8smanifests_test.go +++ b/pkg/skaffold/lint/k8smanifests_test.go @@ -25,7 +25,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -134,15 +134,15 @@ func TestGetK8sManifestsLintResults(t *testing.T) { t.Fatalf("error creating deployment.yaml %s: %v", mp, err) } if test.k8sManifestIsNil { - configSet = append(configSet, &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: module}, - Pipeline: v1.Pipeline{}, + configSet = append(configSet, &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: module}, + Pipeline: latest.Pipeline{}, }, }) } else { - configSet = append(configSet, &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: module}, - Pipeline: v1.Pipeline{Deploy: v1.DeployConfig{DeployType: v1.DeployType{KubectlDeploy: &v1.KubectlDeploy{Manifests: []string{mp}}}}}, + configSet = append(configSet, &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: module}, + Pipeline: latest.Pipeline{Deploy: latest.DeployConfig{DeployType: latest.DeployType{KubectlDeploy: &latest.KubectlDeploy{Manifests: []string{mp}}}}}, }, }) } diff --git a/pkg/skaffold/lint/skaffoldyamls_test.go b/pkg/skaffold/lint/skaffoldyamls_test.go index 42fc0ee7138..5bbf4c7d695 100644 --- a/pkg/skaffold/lint/skaffoldyamls_test.go +++ b/pkg/skaffold/lint/skaffoldyamls_test.go @@ -25,7 +25,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -203,9 +203,9 @@ func TestGetSkaffoldYamlsLintResults(t *testing.T) { if err != nil { t.Fatalf("error creating deployment.yaml file with name %s: %v", fp, err) } - configSet = append(configSet, &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: module}, - Pipeline: v1.Pipeline{Deploy: v1.DeployConfig{DeployType: v1.DeployType{KubectlDeploy: &v1.KubectlDeploy{Manifests: []string{ + configSet = append(configSet, &parser.SkaffoldConfigEntry{SkaffoldConfig: &latest.SkaffoldConfig{ + Metadata: latest.Metadata{Name: module}, + Pipeline: latest.Pipeline{Deploy: latest.DeployConfig{DeployType: latest.DeployType{KubectlDeploy: &latest.KubectlDeploy{Manifests: []string{ mp, }}}}}, }, diff --git a/pkg/skaffold/log/formatter.go b/pkg/skaffold/log/formatter.go index 07845d07d8f..cbe46077a40 100644 --- a/pkg/skaffold/log/formatter.go +++ b/pkg/skaffold/log/formatter.go @@ -24,7 +24,7 @@ import ( "strings" olog "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) type Formatter interface { @@ -33,7 +33,7 @@ type Formatter interface { PrintLine(io.Writer, string) } -func ParseJSON(config latestV1.JSONParseConfig, line string) string { +func ParseJSON(config latest.JSONParseConfig, line string) string { if len(config.Fields) == 0 { return line } diff --git a/pkg/skaffold/log/formatter_test.go b/pkg/skaffold/log/formatter_test.go index fd3d8529341..feb5f7892e0 100644 --- a/pkg/skaffold/log/formatter_test.go +++ b/pkg/skaffold/log/formatter_test.go @@ -19,44 +19,44 @@ package log import ( "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) func TestParseJson(t *testing.T) { tests := []struct { name string - config latestV1.JSONParseConfig + config latest.JSONParseConfig line string expected string }{ { name: "standard json parse", - config: latestV1.JSONParseConfig{Fields: []string{"message", "severity", "timestampSeconds"}}, + config: latest.JSONParseConfig{Fields: []string{"message", "severity", "timestampSeconds"}}, line: "{\"timestampSeconds\":1643740871,\"timestampNanos\":446000000,\"severity\":\"INFO\",\"message\":\"Hello World\"}\n", expected: "message: Hello World, severity: INFO, timestampSeconds: 1.643740871e+09\n", }, { name: "mix of found and not found fields", - config: latestV1.JSONParseConfig{Fields: []string{"message", "severity", "invalid"}}, + config: latest.JSONParseConfig{Fields: []string{"message", "severity", "invalid"}}, line: "{\"timestampSeconds\":1643740871,\"timestampNanos\":446000000,\"severity\":\"INFO\",\"message\":\"Hello World\"}\n", expected: "message: Hello World, severity: INFO\n", }, { name: "all specified fields not found in json object", - config: latestV1.JSONParseConfig{Fields: []string{"invalid"}}, + config: latest.JSONParseConfig{Fields: []string{"invalid"}}, line: "{\"valid\":\"Hello World\"}\n", expected: "{\"valid\":\"Hello World\"}\n", }, { name: "non json line input", - config: latestV1.JSONParseConfig{Fields: []string{"message", "severity"}}, + config: latest.JSONParseConfig{Fields: []string{"message", "severity"}}, line: "Hello World!\n", expected: "Hello World!\n", }, { name: "json input with no config", - config: latestV1.JSONParseConfig{}, + config: latest.JSONParseConfig{}, line: "{\"timestampSeconds\":1643740871,\"timestampNanos\":446000000,\"severity\":\"INFO\",\"message\":\"Hello World\"}\n", expected: "{\"timestampSeconds\":1643740871,\"timestampNanos\":446000000,\"severity\":\"INFO\",\"message\":\"Hello World\"}\n", }, diff --git a/pkg/skaffold/parser/config.go b/pkg/skaffold/parser/config.go index d08e3e556b1..363919e79c5 100644 --- a/pkg/skaffold/parser/config.go +++ b/pkg/skaffold/parser/config.go @@ -32,7 +32,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema" "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" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" schemaUtil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/tags" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" @@ -134,7 +134,7 @@ func getConfigs(ctx context.Context, cfgOpts configOpts, opts config.SkaffoldOpt // add profiles to record and validate that config names are unique if specified seen := make(map[string]bool) for _, cfg := range parsed { - config := cfg.(*latestV1.SkaffoldConfig) + config := cfg.(*latest.SkaffoldConfig) for _, profile := range config.Profiles { if !stringslice.Contains(r.allProfiles, profile.Name) { r.allProfiles = append(r.allProfiles, profile.Name) @@ -153,7 +153,7 @@ func getConfigs(ctx context.Context, cfgOpts configOpts, opts config.SkaffoldOpt var configs SkaffoldConfigSet for i, cfg := range parsed { - config := cfg.(*latestV1.SkaffoldConfig) + config := cfg.(*latest.SkaffoldConfig) processed, err := processEachConfig(ctx, config, cfgOpts, opts, r, i, fieldsOverrodeByProfile) if err != nil { return nil, nil, err @@ -165,7 +165,7 @@ func getConfigs(ctx context.Context, cfgOpts configOpts, opts config.SkaffoldOpt // processEachConfig processes each parsed config by applying profiles and recursively processing its dependencies. // The `index` parameter specifies the index of the current config in its `skaffold.yaml` file. We use the `index` instead of the config `metadata.name` property to uniquely identify each config since not all configs define `name`. -func processEachConfig(ctx context.Context, config *latestV1.SkaffoldConfig, cfgOpts configOpts, opts config.SkaffoldOptions, r *record, index int, fieldsOverrodeByProfile map[string]configlocations.YAMLOverrideInfo) (SkaffoldConfigSet, error) { +func processEachConfig(ctx context.Context, config *latest.SkaffoldConfig, cfgOpts configOpts, opts config.SkaffoldOptions, r *record, index int, fieldsOverrodeByProfile map[string]configlocations.YAMLOverrideInfo) (SkaffoldConfigSet, error) { // check that the same config name isn't repeated in multiple files. if config.Metadata.Name != "" { prevConfig, found := r.configNameToFile[config.Metadata.Name] @@ -248,7 +248,7 @@ func processEachConfig(ctx context.Context, config *latestV1.SkaffoldConfig, cfg } // filterActiveProfiles selects the set of profiles to activate in the dependency config based on the current set of active profiles. -func filterActiveProfiles(d latestV1.ConfigDependency, profiles []string) []string { +func filterActiveProfiles(d latest.ConfigDependency, profiles []string) []string { var depProfiles []string for _, ap := range d.ActiveProfiles { if len(ap.ActivatedBy) == 0 { @@ -266,7 +266,7 @@ func filterActiveProfiles(d latestV1.ConfigDependency, profiles []string) []stri } // processEachDependency parses a config dependency with the calculated set of activated profiles. -func processEachDependency(ctx context.Context, d latestV1.ConfigDependency, cfgOpts configOpts, opts config.SkaffoldOptions, r *record) (SkaffoldConfigSet, error) { +func processEachDependency(ctx context.Context, d latest.ConfigDependency, cfgOpts configOpts, opts config.SkaffoldOptions, r *record) (SkaffoldConfigSet, error) { path := makeConfigPathAbsolute(d.Path, cfgOpts.file) if d.GitRepo != nil { @@ -307,7 +307,7 @@ func processEachDependency(ctx context.Context, d latestV1.ConfigDependency, cfg } // cacheRepo downloads the referenced git repository to skaffold's cache if required and returns the path to the target configuration file in that repository. -func cacheRepo(ctx context.Context, g latestV1.GitInfo, opts config.SkaffoldOptions, r *record) (string, error) { +func cacheRepo(ctx context.Context, g latest.GitInfo, opts config.SkaffoldOptions, r *record) (string, error) { key := fmt.Sprintf("%s@%s", g.Repo, g.Ref) if p, found := r.cachedRepos[key]; found { switch v := p.(type) { @@ -332,7 +332,7 @@ func cacheRepo(ctx context.Context, g latestV1.GitInfo, opts config.SkaffoldOpti // checkRevisit ensures that each config is activated with the same set of active profiles // It returns true if this config was visited once before. It additionally returns an error if the previous visit was with a different set of active profiles. -func checkRevisit(config *latestV1.SkaffoldConfig, profiles []string, appliedProfiles map[string]string, file string, required bool, index int) (bool, error) { +func checkRevisit(config *latest.SkaffoldConfig, profiles []string, appliedProfiles map[string]string, file string, required bool, index int) (bool, error) { key := fmt.Sprintf("%s:%d:%t", file, index, required) expected := strings.Join(profiles, ",") // including `required` in the key implies that we search this dependency tree once for a possible match of required named configs, but also again if the current config is itself required which makes all subsequent configs also required. diff --git a/pkg/skaffold/parser/config_test.go b/pkg/skaffold/parser/config_test.go index 913a723cbb0..6c1aa0bcfa8 100644 --- a/pkg/skaffold/parser/config_test.go +++ b/pkg/skaffold/parser/config_test.go @@ -31,7 +31,7 @@ import ( sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/git" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser/configlocations" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" schemaUtil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/proto/v1" @@ -60,18 +60,18 @@ profiles: ` ) -func createCfg(name string, imageName string, workspace string, requires []latestV1.ConfigDependency) *latestV1.SkaffoldConfig { - return &latestV1.SkaffoldConfig{ - APIVersion: latestV1.Version, +func createCfg(name string, imageName string, workspace string, requires []latest.ConfigDependency) *latest.SkaffoldConfig { + return &latest.SkaffoldConfig{ + APIVersion: latest.Version, Kind: "Config", Dependencies: requires, - Metadata: latestV1.Metadata{Name: name}, - Pipeline: latestV1.Pipeline{Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{{ImageName: imageName, ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{DockerfilePath: "Dockerfile"}}, Workspace: workspace}}, TagPolicy: latestV1.TagPolicy{ - GitTagger: &latestV1.GitTagger{}}, BuildType: latestV1.BuildType{ - LocalBuild: &latestV1.LocalBuild{}, - }}, Deploy: latestV1.DeployConfig{Logs: latestV1.LogsConfig{Prefix: "container"}}}, + Metadata: latest.Metadata{Name: name}, + Pipeline: latest.Pipeline{Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{{ImageName: imageName, ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{DockerfilePath: "Dockerfile"}}, Workspace: workspace}}, TagPolicy: latest.TagPolicy{ + GitTagger: &latest.GitTagger{}}, BuildType: latest.BuildType{ + LocalBuild: &latest.LocalBuild{}, + }}, Deploy: latest.DeployConfig{Logs: latest.LogsConfig{Prefix: "container"}}}, } } @@ -143,7 +143,7 @@ requires: 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"}}}), + createCfg("cfg00", "image00", ".", []latest.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}, {Path: "doc2", Names: []string{"cfg21"}}}), createCfg("cfg01", "image01", ".", nil), } }, @@ -166,8 +166,8 @@ requires: 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"}}}), + createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latest.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), + createCfg("cfg00", "image00", ".", []latest.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}}), createCfg("cfg01", "image01", ".", nil), } }, @@ -188,7 +188,7 @@ requires: 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"}}}), + createCfg("cfg00", "image00", ".", []latest.ConfigDependency{{Names: []string{"cfg01"}}, {Path: "doc2", Names: []string{"cfg21"}}}), } }, }, @@ -207,8 +207,8 @@ requires: 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"}}), + createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latest.ConfigDependency{{Names: []string{"cfg11"}}}), + createCfg("cfg00", "image00", ".", []latest.ConfigDependency{{Path: "doc1"}}), } }, }, @@ -233,9 +233,9 @@ requires: }, 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"}}}), + createCfg("cfg21", "image21", filepath.Join(base, "doc2"), []latest.ConfigDependency{{Path: base, Names: []string{"cfg00"}}}), + createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latest.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), + createCfg("cfg00", "image00", ".", []latest.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}}), createCfg("cfg01", "image01", ".", nil), } }, @@ -259,8 +259,8 @@ requires: 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"}}}), + createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latest.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), + createCfg("cfg00", "pf0image00", ".", []latest.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}}), createCfg("cfg01", "pf0image01", ".", nil), } }, @@ -290,8 +290,8 @@ requires: 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"}}}}}), + createCfg("cfg10", "pf0image10", filepath.Join(base, "doc1"), []latest.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}, ActiveProfiles: []latest.ProfileDependency{{Name: "pf0", ActivatedBy: []string{"pf0"}}}}}), + createCfg("cfg00", "pf0image00", ".", []latest.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}, ActiveProfiles: []latest.ProfileDependency{{Name: "pf0", ActivatedBy: []string{"pf0"}}}}}), createCfg("cfg01", "pf0image01", ".", nil), } }, @@ -318,8 +318,8 @@ requires: 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"}}}}), + createCfg("cfg10", "pf0image10", filepath.Join(base, "doc1"), []latest.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}, ActiveProfiles: []latest.ProfileDependency{{Name: "pf1"}}}}), + createCfg("cfg00", "image00", ".", []latest.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}, ActiveProfiles: []latest.ProfileDependency{{Name: "pf0"}}}}), createCfg("cfg01", "image01", ".", nil), } }, @@ -375,7 +375,7 @@ requires: 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"}}}), + createCfg("cfg11", "image11", filepath.Join(base, "doc1"), []latest.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), } }, }, @@ -454,9 +454,9 @@ requires: 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"}}}), - createCfg("cfg00", "image00", ".", []latestV1.ConfigDependency{{Path: "doc1"}}), + createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latest.ConfigDependency{{GitRepo: &latest.GitInfo{Repo: "doc2", Path: "skaffold.yaml", Ref: "main"}, Names: []string{"cfg21"}}}), + createCfg("cfg11", "image11", filepath.Join(base, "doc1"), []latest.ConfigDependency{{GitRepo: &latest.GitInfo{Repo: "doc2", Ref: "main"}, Names: []string{"cfg21"}}}), + createCfg("cfg00", "image00", ".", []latest.ConfigDependency{{Path: "doc1"}}), createCfg("cfg01", "image01", ".", nil), } }, @@ -512,7 +512,7 @@ requires: 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"}}}), + createCfg("cfg00", "image00", ".", []latest.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}, {Path: "doc2", Names: []string{"cfg21"}}}), createCfg("cfg01", "image01", ".", nil), } }, @@ -536,8 +536,8 @@ requires: 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"}}}), + createCfg("cfg10", "image10", ".", []latest.ConfigDependency{{Path: "../doc2", Names: []string{"cfg21"}}}), + createCfg("cfg00", "image00", ".", []latest.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}}), createCfg("cfg01", "image01", ".", nil), } }, @@ -559,7 +559,7 @@ requires: return []schemaUtil.VersionedConfig{ createCfg("cfg01", "image01", ".", nil), createCfg("cfg21", "image21", ".", nil), - createCfg("cfg00", "image00", ".", []latestV1.ConfigDependency{{Names: []string{"cfg01"}}, {Path: "doc2", Names: []string{"cfg21"}}}), + createCfg("cfg00", "image00", ".", []latest.ConfigDependency{{Names: []string{"cfg01"}}, {Path: "doc2", Names: []string{"cfg21"}}}), } }, }, @@ -579,8 +579,8 @@ requires: 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"}}), + createCfg("cfg10", "image10", ".", []latest.ConfigDependency{{Names: []string{"cfg11"}}}), + createCfg("cfg00", "image00", ".", []latest.ConfigDependency{{Path: "doc1"}}), } }, }, @@ -606,9 +606,9 @@ requires: }, 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"}}}), + createCfg("cfg21", "image21", ".", []latest.ConfigDependency{{Path: "../", Names: []string{"cfg00"}}}), + createCfg("cfg10", "image10", ".", []latest.ConfigDependency{{Path: "../doc2", Names: []string{"cfg21"}}}), + createCfg("cfg00", "image00", ".", []latest.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}}), createCfg("cfg01", "image01", ".", nil), } }, @@ -633,8 +633,8 @@ requires: 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"}}}), + createCfg("cfg10", "image10", ".", []latest.ConfigDependency{{Path: "../doc2", Names: []string{"cfg21"}}}), + createCfg("cfg00", "pf0image00", ".", []latest.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}}), createCfg("cfg01", "pf0image01", ".", nil), } }, @@ -665,8 +665,8 @@ requires: 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"}}}}}), + createCfg("cfg10", "pf0image10", ".", []latest.ConfigDependency{{Path: "../doc2", Names: []string{"cfg21"}, ActiveProfiles: []latest.ProfileDependency{{Name: "pf0", ActivatedBy: []string{"pf0"}}}}}), + createCfg("cfg00", "pf0image00", ".", []latest.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}, ActiveProfiles: []latest.ProfileDependency{{Name: "pf0", ActivatedBy: []string{"pf0"}}}}}), createCfg("cfg01", "pf0image01", ".", nil), } }, @@ -694,8 +694,8 @@ requires: 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"}}}}), + createCfg("cfg10", "pf0image10", ".", []latest.ConfigDependency{{Path: "../doc2", Names: []string{"cfg21"}, ActiveProfiles: []latest.ProfileDependency{{Name: "pf1"}}}}), + createCfg("cfg00", "image00", ".", []latest.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}, ActiveProfiles: []latest.ProfileDependency{{Name: "pf0"}}}}), createCfg("cfg01", "image01", ".", nil), } }, @@ -753,7 +753,7 @@ requires: expected: func(string) []schemaUtil.VersionedConfig { return []schemaUtil.VersionedConfig{ createCfg("cfg21", "image21", ".", nil), - createCfg("cfg11", "image11", ".", []latestV1.ConfigDependency{{Path: "../doc2", Names: []string{"cfg21"}}}), + createCfg("cfg11", "image11", ".", []latest.ConfigDependency{{Path: "../doc2", Names: []string{"cfg21"}}}), } }, }, @@ -836,9 +836,9 @@ requires: 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"}}}), - createCfg("cfg00", "image00", ".", []latestV1.ConfigDependency{{Path: "doc1"}}), + createCfg("cfg10", "image10", ".", []latest.ConfigDependency{{GitRepo: &latest.GitInfo{Repo: "doc2", Path: "skaffold.yaml", Ref: "main"}, Names: []string{"cfg21"}}}), + createCfg("cfg11", "image11", ".", []latest.ConfigDependency{{GitRepo: &latest.GitInfo{Repo: "doc2", Ref: "main"}, Names: []string{"cfg21"}}}), + createCfg("cfg00", "image00", ".", []latest.ConfigDependency{{Path: "doc1"}}), createCfg("cfg01", "image01", ".", nil), } }, @@ -894,7 +894,7 @@ requires: 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"}}}), + createCfg("cfg00", "image00", base, []latest.ConfigDependency{{Path: filepath.Join(base, "doc1"), Names: []string{"cfg10"}}, {Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), createCfg("cfg01", "image01", base, nil), } }, @@ -918,8 +918,8 @@ requires: 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"}}}), + createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latest.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), + createCfg("cfg00", "image00", base, []latest.ConfigDependency{{Path: filepath.Join(base, "doc1"), Names: []string{"cfg10"}}}), createCfg("cfg01", "image01", base, nil), } }, @@ -941,7 +941,7 @@ requires: 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"}}}), + createCfg("cfg00", "image00", base, []latest.ConfigDependency{{Names: []string{"cfg01"}}, {Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), } }, }, @@ -961,8 +961,8 @@ requires: 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")}}), + createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latest.ConfigDependency{{Names: []string{"cfg11"}}}), + createCfg("cfg00", "image00", base, []latest.ConfigDependency{{Path: filepath.Join(base, "doc1")}}), } }, }, @@ -988,9 +988,9 @@ requires: }, 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"}}}), + createCfg("cfg21", "image21", filepath.Join(base, "doc2"), []latest.ConfigDependency{{Path: base, Names: []string{"cfg00"}}}), + createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latest.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), + createCfg("cfg00", "image00", base, []latest.ConfigDependency{{Path: filepath.Join(base, "doc1"), Names: []string{"cfg10"}}}), createCfg("cfg01", "image01", base, nil), } }, @@ -1015,8 +1015,8 @@ requires: 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"}}}), + createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latest.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), + createCfg("cfg00", "pf0image00", base, []latest.ConfigDependency{{Path: filepath.Join(base, "doc1"), Names: []string{"cfg10"}}}), createCfg("cfg01", "pf0image01", base, nil), } }, @@ -1047,8 +1047,8 @@ requires: 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"}}}}}), + createCfg("cfg10", "pf0image10", filepath.Join(base, "doc1"), []latest.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}, ActiveProfiles: []latest.ProfileDependency{{Name: "pf0", ActivatedBy: []string{"pf0"}}}}}), + createCfg("cfg00", "pf0image00", base, []latest.ConfigDependency{{Path: filepath.Join(base, "doc1"), Names: []string{"cfg10"}, ActiveProfiles: []latest.ProfileDependency{{Name: "pf0", ActivatedBy: []string{"pf0"}}}}}), createCfg("cfg01", "pf0image01", base, nil), } }, @@ -1076,8 +1076,8 @@ requires: 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"}}}}), + createCfg("cfg10", "pf0image10", filepath.Join(base, "doc1"), []latest.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}, ActiveProfiles: []latest.ProfileDependency{{Name: "pf1"}}}}), + createCfg("cfg00", "image00", base, []latest.ConfigDependency{{Path: filepath.Join(base, "doc1"), Names: []string{"cfg10"}, ActiveProfiles: []latest.ProfileDependency{{Name: "pf0"}}}}), createCfg("cfg01", "image01", base, nil), } }, @@ -1135,7 +1135,7 @@ requires: 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"}}}), + createCfg("cfg11", "image11", filepath.Join(base, "doc1"), []latest.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), } }, }, @@ -1218,9 +1218,9 @@ requires: 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"}}}), - createCfg("cfg00", "image00", base, []latestV1.ConfigDependency{{Path: filepath.Join(base, "doc1")}}), + createCfg("cfg10", "image10", filepath.Join(base, "doc1"), []latest.ConfigDependency{{GitRepo: &latest.GitInfo{Repo: "doc2", Path: "skaffold.yaml", Ref: "main"}, Names: []string{"cfg21"}}}), + createCfg("cfg11", "image11", filepath.Join(base, "doc1"), []latest.ConfigDependency{{GitRepo: &latest.GitInfo{Repo: "doc2", Ref: "main"}, Names: []string{"cfg21"}}}), + createCfg("cfg00", "image00", base, []latest.ConfigDependency{{Path: filepath.Join(base, "doc1")}}), createCfg("cfg01", "image01", base, nil), } }, @@ -1245,8 +1245,8 @@ requires: 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"}}}), + createCfg("cfg10", "pf0image10", filepath.Join(base, "doc1"), []latest.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), + createCfg("cfg00", "pf0image00", ".", []latest.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}}), createCfg("cfg01", "pf0image01", ".", nil), } }, @@ -1272,8 +1272,8 @@ requires: 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"}}}), + createCfg("cfg10", "pf0image10", ".", []latest.ConfigDependency{{Path: "../doc2", Names: []string{"cfg21"}}}), + createCfg("cfg00", "pf0image00", ".", []latest.ConfigDependency{{Path: "doc1", Names: []string{"cfg10"}}}), createCfg("cfg01", "pf0image01", ".", nil), } }, @@ -1299,8 +1299,8 @@ requires: 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"}}}), + createCfg("cfg10", "pf0image10", filepath.Join(base, "doc1"), []latest.ConfigDependency{{Path: filepath.Join(base, "doc2"), Names: []string{"cfg21"}}}), + createCfg("cfg00", "pf0image00", base, []latest.ConfigDependency{{Path: filepath.Join(base, "doc1"), Names: []string{"cfg10"}}}), createCfg("cfg01", "pf0image01", base, nil), } }, @@ -1313,7 +1313,7 @@ requires: var cfgs []string for j, c := range d.configs { id := fmt.Sprintf("%d%d", i, j) - s := fmt.Sprintf(template, latestV1.Version, c.name, c.requiresStanza, id, id, id) + s := fmt.Sprintf(template, latest.Version, c.name, c.requiresStanza, id, id, id) cfgs = append(cfgs, s) } tmpDir.Write(d.path, strings.Join(cfgs, "\n---\n")) @@ -1324,7 +1324,7 @@ requires: wd, _ := util.RealWorkDir() expected = test.expected(wd) } - t.Override(&git.SyncRepo, func(ctx context.Context, g latestV1.GitInfo, _ config.SkaffoldOptions) (string, error) { + t.Override(&git.SyncRepo, func(ctx context.Context, g latest.GitInfo, _ config.SkaffoldOptions) (string, error) { return g.Repo, nil }) cfgs, err := GetAllConfigs(context.Background(), config.SkaffoldOptions{ diff --git a/pkg/skaffold/parser/configlocations/configlocations.go b/pkg/skaffold/parser/configlocations/configlocations.go index ead0ebc58ad..3fdadabd756 100644 --- a/pkg/skaffold/parser/configlocations/configlocations.go +++ b/pkg/skaffold/parser/configlocations/configlocations.go @@ -26,7 +26,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/errors" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -87,7 +87,7 @@ type YAMLOverrideInfo struct { } // Parse parses a skaffold config entry collecting file location information for each schema config object -func Parse(sourceFile string, config *latestV1.SkaffoldConfig, fieldsOverrodeByProfile map[string]YAMLOverrideInfo) (*YAMLInfos, error) { +func Parse(sourceFile string, config *latest.SkaffoldConfig, fieldsOverrodeByProfile map[string]YAMLOverrideInfo) (*YAMLInfos, error) { yamlInfos, err := buildMapOfSchemaObjPointerToYAMLInfos(sourceFile, config, map[uintptr]map[string]YAMLInfo{}, fieldsOverrodeByProfile) return &YAMLInfos{ yamlInfos: yamlInfos, @@ -194,7 +194,7 @@ func getLinesAndColsOfString(str string) (int, int) { return line, col } -func buildMapOfSchemaObjPointerToYAMLInfos(sourceFile string, config *latestV1.SkaffoldConfig, yamlInfos map[uintptr]map[string]YAMLInfo, +func buildMapOfSchemaObjPointerToYAMLInfos(sourceFile string, config *latest.SkaffoldConfig, yamlInfos map[uintptr]map[string]YAMLInfo, fieldsOverrodeByProfile map[string]YAMLOverrideInfo) (map[uintptr]map[string]YAMLInfo, error) { skaffoldConfigText, err := util.ReadConfiguration(sourceFile) if err != nil { diff --git a/pkg/skaffold/parser/types.go b/pkg/skaffold/parser/types.go index 85f6e884e16..7121f8d405c 100644 --- a/pkg/skaffold/parser/types.go +++ b/pkg/skaffold/parser/types.go @@ -18,7 +18,7 @@ package parser import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser/configlocations" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // SkaffoldConfigSet encapsulates a slice of skaffold configurations. @@ -26,7 +26,7 @@ type SkaffoldConfigSet []*SkaffoldConfigEntry // SkaffoldConfigEntry encapsulates a single skaffold configuration, along with the source filename and its index in that file. type SkaffoldConfigEntry struct { - *latestV1.SkaffoldConfig + *latest.SkaffoldConfig SourceFile string SourceIndex int IsRootConfig bool diff --git a/pkg/skaffold/platform/resolver.go b/pkg/skaffold/platform/resolver.go index 344354cdf4d..b5ea0fa5388 100644 --- a/pkg/skaffold/platform/resolver.go +++ b/pkg/skaffold/platform/resolver.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/instrumentation" kubernetesclient "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) var ( @@ -48,7 +48,7 @@ func (r Resolver) GetPlatforms(imageName string) Matcher { return r.platformsByImageName[imageName] } -func NewResolver(ctx context.Context, pipelines []latestV1.Pipeline, cliPlatformsSelection []string, runMode config.RunMode, kubeContext string) (Resolver, error) { +func NewResolver(ctx context.Context, pipelines []latest.Pipeline, cliPlatformsSelection []string, runMode config.RunMode, kubeContext string) (Resolver, error) { r := Resolver{} r.platformsByImageName = make(map[string]Matcher) diff --git a/pkg/skaffold/platform/resolver_test.go b/pkg/skaffold/platform/resolver_test.go index 9fac1f43331..428ca4a30e1 100644 --- a/pkg/skaffold/platform/resolver_test.go +++ b/pkg/skaffold/platform/resolver_test.go @@ -29,7 +29,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" kubernetesclient "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -38,7 +38,7 @@ func TestResolver(t *testing.T) { description string cliPlatforms []string clusterPlatforms []string - pipelines []latestV1.Pipeline + pipelines []latest.Pipeline runMode config.RunMode shouldErr bool expected map[string]Matcher @@ -47,9 +47,9 @@ func TestResolver(t *testing.T) { description: "all platforms specified valid for `build` mode", cliPlatforms: []string{"linux/amd64", "linux/386"}, clusterPlatforms: []string{"linux/arm64"}, - pipelines: []latestV1.Pipeline{{Build: latestV1.BuildConfig{ + pipelines: []latest.Pipeline{{Build: latest.BuildConfig{ Platforms: []string{"windows/amd64"}, - Artifacts: []*latestV1.Artifact{{ImageName: "img1"}, {ImageName: "img2"}}}}}, + Artifacts: []*latest.Artifact{{ImageName: "img1"}, {ImageName: "img2"}}}}}, runMode: config.RunModes.Build, expected: map[string]Matcher{ "img1": {Platforms: []v1.Platform{ @@ -64,9 +64,9 @@ func TestResolver(t *testing.T) { description: "cluster platform mismatch for `dev` mode", cliPlatforms: []string{"linux/amd64", "linux/386"}, clusterPlatforms: []string{"linux/arm64"}, - pipelines: []latestV1.Pipeline{{Build: latestV1.BuildConfig{ + pipelines: []latest.Pipeline{{Build: latest.BuildConfig{ Platforms: []string{"windows/amd64"}, - Artifacts: []*latestV1.Artifact{{ImageName: "img1"}, {ImageName: "img2"}}}}}, + Artifacts: []*latest.Artifact{{ImageName: "img1"}, {ImageName: "img2"}}}}}, runMode: config.RunModes.Dev, shouldErr: true, }, @@ -74,9 +74,9 @@ func TestResolver(t *testing.T) { description: "cluster platform selected for `dev` mode", cliPlatforms: []string{"linux/amd64", "linux/386"}, clusterPlatforms: []string{"linux/amd64"}, - pipelines: []latestV1.Pipeline{{Build: latestV1.BuildConfig{ + pipelines: []latest.Pipeline{{Build: latest.BuildConfig{ Platforms: []string{"windows/amd64"}, - Artifacts: []*latestV1.Artifact{{ImageName: "img1"}, {ImageName: "img2"}}}}}, + Artifacts: []*latest.Artifact{{ImageName: "img1"}, {ImageName: "img2"}}}}}, runMode: config.RunModes.Dev, expected: map[string]Matcher{ "img1": {Platforms: []v1.Platform{{OS: "linux", Architecture: "amd64"}}}, @@ -87,9 +87,9 @@ func TestResolver(t *testing.T) { description: "cluster platform selected for `debug` mode", cliPlatforms: []string{"linux/amd64", "linux/386"}, clusterPlatforms: []string{"linux/amd64"}, - pipelines: []latestV1.Pipeline{{Build: latestV1.BuildConfig{ + pipelines: []latest.Pipeline{{Build: latest.BuildConfig{ Platforms: []string{"windows/amd64"}, - Artifacts: []*latestV1.Artifact{{ImageName: "img1"}, {ImageName: "img2"}}}}}, + Artifacts: []*latest.Artifact{{ImageName: "img1"}, {ImageName: "img2"}}}}}, runMode: config.RunModes.Debug, expected: map[string]Matcher{ "img1": {Platforms: []v1.Platform{{OS: "linux", Architecture: "amd64"}}}, @@ -99,9 +99,9 @@ func TestResolver(t *testing.T) { { description: "artifact platform constraint applied", cliPlatforms: []string{"linux/amd64", "linux/386"}, - pipelines: []latestV1.Pipeline{{Build: latestV1.BuildConfig{ + pipelines: []latest.Pipeline{{Build: latest.BuildConfig{ Platforms: []string{"windows/amd64"}, - Artifacts: []*latestV1.Artifact{{ImageName: "img1", Platforms: []string{"darwin/arm64", "linux/386"}}, {ImageName: "img2"}}}}}, + Artifacts: []*latest.Artifact{{ImageName: "img1", Platforms: []string{"darwin/arm64", "linux/386"}}, {ImageName: "img2"}}}}}, expected: map[string]Matcher{ "img1": {Platforms: []v1.Platform{{OS: "linux", Architecture: "386"}}}, "img2": {Platforms: []v1.Platform{{OS: "linux", Architecture: "amd64"}, {OS: "linux", Architecture: "386"}}}, @@ -111,9 +111,9 @@ func TestResolver(t *testing.T) { description: "artifact platform constraint mismatch", cliPlatforms: []string{"linux/amd64", "linux/386"}, clusterPlatforms: []string{"linux/amd64"}, - pipelines: []latestV1.Pipeline{{Build: latestV1.BuildConfig{ + pipelines: []latest.Pipeline{{Build: latest.BuildConfig{ Platforms: []string{"windows/amd64"}, - Artifacts: []*latestV1.Artifact{{ImageName: "img1", Platforms: []string{"darwin/arm64"}}, {ImageName: "img2"}}}}}, + Artifacts: []*latest.Artifact{{ImageName: "img1", Platforms: []string{"darwin/arm64"}}, {ImageName: "img2"}}}}}, runMode: config.RunModes.Dev, shouldErr: true, }, diff --git a/pkg/skaffold/runner/build.go b/pkg/skaffold/runner/build.go index dbf0e203765..c053028841a 100644 --- a/pkg/skaffold/runner/build.go +++ b/pkg/skaffold/runner/build.go @@ -36,7 +36,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/tag" timeutil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/time" ) @@ -68,7 +68,7 @@ func (r *Builder) GetBuilds() []graph.Artifact { } // Build builds a list of artifacts. -func (r *Builder) Build(ctx context.Context, out io.Writer, artifacts []*latestV1.Artifact) ([]graph.Artifact, error) { +func (r *Builder) Build(ctx context.Context, out io.Writer, artifacts []*latest.Artifact) ([]graph.Artifact, error) { eventV2.TaskInProgress(constants.Build, "Build containers") out, ctx = output.WithEventContext(ctx, out, constants.Build, constants.SubtaskIDNone) @@ -102,7 +102,7 @@ func (r *Builder) Build(ctx context.Context, out io.Writer, artifacts []*latestV default: } - bRes, err := r.cache.Build(ctx, out, tags, artifacts, r.platforms, func(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latestV1.Artifact, platforms platform.Resolver) ([]graph.Artifact, error) { + bRes, err := r.cache.Build(ctx, out, tags, artifacts, r.platforms, func(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latest.Artifact, platforms platform.Resolver) ([]graph.Artifact, error) { if len(artifacts) == 0 { return nil, nil } @@ -135,7 +135,7 @@ func (r *Builder) HasBuilt() bool { return r.hasBuilt } -func artifactsWithTags(tags tag.ImageTags, artifacts []*latestV1.Artifact) []graph.Artifact { +func artifactsWithTags(tags tag.ImageTags, artifacts []*latest.Artifact) []graph.Artifact { var bRes []graph.Artifact for _, artifact := range artifacts { bRes = append(bRes, graph.Artifact{ @@ -158,7 +158,7 @@ func (r *Builder) ApplyDefaultRepo(tag string) (string, error) { } // imageTags generates tags for a list of artifacts -func (r *Builder) imageTags(ctx context.Context, out io.Writer, artifacts []*latestV1.Artifact) (tag.ImageTags, error) { +func (r *Builder) imageTags(ctx context.Context, out io.Writer, artifacts []*latest.Artifact) (tag.ImageTags, error) { start := time.Now() maxWorkers := runtime.GOMAXPROCS(0) output.Default.Fprintln(out, "Generating tags...") @@ -226,7 +226,7 @@ func (r *Builder) imageTags(ctx context.Context, out io.Writer, artifacts []*lat return imageTags, nil } -func CheckWorkspaces(artifacts []*latestV1.Artifact) error { +func CheckWorkspaces(artifacts []*latest.Artifact) error { for _, a := range artifacts { if a.Workspace != "" { if info, err := os.Stat(a.Workspace); err != nil { diff --git a/pkg/skaffold/runner/builder.go b/pkg/skaffold/runner/builder.go index 95ed186e17c..4d2533b1059 100644 --- a/pkg/skaffold/runner/builder.go +++ b/pkg/skaffold/runner/builder.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "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/latest" ) // builderCtx encapsulates a given skaffold run context along with additional builder constructs. @@ -46,7 +46,7 @@ func (b *builderCtx) SourceDependenciesResolver() graph.SourceDependenciesCache } // GetBuilder creates a builder from a given RunContext and build pipeline type. -func GetBuilder(ctx context.Context, r *runcontext.RunContext, s build.ArtifactStore, d graph.SourceDependenciesCache, p latestV1.Pipeline) (build.PipelineBuilder, error) { +func GetBuilder(ctx context.Context, r *runcontext.RunContext, s build.ArtifactStore, d graph.SourceDependenciesCache, p latest.Pipeline) (build.PipelineBuilder, error) { bCtx := &builderCtx{artifactStore: s, sourceDependenciesCache: d, RunContext: r} switch { case p.Build.LocalBuild != nil: diff --git a/pkg/skaffold/runner/changeset.go b/pkg/skaffold/runner/changeset.go index f9d110309f1..3ef6198af2f 100644 --- a/pkg/skaffold/runner/changeset.go +++ b/pkg/skaffold/runner/changeset.go @@ -17,13 +17,13 @@ limitations under the License. package runner import ( - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync" ) type ChangeSet struct { - needsRebuild []*latestV1.Artifact - rebuildTracker map[string]*latestV1.Artifact + needsRebuild []*latest.Artifact + rebuildTracker map[string]*latest.Artifact needsResync []*sync.Item resyncTracker map[string]*sync.Item needsRetest map[string]bool // keyed on artifact image name @@ -32,7 +32,7 @@ type ChangeSet struct { } // NeedsRebuild gets the value of needsRebuild, which itself is not expected to be changed outside ChangeSet -func (c *ChangeSet) NeedsRebuild() []*latestV1.Artifact { +func (c *ChangeSet) NeedsRebuild() []*latest.Artifact { return c.needsRebuild } @@ -56,18 +56,18 @@ func (c *ChangeSet) NeedsReload() bool { return c.needsReload } -func (c *ChangeSet) AddRebuild(a *latestV1.Artifact) { +func (c *ChangeSet) AddRebuild(a *latest.Artifact) { if _, ok := c.rebuildTracker[a.ImageName]; ok { return } if c.rebuildTracker == nil { - c.rebuildTracker = map[string]*latestV1.Artifact{} + c.rebuildTracker = map[string]*latest.Artifact{} } c.rebuildTracker[a.ImageName] = a c.needsRebuild = append(c.needsRebuild, a) } -func (c *ChangeSet) AddRetest(a *latestV1.Artifact) { +func (c *ChangeSet) AddRetest(a *latest.Artifact) { if c.needsRetest == nil { c.needsRetest = make(map[string]bool) } @@ -86,7 +86,7 @@ func (c *ChangeSet) AddResync(s *sync.Item) { } func (c *ChangeSet) ResetBuild() { - c.rebuildTracker = make(map[string]*latestV1.Artifact) + c.rebuildTracker = make(map[string]*latest.Artifact) c.needsRebuild = nil } diff --git a/pkg/skaffold/runner/deployer.go b/pkg/skaffold/runner/deployer.go index 435c85571af..c748ed5db61 100644 --- a/pkg/skaffold/runner/deployer.go +++ b/pkg/skaffold/runner/deployer.go @@ -32,14 +32,14 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/label" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/status" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" ) // deployerCtx encapsulates a given skaffold run context along with additional deployer constructs. type deployerCtx struct { *runcontext.RunContext - deploy v1.DeployConfig + deploy latest.DeployConfig } func (d *deployerCtx) GetKubeContext() string { @@ -60,7 +60,7 @@ func (d *deployerCtx) StatusCheck() *bool { } // JsonParseType returns the JsonParseType field from the underlying deployConfig struct -func (d *deployerCtx) JSONParseConfig() v1.JSONParseConfig { +func (d *deployerCtx) JSONParseConfig() latest.JSONParseConfig { return d.deploy.Logs.JSONParse } @@ -182,7 +182,7 @@ Therefore, in this function we do implicit validation of the provided configurat func getDefaultDeployer(runCtx *runcontext.RunContext, labeller *label.DefaultLabeller) (deploy.Deployer, error) { deployCfgs := runCtx.DeployConfigs() - var kFlags *v1.KubectlFlags + var kFlags *latest.KubectlFlags var logPrefix string var defaultNamespace *string var kubeContext string @@ -208,7 +208,7 @@ func getDefaultDeployer(runCtx *runcontext.RunContext, labeller *label.DefaultLa logPrefix = d.Logs.Prefix } var currentDefaultNamespace *string - var currentKubectlFlags v1.KubectlFlags + var currentKubectlFlags latest.KubectlFlags if d.KubectlDeploy != nil { currentDefaultNamespace = d.KubectlDeploy.DefaultNamespace currentKubectlFlags = d.KubectlDeploy.Flags @@ -231,9 +231,9 @@ func getDefaultDeployer(runCtx *runcontext.RunContext, labeller *label.DefaultLa } } if kFlags == nil { - kFlags = &v1.KubectlFlags{} + kFlags = &latest.KubectlFlags{} } - k := &v1.KubectlDeploy{ + k := &latest.KubectlDeploy{ Flags: *kFlags, DefaultNamespace: defaultNamespace, } @@ -244,7 +244,7 @@ func getDefaultDeployer(runCtx *runcontext.RunContext, labeller *label.DefaultLa return defaultDeployer, nil } -func validateKubectlFlags(flags *v1.KubectlFlags, additional v1.KubectlFlags) error { +func validateKubectlFlags(flags *latest.KubectlFlags, additional latest.KubectlFlags) error { errStr := "conflicting sets of kubectl deploy flags not supported in `skaffold apply` (flag: %s)" if additional.DisableValidation != flags.DisableValidation { return fmt.Errorf(errStr, strconv.FormatBool(additional.DisableValidation)) diff --git a/pkg/skaffold/runner/deployer_test.go b/pkg/skaffold/runner/deployer_test.go index 9019bba269c..bcd328673ab 100644 --- a/pkg/skaffold/runner/deployer_test.go +++ b/pkg/skaffold/runner/deployer_test.go @@ -39,7 +39,7 @@ import ( k8sstatus "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/status" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/loader" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" @@ -49,7 +49,7 @@ func TestGetDeployer(tOuter *testing.T) { testutil.Run(tOuter, "TestGetDeployer", func(t *testutil.T) { tests := []struct { description string - cfg latestV1.DeployType + cfg latest.DeployType helmVersion string expected deploy.Deployer apply bool @@ -61,71 +61,71 @@ func TestGetDeployer(tOuter *testing.T) { }, { description: "helm deployer with 3.0.0 version", - cfg: latestV1.DeployType{HelmDeploy: &latestV1.HelmDeploy{}}, + cfg: latest.DeployType{HelmDeploy: &latest.HelmDeploy{}}, helmVersion: `version.BuildInfo{Version:"v3.0.0"}`, expected: deploy.NewDeployerMux([]deploy.Deployer{&helm.Deployer{}}, false), }, { description: "helm deployer with less than 3.0.0 version", - cfg: latestV1.DeployType{HelmDeploy: &latestV1.HelmDeploy{}}, + cfg: latest.DeployType{HelmDeploy: &latest.HelmDeploy{}}, helmVersion: "2.0.0", shouldErr: true, }, { description: "kubectl deployer", - cfg: latestV1.DeployType{KubectlDeploy: &latestV1.KubectlDeploy{}}, + cfg: latest.DeployType{KubectlDeploy: &latest.KubectlDeploy{}}, expected: deploy.NewDeployerMux([]deploy.Deployer{ t.RequireNonNilResult(kubectl.NewDeployer(&runcontext.RunContext{ - Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{{}}), - }, &label.DefaultLabeller{}, &latestV1.KubectlDeploy{ - Flags: latestV1.KubectlFlags{}, + Pipelines: runcontext.NewPipelines([]latest.Pipeline{{}}), + }, &label.DefaultLabeller{}, &latest.KubectlDeploy{ + Flags: latest.KubectlFlags{}, })).(deploy.Deployer), }, false), }, { description: "kustomize deployer", - cfg: latestV1.DeployType{KustomizeDeploy: &latestV1.KustomizeDeploy{}}, + cfg: latest.DeployType{KustomizeDeploy: &latest.KustomizeDeploy{}}, expected: deploy.NewDeployerMux([]deploy.Deployer{ t.RequireNonNilResult(kustomize.NewDeployer(&runcontext.RunContext{ - Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{{}}), - }, &label.DefaultLabeller{}, &latestV1.KustomizeDeploy{ - Flags: latestV1.KubectlFlags{}, + Pipelines: runcontext.NewPipelines([]latest.Pipeline{{}}), + }, &label.DefaultLabeller{}, &latest.KustomizeDeploy{ + Flags: latest.KubectlFlags{}, })).(deploy.Deployer), }, false), }, { description: "kpt deployer", - cfg: latestV1.DeployType{KptDeploy: &latestV1.KptDeploy{}}, + cfg: latest.DeployType{KptDeploy: &latest.KptDeploy{}}, expected: deploy.NewDeployerMux([]deploy.Deployer{ &kpt.Deployer{}, }, false), }, { description: "apply forces creation of kubectl deployer with kpt config", - cfg: latestV1.DeployType{KptDeploy: &latestV1.KptDeploy{}}, + cfg: latest.DeployType{KptDeploy: &latest.KptDeploy{}}, apply: true, expected: t.RequireNonNilResult(kubectl.NewDeployer(&runcontext.RunContext{ - Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{{}}), - }, &label.DefaultLabeller{}, &latestV1.KubectlDeploy{ - Flags: latestV1.KubectlFlags{}, + Pipelines: runcontext.NewPipelines([]latest.Pipeline{{}}), + }, &label.DefaultLabeller{}, &latest.KubectlDeploy{ + Flags: latest.KubectlFlags{}, })).(deploy.Deployer), }, { description: "apply forces creation of kubectl deployer with helm config", - cfg: latestV1.DeployType{HelmDeploy: &latestV1.HelmDeploy{}}, + cfg: latest.DeployType{HelmDeploy: &latest.HelmDeploy{}}, helmVersion: `version.BuildInfo{Version:"v3.0.0"}`, apply: true, expected: t.RequireNonNilResult(kubectl.NewDeployer(&runcontext.RunContext{ - Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{{}}), - }, &label.DefaultLabeller{}, &latestV1.KubectlDeploy{ - Flags: latestV1.KubectlFlags{}, + Pipelines: runcontext.NewPipelines([]latest.Pipeline{{}}), + }, &label.DefaultLabeller{}, &latest.KubectlDeploy{ + Flags: latest.KubectlFlags{}, })).(deploy.Deployer), }, { description: "multiple deployers", - cfg: latestV1.DeployType{ - HelmDeploy: &latestV1.HelmDeploy{}, - KptDeploy: &latestV1.KptDeploy{}, + cfg: latest.DeployType{ + HelmDeploy: &latest.HelmDeploy{}, + KptDeploy: &latest.KptDeploy{}, }, helmVersion: `version.BuildInfo{Version:"v3.0.0"}`, expected: deploy.NewDeployerMux([]deploy.Deployer{ @@ -136,24 +136,24 @@ func TestGetDeployer(tOuter *testing.T) { { description: "apply does not allow multiple deployers when a helm namespace is set", apply: true, - cfg: latestV1.DeployType{ - HelmDeploy: &latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{ + cfg: latest.DeployType{ + HelmDeploy: &latest.HelmDeploy{ + Releases: []latest.HelmRelease{ { Namespace: "foo", }, }, }, - KubectlDeploy: &latestV1.KubectlDeploy{}, + KubectlDeploy: &latest.KubectlDeploy{}, }, shouldErr: true, }, { description: "apply does not allow multiple helm releases with different namespaces set", apply: true, - cfg: latestV1.DeployType{ - HelmDeploy: &latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{ + cfg: latest.DeployType{ + HelmDeploy: &latest.HelmDeploy{ + Releases: []latest.HelmRelease{ { Namespace: "foo", }, @@ -168,9 +168,9 @@ func TestGetDeployer(tOuter *testing.T) { { description: "apply does allow multiple helm releases with the same namespace set", apply: true, - cfg: latestV1.DeployType{ - HelmDeploy: &latestV1.HelmDeploy{ - Releases: []latestV1.HelmRelease{ + cfg: latest.DeployType{ + HelmDeploy: &latest.HelmDeploy{ + Releases: []latest.HelmRelease{ { Namespace: "foo", }, @@ -181,9 +181,9 @@ func TestGetDeployer(tOuter *testing.T) { }, }, expected: t.RequireNonNilResult(kubectl.NewDeployer(&runcontext.RunContext{ - Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{{}}), - }, &label.DefaultLabeller{}, &latestV1.KubectlDeploy{ - Flags: latestV1.KubectlFlags{}, + Pipelines: runcontext.NewPipelines([]latest.Pipeline{{}}), + }, &label.DefaultLabeller{}, &latest.KubectlDeploy{ + Flags: latest.KubectlFlags{}, })).(deploy.Deployer), }, } @@ -200,8 +200,8 @@ func TestGetDeployer(tOuter *testing.T) { Opts: config.SkaffoldOptions{ Apply: test.apply, }, - Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{{ - Deploy: latestV1.DeployConfig{ + Pipelines: runcontext.NewPipelines([]latest.Pipeline{{ + Deploy: latest.DeployConfig{ DeployType: test.cfg, }, }}), @@ -245,35 +245,35 @@ func TestGetDefaultDeployer(tOuter *testing.T) { }) tests := []struct { name string - cfgs []latestV1.DeployType + cfgs []latest.DeployType expected *kubectl.Deployer shouldErr bool }{ { name: "one config with kubectl deploy", - cfgs: []latestV1.DeployType{{ - KubectlDeploy: &latestV1.KubectlDeploy{}, + cfgs: []latest.DeployType{{ + KubectlDeploy: &latest.KubectlDeploy{}, }}, expected: t.RequireNonNilResult(kubectl.NewDeployer(&runcontext.RunContext{ - Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{{}}), - }, &label.DefaultLabeller{}, &latestV1.KubectlDeploy{ - Flags: latestV1.KubectlFlags{}, + Pipelines: runcontext.NewPipelines([]latest.Pipeline{{}}), + }, &label.DefaultLabeller{}, &latest.KubectlDeploy{ + Flags: latest.KubectlFlags{}, })).(*kubectl.Deployer), }, { name: "one config with kubectl deploy, with flags", - cfgs: []latestV1.DeployType{{ - KubectlDeploy: &latestV1.KubectlDeploy{ - Flags: latestV1.KubectlFlags{ + cfgs: []latest.DeployType{{ + KubectlDeploy: &latest.KubectlDeploy{ + Flags: latest.KubectlFlags{ Apply: []string{"--foo"}, Global: []string{"--bar"}, }, }, }}, expected: t.RequireNonNilResult(kubectl.NewDeployer(&runcontext.RunContext{ - Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{{}}), - }, &label.DefaultLabeller{}, &latestV1.KubectlDeploy{ - Flags: latestV1.KubectlFlags{ + Pipelines: runcontext.NewPipelines([]latest.Pipeline{{}}), + }, &label.DefaultLabeller{}, &latest.KubectlDeploy{ + Flags: latest.KubectlFlags{ Apply: []string{"--foo"}, Global: []string{"--bar"}, }, @@ -281,17 +281,17 @@ func TestGetDefaultDeployer(tOuter *testing.T) { }, { name: "two kubectl configs with mismatched flags should fail", - cfgs: []latestV1.DeployType{ + cfgs: []latest.DeployType{ { - KubectlDeploy: &latestV1.KubectlDeploy{ - Flags: latestV1.KubectlFlags{ + KubectlDeploy: &latest.KubectlDeploy{ + Flags: latest.KubectlFlags{ Apply: []string{"--foo"}, }, }, }, { - KubectlDeploy: &latestV1.KubectlDeploy{ - Flags: latestV1.KubectlFlags{ + KubectlDeploy: &latest.KubectlDeploy{ + Flags: latest.KubectlFlags{ Apply: []string{"--bar"}, }, }, @@ -301,34 +301,34 @@ func TestGetDefaultDeployer(tOuter *testing.T) { }, { name: "one config with helm deploy", - cfgs: []latestV1.DeployType{{ - HelmDeploy: &latestV1.HelmDeploy{}, + cfgs: []latest.DeployType{{ + HelmDeploy: &latest.HelmDeploy{}, }}, expected: t.RequireNonNilResult(kubectl.NewDeployer(&runcontext.RunContext{ - Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{{}}), - }, &label.DefaultLabeller{}, &latestV1.KubectlDeploy{ - Flags: latestV1.KubectlFlags{}, + Pipelines: runcontext.NewPipelines([]latest.Pipeline{{}}), + }, &label.DefaultLabeller{}, &latest.KubectlDeploy{ + Flags: latest.KubectlFlags{}, })).(*kubectl.Deployer), }, { name: "one config with kustomize deploy", - cfgs: []latestV1.DeployType{{ - KustomizeDeploy: &latestV1.KustomizeDeploy{}, + cfgs: []latest.DeployType{{ + KustomizeDeploy: &latest.KustomizeDeploy{}, }}, expected: t.RequireNonNilResult(kubectl.NewDeployer(&runcontext.RunContext{ - Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{{}}), - }, &label.DefaultLabeller{}, &latestV1.KubectlDeploy{ - Flags: latestV1.KubectlFlags{}, + Pipelines: runcontext.NewPipelines([]latest.Pipeline{{}}), + }, &label.DefaultLabeller{}, &latest.KubectlDeploy{ + Flags: latest.KubectlFlags{}, })).(*kubectl.Deployer), }, } for _, test := range tests { testutil.Run(tOuter, test.name, func(t *testutil.T) { - pipelines := []latestV1.Pipeline{} + pipelines := []latest.Pipeline{} for _, cfg := range test.cfgs { - pipelines = append(pipelines, latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ + pipelines = append(pipelines, latest.Pipeline{ + Deploy: latest.DeployConfig{ DeployType: cfg, }, }) diff --git a/pkg/skaffold/runner/listen_test.go b/pkg/skaffold/runner/listen_test.go index 496c0bdc3ac..40e2bda70d5 100644 --- a/pkg/skaffold/runner/listen_test.go +++ b/pkg/skaffold/runner/listen_test.go @@ -22,7 +22,7 @@ import ( "testing" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/filemon" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/trigger" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -55,11 +55,11 @@ func (f *fakeTriggger) Debounce() bool { type fakeDepsResolver struct{} -func (f *fakeDepsResolver) TransitiveArtifactDependencies(context.Context, *latestV1.Artifact) ([]string, error) { +func (f *fakeDepsResolver) TransitiveArtifactDependencies(context.Context, *latest.Artifact) ([]string, error) { return nil, nil } -func (f *fakeDepsResolver) SingleArtifactDependencies(context.Context, *latestV1.Artifact) ([]string, error) { +func (f *fakeDepsResolver) SingleArtifactDependencies(context.Context, *latest.Artifact) ([]string, error) { return nil, nil } diff --git a/pkg/skaffold/runner/runcontext/context.go b/pkg/skaffold/runner/runcontext/context.go index 02d59dec3b2..ba1e07be864 100644 --- a/pkg/skaffold/runner/runcontext/context.go +++ b/pkg/skaffold/runner/runcontext/context.go @@ -26,7 +26,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" kubectx "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" schemaUtil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) @@ -42,22 +42,22 @@ type RunContext struct { // Pipelines encapsulates multiple config pipelines type Pipelines struct { - pipelines []latestV1.Pipeline - pipelinesByImageName map[string]latestV1.Pipeline + pipelines []latest.Pipeline + pipelinesByImageName map[string]latest.Pipeline } // All returns all config pipelines. -func (ps Pipelines) All() []latestV1.Pipeline { +func (ps Pipelines) All() []latest.Pipeline { return ps.pipelines } -// Head returns the first `latestV1.Pipeline`. -func (ps Pipelines) Head() latestV1.Pipeline { +// Head returns the first `latest.Pipeline`. +func (ps Pipelines) Head() latest.Pipeline { return ps.pipelines[0] // there always exists atleast one pipeline. } -// Select returns the first `latestV1.Pipeline` that matches the given artifact `imageName`. -func (ps Pipelines) Select(imageName string) (latestV1.Pipeline, bool) { +// Select returns the first `latest.Pipeline` that matches the given artifact `imageName`. +func (ps Pipelines) Select(imageName string) (latest.Pipeline, bool) { p, found := ps.pipelinesByImageName[imageName] return p, found } @@ -67,40 +67,40 @@ func (ps Pipelines) IsMultiPipeline() bool { return len(ps.pipelines) > 1 } -func (ps Pipelines) PortForwardResources() []*latestV1.PortForwardResource { - var pf []*latestV1.PortForwardResource +func (ps Pipelines) PortForwardResources() []*latest.PortForwardResource { + var pf []*latest.PortForwardResource for _, p := range ps.pipelines { pf = append(pf, p.PortForward...) } return pf } -func (ps Pipelines) Artifacts() []*latestV1.Artifact { - var artifacts []*latestV1.Artifact +func (ps Pipelines) Artifacts() []*latest.Artifact { + var artifacts []*latest.Artifact for _, p := range ps.pipelines { artifacts = append(artifacts, p.Build.Artifacts...) } return artifacts } -func (ps Pipelines) DeployConfigs() []latestV1.DeployConfig { - var cfgs []latestV1.DeployConfig +func (ps Pipelines) DeployConfigs() []latest.DeployConfig { + var cfgs []latest.DeployConfig for _, p := range ps.pipelines { cfgs = append(cfgs, p.Deploy) } return cfgs } -func (ps Pipelines) Deployers() []latestV1.DeployConfig { - var deployers []latestV1.DeployConfig +func (ps Pipelines) Deployers() []latest.DeployConfig { + var deployers []latest.DeployConfig for _, p := range ps.pipelines { deployers = append(deployers, p.Deploy) } return deployers } -func (ps Pipelines) TestCases() []*latestV1.TestCase { - var tests []*latestV1.TestCase +func (ps Pipelines) TestCases() []*latest.TestCase { + var tests []*latest.TestCase for _, p := range ps.pipelines { tests = append(tests, p.Test...) } @@ -108,8 +108,8 @@ func (ps Pipelines) TestCases() []*latestV1.TestCase { } // TransformAllowList returns combined allowlist from pipelines -func (ps Pipelines) TransformAllowList() []latestV1.ResourceFilter { - var allowlist []latestV1.ResourceFilter +func (ps Pipelines) TransformAllowList() []latest.ResourceFilter { + var allowlist []latest.ResourceFilter for _, p := range ps.pipelines { if p.ResourceSelector.Allow != nil { allowlist = append(allowlist, p.ResourceSelector.Allow...) @@ -119,8 +119,8 @@ func (ps Pipelines) TransformAllowList() []latestV1.ResourceFilter { } // TransformDenyList returns combined denylist from pipelines -func (ps Pipelines) TransformDenyList() []latestV1.ResourceFilter { - var denylist []latestV1.ResourceFilter +func (ps Pipelines) TransformDenyList() []latest.ResourceFilter { + var denylist []latest.ResourceFilter for _, p := range ps.pipelines { if p.ResourceSelector.Deny != nil { denylist = append(denylist, p.ResourceSelector.Deny...) @@ -139,8 +139,8 @@ func (ps Pipelines) StatusCheckDeadlineSeconds() int { } return c } -func NewPipelines(pipelines []latestV1.Pipeline) Pipelines { - m := make(map[string]latestV1.Pipeline) +func NewPipelines(pipelines []latest.Pipeline) Pipelines { + m := make(map[string]latest.Pipeline) for _, p := range pipelines { for _, a := range p.Build.Artifacts { m[a.ImageName] = p @@ -149,21 +149,21 @@ func NewPipelines(pipelines []latestV1.Pipeline) Pipelines { return Pipelines{pipelines: pipelines, pipelinesByImageName: m} } -func (rc *RunContext) PipelineForImage(imageName string) (latestV1.Pipeline, bool) { +func (rc *RunContext) PipelineForImage(imageName string) (latest.Pipeline, bool) { return rc.Pipelines.Select(imageName) } -func (rc *RunContext) PortForwardResources() []*latestV1.PortForwardResource { +func (rc *RunContext) PortForwardResources() []*latest.PortForwardResource { return rc.Pipelines.PortForwardResources() } -func (rc *RunContext) Artifacts() []*latestV1.Artifact { return rc.Pipelines.Artifacts() } +func (rc *RunContext) Artifacts() []*latest.Artifact { return rc.Pipelines.Artifacts() } -func (rc *RunContext) DeployConfigs() []latestV1.DeployConfig { return rc.Pipelines.DeployConfigs() } +func (rc *RunContext) DeployConfigs() []latest.DeployConfig { return rc.Pipelines.DeployConfigs() } -func (rc *RunContext) Deployers() []latestV1.DeployConfig { return rc.Pipelines.Deployers() } +func (rc *RunContext) Deployers() []latest.DeployConfig { return rc.Pipelines.Deployers() } -func (rc *RunContext) TestCases() []*latestV1.TestCase { return rc.Pipelines.TestCases() } +func (rc *RunContext) TestCases() []*latest.TestCase { return rc.Pipelines.TestCases() } func (rc *RunContext) StatusCheckDeadlineSeconds() int { return rc.Pipelines.StatusCheckDeadlineSeconds() @@ -177,11 +177,11 @@ func (rc *RunContext) IsTestPhaseActive() bool { return !rc.SkipTests() && len(rc.TestCases()) != 0 } -func (rc *RunContext) TransformAllowList() []latestV1.ResourceFilter { +func (rc *RunContext) TransformAllowList() []latest.ResourceFilter { return rc.Pipelines.TransformAllowList() } -func (rc *RunContext) TransformDenyList() []latestV1.ResourceFilter { +func (rc *RunContext) TransformDenyList() []latest.ResourceFilter { return rc.Pipelines.TransformDenyList() } @@ -191,9 +191,9 @@ func (rc *RunContext) AddSkaffoldLabels() bool { return rc.Opts.Mode() != config.RunModes.Render } -func (rc *RunContext) DefaultPipeline() latestV1.Pipeline { return rc.Pipelines.Head() } +func (rc *RunContext) DefaultPipeline() latest.Pipeline { return rc.Pipelines.Head() } func (rc *RunContext) GetKubeContext() string { return rc.KubeContext } -func (rc *RunContext) GetPipelines() []latestV1.Pipeline { return rc.Pipelines.All() } +func (rc *RunContext) GetPipelines() []latest.Pipeline { return rc.Pipelines.All() } func (rc *RunContext) GetInsecureRegistries() map[string]bool { return rc.InsecureRegistries } func (rc *RunContext) GetWorkingDir() string { return rc.WorkingDir } func (rc *RunContext) GetCluster() config.Cluster { return rc.Cluster } @@ -243,15 +243,15 @@ func (rc *RunContext) RPCPort() *int { return rc func (rc *RunContext) RPCHTTPPort() *int { return rc.Opts.RPCHTTPPort.Value() } func (rc *RunContext) PushImages() config.BoolOrUndefined { return rc.Opts.PushImages } func (rc *RunContext) TransformRulesFile() string { return rc.Opts.TransformRulesFile } -func (rc *RunContext) JSONParseConfig() latestV1.JSONParseConfig { +func (rc *RunContext) JSONParseConfig() latest.JSONParseConfig { return rc.DefaultPipeline().Deploy.Logs.JSONParse } func GetRunContext(ctx context.Context, opts config.SkaffoldOptions, configs []schemaUtil.VersionedConfig) (*RunContext, error) { - var pipelines []latestV1.Pipeline + var pipelines []latest.Pipeline for _, cfg := range configs { if cfg != nil { - pipelines = append(pipelines, cfg.(*latestV1.SkaffoldConfig).Pipeline) + pipelines = append(pipelines, cfg.(*latest.SkaffoldConfig).Pipeline) } } kubeConfig, err := kubectx.CurrentConfig() diff --git a/pkg/skaffold/runner/runner.go b/pkg/skaffold/runner/runner.go index b45d66b47b3..ed2a834b99f 100644 --- a/pkg/skaffold/runner/runner.go +++ b/pkg/skaffold/runner/runner.go @@ -22,7 +22,7 @@ import ( "io" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) @@ -39,9 +39,9 @@ var ErrorConfigurationChanged = errors.New("configuration changed") type Runner interface { Apply(context.Context, io.Writer) error ApplyDefaultRepo(tag string) (string, error) - Build(context.Context, io.Writer, []*latestV1.Artifact) ([]graph.Artifact, error) + Build(context.Context, io.Writer, []*latest.Artifact) ([]graph.Artifact, error) Cleanup(context.Context, io.Writer, bool) error - Dev(context.Context, io.Writer, []*latestV1.Artifact) error + Dev(context.Context, io.Writer, []*latest.Artifact) error Deploy(context.Context, io.Writer, []graph.Artifact) error DeployAndLog(context.Context, io.Writer, []graph.Artifact) error GeneratePipeline(context.Context, io.Writer, []util.VersionedConfig, []string, string) error diff --git a/pkg/skaffold/runner/timings.go b/pkg/skaffold/runner/timings.go index 756ec94964d..3bcb36f5157 100644 --- a/pkg/skaffold/runner/timings.go +++ b/pkg/skaffold/runner/timings.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/tag" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/test" timeutil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/time" @@ -52,7 +52,7 @@ type withTimings struct { cacheArtifacts bool } -func (w withTimings) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, platforms platform.Resolver, artifacts []*latestV1.Artifact) ([]graph.Artifact, error) { +func (w withTimings) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, platforms platform.Resolver, artifacts []*latest.Artifact) ([]graph.Artifact, error) { if len(artifacts) == 0 && w.cacheArtifacts { return nil, nil } diff --git a/pkg/skaffold/runner/timings_test.go b/pkg/skaffold/runner/timings_test.go index 7fe62409afe..d440fde84f8 100644 --- a/pkg/skaffold/runner/timings_test.go +++ b/pkg/skaffold/runner/timings_test.go @@ -31,7 +31,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/tag" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/test" "github.com/GoogleContainerTools/skaffold/testutil" @@ -42,7 +42,7 @@ type mockBuilder struct { err bool } -func (m *mockBuilder) Build(context.Context, io.Writer, tag.ImageTags, platform.Resolver, []*latestV1.Artifact) ([]graph.Artifact, error) { +func (m *mockBuilder) Build(context.Context, io.Writer, tag.ImageTags, platform.Resolver, []*latest.Artifact) ([]graph.Artifact, error) { if m.err { return nil, errors.New("Unable to build") } diff --git a/pkg/skaffold/runner/v1/build_test.go b/pkg/skaffold/runner/v1/build_test.go index faa68a23fb8..5a77fae69e1 100644 --- a/pkg/skaffold/runner/v1/build_test.go +++ b/pkg/skaffold/runner/v1/build_test.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -37,7 +37,7 @@ func TestTest(t *testing.T) { tests := []struct { description string testBench *TestBench - cfg []*latestV1.Artifact + cfg []*latest.Artifact artifacts []graph.Artifact expectedActions []Actions shouldErr bool @@ -45,7 +45,7 @@ func TestTest(t *testing.T) { { description: "test no error", testBench: &TestBench{}, - cfg: []*latestV1.Artifact{{ImageName: "img1"}, {ImageName: "img2"}}, + cfg: []*latest.Artifact{{ImageName: "img1"}, {ImageName: "img2"}}, artifacts: []graph.Artifact{ {ImageName: "img1", Tag: "img1:tag1"}, {ImageName: "img2", Tag: "img2:tag2"}, @@ -63,7 +63,7 @@ func TestTest(t *testing.T) { { description: "missing tag", testBench: &TestBench{}, - cfg: []*latestV1.Artifact{{ImageName: "image1"}}, + cfg: []*latest.Artifact{{ImageName: "image1"}}, artifacts: []graph.Artifact{{ImageName: "image1"}}, expectedActions: []Actions{{ Tested: []string{""}, @@ -135,7 +135,7 @@ func TestBuildTestDeploy(t *testing.T) { t.Override(&client.Client, mockK8sClient) ctx := context.Background() - artifacts := []*latestV1.Artifact{{ + artifacts := []*latest.Artifact{{ ImageName: "img", }} @@ -156,7 +156,7 @@ func TestBuildTestDeploy(t *testing.T) { func TestBuildDryRun(t *testing.T) { testutil.Run(t, "", func(t *testutil.T) { testBench := &TestBench{} - artifacts := []*latestV1.Artifact{ + artifacts := []*latest.Artifact{ {ImageName: "img1"}, {ImageName: "img2"}, } @@ -177,7 +177,7 @@ func TestBuildDryRun(t *testing.T) { func TestBuildPushFlag(t *testing.T) { testutil.Run(t, "", func(t *testutil.T) { testBench := &TestBench{} - artifacts := []*latestV1.Artifact{ + artifacts := []*latest.Artifact{ {ImageName: "img1"}, {ImageName: "img2"}, } @@ -191,7 +191,7 @@ func TestBuildPushFlag(t *testing.T) { } func TestDigestSources(t *testing.T) { - artifacts := []*latestV1.Artifact{ + artifacts := []*latest.Artifact{ {ImageName: "img1"}, } @@ -242,12 +242,12 @@ func TestCheckWorkspaces(t *testing.T) { tests := []struct { description string - artifacts []*latestV1.Artifact + artifacts []*latest.Artifact shouldErr bool }{ { description: "no workspace", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image", }, @@ -255,7 +255,7 @@ func TestCheckWorkspaces(t *testing.T) { }, { description: "directory that exists", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image", Workspace: tmpDir.Root(), @@ -264,7 +264,7 @@ func TestCheckWorkspaces(t *testing.T) { }, { description: "error on non-existent location", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image", Workspace: "doesnotexist", @@ -274,7 +274,7 @@ func TestCheckWorkspaces(t *testing.T) { }, { description: "error on file", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image", Workspace: tmpFile, diff --git a/pkg/skaffold/runner/v1/deploy_test.go b/pkg/skaffold/runner/v1/deploy_test.go index a34d3add385..ac85a58e5f4 100644 --- a/pkg/skaffold/runner/v1/deploy_test.go +++ b/pkg/skaffold/runner/v1/deploy_test.go @@ -30,7 +30,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" "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/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -56,7 +56,7 @@ func TestDeploy(t *testing.T) { t.SetupFakeKubernetesContext(api.Config{CurrentContext: "cluster1"}) t.Override(&client.Client, mockK8sClient) - r := createRunner(t, test.testBench, nil, []*latestV1.Artifact{{ImageName: "img1"}, {ImageName: "img2"}}, nil) + r := createRunner(t, test.testBench, nil, []*latest.Artifact{{ImageName: "img1"}, {ImageName: "img2"}}, nil) out := new(bytes.Buffer) err := r.Deploy(context.Background(), out, []graph.Artifact{ diff --git a/pkg/skaffold/runner/v1/dev.go b/pkg/skaffold/runner/v1/dev.go index 681391631b1..be803ebcb15 100644 --- a/pkg/skaffold/runner/v1/dev.go +++ b/pkg/skaffold/runner/v1/dev.go @@ -32,7 +32,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync" timeutil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/time" "github.com/GoogleContainerTools/skaffold/proto/v1" @@ -205,7 +205,7 @@ func (r *SkaffoldRunner) doDev(ctx context.Context, out io.Writer) error { // Dev watches for changes and runs the skaffold build, test and deploy // config until interrupted by the user. -func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*latestV1.Artifact) error { +func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*latest.Artifact) error { event.DevLoopInProgress(r.devIteration) eventV2.InitializeState(r.runCtx) eventV2.TaskInProgress(constants.DevLoop, "") @@ -359,11 +359,11 @@ func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*la } // graph represents the artifact graph -type devGraph map[string][]*latestV1.Artifact +type devGraph map[string][]*latest.Artifact // getTransposeGraph builds the transpose of the graph represented by the artifacts slice, with edges directed from required artifact to the dependent artifact. -func getTransposeGraph(artifacts []*latestV1.Artifact) devGraph { - g := make(map[string][]*latestV1.Artifact) +func getTransposeGraph(artifacts []*latest.Artifact) devGraph { + g := make(map[string][]*latest.Artifact) for _, a := range artifacts { for _, d := range a.Dependencies { g[d.ImageName] = append(g[d.ImageName], a) diff --git a/pkg/skaffold/runner/v1/dev_test.go b/pkg/skaffold/runner/v1/dev_test.go index 6d56db05644..9fb63992d96 100644 --- a/pkg/skaffold/runner/v1/dev_test.go +++ b/pkg/skaffold/runner/v1/dev_test.go @@ -31,7 +31,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/filemon" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -144,7 +144,7 @@ func TestDevFailFirstCycle(t *testing.T) { testutil.Run(t, test.description, func(t *testutil.T) { t.SetupFakeKubernetesContext(api.Config{CurrentContext: "cluster1"}) t.Override(&client.Client, mockK8sClient) - artifacts := []*latestV1.Artifact{{ + artifacts := []*latest.Artifact{{ ImageName: "img", }} r := createRunner(t, test.testBench, test.monitor, artifacts, nil) @@ -275,7 +275,7 @@ func TestDev(t *testing.T) { t.SetupFakeKubernetesContext(api.Config{CurrentContext: "cluster1"}) t.Override(&client.Client, mockK8sClient) test.testBench.cycles = len(test.watchEvents) - artifacts := []*latestV1.Artifact{ + artifacts := []*latest.Artifact{ {ImageName: "img1"}, {ImageName: "img2"}, } @@ -419,11 +419,11 @@ func TestDevAutoTriggers(t *testing.T) { testBench := &TestBench{} testBench.cycles = len(test.watchEvents) testBench.userIntents = test.userIntents - artifacts := []*latestV1.Artifact{ + artifacts := []*latest.Artifact{ { ImageName: "img1", - Sync: &latestV1.Sync{ - Manual: []*latestV1.SyncRule{{Src: "file1", Dest: "file1"}}, + Sync: &latest.Sync{ + Manual: []*latest.SyncRule{{Src: "file1", Dest: "file1"}}, }, }, { @@ -526,11 +526,11 @@ func TestDevSync(t *testing.T) { t.Override(&fileSyncSucceeded, func(int, string) { actualFileSyncEventCalls.Succeeded++ }) t.Override(&sync.WorkingDir, func(context.Context, string, docker.Config) (string, error) { return "/", nil }) test.testBench.cycles = len(test.watchEvents) - artifacts := []*latestV1.Artifact{ + artifacts := []*latest.Artifact{ { ImageName: "img1", - Sync: &latestV1.Sync{ - Manual: []*latestV1.SyncRule{{Src: "file1", Dest: "file1"}}, + Sync: &latest.Sync{ + Manual: []*latest.SyncRule{{Src: "file1", Dest: "file1"}}, }, }, { diff --git a/pkg/skaffold/runner/v1/generate_pipeline.go b/pkg/skaffold/runner/v1/generate_pipeline.go index 767063536f1..0de057944aa 100644 --- a/pkg/skaffold/runner/v1/generate_pipeline.go +++ b/pkg/skaffold/runner/v1/generate_pipeline.go @@ -26,7 +26,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) @@ -37,7 +37,7 @@ func (r *SkaffoldRunner) GeneratePipeline(ctx context.Context, out io.Writer, co for _, config := range configs { cfgFile := &pipeline.ConfigFile{ Path: r.runCtx.ConfigurationFile(), - Config: config.(*latestV1.SkaffoldConfig), + Config: config.(*latest.SkaffoldConfig), Profile: nil, } baseConfig = append(baseConfig, cfgFile) @@ -80,7 +80,7 @@ func setupConfigFiles(configPaths []string) ([]*pipeline.ConfigFile, error) { return nil, fmt.Errorf("parsing config %q: %w", path, err) } for _, parsedCfg := range parsedCfgs { - config := parsedCfg.(*latestV1.SkaffoldConfig) + config := parsedCfg.(*latest.SkaffoldConfig) if err := defaults.Set(config); err != nil { return nil, fmt.Errorf("setting default values for extra configs: %w", err) diff --git a/pkg/skaffold/runner/v1/new.go b/pkg/skaffold/runner/v1/new.go index fe8f29cd99b..d457c069f87 100644 --- a/pkg/skaffold/runner/v1/new.go +++ b/pkg/skaffold/runner/v1/new.go @@ -33,7 +33,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/server" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/tag" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/test" @@ -85,7 +85,7 @@ func NewForConfig(ctx context.Context, runCtx *runcontext.RunContext) (*Skaffold // The Builder must be instantiated AFTER the Deployer, because the Deploy target influences // the Cluster object on the RunContext, which in turn influences whether or not we will push images. var builder build.Builder - builder, err = build.NewBuilderMux(runCtx, store, func(p latestV1.Pipeline) (build.PipelineBuilder, error) { + builder, err = build.NewBuilderMux(runCtx, store, func(p latest.Pipeline) (build.PipelineBuilder, error) { return runner.GetBuilder(ctx, runCtx, store, sourceDependencies, p) }) if err != nil { @@ -93,7 +93,7 @@ func NewForConfig(ctx context.Context, runCtx *runcontext.RunContext) (*Skaffold return nil, fmt.Errorf("creating builder: %w", err) } - depLister := func(ctx context.Context, artifact *latestV1.Artifact) ([]string, error) { + depLister := func(ctx context.Context, artifact *latest.Artifact) ([]string, error) { ctx, endTrace := instrumentation.StartTrace(ctx, "NewForConfig_depLister") defer endTrace() diff --git a/pkg/skaffold/runner/v1/new_test.go b/pkg/skaffold/runner/v1/new_test.go index 5f260694191..39ee79d43ec 100644 --- a/pkg/skaffold/runner/v1/new_test.go +++ b/pkg/skaffold/runner/v1/new_test.go @@ -21,7 +21,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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -98,13 +98,13 @@ func TestIsImageLocal(t *testing.T) { Opts: config.SkaffoldOptions{ PushImages: config.NewBoolOrUndefined(test.pushImagesFlagVal), }, - Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + Pipelines: runcontext.NewPipelines([]latest.Pipeline{{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ {ImageName: imageName}, }, - BuildType: latestV1.BuildType{ - LocalBuild: &latestV1.LocalBuild{ + BuildType: latest.BuildType{ + LocalBuild: &latest.LocalBuild{ Push: test.localBuildConfig, }, }, diff --git a/pkg/skaffold/runner/v1/runner_test.go b/pkg/skaffold/runner/v1/runner_test.go index 77fe66d7431..e671bc14ea2 100644 --- a/pkg/skaffold/runner/v1/runner_test.go +++ b/pkg/skaffold/runner/v1/runner_test.go @@ -42,7 +42,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/status" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/tag" @@ -129,7 +129,7 @@ func (t *TestBench) GetSyncer() sync.Syncer { func (t *TestBench) RegisterLocalImages(_ []graph.Artifact) {} func (t *TestBench) TrackBuildArtifacts(_ []graph.Artifact) {} -func (t *TestBench) TestDependencies(context.Context, *latestV1.Artifact) ([]string, error) { +func (t *TestBench) TestDependencies(context.Context, *latest.Artifact) ([]string, error) { return nil, nil } func (t *TestBench) Dependencies() ([]string, error) { return nil, nil } @@ -141,7 +141,7 @@ func (t *TestBench) enterNewCycle() { t.currentActions = Actions{} } -func (t *TestBench) Build(_ context.Context, _ io.Writer, _ tag.ImageTags, _ platform.Resolver, artifacts []*latestV1.Artifact) ([]graph.Artifact, error) { +func (t *TestBench) Build(_ context.Context, _ io.Writer, _ tag.ImageTags, _ platform.Resolver, artifacts []*latest.Artifact) ([]graph.Artifact, error) { if len(t.buildErrors) > 0 { err := t.buildErrors[0] t.buildErrors = t.buildErrors[1:] @@ -257,33 +257,33 @@ type triggerState struct { deploy bool } -func createRunner(t *testutil.T, testBench *TestBench, monitor filemon.Monitor, artifacts []*latestV1.Artifact, autoTriggers *triggerState) *SkaffoldRunner { +func createRunner(t *testutil.T, testBench *TestBench, monitor filemon.Monitor, artifacts []*latest.Artifact, autoTriggers *triggerState) *SkaffoldRunner { if autoTriggers == nil { autoTriggers = &triggerState{true, true, true} } - var tests []*latestV1.TestCase + var tests []*latest.TestCase for _, a := range artifacts { - tests = append(tests, &latestV1.TestCase{ + tests = append(tests, &latest.TestCase{ ImageName: a.ImageName, }) } - cfg := &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - TagPolicy: latestV1.TagPolicy{ + cfg := &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + TagPolicy: latest.TagPolicy{ // Use the fastest tagger - ShaTagger: &latestV1.ShaTagger{}, + ShaTagger: &latest.ShaTagger{}, }, Artifacts: artifacts, }, Test: tests, - Deploy: latestV1.DeployConfig{StatusCheckDeadlineSeconds: 60}, + Deploy: latest.DeployConfig{StatusCheckDeadlineSeconds: 60}, }, } defaults.Set(cfg) defaults.SetDefaultDeployer(cfg) runCtx := &runcontext.RunContext{ - Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{cfg.Pipeline}), + Pipelines: runcontext.NewPipelines([]latest.Pipeline{cfg.Pipeline}), Opts: config.SkaffoldOptions{ Trigger: "polling", WatchPollInterval: 100, @@ -320,7 +320,7 @@ func createRunner(t *testutil.T, testBench *TestBench, monitor filemon.Monitor, func TestNewForConfig(t *testing.T) { tests := []struct { description string - pipeline latestV1.Pipeline + pipeline latest.Pipeline shouldErr bool cacheArtifacts bool expectedBuilder build.BuilderMux @@ -329,16 +329,16 @@ func TestNewForConfig(t *testing.T) { }{ { description: "local builder config", - pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - TagPolicy: latestV1.TagPolicy{ShaTagger: &latestV1.ShaTagger{}}, - BuildType: latestV1.BuildType{ - LocalBuild: &latestV1.LocalBuild{}, + pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + TagPolicy: latest.TagPolicy{ShaTagger: &latest.ShaTagger{}}, + BuildType: latest.BuildType{ + LocalBuild: &latest.LocalBuild{}, }, }, - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{}, + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{}, }, }, }, @@ -347,16 +347,16 @@ func TestNewForConfig(t *testing.T) { }, { description: "gcb config", - pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - TagPolicy: latestV1.TagPolicy{ShaTagger: &latestV1.ShaTagger{}}, - BuildType: latestV1.BuildType{ - GoogleCloudBuild: &latestV1.GoogleCloudBuild{}, + pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + TagPolicy: latest.TagPolicy{ShaTagger: &latest.ShaTagger{}}, + BuildType: latest.BuildType{ + GoogleCloudBuild: &latest.GoogleCloudBuild{}, }, }, - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{}, + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{}, }, }, }, @@ -365,16 +365,16 @@ func TestNewForConfig(t *testing.T) { }, { description: "cluster builder config", - pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - TagPolicy: latestV1.TagPolicy{ShaTagger: &latestV1.ShaTagger{}}, - BuildType: latestV1.BuildType{ - Cluster: &latestV1.ClusterDetails{Timeout: "100s"}, + pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + TagPolicy: latest.TagPolicy{ShaTagger: &latest.ShaTagger{}}, + BuildType: latest.BuildType{ + Cluster: &latest.ClusterDetails{Timeout: "100s"}, }, }, - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{}, + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{}, }, }, }, @@ -383,16 +383,16 @@ func TestNewForConfig(t *testing.T) { }, { description: "bad tagger config", - pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - TagPolicy: latestV1.TagPolicy{}, - BuildType: latestV1.BuildType{ - LocalBuild: &latestV1.LocalBuild{}, + pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + TagPolicy: latest.TagPolicy{}, + BuildType: latest.BuildType{ + LocalBuild: &latest.LocalBuild{}, }, }, - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{}, + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{}, }, }, }, @@ -400,23 +400,23 @@ func TestNewForConfig(t *testing.T) { }, { description: "unknown builder and tagger", - pipeline: latestV1.Pipeline{}, + pipeline: latest.Pipeline{}, shouldErr: true, expectedTester: &test.FullTester{}, expectedDeployer: &kubectl.Deployer{}, }, { description: "no artifacts, cache", - pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - TagPolicy: latestV1.TagPolicy{ShaTagger: &latestV1.ShaTagger{}}, - BuildType: latestV1.BuildType{ - LocalBuild: &latestV1.LocalBuild{}, + pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + TagPolicy: latest.TagPolicy{ShaTagger: &latest.ShaTagger{}}, + BuildType: latest.BuildType{ + LocalBuild: &latest.LocalBuild{}, }, }, - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{}, + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{}, }, }, }, @@ -426,20 +426,20 @@ func TestNewForConfig(t *testing.T) { }, { description: "transformableAllowList", - pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - TagPolicy: latestV1.TagPolicy{ShaTagger: &latestV1.ShaTagger{}}, - BuildType: latestV1.BuildType{ - LocalBuild: &latestV1.LocalBuild{}, + pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + TagPolicy: latest.TagPolicy{ShaTagger: &latest.ShaTagger{}}, + BuildType: latest.BuildType{ + LocalBuild: &latest.LocalBuild{}, }, }, - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{}, + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{}, }, }, - ResourceSelector: latestV1.ResourceSelectorConfig{ - Allow: []latestV1.ResourceFilter{ + ResourceSelector: latest.ResourceSelectorConfig{ + Allow: []latest.ResourceFilter{ { GroupKind: "example.com/Application", }, @@ -451,18 +451,18 @@ func TestNewForConfig(t *testing.T) { }, { description: "multiple deployers", - pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - TagPolicy: latestV1.TagPolicy{ShaTagger: &latestV1.ShaTagger{}}, - BuildType: latestV1.BuildType{ - LocalBuild: &latestV1.LocalBuild{}, + pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + TagPolicy: latest.TagPolicy{ShaTagger: &latest.ShaTagger{}}, + BuildType: latest.BuildType{ + LocalBuild: &latest.LocalBuild{}, }, }, - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{}, - KustomizeDeploy: &latestV1.KustomizeDeploy{}, - HelmDeploy: &latestV1.HelmDeploy{}, + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{}, + KustomizeDeploy: &latest.KustomizeDeploy{}, + HelmDeploy: &latest.HelmDeploy{}, }, }, }, @@ -485,7 +485,7 @@ func TestNewForConfig(t *testing.T) { AndRunWithOutput("kubectl version --client -ojson", "v1.5.6")) runCtx := &runcontext.RunContext{ - Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{test.pipeline}), + Pipelines: runcontext.NewPipelines([]latest.Pipeline{test.pipeline}), Opts: config.SkaffoldOptions{ Trigger: "polling", }, @@ -572,22 +572,22 @@ func TestTriggerCallbackAndIntents(t *testing.T) { AutoSync: test.autoSync, AutoDeploy: test.autoDeploy, } - pipeline := latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - TagPolicy: latestV1.TagPolicy{ShaTagger: &latestV1.ShaTagger{}}, - BuildType: latestV1.BuildType{ - LocalBuild: &latestV1.LocalBuild{}, + pipeline := latest.Pipeline{ + Build: latest.BuildConfig{ + TagPolicy: latest.TagPolicy{ShaTagger: &latest.ShaTagger{}}, + BuildType: latest.BuildType{ + LocalBuild: &latest.LocalBuild{}, }, }, - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{}, + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{}, }, }, } r, _ := NewForConfig(context.Background(), &runcontext.RunContext{ Opts: opts, - Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{pipeline}), + Pipelines: runcontext.NewPipelines([]latest.Pipeline{pipeline}), }) r.intents.ResetBuild() diff --git a/pkg/skaffold/runner/v2/dev.go b/pkg/skaffold/runner/v2/dev.go index c34d818c0e0..11ced686692 100644 --- a/pkg/skaffold/runner/v2/dev.go +++ b/pkg/skaffold/runner/v2/dev.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/latest" ) -func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*latestV1.Artifact) error { +func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*latest.Artifact) error { return fmt.Errorf("not implemented error: SkaffoldRunner(v2).Dev") } diff --git a/pkg/skaffold/schema/defaults/defaults.go b/pkg/skaffold/schema/defaults/defaults.go index 672e04f8daa..88df8881f25 100644 --- a/pkg/skaffold/schema/defaults/defaults.go +++ b/pkg/skaffold/schema/defaults/defaults.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" kubectx "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" schemautil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -41,7 +41,7 @@ const ( ) // Set makes sure default values are set on a SkaffoldConfig. -func Set(c *latestV1.SkaffoldConfig) error { +func Set(c *latest.SkaffoldConfig) error { defaultToLocalBuild(c) setDefaultTagger(c) setDefaultKustomizePath(c) @@ -106,30 +106,30 @@ func Set(c *latestV1.SkaffoldConfig) error { } // SetDefaultDeployer adds a default kubectl deploy configuration. -func SetDefaultDeployer(c *latestV1.SkaffoldConfig) { +func SetDefaultDeployer(c *latest.SkaffoldConfig) { defaultToKubectlDeploy(c) setDefaultKubectlManifests(c) } -func defaultToLocalBuild(c *latestV1.SkaffoldConfig) { - if c.Build.BuildType != (latestV1.BuildType{}) { +func defaultToLocalBuild(c *latest.SkaffoldConfig) { + if c.Build.BuildType != (latest.BuildType{}) { return } log.Entry(context.TODO()).Debug("Defaulting build type to local build") - c.Build.BuildType.LocalBuild = &latestV1.LocalBuild{} + c.Build.BuildType.LocalBuild = &latest.LocalBuild{} } -func defaultToKubectlDeploy(c *latestV1.SkaffoldConfig) { - if c.Deploy.DeployType != (latestV1.DeployType{}) { +func defaultToKubectlDeploy(c *latest.SkaffoldConfig) { + if c.Deploy.DeployType != (latest.DeployType{}) { return } log.Entry(context.TODO()).Debug("Defaulting deploy type to kubectl") - c.Deploy.DeployType.KubectlDeploy = &latestV1.KubectlDeploy{} + c.Deploy.DeployType.KubectlDeploy = &latest.KubectlDeploy{} } -func withCloudBuildConfig(c *latestV1.SkaffoldConfig, operations ...func(*latestV1.GoogleCloudBuild)) { +func withCloudBuildConfig(c *latest.SkaffoldConfig, operations ...func(*latest.GoogleCloudBuild)) { if gcb := c.Build.GoogleCloudBuild; gcb != nil { for _, operation := range operations { operation(gcb) @@ -137,35 +137,35 @@ func withCloudBuildConfig(c *latestV1.SkaffoldConfig, operations ...func(*latest } } -func setDefaultCloudBuildDockerImage(gcb *latestV1.GoogleCloudBuild) { +func setDefaultCloudBuildDockerImage(gcb *latest.GoogleCloudBuild) { gcb.DockerImage = valueOrDefault(gcb.DockerImage, defaultCloudBuildDockerImage) } -func setDefaultCloudBuildMavenImage(gcb *latestV1.GoogleCloudBuild) { +func setDefaultCloudBuildMavenImage(gcb *latest.GoogleCloudBuild) { gcb.MavenImage = valueOrDefault(gcb.MavenImage, defaultCloudBuildMavenImage) } -func setDefaultCloudBuildGradleImage(gcb *latestV1.GoogleCloudBuild) { +func setDefaultCloudBuildGradleImage(gcb *latest.GoogleCloudBuild) { gcb.GradleImage = valueOrDefault(gcb.GradleImage, defaultCloudBuildGradleImage) } -func setDefaultCloudBuildKanikoImage(gcb *latestV1.GoogleCloudBuild) { +func setDefaultCloudBuildKanikoImage(gcb *latest.GoogleCloudBuild) { gcb.KanikoImage = valueOrDefault(gcb.KanikoImage, defaultCloudBuildKanikoImage) } -func setDefaultCloudBuildPackImage(gcb *latestV1.GoogleCloudBuild) { +func setDefaultCloudBuildPackImage(gcb *latest.GoogleCloudBuild) { gcb.PackImage = valueOrDefault(gcb.PackImage, defaultCloudBuildPackImage) } -func setDefaultTagger(c *latestV1.SkaffoldConfig) { - if c.Build.TagPolicy != (latestV1.TagPolicy{}) { +func setDefaultTagger(c *latest.SkaffoldConfig) { + if c.Build.TagPolicy != (latest.TagPolicy{}) { return } - c.Build.TagPolicy = latestV1.TagPolicy{GitTagger: &latestV1.GitTagger{}} + c.Build.TagPolicy = latest.TagPolicy{GitTagger: &latest.GitTagger{}} } -func setDefaultKustomizePath(c *latestV1.SkaffoldConfig) { +func setDefaultKustomizePath(c *latest.SkaffoldConfig) { kustomize := c.Deploy.KustomizeDeploy if kustomize == nil { return @@ -175,54 +175,54 @@ func setDefaultKustomizePath(c *latestV1.SkaffoldConfig) { } } -func setDefaultKubectlManifests(c *latestV1.SkaffoldConfig) { +func setDefaultKubectlManifests(c *latest.SkaffoldConfig) { if c.Deploy.KubectlDeploy != nil && len(c.Deploy.KubectlDeploy.Manifests) == 0 && len(c.Deploy.KubectlDeploy.RemoteManifests) == 0 { c.Deploy.KubectlDeploy.Manifests = constants.DefaultKubectlManifests } } -func setDefaultLogsConfig(c *latestV1.SkaffoldConfig) { +func setDefaultLogsConfig(c *latest.SkaffoldConfig) { if c.Deploy.Logs.Prefix == "" { c.Deploy.Logs.Prefix = "container" } } -func defaultToDockerArtifact(a *latestV1.Artifact) { - if a.ArtifactType == (latestV1.ArtifactType{}) { - a.ArtifactType = latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, +func defaultToDockerArtifact(a *latest.Artifact) { + if a.ArtifactType == (latest.ArtifactType{}) { + a.ArtifactType = latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, } } } -func setCustomArtifactDefaults(a *latestV1.CustomArtifact) { +func setCustomArtifactDefaults(a *latest.CustomArtifact) { if a.Dependencies == nil { - a.Dependencies = &latestV1.CustomDependencies{ + a.Dependencies = &latest.CustomDependencies{ Paths: []string{"."}, } } } -func setBuildpackArtifactDefaults(a *latestV1.BuildpackArtifact) { +func setBuildpackArtifactDefaults(a *latest.BuildpackArtifact) { if a.ProjectDescriptor == "" { a.ProjectDescriptor = constants.DefaultProjectDescriptor } if a.Dependencies == nil { - a.Dependencies = &latestV1.BuildpackDependencies{ + a.Dependencies = &latest.BuildpackDependencies{ Paths: []string{"."}, } } } -func setDockerArtifactDefaults(a *latestV1.DockerArtifact) { +func setDockerArtifactDefaults(a *latest.DockerArtifact) { a.DockerfilePath = valueOrDefault(a.DockerfilePath, constants.DefaultDockerfilePath) } -func setDefaultWorkspace(a *latestV1.Artifact) { +func setDefaultWorkspace(a *latest.Artifact) { a.Workspace = valueOrDefault(a.Workspace, ".") } -func setDefaultSync(a *latestV1.Artifact) { +func setDefaultSync(a *latest.Artifact) { if a.Sync != nil { if len(a.Sync.Manual) == 0 && len(a.Sync.Infer) == 0 && a.Sync.Auto == nil { switch { @@ -233,11 +233,11 @@ func setDefaultSync(a *latestV1.Artifact) { } } } else if a.BuildpackArtifact != nil { - a.Sync = &latestV1.Sync{Auto: util.BoolPtr(true)} + a.Sync = &latest.Sync{Auto: util.BoolPtr(true)} } } -func withClusterConfig(c *latestV1.SkaffoldConfig, opts ...func(*latestV1.ClusterDetails) error) error { +func withClusterConfig(c *latest.SkaffoldConfig, opts ...func(*latest.ClusterDetails) error) error { clusterDetails := c.Build.BuildType.Cluster if clusterDetails == nil { return nil @@ -250,7 +250,7 @@ func withClusterConfig(c *latestV1.SkaffoldConfig, opts ...func(*latestV1.Cluste return nil } -func setDefaultClusterNamespace(cluster *latestV1.ClusterDetails) error { +func setDefaultClusterNamespace(cluster *latest.ClusterDetails) error { if cluster.Namespace == "" { ns, err := currentNamespace() if err != nil { @@ -261,12 +261,12 @@ func setDefaultClusterNamespace(cluster *latestV1.ClusterDetails) error { return nil } -func setDefaultClusterTimeout(cluster *latestV1.ClusterDetails) error { +func setDefaultClusterTimeout(cluster *latest.ClusterDetails) error { cluster.Timeout = valueOrDefault(cluster.Timeout, kaniko.DefaultTimeout) return nil } -func setDefaultClusterPullSecret(cluster *latestV1.ClusterDetails) error { +func setDefaultClusterPullSecret(cluster *latest.ClusterDetails) error { cluster.PullSecretMountPath = valueOrDefault(cluster.PullSecretMountPath, kaniko.DefaultSecretMountPath) if cluster.PullSecretPath != "" { absPath, err := homedir.Expand(cluster.PullSecretPath) @@ -285,7 +285,7 @@ func setDefaultClusterPullSecret(cluster *latestV1.ClusterDetails) error { return nil } -func setDefaultClusterDockerConfigSecret(cluster *latestV1.ClusterDetails) error { +func setDefaultClusterDockerConfigSecret(cluster *latest.ClusterDetails) error { if cluster.DockerConfig == nil { return nil } @@ -311,13 +311,13 @@ func setDefaultClusterDockerConfigSecret(cluster *latestV1.ClusterDetails) error return nil } -func defaultToKanikoArtifact(artifact *latestV1.Artifact) { +func defaultToKanikoArtifact(artifact *latest.Artifact) { if artifact.KanikoArtifact == nil { - artifact.KanikoArtifact = &latestV1.KanikoArtifact{} + artifact.KanikoArtifact = &latest.KanikoArtifact{} } } -func setKanikoArtifactDefaults(a *latestV1.KanikoArtifact) { +func setKanikoArtifactDefaults(a *latest.KanikoArtifact) { a.Image = valueOrDefault(a.Image, kaniko.DefaultImage) a.DockerfilePath = valueOrDefault(a.DockerfilePath, constants.DefaultDockerfilePath) a.InitImage = valueOrDefault(a.InitImage, constants.DefaultBusyboxImage) @@ -346,7 +346,7 @@ func currentNamespace() (string, error) { return "default", nil } -func setDefaultLocalPort(pf *latestV1.PortForwardResource) { +func setDefaultLocalPort(pf *latest.PortForwardResource) { if pf.LocalPort == 0 { if pf.Port.Type == schemautil.Int { pf.LocalPort = pf.Port.IntVal @@ -354,19 +354,19 @@ func setDefaultLocalPort(pf *latestV1.PortForwardResource) { } } -func setDefaultAddress(pf *latestV1.PortForwardResource) { +func setDefaultAddress(pf *latest.PortForwardResource) { if pf.Address == "" { pf.Address = constants.DefaultPortForwardAddress } } -func setDefaultArtifactDependencyAlias(d *latestV1.ArtifactDependency) { +func setDefaultArtifactDependencyAlias(d *latest.ArtifactDependency) { if d.Alias == "" { d.Alias = d.ImageName } } -func setDefaultTestWorkspace(c *latestV1.SkaffoldConfig) { +func setDefaultTestWorkspace(c *latest.SkaffoldConfig) { for _, tc := range c.Test { if tc == nil { continue diff --git a/pkg/skaffold/schema/defaults/defaults_test.go b/pkg/skaffold/schema/defaults/defaults_test.go index 94e85f425b4..24ec4eb0bd8 100644 --- a/pkg/skaffold/schema/defaults/defaults_test.go +++ b/pkg/skaffold/schema/defaults/defaults_test.go @@ -23,20 +23,20 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/kaniko" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" schemautil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) func TestSetDefaults(t *testing.T) { - cfg := &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + cfg := &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ { ImageName: "first", - Dependencies: []*latestV1.ArtifactDependency{ + Dependencies: []*latest.ArtifactDependency{ {ImageName: "second", Alias: "secondAlias"}, {ImageName: "third"}, }, @@ -44,44 +44,44 @@ func TestSetDefaults(t *testing.T) { { ImageName: "second", Workspace: "folder", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: "Dockerfile.second", }, }, }, { ImageName: "third", - ArtifactType: latestV1.ArtifactType{ - CustomArtifact: &latestV1.CustomArtifact{}, + ArtifactType: latest.ArtifactType{ + CustomArtifact: &latest.CustomArtifact{}, }, }, { ImageName: "fourth", - ArtifactType: latestV1.ArtifactType{ - BuildpackArtifact: &latestV1.BuildpackArtifact{}, + ArtifactType: latest.ArtifactType{ + BuildpackArtifact: &latest.BuildpackArtifact{}, }, - Sync: &latestV1.Sync{}, + Sync: &latest.Sync{}, }, { ImageName: "fifth", - ArtifactType: latestV1.ArtifactType{ - JibArtifact: &latestV1.JibArtifact{}, + ArtifactType: latest.ArtifactType{ + JibArtifact: &latest.JibArtifact{}, }, - Sync: &latestV1.Sync{}, + Sync: &latest.Sync{}, }, { ImageName: "sixth", - ArtifactType: latestV1.ArtifactType{ - BuildpackArtifact: &latestV1.BuildpackArtifact{}, + ArtifactType: latest.ArtifactType{ + BuildpackArtifact: &latest.BuildpackArtifact{}, }, }, { ImageName: "seventh", - ArtifactType: latestV1.ArtifactType{ - BuildpackArtifact: &latestV1.BuildpackArtifact{}, + ArtifactType: latest.ArtifactType{ + BuildpackArtifact: &latest.BuildpackArtifact{}, }, - Sync: &latestV1.Sync{Auto: util.BoolPtr(false)}, + Sync: &latest.Sync{Auto: util.BoolPtr(false)}, }, }, }, @@ -139,37 +139,37 @@ func TestSetDefaultsOnCluster(t *testing.T) { }) // no docker config - cfg := &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + cfg := &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ { ImageName: "docker", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, }, }, { ImageName: "kaniko", - ArtifactType: latestV1.ArtifactType{ - KanikoArtifact: &latestV1.KanikoArtifact{}, + ArtifactType: latest.ArtifactType{ + KanikoArtifact: &latest.KanikoArtifact{}, }, }, { ImageName: "custom", - ArtifactType: latestV1.ArtifactType{ - CustomArtifact: &latestV1.CustomArtifact{}, + ArtifactType: latest.ArtifactType{ + CustomArtifact: &latest.CustomArtifact{}, }, }, { ImageName: "buildpacks", - ArtifactType: latestV1.ArtifactType{ - BuildpackArtifact: &latestV1.BuildpackArtifact{}, + ArtifactType: latest.ArtifactType{ + BuildpackArtifact: &latest.BuildpackArtifact{}, }, }, }, - BuildType: latestV1.BuildType{ - Cluster: &latestV1.ClusterDetails{}, + BuildType: latest.BuildType{ + Cluster: &latest.ClusterDetails{}, }, }, }, @@ -188,11 +188,11 @@ func TestSetDefaultsOnCluster(t *testing.T) { t.CheckNil(cfg.Pipeline.Build.Artifacts[3].KanikoArtifact) // pull secret set - cfg = &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - BuildType: latestV1.BuildType{ - Cluster: &latestV1.ClusterDetails{ + cfg = &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + BuildType: latest.BuildType{ + Cluster: &latest.ClusterDetails{ PullSecretPath: "path/to/pull/secret", }, }, @@ -208,11 +208,11 @@ func TestSetDefaultsOnCluster(t *testing.T) { // pull secret mount path set path := "/path" - cfg = &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - BuildType: latestV1.BuildType{ - Cluster: &latestV1.ClusterDetails{ + cfg = &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + BuildType: latest.BuildType{ + Cluster: &latest.ClusterDetails{ PullSecretPath: "path/to/pull/secret", PullSecretMountPath: path, }, @@ -227,14 +227,14 @@ func TestSetDefaultsOnCluster(t *testing.T) { t.CheckDeepEqual(path, cfg.Build.Cluster.PullSecretMountPath) // default docker config - cfg.Pipeline.Build.BuildType.Cluster.DockerConfig = &latestV1.DockerConfig{} + cfg.Pipeline.Build.BuildType.Cluster.DockerConfig = &latest.DockerConfig{} err = Set(cfg) SetDefaultDeployer(cfg) t.CheckNoError(err) // docker config with path - cfg.Pipeline.Build.BuildType.Cluster.DockerConfig = &latestV1.DockerConfig{ + cfg.Pipeline.Build.BuildType.Cluster.DockerConfig = &latest.DockerConfig{ Path: "/path", } err = Set(cfg) @@ -244,7 +244,7 @@ func TestSetDefaultsOnCluster(t *testing.T) { t.CheckDeepEqual("/path", cfg.Build.Cluster.DockerConfig.Path) // docker config with secret name - cfg.Pipeline.Build.BuildType.Cluster.DockerConfig = &latestV1.DockerConfig{ + cfg.Pipeline.Build.BuildType.Cluster.DockerConfig = &latest.DockerConfig{ SecretName: "secret", } err = Set(cfg) @@ -257,21 +257,21 @@ func TestSetDefaultsOnCluster(t *testing.T) { } func TestCustomBuildWithCluster(t *testing.T) { - cfg := &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + cfg := &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ { ImageName: "image", - ArtifactType: latestV1.ArtifactType{ - CustomArtifact: &latestV1.CustomArtifact{ + ArtifactType: latest.ArtifactType{ + CustomArtifact: &latest.CustomArtifact{ BuildCommand: "./build.sh", }, }, }, }, - BuildType: latestV1.BuildType{ - Cluster: &latestV1.ClusterDetails{}, + BuildType: latest.BuildType{ + Cluster: &latest.ClusterDetails{}, }, }, }, @@ -281,18 +281,18 @@ func TestCustomBuildWithCluster(t *testing.T) { SetDefaultDeployer(cfg) testutil.CheckError(t, false, err) - testutil.CheckDeepEqual(t, (*latestV1.KanikoArtifact)(nil), cfg.Build.Artifacts[0].KanikoArtifact) + testutil.CheckDeepEqual(t, (*latest.KanikoArtifact)(nil), cfg.Build.Artifacts[0].KanikoArtifact) } func TestSetDefaultsOnCloudBuild(t *testing.T) { - cfg := &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + cfg := &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ {ImageName: "image"}, }, - BuildType: latestV1.BuildType{ - GoogleCloudBuild: &latestV1.GoogleCloudBuild{}, + BuildType: latest.BuildType{ + GoogleCloudBuild: &latest.GoogleCloudBuild{}, }, }, }, @@ -309,23 +309,23 @@ func TestSetDefaultsOnCloudBuild(t *testing.T) { } func TestSetDefaultsOnLocalBuild(t *testing.T) { - cfg1 := &latestV1.SkaffoldConfig{Pipeline: latestV1.Pipeline{Build: latestV1.BuildConfig{}}} - cfg2 := &latestV1.SkaffoldConfig{Pipeline: latestV1.Pipeline{Build: latestV1.BuildConfig{Artifacts: []*latestV1.Artifact{{ImageName: "foo"}}}}} + cfg1 := &latest.SkaffoldConfig{Pipeline: latest.Pipeline{Build: latest.BuildConfig{}}} + cfg2 := &latest.SkaffoldConfig{Pipeline: latest.Pipeline{Build: latest.BuildConfig{Artifacts: []*latest.Artifact{{ImageName: "foo"}}}}} err := Set(cfg1) testutil.CheckError(t, false, err) SetDefaultDeployer(cfg1) - testutil.CheckDeepEqual(t, latestV1.LocalBuild{}, *cfg1.Build.LocalBuild) + testutil.CheckDeepEqual(t, latest.LocalBuild{}, *cfg1.Build.LocalBuild) err = Set(cfg2) testutil.CheckError(t, false, err) SetDefaultDeployer(cfg2) } func TestSetPortForwardLocalPort(t *testing.T) { - cfg := &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{}, - PortForward: []*latestV1.PortForwardResource{ + cfg := &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{}, + PortForward: []*latest.PortForwardResource{ { Type: constants.Service, Port: schemautil.FromInt(8080), @@ -345,10 +345,10 @@ func TestSetPortForwardLocalPort(t *testing.T) { } func TestSetPortForwardOnEmptyPortForwardResource(t *testing.T) { - cfg := &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{}, - PortForward: []*latestV1.PortForwardResource{ + cfg := &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{}, + PortForward: []*latest.PortForwardResource{ nil, }, }, @@ -358,10 +358,10 @@ func TestSetPortForwardOnEmptyPortForwardResource(t *testing.T) { } func TestSetDefaultPortForwardAddress(t *testing.T) { - cfg := &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{}, - PortForward: []*latestV1.PortForwardResource{ + cfg := &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{}, + PortForward: []*latest.PortForwardResource{ { Type: constants.Service, Address: "0.0.0.0", @@ -381,60 +381,60 @@ func TestSetDefaultPortForwardAddress(t *testing.T) { func TestSetDefaultDeployer(t *testing.T) { tests := []struct { description string - cfg *latestV1.SkaffoldConfig - expected latestV1.DeployConfig + cfg *latest.SkaffoldConfig + expected latest.DeployConfig }{ { description: "no deployer definition", - cfg: &latestV1.SkaffoldConfig{}, - expected: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{Manifests: []string{"k8s/*.yaml"}}, + cfg: &latest.SkaffoldConfig{}, + expected: latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{Manifests: []string{"k8s/*.yaml"}}, }, }, }, { description: "existing kubectl definition with local manifests", - cfg: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{Manifests: []string{"foo.yaml"}}, + cfg: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{Manifests: []string{"foo.yaml"}}, }}, }, }, - expected: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{Manifests: []string{"foo.yaml"}}, + expected: latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{Manifests: []string{"foo.yaml"}}, }, }, }, { description: "existing kubectl definition with remote manifests", - cfg: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{RemoteManifests: []string{"foo:bar"}}, + cfg: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{RemoteManifests: []string{"foo:bar"}}, }}, }, }, - expected: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{RemoteManifests: []string{"foo:bar"}}, + expected: latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{RemoteManifests: []string{"foo:bar"}}, }, }, }, { description: "existing helm definition", - cfg: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{DeployType: latestV1.DeployType{ - HelmDeploy: &latestV1.HelmDeploy{Releases: []latestV1.HelmRelease{{ChartPath: "foo"}}}, + cfg: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{DeployType: latest.DeployType{ + HelmDeploy: &latest.HelmDeploy{Releases: []latest.HelmRelease{{ChartPath: "foo"}}}, }}, }, }, - expected: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - HelmDeploy: &latestV1.HelmDeploy{Releases: []latestV1.HelmRelease{{ChartPath: "foo"}}}, + expected: latest.DeployConfig{ + DeployType: latest.DeployType{ + HelmDeploy: &latest.HelmDeploy{Releases: []latest.HelmRelease{{ChartPath: "foo"}}}, }, }, }, @@ -450,31 +450,31 @@ func TestSetDefaultDeployer(t *testing.T) { func TestSetLogsConfig(t *testing.T) { tests := []struct { description string - input latestV1.LogsConfig - expected latestV1.LogsConfig + input latest.LogsConfig + expected latest.LogsConfig }{ { description: "prefix defaults to 'container'", - input: latestV1.LogsConfig{}, - expected: latestV1.LogsConfig{ + input: latest.LogsConfig{}, + expected: latest.LogsConfig{ Prefix: "container", }, }, { description: "don't override existing prefix", - input: latestV1.LogsConfig{ + input: latest.LogsConfig{ Prefix: "none", }, - expected: latestV1.LogsConfig{ + expected: latest.LogsConfig{ Prefix: "none", }, }, } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - cfg := latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ + cfg := latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{ Logs: test.input, }, }, diff --git a/pkg/skaffold/schema/latest/v1/config.go b/pkg/skaffold/schema/latest/config.go similarity index 99% rename from pkg/skaffold/schema/latest/v1/config.go rename to pkg/skaffold/schema/latest/config.go index d04b5297c0d..6cbb1f07517 100644 --- a/pkg/skaffold/schema/latest/v1/config.go +++ b/pkg/skaffold/schema/latest/config.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1 +package latest import ( "encoding/json" diff --git a/pkg/skaffold/schema/latest/v1/upgrade.go b/pkg/skaffold/schema/latest/upgrade.go similarity index 98% rename from pkg/skaffold/schema/latest/v1/upgrade.go rename to pkg/skaffold/schema/latest/upgrade.go index 6bb60e1e261..225a031d998 100644 --- a/pkg/skaffold/schema/latest/v1/upgrade.go +++ b/pkg/skaffold/schema/latest/upgrade.go @@ -13,7 +13,7 @@ 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 v1 +package latest import ( "errors" diff --git a/pkg/skaffold/schema/profiles.go b/pkg/skaffold/schema/profiles.go index 236dbaa287c..9a55f869871 100644 --- a/pkg/skaffold/schema/profiles.go +++ b/pkg/skaffold/schema/profiles.go @@ -31,7 +31,7 @@ import ( kubectx "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser/configlocations" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" skutil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" @@ -41,7 +41,7 @@ import ( // ApplyProfiles modifies the input skaffold configuration by the application // of a list of profiles, and returns the list of applied profiles. -func ApplyProfiles(c *latestV1.SkaffoldConfig, fieldsOverrodeByProfile map[string]configlocations.YAMLOverrideInfo, opts cfg.SkaffoldOptions, namedProfiles []string) ([]string, map[string]configlocations.YAMLOverrideInfo, error) { +func ApplyProfiles(c *latest.SkaffoldConfig, fieldsOverrodeByProfile map[string]configlocations.YAMLOverrideInfo, opts cfg.SkaffoldOptions, namedProfiles []string) ([]string, map[string]configlocations.YAMLOverrideInfo, error) { byName := profilesByName(c.Profiles) profiles, contextSpecificProfiles, err := activatedProfiles(c.Profiles, opts, namedProfiles) @@ -89,7 +89,7 @@ func checkKubeContextConsistency(contextSpecificProfiles []string, cliContext, e // activatedProfiles returns the activated profiles and activated profiles which are kube-context specific. // The latter matters for error reporting when the effective kube-context changes. -func activatedProfiles(profiles []latestV1.Profile, opts cfg.SkaffoldOptions, namedProfiles []string) ([]string, []string, error) { +func activatedProfiles(profiles []latest.Profile, opts cfg.SkaffoldOptions, namedProfiles []string) ([]string, []string, error) { var activated []string var contextSpecificProfiles []string @@ -198,7 +198,7 @@ func isKubeContext(kubeContext string, opts cfg.SkaffoldOptions) (bool, error) { return skutil.RegexEqual(kubeContext, currentKubeConfig.CurrentContext), nil } -func applyProfile(config *latestV1.SkaffoldConfig, fieldsOverrodeByProfile map[string]configlocations.YAMLOverrideInfo, profile latestV1.Profile) error { +func applyProfile(config *latest.SkaffoldConfig, fieldsOverrodeByProfile map[string]configlocations.YAMLOverrideInfo, profile latest.Profile) error { log.Entry(context.TODO()).Infof("applying profile: %s", profile.Name) // Apply profile, field by field @@ -268,7 +268,7 @@ func applyProfile(config *latestV1.SkaffoldConfig, fieldsOverrodeByProfile map[s return err } - *config = latestV1.SkaffoldConfig{} + *config = latest.SkaffoldConfig{} return yaml.Unmarshal(buf, config) } @@ -286,8 +286,8 @@ func tryPatch(patch yamlpatch.Operation, buf []byte) (valid bool) { return err == nil } -func profilesByName(profiles []latestV1.Profile) map[string]latestV1.Profile { - byName := make(map[string]latestV1.Profile) +func profilesByName(profiles []latest.Profile) map[string]latest.Profile { + byName := make(map[string]latest.Profile) for _, profile := range profiles { byName[profile.Name] = profile } diff --git a/pkg/skaffold/schema/profiles_test.go b/pkg/skaffold/schema/profiles_test.go index 081cd2c2e5f..1df989c4b42 100644 --- a/pkg/skaffold/schema/profiles_test.go +++ b/pkg/skaffold/schema/profiles_test.go @@ -27,7 +27,7 @@ import ( cfg "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" kubectx "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser/configlocations" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -68,14 +68,14 @@ profiles: t.CheckNoError(err) t.CheckTrue(len(parsed) > 0) - skaffoldConfig := parsed[0].(*latestV1.SkaffoldConfig) + skaffoldConfig := parsed[0].(*latest.SkaffoldConfig) activated, _, err := ApplyProfiles(skaffoldConfig, map[string]configlocations.YAMLOverrideInfo{}, cfg.SkaffoldOptions{}, []string{"patches"}) t.CheckNoError(err) t.CheckDeepEqual([]string{"patches"}, activated) t.CheckDeepEqual("replacement", skaffoldConfig.Build.Artifacts[0].ImageName) t.CheckDeepEqual("Dockerfile.DEV", skaffoldConfig.Build.Artifacts[0].DockerArtifact.DockerfilePath) t.CheckDeepEqual("Dockerfile.second", skaffoldConfig.Build.Artifacts[1].DockerArtifact.DockerfilePath) - t.CheckDeepEqual(latestV1.DeployConfig{}, skaffoldConfig.Deploy) + t.CheckDeepEqual(latest.DeployConfig{}, skaffoldConfig.Deploy) }) } @@ -98,7 +98,7 @@ profiles: t.CheckNoError(err) t.CheckTrue(len(parsed) > 0) - skaffoldConfig := parsed[0].(*latestV1.SkaffoldConfig) + skaffoldConfig := parsed[0].(*latest.SkaffoldConfig) _, _, err = ApplyProfiles(skaffoldConfig, map[string]configlocations.YAMLOverrideInfo{}, cfg.SkaffoldOptions{}, []string{"patches"}) t.CheckErrorAndDeepEqual(true, err, `applying profile "patches": invalid path: /build/artifacts/0/image/`, err.Error()) }) @@ -107,9 +107,9 @@ profiles: func TestApplyProfiles(t *testing.T) { tests := []struct { description string - config *latestV1.SkaffoldConfig + config *latest.SkaffoldConfig profile string - expected *latestV1.SkaffoldConfig + expected *latest.SkaffoldConfig kubeContextCli string profileAutoActivationCli bool shouldErr bool @@ -124,12 +124,12 @@ func TestApplyProfiles(t *testing.T) { withDockerArtifact("image", ".", "Dockerfile"), ), withKubectlDeploy("k8s/*.yaml"), - withProfiles(latestV1.Profile{ + withProfiles(latest.Profile{ Name: "profile", - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - BuildType: latestV1.BuildType{ - GoogleCloudBuild: &latestV1.GoogleCloudBuild{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + BuildType: latest.BuildType{ + GoogleCloudBuild: &latest.GoogleCloudBuild{ ProjectID: "my-project", DockerImage: "gcr.io/cloud-builders/docker", MavenImage: "gcr.io/cloud-builders/mvn", @@ -160,11 +160,11 @@ func TestApplyProfiles(t *testing.T) { withDockerArtifact("image", ".", "Dockerfile"), ), withKubectlDeploy("k8s/*.yaml"), - withProfiles(latestV1.Profile{ + withProfiles(latest.Profile{ Name: "dev", - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - TagPolicy: latestV1.TagPolicy{ShaTagger: &latestV1.ShaTagger{}}, + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + TagPolicy: latest.TagPolicy{ShaTagger: &latest.ShaTagger{}}, }, }, }), @@ -187,18 +187,18 @@ func TestApplyProfiles(t *testing.T) { withDockerArtifact("image", ".", "Dockerfile"), ), withKubectlDeploy("k8s/*.yaml"), - withProfiles(latestV1.Profile{ + withProfiles(latest.Profile{ Name: "profile", - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ - {ImageName: "image", Workspace: ".", ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ + {ImageName: "image", Workspace: ".", ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: "Dockerfile.DEV", }, }}, - {ImageName: "imageProd", Workspace: ".", ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + {ImageName: "imageProd", Workspace: ".", ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: "Dockerfile.DEV", }, }}, @@ -225,12 +225,12 @@ func TestApplyProfiles(t *testing.T) { withGitTagger(), ), withKubectlDeploy("k8s/*.yaml"), - withProfiles(latestV1.Profile{ + withProfiles(latest.Profile{ Name: "profile", - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - HelmDeploy: &latestV1.HelmDeploy{}, + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + HelmDeploy: &latest.HelmDeploy{}, }, }, }, @@ -254,9 +254,9 @@ func TestApplyProfiles(t *testing.T) { withDockerArtifact("image", ".", "Dockerfile"), ), withKubectlDeploy("k8s/*.yaml"), - withProfiles(latestV1.Profile{ + withProfiles(latest.Profile{ Name: "profile", - Patches: []latestV1.JSONPatch{{ + Patches: []latest.JSONPatch{{ Path: "/build/artifacts/0/docker/dockerfile", Value: &util.YamlpatchNode{Node: *yamlpatch.NewNode(str("Dockerfile.DEV"))}, }}, @@ -280,9 +280,9 @@ func TestApplyProfiles(t *testing.T) { withDockerArtifact("image", ".", "Dockerfile"), ), withKubectlDeploy("k8s/*.yaml"), - withProfiles(latestV1.Profile{ + withProfiles(latest.Profile{ Name: "profile", - Patches: []latestV1.JSONPatch{{ + Patches: []latest.JSONPatch{{ Path: "/unknown", Op: "replace", }}, @@ -298,10 +298,10 @@ func TestApplyProfiles(t *testing.T) { withLocalBuild( withGitTagger(), ), - withProfiles(latestV1.Profile{ + withProfiles(latest.Profile{ Name: "profile", - Pipeline: latestV1.Pipeline{ - Test: []*latestV1.TestCase{{ + Pipeline: latest.Pipeline{ + Test: []*latest.TestCase{{ ImageName: "image", StructureTests: []string{"test/*"}, }}, @@ -312,7 +312,7 @@ func TestApplyProfiles(t *testing.T) { withLocalBuild( withGitTagger(), ), - withTests(&latestV1.TestCase{ + withTests(&latest.TestCase{ ImageName: "image", StructureTests: []string{"test/*"}, }), @@ -326,10 +326,10 @@ func TestApplyProfiles(t *testing.T) { withLocalBuild( withGitTagger(), ), - withProfiles(latestV1.Profile{ + withProfiles(latest.Profile{ Name: "profile", - Pipeline: latestV1.Pipeline{ - PortForward: []*latestV1.PortForwardResource{{ + Pipeline: latest.Pipeline{ + PortForward: []*latest.PortForwardResource{{ Namespace: "ns", Name: "name", Type: "service", @@ -343,7 +343,7 @@ func TestApplyProfiles(t *testing.T) { withLocalBuild( withGitTagger(), ), - withPortForward(&latestV1.PortForwardResource{ + withPortForward(&latest.PortForwardResource{ Namespace: "ns", Name: "name", Type: "service", @@ -357,16 +357,16 @@ func TestApplyProfiles(t *testing.T) { profile: "profile", profileAutoActivationCli: true, config: config( - withProfiles(latestV1.Profile{ + withProfiles(latest.Profile{ Name: "profile", - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{ KubeContext: "staging", }, }}, - latestV1.Profile{ + latest.Profile{ Name: "prod", - Activation: []latestV1.Activation{{KubeContext: "prod-context"}}, + Activation: []latest.Activation{{KubeContext: "prod-context"}}, }, ), ), @@ -377,10 +377,10 @@ func TestApplyProfiles(t *testing.T) { profile: "profile", profileAutoActivationCli: true, config: config( - withProfiles(latestV1.Profile{ + withProfiles(latest.Profile{ Name: "profile", - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{ KubeContext: "staging", }, }}, @@ -396,14 +396,14 @@ func TestApplyProfiles(t *testing.T) { profileAutoActivationCli: true, config: config( withProfiles( - latestV1.Profile{ + latest.Profile{ Name: "prod", - Activation: []latestV1.Activation{{KubeContext: "prod-context"}}, + Activation: []latest.Activation{{KubeContext: "prod-context"}}, }, - latestV1.Profile{ + latest.Profile{ Name: "profile", - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{ KubeContext: "staging", }, }}, @@ -424,15 +424,15 @@ func TestApplyProfiles(t *testing.T) { withDockerArtifact("image", ".", "Dockerfile"), ), withKubectlDeploy("k8s/*.yaml"), - withProfiles(latestV1.Profile{ + withProfiles(latest.Profile{ Name: "dev", }, - latestV1.Profile{ + latest.Profile{ Name: "prod", - Activation: []latestV1.Activation{{KubeContext: "prod-context"}}, - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - TagPolicy: latestV1.TagPolicy{ShaTagger: &latestV1.ShaTagger{}}, + Activation: []latest.Activation{{KubeContext: "prod-context"}}, + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + TagPolicy: latest.TagPolicy{ShaTagger: &latest.ShaTagger{}}, }, }, }), @@ -455,15 +455,15 @@ func TestApplyProfiles(t *testing.T) { withDockerArtifact("image", ".", "Dockerfile"), ), withKubectlDeploy("k8s/*.yaml"), - withProfiles(latestV1.Profile{ + withProfiles(latest.Profile{ Name: "dev", }, - latestV1.Profile{ + latest.Profile{ Name: "prod", - Activation: []latestV1.Activation{{KubeContext: "prod-context"}}, - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - TagPolicy: latestV1.TagPolicy{ShaTagger: &latestV1.ShaTagger{}}, + Activation: []latest.Activation{{KubeContext: "prod-context"}}, + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + TagPolicy: latest.TagPolicy{ShaTagger: &latest.ShaTagger{}}, }, }, }), @@ -498,7 +498,7 @@ func TestApplyProfiles(t *testing.T) { func TestActivatedProfiles(t *testing.T) { tests := []struct { description string - profiles []latestV1.Profile + profiles []latest.Profile opts cfg.SkaffoldOptions envs map[string]string expected []string @@ -511,7 +511,7 @@ func TestActivatedProfiles(t *testing.T) { Command: "dev", Profiles: []string{"activated", "also-activated"}, }, - profiles: []latestV1.Profile{ + profiles: []latest.Profile{ {Name: "activated"}, {Name: "not-activated"}, {Name: "also-activated"}, @@ -523,12 +523,12 @@ func TestActivatedProfiles(t *testing.T) { ProfileAutoActivation: true, Command: "dev", }, - profiles: []latestV1.Profile{ - {Name: "run-profile", Activation: []latestV1.Activation{{Command: "run"}}}, - {Name: "dev-profile", Activation: []latestV1.Activation{{Command: "dev"}}}, - {Name: "non-run-profile", Activation: []latestV1.Activation{{Command: "!run"}}}, - {Name: "run-or-dev-profile", Activation: []latestV1.Activation{{Command: "(run)|(dev)"}}}, - {Name: "other-profile", Activation: []latestV1.Activation{{Command: "!(run)|(dev)"}}}, + profiles: []latest.Profile{ + {Name: "run-profile", Activation: []latest.Activation{{Command: "run"}}}, + {Name: "dev-profile", Activation: []latest.Activation{{Command: "dev"}}}, + {Name: "non-run-profile", Activation: []latest.Activation{{Command: "!run"}}}, + {Name: "run-or-dev-profile", Activation: []latest.Activation{{Command: "(run)|(dev)"}}}, + {Name: "other-profile", Activation: []latest.Activation{{Command: "!(run)|(dev)"}}}, }, expected: []string{"dev-profile", "non-run-profile", "run-or-dev-profile"}, }, { @@ -537,14 +537,14 @@ func TestActivatedProfiles(t *testing.T) { opts: cfg.SkaffoldOptions{ ProfileAutoActivation: true, }, - profiles: []latestV1.Profile{ - {Name: "activated", Activation: []latestV1.Activation{{Env: "KEY=VALUE"}}}, - {Name: "not-activated", Activation: []latestV1.Activation{{Env: "KEY=OTHER"}}}, - {Name: "also-activated", Activation: []latestV1.Activation{{Env: "KEY=!OTHER"}}}, - {Name: "not-treated-as-regex", Activation: []latestV1.Activation{{Env: "KEY="}}}, - {Name: "regex-activated", Activation: []latestV1.Activation{{Env: "KEY=V.*E"}}}, - {Name: "regex-activated-two", Activation: []latestV1.Activation{{Env: "KEY=^V.*E$"}}}, - {Name: "regex-activated-substring-match", Activation: []latestV1.Activation{{Env: "KEY=^VAL"}}}, + profiles: []latest.Profile{ + {Name: "activated", Activation: []latest.Activation{{Env: "KEY=VALUE"}}}, + {Name: "not-activated", Activation: []latest.Activation{{Env: "KEY=OTHER"}}}, + {Name: "also-activated", Activation: []latest.Activation{{Env: "KEY=!OTHER"}}}, + {Name: "not-treated-as-regex", Activation: []latest.Activation{{Env: "KEY="}}}, + {Name: "regex-activated", Activation: []latest.Activation{{Env: "KEY=V.*E"}}}, + {Name: "regex-activated-two", Activation: []latest.Activation{{Env: "KEY=^V.*E$"}}}, + {Name: "regex-activated-substring-match", Activation: []latest.Activation{{Env: "KEY=^VAL"}}}, }, expected: []string{"activated", "also-activated", "regex-activated", "regex-activated-two", "regex-activated-substring-match"}, }, { @@ -555,10 +555,10 @@ func TestActivatedProfiles(t *testing.T) { Command: "dev", Profiles: []string{"activated", "also-activated"}, }, - profiles: []latestV1.Profile{ - {Name: "activated", Activation: []latestV1.Activation{{Env: "KEY=VALUE"}, {Command: "dev"}}}, - {Name: "not-activated", Activation: []latestV1.Activation{{Env: "KEY=OTHER"}}}, - {Name: "also-activated", Activation: []latestV1.Activation{{Env: "KEY=!OTHER"}}}, + profiles: []latest.Profile{ + {Name: "activated", Activation: []latest.Activation{{Env: "KEY=VALUE"}, {Command: "dev"}}}, + {Name: "not-activated", Activation: []latest.Activation{{Env: "KEY=OTHER"}}}, + {Name: "also-activated", Activation: []latest.Activation{{Env: "KEY=!OTHER"}}}, }, expected: []string{"activated", "also-activated"}, }, { @@ -567,8 +567,8 @@ func TestActivatedProfiles(t *testing.T) { opts: cfg.SkaffoldOptions{ ProfileAutoActivation: true, }, - profiles: []latestV1.Profile{ - {Name: "activated", Activation: []latestV1.Activation{{Env: "KEY:VALUE"}}}, + profiles: []latest.Profile{ + {Name: "activated", Activation: []latest.Activation{{Env: "KEY:VALUE"}}}, }, shouldErr: true, }, { @@ -576,13 +576,13 @@ func TestActivatedProfiles(t *testing.T) { opts: cfg.SkaffoldOptions{ ProfileAutoActivation: true, }, - profiles: []latestV1.Profile{ - {Name: "activated", Activation: []latestV1.Activation{{KubeContext: "prod-context"}}}, - {Name: "not-activated", Activation: []latestV1.Activation{{KubeContext: "dev-context"}}}, - {Name: "also-activated", Activation: []latestV1.Activation{{KubeContext: "!dev-context"}}}, - {Name: "activated-regexp", Activation: []latestV1.Activation{{KubeContext: "prod-.*"}}}, - {Name: "not-activated-regexp", Activation: []latestV1.Activation{{KubeContext: "dev-.*"}}}, - {Name: "invalid-regexp", Activation: []latestV1.Activation{{KubeContext: `\`}}}, + profiles: []latest.Profile{ + {Name: "activated", Activation: []latest.Activation{{KubeContext: "prod-context"}}}, + {Name: "not-activated", Activation: []latest.Activation{{KubeContext: "dev-context"}}}, + {Name: "also-activated", Activation: []latest.Activation{{KubeContext: "!dev-context"}}}, + {Name: "activated-regexp", Activation: []latest.Activation{{KubeContext: "prod-.*"}}}, + {Name: "not-activated-regexp", Activation: []latest.Activation{{KubeContext: "dev-.*"}}}, + {Name: "invalid-regexp", Activation: []latest.Activation{{KubeContext: `\`}}}, }, expected: []string{"activated", "also-activated", "activated-regexp"}, }, { @@ -592,16 +592,16 @@ func TestActivatedProfiles(t *testing.T) { ProfileAutoActivation: true, Command: "dev", }, - profiles: []latestV1.Profile{ + profiles: []latest.Profile{ { - Name: "activated", Activation: []latestV1.Activation{{ + Name: "activated", Activation: []latest.Activation{{ Env: "KEY=VALUE", KubeContext: "prod-context", Command: "dev", }}, }, { - Name: "not-activated", Activation: []latestV1.Activation{{ + Name: "not-activated", Activation: []latest.Activation{{ Env: "KEY=VALUE", KubeContext: "prod-context", Command: "build", @@ -615,9 +615,9 @@ func TestActivatedProfiles(t *testing.T) { ProfileAutoActivation: true, Command: "dev", }, - profiles: []latestV1.Profile{ + profiles: []latest.Profile{ { - Name: "activated", Activation: []latestV1.Activation{{ + Name: "activated", Activation: []latest.Activation{{ Command: "run", }, { Command: "dev", @@ -633,34 +633,34 @@ func TestActivatedProfiles(t *testing.T) { ProfileAutoActivation: true, Command: "dev", }, - profiles: []latestV1.Profile{ + profiles: []latest.Profile{ { - Name: "empty", Activation: []latestV1.Activation{{ + Name: "empty", Activation: []latest.Activation{{ Env: "ABC=", }}, }, { - Name: "empty-by-regex", Activation: []latestV1.Activation{{ + Name: "empty-by-regex", Activation: []latest.Activation{{ Env: "ABC=^$", }}, }, { - Name: "not-empty", Activation: []latestV1.Activation{{ + Name: "not-empty", Activation: []latest.Activation{{ Env: "ABC=!", }}, }, { - Name: "one", Activation: []latestV1.Activation{{ + Name: "one", Activation: []latest.Activation{{ Env: "ABC=1", }}, }, { - Name: "not-one", Activation: []latestV1.Activation{{ + Name: "not-one", Activation: []latest.Activation{{ Env: "ABC=!1", }}, }, { - Name: "two", Activation: []latestV1.Activation{{ + Name: "two", Activation: []latest.Activation{{ Env: "ABC=2", }}, }, @@ -674,33 +674,33 @@ func TestActivatedProfiles(t *testing.T) { ProfileAutoActivation: true, Command: "dev", }, - profiles: []latestV1.Profile{ + profiles: []latest.Profile{ { - Name: "empty", Activation: []latestV1.Activation{{ + Name: "empty", Activation: []latest.Activation{{ Env: "ABC=", }}, }, { - Name: "one", Activation: []latestV1.Activation{{ + Name: "one", Activation: []latest.Activation{{ Env: "ABC=1", }}, }, { - Name: "one-as-well", Activation: []latestV1.Activation{{ + Name: "one-as-well", Activation: []latest.Activation{{ Command: "not-triggered", }, { Env: "ABC=1", }}, }, { - Name: "two", Activation: []latestV1.Activation{{ + Name: "two", Activation: []latest.Activation{{ Command: "build", }, { Env: "ABC=2", }}, }, { - Name: "not-two", Activation: []latestV1.Activation{{ + Name: "not-two", Activation: []latest.Activation{{ Command: "build", }, { Env: "ABC=!2", @@ -716,10 +716,10 @@ func TestActivatedProfiles(t *testing.T) { Command: "run", Profiles: []string{"activated", "also-activated"}, }, - profiles: []latestV1.Profile{ + profiles: []latest.Profile{ {Name: "activated"}, {Name: "also-activated"}, - {Name: "run-profile", Activation: []latestV1.Activation{{Command: "run"}}}, + {Name: "run-profile", Activation: []latest.Activation{{Command: "run"}}}, }, expected: []string{"run-profile", "activated", "also-activated"}, }, @@ -730,12 +730,12 @@ func TestActivatedProfiles(t *testing.T) { Command: "dev", Profiles: []string{"activated", "also-activated"}, }, - profiles: []latestV1.Profile{ + profiles: []latest.Profile{ {Name: "activated"}, {Name: "not-activated"}, {Name: "also-activated"}, - {Name: "not-activated-regexp", Activation: []latestV1.Activation{{KubeContext: "prod-.*"}}}, - {Name: "not-activated-kubecontext", Activation: []latestV1.Activation{{KubeContext: "prod-context"}}}, + {Name: "not-activated-regexp", Activation: []latest.Activation{{KubeContext: "prod-.*"}}}, + {Name: "not-activated-kubecontext", Activation: []latest.Activation{{KubeContext: "prod-context"}}}, }, expected: []string{"activated", "also-activated"}, }, @@ -746,9 +746,9 @@ func TestActivatedProfiles(t *testing.T) { Command: "dev", Profiles: []string{"-dev-profile"}, }, - profiles: []latestV1.Profile{ - {Name: "dev-profile", Activation: []latestV1.Activation{{Command: "dev"}}}, - {Name: "run-or-dev-profile", Activation: []latestV1.Activation{{Command: "(run)|(dev)"}}}, + profiles: []latest.Profile{ + {Name: "dev-profile", Activation: []latest.Activation{{Command: "dev"}}}, + {Name: "run-or-dev-profile", Activation: []latest.Activation{{Command: "(run)|(dev)"}}}, }, expected: []string{"run-or-dev-profile"}, }, @@ -798,19 +798,19 @@ profiles: t.RequireNoError(err) t.CheckTrue(len(parsed) > 0) - skaffoldConfig := parsed[0].(*latestV1.SkaffoldConfig) + skaffoldConfig := parsed[0].(*latest.SkaffoldConfig) t.CheckDeepEqual(2, len(skaffoldConfig.Profiles)) t.CheckDeepEqual("simple1", skaffoldConfig.Profiles[0].Name) - t.CheckDeepEqual([]latestV1.Activation{{Env: "ABC=common"}, {Env: "ABC=1"}}, skaffoldConfig.Profiles[0].Activation) + t.CheckDeepEqual([]latest.Activation{{Env: "ABC=common"}, {Env: "ABC=1"}}, skaffoldConfig.Profiles[0].Activation) t.CheckDeepEqual("simple2", skaffoldConfig.Profiles[1].Name) - t.CheckDeepEqual([]latestV1.Activation{{Env: "ABC=common"}, {Env: "ABC=2"}}, skaffoldConfig.Profiles[1].Activation) + t.CheckDeepEqual([]latest.Activation{{Env: "ABC=common"}, {Env: "ABC=2"}}, skaffoldConfig.Profiles[1].Activation) applied, _, err := ApplyProfiles(skaffoldConfig, map[string]configlocations.YAMLOverrideInfo{}, cfg.SkaffoldOptions{}, []string{"simple1"}) t.CheckNoError(err) t.CheckDeepEqual([]string{"simple1"}, applied) t.CheckDeepEqual(1, len(skaffoldConfig.Build.Artifacts)) - t.CheckDeepEqual(latestV1.Artifact{ImageName: "simpleimage1"}, *skaffoldConfig.Build.Artifacts[0]) + t.CheckDeepEqual(latest.Artifact{ImageName: "simpleimage1"}, *skaffoldConfig.Build.Artifacts[0]) }) } @@ -820,7 +820,7 @@ func str(value string) *interface{} { } func addVersion(yaml string) string { - return fmt.Sprintf("apiVersion: %s\nkind: Config\n%s", latestV1.Version, yaml) + return fmt.Sprintf("apiVersion: %s\nkind: Config\n%s", latest.Version, yaml) } func setupFakeKubeConfig(t *testutil.T, config api.Config) { diff --git a/pkg/skaffold/schema/v2beta27/upgrade.go b/pkg/skaffold/schema/v2beta27/upgrade.go index d8f46bf5fdc..d72da296609 100755 --- a/pkg/skaffold/schema/v2beta27/upgrade.go +++ b/pkg/skaffold/schema/v2beta27/upgrade.go @@ -17,7 +17,7 @@ limitations under the License. package v2beta27 import ( - next "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + next "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" pkgutil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) diff --git a/pkg/skaffold/schema/v2beta27/upgrade_test.go b/pkg/skaffold/schema/v2beta27/upgrade_test.go index 88bed0ba707..2e29f970d0a 100755 --- a/pkg/skaffold/schema/v2beta27/upgrade_test.go +++ b/pkg/skaffold/schema/v2beta27/upgrade_test.go @@ -19,7 +19,7 @@ package v2beta27 import ( "testing" - next "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + next "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml" "github.com/GoogleContainerTools/skaffold/testutil" ) diff --git a/pkg/skaffold/schema/validation/samples_test.go b/pkg/skaffold/schema/validation/samples_test.go index e8e05025cd9..75ce9f2514a 100644 --- a/pkg/skaffold/schema/validation/samples_test.go +++ b/pkg/skaffold/schema/validation/samples_test.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/walk" "github.com/GoogleContainerTools/skaffold/testutil" @@ -83,7 +83,7 @@ func checkSkaffoldConfig(t *testutil.T, yaml []byte) { t.CheckNoError(err) var cfgs parser.SkaffoldConfigSet for _, p := range parsed { - cfg := &parser.SkaffoldConfigEntry{SkaffoldConfig: p.(*latestV1.SkaffoldConfig)} + cfg := &parser.SkaffoldConfigEntry{SkaffoldConfig: p.(*latest.SkaffoldConfig)} err = defaults.Set(cfg.SkaffoldConfig) defaults.SetDefaultDeployer(cfg.SkaffoldConfig) t.CheckNoError(err) @@ -123,5 +123,5 @@ func addHeader(buf []byte) []byte { if bytes.HasPrefix(buf, []byte("apiVersion:")) { return buf } - return []byte(fmt.Sprintf("apiVersion: %s\nkind: Config\n%s", latestV1.Version, buf)) + return []byte(fmt.Sprintf("apiVersion: %s\nkind: Config\n%s", latest.Version, buf)) } diff --git a/pkg/skaffold/schema/validation/validation.go b/pkg/skaffold/schema/validation/validation.go index 8417cb9b29b..efd2dc0d480 100644 --- a/pkg/skaffold/schema/validation/validation.go +++ b/pkg/skaffold/schema/validation/validation.go @@ -37,7 +37,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser/configlocations" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util/stringslice" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yamltags" @@ -128,7 +128,7 @@ func ProcessWithRunContext(ctx context.Context, runCtx *runcontext.RunContext) e } // validateTaggingPolicy checks that the tagging policy is valid in combination with other options. -func validateTaggingPolicy(cfg *parser.SkaffoldConfigEntry, bc latestV1.BuildConfig) (cfgErrs []ErrorWithLocation) { +func validateTaggingPolicy(cfg *parser.SkaffoldConfigEntry, bc latest.BuildConfig) (cfgErrs []ErrorWithLocation) { if bc.LocalBuild != nil { // sha256 just uses `latest` tag, so tryImportMissing will virtually always succeed (#4889) if bc.LocalBuild.TryImportMissing && bc.TagPolicy.ShaTagger != nil { @@ -145,7 +145,7 @@ func validateTaggingPolicy(cfg *parser.SkaffoldConfigEntry, bc latestV1.BuildCon // without tags nor digests. func validateImageNames(configs parser.SkaffoldConfigSet) (errs []ErrorWithLocation) { seen := make(map[string]string) - arMap := make(map[string]*latestV1.Artifact) + arMap := make(map[string]*latest.Artifact) for _, c := range configs { for i, a := range c.Build.Artifacts { @@ -195,7 +195,7 @@ func validateImageNames(configs parser.SkaffoldConfigSet) (errs []ErrorWithLocat } func validateArtifactDependencies(configs parser.SkaffoldConfigSet) (cfgErrs []ErrorWithLocation) { - var artifacts []*latestV1.Artifact + var artifacts []*latest.Artifact for _, c := range configs { artifacts = append(artifacts, c.Build.Artifacts...) } @@ -206,8 +206,8 @@ func validateArtifactDependencies(configs parser.SkaffoldConfigSet) (cfgErrs []E } // validateAcyclicDependencies makes sure all artifact dependencies are found and don't have cyclic references -func validateAcyclicDependencies(cfgs *parser.SkaffoldConfigSet, artifacts []*latestV1.Artifact) (cfgErrs []ErrorWithLocation) { - m := make(map[string]*latestV1.Artifact) +func validateAcyclicDependencies(cfgs *parser.SkaffoldConfigSet, artifacts []*latest.Artifact) (cfgErrs []ErrorWithLocation) { + m := make(map[string]*latest.Artifact) for _, artifact := range artifacts { m[artifact.ImageName] = artifact } @@ -225,7 +225,7 @@ func validateAcyclicDependencies(cfgs *parser.SkaffoldConfigSet, artifacts []*la } // dfs runs a Depth First Search algorithm for cycle detection in a directed graph -func dfs(artifact *latestV1.Artifact, visited, marked map[string]bool, artifacts map[string]*latestV1.Artifact) error { +func dfs(artifact *latest.Artifact, visited, marked map[string]bool, artifacts map[string]*latest.Artifact) error { if marked[artifact.ImageName] { return fmt.Errorf("cycle detected in build dependencies involving %q", artifact.ImageName) } @@ -252,7 +252,7 @@ func dfs(artifact *latestV1.Artifact, visited, marked map[string]bool, artifacts // validateValidDependencyAliases makes sure that artifact dependency aliases are valid. // docker and custom builders require aliases match [a-zA-Z_][a-zA-Z0-9_]* pattern -func validateValidDependencyAliases(cfgs *parser.SkaffoldConfigSet, artifacts []*latestV1.Artifact) (cfgErrs []ErrorWithLocation) { +func validateValidDependencyAliases(cfgs *parser.SkaffoldConfigSet, artifacts []*latest.Artifact) (cfgErrs []ErrorWithLocation) { for i, a := range artifacts { if a.DockerArtifact == nil && a.CustomArtifact == nil { continue @@ -270,7 +270,7 @@ func validateValidDependencyAliases(cfgs *parser.SkaffoldConfigSet, artifacts [] } // validateUniqueDependencyAliases makes sure that artifact dependency aliases are unique for each artifact -func validateUniqueDependencyAliases(cfgs *parser.SkaffoldConfigSet, artifacts []*latestV1.Artifact) (cfgErrs []ErrorWithLocation) { +func validateUniqueDependencyAliases(cfgs *parser.SkaffoldConfigSet, artifacts []*latest.Artifact) (cfgErrs []ErrorWithLocation) { type State int var ( unseen State = 0 @@ -361,7 +361,7 @@ func validateDockerContainerExpression(image string, id string) error { } // validateDockerNetworkMode makes sure that networkMode is one of `bridge`, `none`, `container:`, or `host` if set. -func validateDockerNetworkMode(cfg *parser.SkaffoldConfigEntry, artifacts []*latestV1.Artifact) (cfgErrs []ErrorWithLocation) { +func validateDockerNetworkMode(cfg *parser.SkaffoldConfigEntry, artifacts []*latest.Artifact) (cfgErrs []ErrorWithLocation) { for i, a := range artifacts { if a.DockerArtifact == nil || a.DockerArtifact.NetworkMode == "" { continue @@ -384,7 +384,7 @@ func validateDockerNetworkMode(cfg *parser.SkaffoldConfigEntry, artifacts []*lat } // Validates that a Docker Container with a Network Mode "container:" points to an actually running container -func validateDockerNetworkContainerExists(ctx context.Context, artifacts []*latestV1.Artifact, runCtx docker.Config) []error { +func validateDockerNetworkContainerExists(ctx context.Context, artifacts []*latest.Artifact, runCtx docker.Config) []error { var errs []error apiClient, err := docker.NewAPIClient(ctx, runCtx) if err != nil { @@ -455,7 +455,7 @@ func validateDockerNetworkContainerExists(ctx context.Context, artifacts []*late } // validateCustomDependencies makes sure that dependencies.ignore is only used in conjunction with dependencies.paths -func validateCustomDependencies(cfg *parser.SkaffoldConfigEntry, artifacts []*latestV1.Artifact) (cfgErrs []ErrorWithLocation) { +func validateCustomDependencies(cfg *parser.SkaffoldConfigEntry, artifacts []*latest.Artifact) (cfgErrs []ErrorWithLocation) { for i, a := range artifacts { if a.CustomArtifact == nil || a.CustomArtifact.Dependencies == nil || a.CustomArtifact.Dependencies.Ignore == nil { continue @@ -529,7 +529,7 @@ func visitStructs(cfg *parser.SkaffoldConfigEntry, v reflect.Value, visitor func } // validateSyncRules checks that all manual sync rules have a valid strip prefix -func validateSyncRules(cfg *parser.SkaffoldConfigEntry, artifacts []*latestV1.Artifact) []ErrorWithLocation { +func validateSyncRules(cfg *parser.SkaffoldConfigEntry, artifacts []*latest.Artifact) []ErrorWithLocation { var cfgErrs []ErrorWithLocation for i, a := range artifacts { if a.Sync != nil { @@ -549,7 +549,7 @@ func validateSyncRules(cfg *parser.SkaffoldConfigEntry, artifacts []*latestV1.Ar // validatePortForwardResources checks that all user defined port forward resources // have a valid resourceType -func validatePortForwardResources(cfg *parser.SkaffoldConfigEntry, pfrs []*latestV1.PortForwardResource) []ErrorWithLocation { +func validatePortForwardResources(cfg *parser.SkaffoldConfigEntry, pfrs []*latest.PortForwardResource) []ErrorWithLocation { var errs []ErrorWithLocation validResourceTypes := map[string]struct{}{ "container": {}, @@ -576,7 +576,7 @@ func validatePortForwardResources(cfg *parser.SkaffoldConfigEntry, pfrs []*lates } // validateJibPluginTypes makes sure that jib type is one of `maven`, or `gradle` if set. -func validateJibPluginTypes(cfg *parser.SkaffoldConfigEntry, artifacts []*latestV1.Artifact) (cfgErrs []ErrorWithLocation) { +func validateJibPluginTypes(cfg *parser.SkaffoldConfigEntry, artifacts []*latest.Artifact) (cfgErrs []ErrorWithLocation) { for i, a := range artifacts { if a.JibArtifact == nil || a.JibArtifact.Type == "" { continue @@ -594,7 +594,7 @@ func validateJibPluginTypes(cfg *parser.SkaffoldConfigEntry, artifacts []*latest } // validateArtifactTypes checks that the artifact types are compatible with the specified builder. -func validateArtifactTypes(cfg *parser.SkaffoldConfigEntry, bc latestV1.BuildConfig) []ErrorWithLocation { +func validateArtifactTypes(cfg *parser.SkaffoldConfigEntry, bc latest.BuildConfig) []ErrorWithLocation { cfgErrs := []ErrorWithLocation{} switch { case bc.LocalBuild != nil: @@ -630,7 +630,7 @@ func validateArtifactTypes(cfg *parser.SkaffoldConfigEntry, bc latestV1.BuildCon } // validateLogPrefix checks that logs are configured with a valid prefix. -func validateLogPrefix(cfg *parser.SkaffoldConfigEntry, lc latestV1.LogsConfig) []ErrorWithLocation { +func validateLogPrefix(cfg *parser.SkaffoldConfigEntry, lc latest.LogsConfig) []ErrorWithLocation { validPrefixes := []string{"", "auto", "container", "podAndContainer", "none"} if !stringslice.Contains(validPrefixes, lc.Prefix) { @@ -648,7 +648,7 @@ func validateLogPrefix(cfg *parser.SkaffoldConfigEntry, lc latestV1.LogsConfig) // validateCustomTest // - makes sure that command is not empty // - makes sure that dependencies.ignore is only used in conjunction with dependencies.paths -func validateCustomTest(cfg *parser.SkaffoldConfigEntry, tcs []*latestV1.TestCase) (cfgErrs []ErrorWithLocation) { +func validateCustomTest(cfg *parser.SkaffoldConfigEntry, tcs []*latest.TestCase) (cfgErrs []ErrorWithLocation) { for i, tc := range tcs { for j, ct := range tc.CustomTests { if ct.Command == "" { diff --git a/pkg/skaffold/schema/validation/validation_test.go b/pkg/skaffold/schema/validation/validation_test.go index 9046f2e6652..90a64b5083d 100644 --- a/pkg/skaffold/schema/validation/validation_test.go +++ b/pkg/skaffold/schema/validation/validation_test.go @@ -32,34 +32,34 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser/configlocations" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) var ( - cfgWithErrors = &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + cfgWithErrors = &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ { - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, - BazelArtifact: &latestV1.BazelArtifact{}, + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, + BazelArtifact: &latest.BazelArtifact{}, }, }, { - ArtifactType: latestV1.ArtifactType{ - BazelArtifact: &latestV1.BazelArtifact{}, - KanikoArtifact: &latestV1.KanikoArtifact{}, + ArtifactType: latest.ArtifactType{ + BazelArtifact: &latest.BazelArtifact{}, + KanikoArtifact: &latest.KanikoArtifact{}, }, }, }, }, - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - HelmDeploy: &latestV1.HelmDeploy{}, - KubectlDeploy: &latestV1.KubectlDeploy{}, + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + HelmDeploy: &latest.HelmDeploy{}, + KubectlDeploy: &latest.KubectlDeploy{}, }, }, }, @@ -69,7 +69,7 @@ var ( func TestValidateSchema(t *testing.T) { tests := []struct { description string - cfg *latestV1.SkaffoldConfig + cfg *latest.SkaffoldConfig shouldErr bool }{ { @@ -79,12 +79,12 @@ func TestValidateSchema(t *testing.T) { }, { description: "empty config", - cfg: &latestV1.SkaffoldConfig{}, + cfg: &latest.SkaffoldConfig{}, shouldErr: true, }, { description: "minimal config", - cfg: &latestV1.SkaffoldConfig{ + cfg: &latest.SkaffoldConfig{ APIVersion: "foo", Kind: "bar", }, @@ -267,39 +267,39 @@ func TestVisitStructs(t *testing.T) { func TestValidateNetworkMode(t *testing.T) { tests := []struct { description string - artifacts []*latestV1.Artifact + artifacts []*latest.Artifact shouldErr bool env []string }{ { description: "not a docker artifact", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/bazel", - ArtifactType: latestV1.ArtifactType{ - BazelArtifact: &latestV1.BazelArtifact{}, + ArtifactType: latest.ArtifactType{ + BazelArtifact: &latest.BazelArtifact{}, }, }, }, }, { description: "no networkmode", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/no-network", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, }, }, }, }, { description: "bridge", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/bridge", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Bridge", }, }, @@ -308,11 +308,11 @@ func TestValidateNetworkMode(t *testing.T) { }, { description: "empty container's network stack", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/container", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Container:", }, }, @@ -322,11 +322,11 @@ func TestValidateNetworkMode(t *testing.T) { }, { description: "empty container's network stack in env var", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/container", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Container:{{.CONTAINER}}", }, }, @@ -337,11 +337,11 @@ func TestValidateNetworkMode(t *testing.T) { }, { description: "wrong container's network stack '-not-valid'", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/container", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Container:-not-valid", }, }, @@ -351,11 +351,11 @@ func TestValidateNetworkMode(t *testing.T) { }, { description: "wrong container's network stack '-not-valid' in env var", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/container", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Container:{{.CONTAINER}}", }, }, @@ -366,11 +366,11 @@ func TestValidateNetworkMode(t *testing.T) { }, { description: "wrong container's network stack 'fussball'", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/container", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Container:fußball", }, }, @@ -380,11 +380,11 @@ func TestValidateNetworkMode(t *testing.T) { }, { description: "wrong container's network stack 'fussball' in env var", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/container", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Container:{{.CONTAINER}}", }, }, @@ -395,11 +395,11 @@ func TestValidateNetworkMode(t *testing.T) { }, { description: "container's network stack 'unique'", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/container", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Container:unique", }, }, @@ -408,11 +408,11 @@ func TestValidateNetworkMode(t *testing.T) { }, { description: "container's network stack 'unique' in env var", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/container", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Container:{{.CONTAINER}}", }, }, @@ -422,11 +422,11 @@ func TestValidateNetworkMode(t *testing.T) { }, { description: "container's network stack 'unique-id.123'", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/container", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Container:unique-id.123", }, }, @@ -435,11 +435,11 @@ func TestValidateNetworkMode(t *testing.T) { }, { description: "container's network stack 'unique-id.123' in env var", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/container", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Container:{{.CONTAINER}}", }, }, @@ -449,11 +449,11 @@ func TestValidateNetworkMode(t *testing.T) { }, { description: "none", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/none", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "None", }, }, @@ -462,11 +462,11 @@ func TestValidateNetworkMode(t *testing.T) { }, { description: "host", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/host", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Host", }, }, @@ -476,11 +476,11 @@ func TestValidateNetworkMode(t *testing.T) { { description: "invalid networkmode", shouldErr: true, - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/bad", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Bad", }, }, @@ -489,11 +489,11 @@ func TestValidateNetworkMode(t *testing.T) { }, { description: "case insensitive", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/case-insensitive", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "bRiDgE", }, }, @@ -509,9 +509,9 @@ func TestValidateNetworkMode(t *testing.T) { err := Process(parser.SkaffoldConfigSet{&parser.SkaffoldConfigEntry{ YAMLInfos: configlocations.NewYAMLInfos(), - SkaffoldConfig: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ + SkaffoldConfig: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ Artifacts: test.artifacts, }, }, @@ -534,18 +534,18 @@ func (f fakeCommonAPIClient) ContainerList(ctx context.Context, options types.Co func TestValidateNetworkModeDockerContainerExists(t *testing.T) { tests := []struct { description string - artifacts []*latestV1.Artifact + artifacts []*latest.Artifact clientResponse []types.Container shouldErr bool env []string }{ { description: "no running containers", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/container", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Container:foo", }, }, @@ -556,11 +556,11 @@ func TestValidateNetworkModeDockerContainerExists(t *testing.T) { }, { description: "not matching running containers", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/container", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Container:foo", }, }, @@ -576,11 +576,11 @@ func TestValidateNetworkModeDockerContainerExists(t *testing.T) { }, { description: "existing running container referenced by id", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/container", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Container:foo", }, }, @@ -594,11 +594,11 @@ func TestValidateNetworkModeDockerContainerExists(t *testing.T) { }, { description: "existing running container referenced by first id chars", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/container", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Container:123", }, }, @@ -612,11 +612,11 @@ func TestValidateNetworkModeDockerContainerExists(t *testing.T) { }, { description: "existing running container referenced by name", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/container", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Container:foo", }, }, @@ -631,11 +631,11 @@ func TestValidateNetworkModeDockerContainerExists(t *testing.T) { }, { description: "non existing running container referenced by id in envvar", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/container", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Container:{{ .CONTAINER }}", }, }, @@ -651,11 +651,11 @@ func TestValidateNetworkModeDockerContainerExists(t *testing.T) { }, { description: "existing running container referenced by id in envvar", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/container", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Container:{{ .CONTAINER }}", }, }, @@ -670,11 +670,11 @@ func TestValidateNetworkModeDockerContainerExists(t *testing.T) { }, { description: "existing running container referenced by name in envvar", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/container", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ NetworkMode: "Container:{{ .CONTAINER }}", }, }, @@ -705,9 +705,9 @@ func TestValidateNetworkModeDockerContainerExists(t *testing.T) { }) err := ProcessWithRunContext(context.Background(), &runcontext.RunContext{ - Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{ + Pipelines: runcontext.NewPipelines([]latest.Pipeline{ { - Build: latestV1.BuildConfig{ + Build: latest.BuildConfig{ Artifacts: test.artifacts, }, }, @@ -722,7 +722,7 @@ func TestValidateNetworkModeDockerContainerExists(t *testing.T) { func TestValidateSyncRules(t *testing.T) { tests := []struct { description string - artifacts []*latestV1.Artifact + artifacts []*latest.Artifact shouldErr bool }{ { @@ -731,16 +731,16 @@ func TestValidateSyncRules(t *testing.T) { }, { description: "no sync rules", - artifacts: []*latestV1.Artifact{{ + artifacts: []*latest.Artifact{{ ImageName: "img", Sync: nil, }}, }, { description: "two good rules", - artifacts: []*latestV1.Artifact{{ + artifacts: []*latest.Artifact{{ ImageName: "img", - Sync: &latestV1.Sync{Manual: []*latestV1.SyncRule{ + Sync: &latest.Sync{Manual: []*latest.SyncRule{ { Src: "src/**/*.js", Dest: ".", @@ -755,9 +755,9 @@ func TestValidateSyncRules(t *testing.T) { }, { description: "one good one bad rule", - artifacts: []*latestV1.Artifact{{ + artifacts: []*latest.Artifact{{ ImageName: "img", - Sync: &latestV1.Sync{Manual: []*latestV1.SyncRule{ + Sync: &latest.Sync{Manual: []*latest.SyncRule{ { Src: "src/**/*.js", Dest: ".", @@ -774,9 +774,9 @@ func TestValidateSyncRules(t *testing.T) { }, { description: "two bad rules", - artifacts: []*latestV1.Artifact{{ + artifacts: []*latest.Artifact{{ ImageName: "img", - Sync: &latestV1.Sync{Manual: []*latestV1.SyncRule{ + Sync: &latest.Sync{Manual: []*latest.SyncRule{ { Dest: ".", Strip: "src", @@ -792,10 +792,10 @@ func TestValidateSyncRules(t *testing.T) { }, { description: "stripping part of folder name is valid", - artifacts: []*latestV1.Artifact{{ + artifacts: []*latest.Artifact{{ ImageName: "img", - Sync: &latestV1.Sync{ - Manual: []*latestV1.SyncRule{{ + Sync: &latest.Sync{ + Manual: []*latest.SyncRule{{ Src: "srcsomeother/**/*.js", Dest: ".", Strip: "src", @@ -811,9 +811,9 @@ func TestValidateSyncRules(t *testing.T) { err := Process(parser.SkaffoldConfigSet{&parser.SkaffoldConfigEntry{ YAMLInfos: configlocations.NewYAMLInfos(), - SkaffoldConfig: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ + SkaffoldConfig: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ Artifacts: test.artifacts, }, }, @@ -827,19 +827,19 @@ func TestValidateSyncRules(t *testing.T) { func TestValidateCustomDependencies(t *testing.T) { tests := []struct { description string - dependencies *latestV1.CustomDependencies + dependencies *latest.CustomDependencies expectedErrors int }{ { description: "no errors", - dependencies: &latestV1.CustomDependencies{ + dependencies: &latest.CustomDependencies{ Paths: []string{"somepath"}, Ignore: []string{"anotherpath"}, }, }, { description: "ignore in conjunction with dockerfile", - dependencies: &latestV1.CustomDependencies{ - Dockerfile: &latestV1.DockerfileDependency{ + dependencies: &latest.CustomDependencies{ + Dockerfile: &latest.DockerfileDependency{ Path: "some/path", }, Ignore: []string{"ignoreme"}, @@ -847,7 +847,7 @@ func TestValidateCustomDependencies(t *testing.T) { expectedErrors: 1, }, { description: "ignore in conjunction with command", - dependencies: &latestV1.CustomDependencies{ + dependencies: &latest.CustomDependencies{ Command: "bazel query deps", Ignore: []string{"ignoreme"}, }, @@ -859,25 +859,25 @@ func TestValidateCustomDependencies(t *testing.T) { } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - artifact := &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - CustomArtifact: &latestV1.CustomArtifact{ + artifact := &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + CustomArtifact: &latest.CustomArtifact{ Dependencies: test.dependencies, }, }, } errs := validateCustomDependencies(&parser.SkaffoldConfigEntry{ YAMLInfos: configlocations.NewYAMLInfos(), - SkaffoldConfig: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + SkaffoldConfig: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ artifact, }, }, }, }, - }, []*latestV1.Artifact{artifact}) + }, []*latest.Artifact{artifact}) t.CheckDeepEqual(test.expectedErrors, len(errs)) }) @@ -902,9 +902,9 @@ func TestValidatePortForwardResources(t *testing.T) { } for _, test := range tests { testutil.Run(t, test.resourceType, func(t *testutil.T) { - pfrs := []*latestV1.PortForwardResource{ + pfrs := []*latest.PortForwardResource{ { - Type: latestV1.ResourceType(test.resourceType), + Type: latest.ResourceType(test.resourceType), }, } errs := validatePortForwardResources(&parser.SkaffoldConfigEntry{YAMLInfos: configlocations.NewYAMLInfos()}, pfrs) @@ -921,26 +921,26 @@ func TestValidatePortForwardResources(t *testing.T) { func TestValidateImageNames(t *testing.T) { tests := []struct { description string - artifacts []*latestV1.Artifact + artifacts []*latest.Artifact shouldErr bool }{ { description: "no name", - artifacts: []*latestV1.Artifact{{ + artifacts: []*latest.Artifact{{ ImageName: "", }}, shouldErr: true, }, { description: "valid", - artifacts: []*latestV1.Artifact{{ + artifacts: []*latest.Artifact{{ ImageName: "img", }}, shouldErr: false, }, { description: "duplicates", - artifacts: []*latestV1.Artifact{{ + artifacts: []*latest.Artifact{{ ImageName: "img", }, { ImageName: "img", @@ -949,21 +949,21 @@ func TestValidateImageNames(t *testing.T) { }, { description: "shouldn't have a tag", - artifacts: []*latestV1.Artifact{{ + artifacts: []*latest.Artifact{{ ImageName: "img:tag", }}, shouldErr: true, }, { description: "shouldn't have a digest", - artifacts: []*latestV1.Artifact{{ + artifacts: []*latest.Artifact{{ ImageName: "img@sha256:77af4d6b9913e693e8d0b4b294fa62ade6054e6b2f1ffb617ac955dd63fb0182", }}, shouldErr: true, }, { description: "no tag nor digest", - artifacts: []*latestV1.Artifact{{ + artifacts: []*latest.Artifact{{ ImageName: "img:tag@sha256:77af4d6b9913e693e8d0b4b294fa62ade6054e6b2f1ffb617ac955dd63fb0182", }}, shouldErr: true, @@ -978,9 +978,9 @@ func TestValidateImageNames(t *testing.T) { parser.SkaffoldConfigSet{ &parser.SkaffoldConfigEntry{ YAMLInfos: configlocations.NewYAMLInfos(), - SkaffoldConfig: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ + SkaffoldConfig: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ Artifacts: test.artifacts, }, }, @@ -996,27 +996,27 @@ func TestValidateImageNames(t *testing.T) { func TestValidateJibPluginType(t *testing.T) { tests := []struct { description string - artifacts []*latestV1.Artifact + artifacts []*latest.Artifact shouldErr bool }{ { description: "no type", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/jib", - ArtifactType: latestV1.ArtifactType{ - JibArtifact: &latestV1.JibArtifact{}, + ArtifactType: latest.ArtifactType{ + JibArtifact: &latest.JibArtifact{}, }, }, }, }, { description: "maven", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/jib", - ArtifactType: latestV1.ArtifactType{ - JibArtifact: &latestV1.JibArtifact{ + ArtifactType: latest.ArtifactType{ + JibArtifact: &latest.JibArtifact{ Type: "maven", }, }, @@ -1025,11 +1025,11 @@ func TestValidateJibPluginType(t *testing.T) { }, { description: "gradle", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/jib", - ArtifactType: latestV1.ArtifactType{ - JibArtifact: &latestV1.JibArtifact{ + ArtifactType: latest.ArtifactType{ + JibArtifact: &latest.JibArtifact{ Type: "gradle", }, }, @@ -1038,11 +1038,11 @@ func TestValidateJibPluginType(t *testing.T) { }, { description: "empty", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/jib", - ArtifactType: latestV1.ArtifactType{ - JibArtifact: &latestV1.JibArtifact{ + ArtifactType: latest.ArtifactType{ + JibArtifact: &latest.JibArtifact{ Type: "", }, }, @@ -1051,11 +1051,11 @@ func TestValidateJibPluginType(t *testing.T) { }, { description: "cAsE inSenSiTiVe", - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/jib", - ArtifactType: latestV1.ArtifactType{ - JibArtifact: &latestV1.JibArtifact{ + ArtifactType: latest.ArtifactType{ + JibArtifact: &latest.JibArtifact{ Type: "gRaDlE", }, }, @@ -1065,11 +1065,11 @@ func TestValidateJibPluginType(t *testing.T) { { description: "invalid type", shouldErr: true, - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ { ImageName: "image/jib", - ArtifactType: latestV1.ArtifactType{ - JibArtifact: &latestV1.JibArtifact{ + ArtifactType: latest.ArtifactType{ + JibArtifact: &latest.JibArtifact{ Type: "invalid", }, }, @@ -1084,9 +1084,9 @@ func TestValidateJibPluginType(t *testing.T) { err := Process(parser.SkaffoldConfigSet{&parser.SkaffoldConfigEntry{ YAMLInfos: configlocations.NewYAMLInfos(), - SkaffoldConfig: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ + SkaffoldConfig: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ Artifacts: test.artifacts, }, }, @@ -1101,7 +1101,7 @@ func TestValidateJibPluginType(t *testing.T) { func TestValidateLogsConfig(t *testing.T) { tests := []struct { prefix string - cfg latestV1.LogsConfig + cfg latest.LogsConfig shouldErr bool }{ {prefix: "auto", shouldErr: false}, @@ -1118,10 +1118,10 @@ func TestValidateLogsConfig(t *testing.T) { err := Process(parser.SkaffoldConfigSet{&parser.SkaffoldConfigEntry{ YAMLInfos: configlocations.NewYAMLInfos(), - SkaffoldConfig: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ - Logs: latestV1.LogsConfig{ + SkaffoldConfig: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{ + Logs: latest.LogsConfig{ Prefix: test.prefix, }, }, @@ -1191,10 +1191,10 @@ func TestValidateAcyclicDependencies(t *testing.T) { } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - artifacts := make([]*latestV1.Artifact, test.artifactLen) + artifacts := make([]*latest.Artifact, test.artifactLen) for i := 0; i < test.artifactLen; i++ { a := fmt.Sprintf("artifact%d", i+1) - artifacts[i] = &latestV1.Artifact{ImageName: a} + artifacts[i] = &latest.Artifact{ImageName: a} } setDependencies(artifacts, test.dependency) @@ -1225,10 +1225,10 @@ func TestValidateAcyclicDependencies(t *testing.T) { // 2 : {3}, //} // implies that a[0] artifact depends on a[1] and a[2]; and a[2] depends on a[3]. -func setDependencies(a []*latestV1.Artifact, d map[int][]int) { +func setDependencies(a []*latest.Artifact, d map[int][]int) { for k, dep := range d { for i := range dep { - a[k].Dependencies = append(a[k].Dependencies, &latestV1.ArtifactDependency{ + a[k].Dependencies = append(a[k].Dependencies, &latest.ArtifactDependency{ ImageName: a[dep[i]].ImageName, }) } @@ -1238,20 +1238,20 @@ func setDependencies(a []*latestV1.Artifact, d map[int][]int) { func TestValidateUniqueDependencyAliases(t *testing.T) { cfgs := parser.SkaffoldConfigSet{ &parser.SkaffoldConfigEntry{ - SkaffoldConfig: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + SkaffoldConfig: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ { ImageName: "artifact1", - Dependencies: []*latestV1.ArtifactDependency{ + Dependencies: []*latest.ArtifactDependency{ {Alias: "alias2", ImageName: "artifact2a"}, {Alias: "alias2", ImageName: "artifact2b"}, }, }, { ImageName: "artifact2", - Dependencies: []*latestV1.ArtifactDependency{ + Dependencies: []*latest.ArtifactDependency{ {Alias: "alias1", ImageName: "artifact1"}, {Alias: "alias2", ImageName: "artifact1"}, }, @@ -1282,49 +1282,49 @@ func TestValidateUniqueDependencyAliases(t *testing.T) { func TestValidateValidDependencyAliases(t *testing.T) { cfgs := parser.SkaffoldConfigSet{ &parser.SkaffoldConfigEntry{ - SkaffoldConfig: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + SkaffoldConfig: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ { ImageName: "artifact1", }, { ImageName: "artifact2", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, }, - Dependencies: []*latestV1.ArtifactDependency{ + Dependencies: []*latest.ArtifactDependency{ {Alias: "ARTIFACT_1", ImageName: "artifact1"}, {Alias: "1_ARTIFACT", ImageName: "artifact1"}, }, }, { ImageName: "artifact3", - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{}, + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{}, }, - Dependencies: []*latestV1.ArtifactDependency{ + Dependencies: []*latest.ArtifactDependency{ {Alias: "artifact!", ImageName: "artifact1"}, {Alias: "artifact#1", ImageName: "artifact1"}, }, }, { ImageName: "artifact4", - ArtifactType: latestV1.ArtifactType{ - CustomArtifact: &latestV1.CustomArtifact{}, + ArtifactType: latest.ArtifactType{ + CustomArtifact: &latest.CustomArtifact{}, }, - Dependencies: []*latestV1.ArtifactDependency{ + Dependencies: []*latest.ArtifactDependency{ {Alias: "alias1", ImageName: "artifact1"}, {Alias: "alias2", ImageName: "artifact2"}, }, }, { ImageName: "artifact5", - ArtifactType: latestV1.ArtifactType{ - BuildpackArtifact: &latestV1.BuildpackArtifact{}, + ArtifactType: latest.ArtifactType{ + BuildpackArtifact: &latest.BuildpackArtifact{}, }, - Dependencies: []*latestV1.ArtifactDependency{ + Dependencies: []*latest.ArtifactDependency{ {Alias: "artifact!", ImageName: "artifact1"}, {Alias: "artifact#1", ImageName: "artifact1"}, }, @@ -1370,34 +1370,34 @@ func errorsComparer(a, b error) bool { func TestValidateTaggingPolicy(t *testing.T) { tests := []struct { description string - cfg latestV1.BuildConfig + cfg latest.BuildConfig shouldErr bool }{ { description: "ShaTagger can be used when tryImportMissing is disabled", shouldErr: false, - cfg: latestV1.BuildConfig{ - BuildType: latestV1.BuildType{ - LocalBuild: &latestV1.LocalBuild{ + cfg: latest.BuildConfig{ + BuildType: latest.BuildType{ + LocalBuild: &latest.LocalBuild{ TryImportMissing: false, }, }, - TagPolicy: latestV1.TagPolicy{ - ShaTagger: &latestV1.ShaTagger{}, + TagPolicy: latest.TagPolicy{ + ShaTagger: &latest.ShaTagger{}, }, }, }, { description: "ShaTagger can not be used when tryImportMissing is enabled", shouldErr: true, - cfg: latestV1.BuildConfig{ - BuildType: latestV1.BuildType{ - LocalBuild: &latestV1.LocalBuild{ + cfg: latest.BuildConfig{ + BuildType: latest.BuildType{ + LocalBuild: &latest.LocalBuild{ TryImportMissing: true, }, }, - TagPolicy: latestV1.TagPolicy{ - ShaTagger: &latestV1.ShaTagger{}, + TagPolicy: latest.TagPolicy{ + ShaTagger: &latest.ShaTagger{}, }, }, }, @@ -1410,8 +1410,8 @@ func TestValidateTaggingPolicy(t *testing.T) { err := Process(parser.SkaffoldConfigSet{ &parser.SkaffoldConfigEntry{ YAMLInfos: configlocations.NewYAMLInfos(), - SkaffoldConfig: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ + SkaffoldConfig: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ Build: test.cfg, }, }, @@ -1427,20 +1427,20 @@ func TestValidateCustomTest(t *testing.T) { tests := []struct { description string command string - dependencies *latestV1.CustomTestDependencies + dependencies *latest.CustomTestDependencies expectedErrors int }{ { description: "no errors", command: "echo Hello!", - dependencies: &latestV1.CustomTestDependencies{ + dependencies: &latest.CustomTestDependencies{ Paths: []string{"somepath"}, Ignore: []string{"anotherpath"}, }, }, { description: "empty command", command: "", - dependencies: &latestV1.CustomTestDependencies{ + dependencies: &latest.CustomTestDependencies{ Paths: []string{"somepath"}, Ignore: []string{"anotherpath"}, }, @@ -1448,7 +1448,7 @@ func TestValidateCustomTest(t *testing.T) { }, { description: "use both path and command", command: "echo Hello!", - dependencies: &latestV1.CustomTestDependencies{ + dependencies: &latest.CustomTestDependencies{ Command: "bazel query deps", Paths: []string{"somepath"}, }, @@ -1456,7 +1456,7 @@ func TestValidateCustomTest(t *testing.T) { }, { description: "ignore in conjunction with command", command: "echo Hello!", - dependencies: &latestV1.CustomTestDependencies{ + dependencies: &latest.CustomTestDependencies{ Command: "bazel query deps", Ignore: []string{"ignoreme"}, }, @@ -1469,9 +1469,9 @@ func TestValidateCustomTest(t *testing.T) { } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - testCase := &latestV1.TestCase{ + testCase := &latest.TestCase{ ImageName: "image", - CustomTests: []latestV1.CustomTest{{ + CustomTests: []latest.CustomTest{{ Command: test.command, Dependencies: test.dependencies, }}, @@ -1479,14 +1479,14 @@ func TestValidateCustomTest(t *testing.T) { errs := validateCustomTest(&parser.SkaffoldConfigEntry{ YAMLInfos: configlocations.NewYAMLInfos(), - SkaffoldConfig: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Test: []*latestV1.TestCase{ + SkaffoldConfig: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Test: []*latest.TestCase{ testCase, }, }, }, - }, []*latestV1.TestCase{testCase}) + }, []*latest.TestCase{testCase}) t.CheckDeepEqual(test.expectedErrors, len(errs)) }) } @@ -1496,18 +1496,18 @@ func TestValidateKubectlManifests(t *testing.T) { tempDir := t.TempDir() tests := []struct { description string - configs []*latestV1.SkaffoldConfig + configs []*latest.SkaffoldConfig files []string shouldErr bool }{ { description: "specified manifest file exists", - configs: []*latestV1.SkaffoldConfig{ + configs: []*latest.SkaffoldConfig{ { - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{ + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{ Manifests: []string{filepath.Join(tempDir, "validation-test-exists.yaml")}, }, }, @@ -1519,12 +1519,12 @@ func TestValidateKubectlManifests(t *testing.T) { }, { description: "specified manifest file does not exist", - configs: []*latestV1.SkaffoldConfig{ + configs: []*latest.SkaffoldConfig{ { - Pipeline: latestV1.Pipeline{ - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KubectlDeploy: &latestV1.KubectlDeploy{ + Pipeline: latest.Pipeline{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KubectlDeploy: &latest.KubectlDeploy{ Manifests: []string{filepath.Join(tempDir, "validation-test-missing.yaml")}, }, }, diff --git a/pkg/skaffold/schema/versions.go b/pkg/skaffold/schema/versions.go index 562d612455d..babfa2e4126 100644 --- a/pkg/skaffold/schema/versions.go +++ b/pkg/skaffold/schema/versions.go @@ -30,7 +30,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/apiversion" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/errors" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" latestV2 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v2" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1" @@ -158,7 +158,7 @@ var SchemaVersionsV1 = Versions{ {v2beta25.Version, v2beta25.NewSkaffoldConfig}, {v2beta26.Version, v2beta26.NewSkaffoldConfig}, {v2beta27.Version, v2beta27.NewSkaffoldConfig}, - {latestV1.Version, latestV1.NewSkaffoldConfig}, + {latest.Version, latest.NewSkaffoldConfig}, } // SchemaVersionsV2 refers to all the supported API Schemas for skaffold v2 executables. The API schema versions are @@ -325,7 +325,7 @@ func getLatestFromCompatibilityCheck(cfgs []util.VersionedConfig) (string, error return "", fmt.Errorf("detected incompatible versions:%v are incompatible with %v", v1Track, v2Track) } if len(v1Track) > 0 { - return latestV1.Version, nil + return latest.Version, nil } if len(v2Track) > 0 { return latestV2.Version, nil diff --git a/pkg/skaffold/schema/versions_test.go b/pkg/skaffold/schema/versions_test.go index ce03cc9dd36..53bf3ebf896 100644 --- a/pkg/skaffold/schema/versions_test.go +++ b/pkg/skaffold/schema/versions_test.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/kaniko" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" "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/latest" latestV2 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v2" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha1" @@ -194,7 +194,7 @@ func TestParseConfigAndUpgrade(t *testing.T) { shouldErr bool }{ { - apiVersion: []string{latestV1.Version}, + apiVersion: []string{latest.Version}, description: "Kaniko Volume Mount - ConfigMap", config: []string{kanikoConfigMap}, expected: []util.VersionedConfig{config( @@ -217,7 +217,7 @@ func TestParseConfigAndUpgrade(t *testing.T) { )}, }, { - apiVersion: []string{latestV1.Version}, + apiVersion: []string{latest.Version}, description: "Minimal config", config: []string{minimalConfig}, expected: []util.VersionedConfig{config( @@ -241,7 +241,7 @@ func TestParseConfigAndUpgrade(t *testing.T) { )}, }, { - apiVersion: []string{latestV1.Version}, + apiVersion: []string{latest.Version}, description: "Simple config", config: []string{simpleConfig}, expected: []util.VersionedConfig{config( @@ -254,7 +254,7 @@ func TestParseConfigAndUpgrade(t *testing.T) { )}, }, { - apiVersion: []string{latestV1.Version}, + apiVersion: []string{latest.Version}, description: "Complete config", config: []string{completeConfig}, expected: []util.VersionedConfig{config( @@ -282,7 +282,7 @@ func TestParseConfigAndUpgrade(t *testing.T) { )}, }, { - apiVersion: []string{latestV1.Version, latestV1.Version}, + apiVersion: []string{latest.Version, latest.Version}, description: "Multiple complete config with same API versions", config: []string{completeConfig, completeClusterConfig}, expected: []util.VersionedConfig{config( @@ -304,7 +304,7 @@ func TestParseConfigAndUpgrade(t *testing.T) { )}, }, { - apiVersion: []string{latestV1.Version, v2beta8.Version}, + apiVersion: []string{latest.Version, v2beta8.Version}, description: "Multiple complete config with different API versions", config: []string{completeConfig, completeClusterConfig}, expected: []util.VersionedConfig{config( @@ -326,7 +326,7 @@ func TestParseConfigAndUpgrade(t *testing.T) { )}, }, { - apiVersion: []string{latestV1.Version}, + apiVersion: []string{latest.Version}, description: "Minimal Cluster config", config: []string{minimalClusterConfig}, expected: []util.VersionedConfig{config( @@ -339,7 +339,7 @@ func TestParseConfigAndUpgrade(t *testing.T) { )}, }, { - apiVersion: []string{latestV1.Version}, + apiVersion: []string{latest.Version}, description: "Complete Cluster config", config: []string{completeClusterConfig}, expected: []util.VersionedConfig{config( @@ -353,13 +353,13 @@ func TestParseConfigAndUpgrade(t *testing.T) { )}, }, { - apiVersion: []string{latestV1.Version}, + apiVersion: []string{latest.Version}, description: "Bad config", config: []string{badConfig}, shouldErr: true, }, { - apiVersion: []string{latestV1.Version}, + apiVersion: []string{latest.Version}, description: "two taggers defined", config: []string{invalidConfig}, shouldErr: true, @@ -371,13 +371,13 @@ func TestParseConfigAndUpgrade(t *testing.T) { shouldErr: true, }, { - apiVersion: []string{latestV1.Version}, + apiVersion: []string{latest.Version}, description: "invalid statusCheckDeadline", config: []string{invalidStatusCheckConfig}, shouldErr: true, }, { - apiVersion: []string{latestV1.Version}, + apiVersion: []string{latest.Version}, description: "valid statusCheckDeadline", config: []string{validStatusCheckConfig}, expected: []util.VersionedConfig{config( @@ -390,7 +390,7 @@ func TestParseConfigAndUpgrade(t *testing.T) { )}, }, { - apiVersion: []string{latestV1.Version}, + apiVersion: []string{latest.Version}, description: "custom log prefix", config: []string{customLogPrefix}, expected: []util.VersionedConfig{config( @@ -411,8 +411,8 @@ func TestParseConfigAndUpgrade(t *testing.T) { cfgs, err := ParseConfigAndUpgrade(tmpDir.Path("skaffold.yaml")) for _, cfg := range cfgs { - err := defaults.Set(cfg.(*latestV1.SkaffoldConfig)) - defaults.SetDefaultDeployer(cfg.(*latestV1.SkaffoldConfig)) + err := defaults.Set(cfg.(*latest.SkaffoldConfig)) + defaults.SetDefaultDeployer(cfg.(*latest.SkaffoldConfig)) t.CheckNoError(err) } @@ -424,7 +424,7 @@ func TestParseConfigAndUpgrade(t *testing.T) { func TestMarshalConfig(t *testing.T) { tests := []struct { description string - config *latestV1.SkaffoldConfig + config *latest.SkaffoldConfig shouldErr bool }{ { @@ -461,7 +461,7 @@ func TestMarshalConfig(t *testing.T) { // TestParseConfigAndUpgrade verifies that YAML -> Go works correctly. // This test verifies Go -> YAML -> Go returns the original structure. Since we know // YAML -> Go is working this ensures Go -> YAML is correct. - recovered := &latestV1.SkaffoldConfig{} + recovered := &latest.SkaffoldConfig{} err = yaml.Unmarshal(actual, recovered) @@ -470,8 +470,8 @@ func TestMarshalConfig(t *testing.T) { } } -func config(ops ...func(*latestV1.SkaffoldConfig)) *latestV1.SkaffoldConfig { - cfg := &latestV1.SkaffoldConfig{APIVersion: latestV1.Version, Kind: "Config"} +func config(ops ...func(*latest.SkaffoldConfig)) *latest.SkaffoldConfig { + cfg := &latest.SkaffoldConfig{APIVersion: latest.Version, Kind: "Config"} for _, op := range ops { op(cfg) } @@ -487,9 +487,9 @@ func format(t *testutil.T, configs []string, apiVersions []string) string { return strings.Join(str, "\n---\n") } -func withLocalBuild(ops ...func(*latestV1.BuildConfig)) func(*latestV1.SkaffoldConfig) { - return func(cfg *latestV1.SkaffoldConfig) { - b := latestV1.BuildConfig{BuildType: latestV1.BuildType{LocalBuild: &latestV1.LocalBuild{}}} +func withLocalBuild(ops ...func(*latest.BuildConfig)) func(*latest.SkaffoldConfig) { + return func(cfg *latest.SkaffoldConfig) { + b := latest.BuildConfig{BuildType: latest.BuildType{LocalBuild: &latest.LocalBuild{}}} for _, op := range ops { op(&b) } @@ -497,9 +497,9 @@ func withLocalBuild(ops ...func(*latestV1.BuildConfig)) func(*latestV1.SkaffoldC } } -func withGoogleCloudBuild(id string, ops ...func(*latestV1.BuildConfig)) func(*latestV1.SkaffoldConfig) { - return func(cfg *latestV1.SkaffoldConfig) { - b := latestV1.BuildConfig{BuildType: latestV1.BuildType{GoogleCloudBuild: &latestV1.GoogleCloudBuild{ +func withGoogleCloudBuild(id string, ops ...func(*latest.BuildConfig)) func(*latest.SkaffoldConfig) { + return func(cfg *latest.SkaffoldConfig) { + b := latest.BuildConfig{BuildType: latest.BuildType{GoogleCloudBuild: &latest.GoogleCloudBuild{ ProjectID: id, DockerImage: "gcr.io/cloud-builders/docker", MavenImage: "gcr.io/cloud-builders/mvn", @@ -514,9 +514,9 @@ func withGoogleCloudBuild(id string, ops ...func(*latestV1.BuildConfig)) func(*l } } -func withClusterBuild(secretName, mountPath, namespace, secret string, timeout string, ops ...func(*latestV1.BuildConfig)) func(*latestV1.SkaffoldConfig) { - return func(cfg *latestV1.SkaffoldConfig) { - b := latestV1.BuildConfig{BuildType: latestV1.BuildType{Cluster: &latestV1.ClusterDetails{ +func withClusterBuild(secretName, mountPath, namespace, secret string, timeout string, ops ...func(*latest.BuildConfig)) func(*latest.SkaffoldConfig) { + return func(cfg *latest.SkaffoldConfig) { + b := latest.BuildConfig{BuildType: latest.BuildType{Cluster: &latest.ClusterDetails{ PullSecretName: secretName, Namespace: namespace, PullSecretPath: secret, @@ -530,44 +530,44 @@ func withClusterBuild(secretName, mountPath, namespace, secret string, timeout s } } -func withDockerConfig(secretName string, path string) func(*latestV1.BuildConfig) { - return func(cfg *latestV1.BuildConfig) { - cfg.Cluster.DockerConfig = &latestV1.DockerConfig{ +func withDockerConfig(secretName string, path string) func(*latest.BuildConfig) { + return func(cfg *latest.BuildConfig) { + cfg.Cluster.DockerConfig = &latest.DockerConfig{ SecretName: secretName, Path: path, } } } -func withKubectlDeploy(manifests ...string) func(*latestV1.SkaffoldConfig) { - return func(cfg *latestV1.SkaffoldConfig) { - cfg.Deploy.DeployType.KubectlDeploy = &latestV1.KubectlDeploy{ +func withKubectlDeploy(manifests ...string) func(*latest.SkaffoldConfig) { + return func(cfg *latest.SkaffoldConfig) { + cfg.Deploy.DeployType.KubectlDeploy = &latest.KubectlDeploy{ Manifests: manifests, } } } -func withKubeContext(kubeContext string) func(*latestV1.SkaffoldConfig) { - return func(cfg *latestV1.SkaffoldConfig) { - cfg.Deploy = latestV1.DeployConfig{ +func withKubeContext(kubeContext string) func(*latest.SkaffoldConfig) { + return func(cfg *latest.SkaffoldConfig) { + cfg.Deploy = latest.DeployConfig{ KubeContext: kubeContext, } } } -func withHelmDeploy() func(*latestV1.SkaffoldConfig) { - return func(cfg *latestV1.SkaffoldConfig) { - cfg.Deploy.DeployType.HelmDeploy = &latestV1.HelmDeploy{} +func withHelmDeploy() func(*latest.SkaffoldConfig) { + return func(cfg *latest.SkaffoldConfig) { + cfg.Deploy.DeployType.HelmDeploy = &latest.HelmDeploy{} } } -func withDockerArtifact(image, workspace, dockerfile string) func(*latestV1.BuildConfig) { - return func(cfg *latestV1.BuildConfig) { - cfg.Artifacts = append(cfg.Artifacts, &latestV1.Artifact{ +func withDockerArtifact(image, workspace, dockerfile string) func(*latest.BuildConfig) { + return func(cfg *latest.BuildConfig) { + cfg.Artifacts = append(cfg.Artifacts, &latest.Artifact{ ImageName: image, Workspace: workspace, - ArtifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: dockerfile, }, }, @@ -575,13 +575,13 @@ func withDockerArtifact(image, workspace, dockerfile string) func(*latestV1.Buil } } -func withBazelArtifact() func(*latestV1.BuildConfig) { - return func(cfg *latestV1.BuildConfig) { - cfg.Artifacts = append(cfg.Artifacts, &latestV1.Artifact{ +func withBazelArtifact() func(*latest.BuildConfig) { + return func(cfg *latest.BuildConfig) { + cfg.Artifacts = append(cfg.Artifacts, &latest.Artifact{ ImageName: "image2", Workspace: "./examples/app2", - ArtifactType: latestV1.ArtifactType{ - BazelArtifact: &latestV1.BazelArtifact{ + ArtifactType: latest.ArtifactType{ + BazelArtifact: &latest.BazelArtifact{ BuildTarget: "//:example.tar", }, }, @@ -589,13 +589,13 @@ func withBazelArtifact() func(*latestV1.BuildConfig) { } } -func withKanikoArtifact() func(*latestV1.BuildConfig) { - return func(cfg *latestV1.BuildConfig) { - cfg.Artifacts = append(cfg.Artifacts, &latestV1.Artifact{ +func withKanikoArtifact() func(*latest.BuildConfig) { + return func(cfg *latest.BuildConfig) { + cfg.Artifacts = append(cfg.Artifacts, &latest.Artifact{ ImageName: "image1", Workspace: "./examples/app1", - ArtifactType: latestV1.ArtifactType{ - KanikoArtifact: &latestV1.KanikoArtifact{ + ArtifactType: latest.ArtifactType{ + KanikoArtifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", InitImage: constants.DefaultBusyboxImage, Image: kaniko.DefaultImage, @@ -606,8 +606,8 @@ func withKanikoArtifact() func(*latestV1.BuildConfig) { } // withKanikoVolumeMount appends a volume mount to the latest Kaniko artifact -func withKanikoVolumeMount(name, mountPath string) func(*latestV1.BuildConfig) { - return func(cfg *latestV1.BuildConfig) { +func withKanikoVolumeMount(name, mountPath string) func(*latest.BuildConfig) { + return func(cfg *latest.BuildConfig) { if cfg.Artifacts[len(cfg.Artifacts)-1].KanikoArtifact.VolumeMounts == nil { cfg.Artifacts[len(cfg.Artifacts)-1].KanikoArtifact.VolumeMounts = []v1.VolumeMount{} } @@ -623,50 +623,50 @@ func withKanikoVolumeMount(name, mountPath string) func(*latestV1.BuildConfig) { } // withVolume appends a volume to the cluster -func withVolume(v v1.Volume) func(*latestV1.BuildConfig) { - return func(cfg *latestV1.BuildConfig) { +func withVolume(v v1.Volume) func(*latest.BuildConfig) { + return func(cfg *latest.BuildConfig) { cfg.Cluster.Volumes = append(cfg.Cluster.Volumes, v) } } -func withTagPolicy(tagPolicy latestV1.TagPolicy) func(*latestV1.BuildConfig) { - return func(cfg *latestV1.BuildConfig) { cfg.TagPolicy = tagPolicy } +func withTagPolicy(tagPolicy latest.TagPolicy) func(*latest.BuildConfig) { + return func(cfg *latest.BuildConfig) { cfg.TagPolicy = tagPolicy } } -func withGitTagger() func(*latestV1.BuildConfig) { - return withTagPolicy(latestV1.TagPolicy{GitTagger: &latestV1.GitTagger{}}) +func withGitTagger() func(*latest.BuildConfig) { + return withTagPolicy(latest.TagPolicy{GitTagger: &latest.GitTagger{}}) } -func withShaTagger() func(*latestV1.BuildConfig) { - return withTagPolicy(latestV1.TagPolicy{ShaTagger: &latestV1.ShaTagger{}}) +func withShaTagger() func(*latest.BuildConfig) { + return withTagPolicy(latest.TagPolicy{ShaTagger: &latest.ShaTagger{}}) } -func withProfiles(profiles ...latestV1.Profile) func(*latestV1.SkaffoldConfig) { - return func(cfg *latestV1.SkaffoldConfig) { +func withProfiles(profiles ...latest.Profile) func(*latest.SkaffoldConfig) { + return func(cfg *latest.SkaffoldConfig) { cfg.Profiles = profiles } } -func withTests(testCases ...*latestV1.TestCase) func(*latestV1.SkaffoldConfig) { - return func(cfg *latestV1.SkaffoldConfig) { +func withTests(testCases ...*latest.TestCase) func(*latest.SkaffoldConfig) { + return func(cfg *latest.SkaffoldConfig) { cfg.Test = testCases } } -func withPortForward(portForward ...*latestV1.PortForwardResource) func(*latestV1.SkaffoldConfig) { - return func(cfg *latestV1.SkaffoldConfig) { +func withPortForward(portForward ...*latest.PortForwardResource) func(*latest.SkaffoldConfig) { + return func(cfg *latest.SkaffoldConfig) { cfg.PortForward = portForward } } -func withStatusCheckDeadline(deadline int) func(*latestV1.SkaffoldConfig) { - return func(cfg *latestV1.SkaffoldConfig) { +func withStatusCheckDeadline(deadline int) func(*latest.SkaffoldConfig) { + return func(cfg *latest.SkaffoldConfig) { cfg.Deploy.StatusCheckDeadlineSeconds = deadline } } -func withLogsPrefix(prefix string) func(*latestV1.SkaffoldConfig) { - return func(cfg *latestV1.SkaffoldConfig) { +func withLogsPrefix(prefix string) func(*latest.SkaffoldConfig) { + return func(cfg *latest.SkaffoldConfig) { cfg.Deploy.Logs.Prefix = prefix } } @@ -691,7 +691,7 @@ func TestUpgradeToNextVersion(t *testing.T) { } func TestCantUpgradeFromLatestV1Version(t *testing.T) { - factory, present := SchemaVersionsV1.Find(latestV1.Version) + factory, present := SchemaVersionsV1.Find(latest.Version) testutil.CheckDeepEqual(t, true, present) _, err := factory().Upgrade() @@ -709,7 +709,7 @@ func TestCantUpgradeFromLatestV2Version(t *testing.T) { func TestParseConfigAndUpgradeToOlderVersion(t *testing.T) { testutil.Run(t, "", func(t *testutil.T) { t.NewTempDir(). - Write("skaffold.yaml", fmt.Sprintf("apiVersion: %s\nkind: Config\n%s", latestV1.Version, minimalConfig)). + Write("skaffold.yaml", fmt.Sprintf("apiVersion: %s\nkind: Config\n%s", latest.Version, minimalConfig)). Chdir() cfgs, err := ParseConfig("skaffold.yaml") @@ -735,7 +735,7 @@ func TestGetLatestFromCompatibilityCheck(t *testing.T) { &v2beta1.SkaffoldConfig{APIVersion: v2beta1.Version}, }, description: "valid compatibility check for all v1 schemas releases", - expected: latestV1.Version, + expected: latest.Version, shouldErr: false, }, { @@ -755,7 +755,7 @@ func TestGetLatestFromCompatibilityCheck(t *testing.T) { description: "invalid compatibility among v1 and v2 versions", shouldErr: true, err: fmt.Errorf("detected incompatible versions:%v are incompatible with %v", - []string{latestV1.Version, v1alpha1.Version}, []string{v3alpha1.Version}), + []string{latest.Version, v1alpha1.Version}, []string{v3alpha1.Version}), }, { apiVersions: []util.VersionedConfig{ @@ -818,7 +818,7 @@ func TestIsCompatibleWith(t *testing.T) { &latestV2.SkaffoldConfig{APIVersion: latestV2.Version}, }, description: "v2 schemas are incompatible with v1.", - toVersion: latestV1.Version, + toVersion: latest.Version, shouldErr: true, err: fmt.Errorf("the following versions are incompatible with target version %v. upgrade aborted", []string{v3alpha1.Version, latestV2.Version}), diff --git a/pkg/skaffold/sources/upload.go b/pkg/skaffold/sources/upload.go index f1fb5a8f48d..54562c063f3 100644 --- a/pkg/skaffold/sources/upload.go +++ b/pkg/skaffold/sources/upload.go @@ -22,12 +22,12 @@ import ( cstorage "cloud.google.com/go/storage" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) // UploadToGCS uploads the artifact's sources to a GCS bucket. -func UploadToGCS(ctx context.Context, c *cstorage.Client, a *latestV1.Artifact, bucket, objectName string, dependencies []string) error { +func UploadToGCS(ctx context.Context, c *cstorage.Client, a *latest.Artifact, bucket, objectName string, dependencies []string) error { w := c.Bucket(bucket).Object(objectName).NewWriter(ctx) if err := util.CreateTarGz(w, a.Workspace, dependencies); err != nil { diff --git a/pkg/skaffold/survey/config.go b/pkg/skaffold/survey/config.go index 61e9d7edb99..10ba626eb96 100644 --- a/pkg/skaffold/survey/config.go +++ b/pkg/skaffold/survey/config.go @@ -22,7 +22,7 @@ import ( "time" sConfig "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" ) @@ -52,7 +52,7 @@ var ( promptText: "Help improve Skaffold's Helm support by taking our 2-minute anonymous survey", isRelevantFn: func(cfgs []util.VersionedConfig, _ sConfig.RunMode) bool { for _, cfg := range cfgs { - v1Cfg, ok := cfg.(*latestV1.SkaffoldConfig) + v1Cfg, ok := cfg.(*latest.SkaffoldConfig) if !ok { return false } diff --git a/pkg/skaffold/sync/docker_test.go b/pkg/skaffold/sync/docker_test.go index 11082a5f2b1..17673305507 100644 --- a/pkg/skaffold/sync/docker_test.go +++ b/pkg/skaffold/sync/docker_test.go @@ -21,7 +21,7 @@ import ( "strings" "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -36,7 +36,7 @@ func TestDockerSync(t *testing.T) { description: "additions are added via tar", item: &Item{ Image: "image:123", - Artifact: &latestV1.Artifact{ + Artifact: &latest.Artifact{ ImageName: "image", }, Copy: syncMap{"test.go": {"/test.go"}}, @@ -47,7 +47,7 @@ func TestDockerSync(t *testing.T) { description: "one deletion", item: &Item{ Image: "image:123", - Artifact: &latestV1.Artifact{ + Artifact: &latest.Artifact{ ImageName: "image", }, Delete: syncMap{"test.go": {"/test.go"}}, @@ -58,7 +58,7 @@ func TestDockerSync(t *testing.T) { description: "two deletions", item: &Item{ Image: "image:123", - Artifact: &latestV1.Artifact{ + Artifact: &latest.Artifact{ ImageName: "image", }, Delete: syncMap{"test.go": {"/test.go"}, "foobar.js": {"/dev/js/foobar.js"}}, diff --git a/pkg/skaffold/sync/sync.go b/pkg/skaffold/sync/sync.go index 3ee5634f08b..e673bd89b4e 100644 --- a/pkg/skaffold/sync/sync.go +++ b/pkg/skaffold/sync/sync.go @@ -40,7 +40,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/hooks" kubernetesclient "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -51,7 +51,7 @@ var ( SyncMap = syncMapForArtifact ) -func NewItem(ctx context.Context, a *latestV1.Artifact, e filemon.Events, builds []graph.Artifact, cfg docker.Config, dependentArtifactsCount int) (*Item, error) { +func NewItem(ctx context.Context, a *latest.Artifact, e filemon.Events, builds []graph.Artifact, cfg docker.Config, dependentArtifactsCount int) (*Item, error) { if !e.HasChanged() || a.Sync == nil { return nil, nil } @@ -81,7 +81,7 @@ func NewItem(ctx context.Context, a *latestV1.Artifact, e filemon.Events, builds } } -func syncItem(ctx context.Context, a *latestV1.Artifact, tag string, e filemon.Events, syncRules []*latestV1.SyncRule, cfg docker.Config) (*Item, error) { +func syncItem(ctx context.Context, a *latest.Artifact, tag string, e filemon.Events, syncRules []*latest.SyncRule, cfg docker.Config) (*Item, error) { containerWd, err := WorkingDir(ctx, tag, cfg) if err != nil { return nil, fmt.Errorf("retrieving working dir for %q: %w", tag, err) @@ -105,7 +105,7 @@ func syncItem(ctx context.Context, a *latestV1.Artifact, tag string, e filemon.E return &Item{Image: tag, Artifact: a, Copy: toCopy, Delete: toDelete}, nil } -func inferredSyncItem(ctx context.Context, a *latestV1.Artifact, tag string, e filemon.Events, cfg docker.Config) (*Item, error) { +func inferredSyncItem(ctx context.Context, a *latest.Artifact, tag string, e filemon.Events, cfg docker.Config) (*Item, error) { // deleted files are no longer contained in the syncMap, so we need to rebuild if len(e.Deleted) > 0 { return nil, nil @@ -149,7 +149,7 @@ func inferredSyncItem(ctx context.Context, a *latestV1.Artifact, tag string, e f return &Item{Image: tag, Artifact: a, Copy: toCopy}, nil } -func syncMapForArtifact(ctx context.Context, a *latestV1.Artifact, cfg docker.Config) (map[string][]string, error) { +func syncMapForArtifact(ctx context.Context, a *latest.Artifact, cfg docker.Config) (map[string][]string, error) { switch { case a.DockerArtifact != nil: return docker.SyncMap(ctx, a.Workspace, a.DockerArtifact.DockerfilePath, a.DockerArtifact.BuildArgs, cfg) @@ -168,7 +168,7 @@ func syncMapForArtifact(ctx context.Context, a *latestV1.Artifact, cfg docker.Co } } -func autoSyncItem(ctx context.Context, a *latestV1.Artifact, tag string, e filemon.Events, cfg docker.Config) (*Item, error) { +func autoSyncItem(ctx context.Context, a *latest.Artifact, tag string, e filemon.Events, cfg docker.Config) (*Item, error) { switch { case a.BuildpackArtifact != nil: labels, err := Labels(ctx, tag, cfg) @@ -209,7 +209,7 @@ func latestTag(image string, builds []graph.Artifact) string { return "" } -func intersect(ctx context.Context, contextWd, containerWd string, syncRules []*latestV1.SyncRule, files []string) (syncMap, error) { +func intersect(ctx context.Context, contextWd, containerWd string, syncRules []*latest.SyncRule, files []string) (syncMap, error) { ret := make(syncMap) for _, f := range files { relPath, err := filepath.Rel(contextWd, f) @@ -232,7 +232,7 @@ func intersect(ctx context.Context, contextWd, containerWd string, syncRules []* return ret, nil } -func matchSyncRules(syncRules []*latestV1.SyncRule, relPath, containerWd string) ([]string, error) { +func matchSyncRules(syncRules []*latest.SyncRule, relPath, containerWd string) ([]string, error) { dsts := make([]string, 0, 1) for _, r := range syncRules { matches, err := doublestar.PathMatch(filepath.FromSlash(r.Src), relPath) @@ -356,7 +356,7 @@ func Perform(ctx context.Context, image string, files syncMap, cmdFn func(contex return nil } -func Init(ctx context.Context, artifacts []*latestV1.Artifact) error { +func Init(ctx context.Context, artifacts []*latest.Artifact) error { for _, a := range artifacts { if a.Sync == nil { continue diff --git a/pkg/skaffold/sync/sync_test.go b/pkg/skaffold/sync/sync_test.go index 9d0b11579d9..bde29a40d1d 100644 --- a/pkg/skaffold/sync/sync_test.go +++ b/pkg/skaffold/sync/sync_test.go @@ -35,7 +35,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/filemon" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -44,7 +44,7 @@ func TestNewSyncItem(t *testing.T) { ctx := context.Background() tests := []struct { description string - artifact *latestV1.Artifact + artifact *latest.Artifact dependencies map[string][]string labels map[string]string evt filemon.Events @@ -56,10 +56,10 @@ func TestNewSyncItem(t *testing.T) { // manual sync cases { description: "manual: match copy", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "test", - Sync: &latestV1.Sync{ - Manual: []*latestV1.SyncRule{{Src: "*.html", Dest: "."}}, + Sync: &latest.Sync{ + Manual: []*latest.SyncRule{{Src: "*.html", Dest: "."}}, }, Workspace: ".", }, @@ -82,10 +82,10 @@ func TestNewSyncItem(t *testing.T) { }, { description: "manual: no tag for image", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "notbuildyet", - Sync: &latestV1.Sync{ - Manual: []*latestV1.SyncRule{{Src: "*.html", Dest: "."}}, + Sync: &latest.Sync{ + Manual: []*latest.SyncRule{{Src: "*.html", Dest: "."}}, }, Workspace: ".", }, @@ -102,10 +102,10 @@ func TestNewSyncItem(t *testing.T) { }, { description: "manual: multiple sync patterns", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "test", - Sync: &latestV1.Sync{ - Manual: []*latestV1.SyncRule{ + Sync: &latest.Sync{ + Manual: []*latest.SyncRule{ {Src: "*.js", Dest: "."}, {Src: "*.html", Dest: "."}, {Src: "*.json", Dest: "."}, @@ -137,10 +137,10 @@ func TestNewSyncItem(t *testing.T) { }, { description: "manual: recursive glob patterns", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "test", - Sync: &latestV1.Sync{ - Manual: []*latestV1.SyncRule{ + Sync: &latest.Sync{ + Manual: []*latest.SyncRule{ {Src: "src/**/*.js", Dest: "src/", Strip: "src/"}, }, }, @@ -166,10 +166,10 @@ func TestNewSyncItem(t *testing.T) { }, { description: "manual: sync all", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "test", - Sync: &latestV1.Sync{ - Manual: []*latestV1.SyncRule{ + Sync: &latest.Sync{ + Manual: []*latest.SyncRule{ {Src: "*", Dest: "."}, }, }, @@ -199,9 +199,9 @@ func TestNewSyncItem(t *testing.T) { }, { description: "manual: not copy syncable", - artifact: &latestV1.Artifact{ - Sync: &latestV1.Sync{ - Manual: []*latestV1.SyncRule{ + artifact: &latest.Artifact{ + Sync: &latest.Sync{ + Manual: []*latest.SyncRule{ {Src: "*.html", Dest: "."}, }, }, @@ -219,9 +219,9 @@ func TestNewSyncItem(t *testing.T) { }, { description: "manual: not delete syncable", - artifact: &latestV1.Artifact{ - Sync: &latestV1.Sync{ - Manual: []*latestV1.SyncRule{ + artifact: &latest.Artifact{ + Sync: &latest.Sync{ + Manual: []*latest.SyncRule{ {Src: "*.html", Dest: "/static"}, }, }, @@ -239,9 +239,9 @@ func TestNewSyncItem(t *testing.T) { }, { description: "manual: err bad pattern", - artifact: &latestV1.Artifact{ - Sync: &latestV1.Sync{ - Manual: []*latestV1.SyncRule{ + artifact: &latest.Artifact{ + Sync: &latest.Sync{ + Manual: []*latest.SyncRule{ {Src: "[*.html", Dest: "*"}, }, }, @@ -255,9 +255,9 @@ func TestNewSyncItem(t *testing.T) { }, { description: "manual: no change no sync", - artifact: &latestV1.Artifact{ - Sync: &latestV1.Sync{ - Manual: []*latestV1.SyncRule{ + artifact: &latest.Artifact{ + Sync: &latest.Sync{ + Manual: []*latest.SyncRule{ {Src: "*.html", Dest: "*"}, }, }, @@ -272,10 +272,10 @@ func TestNewSyncItem(t *testing.T) { }, { description: "manual: slashes in glob pattern", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "test", - Sync: &latestV1.Sync{ - Manual: []*latestV1.SyncRule{ + Sync: &latest.Sync{ + Manual: []*latest.SyncRule{ {Src: "**/**/*.js", Dest: "."}, }, }, @@ -301,10 +301,10 @@ func TestNewSyncItem(t *testing.T) { }, { description: "manual: sync subtrees", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "test", - Sync: &latestV1.Sync{ - Manual: []*latestV1.SyncRule{ + Sync: &latest.Sync{ + Manual: []*latest.SyncRule{ {Src: "dir1/**/*.js", Dest: ".", Strip: "dir1/"}, }, }, @@ -330,10 +330,10 @@ func TestNewSyncItem(t *testing.T) { }, { description: "manual: multiple matches", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "test", - Sync: &latestV1.Sync{ - Manual: []*latestV1.SyncRule{ + Sync: &latest.Sync{ + Manual: []*latest.SyncRule{ {Src: "dir1/**/*.js", Dest: ".", Strip: "dir1/"}, {Src: "dir1/**/**/*.js", Dest: "."}, }, @@ -360,10 +360,10 @@ func TestNewSyncItem(t *testing.T) { }, { description: "manual: stars work with absolute paths", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "test", - Sync: &latestV1.Sync{ - Manual: []*latestV1.SyncRule{ + Sync: &latest.Sync{ + Manual: []*latest.SyncRule{ {Src: "dir1a/**/*.js", Dest: "/tstar", Strip: "dir1a/"}, {Src: "dir1b/**/*.js", Dest: "/dstar"}, }, @@ -396,9 +396,9 @@ func TestNewSyncItem(t *testing.T) { // auto-sync cases { description: "infer: match copy", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "test", - Sync: &latestV1.Sync{ + Sync: &latest.Sync{ Infer: []string{"*.html"}, }, Workspace: ".", @@ -422,9 +422,9 @@ func TestNewSyncItem(t *testing.T) { }, { description: "infer: not auto-syncable", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "test", - Sync: &latestV1.Sync{ + Sync: &latest.Sync{ Infer: []string{"*.html"}, }, Workspace: ".", @@ -442,9 +442,9 @@ func TestNewSyncItem(t *testing.T) { }, { description: "infer: file not specified for syncing", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "test", - Sync: &latestV1.Sync{ + Sync: &latest.Sync{ Infer: []string{"*.js"}, }, Workspace: ".", @@ -462,9 +462,9 @@ func TestNewSyncItem(t *testing.T) { }, { description: "infer: no tag for image", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "notbuildyet", - Sync: &latestV1.Sync{ + Sync: &latest.Sync{ Infer: []string{"*.html"}, }, Workspace: ".", @@ -483,9 +483,9 @@ func TestNewSyncItem(t *testing.T) { }, { description: "infer: multiple sync patterns", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "test", - Sync: &latestV1.Sync{ + Sync: &latest.Sync{ Infer: []string{"*.js", "*.html", "*.json"}, }, Workspace: "node", @@ -511,9 +511,9 @@ func TestNewSyncItem(t *testing.T) { }, { description: "infer: recursive glob patterns", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "test", - Sync: &latestV1.Sync{ + Sync: &latest.Sync{ Infer: []string{"src/**/*.js"}, }, Workspace: "node", @@ -538,9 +538,9 @@ func TestNewSyncItem(t *testing.T) { }, { description: "infer: sync all", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "test", - Sync: &latestV1.Sync{ + Sync: &latest.Sync{ Infer: []string{"*"}, }, Workspace: "node", @@ -566,8 +566,8 @@ func TestNewSyncItem(t *testing.T) { }, { description: "infer: delete not syncable", - artifact: &latestV1.Artifact{ - Sync: &latestV1.Sync{ + artifact: &latest.Artifact{ + Sync: &latest.Sync{ Infer: []string{"*"}, }, Workspace: ".", @@ -585,8 +585,8 @@ func TestNewSyncItem(t *testing.T) { }, { description: "infer: err bad pattern", - artifact: &latestV1.Artifact{ - Sync: &latestV1.Sync{ + artifact: &latest.Artifact{ + Sync: &latest.Sync{ Infer: []string{"[*.html"}, }, Workspace: ".", @@ -599,8 +599,8 @@ func TestNewSyncItem(t *testing.T) { }, { description: "infer: no change no sync", - artifact: &latestV1.Artifact{ - Sync: &latestV1.Sync{ + artifact: &latest.Artifact{ + Sync: &latest.Sync{ Infer: []string{"*.html"}, }, Workspace: ".", @@ -615,9 +615,9 @@ func TestNewSyncItem(t *testing.T) { }, { description: "infer: slashes in glob pattern", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "test", - Sync: &latestV1.Sync{ + Sync: &latest.Sync{ Infer: []string{"**/**/*.js"}, }, Workspace: ".", @@ -644,12 +644,12 @@ func TestNewSyncItem(t *testing.T) { // Buildpacks { description: "auto with buildpacks", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - BuildpackArtifact: &latestV1.BuildpackArtifact{}, + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + BuildpackArtifact: &latest.BuildpackArtifact{}, }, ImageName: "test", - Sync: &latestV1.Sync{ + Sync: &latest.Sync{ Auto: util.BoolPtr(true), }, Workspace: ".", @@ -684,12 +684,12 @@ func TestNewSyncItem(t *testing.T) { }, { description: "unknown change with buildpacks", - artifact: &latestV1.Artifact{ - ArtifactType: latestV1.ArtifactType{ - BuildpackArtifact: &latestV1.BuildpackArtifact{}, + artifact: &latest.Artifact{ + ArtifactType: latest.ArtifactType{ + BuildpackArtifact: &latest.BuildpackArtifact{}, }, ImageName: "test", - Sync: &latestV1.Sync{ + Sync: &latest.Sync{ Auto: util.BoolPtr(true), }, Workspace: ".", @@ -720,14 +720,14 @@ func TestNewSyncItem(t *testing.T) { // Auto with Jib { description: "auto with jib", - artifact: &latestV1.Artifact{ + artifact: &latest.Artifact{ ImageName: "test", Workspace: ".", - Sync: &latestV1.Sync{ + Sync: &latest.Sync{ Auto: util.BoolPtr(true), }, - ArtifactType: latestV1.ArtifactType{ - JibArtifact: &latestV1.JibArtifact{}, + ArtifactType: latest.ArtifactType{ + JibArtifact: &latest.JibArtifact{}, }, }, evt: filemon.Events{ @@ -751,11 +751,11 @@ func TestNewSyncItem(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { t.Override(&WorkingDir, func(context.Context, string, docker.Config) (string, error) { return test.workingDir, nil }) - t.Override(&SyncMap, func(context.Context, *latestV1.Artifact, docker.Config) (map[string][]string, error) { + t.Override(&SyncMap, func(context.Context, *latest.Artifact, docker.Config) (map[string][]string, error) { return test.dependencies, nil }) t.Override(&Labels, func(context.Context, string, docker.Config) (map[string]string, error) { return test.labels, nil }) - t.Override(&jib.GetSyncDiff, func(context.Context, string, *latestV1.JibArtifact, filemon.Events) (map[string][]string, map[string][]string, error) { + t.Override(&jib.GetSyncDiff, func(context.Context, string, *latest.JibArtifact, filemon.Events) (map[string][]string, map[string][]string, error) { return map[string][]string{"file.class": {"/some/file.class"}}, nil, nil }) @@ -771,7 +771,7 @@ func TestNewSyncItem(t *testing.T) { func TestIntersect(t *testing.T) { tests := []struct { description string - syncRules []*latestV1.SyncRule + syncRules []*latest.SyncRule files []string context string workingDir string @@ -785,7 +785,7 @@ func TestIntersect(t *testing.T) { { description: "copy nested file to correct destination", files: []string{filepath.Join("static", "index.html"), filepath.Join("static", "test.html")}, - syncRules: []*latestV1.SyncRule{ + syncRules: []*latest.SyncRule{ {Src: filepath.Join("static", "*.html"), Dest: "/html", Strip: "static/"}, }, expected: map[string][]string{ @@ -796,7 +796,7 @@ func TestIntersect(t *testing.T) { { description: "double-star matches depth zero", files: []string{"index.html"}, - syncRules: []*latestV1.SyncRule{ + syncRules: []*latest.SyncRule{ {Src: filepath.Join("**", "*.html"), Dest: "/html"}, }, expected: map[string][]string{ @@ -807,7 +807,7 @@ func TestIntersect(t *testing.T) { description: "file not in . copies to correct destination", files: []string{filepath.Join("node", "server.js")}, context: "node", - syncRules: []*latestV1.SyncRule{ + syncRules: []*latest.SyncRule{ {Src: "*.js", Dest: "/"}, }, expected: map[string][]string{ @@ -818,7 +818,7 @@ func TestIntersect(t *testing.T) { description: "file change not relative to context throws error", files: []string{filepath.Join("node", "server.js"), filepath.Join("/", "something", "test.js")}, context: "node", - syncRules: []*latestV1.SyncRule{ + syncRules: []*latest.SyncRule{ {Src: "*.js", Dest: "/"}, }, shouldErr: true, @@ -970,15 +970,15 @@ func TestPerform(t *testing.T) { func TestSyncMap(t *testing.T) { tests := []struct { description string - artifactType latestV1.ArtifactType + artifactType latest.ArtifactType files map[string]string shouldErr bool expectedMap map[string][]string }{ { description: "docker - supported", - artifactType: latestV1.ArtifactType{ - DockerArtifact: &latestV1.DockerArtifact{ + artifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ DockerfilePath: "Dockerfile", }, }, @@ -990,8 +990,8 @@ func TestSyncMap(t *testing.T) { }, { description: "kaniko - supported", - artifactType: latestV1.ArtifactType{ - KanikoArtifact: &latestV1.KanikoArtifact{ + artifactType: latest.ArtifactType{ + KanikoArtifact: &latest.KanikoArtifact{ DockerfilePath: "Dockerfile", }, }, @@ -1003,10 +1003,10 @@ func TestSyncMap(t *testing.T) { }, { description: "custom - supported", - artifactType: latestV1.ArtifactType{ - CustomArtifact: &latestV1.CustomArtifact{ - Dependencies: &latestV1.CustomDependencies{ - Dockerfile: &latestV1.DockerfileDependency{ + artifactType: latest.ArtifactType{ + CustomArtifact: &latest.CustomArtifact{ + Dependencies: &latest.CustomDependencies{ + Dockerfile: &latest.DockerfileDependency{ Path: "Dockerfile", }, }, @@ -1020,14 +1020,14 @@ func TestSyncMap(t *testing.T) { }, { description: "custom, no dockerfile - not supported", - artifactType: latestV1.ArtifactType{ - CustomArtifact: &latestV1.CustomArtifact{}, + artifactType: latest.ArtifactType{ + CustomArtifact: &latest.CustomArtifact{}, }, shouldErr: true, }, { description: "not supported", - artifactType: latestV1.ArtifactType{}, + artifactType: latest.ArtifactType{}, shouldErr: true, }, } @@ -1037,7 +1037,7 @@ func TestSyncMap(t *testing.T) { t.Override(&docker.RetrieveImage, imageFetcher.fetch) t.NewTempDir().WriteFiles(test.files).Chdir() - syncMap, err := SyncMap(context.Background(), &latestV1.Artifact{ArtifactType: test.artifactType}, nil) + syncMap, err := SyncMap(context.Background(), &latest.Artifact{ArtifactType: test.artifactType}, nil) t.CheckError(test.shouldErr, err) t.CheckDeepEqual(test.expectedMap, syncMap) @@ -1055,34 +1055,34 @@ func TestInit(t *testing.T) { ctx := context.Background() tests := []struct { description string - artifact *latestV1.Artifact + artifact *latest.Artifact shouldInit bool initErrors bool }{ { description: "sync off", - artifact: &latestV1.Artifact{}, + artifact: &latest.Artifact{}, shouldInit: false, }, { description: "sync on, auto off", - artifact: &latestV1.Artifact{Sync: &latestV1.Sync{}}, + artifact: &latest.Artifact{Sync: &latest.Sync{}}, shouldInit: false, }, { description: "sync on, auto on, non-jib", - artifact: &latestV1.Artifact{Sync: &latestV1.Sync{Auto: util.BoolPtr(true)}}, + artifact: &latest.Artifact{Sync: &latest.Sync{Auto: util.BoolPtr(true)}}, shouldInit: false, }, { description: "sync on, auto on, jib", - artifact: &latestV1.Artifact{ArtifactType: latestV1.ArtifactType{JibArtifact: &latestV1.JibArtifact{}}, Sync: &latestV1.Sync{Auto: util.BoolPtr(true)}}, + artifact: &latest.Artifact{ArtifactType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{}}, Sync: &latest.Sync{Auto: util.BoolPtr(true)}}, shouldInit: true, initErrors: false, }, { description: "sync on, auto on, jib, init fails", - artifact: &latestV1.Artifact{ArtifactType: latestV1.ArtifactType{JibArtifact: &latestV1.JibArtifact{}}, Sync: &latestV1.Sync{Auto: util.BoolPtr(true)}}, + artifact: &latest.Artifact{ArtifactType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{}}, Sync: &latest.Sync{Auto: util.BoolPtr(true)}}, shouldInit: true, initErrors: true, }, @@ -1090,7 +1090,7 @@ func TestInit(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { isCalled := false - t.Override(&jib.InitSync, func(ctx context.Context, workspace string, a *latestV1.JibArtifact) error { + t.Override(&jib.InitSync, func(ctx context.Context, workspace string, a *latest.JibArtifact) error { isCalled = true if test.initErrors { return errors.New("intentional test failure") @@ -1098,7 +1098,7 @@ func TestInit(t *testing.T) { return nil }) - artifacts := []*latestV1.Artifact{test.artifact} + artifacts := []*latest.Artifact{test.artifact} err := Init(ctx, artifacts) t.CheckDeepEqual(test.shouldInit, isCalled) t.CheckError(test.initErrors, err) diff --git a/pkg/skaffold/sync/types.go b/pkg/skaffold/sync/types.go index 36384289415..28ece32da0c 100644 --- a/pkg/skaffold/sync/types.go +++ b/pkg/skaffold/sync/types.go @@ -22,14 +22,14 @@ import ( pkgkubectl "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/logger" - v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) type syncMap map[string][]string type Item struct { Image string - Artifact *v1.Artifact + Artifact *latest.Artifact Copy map[string][]string Delete map[string][]string } diff --git a/pkg/skaffold/tag/custom.go b/pkg/skaffold/tag/custom.go index 602d2559ece..e90f13552b6 100644 --- a/pkg/skaffold/tag/custom.go +++ b/pkg/skaffold/tag/custom.go @@ -20,7 +20,7 @@ import ( "context" "errors" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) type CustomTag struct { @@ -28,7 +28,7 @@ type CustomTag struct { } // GenerateTag generates a tag using the custom tag. -func (t *CustomTag) GenerateTag(ctx context.Context, image latestV1.Artifact) (string, error) { +func (t *CustomTag) GenerateTag(ctx context.Context, image latest.Artifact) (string, error) { tag := t.Tag if tag == "" { return "", errors.New("custom tag not provided") diff --git a/pkg/skaffold/tag/custom_template.go b/pkg/skaffold/tag/custom_template.go index 3acff3175d5..70b033a719d 100644 --- a/pkg/skaffold/tag/custom_template.go +++ b/pkg/skaffold/tag/custom_template.go @@ -23,7 +23,7 @@ import ( "text/template" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // customTemplateTagger implements Tagger @@ -46,7 +46,7 @@ func NewCustomTemplateTagger(t string, components map[string]Tagger) (Tagger, er } // GenerateTag generates a tag from a template referencing tagging strategies. -func (t *customTemplateTagger) GenerateTag(ctx context.Context, image latestV1.Artifact) (string, error) { +func (t *customTemplateTagger) GenerateTag(ctx context.Context, image latest.Artifact) (string, error) { customMap, err := t.EvaluateComponents(ctx, image) if err != nil { return "", err @@ -62,7 +62,7 @@ func (t *customTemplateTagger) GenerateTag(ctx context.Context, image latestV1.A } // EvaluateComponents creates a custom mapping of component names to their tagger string representation. -func (t *customTemplateTagger) EvaluateComponents(ctx context.Context, image latestV1.Artifact) (map[string]string, error) { +func (t *customTemplateTagger) EvaluateComponents(ctx context.Context, image latest.Artifact) (map[string]string, error) { customMap := map[string]string{} gitTagger, _ := NewGitCommit("", "", false) diff --git a/pkg/skaffold/tag/custom_template_test.go b/pkg/skaffold/tag/custom_template_test.go index c3aa063ea58..71196be08e0 100644 --- a/pkg/skaffold/tag/custom_template_test.go +++ b/pkg/skaffold/tag/custom_template_test.go @@ -21,7 +21,7 @@ import ( "testing" "time" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -105,7 +105,7 @@ func TestTagTemplate_GenerateTag(t *testing.T) { t.CheckNoError(err) - image := latestV1.Artifact{ + image := latest.Artifact{ ImageName: "test", } tag, err := c.GenerateTag(context.Background(), image) diff --git a/pkg/skaffold/tag/custom_test.go b/pkg/skaffold/tag/custom_test.go index 1cd302c4a2e..2f29563b273 100644 --- a/pkg/skaffold/tag/custom_test.go +++ b/pkg/skaffold/tag/custom_test.go @@ -20,7 +20,7 @@ import ( "context" "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -45,7 +45,7 @@ func TestCustomTag_GenerateTag(t *testing.T) { }, } for _, test := range tests { - image := latestV1.Artifact{ + image := latest.Artifact{ ImageName: "test", } tag, err := test.c.GenerateTag(context.Background(), image) diff --git a/pkg/skaffold/tag/date_time.go b/pkg/skaffold/tag/date_time.go index 27a29636502..47d6e1e21e0 100644 --- a/pkg/skaffold/tag/date_time.go +++ b/pkg/skaffold/tag/date_time.go @@ -23,7 +23,7 @@ import ( "4d63.com/tz" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) const tagTime = "2006-01-02_15-04-05.999_MST" @@ -46,7 +46,7 @@ func NewDateTimeTagger(format, timezone string) Tagger { } // GenerateTag generates a tag using the current timestamp. -func (t *dateTimeTagger) GenerateTag(ctx context.Context, image latestV1.Artifact) (string, error) { +func (t *dateTimeTagger) GenerateTag(ctx context.Context, image latest.Artifact) (string, error) { format := tagTime if len(t.Format) > 0 { format = t.Format diff --git a/pkg/skaffold/tag/date_time_test.go b/pkg/skaffold/tag/date_time_test.go index 892c1023abb..9d2fe4dc408 100644 --- a/pkg/skaffold/tag/date_time_test.go +++ b/pkg/skaffold/tag/date_time_test.go @@ -21,7 +21,7 @@ import ( "testing" "time" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -70,7 +70,7 @@ func TestDateTime_GenerateTag(t *testing.T) { timeFn: func() time.Time { return test.buildTime }, } - image := latestV1.Artifact{ + image := latest.Artifact{ ImageName: "test", } diff --git a/pkg/skaffold/tag/env_template.go b/pkg/skaffold/tag/env_template.go index c7f4050b31a..f403fb27604 100644 --- a/pkg/skaffold/tag/env_template.go +++ b/pkg/skaffold/tag/env_template.go @@ -21,7 +21,7 @@ import ( "fmt" "text/template" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -43,7 +43,7 @@ func NewEnvTemplateTagger(t string) (Tagger, error) { } // GenerateTag generates a tag from a template referencing environment variables. -func (t *envTemplateTagger) GenerateTag(ctx context.Context, image latestV1.Artifact) (string, error) { +func (t *envTemplateTagger) GenerateTag(ctx context.Context, image latest.Artifact) (string, error) { // missingkey=error throws error when map is indexed with an undefined key tag, err := util.ExecuteEnvTemplate(t.Template.Option("missingkey=error"), map[string]string{ "IMAGE_NAME": image.ImageName, diff --git a/pkg/skaffold/tag/env_template_test.go b/pkg/skaffold/tag/env_template_test.go index d98248b6a3b..ec7819c6978 100644 --- a/pkg/skaffold/tag/env_template_test.go +++ b/pkg/skaffold/tag/env_template_test.go @@ -20,7 +20,7 @@ import ( "context" "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/warnings" "github.com/GoogleContainerTools/skaffold/testutil" @@ -101,7 +101,7 @@ func TestEnvTemplateTagger_GenerateTag(t *testing.T) { c, err := NewEnvTemplateTagger(test.template) t.CheckNoError(err) - image := latestV1.Artifact{ + image := latest.Artifact{ ImageName: test.imageName, } diff --git a/pkg/skaffold/tag/git_commit.go b/pkg/skaffold/tag/git_commit.go index fa72724afae..816e059f2cf 100644 --- a/pkg/skaffold/tag/git_commit.go +++ b/pkg/skaffold/tag/git_commit.go @@ -26,7 +26,7 @@ import ( "strings" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -62,7 +62,7 @@ func NewGitCommit(prefix, variant string, ignoreChanges bool) (*GitCommit, error } // GenerateTag generates a tag from the git commit. -func (t *GitCommit) GenerateTag(ctx context.Context, image latestV1.Artifact) (string, error) { +func (t *GitCommit) GenerateTag(ctx context.Context, image latest.Artifact) (string, error) { ref, err := t.runGitFn(ctx, image.Workspace) if err != nil { return "", fmt.Errorf("unable to find git commit: %w", err) diff --git a/pkg/skaffold/tag/git_commit_test.go b/pkg/skaffold/tag/git_commit_test.go index 0d69859aa45..20a0d1c0747 100644 --- a/pkg/skaffold/tag/git_commit_test.go +++ b/pkg/skaffold/tag/git_commit_test.go @@ -32,7 +32,7 @@ import ( "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -439,7 +439,7 @@ func TestGitCommit_GenerateTag(t *testing.T) { tmpDir := t.NewTempDir() test.createGitRepo(tmpDir.Root()) - image := latestV1.Artifact{ + image := latest.Artifact{ ImageName: "test", Workspace: tmpDir.Path(test.subDir), } @@ -506,7 +506,7 @@ func TestGitCommit_GenerateFullyQualifiedImageName(t *testing.T) { testutil.Run(t, test.description, func(t *testutil.T) { tmpDir := t.NewTempDir() test.createGitRepo(tmpDir.Root()) - image := latestV1.Artifact{ + image := latest.Artifact{ ImageName: "test", Workspace: tmpDir.Path(test.subDir), } @@ -569,7 +569,7 @@ func TestGitCommit_CustomTemplate(t *testing.T) { testutil.Run(t, test.description, func(t *testutil.T) { tmpDir := t.NewTempDir() test.createGitRepo(tmpDir.Root()) - image := latestV1.Artifact{ + image := latest.Artifact{ ImageName: "test", Workspace: tmpDir.Path(test.subDir), } @@ -590,7 +590,7 @@ func TestGitCommitSubDirectory(t *testing.T) { testutil.Run(t, "", func(t *testutil.T) { tmpDir := t.NewTempDir() gitInit(t.T, tmpDir.Root()).mkdir("sub/sub").commit("initial") - image := latestV1.Artifact{ + image := latest.Artifact{ ImageName: "test", Workspace: tmpDir.Path("sub/sub"), } @@ -629,7 +629,7 @@ func TestPrefix(t *testing.T) { testutil.Run(t, "", func(t *testutil.T) { tmpDir := t.NewTempDir() gitInit(t.T, tmpDir.Root()).commit("initial") - image := latestV1.Artifact{ + image := latest.Artifact{ ImageName: "test", Workspace: tmpDir.Path("."), } diff --git a/pkg/skaffold/tag/input_digest.go b/pkg/skaffold/tag/input_digest.go index 1c3960a2731..2b5bcb724cf 100644 --- a/pkg/skaffold/tag/input_digest.go +++ b/pkg/skaffold/tag/input_digest.go @@ -31,7 +31,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) type inputDigestTagger struct { @@ -46,7 +46,7 @@ func NewInputDigestTagger(cfg docker.Config, ag graph.ArtifactGraph) (Tagger, er }, nil } -func (t *inputDigestTagger) GenerateTag(ctx context.Context, image latestV1.Artifact) (string, error) { +func (t *inputDigestTagger) GenerateTag(ctx context.Context, image latest.Artifact) (string, error) { var inputs []string srcFiles, err := t.cache.TransitiveArtifactDependencies(ctx, &image) if err != nil { diff --git a/pkg/skaffold/tag/sha256.go b/pkg/skaffold/tag/sha256.go index fe9d9b84dfb..5568f143782 100644 --- a/pkg/skaffold/tag/sha256.go +++ b/pkg/skaffold/tag/sha256.go @@ -20,14 +20,14 @@ import ( "context" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // ChecksumTagger tags an image by the sha256 of the image tarball type ChecksumTagger struct{} // GenerateTag returns either the current tag or `latest`. -func (t *ChecksumTagger) GenerateTag(ctx context.Context, image latestV1.Artifact) (string, error) { +func (t *ChecksumTagger) GenerateTag(ctx context.Context, image latest.Artifact) (string, error) { parsed, err := docker.ParseReference(image.ImageName) if err != nil { return "", err diff --git a/pkg/skaffold/tag/sha256_test.go b/pkg/skaffold/tag/sha256_test.go index 4f7cba8c340..7eca5a8b387 100644 --- a/pkg/skaffold/tag/sha256_test.go +++ b/pkg/skaffold/tag/sha256_test.go @@ -20,14 +20,14 @@ import ( "context" "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) func TestSha256_GenerateTag(t *testing.T) { c := &ChecksumTagger{} - image := latestV1.Artifact{ + image := latest.Artifact{ ImageName: "img:tag", } diff --git a/pkg/skaffold/tag/tag.go b/pkg/skaffold/tag/tag.go index 9891c6b1333..8354d76baa9 100644 --- a/pkg/skaffold/tag/tag.go +++ b/pkg/skaffold/tag/tag.go @@ -21,7 +21,7 @@ import ( "fmt" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // ImageTags maps image names to tags @@ -30,13 +30,13 @@ type ImageTags map[string]string // Tagger is an interface for tag strategies to be implemented against type Tagger interface { // GenerateTag generates a tag for an artifact. - GenerateTag(ctx context.Context, image latestV1.Artifact) (string, error) + GenerateTag(ctx context.Context, image latest.Artifact) (string, error) } // GenerateFullyQualifiedImageName resolves the fully qualified image name for an artifact. // The workingDir is the root directory of the artifact with respect to the Skaffold root, // and imageName is the base name of the image. -func GenerateFullyQualifiedImageName(ctx context.Context, t Tagger, image latestV1.Artifact) (string, error) { +func GenerateFullyQualifiedImageName(ctx context.Context, t Tagger, image latest.Artifact) (string, error) { tag, err := t.GenerateTag(ctx, image) if err != nil { return "", fmt.Errorf("generating tag: %w", err) diff --git a/pkg/skaffold/tag/tag_test.go b/pkg/skaffold/tag/tag_test.go index d3492436701..5162a0c9af3 100644 --- a/pkg/skaffold/tag/tag_test.go +++ b/pkg/skaffold/tag/tag_test.go @@ -21,7 +21,7 @@ import ( "testing" "time" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/warnings" "github.com/GoogleContainerTools/skaffold/testutil" @@ -117,7 +117,7 @@ func TestTagger_GenerateFullyQualifiedImageName(t *testing.T) { t.Override(&warnings.Printf, fakeWarner.Warnf) t.Override(&util.OSEnviron, func() []string { return env }) - image := latestV1.Artifact{ + image := latest.Artifact{ ImageName: test.imageName, } diff --git a/pkg/skaffold/tag/tagger_mux.go b/pkg/skaffold/tag/tagger_mux.go index db5e7dc6e14..b54fb190c2f 100644 --- a/pkg/skaffold/tag/tagger_mux.go +++ b/pkg/skaffold/tag/tagger_mux.go @@ -22,7 +22,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "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/latest" ) type TaggerMux struct { @@ -30,7 +30,7 @@ type TaggerMux struct { byImageName map[string]Tagger } -func (t *TaggerMux) GenerateTag(ctx context.Context, image latestV1.Artifact) (string, error) { +func (t *TaggerMux) GenerateTag(ctx context.Context, image latest.Artifact) (string, error) { tagger, found := t.byImageName[image.ImageName] if !found { return "", fmt.Errorf("no valid tagger found for artifact: %q", image.ImageName) @@ -55,7 +55,7 @@ func NewTaggerMux(runCtx *runcontext.RunContext) (Tagger, error) { return &TaggerMux{taggers: sl, byImageName: m}, nil } -func getTagger(runCtx *runcontext.RunContext, t *latestV1.TagPolicy) (Tagger, error) { +func getTagger(runCtx *runcontext.RunContext, t *latest.TagPolicy) (Tagger, error) { switch { case runCtx.CustomTag() != "": return &CustomTag{ @@ -93,7 +93,7 @@ func getTagger(runCtx *runcontext.RunContext, t *latestV1.TagPolicy) (Tagger, er } // CreateComponents creates a map of taggers for CustomTemplateTagger -func CreateComponents(runCtx *runcontext.RunContext, t *latestV1.CustomTemplateTagger) (map[string]Tagger, error) { +func CreateComponents(runCtx *runcontext.RunContext, t *latest.CustomTemplateTagger) (map[string]Tagger, error) { components := map[string]Tagger{} for _, taggerComponent := range t.Components { diff --git a/pkg/skaffold/tag/tagger_mux_test.go b/pkg/skaffold/tag/tagger_mux_test.go index b55971ee8f6..dc0d790a7f7 100644 --- a/pkg/skaffold/tag/tagger_mux_test.go +++ b/pkg/skaffold/tag/tagger_mux_test.go @@ -21,7 +21,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "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/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -34,19 +34,19 @@ func TestCreateComponents(t *testing.T) { tests := []struct { description string - customTemplateTagger *latestV1.CustomTemplateTagger + customTemplateTagger *latest.CustomTemplateTagger expected map[string]Tagger shouldErr bool }{ { description: "correct component types", - customTemplateTagger: &latestV1.CustomTemplateTagger{ - Components: []latestV1.TaggerComponent{ - {Name: "FOO", Component: latestV1.TagPolicy{GitTagger: &latestV1.GitTagger{}}}, - {Name: "FOE", Component: latestV1.TagPolicy{ShaTagger: &latestV1.ShaTagger{}}}, - {Name: "BAR", Component: latestV1.TagPolicy{EnvTemplateTagger: &latestV1.EnvTemplateTagger{Template: "test"}}}, - {Name: "BAT", Component: latestV1.TagPolicy{DateTimeTagger: &latestV1.DateTimeTagger{}}}, - {Name: "BAS", Component: latestV1.TagPolicy{InputDigest: &latestV1.InputDigest{}}}, + customTemplateTagger: &latest.CustomTemplateTagger{ + Components: []latest.TaggerComponent{ + {Name: "FOO", Component: latest.TagPolicy{GitTagger: &latest.GitTagger{}}}, + {Name: "FOE", Component: latest.TagPolicy{ShaTagger: &latest.ShaTagger{}}}, + {Name: "BAR", Component: latest.TagPolicy{EnvTemplateTagger: &latest.EnvTemplateTagger{Template: "test"}}}, + {Name: "BAT", Component: latest.TagPolicy{DateTimeTagger: &latest.DateTimeTagger{}}}, + {Name: "BAS", Component: latest.TagPolicy{InputDigest: &latest.InputDigest{}}}, }, }, expected: map[string]Tagger{ @@ -59,28 +59,28 @@ func TestCreateComponents(t *testing.T) { }, { description: "customTemplate is an invalid component", - customTemplateTagger: &latestV1.CustomTemplateTagger{ - Components: []latestV1.TaggerComponent{ - {Name: "FOO", Component: latestV1.TagPolicy{CustomTemplateTagger: &latestV1.CustomTemplateTagger{Template: "test"}}}, + customTemplateTagger: &latest.CustomTemplateTagger{ + Components: []latest.TaggerComponent{ + {Name: "FOO", Component: latest.TagPolicy{CustomTemplateTagger: &latest.CustomTemplateTagger{Template: "test"}}}, }, }, shouldErr: true, }, { description: "recurring names", - customTemplateTagger: &latestV1.CustomTemplateTagger{ - Components: []latestV1.TaggerComponent{ - {Name: "FOO", Component: latestV1.TagPolicy{GitTagger: &latestV1.GitTagger{}}}, - {Name: "FOO", Component: latestV1.TagPolicy{GitTagger: &latestV1.GitTagger{}}}, + customTemplateTagger: &latest.CustomTemplateTagger{ + Components: []latest.TaggerComponent{ + {Name: "FOO", Component: latest.TagPolicy{GitTagger: &latest.GitTagger{}}}, + {Name: "FOO", Component: latest.TagPolicy{GitTagger: &latest.GitTagger{}}}, }, }, shouldErr: true, }, { description: "unknown component", - customTemplateTagger: &latestV1.CustomTemplateTagger{ - Components: []latestV1.TaggerComponent{ - {Name: "FOO", Component: latestV1.TagPolicy{}}, + customTemplateTagger: &latest.CustomTemplateTagger{ + Components: []latest.TaggerComponent{ + {Name: "FOO", Component: latest.TagPolicy{}}, }, }, shouldErr: true, diff --git a/pkg/skaffold/tags/paths_test.go b/pkg/skaffold/tags/paths_test.go index 5f39a796dd8..15505e72ff7 100644 --- a/pkg/skaffold/tags/paths_test.go +++ b/pkg/skaffold/tags/paths_test.go @@ -22,32 +22,32 @@ package tags import ( "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) func TestSetAbsFilePaths(t *testing.T) { tests := []struct { description string - config *latestV1.SkaffoldConfig + config *latest.SkaffoldConfig base string - expected *latestV1.SkaffoldConfig + expected *latest.SkaffoldConfig }{ { description: "relative path", - config: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + config: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ {ImageName: "foo1", Workspace: "./foo"}, {ImageName: "foo2", Workspace: "/a/foo"}, }, }, - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KptDeploy: &latestV1.KptDeploy{Dir: "."}, - KubectlDeploy: &latestV1.KubectlDeploy{Manifests: []string{"foo/*", "/a/foo/*"}}, - HelmDeploy: &latestV1.HelmDeploy{Releases: []latestV1.HelmRelease{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KptDeploy: &latest.KptDeploy{Dir: "."}, + KubectlDeploy: &latest.KubectlDeploy{Manifests: []string{"foo/*", "/a/foo/*"}}, + HelmDeploy: &latest.HelmDeploy{Releases: []latest.HelmRelease{ {ChartPath: "../charts", ValuesFiles: []string{"./values1.yaml", "./values2.yaml"}, SetFiles: map[string]string{"envFile": "./values3.yaml", "configFile": "./values4.yaml", "anotherFile": "/c/values5.yaml"}}, {RemoteChart: "foo/bar", ValuesFiles: []string{"./values1.yaml", "./values2.yaml"}, SetFiles: map[string]string{"envFile": "./values3.yaml", "configFile": "./values4.yaml", "anotherFile": "/c/values5.yaml"}}, }}, @@ -56,19 +56,19 @@ func TestSetAbsFilePaths(t *testing.T) { }, }, base: "/a/b", - expected: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + expected: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ {ImageName: "foo1", Workspace: "/a/b/foo"}, {ImageName: "foo2", Workspace: "/a/foo"}, }, }, - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KptDeploy: &latestV1.KptDeploy{Dir: "/a/b"}, - KubectlDeploy: &latestV1.KubectlDeploy{Manifests: []string{"/a/b/foo/*", "/a/foo/*"}}, - HelmDeploy: &latestV1.HelmDeploy{Releases: []latestV1.HelmRelease{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KptDeploy: &latest.KptDeploy{Dir: "/a/b"}, + KubectlDeploy: &latest.KubectlDeploy{Manifests: []string{"/a/b/foo/*", "/a/foo/*"}}, + HelmDeploy: &latest.HelmDeploy{Releases: []latest.HelmRelease{ {ChartPath: "/a/charts", ValuesFiles: []string{"/a/b/values1.yaml", "/a/b/values2.yaml"}, SetFiles: map[string]string{"envFile": "/a/b/values3.yaml", "configFile": "/a/b/values4.yaml", "anotherFile": "/c/values5.yaml"}}, {RemoteChart: "foo/bar", ValuesFiles: []string{"/a/b/values1.yaml", "/a/b/values2.yaml"}, SetFiles: map[string]string{"envFile": "/a/b/values3.yaml", "configFile": "/a/b/values4.yaml", "anotherFile": "/c/values5.yaml"}}, }}, diff --git a/pkg/skaffold/tags/paths_windows_test.go b/pkg/skaffold/tags/paths_windows_test.go index 29bc0e912f9..81919d09178 100644 --- a/pkg/skaffold/tags/paths_windows_test.go +++ b/pkg/skaffold/tags/paths_windows_test.go @@ -19,32 +19,32 @@ package tags import ( "testing" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) func TestSetAbsFilePaths(t *testing.T) { tests := []struct { description string - config *latestV1.SkaffoldConfig + config *latest.SkaffoldConfig base string - expected *latestV1.SkaffoldConfig + expected *latest.SkaffoldConfig }{ { description: "relative path", - config: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + config: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ {ImageName: "foo1", Workspace: "foo"}, {ImageName: "foo2", Workspace: `C:\a\foo`}, }, }, - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KptDeploy: &latestV1.KptDeploy{Dir: "."}, - KubectlDeploy: &latestV1.KubectlDeploy{Manifests: []string{`foo\*`, `C:\a\foo\*`}}, - HelmDeploy: &latestV1.HelmDeploy{Releases: []latestV1.HelmRelease{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KptDeploy: &latest.KptDeploy{Dir: "."}, + KubectlDeploy: &latest.KubectlDeploy{Manifests: []string{`foo\*`, `C:\a\foo\*`}}, + HelmDeploy: &latest.HelmDeploy{Releases: []latest.HelmRelease{ {ChartPath: `..\charts`, ValuesFiles: []string{"values1.yaml", "values2.yaml"}, SetFiles: map[string]string{"envFile": "values3.yaml", "configFile": "values4.yaml", "anotherFile": `C:\c\values5.yaml`}}, {RemoteChart: "foo/bar", ValuesFiles: []string{"values1.yaml", "values2.yaml"}, SetFiles: map[string]string{"envFile": "values3.yaml", "configFile": "values4.yaml", "anotherFile": `C:\c\values5.yaml`}}, }}, @@ -53,19 +53,19 @@ func TestSetAbsFilePaths(t *testing.T) { }, }, base: `C:\a\b`, - expected: &latestV1.SkaffoldConfig{ - Pipeline: latestV1.Pipeline{ - Build: latestV1.BuildConfig{ - Artifacts: []*latestV1.Artifact{ + expected: &latest.SkaffoldConfig{ + Pipeline: latest.Pipeline{ + Build: latest.BuildConfig{ + Artifacts: []*latest.Artifact{ {ImageName: "foo1", Workspace: `C:\a\b\foo`}, {ImageName: "foo2", Workspace: `C:\a\foo`}, }, }, - Deploy: latestV1.DeployConfig{ - DeployType: latestV1.DeployType{ - KptDeploy: &latestV1.KptDeploy{Dir: `C:\a\b`}, - KubectlDeploy: &latestV1.KubectlDeploy{Manifests: []string{`C:\a\b\foo\*`, `C:\a\foo\*`}}, - HelmDeploy: &latestV1.HelmDeploy{Releases: []latestV1.HelmRelease{ + Deploy: latest.DeployConfig{ + DeployType: latest.DeployType{ + KptDeploy: &latest.KptDeploy{Dir: `C:\a\b`}, + KubectlDeploy: &latest.KubectlDeploy{Manifests: []string{`C:\a\b\foo\*`, `C:\a\foo\*`}}, + HelmDeploy: &latest.HelmDeploy{Releases: []latest.HelmRelease{ {ChartPath: `C:\a\charts`, ValuesFiles: []string{`C:\a\b\values1.yaml`, `C:\a\b\values2.yaml`}, SetFiles: map[string]string{"envFile": `C:\a\b\values3.yaml`, "configFile": `C:\a\b\values4.yaml`, "anotherFile": `C:\c\values5.yaml`}}, {RemoteChart: "foo/bar", ValuesFiles: []string{`C:\a\b\values1.yaml`, `C:\a\b\values2.yaml`}, SetFiles: map[string]string{"envFile": `C:\a\b\values3.yaml`, "configFile": `C:\a\b\values4.yaml`, "anotherFile": `C:\c\values5.yaml`}}, }}, diff --git a/pkg/skaffold/test/custom/custom.go b/pkg/skaffold/test/custom/custom.go index a195850fc7d..423d2ae2d2c 100644 --- a/pkg/skaffold/test/custom/custom.go +++ b/pkg/skaffold/test/custom/custom.go @@ -30,7 +30,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -43,13 +43,13 @@ const Windows string = "windows" type Runner struct { cfg docker.Config - customTest latestV1.CustomTest + customTest latest.CustomTest imageName string workspace string } // New creates a new custom.Runner. -func New(cfg docker.Config, imageName string, ws string, ct latestV1.CustomTest) (*Runner, error) { +func New(cfg docker.Config, imageName string, ws string, ct latest.CustomTest) (*Runner, error) { return &Runner{ cfg: cfg, imageName: imageName, diff --git a/pkg/skaffold/test/custom/custom_test.go b/pkg/skaffold/test/custom/custom_test.go index 9b714bffe31..e5aeffc07e4 100644 --- a/pkg/skaffold/test/custom/custom_test.go +++ b/pkg/skaffold/test/custom/custom_test.go @@ -26,7 +26,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" testEvent "github.com/GoogleContainerTools/skaffold/testutil/event" @@ -49,25 +49,25 @@ func TestNewCustomTestRunner(t *testing.T) { tmpDir := t.NewTempDir().Touch("test.yaml") - custom := latestV1.CustomTest{ + custom := latest.CustomTest{ Command: "echo Running Custom Test command.", TimeoutSeconds: 10, - Dependencies: &latestV1.CustomTestDependencies{ + Dependencies: &latest.CustomTestDependencies{ Paths: []string{"**"}, Ignore: []string{"b*"}, }, } - testCase := &latestV1.TestCase{ + testCase := &latest.TestCase{ ImageName: "image", Workspace: tmpDir.Root(), - CustomTests: []latestV1.CustomTest{custom}, + CustomTests: []latest.CustomTest{custom}, } cfg := &mockConfig{ - tests: []*latestV1.TestCase{testCase}, + tests: []*latest.TestCase{testCase}, } - testEvent.InitializeState([]latestV1.Pipeline{{}}) + testEvent.InitializeState([]latest.Pipeline{{}}) testRunner, err := New(cfg, testCase.ImageName, testCase.Workspace, custom) t.CheckNoError(err) @@ -80,7 +80,7 @@ func TestNewCustomTestRunner(t *testing.T) { func TestCustomCommandError(t *testing.T) { tests := []struct { description string - custom latestV1.CustomTest + custom latest.CustomTest shouldErr bool expectedCmd string expectedWindowsCmd string @@ -88,7 +88,7 @@ func TestCustomCommandError(t *testing.T) { }{ { description: "Non zero exit", - custom: latestV1.CustomTest{ + custom: latest.CustomTest{ Command: "exit 20", }, shouldErr: true, @@ -98,7 +98,7 @@ func TestCustomCommandError(t *testing.T) { }, { description: "Command timed out", - custom: latestV1.CustomTest{ + custom: latest.CustomTest{ Command: "sleep 20", TimeoutSeconds: 2, }, @@ -120,16 +120,16 @@ func TestCustomCommandError(t *testing.T) { return fakeLocalDaemonWithExtraEnv([]string{}), nil }) - testCase := &latestV1.TestCase{ + testCase := &latest.TestCase{ ImageName: "image", Workspace: tmpDir.Root(), - CustomTests: []latestV1.CustomTest{test.custom}, + CustomTests: []latest.CustomTest{test.custom}, } cfg := &mockConfig{ - tests: []*latestV1.TestCase{testCase}, + tests: []*latest.TestCase{testCase}, } - testEvent.InitializeState([]latestV1.Pipeline{{}}) + testEvent.InitializeState([]latest.Pipeline{{}}) testRunner, err := New(cfg, testCase.ImageName, testCase.Workspace, test.custom) t.CheckNoError(err) @@ -148,23 +148,23 @@ func TestTestDependenciesCommand(t *testing.T) { testutil.Run(t, "Testing new custom test runner", func(t *testutil.T) { tmpDir := t.NewTempDir().Touch("test.yaml") - custom := latestV1.CustomTest{ + custom := latest.CustomTest{ Command: "echo Hello!", - Dependencies: &latestV1.CustomTestDependencies{ + Dependencies: &latest.CustomTestDependencies{ Command: "echo [\"file1\",\"file2\",\"file3\"]", }, } - testCase := &latestV1.TestCase{ + testCase := &latest.TestCase{ ImageName: "image", Workspace: tmpDir.Root(), - CustomTests: []latestV1.CustomTest{custom}, + CustomTests: []latest.CustomTest{custom}, } cfg := &mockConfig{ - tests: []*latestV1.TestCase{testCase}, + tests: []*latest.TestCase{testCase}, } - testEvent.InitializeState([]latestV1.Pipeline{{}}) + testEvent.InitializeState([]latest.Pipeline{{}}) if runtime.GOOS == Windows { t.Override(&util.DefaultExecCommand, testutil.CmdRunOut( @@ -231,24 +231,24 @@ func TestTestDependenciesPaths(t *testing.T) { tmpDir := t.NewTempDir(). Touch("foo", "bar", "baz/file") - custom := latestV1.CustomTest{ + custom := latest.CustomTest{ Command: "echo Hello!", - Dependencies: &latestV1.CustomTestDependencies{ + Dependencies: &latest.CustomTestDependencies{ Paths: test.paths, Ignore: test.ignore, }, } - testCase := &latestV1.TestCase{ + testCase := &latest.TestCase{ ImageName: "image", Workspace: tmpDir.Root(), - CustomTests: []latestV1.CustomTest{custom}, + CustomTests: []latest.CustomTest{custom}, } cfg := &mockConfig{ - tests: []*latestV1.TestCase{testCase}, + tests: []*latest.TestCase{testCase}, } - testEvent.InitializeState([]latestV1.Pipeline{{}}) + testEvent.InitializeState([]latest.Pipeline{{}}) testRunner, err := New(cfg, testCase.ImageName, testCase.Workspace, custom) t.CheckNoError(err) @@ -303,20 +303,20 @@ func TestGetEnv(t *testing.T) { }) tmpDir := t.NewTempDir().Touch("test.yaml") - custom := latestV1.CustomTest{ + custom := latest.CustomTest{ Command: "echo Running Custom Test command.", } - testCase := &latestV1.TestCase{ + testCase := &latest.TestCase{ ImageName: "image", Workspace: tmpDir.Root(), - CustomTests: []latestV1.CustomTest{custom}, + CustomTests: []latest.CustomTest{custom}, } cfg := &mockConfig{ - tests: []*latestV1.TestCase{testCase}, + tests: []*latest.TestCase{testCase}, } - testEvent.InitializeState([]latestV1.Pipeline{{}}) + testEvent.InitializeState([]latest.Pipeline{{}}) testRunner, err := New(cfg, testCase.ImageName, testCase.Workspace, custom) t.CheckNoError(err) @@ -330,5 +330,5 @@ func TestGetEnv(t *testing.T) { type mockConfig struct { runcontext.RunContext // Embedded to provide the default values. - tests []*latestV1.TestCase + tests []*latest.TestCase } diff --git a/pkg/skaffold/test/structure/structure.go b/pkg/skaffold/test/structure/structure.go index c5c84faeaeb..3ece30061ed 100644 --- a/pkg/skaffold/test/structure/structure.go +++ b/pkg/skaffold/test/structure/structure.go @@ -26,7 +26,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -40,7 +40,7 @@ type Runner struct { } // New creates a new structure.Runner. -func New(ctx context.Context, cfg docker.Config, tc *latestV1.TestCase, imageIsLocal bool) (*Runner, error) { +func New(ctx context.Context, cfg docker.Config, tc *latest.TestCase, imageIsLocal bool) (*Runner, error) { localDaemon, err := docker.NewAPIClient(ctx, cfg) if err != nil { return nil, err diff --git a/pkg/skaffold/test/structure/structure_test.go b/pkg/skaffold/test/structure/structure_test.go index 4bdce3b93a9..d03a86b164d 100644 --- a/pkg/skaffold/test/structure/structure_test.go +++ b/pkg/skaffold/test/structure/structure_test.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" testEvent "github.com/GoogleContainerTools/skaffold/testutil/event" @@ -43,14 +43,14 @@ func TestNewRunner(t *testing.T) { t.Override(&util.DefaultExecCommand, testutil.CmdRun("container-structure-test test -v warn --image image:tag --config "+tmpDir.Path("test.yaml"))) - testCase := &latestV1.TestCase{ + testCase := &latest.TestCase{ ImageName: "image", Workspace: tmpDir.Root(), StructureTests: []string{"test.yaml"}, } - cfg := &mockConfig{tests: []*latestV1.TestCase{testCase}} + cfg := &mockConfig{tests: []*latest.TestCase{testCase}} - testEvent.InitializeState([]latestV1.Pipeline{{}}) + testEvent.InitializeState([]latest.Pipeline{{}}) testRunner, err := New(context.Background(), cfg, testCase, true) t.CheckNoError(err) @@ -66,12 +66,12 @@ func TestIgnoreDockerNotFound(t *testing.T) { return nil, errors.New("not found") }) - testCase := &latestV1.TestCase{ + testCase := &latest.TestCase{ ImageName: "image", Workspace: tmpDir.Root(), StructureTests: []string{"test.yaml"}, } - cfg := &mockConfig{tests: []*latestV1.TestCase{testCase}} + cfg := &mockConfig{tests: []*latest.TestCase{testCase}} testRunner, err := New(context.Background(), cfg, testCase, true) t.CheckError(true, err) @@ -111,15 +111,15 @@ func TestCustomParams(t *testing.T) { } t.Override(&util.DefaultExecCommand, testutil.CmdRun(expected)) - testCase := &latestV1.TestCase{ + testCase := &latest.TestCase{ ImageName: "image", Workspace: tmpDir.Root(), StructureTests: []string{"test.yaml"}, StructureTestArgs: tc.structureTestArgs, } - cfg := &mockConfig{tests: []*latestV1.TestCase{testCase}} + cfg := &mockConfig{tests: []*latest.TestCase{testCase}} - testEvent.InitializeState([]latestV1.Pipeline{{}}) + testEvent.InitializeState([]latest.Pipeline{{}}) testRunner, err := New(context.Background(), cfg, testCase, true) t.CheckNoError(err) @@ -131,10 +131,10 @@ func TestCustomParams(t *testing.T) { type mockConfig struct { runcontext.RunContext // Embedded to provide the default values. - tests []*latestV1.TestCase + tests []*latest.TestCase muted config.Muted } func (c *mockConfig) Muted() config.Muted { return c.muted } -func (c *mockConfig) TestCases() []*latestV1.TestCase { return c.tests } +func (c *mockConfig) TestCases() []*latest.TestCase { return c.tests } diff --git a/pkg/skaffold/test/test_factory.go b/pkg/skaffold/test/test_factory.go index 15a24e82e44..729078776ab 100644 --- a/pkg/skaffold/test/test_factory.go +++ b/pkg/skaffold/test/test_factory.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/logfile" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/test/custom" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/test/structure" ) @@ -36,7 +36,7 @@ import ( type Config interface { docker.Config - TestCases() []*latestV1.TestCase + TestCases() []*latest.TestCase Muted() config.Muted } @@ -56,7 +56,7 @@ func NewTester(ctx context.Context, cfg Config, imagesAreLocal func(imageName st } // TestDependencies returns the watch dependencies for the target artifact to the runner. -func (t FullTester) TestDependencies(ctx context.Context, artifact *latestV1.Artifact) ([]string, error) { +func (t FullTester) TestDependencies(ctx context.Context, artifact *latest.Artifact) ([]string, error) { var deps []string for _, tester := range t.Testers[artifact.ImageName] { result, err := tester.TestDependencies(ctx) @@ -123,7 +123,7 @@ func (t FullTester) runTests(ctx context.Context, out io.Writer, bRes []graph.Ar return nil } -func getImageTesters(ctx context.Context, cfg docker.Config, imagesAreLocal func(imageName string) (bool, error), tcs []*latestV1.TestCase) (ImageTesters, error) { +func getImageTesters(ctx context.Context, cfg docker.Config, imagesAreLocal func(imageName string) (bool, error), tcs []*latest.TestCase) (ImageTesters, error) { runners := make(map[string][]ImageTester) for _, tc := range tcs { isLocal, err := imagesAreLocal(tc.ImageName) diff --git a/pkg/skaffold/test/test_factory_test.go b/pkg/skaffold/test/test_factory_test.go index b164cfdd558..051b1791ca1 100644 --- a/pkg/skaffold/test/test_factory_test.go +++ b/pkg/skaffold/test/test_factory_test.go @@ -31,7 +31,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" "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/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" testEvent "github.com/GoogleContainerTools/skaffold/testutil/event" @@ -44,7 +44,7 @@ func TestNoTestDependencies(t *testing.T) { cfg := &mockConfig{} tester, err := NewTester(context.Background(), cfg, func(imageName string) (bool, error) { return true, nil }) t.CheckNoError(err) - deps, err := tester.TestDependencies(context.Background(), &latestV1.Artifact{ImageName: "foo"}) + deps, err := tester.TestDependencies(context.Background(), &latest.Artifact{ImageName: "foo"}) t.CheckNoError(err) t.CheckEmpty(deps) }) @@ -55,7 +55,7 @@ func TestTestDependencies(t *testing.T) { tmpDir := t.NewTempDir().Touch("tests/test1.yaml", "tests/test2.yaml", "test3.yaml") cfg := &mockConfig{ - tests: []*latestV1.TestCase{ + tests: []*latest.TestCase{ {StructureTests: []string{"./tests/*"}, Workspace: tmpDir.Root(), ImageName: "foo"}, {}, {StructureTests: []string{"test3.yaml"}, Workspace: tmpDir.Root(), ImageName: "foo"}, @@ -64,7 +64,7 @@ func TestTestDependencies(t *testing.T) { tester, err := NewTester(context.Background(), cfg, func(imageName string) (bool, error) { return true, nil }) t.CheckNoError(err) - deps, err := tester.TestDependencies(context.Background(), &latestV1.Artifact{ImageName: "foo"}) + deps, err := tester.TestDependencies(context.Background(), &latest.Artifact{ImageName: "foo"}) expectedDeps := tmpDir.Paths("tests/test1.yaml", "tests/test2.yaml", "test3.yaml") t.CheckNoError(err) @@ -75,7 +75,7 @@ func TestTestDependencies(t *testing.T) { func TestWrongPattern(t *testing.T) { testutil.Run(t, "", func(t *testutil.T) { cfg := &mockConfig{ - tests: []*latestV1.TestCase{{ + tests: []*latest.TestCase{{ ImageName: "image", StructureTests: []string{"[]"}, }}, @@ -84,9 +84,9 @@ func TestWrongPattern(t *testing.T) { tester, err := NewTester(context.Background(), cfg, func(imageName string) (bool, error) { return true, nil }) t.CheckNoError(err) - _, err = tester.TestDependencies(context.Background(), &latestV1.Artifact{ImageName: "image"}) + _, err = tester.TestDependencies(context.Background(), &latest.Artifact{ImageName: "image"}) t.CheckError(true, err) - testEvent.InitializeState([]latestV1.Pipeline{{}}) + testEvent.InitializeState([]latest.Pipeline{{}}) err = tester.Test(context.Background(), ioutil.Discard, []graph.Artifact{{ ImageName: "image", @@ -118,7 +118,7 @@ func TestTestSuccess(t *testing.T) { AndRun("container-structure-test test -v warn --image image:tag --config "+tmpDir.Path("test3.yaml"))) cfg := &mockConfig{ - tests: []*latestV1.TestCase{ + tests: []*latest.TestCase{ { ImageName: "image", Workspace: tmpDir.Root(), @@ -158,7 +158,7 @@ func TestTestSuccessRemoteImage(t *testing.T) { }) cfg := &mockConfig{ - tests: []*latestV1.TestCase{{ + tests: []*latest.TestCase{{ ImageName: "image", StructureTests: []string{"test.yaml"}, }}, @@ -186,7 +186,7 @@ func TestTestFailureRemoteImage(t *testing.T) { }) cfg := &mockConfig{ - tests: []*latestV1.TestCase{{ + tests: []*latest.TestCase{{ ImageName: "image", StructureTests: []string{"test.yaml"}, }}, @@ -215,7 +215,7 @@ func TestTestFailure(t *testing.T) { )) cfg := &mockConfig{ - tests: []*latestV1.TestCase{ + tests: []*latest.TestCase{ { ImageName: "broken-image", StructureTests: []string{"test.yaml"}, @@ -240,7 +240,7 @@ func TestTestMuted(t *testing.T) { t.Override(&util.DefaultExecCommand, testutil.CmdRun("container-structure-test test -v warn --image image:tag --config "+tmpDir.Path("test.yaml"))) cfg := &mockConfig{ - tests: []*latestV1.TestCase{{ + tests: []*latest.TestCase{{ ImageName: "image", Workspace: tmpDir.Root(), StructureTests: []string{"test.yaml"}, @@ -270,10 +270,10 @@ func fakeLocalDaemon(api client.CommonAPIClient) docker.LocalDaemon { type mockConfig struct { runcontext.RunContext // Embedded to provide the default values. - tests []*latestV1.TestCase + tests []*latest.TestCase muted config.Muted } func (c *mockConfig) Muted() config.Muted { return c.muted } -func (c *mockConfig) TestCases() []*latestV1.TestCase { return c.tests } +func (c *mockConfig) TestCases() []*latest.TestCase { return c.tests } diff --git a/pkg/skaffold/test/types.go b/pkg/skaffold/test/types.go index 49e827c8831..15d6371e87f 100644 --- a/pkg/skaffold/test/types.go +++ b/pkg/skaffold/test/types.go @@ -21,7 +21,7 @@ import ( "io" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) // Tester is the top level test executor in Skaffold. @@ -30,7 +30,7 @@ import ( // a single test run. type Tester interface { Test(context.Context, io.Writer, []graph.Artifact) error - TestDependencies(ctx context.Context, artifact *latestV1.Artifact) ([]string, error) + TestDependencies(ctx context.Context, artifact *latest.Artifact) ([]string, error) } type Muted interface { diff --git a/pkg/skaffold/trigger/triggers.go b/pkg/skaffold/trigger/triggers.go index 57226f8891b..ce8e2511072 100644 --- a/pkg/skaffold/trigger/triggers.go +++ b/pkg/skaffold/trigger/triggers.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" fsNotify "github.com/GoogleContainerTools/skaffold/pkg/skaffold/trigger/fsnotify" ) @@ -41,7 +41,7 @@ type Trigger interface { type Config interface { Trigger() string - Artifacts() []*latestV1.Artifact + Artifacts() []*latest.Artifact WatchPollInterval() int } diff --git a/pkg/skaffold/trigger/triggers_test.go b/pkg/skaffold/trigger/triggers_test.go index 6952ffefb53..8bc351b71eb 100644 --- a/pkg/skaffold/trigger/triggers_test.go +++ b/pkg/skaffold/trigger/triggers_test.go @@ -26,7 +26,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/rjeczalik/notify" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" fsNotify "github.com/GoogleContainerTools/skaffold/pkg/skaffold/trigger/fsnotify" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -71,7 +71,7 @@ func TestNewTrigger(t *testing.T) { cfg := &mockConfig{ trigger: test.trigger, watchPollInterval: test.watchPollInterval, - artifacts: []*latestV1.Artifact{ + artifacts: []*latest.Artifact{ {Workspace: "../workspace"}, {Workspace: "../workspace"}, {Workspace: "../some/other/workspace"}, @@ -208,9 +208,9 @@ func TestStartTrigger(t *testing.T) { type mockConfig struct { trigger string watchPollInterval int - artifacts []*latestV1.Artifact + artifacts []*latest.Artifact } -func (c *mockConfig) Trigger() string { return c.trigger } -func (c *mockConfig) WatchPollInterval() int { return c.watchPollInterval } -func (c *mockConfig) Artifacts() []*latestV1.Artifact { return c.artifacts } +func (c *mockConfig) Trigger() string { return c.trigger } +func (c *mockConfig) WatchPollInterval() int { return c.watchPollInterval } +func (c *mockConfig) Artifacts() []*latest.Artifact { return c.artifacts } diff --git a/pkg/skaffold/util/util_test.go b/pkg/skaffold/util/util_test.go index 2cb20b349dc..112175c2256 100644 --- a/pkg/skaffold/util/util_test.go +++ b/pkg/skaffold/util/util_test.go @@ -22,7 +22,7 @@ import ( "github.com/mitchellh/go-homedir" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -182,8 +182,8 @@ func TestCloneThroughJSON(t *testing.T) { old: map[string]string{ "projectId": "unit-test", }, - new: &latestV1.GoogleCloudBuild{}, - expected: &latestV1.GoogleCloudBuild{ + new: &latest.GoogleCloudBuild{}, + expected: &latest.GoogleCloudBuild{ ProjectID: "unit-test", }, }, @@ -209,8 +209,8 @@ func TestCloneThroughYAML(t *testing.T) { old: map[string]string{ "projectId": "unit-test", }, - new: &latestV1.GoogleCloudBuild{}, - expected: &latestV1.GoogleCloudBuild{ + new: &latest.GoogleCloudBuild{}, + expected: &latest.GoogleCloudBuild{ ProjectID: "unit-test", }, }, diff --git a/pkg/skaffold/version/version.go b/pkg/skaffold/version/version.go index 0d5f434de09..556c0baf0d8 100644 --- a/pkg/skaffold/version/version.go +++ b/pkg/skaffold/version/version.go @@ -23,7 +23,7 @@ import ( "github.com/blang/semver" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/user" ) @@ -48,7 +48,7 @@ var Get = func() *Info { // These variables typically come from -ldflags settings to `go build` return &Info{ Version: version, - ConfigVersion: latestV1.Version, + ConfigVersion: latest.Version, GitCommit: gitCommit, BuildDate: buildDate, GoVersion: runtime.Version(), diff --git a/pkg/skaffold/yamltags/tags.go b/pkg/skaffold/yamltags/tags.go index e24e4108023..eea66d9fd26 100644 --- a/pkg/skaffold/yamltags/tags.go +++ b/pkg/skaffold/yamltags/tags.go @@ -76,7 +76,7 @@ func GetYamlTag(value interface{}) string { } // GetYamlKeys returns the yaml key for each non-nested field of the given non-nil config parameter -// For example if config is `latestV1.DeployType{HelmDeploy: &HelmDeploy{...}, KustomizeDeploy: &KustomizeDeploy{...}}` +// For example if config is `latest.DeployType{HelmDeploy: &HelmDeploy{...}, KustomizeDeploy: &KustomizeDeploy{...}}` // then it returns `["helm", "kustomize"]` func GetYamlKeys(config interface{}) []string { var tags []string diff --git a/testutil/event/config.go b/testutil/event/config.go index ed0c28550e9..713785b8d9d 100644 --- a/testutil/event/config.go +++ b/testutil/event/config.go @@ -19,10 +19,10 @@ package event import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event" eventV2 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event/v2" - latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) -func InitializeState(pipes []latestV1.Pipeline) { +func InitializeState(pipes []latest.Pipeline) { cfg := config{ pipes: pipes, } @@ -31,12 +31,12 @@ func InitializeState(pipes []latestV1.Pipeline) { } type config struct { - pipes []latestV1.Pipeline + pipes []latest.Pipeline } -func (c config) AutoBuild() bool { return true } -func (c config) AutoDeploy() bool { return true } -func (c config) AutoSync() bool { return true } -func (c config) GetPipelines() []latestV1.Pipeline { return c.pipes } -func (c config) GetKubeContext() string { return "temp" } -func (c config) GetRunID() string { return "run-id" } +func (c config) AutoBuild() bool { return true } +func (c config) AutoDeploy() bool { return true } +func (c config) AutoSync() bool { return true } +func (c config) GetPipelines() []latest.Pipeline { return c.pipes } +func (c config) GetKubeContext() string { return "temp" } +func (c config) GetRunID() string { return "run-id" }