mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Fix some golint errors for packages in pkg/kubectl/cmd
Co-authored-by: Arijit Basu <sayanarijit@gmail.com>
This commit is contained in:
@@ -81,6 +81,7 @@ type EditOptions struct {
|
||||
updatedResultGetter func(data []byte) *resource.Result
|
||||
}
|
||||
|
||||
// NewEditOptions returns an initialized EditOptions instance
|
||||
func NewEditOptions(editMode EditMode, ioStreams genericclioptions.IOStreams) *EditOptions {
|
||||
return &EditOptions{
|
||||
RecordFlags: genericclioptions.NewRecordFlags(),
|
||||
@@ -216,6 +217,7 @@ func (o *EditOptions) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run performs the execution
|
||||
func (o *EditOptions) Run() error {
|
||||
edit := NewDefaultEditor(editorEnvs())
|
||||
// editFn is invoked for each edit session (once with a list for normal edit, once for each individual resource in a edit-on-create invocation)
|
||||
@@ -399,7 +401,7 @@ func (o *EditOptions) Run() error {
|
||||
return err
|
||||
}
|
||||
if len(infos) == 0 {
|
||||
return errors.New("edit cancelled, no objects found.")
|
||||
return errors.New("edit cancelled, no objects found")
|
||||
}
|
||||
return editFn(infos)
|
||||
case ApplyEditMode:
|
||||
@@ -459,12 +461,12 @@ func (o *EditOptions) visitToApplyEditPatch(originalInfos []*resource.Info, patc
|
||||
return fmt.Errorf("no original object found for %#v", info.Object)
|
||||
}
|
||||
|
||||
originalJS, err := encodeToJson(originalInfo.Object.(runtime.Unstructured))
|
||||
originalJS, err := encodeToJSON(originalInfo.Object.(runtime.Unstructured))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
editedJS, err := encodeToJson(info.Object.(runtime.Unstructured))
|
||||
editedJS, err := encodeToJSON(info.Object.(runtime.Unstructured))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -474,21 +476,18 @@ func (o *EditOptions) visitToApplyEditPatch(originalInfos []*resource.Info, patc
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printer.PrintObj(info.Object, o.Out)
|
||||
return nil
|
||||
} else {
|
||||
err := o.annotationPatch(info)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printer, err := o.ToPrinter("edited")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printer.PrintObj(info.Object, o.Out)
|
||||
return nil
|
||||
return printer.PrintObj(info.Object, o.Out)
|
||||
}
|
||||
err = o.annotationPatch(info)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printer, err := o.ToPrinter("edited")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return printer.PrintObj(info.Object, o.Out)
|
||||
})
|
||||
return err
|
||||
}
|
||||
@@ -511,8 +510,9 @@ func (o *EditOptions) annotationPatch(update *resource.Info) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetApplyPatch is used to get and apply patches
|
||||
func GetApplyPatch(obj runtime.Unstructured) ([]byte, []byte, types.PatchType, error) {
|
||||
beforeJSON, err := encodeToJson(obj)
|
||||
beforeJSON, err := encodeToJSON(obj)
|
||||
if err != nil {
|
||||
return nil, []byte(""), types.MergePatchType, err
|
||||
}
|
||||
@@ -527,7 +527,7 @@ func GetApplyPatch(obj runtime.Unstructured) ([]byte, []byte, types.PatchType, e
|
||||
}
|
||||
annotations[corev1.LastAppliedConfigAnnotation] = string(beforeJSON)
|
||||
accessor.SetAnnotations(objCopy, annotations)
|
||||
afterJSON, err := encodeToJson(objCopy.(runtime.Unstructured))
|
||||
afterJSON, err := encodeToJSON(objCopy.(runtime.Unstructured))
|
||||
if err != nil {
|
||||
return nil, beforeJSON, types.MergePatchType, err
|
||||
}
|
||||
@@ -535,7 +535,7 @@ func GetApplyPatch(obj runtime.Unstructured) ([]byte, []byte, types.PatchType, e
|
||||
return patch, beforeJSON, types.MergePatchType, err
|
||||
}
|
||||
|
||||
func encodeToJson(obj runtime.Unstructured) ([]byte, error) {
|
||||
func encodeToJSON(obj runtime.Unstructured) ([]byte, error) {
|
||||
serialization, err := runtime.Encode(unstructured.UnstructuredJSONScheme, obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -569,12 +569,12 @@ func (o *EditOptions) visitToPatch(originalInfos []*resource.Info, patchVisitor
|
||||
return fmt.Errorf("no original object found for %#v", info.Object)
|
||||
}
|
||||
|
||||
originalJS, err := encodeToJson(originalInfo.Object.(runtime.Unstructured))
|
||||
originalJS, err := encodeToJSON(originalInfo.Object.(runtime.Unstructured))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
editedJS, err := encodeToJson(info.Object.(runtime.Unstructured))
|
||||
editedJS, err := encodeToJSON(info.Object.(runtime.Unstructured))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -585,8 +585,7 @@ func (o *EditOptions) visitToPatch(originalInfos []*resource.Info, patchVisitor
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printer.PrintObj(info.Object, o.Out)
|
||||
return nil
|
||||
return printer.PrintObj(info.Object, o.Out)
|
||||
}
|
||||
|
||||
preconditions := []mergepatch.PreconditionFunc{
|
||||
@@ -643,8 +642,7 @@ func (o *EditOptions) visitToPatch(originalInfos []*resource.Info, patchVisitor
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printer.PrintObj(info.Object, o.Out)
|
||||
return nil
|
||||
return printer.PrintObj(info.Object, o.Out)
|
||||
})
|
||||
return err
|
||||
}
|
||||
@@ -658,8 +656,7 @@ func (o *EditOptions) visitToCreate(createVisitor resource.Visitor) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printer.PrintObj(info.Object, o.Out)
|
||||
return nil
|
||||
return printer.PrintObj(info.Object, o.Out)
|
||||
})
|
||||
return err
|
||||
}
|
||||
@@ -683,12 +680,18 @@ func (o *EditOptions) visitAnnotation(annotationVisitor resource.Visitor) error
|
||||
return err
|
||||
}
|
||||
|
||||
// EditMode can be either NormalEditMode, EditBeforeCreateMode or ApplyEditMode
|
||||
type EditMode string
|
||||
|
||||
const (
|
||||
NormalEditMode EditMode = "normal_mode"
|
||||
// NormalEditMode is an edit mode
|
||||
NormalEditMode EditMode = "normal_mode"
|
||||
|
||||
// EditBeforeCreateMode is an edit mode
|
||||
EditBeforeCreateMode EditMode = "edit_before_create_mode"
|
||||
ApplyEditMode EditMode = "edit_last_applied_mode"
|
||||
|
||||
// ApplyEditMode is an edit mode
|
||||
ApplyEditMode EditMode = "edit_last_applied_mode"
|
||||
)
|
||||
|
||||
// editReason preserves a message about the reason this file must be edited again
|
||||
|
||||
Reference in New Issue
Block a user