Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kubectl edit-status

Edit Kubernetes resource status subresources with your local editor.

edit-status is a kubectl plugin for targeted status edits during development, testing, and operator troubleshooting. It resolves resources dynamically, so it works with built-in Kubernetes resources and CRDs that expose a /status subresource.

Features

  • Edit only the status field, never the full object.
  • Patch the Kubernetes /status subresource.
  • Support built-in resources, CRDs, resource short names, and resource.group names.
  • Complete resource types and object names through kubectl shell completion.
  • Preview generated patches with --dry-run.
  • Use YAML or JSON in the editor.

Build and install

Build the plugin:

make bin

Install it somewhere in PATH using the kubectl plugin name expected by kubectl:

install -m 0755 bin/edit-status "$(go env GOPATH)/bin/kubectl-edit_status"

For kubectl-managed plugin argument completion, also install the completion delegate executable:

ln -sf "$(go env GOPATH)/bin/kubectl-edit_status" "$(go env GOPATH)/bin/kubectl_complete-edit_status"

Verify installation:

kubectl plugin list | grep edit_status
kubectl edit-status --help

Shell completion

Load kubectl's own completion in your shell. For zsh:

source <(kubectl completion zsh)

Kubectl will discover kubectl_complete-edit_status and delegate completion for plugin arguments. This enables:

kubectl edit-status <TAB>
kubectl edit-status est <TAB>
kubectl edit-status --dry-run -o yaml est <TAB>

The plugin also provides standalone completion scripts:

kubectl edit-status completion bash
kubectl edit-status completion zsh
kubectl edit-status completion fish
kubectl edit-status completion powershell

Those scripts are useful only when running the plugin as a standalone command; for kubectl edit-status ..., prefer kubectl completion zsh.

Usage

kubectl edit-status RESOURCE NAME [flags]

Examples:

kubectl edit-status pod nginx -n default
kubectl edit-status deployment web -n prod
kubectl edit-status widgets.example.com demo -n default
kubectl edit-status est demo -n default

The plugin opens a document containing only the resource status:

status:
  conditions: []

After you save and close the editor, the plugin sends a JSON merge patch to the resource's /status subresource. If you remove fields in the editor, the patch marks those fields as null so they are removed from status. If nothing changed, it exits without sending a request.

Flags

--field-manager string   field manager name used for the status patch (default "edit-status")
--dry-run                print the status patch without sending it to the API server
-o, --output string      format used in the editor: yaml or json (default "yaml")

All standard kubectl config flags are also available, including --context, --kubeconfig, and --namespace.

Editor

The editor is selected in this order:

KUBE_EDITOR
EDITOR
VISUAL
vi

Lightweight test resource

Use this CRD and custom resource to test edit-status without creating Pods or consuming CPU and memory workloads:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: editstatustests.status.example.com
spec:
  group: status.example.com
  scope: Namespaced
  names:
    plural: editstatustests
    singular: editstatustest
    kind: EditStatusTest
    shortNames:
      - est
  versions:
    - name: v1
      served: true
      storage: true
      subresources:
        status: {}
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              x-kubernetes-preserve-unknown-fields: true
            status:
              type: object
              x-kubernetes-preserve-unknown-fields: true
---
apiVersion: status.example.com/v1
kind: EditStatusTest
metadata:
  name: demo
  namespace: default
spec: {}

Apply it and edit status:

kubectl apply -f edit-status-test.yaml
kubectl edit-status est demo -n default

Set a status like this:

status:
  phase: Ready
  message: edit-status works

Verify and clean up:

kubectl get est demo -n default -o yaml
kubectl delete -f edit-status-test.yaml

RBAC

Users need permission to get the object and patch its status subresource. For example:

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: edit-deployment-status
rules:
- apiGroups: ["apps"]
  resources: ["deployments"]
  verbs: ["get"]
- apiGroups: ["apps"]
  resources: ["deployments/status"]
  verbs: ["patch"]

Resources that do not enable a status subresource cannot be updated by this plugin.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages