Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kueuectl] Added list workloads command. #2195

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/kueuectl/app/list/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ func addAllNamespacesFlagVar(cmd *cobra.Command, p *bool) {

func addClusterQueueFilterFlagVar(cmd *cobra.Command, p *string) {
cmd.Flags().StringVarP(p, "clusterqueue", "c", "",
"Filter by cluster queue name which associated with the local queue.")
"Filter by cluster queue name which is associated with the resource.")
}

func addLocalQueueFilterFlagVar(cmd *cobra.Command, p *string) {
cmd.Flags().StringVarP(p, "localqueue", "q", "",
"Filter by local queue name which is associated with the resource.")
}

func addActiveFilterFlagVar(cmd *cobra.Command, p *[]bool) {
Expand Down
1 change: 1 addition & 0 deletions cmd/kueuectl/app/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func NewListCmd(clientGetter util.ClientGetter, streams genericiooptions.IOStrea

cmd.AddCommand(NewLocalQueueCmd(clientGetter, streams))
cmd.AddCommand(NewClusterQueueCmd(clientGetter, streams))
cmd.AddCommand(NewWorkloadCmd(clientGetter, streams))

return cmd
}
8 changes: 1 addition & 7 deletions cmd/kueuectl/app/list/list_clusterqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"k8s.io/cli-runtime/pkg/printers"

"sigs.k8s.io/kueue/apis/kueue/v1beta1"
"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"
Expand Down Expand Up @@ -104,12 +103,7 @@ func NewClusterQueueCmd(clientGetter util.ClientGetter, streams genericiooptions
func (o *ClusterQueueOptions) Complete(clientGetter util.ClientGetter, cmd *cobra.Command, args []string) error {
var err error

config, err := clientGetter.ToRESTConfig()
if err != nil {
return err
}

clientset, err := versioned.NewForConfig(config)
clientset, err := clientGetter.KueueClientSet()
if err != nil {
return err
}
Expand Down
19 changes: 8 additions & 11 deletions cmd/kueuectl/app/list/list_localqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericiooptions"

Expand All @@ -32,8 +33,6 @@ import (
utiltesting "sigs.k8s.io/kueue/pkg/util/testing"
)

const defaultNamespace = "default"

func TestLocalQueueFilter(t *testing.T) {
testCases := map[string]struct {
options *LocalQueueOptions
Expand Down Expand Up @@ -130,13 +129,13 @@ lq1 cq1 1 1 60m
"should print local queue list with clusterqueue filter": {
args: []string{"--clusterqueue", "cq1"},
objs: []runtime.Object{
utiltesting.MakeLocalQueue("lq1", defaultNamespace).
utiltesting.MakeLocalQueue("lq1", metav1.NamespaceDefault).
ClusterQueue("cq1").
PendingWorkloads(1).
AdmittedWorkloads(1).
Creation(testStartTime.Add(-1 * time.Hour).Truncate(time.Second)).
Obj(),
utiltesting.MakeLocalQueue("lq2", defaultNamespace).
utiltesting.MakeLocalQueue("lq2", metav1.NamespaceDefault).
ClusterQueue("cq2").
PendingWorkloads(2).
AdmittedWorkloads(2).
Expand All @@ -150,14 +149,14 @@ lq1 cq1 1 1 60m
"should print local queue list with label selector filter": {
args: []string{"--selector", "key=value1"},
objs: []runtime.Object{
utiltesting.MakeLocalQueue("lq1", defaultNamespace).
utiltesting.MakeLocalQueue("lq1", metav1.NamespaceDefault).
ClusterQueue("cq1").
PendingWorkloads(1).
AdmittedWorkloads(1).
Label("key", "value1").
Creation(testStartTime.Add(-1 * time.Hour).Truncate(time.Second)).
Obj(),
utiltesting.MakeLocalQueue("lq2", defaultNamespace).
utiltesting.MakeLocalQueue("lq2", metav1.NamespaceDefault).
ClusterQueue("cq2").
PendingWorkloads(2).
AdmittedWorkloads(2).
Expand All @@ -172,14 +171,14 @@ lq1 cq1 1 1 60m
"should print local queue list with label selector filter (short flag)": {
args: []string{"-l", "foo=bar"},
objs: []runtime.Object{
utiltesting.MakeLocalQueue("lq1", defaultNamespace).
utiltesting.MakeLocalQueue("lq1", metav1.NamespaceDefault).
ClusterQueue("cq1").
PendingWorkloads(1).
AdmittedWorkloads(1).
Label("foo", "bar").
Creation(testStartTime.Add(-1 * time.Hour).Truncate(time.Second)).
Obj(),
utiltesting.MakeLocalQueue("lq2", defaultNamespace).
utiltesting.MakeLocalQueue("lq2", metav1.NamespaceDefault).
ClusterQueue("cq2").
PendingWorkloads(2).
AdmittedWorkloads(2).
Expand All @@ -191,7 +190,7 @@ lq1 cq1 1 1 60m
`,
},
"should print not found error": {
wantOutErr: fmt.Sprintf("No resources found in %s namespace.\n", defaultNamespace),
wantOutErr: fmt.Sprintf("No resources found in %s namespace.\n", metav1.NamespaceDefault),
},
"should print not found error with all-namespaces filter": {
args: []string{"-A"},
Expand All @@ -205,8 +204,6 @@ lq1 cq1 1 1 60m
tf := cmdtesting.NewTestClientGetter()
if len(tc.ns) > 0 {
tf.WithNamespace(tc.ns)
} else {
tf.WithNamespace(defaultNamespace)
}

tf.ClientSet = fake.NewSimpleClientset(tc.objs...)
Expand Down
96 changes: 92 additions & 4 deletions cmd/kueuectl/app/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
batchv1 "k8s.io/api/batch/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericiooptions"

"sigs.k8s.io/kueue/apis/kueue/v1beta1"
"sigs.k8s.io/kueue/client-go/clientset/versioned/fake"
cmdtesting "sigs.k8s.io/kueue/cmd/kueuectl/app/testing"
utiltesting "sigs.k8s.io/kueue/pkg/util/testing"
Expand All @@ -26,6 +30,7 @@ func TestListCmd(t *testing.T) {
wantErr error
}{
"should print local queue list with all namespaces": {
args: []string{"localqueue", "--all-namespaces"},
objs: []runtime.Object{
utiltesting.MakeLocalQueue("lq1", "ns1").
ClusterQueue("cq1").
Expand All @@ -40,10 +45,95 @@ func TestListCmd(t *testing.T) {
Creation(testStartTime.Add(-2 * time.Hour).Truncate(time.Second)).
Obj(),
},
args: []string{"--all-namespaces"},
wantOut: `NAMESPACE NAME CLUSTERQUEUE PENDING WORKLOADS ADMITTED WORKLOADS AGE
ns1 lq1 cq1 1 1 60m
ns2 lq2 cq2 2 2 120m
`,
},
"should print local queue list with all namespaces (short command and flag)": {
args: []string{"lq", "-A"},
objs: []runtime.Object{
utiltesting.MakeLocalQueue("lq1", "ns1").
ClusterQueue("cq1").
PendingWorkloads(1).
AdmittedWorkloads(1).
Creation(testStartTime.Add(-1 * time.Hour).Truncate(time.Second)).
Obj(),
utiltesting.MakeLocalQueue("lq2", "ns2").
ClusterQueue("cq2").
PendingWorkloads(2).
AdmittedWorkloads(2).
Creation(testStartTime.Add(-2 * time.Hour).Truncate(time.Second)).
Obj(),
},
wantOut: `NAMESPACE NAME CLUSTERQUEUE PENDING WORKLOADS ADMITTED WORKLOADS AGE
ns1 lq1 cq1 1 1 60m
ns2 lq2 cq2 2 2 120m
`,
},
"should print cluster queue list": {
args: []string{"clusterqueue"},
objs: []runtime.Object{
utiltesting.MakeClusterQueue("cq1").
Condition(v1beta1.ClusterQueueActive, metav1.ConditionTrue, "", "").
Cohort("cohort").
Creation(testStartTime.Add(-1 * time.Hour).Truncate(time.Second)).
Obj(),
utiltesting.MakeClusterQueue("cq2").
Condition(v1beta1.ClusterQueueActive, metav1.ConditionFalse, "", "").
Cohort("cohort").
Creation(testStartTime.Add(-2 * time.Hour).Truncate(time.Second)).
Obj(),
},
wantOut: `NAME COHORT PENDING WORKLOADS ADMITTED WORKLOADS ACTIVE AGE
cq1 cohort 0 0 true 60m
cq2 cohort 0 0 false 120m
`,
},
"should print workload list with all namespaces": {
args: []string{"workload", "--all-namespaces"},
objs: []runtime.Object{
utiltesting.MakeWorkload("wl1", "ns1").
OwnerReference(batchv1.SchemeGroupVersion.WithKind("Job"), "j1", "test-uid").
Queue("lq1").
Active(true).
Admission(utiltesting.MakeAdmission("cq1").Obj()).
Creation(testStartTime.Add(-1 * time.Hour).Truncate(time.Second)).
Obj(),
utiltesting.MakeWorkload("wl2", "ns2").
OwnerReference(rayv1.GroupVersion.WithKind("RayJob"), "j2", "test-uid").
Queue("lq2").
Active(true).
Admission(utiltesting.MakeAdmission("cq2").Obj()).
Creation(testStartTime.Add(-2 * time.Hour).Truncate(time.Second)).
Obj(),
},
wantOut: `NAMESPACE NAME JOB TYPE JOB NAME LOCALQUEUE CLUSTERQUEUE STATUS POSITION IN QUEUE AGE
ns1 wl1 j1 lq1 cq1 PENDING 60m
ns2 wl2 j2 lq2 cq2 PENDING 120m
`,
},
"should print workload list with all namespaces (short command and flag)": {
args: []string{"wl", "-A"},
objs: []runtime.Object{
utiltesting.MakeWorkload("wl1", "ns1").
OwnerReference(batchv1.SchemeGroupVersion.WithKind("Job"), "j1", "test-uid").
Queue("lq1").
Active(true).
Admission(utiltesting.MakeAdmission("cq1").Obj()).
Creation(testStartTime.Add(-1 * time.Hour).Truncate(time.Second)).
Obj(),
utiltesting.MakeWorkload("wl2", "ns2").
OwnerReference(rayv1.GroupVersion.WithKind("RayJob"), "j2", "test-uid").
Queue("lq2").
Active(true).
Admission(utiltesting.MakeAdmission("cq2").Obj()).
Creation(testStartTime.Add(-2 * time.Hour).Truncate(time.Second)).
Obj(),
},
wantOut: `NAMESPACE NAME JOB TYPE JOB NAME LOCALQUEUE CLUSTERQUEUE STATUS POSITION IN QUEUE AGE
ns1 wl1 j1 lq1 cq1 PENDING 60m
ns2 wl2 j2 lq2 cq2 PENDING 120m
`,
},
}
Expand All @@ -54,13 +144,11 @@ ns2 lq2 cq2 2 2 120m
tf := cmdtesting.NewTestClientGetter()
if len(tc.ns) > 0 {
tf.WithNamespace(tc.ns)
} else {
tf.WithNamespace(defaultNamespace)
}

tf.ClientSet = fake.NewSimpleClientset(tc.objs...)

cmd := NewLocalQueueCmd(tf, streams)
cmd := NewListCmd(tf, streams)
cmd.SetArgs(tc.args)

gotErr := cmd.Execute()
Expand Down
Loading