Merge pull request #75202 from obitech/fix_linting_kubectl_apply

Fix linting kubectl apply
This commit is contained in:
Kubernetes Prow Robot 2019-05-31 17:44:21 -07:00 committed by GitHub
commit 834db16c9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 0 deletions

View File

@ -56,6 +56,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl/validation" "k8s.io/kubernetes/pkg/kubectl/validation"
) )
// ApplyOptions defines flags and other configuration parameters for the `apply` command
type ApplyOptions struct { type ApplyOptions struct {
RecordFlags *genericclioptions.RecordFlags RecordFlags *genericclioptions.RecordFlags
Recorder genericclioptions.Recorder Recorder genericclioptions.Recorder
@ -132,6 +133,7 @@ var (
warningNoLastAppliedConfigAnnotation = "Warning: %[1]s apply should be used on resource created by either %[1]s create --save-config or %[1]s apply\n" warningNoLastAppliedConfigAnnotation = "Warning: %[1]s apply should be used on resource created by either %[1]s create --save-config or %[1]s apply\n"
) )
// NewApplyOptions creates new ApplyOptions for the `apply` command
func NewApplyOptions(ioStreams genericclioptions.IOStreams) *ApplyOptions { func NewApplyOptions(ioStreams genericclioptions.IOStreams) *ApplyOptions {
return &ApplyOptions{ return &ApplyOptions{
RecordFlags: genericclioptions.NewRecordFlags(), RecordFlags: genericclioptions.NewRecordFlags(),
@ -194,6 +196,7 @@ func NewCmdApply(baseName string, f cmdutil.Factory, ioStreams genericclioptions
return cmd return cmd
} }
// Complete verifies if ApplyOptions are valid and without conflicts.
func (o *ApplyOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error { func (o *ApplyOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error {
o.ServerSideApply = cmdutil.GetServerSideApplyFlag(cmd) o.ServerSideApply = cmdutil.GetServerSideApplyFlag(cmd)
o.ForceConflicts = cmdutil.GetForceConflictsFlag(cmd) o.ForceConflicts = cmdutil.GetForceConflictsFlag(cmd)
@ -325,6 +328,7 @@ func isIncompatibleServerError(err error) bool {
return err.(*errors.StatusError).Status().Code == http.StatusUnsupportedMediaType return err.(*errors.StatusError).Status().Code == http.StatusUnsupportedMediaType
} }
// Run executes the `apply` command.
func (o *ApplyOptions) Run() error { func (o *ApplyOptions) Run() error {
var openapiSchema openapi.Resources var openapiSchema openapi.Resources
if o.OpenAPIPatch { if o.OpenAPIPatch {
@ -761,6 +765,7 @@ func (p *Patcher) delete(namespace, name string) error {
return runDelete(namespace, name, p.Mapping, p.DynamicClient, p.Cascade, p.GracePeriod, p.ServerDryRun) return runDelete(namespace, name, p.Mapping, p.DynamicClient, p.Cascade, p.GracePeriod, p.ServerDryRun)
} }
// Patcher defines options to patch OpenAPI objects.
type Patcher struct { type Patcher struct {
Mapping *meta.RESTMapping Mapping *meta.RESTMapping
Helper *resource.Helper Helper *resource.Helper
@ -926,6 +931,8 @@ func (p *Patcher) patchSimple(obj runtime.Object, modified []byte, source, names
return patch, patchedObj, err return patch, patchedObj, err
} }
// Patch tries to patch an OpenAPI resource. On success, returns the merge patch as well
// the final patched object. On failure, returns an error.
func (p *Patcher) Patch(current runtime.Object, modified []byte, source, namespace, name string, errOut io.Writer) ([]byte, runtime.Object, error) { func (p *Patcher) Patch(current runtime.Object, modified []byte, source, namespace, name string, errOut io.Writer) ([]byte, runtime.Object, error) {
var getErr error var getErr error
patchBytes, patchObject, err := p.patchSimple(current, modified, source, namespace, name, errOut) patchBytes, patchObject, err := p.patchSimple(current, modified, source, namespace, name, errOut)

View File

@ -55,6 +55,7 @@ var (
kubectl apply edit-last-applied -f deploy.yaml -o json`) kubectl apply edit-last-applied -f deploy.yaml -o json`)
) )
// NewCmdApplyEditLastApplied created the cobra CLI command for the `apply edit-last-applied` command.
func NewCmdApplyEditLastApplied(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdApplyEditLastApplied(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
o := editor.NewEditOptions(editor.ApplyEditMode, ioStreams) o := editor.NewEditOptions(editor.ApplyEditMode, ioStreams)

View File

@ -37,6 +37,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl/util/templates" "k8s.io/kubernetes/pkg/kubectl/util/templates"
) )
// SetLastAppliedOptions defines options for the `apply set-last-applied` command.`
type SetLastAppliedOptions struct { type SetLastAppliedOptions struct {
CreateAnnotation bool CreateAnnotation bool
@ -58,6 +59,7 @@ type SetLastAppliedOptions struct {
genericclioptions.IOStreams genericclioptions.IOStreams
} }
// PatchBuffer caches changes that are to be applied.
type PatchBuffer struct { type PatchBuffer struct {
Patch []byte Patch []byte
PatchType types.PatchType PatchType types.PatchType
@ -81,6 +83,7 @@ var (
`)) `))
) )
// NewSetLastAppliedOptions takes option arguments from a CLI stream and returns it at SetLastAppliedOptions type.
func NewSetLastAppliedOptions(ioStreams genericclioptions.IOStreams) *SetLastAppliedOptions { func NewSetLastAppliedOptions(ioStreams genericclioptions.IOStreams) *SetLastAppliedOptions {
return &SetLastAppliedOptions{ return &SetLastAppliedOptions{
PrintFlags: genericclioptions.NewPrintFlags("configured").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("configured").WithTypeSetter(scheme.Scheme),
@ -88,6 +91,7 @@ func NewSetLastAppliedOptions(ioStreams genericclioptions.IOStreams) *SetLastApp
} }
} }
// NewCmdApplySetLastApplied creates the cobra CLI `apply` subcommand `set-last-applied`.`
func NewCmdApplySetLastApplied(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdApplySetLastApplied(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
o := NewSetLastAppliedOptions(ioStreams) o := NewSetLastAppliedOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -112,6 +116,7 @@ func NewCmdApplySetLastApplied(f cmdutil.Factory, ioStreams genericclioptions.IO
return cmd return cmd
} }
// Complete populates dry-run and output flag options.
func (o *SetLastAppliedOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error { func (o *SetLastAppliedOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error {
o.dryRun = cmdutil.GetDryRunFlag(cmd) o.dryRun = cmdutil.GetDryRunFlag(cmd)
o.output = cmdutil.GetFlagString(cmd, "output") o.output = cmdutil.GetFlagString(cmd, "output")
@ -141,6 +146,7 @@ func (o *SetLastAppliedOptions) Complete(f cmdutil.Factory, cmd *cobra.Command)
return nil return nil
} }
// Validate checks SetLastAppliedOptions for validity.
func (o *SetLastAppliedOptions) Validate() error { func (o *SetLastAppliedOptions) Validate() error {
r := o.builder. r := o.builder.
Unstructured(). Unstructured().
@ -187,6 +193,7 @@ func (o *SetLastAppliedOptions) Validate() error {
return err return err
} }
// RunSetLastApplied executes the `set-last-applied` command according to SetLastAppliedOptions.
func (o *SetLastAppliedOptions) RunSetLastApplied() error { func (o *SetLastAppliedOptions) RunSetLastApplied() error {
for i, patch := range o.patchBufferList { for i, patch := range o.patchBufferList {
info := o.infoList[i] info := o.infoList[i]

View File

@ -31,6 +31,7 @@ import (
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
) )
// ViewLastAppliedOptions defines options for the `apply view-last-applied` command.`
type ViewLastAppliedOptions struct { type ViewLastAppliedOptions struct {
FilenameOptions resource.FilenameOptions FilenameOptions resource.FilenameOptions
Selector string Selector string
@ -57,6 +58,7 @@ var (
kubectl apply view-last-applied -f deploy.yaml -o json`)) kubectl apply view-last-applied -f deploy.yaml -o json`))
) )
// NewViewLastAppliedOptions takes option arguments from a CLI stream and returns it at ViewLastAppliedOptions type.
func NewViewLastAppliedOptions(ioStreams genericclioptions.IOStreams) *ViewLastAppliedOptions { func NewViewLastAppliedOptions(ioStreams genericclioptions.IOStreams) *ViewLastAppliedOptions {
return &ViewLastAppliedOptions{ return &ViewLastAppliedOptions{
OutputFormat: "yaml", OutputFormat: "yaml",
@ -65,6 +67,7 @@ func NewViewLastAppliedOptions(ioStreams genericclioptions.IOStreams) *ViewLastA
} }
} }
// NewCmdApplyViewLastApplied creates the cobra CLI `apply` subcommand `view-last-applied`.`
func NewCmdApplyViewLastApplied(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdApplyViewLastApplied(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
options := NewViewLastAppliedOptions(ioStreams) options := NewViewLastAppliedOptions(ioStreams)
@ -90,6 +93,7 @@ func NewCmdApplyViewLastApplied(f cmdutil.Factory, ioStreams genericclioptions.I
return cmd return cmd
} }
// Complete checks an object for last-applied-configuration annotations.
func (o *ViewLastAppliedOptions) Complete(cmd *cobra.Command, f cmdutil.Factory, args []string) error { func (o *ViewLastAppliedOptions) Complete(cmd *cobra.Command, f cmdutil.Factory, args []string) error {
cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace() cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
@ -134,10 +138,12 @@ func (o *ViewLastAppliedOptions) Complete(cmd *cobra.Command, f cmdutil.Factory,
return nil return nil
} }
// Validate checks ViewLastAppliedOptions for validity.
func (o *ViewLastAppliedOptions) Validate(cmd *cobra.Command) error { func (o *ViewLastAppliedOptions) Validate(cmd *cobra.Command) error {
return nil return nil
} }
// RunApplyViewLastApplied executes the `view-last-applied` command according to ViewLastAppliedOptions.
func (o *ViewLastAppliedOptions) RunApplyViewLastApplied(cmd *cobra.Command) error { func (o *ViewLastAppliedOptions) RunApplyViewLastApplied(cmd *cobra.Command) error {
for _, str := range o.LastAppliedConfigurationList { for _, str := range o.LastAppliedConfigurationList {
switch o.OutputFormat { switch o.OutputFormat {