Skip to content

Commit

Permalink
[kueuectl] Delete the corresponding Job when deleting a Workload. (#2992
Browse files Browse the repository at this point in the history
)

* Delete the corresponding Job when deleting a Workload.

* Fix workload completion func.

* Add delete confirmation.

* Allow to delete all workloads.

* Use unit tests instead integration.

* Ignore out for delete all workloads.

* Fix typos.

* Remove unnecessary resources on unit-tests.

* Fixes accordingly to the KEP updates.

* Rephrase description.

Co-authored-by: Traian Schiau <traian_schiau@epam.com>

* Delete cascade strategy.

---------

Co-authored-by: Traian Schiau <traian_schiau@epam.com>
  • Loading branch information
mbobrovskyi and trasc authored Sep 24, 2024
1 parent f378233 commit cf8d196
Show file tree
Hide file tree
Showing 17 changed files with 931 additions and 28 deletions.
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

0 comments on commit cf8d196

Please sign in to comment.