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] Delete the corresponding Job when deleting a Workload. #2992

Merged
merged 11 commits into from
Sep 24, 2024
2 changes: 1 addition & 1 deletion cmd/kueuectl/app/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func NewKueuectlCmd(o KueuectlOptions) *cobra.Command {
cmd.AddCommand(resume.NewResumeCmd(clientGetter, o.IOStreams))
cmd.AddCommand(stop.NewStopCmd(clientGetter, o.IOStreams))
cmd.AddCommand(list.NewListCmd(clientGetter, o.IOStreams, o.Clock))
cmd.AddCommand(passthrough.NewCommands()...)
cmd.AddCommand(passthrough.NewCommands(clientGetter, o.IOStreams)...)
cmd.AddCommand(version.NewVersionCmd(clientGetter, o.IOStreams))

return cmd
Expand Down
13 changes: 6 additions & 7 deletions cmd/kueuectl/app/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package completion

import (
"slices"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -100,10 +101,6 @@ func UsersFunc(clientGetter util.ClientGetter) func(*cobra.Command, []string, st

func WorkloadNameFunc(clientGetter util.ClientGetter, activeStatus *bool) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) > 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}

clientSet, err := clientGetter.KueueClientSet()
if err != nil {
return []string{}, cobra.ShellCompDirectiveError
Expand All @@ -129,9 +126,11 @@ func WorkloadNameFunc(clientGetter util.ClientGetter, activeStatus *bool) func(*
list.Items = filteredItems
}

validArgs := make([]string, len(list.Items))
for i, wl := range list.Items {
validArgs[i] = wl.Name
var validArgs []string
for _, wl := range list.Items {
if !slices.Contains(args, wl.Name) {
validArgs = append(validArgs, wl.Name)
}
}

return validArgs, cobra.ShellCompDirectiveNoFileComp
Expand Down
3 changes: 2 additions & 1 deletion cmd/kueuectl/app/completion/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ func TestWorkloadNameCompletionFunc(t *testing.T) {
wantNames: []string{"wl2"},
wantDirective: cobra.ShellCompDirectiveNoFileComp,
},
"shouldn't return workload names because only one argument can be passed": {
"should filter workload names": {
objs: []runtime.Object{
utiltesting.MakeWorkload("wl1", metav1.NamespaceDefault).Active(true).Obj(),
utiltesting.MakeWorkload("wl2", metav1.NamespaceDefault).Active(false).Obj(),
},
args: []string{"wl2"},
wantNames: []string{"wl1"},
wantDirective: cobra.ShellCompDirectiveNoFileComp,
},
}
Expand Down
Loading