generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[kueuectl] Added stop/resume workload commands. (#2134)
- Loading branch information
1 parent
2ab58f6
commit c55f10c
Showing
14 changed files
with
619 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
cmd/kueuectl/app/options/update_workload_activation_options.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
Copyright 2024 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package options | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
"k8s.io/cli-runtime/pkg/genericiooptions" | ||
"k8s.io/cli-runtime/pkg/printers" | ||
"k8s.io/utils/ptr" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"sigs.k8s.io/kueue/client-go/clientset/versioned" | ||
"sigs.k8s.io/kueue/client-go/clientset/versioned/scheme" | ||
kueuev1beta1 "sigs.k8s.io/kueue/client-go/clientset/versioned/typed/kueue/v1beta1" | ||
"sigs.k8s.io/kueue/cmd/kueuectl/app/util" | ||
) | ||
|
||
type UpdateWorkloadActivationOptions struct { | ||
PrintFlags *genericclioptions.PrintFlags | ||
|
||
Active bool | ||
DryRunStrategy util.DryRunStrategy | ||
Name string | ||
Namespace string | ||
EnforceNamespace bool | ||
|
||
Client kueuev1beta1.KueueV1beta1Interface | ||
|
||
PrintObj printers.ResourcePrinterFunc | ||
|
||
genericiooptions.IOStreams | ||
} | ||
|
||
func NewUpdateWorkloadActivationOptions(streams genericiooptions.IOStreams, operation string, active bool) *UpdateWorkloadActivationOptions { | ||
return &UpdateWorkloadActivationOptions{ | ||
PrintFlags: genericclioptions.NewPrintFlags(operation).WithTypeSetter(scheme.Scheme), | ||
Active: active, | ||
IOStreams: streams, | ||
} | ||
} | ||
|
||
// Complete completes all the required options | ||
func (o *UpdateWorkloadActivationOptions) Complete(clientGetter genericclioptions.RESTClientGetter, cmd *cobra.Command, args []string) error { | ||
o.Name = args[0] | ||
|
||
var err error | ||
o.Namespace, o.EnforceNamespace, err = clientGetter.ToRawKubeConfigLoader().Namespace() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
config, err := clientGetter.ToRESTConfig() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
clientset, err := versioned.NewForConfig(config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
o.Client = clientset.KueueV1beta1() | ||
|
||
o.DryRunStrategy, err = util.GetDryRunStrategy(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = util.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.DryRunStrategy) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
printer, err := o.PrintFlags.ToPrinter() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
o.PrintObj = printer.PrintObj | ||
|
||
return nil | ||
} | ||
|
||
// Run performs to update a Workload status operation. | ||
func (o *UpdateWorkloadActivationOptions) Run(ctx context.Context) error { | ||
wl, err := o.Client.Workloads(o.Namespace).Get(ctx, o.Name, metav1.GetOptions{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
wlOriginal := wl.DeepCopy() | ||
wl.Spec.Active = ptr.To(o.Active) | ||
|
||
if o.DryRunStrategy != util.DryRunClient { | ||
opts := metav1.PatchOptions{} | ||
if o.DryRunStrategy == util.DryRunServer { | ||
opts.DryRun = []string{metav1.DryRunAll} | ||
} | ||
patch := client.MergeFrom(wlOriginal) | ||
data, err := patch.Data(wl) | ||
if err != nil { | ||
return err | ||
} | ||
wl, err = o.Client.Workloads(o.Namespace).Patch(ctx, wl.Name, types.MergePatchType, data, opts) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return o.PrintObj(wl, o.Out) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright 2024 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package resume | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
"k8s.io/cli-runtime/pkg/genericiooptions" | ||
|
||
"sigs.k8s.io/kueue/cmd/kueuectl/app/util" | ||
) | ||
|
||
const ( | ||
resumeExample = ` # Resume the workload | ||
kueuectl resume workload my-workload` | ||
) | ||
|
||
func NewResumeCmd(clientGetter genericclioptions.RESTClientGetter, streams genericiooptions.IOStreams) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "resume", | ||
Short: "Resume the resource", | ||
Example: resumeExample, | ||
} | ||
|
||
util.AddDryRunFlag(cmd) | ||
|
||
cmd.AddCommand(NewWorkloadCmd(clientGetter, streams)) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2024 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package resume | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
"k8s.io/cli-runtime/pkg/genericiooptions" | ||
|
||
"sigs.k8s.io/kueue/cmd/kueuectl/app/options" | ||
) | ||
|
||
const ( | ||
wlLong = `Resumes the Workload, allowing its admission according to regular ClusterQueue rules.` | ||
wlExample = ` # Resume the workload | ||
kueuectl resume workload my-workload` | ||
) | ||
|
||
func NewWorkloadCmd(clientGetter genericclioptions.RESTClientGetter, streams genericiooptions.IOStreams) *cobra.Command { | ||
o := options.NewUpdateWorkloadActivationOptions(streams, "resumed", true) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "workload NAME [--namespace NAMESPACE] [--dry-run STRATEGY]", | ||
// To do not add "[flags]" suffix on the end of usage line | ||
DisableFlagsInUseLine: true, | ||
Aliases: []string{"wl"}, | ||
Short: "Resume the Workload", | ||
Long: wlLong, | ||
Example: wlExample, | ||
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cobra.CheckErr(o.Complete(clientGetter, cmd, args)) | ||
cobra.CheckErr(o.Run(cmd.Context())) | ||
}, | ||
} | ||
|
||
o.PrintFlags.AddFlags(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright 2024 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package stop | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
"k8s.io/cli-runtime/pkg/genericiooptions" | ||
|
||
"sigs.k8s.io/kueue/cmd/kueuectl/app/util" | ||
) | ||
|
||
const ( | ||
stopExample = ` # Stop the workload | ||
kueuectl stop workload my-workload` | ||
) | ||
|
||
func NewStopCmd(clientGetter genericclioptions.RESTClientGetter, streams genericiooptions.IOStreams) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "stop", | ||
Short: "Stop the resource", | ||
Example: stopExample, | ||
} | ||
|
||
util.AddDryRunFlag(cmd) | ||
|
||
cmd.AddCommand(NewWorkloadCmd(clientGetter, streams)) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
Copyright 2024 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package stop | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
"k8s.io/cli-runtime/pkg/genericiooptions" | ||
|
||
"sigs.k8s.io/kueue/cmd/kueuectl/app/options" | ||
) | ||
|
||
const ( | ||
wlLong = `Puts the given Workload on hold. The Workload will not be admitted and | ||
if it is already admitted it will be put back to queue just as if it | ||
was preempted (using .spec.active field).` | ||
wlExample = ` # Stop the workload | ||
kueuectl stop workload my-workload` | ||
) | ||
|
||
func NewWorkloadCmd(clientGetter genericclioptions.RESTClientGetter, streams genericiooptions.IOStreams) *cobra.Command { | ||
o := options.NewUpdateWorkloadActivationOptions(streams, "stopped", false) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "workload NAME [--namespace NAMESPACE] [--dry-run STRATEGY]", | ||
// To do not add "[flags]" suffix on the end of usage line | ||
DisableFlagsInUseLine: true, | ||
Aliases: []string{"wl"}, | ||
Short: "Stop the Workload", | ||
Long: wlLong, | ||
Example: wlExample, | ||
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cobra.CheckErr(o.Complete(clientGetter, cmd, args)) | ||
cobra.CheckErr(o.Run(cmd.Context())) | ||
}, | ||
} | ||
|
||
o.PrintFlags.AddFlags(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
title: "Kubectl Kueue Plugin" | ||
linkTitle: "Kubectl Kueue Plugin" | ||
date: 2024-05-09 | ||
weight: 10 | ||
description: > | ||
The kubectl-kueue plugin, kueuectl, allows you to create, resume and stop kueue resources such as localqueue and workload. | ||
--- | ||
|
||
## Syntax | ||
|
||
Use the following syntax to run `kubectl kueue` commands from your terminal window: | ||
|
||
```shell | ||
kubectl kueue [OPERATION] [TYPE] [NAME] [flags] | ||
``` | ||
|
||
or with shorter syntax `kueuectl`: | ||
|
||
```shell | ||
kueuectl [OPERATION] [TYPE] [NAME] [flags] | ||
``` | ||
|
||
You can run `kubectl kueue help` in the terminal to get the full list of commands, along with all possible flags. |
7 changes: 7 additions & 0 deletions
7
site/content/en/docs/reference/kubectl-kueue/commands/_index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: "Commands" | ||
linkTitle: "Commands" | ||
date: 2024-05-10 | ||
weight: 30 | ||
--- | ||
|
Oops, something went wrong.