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

Bug 1844998: Fix --save-config for kubectl create commands, where it was missing #460

Merged
merged 2 commits into from Jul 17, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions contrib/completions/bash/oc
Expand Up @@ -8961,6 +8961,8 @@ _oc_create_build()
two_word_flags+=("--output")
two_word_flags+=("-o")
local_nonpersistent_flags+=("--output=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--source-git=")
two_word_flags+=("--source-git")
local_nonpersistent_flags+=("--source-git=")
Expand Down Expand Up @@ -9056,6 +9058,8 @@ _oc_create_clusterresourcequota()
flags+=("--project-label-selector=")
two_word_flags+=("--project-label-selector")
local_nonpersistent_flags+=("--project-label-selector=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--template=")
two_word_flags+=("--template")
flags_with_completion+=("--template")
Expand Down Expand Up @@ -9555,6 +9559,8 @@ _oc_create_deploymentconfig()
two_word_flags+=("--output")
two_word_flags+=("-o")
local_nonpersistent_flags+=("--output=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--template=")
two_word_flags+=("--template")
flags_with_completion+=("--template")
Expand Down Expand Up @@ -9627,6 +9633,8 @@ _oc_create_identity()
two_word_flags+=("--output")
two_word_flags+=("-o")
local_nonpersistent_flags+=("--output=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--template=")
two_word_flags+=("--template")
flags_with_completion+=("--template")
Expand Down Expand Up @@ -9700,6 +9708,8 @@ _oc_create_imagestream()
two_word_flags+=("--output")
two_word_flags+=("-o")
local_nonpersistent_flags+=("--output=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--template=")
two_word_flags+=("--template")
flags_with_completion+=("--template")
Expand Down Expand Up @@ -9788,6 +9798,8 @@ _oc_create_imagestreamtag()
flags+=("--reference-policy=")
two_word_flags+=("--reference-policy")
local_nonpersistent_flags+=("--reference-policy=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--scheduled")
local_nonpersistent_flags+=("--scheduled")
flags+=("--template=")
Expand Down Expand Up @@ -10466,6 +10478,8 @@ _oc_create_route_edge()
flags+=("--port=")
two_word_flags+=("--port")
local_nonpersistent_flags+=("--port=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--service=")
two_word_flags+=("--service")
local_nonpersistent_flags+=("--service=")
Expand Down Expand Up @@ -10555,6 +10569,8 @@ _oc_create_route_passthrough()
flags+=("--port=")
two_word_flags+=("--port")
local_nonpersistent_flags+=("--port=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--service=")
two_word_flags+=("--service")
local_nonpersistent_flags+=("--service=")
Expand Down Expand Up @@ -10667,6 +10683,8 @@ _oc_create_route_reencrypt()
flags+=("--port=")
two_word_flags+=("--port")
local_nonpersistent_flags+=("--port=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--service=")
two_word_flags+=("--service")
local_nonpersistent_flags+=("--service=")
Expand Down Expand Up @@ -11597,6 +11615,8 @@ _oc_create_user()
two_word_flags+=("--output")
two_word_flags+=("-o")
local_nonpersistent_flags+=("--output=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--template=")
two_word_flags+=("--template")
flags_with_completion+=("--template")
Expand Down Expand Up @@ -11668,6 +11688,8 @@ _oc_create_useridentitymapping()
two_word_flags+=("--output")
two_word_flags+=("-o")
local_nonpersistent_flags+=("--output=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--template=")
two_word_flags+=("--template")
flags_with_completion+=("--template")
Expand Down
22 changes: 22 additions & 0 deletions contrib/completions/zsh/oc
Expand Up @@ -9103,6 +9103,8 @@ _oc_create_build()
two_word_flags+=("--output")
two_word_flags+=("-o")
local_nonpersistent_flags+=("--output=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--source-git=")
two_word_flags+=("--source-git")
local_nonpersistent_flags+=("--source-git=")
Expand Down Expand Up @@ -9198,6 +9200,8 @@ _oc_create_clusterresourcequota()
flags+=("--project-label-selector=")
two_word_flags+=("--project-label-selector")
local_nonpersistent_flags+=("--project-label-selector=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--template=")
two_word_flags+=("--template")
flags_with_completion+=("--template")
Expand Down Expand Up @@ -9697,6 +9701,8 @@ _oc_create_deploymentconfig()
two_word_flags+=("--output")
two_word_flags+=("-o")
local_nonpersistent_flags+=("--output=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--template=")
two_word_flags+=("--template")
flags_with_completion+=("--template")
Expand Down Expand Up @@ -9769,6 +9775,8 @@ _oc_create_identity()
two_word_flags+=("--output")
two_word_flags+=("-o")
local_nonpersistent_flags+=("--output=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--template=")
two_word_flags+=("--template")
flags_with_completion+=("--template")
Expand Down Expand Up @@ -9842,6 +9850,8 @@ _oc_create_imagestream()
two_word_flags+=("--output")
two_word_flags+=("-o")
local_nonpersistent_flags+=("--output=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--template=")
two_word_flags+=("--template")
flags_with_completion+=("--template")
Expand Down Expand Up @@ -9930,6 +9940,8 @@ _oc_create_imagestreamtag()
flags+=("--reference-policy=")
two_word_flags+=("--reference-policy")
local_nonpersistent_flags+=("--reference-policy=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--scheduled")
local_nonpersistent_flags+=("--scheduled")
flags+=("--template=")
Expand Down Expand Up @@ -10608,6 +10620,8 @@ _oc_create_route_edge()
flags+=("--port=")
two_word_flags+=("--port")
local_nonpersistent_flags+=("--port=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--service=")
two_word_flags+=("--service")
local_nonpersistent_flags+=("--service=")
Expand Down Expand Up @@ -10697,6 +10711,8 @@ _oc_create_route_passthrough()
flags+=("--port=")
two_word_flags+=("--port")
local_nonpersistent_flags+=("--port=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--service=")
two_word_flags+=("--service")
local_nonpersistent_flags+=("--service=")
Expand Down Expand Up @@ -10809,6 +10825,8 @@ _oc_create_route_reencrypt()
flags+=("--port=")
two_word_flags+=("--port")
local_nonpersistent_flags+=("--port=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--service=")
two_word_flags+=("--service")
local_nonpersistent_flags+=("--service=")
Expand Down Expand Up @@ -11739,6 +11757,8 @@ _oc_create_user()
two_word_flags+=("--output")
two_word_flags+=("-o")
local_nonpersistent_flags+=("--output=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--template=")
two_word_flags+=("--template")
flags_with_completion+=("--template")
Expand Down Expand Up @@ -11810,6 +11830,8 @@ _oc_create_useridentitymapping()
two_word_flags+=("--output")
two_word_flags+=("-o")
local_nonpersistent_flags+=("--output=")
flags+=("--save-config")
local_nonpersistent_flags+=("--save-config")
flags+=("--template=")
two_word_flags+=("--template")
flags_with_completion+=("--template")
Expand Down
20 changes: 12 additions & 8 deletions pkg/cli/create/build.go
Expand Up @@ -11,6 +11,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme"
"k8s.io/kubectl/pkg/util"
"k8s.io/kubectl/pkg/util/templates"

