diff --git a/saectl/internal/cmd/apply/apply.go b/saectl/internal/cmd/apply/apply.go index 69e6f8e..056b926 100644 --- a/saectl/internal/cmd/apply/apply.go +++ b/saectl/internal/cmd/apply/apply.go @@ -136,8 +136,8 @@ var ( # Apply the configuration from all files that end with '.json' - i.e. expand wildcard characters in file names saectl apply -f '*.json'`)) - warningNoLastAppliedConfigAnnotation = "Warning: resource %[1]s is missing the %[2]s annotation which is required by %[3]s apply. %[3]s apply should only be used on resources created declaratively by either %[3]s create --save-config or %[3]s apply. The missing annotation will be patched automatically.\n" - warningChangesOnDeletingResource = "Warning: Detected changes to resource %[1]s which is currently being deleted.\n" + //warningNoLastAppliedConfigAnnotation = "Warning: resource %[1]s is missing the %[2]s annotation which is required by %[3]s apply. %[3]s apply should only be used on resources created declaratively by either %[3]s create --save-config or %[3]s apply. The missing annotation will be patched automatically.\n" + warningChangesOnDeletingResource = "Warning: Detected changes to resource %[1]s which is currently being deleted.\n" ) // NewApplyFlags returns a default ApplyFlags @@ -175,11 +175,6 @@ func NewCmdApply(baseName string, f cmdutil.Factory, ioStreams genericclioptions flags.AddFlags(cmd) - // apply subcommands - //cmd.AddCommand(NewCmdApplyViewLastApplied(flags.Factory, flags.IOStreams)) - //cmd.AddCommand(NewCmdApplySetLastApplied(flags.Factory, flags.IOStreams)) - //cmd.AddCommand(NewCmdApplyEditLastApplied(flags.Factory, flags.IOStreams)) - return cmd } @@ -187,19 +182,13 @@ func NewCmdApply(baseName string, f cmdutil.Factory, ioStreams genericclioptions func (flags *ApplyFlags) AddFlags(cmd *cobra.Command) { // bind flag structs flags.DeleteFlags.AddFlags(cmd) - //flags.RecordFlags.AddFlags(cmd) flags.PrintFlags.AddFlags(cmd) - //cmdutil.AddValidateFlags(cmd) - //cmdutil.AddDryRunFlag(cmd) - //cmdutil.AddServerSideApplyFlags(cmd) - //cmdutil.AddFieldManagerFlagVar(cmd, &flags.FieldManager, FieldManagerClientSideApply) + cmdutil.AddDryRunFlag(cmd) cmdutil.AddLabelSelectorFlagVar(cmd, &flags.Selector) cmd.Flags().BoolVar(&flags.Overwrite, "overwrite", flags.Overwrite, "Automatically resolve conflicts between the modified and live configuration by using values from the modified configuration") - //cmd.Flags().BoolVar(&flags.Prune, "prune", flags.Prune, "Automatically delete resource objects, that do not appear in the configs and are created by either apply or create --save-config. Should be used with either -l or --all.") cmd.Flags().BoolVar(&flags.All, "all", flags.All, "Select all resources in the namespace of the specified resource types.") - //cmd.Flags().StringArrayVar(&flags.PruneWhitelist, "prune-whitelist", flags.PruneWhitelist, "Overwrite the default whitelist with for --prune") cmd.Flags().BoolVar(&flags.OpenAPIPatch, "openapi-patch", flags.OpenAPIPatch, "If true, use openapi to calculate diff when the openapi presents and the resource can be found in the openapi spec. Otherwise, fall back to use baked-in types.") } @@ -209,8 +198,6 @@ func (flags *ApplyFlags) ToOptions(cmd *cobra.Command, baseName string, args []s return nil, cmdutil.UsageErrorf(cmd, "Unexpected args: %v", args) } - serverSideApply := cmdutil.GetServerSideApplyFlag(cmd) - forceConflicts := cmdutil.GetForceConflictsFlag(cmd) dryRunStrategy, err := cmdutil.GetDryRunStrategy(cmd) if err != nil { return nil, err @@ -222,8 +209,6 @@ func (flags *ApplyFlags) ToOptions(cmd *cobra.Command, baseName string, args []s } dryRunVerifier := resource.NewQueryParamVerifier(dynamicClient, flags.Factory.OpenAPIGetter(), resource.QueryParamDryRun) - fieldValidationVerifier := resource.NewQueryParamVerifier(dynamicClient, flags.Factory.OpenAPIGetter(), resource.QueryParamFieldValidation) - fieldManager := GetApplyFieldManagerFlag(cmd, serverSideApply) // allow for a success message operation to be specified at print time toPrinter := func(operation string) (printers.ResourcePrinter, error) { @@ -250,14 +235,6 @@ func (flags *ApplyFlags) ToOptions(cmd *cobra.Command, baseName string, args []s openAPISchema, _ := flags.Factory.OpenAPISchema() - validationDirective, err := cmdutil.GetValidationDirective(cmd) - if err != nil { - return nil, err - } - validator, err := flags.Factory.Validator(validationDirective, fieldValidationVerifier) - if err != nil { - return nil, err - } builder := flags.Factory.NewBuilder() mapper, err := flags.Factory.ToRESTMapper() if err != nil { @@ -269,13 +246,6 @@ func (flags *ApplyFlags) ToOptions(cmd *cobra.Command, baseName string, args []s return nil, err } - if flags.Prune { - flags.PruneResources, err = prune.ParseResources(mapper, flags.PruneWhitelist) - if err != nil { - return nil, err - } - } - o := &ApplyOptions{ // Store baseName for use in printing warnings / messages involving the base command name. // This is useful for downstream command that wrap this one. @@ -283,30 +253,24 @@ func (flags *ApplyFlags) ToOptions(cmd *cobra.Command, baseName string, args []s PrintFlags: flags.PrintFlags, - DeleteOptions: deleteOptions, - ToPrinter: toPrinter, - ServerSideApply: serverSideApply, - ForceConflicts: forceConflicts, - FieldManager: fieldManager, - Selector: flags.Selector, - DryRunStrategy: dryRunStrategy, - DryRunVerifier: dryRunVerifier, - Prune: flags.Prune, - PruneResources: flags.PruneResources, - All: flags.All, - Overwrite: flags.Overwrite, - OpenAPIPatch: flags.OpenAPIPatch, - PruneWhitelist: flags.PruneWhitelist, - - Recorder: recorder, - Namespace: namespace, - EnforceNamespace: enforceNamespace, - Validator: validator, - ValidationDirective: validationDirective, - Builder: builder, - Mapper: mapper, - DynamicClient: dynamicClient, - OpenAPISchema: openAPISchema, + DeleteOptions: deleteOptions, + ToPrinter: toPrinter, + Selector: flags.Selector, + DryRunStrategy: dryRunStrategy, + DryRunVerifier: dryRunVerifier, + + All: flags.All, + Overwrite: flags.Overwrite, + OpenAPIPatch: flags.OpenAPIPatch, + + Recorder: recorder, + Namespace: namespace, + EnforceNamespace: enforceNamespace, + + Builder: builder, + Mapper: mapper, + DynamicClient: dynamicClient, + OpenAPISchema: openAPISchema, IOStreams: flags.IOStreams, @@ -589,12 +553,6 @@ See https://kubernetes.io/docs/reference/using-api/server-side-apply/#conflicts` } if o.DryRunStrategy != cmdutil.DryRunClient { - metadata, _ := meta.Accessor(info.Object) - annotationMap := metadata.GetAnnotations() - if _, ok := annotationMap[corev1.LastAppliedConfigAnnotation]; !ok { - fmt.Fprintf(o.ErrOut, warningNoLastAppliedConfigAnnotation, info.ObjectName(), corev1.LastAppliedConfigAnnotation, o.cmdBaseName) - } - patcher, err := newPatcher(o, info, helper) if err != nil { return err @@ -603,7 +561,6 @@ See https://kubernetes.io/docs/reference/using-api/server-side-apply/#conflicts` if err != nil { return cmdutil.AddSourceToErr(fmt.Sprintf("applying patch:\n%s\nto:\n%v\nfor:", patchBytes, info), info.Source, err) } - info.Refresh(patchedObject, true) WarnIfDeleting(info.Object, o.ErrOut) diff --git a/saectl/internal/cmd/cmd.go b/saectl/internal/cmd/cmd.go index 42c3af0..d0258c0 100644 --- a/saectl/internal/cmd/cmd.go +++ b/saectl/internal/cmd/cmd.go @@ -154,9 +154,7 @@ func NewCommand(o CtlOption) *cobra.Command { templates.ActsAsRootCommand(cmds, filters, groups...) - // TODO: add completion for get cmd cmds.AddCommand(apiresources.NewCmdAPIResources(f, o.IOStreams)) - //cmds.AddCommand(apiresources.NewCmdAPIVersions(f, o.IOStreams)) cmds.SetGlobalNormalizationFunc(cliflag.WordSepNormalizeFunc) return cmds } diff --git a/saectl/internal/cmd/create/create.go b/saectl/internal/cmd/create/create.go index 8c0a7ec..2d19261 100644 --- a/saectl/internal/cmd/create/create.go +++ b/saectl/internal/cmd/create/create.go @@ -64,8 +64,8 @@ var ( # Create a deployment(represents an application in sae) using the data in .json saectl create -f ./deployment.json - # Create a pod based on the JSON passed into stdin - cat pod.json | saectl create -f - + # Create a deployment based on the JSON passed into stdin + cat deployment.json | saectl create -f - # Edit the data in registry.yaml in JSON then create the resource using the edited data saectl create -f registry.yaml --edit -o json`)) @@ -75,7 +75,6 @@ var ( func NewCreateOptions(ioStreams genericclioptions.IOStreams) *CreateOptions { return &CreateOptions{ PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme), - // RecordFlags: genericclioptions.NewRecordFlags(), Recorder: genericclioptions.NoopRecorder{}, @@ -108,20 +107,14 @@ func NewCmdCreate(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cob usage := "to use to create the resource" cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, usage) - //cmdutil.AddValidateFlags(cmd) + cmdutil.AddValidateFlags(cmd) cmd.Flags().BoolVar(&o.EditBeforeCreate, "edit", o.EditBeforeCreate, "Edit the API resource before creating") cmd.Flags().Bool("windows-line-endings", runtime.GOOS == "windows", "Only relevant if --edit=true. Defaults to the line ending native to your platform.") - //cmdutil.AddDryRunFlag(cmd) + cmdutil.AddApplyAnnotationFlags(cmd) + cmdutil.AddDryRunFlag(cmd) o.PrintFlags.AddFlags(cmd) - // TODO: 1. Storing objects to annotations is currently not supported - //cmdutil.AddApplyAnnotationFlags(cmd) - // TODO: 2. Label selector is not supported for now - //cmdutil.AddLabelSelectorFlagVar(cmd, &o.Selector) - // TODO: 3. Server-Side Apply is not support for now - //cmdutil.AddFieldManagerFlagVar(cmd, &o.fieldManager, "saectl-create") - // create subcommands cmd.AddCommand(create.NewCmdCreateNamespace(f, ioStreams)) cmd.AddCommand(create.NewCmdCreateConfigMap(f, ioStreams)) diff --git a/saectl/internal/cmd/patch/patch.go b/saectl/internal/cmd/patch/patch.go deleted file mode 100644 index 58c4a55..0000000 --- a/saectl/internal/cmd/patch/patch.go +++ /dev/null @@ -1 +0,0 @@ -package patch diff --git a/saectl/internal/cmd/scale/scale.go b/saectl/internal/cmd/scale/scale.go index b97f942..9c101d0 100644 --- a/saectl/internal/cmd/scale/scale.go +++ b/saectl/internal/cmd/scale/scale.go @@ -90,7 +90,7 @@ func NewCmdScale(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobr validArgs := []string{"deployment"} cmd := &cobra.Command{ - Use: "scale [--resource-version=version] [--current-replicas=count] --replicas=COUNT (-f FILENAME | TYPE NAME)", + Use: "scale [--current-replicas=count] --replicas=COUNT (-f FILENAME | TYPE NAME)", DisableFlagsInUseLine: true, Short: i18n.T("Set a new size for a deployment, replica set, or replication controller"), Long: scaleLong, @@ -103,18 +103,15 @@ func NewCmdScale(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobr }, } - //o.RecordFlags.AddFlags(cmd) o.PrintFlags.AddFlags(cmd) cmd.Flags().BoolVar(&o.All, "all", o.All, "Select all resources in the namespace of the specified resource types") - cmd.Flags().StringVar(&o.ResourceVersion, "resource-version", o.ResourceVersion, i18n.T("Precondition for resource version. Requires that the current resource version match this value in order to scale.")) cmd.Flags().IntVar(&o.CurrentReplicas, "current-replicas", o.CurrentReplicas, "Precondition for current size. Requires that the current size of the resource match this value in order to scale. -1 (default) for no condition.") cmd.Flags().IntVar(&o.Replicas, "replicas", o.Replicas, "The new desired number of replicas. Required.") cmd.MarkFlagRequired("replicas") cmd.Flags().DurationVar(&o.Timeout, "timeout", 0, "The length of time to wait before giving up on a scale operation, zero means don't wait. Any other values should contain a corresponding time unit (e.g. 1s, 2m, 3h).") cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, "identifying the resource to set a new size") cmdutil.AddDryRunFlag(cmd) - cmdutil.AddLabelSelectorFlagVar(cmd, &o.Selector) return cmd } diff --git a/saectl/internal/cmd/set/set.go b/saectl/internal/cmd/set/set.go index e2db839..7e2e7f6 100644 --- a/saectl/internal/cmd/set/set.go +++ b/saectl/internal/cmd/set/set.go @@ -29,9 +29,6 @@ func NewCmdSet(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Co // add subcommands cmd.AddCommand(set.NewCmdImage(f, streams)) cmd.AddCommand(set.NewCmdResources(f, streams)) - //cmd.AddCommand(NewCmdSelector(f, streams)) - //cmd.AddCommand(NewCmdSubject(f, streams)) - //cmd.AddCommand(NewCmdServiceAccount(f, streams)) cmd.AddCommand(set.NewCmdEnv(f, streams)) return cmd diff --git a/saectl/pkg/config/client.go b/saectl/pkg/config/client.go index 11c11ed..0bb55ed 100644 --- a/saectl/pkg/config/client.go +++ b/saectl/pkg/config/client.go @@ -215,5 +215,5 @@ func (c *ClientConfig) ConfigAccess() clientcmd.ConfigAccess { var _ clientcmd.ClientConfig = &ClientConfig{} func genSAEClusterServerAddress(region string) string { - return fmt.Sprintf("sae-share.%s.aliyuncs.com", region) + return fmt.Sprintf("sae.%s.aliyuncs.com", region) }