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

add command skaffold inspect build-env modify googleCloudBuild #5935

Merged
merged 3 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cmd/skaffold/app/cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import (
)

var inspectFlags = struct {
fileName string
filename string
outFormat string
modules []string
buildEnv string
profiles []string
strict bool
}{
fileName: "skaffold.yaml",
filename: "skaffold.yaml",
strict: true,
}

func NewCmdInspect() *cobra.Command {
Expand All @@ -40,6 +42,6 @@ func NewCmdInspect() *cobra.Command {
}

func cmdInspectFlags(f *pflag.FlagSet) {
f.StringVarP(&inspectFlags.fileName, "filename", "f", "skaffold.yaml", "Path to the local Skaffold config file. Defaults to `skaffold.yaml`")
f.StringVarP(&inspectFlags.filename, "filename", "f", "skaffold.yaml", "Path to the local Skaffold config file. Defaults to `skaffold.yaml`")
f.StringVarP(&inspectFlags.outFormat, "format", "o", "json", "Output format. One of: json(default)")
}
65 changes: 47 additions & 18 deletions cmd/skaffold/app/cmd/inspect_build_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func cmdBuildEnv() *cobra.Command {
return NewCmd("build-env").
WithDescription("Interact with skaffold build environment definitions.").
WithPersistentFlagAdder(cmdBuildEnvFlags).
WithCommands(cmdBuildEnvList(), cmdBuildEnvAdd())
WithCommands(cmdBuildEnvList(), cmdBuildEnvAdd(), cmdBuildEnvModify())
}

func cmdBuildEnvList() *cobra.Command {
Expand All @@ -84,24 +84,31 @@ func cmdBuildEnvAdd() *cobra.Command {
WithCommands(cmdBuildEnvAddLocal(), cmdBuildEnvAddGcb(), cmdBuildEnvAddCluster())
}

func cmdBuildEnvModify() *cobra.Command {
return NewCmd("modify").
WithDescription("Modify the build environment for the default pipeline or an existing profile.").
WithPersistentFlagAdder(cmdBuildEnvModifyFlags).
WithCommands(cmdBuildEnvModifyGcb())
}

func cmdBuildEnvAddGcb() *cobra.Command {
return NewCmd("googleCloudBuild").
WithDescription("Add a new GoogleCloudBuild build environment definition").
WithLongDescription(`Add a new GoogleCloudBuild build environment definition.
WithDescription("Add a new 'googleCloudBuild' build environment definition").
WithLongDescription(`Add a new 'googleCloudBuild' build environment definition.
Without the '--profile' flag the new environment definition is added to the default pipeline. With the '--profile' flag it will create a new profile with this build env definition.
In these respective scenarios, it will fail if the build env definition for the default pipeline or the named profile already exists. To override an existing definition use 'skaffold inspect build-env modify' command instead.
In these respective scenarios, it will fail if the build env definition for the default pipeline or the named profile already exists. To override an existing 'googleCloudBuild' definition use 'skaffold inspect build-env modify' command instead.
Use the '--module' filter to specify the individual module to target. Otherwise, it'll be applied to all modules defined in the target file. Also, with the '--profile' flag if the target config imports other configs as dependencies, then the new profile will be recursively created in all the imported configs also.`).
WithExample("Add a new profile named 'gcb' targeting the builder 'googleCloudBuild' against the GCP project ID '1234'.", "inspect build-env add googleCloudBuild --profile gcb --projectID 1234 -f skaffold.yaml").
WithFlagAdder(cmdBuildEnvAddGcbFlags).
WithFlagAdder(cmdBuildEnvGcbFlags).
NoArgs(addGcbBuildEnv)
}

func cmdBuildEnvAddLocal() *cobra.Command {
return NewCmd("local").
WithDescription("Add a new Local build environment definition").
WithLongDescription(`Add a new Local build environment definition.
WithDescription("Add a new 'local' build environment definition").
WithLongDescription(`Add a new 'local' build environment definition.
Without the '--profile' flag the new environment definition is added to the default pipeline. With the '--profile' flag it will create a new profile with this build env definition.
In these respective scenarios, it will fail if the build env definition for the default pipeline or the named profile already exists. To override an existing definition use 'skaffold inspect build-env modify' command instead.
In these respective scenarios, it will fail if the build env definition for the default pipeline or the named profile already exists. To override an existing 'local' build env definition use 'skaffold inspect build-env modify' command instead.
Use the '--module' filter to specify the individual module to target. Otherwise, it'll be applied to all modules defined in the target file. Also, with the '--profile' flag if the target config imports other configs as dependencies, then the new profile will be recursively created in all the imported configs also.`).
WithExample("Add a new profile named 'local' targeting the local build environment with option to push images and using buildkit", "inspect build-env add local --profile local --push true --useBuildkit true -f skaffold.yaml").
WithFlagAdder(cmdBuildEnvLocalFlags).
Expand All @@ -110,16 +117,28 @@ Use the '--module' filter to specify the individual module to target. Otherwise,

func cmdBuildEnvAddCluster() *cobra.Command {
return NewCmd("cluster").
WithDescription("Add a new Cluster build environment definition").
WithLongDescription(`Add a new Cluster build environment definition.
WithDescription("Add a new 'cluster' build environment definition").
WithLongDescription(`Add a new 'cluster' build environment definition.
Without the '--profile' flag the new environment definition is added to the default pipeline. With the '--profile' flag it will create a new profile with this build env definition.
In these respective scenarios, it will fail if the build env definition for the default pipeline or the named profile already exists. To override an existing definition use 'skaffold inspect build-env modify' command instead.
In these respective scenarios, it will fail if the build env definition for the default pipeline or the named profile already exists. To override an existing 'cluster' build env definition use 'skaffold inspect build-env modify' command instead.
Use the '--module' filter to specify the individual module to target. Otherwise, it'll be applied to all modules defined in the target file. Also, with the '--profile' flag if the target config imports other configs as dependencies, then the new profile will be recursively created in all the imported configs also.`).
WithExample("Add a new profile named 'cluster' targeting the builder 'kaniko' using the Kubernetes secret 'my-secret'", "inspect build-env add cluster --profile cluster --pullSecretName my-secret -f skaffold.yaml").
WithFlagAdder(cmdBuildEnvAddClusterFlags).
NoArgs(addClusterBuildEnv)
}

func cmdBuildEnvModifyGcb() *cobra.Command {
return NewCmd("googleCloudBuild").
WithDescription("Modify an existing GoogleCloudBuild build environment definition").
WithLongDescription(`Modify an existing GoogleCloudBuild build environment definition.
Without the '--profile' flag, the default pipeline's build environment definition is modified. With the '--profile' flag it'll modify the build environment definition for all profile pipelines that match the given profile name.
In these respective scenarios, it will fail if the build env definition for the default pipeline or the named profile is not GoogleCloudBuild. To create a new build environment definition use 'skaffold inspect build-env add' command instead.
Use the '--module' filter to specify the individual module to target. Otherwise, it'll be applied to all modules defined in the target file. Also, with the '--profile' flag if the target config imports other configs as dependencies, then it'll modify profiles that match the given name in all imported configs`).
WithExample("Modify an existing profile named 'gcb' targeting the builder 'googleCloudBuild' against the GCP project ID '1234'.", "inspect build-env modify googleCloudBuild --profile gcb --projectID 1234 -f skaffold.yaml").
WithFlagAdder(cmdBuildEnvGcbFlags).
NoArgs(modifyGcbBuildEnv)
}

func listBuildEnv(ctx context.Context, out io.Writer) error {
return buildEnv.PrintBuildEnvsList(ctx, out, printBuildEnvsListOptions())
}
Expand All @@ -129,7 +148,11 @@ func addLocalBuildEnv(ctx context.Context, out io.Writer) error {
}

func addGcbBuildEnv(ctx context.Context, out io.Writer) error {
return buildEnv.AddGcbBuildEnv(ctx, out, addGcbBuildEnvOptions())
return buildEnv.AddGcbBuildEnv(ctx, out, gcbBuildEnvOptions())
}

func modifyGcbBuildEnv(ctx context.Context, out io.Writer) error {
return buildEnv.ModifyGcbBuildEnv(ctx, out, gcbBuildEnvOptions())
}

func addClusterBuildEnv(ctx context.Context, out io.Writer) error {
Expand All @@ -154,7 +177,12 @@ func cmdBuildEnvLocalFlags(f *pflag.FlagSet) {
}
}

func cmdBuildEnvAddGcbFlags(f *pflag.FlagSet) {
func cmdBuildEnvModifyFlags(f *pflag.FlagSet) {
f.StringVarP(&buildEnvFlags.profile, "profile", "p", "", `If specified then the modify actions are performed on all pipelines from profiles that match flag value. It must match at least one existing profile name. If unspecified then only the default pipeline in the target 'skaffold.yaml' file are modified`)
f.BoolVar(&inspectFlags.strict, "strict", true, "If set to 'false' then do not fail on mismatch of build env type or missing definitions. If set to 'true' then all default pipelines or those matching the `--profile` flag need to match the build env type exactly. Defaults to 'true'")
}

func cmdBuildEnvGcbFlags(f *pflag.FlagSet) {
f.StringVar(&buildEnvFlags.projectID, "projectId", "", `ID of the Cloud Platform Project.`)
f.Int64Var(&buildEnvFlags.diskSizeGb, "diskSizeGb", 0, `Disk size of the VM that runs the build`)
f.StringVar(&buildEnvFlags.machineType, "machineType", "", `Type of VM that runs the build`)
Expand Down Expand Up @@ -191,7 +219,7 @@ func cmdBuildEnvListFlags(f *pflag.FlagSet) {

func printBuildEnvsListOptions() inspect.Options {
return inspect.Options{
Filename: inspectFlags.fileName,
Filename: inspectFlags.filename,
OutFormat: inspectFlags.outFormat,
Modules: inspectFlags.modules,
BuildEnvOptions: inspect.BuildEnvOptions{
Expand All @@ -202,7 +230,7 @@ func printBuildEnvsListOptions() inspect.Options {

func localBuildEnvOptions() inspect.Options {
return inspect.Options{
Filename: inspectFlags.fileName,
Filename: inspectFlags.filename,
OutFormat: inspectFlags.outFormat,
Modules: inspectFlags.modules,
BuildEnvOptions: inspect.BuildEnvOptions{
Expand All @@ -216,9 +244,9 @@ func localBuildEnvOptions() inspect.Options {
}
}

func addGcbBuildEnvOptions() inspect.Options {
func gcbBuildEnvOptions() inspect.Options {
return inspect.Options{
Filename: inspectFlags.fileName,
Filename: inspectFlags.filename,
OutFormat: inspectFlags.outFormat,
Modules: inspectFlags.modules,
BuildEnvOptions: inspect.BuildEnvOptions{
Expand All @@ -229,12 +257,13 @@ func addGcbBuildEnvOptions() inspect.Options {
Timeout: buildEnvFlags.timeout,
Concurrency: buildEnvFlags.concurrency,
},
Strict: inspectFlags.strict,
}
}

func addClusterBuildEnvOptions() inspect.Options {
return inspect.Options{
Filename: inspectFlags.fileName,
Filename: inspectFlags.filename,
OutFormat: inspectFlags.outFormat,
Modules: inspectFlags.modules,
BuildEnvOptions: inspect.BuildEnvOptions{
Expand Down
2 changes: 1 addition & 1 deletion cmd/skaffold/app/cmd/inspect_modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ func cmdModulesList() *cobra.Command {
}

func listModules(ctx context.Context, out io.Writer) error {
return modules.PrintModulesList(ctx, out, inspect.Options{Filename: inspectFlags.fileName, OutFormat: inspectFlags.outFormat})
return modules.PrintModulesList(ctx, out, inspect.Options{Filename: inspectFlags.filename, OutFormat: inspectFlags.outFormat})
}
2 changes: 1 addition & 1 deletion cmd/skaffold/app/cmd/inspect_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func cmdProfilesList() *cobra.Command {
}

func listProfiles(ctx context.Context, out io.Writer) error {
return profiles.PrintProfilesList(ctx, out, inspect.Options{Filename: inspectFlags.fileName, OutFormat: inspectFlags.outFormat, Modules: inspectFlags.modules, ProfilesOptions: inspect.ProfilesOptions{BuildEnv: inspect.BuildEnv(inspectFlags.buildEnv)}})
return profiles.PrintProfilesList(ctx, out, inspect.Options{Filename: inspectFlags.filename, OutFormat: inspectFlags.outFormat, Modules: inspectFlags.modules, ProfilesOptions: inspect.ProfilesOptions{BuildEnv: inspect.BuildEnv(inspectFlags.buildEnv)}})
}

func cmdProfilesFlags(f *pflag.FlagSet) {
Expand Down
Loading