buildv1 "github.com/openshift/api/build/v1"
Expand All @@ -19,8 +21,6 @@ import (
"github.com/openshift/oc/pkg/helpers/env"
)

const BuildRecommendedName = "build"

var (
buildLong = templates.LongDesc(`
Create a new build
Expand All @@ -31,7 +31,7 @@ var (

buildExample = templates.Examples(`
# Create a new build
%[1]s myapp`)
oc create build myapp`)
)

type CreateBuildOptions struct {
Expand All @@ -54,15 +54,15 @@ type CreateBuildOptions struct {
}

// NewCmdCreateBuild is a macro command to create a new build stream
func NewCmdCreateBuild(name, fullName string, f genericclioptions.RESTClientGetter, streams genericclioptions.IOStreams) *cobra.Command {
func NewCmdCreateBuild(f genericclioptions.RESTClientGetter, streams genericclioptions.IOStreams) *cobra.Command {
o := &CreateBuildOptions{
CreateSubcommandOptions: NewCreateSubcommandOptions(streams),
}
cmd := &cobra.Command{
Use: name + " NAME",
Use: "build NAME",
Short: "Create a new build",
Long: buildLong,
Example: fmt.Sprintf(buildExample, fullName),
Example: buildExample,
Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(o.Complete(cmd, f, args))
cmdutil.CheckErr(o.Run())
Expand All @@ -81,7 +81,7 @@ func NewCmdCreateBuild(name, fullName string, f genericclioptions.RESTClientGett
cmd.Flags().IntVar(&o.BuildLoglevel, "build-loglevel", o.BuildLoglevel, "Set the log level for builds (0-10, 0 default).")
cmd.Flags().StringArrayVar(&o.Env, "env", o.Env, "Add enviroment variables to the build strategy.")

o.CreateSubcommandOptions.PrintFlags.AddFlags(cmd)
o.CreateSubcommandOptions.AddFlags(cmd)
cmdutil.AddDryRunFlag(cmd)

return cmd
Expand Down Expand Up @@ -212,7 +212,11 @@ func (o *CreateBuildOptions) Run() error {
}
}

if o.CreateSubcommandOptions.DryRunStrategy == cmdutil.DryRunNone {
if err := util.CreateOrUpdateAnnotation(o.CreateSubcommandOptions.CreateAnnotation, build, scheme.DefaultJSONEncoder()); err != nil {
return err
}

if o.CreateSubcommandOptions.DryRunStrategy != cmdutil.DryRunClient {
var err error
build, err = o.Client.Builds(o.CreateSubcommandOptions.Namespace).Create(context.TODO(), build, metav1.CreateOptions{})
if err != nil {
Expand Down
18 changes: 11 additions & 7 deletions pkg/cli/create/clusterquota.go
Expand Up @@ -13,14 +13,14 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme"
"k8s.io/kubectl/pkg/util"
"k8s.io/kubectl/pkg/util/templates"

quotav1 "github.com/openshift/api/quota/v1"
quotav1client "github.com/openshift/client-go/quota/clientset/versioned/typed/quota/v1"
)

const ClusterQuotaRecommendedName = "clusterresourcequota"

var (
clusterQuotaLong = templates.LongDesc(`
Create a cluster resource quota that controls certain resources.
Expand All @@ -29,7 +29,7 @@ var (

clusterQuotaExample = templates.Examples(`
# Create a cluster resource quota limited to 10 pods
%[1]s limit-bob --project-annotation-selector=openshift.io/requester=user-bob --hard=pods=10`)
oc create clusterresourcequota limit-bob --project-annotation-selector=openshift.io/requester=user-bob --hard=pods=10`)
)

type CreateClusterQuotaOptions struct {
Expand All @@ -52,13 +52,13 @@ func NewCreateClusterQuotaOptions(streams genericclioptions.IOStreams) *CreateCl
}

// NewCmdCreateClusterQuota is a macro command to create a new cluster quota.
func NewCmdCreateClusterQuota(name, fullName string, f genericclioptions.RESTClientGetter, streams genericclioptions.IOStreams) *cobra.Command {
func NewCmdCreateClusterQuota(f genericclioptions.RESTClientGetter, streams genericclioptions.IOStreams) *cobra.Command {
o := NewCreateClusterQuotaOptions(streams)
cmd := &cobra.Command{
Use: name + " NAME --project-label-selector=key=value [--hard=RESOURCE=QUANTITY]...",
Use: "clusterresourcequota NAME --project-label-selector=key=value [--hard=RESOURCE=QUANTITY]...",
Short: "Create cluster resource quota resource.",
Long: clusterQuotaLong,
Example: fmt.Sprintf(clusterQuotaExample, fullName),
Example: clusterQuotaExample,
Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(o.Complete(cmd, f, args))
cmdutil.CheckErr(o.Run())
Expand All @@ -69,7 +69,7 @@ func NewCmdCreateClusterQuota(name, fullName string, f genericclioptions.RESTCli
cmd.Flags().StringVar(&o.AnnotationSelectorStr, "project-annotation-selector", o.AnnotationSelectorStr, "The project annotation selector for the cluster resource quota")
cmd.Flags().StringSliceVar(&o.Hard, "hard", o.Hard, "The resource to constrain: RESOURCE=QUANTITY (pods=10)")

o.CreateSubcommandOptions.PrintFlags.AddFlags(cmd)
o.CreateSubcommandOptions.AddFlags(cmd)
cmdutil.AddDryRunFlag(cmd)

return cmd
Expand Down Expand Up @@ -129,6 +129,10 @@ func (o *CreateClusterQuotaOptions) Run() error {
clusterQuota.Spec.Quota.Hard[corev1.ResourceName(tokens[0])] = quantity
}

if err := util.CreateOrUpdateAnnotation(o.CreateSubcommandOptions.CreateAnnotation, clusterQuota, scheme.DefaultJSONEncoder()); err != nil {
return err
}

if o.CreateSubcommandOptions.DryRunStrategy != cmdutil.DryRunClient {
var err error
clusterQuota, err = o.Client.ClusterResourceQuotas().Create(context.TODO(), clusterQuota, metav1.CreateOptions{})
Expand Down
10 changes: 8 additions & 2 deletions pkg/cli/create/create.go
Expand Up @@ -16,8 +16,9 @@ type CreateSubcommandOptions struct {
// PrintFlags holds options necessary for obtaining a printer
PrintFlags *genericclioptions.PrintFlags
// Name of resource being created
Name string
DryRunStrategy cmdutil.DryRunStrategy
Name string
DryRunStrategy cmdutil.DryRunStrategy
CreateAnnotation bool

Namespace string
EnforceNamespace bool
Expand All @@ -32,6 +33,11 @@ func NewCreateSubcommandOptions(ioStreams genericclioptions.IOStreams) *CreateSu
}
}

func (o *CreateSubcommandOptions) AddFlags(cmd *cobra.Command) {
o.PrintFlags.AddFlags(cmd)
cmdutil.AddApplyAnnotationVarFlags(cmd, &o.CreateAnnotation)
}

func (o *CreateSubcommandOptions) Complete(f genericclioptions.RESTClientGetter, cmd *cobra.Command, args []string) error {
name, err := NameFromCommandArgs(cmd, args)
if err != nil {
Expand Down