Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a hidden flag for simpler access to new init format #3660

Merged
merged 2 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/skaffold/app/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
analyze bool
enableJibInit bool
enableBuildpacksInit bool
enableNewInitFormat bool
buildpacksBuilder string
)

Expand All @@ -56,6 +57,8 @@ func NewCmdInit() *cobra.Command {
f.StringArrayVarP(&cliArtifacts, "artifact", "a", nil, "'='-delimited Dockerfile/image pair, or JSON string, to generate build artifact\n(example: --artifact='{\"builder\":\"Docker\",\"payload\":{\"path\":\"/web/Dockerfile.web\"},\"image\":\"gcr.io/web-project/image\"}')")
f.StringArrayVarP(&cliKubernetesManifests, "kubernetes-manifest", "k", nil, "a path or a glob pattern to kubernetes manifests (can be non-existent) to be added to the kubectl deployer (overrides detection of kubernetes manifests). Repeat the flag for multiple entries. E.g.: skaffold init -k pod.yaml -k k8s/*.yml")
f.BoolVar(&analyze, "analyze", false, "Print all discoverable Dockerfiles and images in JSON format to stdout")
f.BoolVar(&enableNewInitFormat, "XXenableNewInitFormat", false, "")
f.MarkHidden("XXenableNewInitFormat")
f.BoolVar(&enableJibInit, "XXenableJibInit", false, "")
f.MarkHidden("XXenableJibInit")
f.BoolVar(&enableBuildpacksInit, "XXenableBuildpacksInit", false, "")
Expand All @@ -77,6 +80,7 @@ func doInit(ctx context.Context, out io.Writer) error {
Analyze: analyze,
EnableJibInit: enableJibInit,
EnableBuildpacksInit: enableBuildpacksInit,
EnableNewInitFormat: enableNewInitFormat || enableBuildpacksInit || enableJibInit,
BuildpacksBuilder: buildpacksBuilder,
Opts: opts,
})
Expand Down
47 changes: 47 additions & 0 deletions cmd/skaffold/app/cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ func TestFlagsToConfigVersion(t *testing.T) {
Analyze: false,
EnableJibInit: false,
EnableBuildpacksInit: false,
EnableNewInitFormat: false,
BuildpacksBuilder: "heroku/buildpacks",
Opts: opts,
},
},

{
name: "no error + non-default values for flags mapped to config values",
args: []string{
Expand All @@ -70,6 +72,7 @@ func TestFlagsToConfigVersion(t *testing.T) {
"--analyze",
"--XXenableJibInit",
"--XXenableBuildpacksInit",
"--XXenableNewInitFormat",
"--XXdefaultBuildpacksBuilder", "buildpacks/builder",
},
expectedConfig: initializer.Config{
Expand All @@ -82,10 +85,54 @@ func TestFlagsToConfigVersion(t *testing.T) {
Analyze: true,
EnableJibInit: true,
EnableBuildpacksInit: true,
EnableNewInitFormat: true,
BuildpacksBuilder: "buildpacks/builder",
Opts: opts,
},
},

{
name: "enableJibInit implies enableNewInitFormat",
args: []string{
"init",
"--XXenableJibInit",
},
expectedConfig: initializer.Config{
ComposeFile: "",
CliArtifacts: nil,
CliKubernetesManifests: nil,
SkipBuild: false,
SkipDeploy: false,
Force: false,
Analyze: false,
EnableJibInit: true,
EnableBuildpacksInit: false,
EnableNewInitFormat: true,
BuildpacksBuilder: "heroku/buildpacks",
Opts: opts,
},
},
{
name: "enableBuildpackInit implies enableNewInitFormat",
args: []string{
"init",
"--XXenableBuildpacksInit",
},
expectedConfig: initializer.Config{
ComposeFile: "",
CliArtifacts: nil,
CliKubernetesManifests: nil,
SkipBuild: false,
SkipDeploy: false,
Force: false,
Analyze: false,
EnableJibInit: false,
EnableBuildpacksInit: true,
EnableNewInitFormat: true,
BuildpacksBuilder: "heroku/buildpacks",
Opts: opts,
},
},
}
for _, test := range tests {
testutil.Run(t, test.name, func(t *testutil.T) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/skaffold/initializer/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Config struct {
EnableBuildpacksInit bool
BuildpacksBuilder string
Opts config.SkaffoldOptions
EnableNewInitFormat bool
Copy link
Contributor

@jonjohnsonjr jonjohnsonjr Feb 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pkg/skaffold/initializer/init.go:54:13: struct of size 400 bytes could be of size 392 bytes (maligned)
type Config struct {

This linter is pedantic! I love it! You can save 4 bytes by moving this up with the other bools.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, right, this always gets me

}

// builderImagePair defines a builder and the image it builds
Expand Down Expand Up @@ -109,8 +110,8 @@ func DoInit(ctx context.Context, out io.Writer, c Config) error {

if c.Analyze {
// TODO: Remove backwards compatibility block
if !c.EnableJibInit && !c.EnableBuildpacksInit {
return printAnalyzeJSONNoJib(out, c.SkipBuild, pairs, unresolvedBuilderConfigs, unresolvedImages)
if !c.EnableNewInitFormat {
return printAnalyzeOldFormat(out, c.SkipBuild, pairs, unresolvedBuilderConfigs, unresolvedImages)
}

return printAnalyzeJSON(out, c.SkipBuild, pairs, unresolvedBuilderConfigs, unresolvedImages)
Expand Down
4 changes: 2 additions & 2 deletions pkg/skaffold/initializer/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ func TestDoInitAnalyze(t *testing.T) {
name: "analyze microservices new format",
dir: "testdata/init/microservices",
config: Config{
Analyze: true,
EnableJibInit: true,
Analyze: true,
EnableNewInitFormat: true,
},
expectedOut: strip(`{
"builders":[
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/initializer/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
)

func printAnalyzeJSONNoJib(out io.Writer, skipBuild bool, pairs []builderImagePair, unresolvedBuilders []InitBuilder, unresolvedImages []string) error {
func printAnalyzeOldFormat(out io.Writer, skipBuild bool, pairs []builderImagePair, unresolvedBuilders []InitBuilder, unresolvedImages []string) error {
if !skipBuild && len(unresolvedBuilders) == 0 {
return errors.New("one or more valid Dockerfiles must be present to build images with skaffold; please provide at least one Dockerfile and try again, or run `skaffold init --skip-build`")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/initializer/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestPrintAnalyzeJSONNoJib(t *testing.T) {
testutil.Run(t, test.description, func(t *testutil.T) {
var out bytes.Buffer

err := printAnalyzeJSONNoJib(&out, test.skipBuild, test.pairs, test.builders, test.images)
err := printAnalyzeOldFormat(&out, test.skipBuild, test.pairs, test.builders, test.images)

t.CheckErrorAndDeepEqual(test.shouldErr, err, test.expected, out.String())
})
Expand Down