Add kubectl-net plugin for managing network-operator resources - #411
Add kubectl-net plugin for managing network-operator resources#411felix-kaestner wants to merge 8 commits into
Conversation
a1f82a8 to
06ea0ef
Compare
7805fa5 to
573acd5
Compare
3082510 to
9d3047f
Compare
bab5c83 to
69fe2ff
Compare
$ kind get clusters
network-operator
network-operator-target
$ kubectl --context kind-network-operator get deploy -n network-operator-system
NAME READY UP-TO-DATE AVAILABLE AGE
network-operator-controller-manager 1/1 1 1 112m
$ kubectl --context kind-network-operator-target get deploy -n network-operator-system
NAME READY UP-TO-DATE AVAILABLE AGE
network-operator-controller-manager 1/1 1 1 23m
$ kubectl net move --context kind-network-operator --to-context kind-network-operator-target --to-kubeconfig ~/.kube/config --dry-run
Checking target cluster CRDs...
Discovering resources in namespace "default"...
Device/leaf1
Interface/lo0
Total: 2 resources would be moved.
$ kubectl net move --context kind-network-operator --to-context kind-network-operator-target --to-kubeconfig ~/.kube/config
Checking target cluster CRDs...
Discovering resources in namespace "default"...
Pausing Devices on source...
Creating resources on target...
Deleting resources from source...
Unpausing Devices on target...
Move complete. |
8459451 to
f9697d3
Compare
SchwarzM
left a comment
There was a problem hiding this comment.
Very nice ! I have some minor points.
Also we might want to consider adding a test or 2 for the non-trivial logic which is now very flat but might get more complicated over time. Thinking of patch generation and flags.
|
|
||
| root := cmd.NewCmdNet(genericiooptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}) | ||
| if err := root.Execute(); err != nil { | ||
| os.Exit(1) |
There was a problem hiding this comment.
this seems we just exit without bubbling the error to the user ?
There was a problem hiding this comment.
Cobra prints errors by default unless SilenceErrors is set. ref/ https://github.com/spf13/cobra/blob/v1.10.2/command.go#L1157-L1161
So based on this the error is already shown to the user.
| list.SetResourceVersion("") | ||
| for _, info := range infos { | ||
| if info.Object != nil { | ||
| list.Items = append(list.Items, *info.Object.(*unstructured.Unstructured)) |
There was a problem hiding this comment.
you've made sure the conversion to unstructured is safe above why not here ?
There was a problem hiding this comment.
Changed to not safely check in both places. It can't ever not be unstructured, as this is explicitly requested in the buildResourceResult.
| crd := schema.GroupVersionResource{Group: "apiextensions.k8s.io", Version: "v1", Resource: "customresourcedefinitions"} | ||
| for _, def := range resourceDefs { | ||
| name := def.Name + "." + def.Group | ||
| _, err := tgtDyn.Resource(crd).Get(ctx, name, metav1.GetOptions{}) |
There was a problem hiding this comment.
maybe we should check the version ? It might not be in use now but could be in the future ...
There was a problem hiding this comment.
The resourceDefs we are looping over here are generated from code and therefore already contain the api version which we check on the target cluster. So this is already implicitly the case.
|
|
||
| infos, err := result.Infos() | ||
| if err != nil { | ||
| return err |
There was a problem hiding this comment.
Error will automatically be printed, as mentioned in #411 (comment)
Signed-off-by: Felix Kästner <felix.kaestner@sap.com>
Signed-off-by: Felix Kästner <felix.kaestner@sap.com>
Implements a kubectl plugin with get, pause, unpause, and shell completion subcommands. The get command supports server-side table printing and all standard kubectl output formats. Label shorthand flags (--device/-d, --aggregate, --vrf, --routed-vlan, --evi) provide convenient filtering. Resource definitions are code-generated from the API types via kubebuilder markers. Signed-off-by: Felix Kästner <felix.kaestner@sap.com>
Add --serial flag for Device resources to filter by DeviceSerialLabel, and --neighbor flag for Interface resources to filter by PhysicalInterfaceNeighborLabel. Both flags are available on get and pause/unpause commands. Signed-off-by: Felix Kästner <felix.kaestner@sap.com>
The generator was capturing kubebuilder marker suffixes (singular=, shortName=) as part of the resource name when all attributes appeared on one line (e.g. path=indices,singular=index). Parse inline attributes from the same line as path= so the Name field contains only the plural resource name. Signed-off-by: Felix Kästner <felix.kaestner@sap.com>
Implements a 'kubectl net move' subcommand that migrates all network-operator resources from a source cluster namespace to a target cluster. Inspired by clusterctl move from cluster-api. The move algorithm: - Verify CRDs exist on the target cluster - Ensure the target namespace exists - Discover all network-operator resources in the source namespace - Pause all Devices on the source (spec.paused) - Create resources on the target (stripped of cluster-specific metadata and owner references) - Delete resources from the source (stripping finalizers) - Unpause Devices on the target Owner references are not rewritten; controllers re-establish them on first reconcile after unpause. The operation is idempotent and can be re-run on partial failure. Signed-off-by: Felix Kästner <felix.kaestner@sap.com>
controller-gen with paths="./..." recurses into the kubectl-net sub-module, fails to resolve its dependencies in CI, and aborts. Narrow the paths to ./api/ and ./internal/ where the actual types and controllers live. Signed-off-by: Felix Kästner <felix.kaestner@sap.com>
Add a 'kubectl net version' subcommand that prints the version injected at build time via ldflags. Add a 'make kubectl-net' target that builds the plugin binary into bin/ with stripped symbols and version info from git describe. Signed-off-by: Felix Kästner <felix.kaestner@sap.com>
Merging this branch will not change overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. |
Implements a kubectl plugin with get, pause, unpause, and shell
completion subcommands. The get command supports server-side table
printing and all standard kubectl output formats. Label shorthand
flags (--device/-d, --aggregate, --vrf, --routed-vlan, --evi)
provide convenient filtering. Resource definitions are code-generated
from the API types via kubebuilder markers.