Skip to content

Commit 865e6d7

Browse files
committed
fix test, rename cmds
Signed-off-by: Wantong Jiang <[email protected]>
1 parent 8d60a12 commit 865e6d7

File tree

8 files changed

+81
-39
lines changed

8 files changed

+81
-39
lines changed

test/e2e/drain_tool_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ var _ = Describe("Drain is allowed on one cluster, blocked on others - ClusterRe
359359

360360
func runDrainClusterBinary(hubClusterName, memberClusterName string) {
361361
By(fmt.Sprintf("draining cluster %s", memberClusterName))
362-
cmd := exec.Command(fleetBinaryPath, "drain",
362+
cmd := exec.Command(fleetBinaryPath, "draincluster",
363363
"--hubClusterContext", hubClusterName,
364364
"--clusterName", memberClusterName)
365365
_, err := cmd.CombinedOutput()
@@ -368,7 +368,7 @@ func runDrainClusterBinary(hubClusterName, memberClusterName string) {
368368

369369
func runUncordonClusterBinary(hubClusterName, memberClusterName string) {
370370
By(fmt.Sprintf("uncordoning cluster %s", memberClusterName))
371-
cmd := exec.Command(fleetBinaryPath, "uncordon",
371+
cmd := exec.Command(fleetBinaryPath, "uncordoncluster",
372372
"--hubClusterContext", hubClusterName,
373373
"--clusterName", memberClusterName)
374374
_, err := cmd.CombinedOutput()

test/e2e/updaterun_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ var _ = Describe("test CRP rollout with staged update run", func() {
10931093
return fmt.Errorf("want 1 approval request, got %d", len(appReqList.Items))
10941094
}
10951095
return nil
1096-
}, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to find cluster approval request")
1096+
}, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to find cluster approval request")
10971097
})
10981098

10991099
It("Should approve cluster approval request using kubectl-fleet approve plugin", func() {

tools/fleet/README.md

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# kubectl-fleet
22

3-
A unified kubectl plugin for KubeFleet cluster management operations, providing drain and uncordon functionality for member clusters in a fleet.
3+
A unified kubectl plugin for KubeFleet cluster management operations, providing draincluster, and uncordoncluster functionality for member clusters in a fleet,
4+
as well as staged update approval capability.
45

56
## Description
67

7-
`kubectl-fleet` allows you to manage member clusters in a KubeFleet deployment by draining workloads from clusters for maintenance and uncordoning them when ready to accept workloads again.
8+
`kubectl-fleet` allows you to manage member clusters in a KubeFleet deployment by approving staged updates, draining workloads from clusters for maintenance, and uncordoning them when ready to accept workloads again.
89

910
## Installation
1011

@@ -63,57 +64,83 @@ CURRENT NAME CLUSTER AUTHINFO
6364

6465
Here you can see that the context of the hub cluster is called `hub` under the `NAME` column.
6566

67+
### Approve a ClusterApprovalRequest
68+
69+
Use the `approve` subcommand to approve ClusterApprovalRequest resources for staged update runs. This allows staged updates to proceed to the next stage by patching an "Approved" condition to the resource status.
70+
71+
```bash
72+
kubectl fleet approve clusterapprovalrequest --hubClusterContext <hub-cluster-context> --name <approval-request-name>
73+
```
74+
75+
Example:
76+
```bash
77+
kubectl fleet approve clusterapprovalrequest --hubClusterContext hub --name my-approval-request
78+
```
79+
6680
### Drain a Member Cluster
6781

68-
Use the `drain` subcommand to remove all resources propagated to a member cluster from the hub cluster by any `Placement` resource. This is useful when you want to temporarily move all workloads off a member cluster in preparation for an event like upgrade or reconfiguration.
82+
Use the `draincluster` subcommand to remove all resources propagated to a member cluster from the hub cluster by any `Placement` resource. This is useful when you want to temporarily move all workloads off a member cluster in preparation for an event like upgrade or reconfiguration.
6983

7084
```bash
71-
kubectl fleet drain --hubClusterContext <hub-cluster-context> --clusterName <memberClusterName>
85+
kubectl fleet draincluster --hubClusterContext <hub-cluster-context> --clusterName <memberClusterName>
7286
```
7387

7488
Example:
7589
```bash
76-
kubectl fleet drain --hubClusterContext hub --clusterName member-cluster-1
90+
kubectl fleet draincluster --hubClusterContext hub --clusterName member-cluster-1
7791
```
7892

7993
### Uncordon a Member Cluster
8094

81-
Use the `uncordon` subcommand to uncordon a member cluster that has been previously drained, allowing resources to be propagated to the cluster again.
95+
Use the `uncordoncluster` subcommand to uncordon a member cluster that has been previously drained, allowing resources to be propagated to the cluster again.
8296

8397
```bash
84-
kubectl fleet uncordon --hubClusterContext <hub-cluster-context> --clusterName <memberClusterName>
98+
kubectl fleet uncordoncluster --hubClusterContext <hub-cluster-context> --clusterName <memberClusterName>
8599
```
86100

87101
Example:
88102
```bash
89-
kubectl fleet uncordon --hubClusterContext hub --clusterName member-cluster-1
103+
kubectl fleet uncordoncluster --hubClusterContext hub --clusterName member-cluster-1
90104
```
91105

92106
## Subcommands
93107

94-
### drain
108+
### approve
109+
110+
Approves ClusterApprovalRequest resources for staged update runs by:
111+
112+
1. **Status Update**: Patches the ClusterApprovalRequest resource with an "Approved" condition
113+
2. **Stage Progression**: Allows staged updates to proceed to the next stage automatically
114+
115+
The approve command currently supports the following resource kinds:
116+
- `clusterapprovalrequest`: Approve a ClusterApprovalRequest for staged updates
117+
118+
### draincluster
95119

96120
Drains a member cluster by performing the following actions:
97121

98122
1. **Cordoning**: Adds a `Taint` to the `MemberCluster` resource to prevent any new resources from being propagated to the member cluster
99123
2. **Eviction**: Creates `Eviction` objects for all the `Placement` objects that have propagated resources to the member cluster
100124
3. **Resource Removal**: Waits for all evictions to complete and resources to be removed from the member cluster
101125

102-
**Note**: The `drain` command is a best-effort mechanism. Once the command runs successfully, you must verify that all resources propagated by `Placement` resources are removed from the member cluster. Re-running the command is safe and recommended if you notice any resources still present on the member cluster.
126+
**Note**: The `draincluster` command is a best-effort mechanism. Once the command runs successfully, you must verify that all resources propagated by `Placement` resources are removed from the member cluster. Re-running the command is safe and recommended if you notice any resources still present on the member cluster.
103127

104-
### uncordon
128+
### uncordoncluster
105129

106130
Uncordons a previously drained member cluster by:
107131

108-
1. **Taint Removal**: Removes the `cordon` taint that was added to the `MemberCluster` resource by the `drain` command
132+
1. **Taint Removal**: Removes the `cordon` taint that was added to the `MemberCluster` resource by the `draincluster` command
109133
2. **Resource Propagation**: Allows resources to be propagated to the cluster again according to existing `Placement` objects
110134

111135
If the `cordon` taint is not present on the member cluster, the command will have no effect and complete successfully.
112136

113137
## Flags
114138

115-
Both `drain` and `uncordon` subcommands use the following flags:
139+
The `approve` subcommand uses the following flags:
140+
- `--hubClusterContext`: kubectl context for the hub cluster (required)
141+
- `--name`: name of the resource to approve (required)
116142

143+
Both `draincluster` and `uncordoncluster` subcommands use the following flags:
117144
- `--hubClusterContext`: kubectl context for the hub cluster (required)
118145
- `--clusterName`: name of the member cluster to operate on (required)
119146

@@ -126,42 +153,57 @@ Both `drain` and `uncordon` subcommands use the following flags:
126153
kubectl config get-contexts
127154

128155
# 2. Drain a cluster for maintenance
129-
kubectl fleet drain --hubClusterContext production-hub --clusterName worker-node-1
156+
kubectl fleet draincluster --hubClusterContext production-hub --clusterName worker-node-1
130157

131158
# 3. Perform maintenance on the worker-node-1 cluster
132159
# ... maintenance operations ...
133160

134161
# 4. After maintenance, uncordon the cluster to allow workloads back
135-
kubectl fleet uncordon --hubClusterContext production-hub --clusterName worker-node-1
162+
kubectl fleet uncordoncluster --hubClusterContext production-hub --clusterName worker-node-1
136163
```
137164

138165
### Additional Examples
139166

140167
```bash
168+
# Approve a ClusterApprovalRequest for staged updates
169+
kubectl fleet approve clusterapprovalrequest --hubClusterContext hub --name update-approval-stage-1
170+
141171
# Drain multiple clusters (run separately for each cluster)
142-
kubectl fleet drain --hubClusterContext hub --clusterName east-cluster
143-
kubectl fleet drain --hubClusterContext hub --clusterName west-cluster
172+
kubectl fleet draincluster --hubClusterContext hub --clusterName east-cluster
173+
kubectl fleet draincluster --hubClusterContext hub --clusterName west-cluster
144174

145175
# Uncordon clusters after maintenance
146-
kubectl fleet uncordon --hubClusterContext hub --clusterName east-cluster
147-
kubectl fleet uncordon --hubClusterContext hub --clusterName west-cluster
176+
kubectl fleet uncordoncluster --hubClusterContext hub --clusterName east-cluster
177+
kubectl fleet uncordoncluster --hubClusterContext hub --clusterName west-cluster
148178
```
149179

150180
## Troubleshooting
151181

182+
### Verifying Approval Operation
183+
184+
After running the approval command, verify that the corresponding clusterApprovalRequest has been approved:
185+
186+
1. Check that the clusterApprovalRequest has `APPROVED` set to true
187+
```
188+
kubectl get clusterapprovalrequest example-run-staging
189+
NAME UPDATE-RUN STAGE APPROVED AGE
190+
example-run-staging example-run staging True 2m46s
191+
```
192+
2. Verify the updateRun is not blocked by the approval after-stage task
193+
152194
### Verifying Drain Operation
153195

154-
After running the drain command, verify that resources have been removed from the member cluster:
196+
After running the draincluster command, verify that resources have been removed from the member cluster:
155197

156198
1. Check that the cordon taint has been applied to the MemberCluster resource
157199
2. Verify that eviction objects have been created for relevant placements
158200
3. Confirm that workloads have been moved off the target cluster
159201

160-
If resources remain on the cluster after draining, it's safe to re-run the drain command.
202+
If resources remain on the cluster after draining, it's safe to re-run the draincluster command.
161203

162204
### Verifying Uncordon Operation
163205

164-
After running the uncordon command:
206+
After running the uncordoncluster command:
165207

166208
1. Check that the cordon taint has been removed from the MemberCluster resource
167209
2. Monitor that new workloads can be scheduled to the cluster according to placement policies

tools/fleet/cmd/drain/drain.go renamed to tools/fleet/cmd/draincluster/draincluster.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package drain
17+
package draincluster
1818

1919
import (
2020
"context"
@@ -53,12 +53,12 @@ type drainOptions struct {
5353
hubClient client.Client
5454
}
5555

56-
// NewCmdDrain creates a new drain command
57-
func NewCmdDrain() *cobra.Command {
56+
// NewCmdDrainCluster creates a new draincluster command
57+
func NewCmdDrainCluster() *cobra.Command {
5858
o := &drainOptions{}
5959

6060
cmd := &cobra.Command{
61-
Use: "drain",
61+
Use: "draincluster",
6262
Short: "Drain a member cluster",
6363
Long: "Drain a member cluster by cordoning it and removing propagated resources",
6464
RunE: func(command *cobra.Command, args []string) error {

tools/fleet/cmd/drain/drain_test.go renamed to tools/fleet/cmd/draincluster/draincluster_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package drain
17+
package draincluster
1818

1919
import (
2020
"context"

tools/fleet/cmd/uncordon/uncordon.go renamed to tools/fleet/cmd/uncordoncluster/uncordoncluster.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package uncordon
17+
package uncordoncluster
1818

1919
import (
2020
"context"
@@ -40,12 +40,12 @@ type uncordonOptions struct {
4040
hubClient client.Client
4141
}
4242

43-
// NewCmdUncordon creates a new uncordon command
44-
func NewCmdUncordon() *cobra.Command {
43+
// NewCmdUncordonCluster creates a new uncordoncluster command
44+
func NewCmdUncordonCluster() *cobra.Command {
4545
o := &uncordonOptions{}
4646

4747
cmd := &cobra.Command{
48-
Use: "uncordon",
48+
Use: "uncordoncluster",
4949
Short: "Uncordon a member cluster",
5050
Long: "Uncordon a previously drained member cluster by removing the cordon taint",
5151
RunE: func(command *cobra.Command, args []string) error {

tools/fleet/cmd/uncordon/uncordon_test.go renamed to tools/fleet/cmd/uncordoncluster/uncordoncluster_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package uncordon
17+
package uncordoncluster
1818

1919
import (
2020
"context"

tools/fleet/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"github.com/spf13/cobra"
2323

2424
"github.com/kubefleet-dev/kubefleet/tools/fleet/cmd/approve"
25-
"github.com/kubefleet-dev/kubefleet/tools/fleet/cmd/drain"
26-
"github.com/kubefleet-dev/kubefleet/tools/fleet/cmd/uncordon"
25+
"github.com/kubefleet-dev/kubefleet/tools/fleet/cmd/draincluster"
26+
"github.com/kubefleet-dev/kubefleet/tools/fleet/cmd/uncordoncluster"
2727
)
2828

2929
func main() {
@@ -35,8 +35,8 @@ func main() {
3535

3636
// Add subcommands
3737
rootCmd.AddCommand(approve.NewCmdApprove())
38-
rootCmd.AddCommand(drain.NewCmdDrain())
39-
rootCmd.AddCommand(uncordon.NewCmdUncordon())
38+
rootCmd.AddCommand(draincluster.NewCmdDrainCluster())
39+
rootCmd.AddCommand(uncordoncluster.NewCmdUncordonCluster())
4040

4141
if err := rootCmd.Execute(); err != nil {
4242
log.Fatalf("Error executing command: %v", err)

0 commit comments

Comments
 (0)