$npx -y skills add kubesphere/kubesphere --skill nodegroupNodeGroup operation Skill for the edgewize nodegroup project. Use this whenever the user wants to query, create, update, delete, bind, unbind, or troubleshoot NodeGroup resources, including node binding, namespace binding, workspace binding, and deployment/config inspection for n
| 1 | # NodeGroup Operations |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | Use this skill to perform real `nodegroup`-related operations in the `edgewize-io/nodegroup` environment. |
| 6 | |
| 7 | This skill should help with: |
| 8 | |
| 9 | - listing and inspecting `NodeGroup` |
| 10 | - creating, updating, patching, and deleting `NodeGroup` |
| 11 | - binding and unbinding nodes |
| 12 | - binding and unbinding namespaces |
| 13 | - binding and unbinding workspaces |
| 14 | - troubleshooting failed or incomplete nodegroup sync |
| 15 | - checking deployment config under `config/nodegroup` |
| 16 | |
| 17 | Prefer using the bundled script `scripts/nodegroup_api.py` for authenticated KAPI operations. Use `kubectl` only as a verification or fallback tool when the API path is unavailable. |
| 18 | |
| 19 | ## Prerequisites |
| 20 | |
| 21 | Use the bundled script: |
| 22 | |
| 23 | - `scripts/nodegroup_api.py` |
| 24 | |
| 25 | Authentication model: |
| 26 | |
| 27 | - logs in against `/oauth/token` |
| 28 | - stores token in `~/.kubesphere_token` |
| 29 | - uses `KUBESPHERE_HOST`, `KUBESPHERE_USERNAME`, `KUBESPHERE_PASSWORD`, and `KUBESPHERE_TOKEN` |
| 30 | |
| 31 | Setup: |
| 32 | |
| 33 | ```bash |
| 34 | cd scripts |
| 35 | pip install requests |
| 36 | export KUBESPHERE_HOST="http://<kubesphere-host>" |
| 37 | python nodegroup_api.py login --username admin --password <password> |
| 38 | ``` |
| 39 | |
| 40 | Token helpers: |
| 41 | |
| 42 | ```bash |
| 43 | python nodegroup_api.py clear-cache |
| 44 | python nodegroup_api.py request GET /kapis/infra.kubesphere.io/v1alpha1/nodegroups |
| 45 | ``` |
| 46 | |
| 47 | ## Source of Truth |
| 48 | |
| 49 | When you need to confirm how an operation works, read these files first from the nodegroup source repository root: |
| 50 | |
| 51 | - `pkg/kapis/infra/v1alpha1/register.go` |
| 52 | - `pkg/kapis/infra/v1alpha1/handler.go` |
| 53 | - `pkg/kapis/infra/v1alpha1/workspace_handler.go` |
| 54 | - `pkg/controller/nodegroup/nodegroup_controller.go` |
| 55 | - `pkg/constants/constants.go` |
| 56 | |
| 57 | Do not invent unsupported operations. Base the workflow on the source repository. |
| 58 | |
| 59 | ## Main Resources |
| 60 | |
| 61 | ### NodeGroup |
| 62 | |
| 63 | Cluster-scoped resource. |
| 64 | |
| 65 | Important fields: |
| 66 | |
| 67 | - `spec.alias` |
| 68 | - `spec.description` |
| 69 | - `spec.manager` |
| 70 | - `status.state` |
| 71 | |
| 72 | ## Safe Operating Rules |
| 73 | |
| 74 | - Read-only requests: prefer `python nodegroup_api.py ...` query commands. |
| 75 | - Write requests: perform only the exact requested change. |
| 76 | - Do not delete resources unless the user explicitly asks for deletion. |
| 77 | - For destructive or potentially disruptive actions such as node unbind or delete, confirm impact in your response if the request is ambiguous. |
| 78 | - When changing bindings, verify the current state first, then apply the change, then verify the result. |
| 79 | |
| 80 | ## Preferred Operation Flow |
| 81 | |
| 82 | For any write operation, follow this order: |
| 83 | |
| 84 | 1. Inspect the current resource. |
| 85 | 2. Apply the minimal required change. |
| 86 | 3. Verify the resulting resource and any affected node, namespace, or workspace. |
| 87 | 4. If sync looks wrong, inspect labels, annotations, and controller behavior. |
| 88 | |
| 89 | ## Core Commands |
| 90 | |
| 91 | ### 1. Query NodeGroups |
| 92 | |
| 93 | ```bash |
| 94 | python nodegroup_api.py nodegroup list |
| 95 | python nodegroup_api.py nodegroup get <name> |
| 96 | ``` |
| 97 | |
| 98 | ### 2. Create a NodeGroup |
| 99 | |
| 100 | ```bash |
| 101 | python nodegroup_api.py nodegroup create \ |
| 102 | --name <nodegroup-name> \ |
| 103 | --alias "<alias>" \ |
| 104 | --description "<description>" \ |
| 105 | --manager "<manager>" |
| 106 | python nodegroup_api.py nodegroup get <nodegroup-name> |
| 107 | ``` |
| 108 | |
| 109 | ### 3. Update or Patch a NodeGroup |
| 110 | |
| 111 | Prefer patching for small changes. |
| 112 | |
| 113 | ```bash |
| 114 | python nodegroup_api.py nodegroup patch <name> \ |
| 115 | --alias "<new-alias>" \ |
| 116 | --description "<new-description>" \ |
| 117 | --manager "<manager>" |
| 118 | python nodegroup_api.py nodegroup get <name> |
| 119 | ``` |
| 120 | |
| 121 | For unsupported fields or ad hoc testing, use raw request mode. |
| 122 | |
| 123 | For `PATCH`, send a JSON Patch array: |
| 124 | |
| 125 | ```bash |
| 126 | python nodegroup_api.py request PATCH /kapis/infra.kubesphere.io/v1alpha1/nodegroups/<name> '[{"op":"add","path":"/spec/alias","value":"<new-alias>"}]' |
| 127 | ``` |
| 128 | |
| 129 | ### 4. Delete a NodeGroup |
| 130 | |
| 131 | Only do this when explicitly requested. |
| 132 | |
| 133 | ```bash |
| 134 | python nodegroup_api.py nodegroup delete <name> |
| 135 | ``` |
| 136 | |
| 137 | If delete hangs, inspect finalizers: |
| 138 | |
| 139 | ```bash |
| 140 | python nodegroup_api.py nodegroup get <name> |
| 141 | ``` |
| 142 | |
| 143 | Relevant finalizer: |
| 144 | |
| 145 | - `finalizers.nodegroups.kubesphere.io` |
| 146 | |
| 147 | ### 5. Bind or Unbind a Node |
| 148 | |
| 149 | Node binding is implemented through nodegroup APIs and reflected with label: |
| 150 | |
| 151 | - `apps.edgewize.io/nodegroup=<nodegroup-name>` |
| 152 | |
| 153 | Read current state: |
| 154 | |
| 155 | ```bash |
| 156 | kubectl get node <node-name> --show-labels |
| 157 | kubectl get nodes -l apps.edgewize.io/nodegroup=<nodegroup-name> |
| 158 | ``` |
| 159 | |
| 160 | Operate through the bundled script: |
| 161 | |
| 162 | ```bash |
| 163 | python nodegroup_api.py bind node --nodegroup <nodegroup-name> --node <node-name> |
| 164 | python nodegroup_api.py unbind node --nodegroup <nodegroup-name> --node <node-name> |
| 165 | |
| 166 | # Verify |
| 167 | kubectl get nodes -l apps.edgewize.io/nodegroup=<nodegroup-name> |
| 168 | kubectl get node <node-name> -o yaml |
| 169 | ``` |
| 170 | |
| 171 | ### 6. Bind or Unbind a Namespace |
| 172 | |
| 173 | Read current state: |
| 174 | |
| 175 | ```bash |
| 176 | kubectl get ns <namespace> --show-labels |
| 177 | ``` |
| 178 | |
| 179 | Operate through the bundled script: |
| 180 | |
| 181 | ```bash |
| 182 | python nodegroup_api.py bind namespace --nodegroup <nodegroup-name |