Skip to content

Commit

Permalink
[kueuectl] Added resourceflavor to passthrough.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbobrovskyi committed Jul 2, 2024
1 parent 398545f commit eca5f99
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 26 deletions.
2 changes: 1 addition & 1 deletion apis/kueue/v1beta1/resourceflavor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
// +genclient:nonNamespaced
// +kubebuilder:object:root=true
// +kubebuilder:storageversion
// +kubebuilder:resource:scope=Cluster,shortName={flavor,flavors}
// +kubebuilder:resource:scope=Cluster,shortName={flavor,flavors,rf}

// ResourceFlavor is the Schema for the resourceflavors API.
type ResourceFlavor struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ spec:
shortNames:
- flavor
- flavors
- rf
singular: resourceflavor
scope: Cluster
versions:
Expand Down
3 changes: 2 additions & 1 deletion cmd/kueuectl/app/passthrough/passthrough.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ var (
passThroughTypes = []passThroughType{
{name: "workload", aliases: []string{"wl"}},
{name: "clusterqueue", aliases: []string{"cq"}},
{name: "localqueue", aliases: []string{"lq"}}}
{name: "localqueue", aliases: []string{"lq"}},
{name: "resourceflavor", aliases: []string{"rf"}}}
)

func NewCommands() ([]*cobra.Command, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ spec:
shortNames:
- flavor
- flavors
- rf
singular: resourceflavor
scope: Cluster
versions:
Expand Down
10 changes: 5 additions & 5 deletions keps/2076-kueuectl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ None.
For completeness there will be 5 additional commands that will simply execute regular kubectl
so that the users won't have to remember to switch the command to kubectl.

* `get workload|clusterqueue|cq|localqueue|lq`
* `describe workload|clusterqueue|cq|localqueue|lq`
* `edit workload|clusterqueue|cq|localqueue|lq`
* `patch workload|clusterqueue|cq|localqueue|lq`
* `delete workload|clusterqueue|cq|localqueue|lq`
* `get workload|wl|clusterqueue|cq|localqueue|lq|resourceflavor|rf`
* `describe workload|wl|clusterqueue|cq|localqueue|lq|resourceflavor|rf`
* `edit workload|wl|clusterqueue|cq|localqueue|lq|resourceflavor|rf`
* `patch workload|wl|clusterqueue|cq|localqueue|lq|resourceflavor|rf`
* `delete workload|wl|clusterqueue|cq|localqueue|lq|resourceflavor|rf`

### Test Plan

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,21 @@ kubectl kueue delete cq my-cluster-queue

The following table includes a list of commands that are passed through to `kubectl`.

| Name | Short |
|------------|--------------------------------------------------------------------------------------------------|
| get | Display one or many resources
| describe | Show details of a specific resource or group of resources
| edit | Edit a resource on the server
| patch | Update fields of a resource
| delete | Delete resources by file names, stdin, resources and names, or by resources and label selector
| Name | Description |
|------------|------------------------------------------------------------------------------------------------|
| get | Display one or many resources |
| describe | Show details of a specific resource or group of resources |
| edit | Edit a resource on the server |
| patch | Update fields of a resource |
| delete | Delete resources by file names, stdin, resources and names, or by resources and label selector |

## Resource types

The following table includes a list of all the supported resource types and their abbreviated aliases:

| Name | Short | API version | Namespaced | Kind |
|--------------|-------|------------------------|------------|--------------|
| workload | wl | kueue.x-k8s.io/v1beta1 | true | Workload |
| clusterqueue | cq | kueue.x-k8s.io/v1beta1 | false | ClusterQueue |
| localqueue | lq | kueue.x-k8s.io/v1beta1 | true | LocalQueue |
| Name | Short | API version | Namespaced | Kind |
|----------------|-------|------------------------|------------|----------------|
| workload | wl | kueue.x-k8s.io/v1beta1 | true | Workload |
| clusterqueue | cq | kueue.x-k8s.io/v1beta1 | false | ClusterQueue |
| localqueue | lq | kueue.x-k8s.io/v1beta1 | true | LocalQueue |
| resourceflavor | rf | kueue.x-k8s.io/v1beta1 | false | ResourceFlavor |
19 changes: 14 additions & 5 deletions test/integration/kueuectl/passthrough_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func makePassThroughWorkload(ns string) client.Object {
return testing.MakeWorkload("pass-through-wl", ns).Obj()
}

func makePassThroughResourceFlavor(_ string) client.Object {
return testing.MakeResourceFlavor("pass-through-resource-flavor").Label("type", "small").Obj()
}

func setupEnv(c *exec.Cmd, kassetsPath string, kubeconfigPath string) {
c.Env = os.Environ()
cmdPath := os.Getenv("PATH")
Expand Down Expand Up @@ -70,13 +74,16 @@ var _ = ginkgo.Describe("Kueuectl Pass-through", ginkgo.Ordered, ginkgo.Continue
gomega.Expect(k8sClient.Create(ctx, obj)).To(gomega.Succeed())
key := client.ObjectKeyFromObject(obj)

identityArgs := []string{oType, key.Name, "-n", key.Namespace}
identityArgs := []string{oType, key.Name}
if len(key.Namespace) > 0 {
identityArgs = append(identityArgs, "-n", key.Namespace)
}

ginkgo.By("Get the object", func() {
args := append([]string{"get"}, identityArgs...)
args = append(args, fmt.Sprintf("-o=jsonpath='%s'", getPath))
cmd := exec.Command(kueuectlPath, args...)
setupEnv(cmd, kassetsPath, kubeconfigPath)
setupEnv(cmd, kAssetsPath, kubeconfigPath)
out, err := cmd.CombinedOutput()
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "%q", string(out))
gomega.Expect(string(out)).To(gomega.BeComparableTo(expectGet))
Expand All @@ -86,14 +93,14 @@ var _ = ginkgo.Describe("Kueuectl Pass-through", ginkgo.Ordered, ginkgo.Continue
args := append([]string{"patch"}, identityArgs...)
args = append(args, "--type=merge", "-p", patch)
cmd := exec.Command(kueuectlPath, args...)
setupEnv(cmd, kassetsPath, kubeconfigPath)
setupEnv(cmd, kAssetsPath, kubeconfigPath)
out, err := cmd.CombinedOutput()
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "%q", string(out))

args = append([]string{"get"}, identityArgs...)
args = append(args, fmt.Sprintf("-o=jsonpath='%s'", getPath))
cmd = exec.Command(kueuectlPath, args...)
setupEnv(cmd, kassetsPath, kubeconfigPath)
setupEnv(cmd, kAssetsPath, kubeconfigPath)
out, err = cmd.CombinedOutput()
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "%q", string(out))
gomega.Expect(string(out)).To(gomega.BeComparableTo(expectGetAfterPatch))
Expand All @@ -102,7 +109,7 @@ var _ = ginkgo.Describe("Kueuectl Pass-through", ginkgo.Ordered, ginkgo.Continue
ginkgo.By("Delete the object", func() {
args := append([]string{"delete"}, identityArgs...)
cmd := exec.Command(kueuectlPath, args...)
setupEnv(cmd, kassetsPath, kubeconfigPath)
setupEnv(cmd, kAssetsPath, kubeconfigPath)
out, err := cmd.CombinedOutput()
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "%q", string(out))

Expand All @@ -113,5 +120,7 @@ var _ = ginkgo.Describe("Kueuectl Pass-through", ginkgo.Ordered, ginkgo.Continue
},
ginkgo.Entry("Workload", "workload", makePassThroughWorkload, "{.spec.active}", "'true'", `{"spec":{"active":false}}`, "'false'"),
ginkgo.Entry("Workload(short)", "wl", makePassThroughWorkload, "{.spec.active}", "'true'", `{"spec":{"active":false}}`, "'false'"),
ginkgo.Entry("ResourceFlavor", "resourceflavor", makePassThroughResourceFlavor, "{.spec.nodeLabels.type}", "'small'", `{"spec":{"nodeLabels":{"type":"large"}}}`, "'large'"),
ginkgo.Entry("ResourceFlavor(short)", "rf", makePassThroughResourceFlavor, "{.spec.nodeLabels.type}", "'small'", `{"spec":{"nodeLabels":{"type":"large"}}}`, "'large'"),
)
})
4 changes: 2 additions & 2 deletions test/integration/kueuectl/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var (
webhookPath = filepath.Join("..", "..", "..", "config", "components", "webhook")

kueuectlPath string
kassetsPath string
kAssetsPath string
kubeconfigPath string
)

Expand All @@ -63,7 +63,7 @@ var _ = ginkgo.BeforeSuite(func() {
cfg = fwk.Init()
ctx, k8sClient = fwk.RunManager(cfg, managerSetup)

kassetsPath = os.Getenv("KUBEBUILDER_ASSETS")
kAssetsPath = os.Getenv("KUBEBUILDER_ASSETS")
kueuectlPath = path.Join(os.Getenv("KUEUE_BIN"), "kubectl-kueue")
kubeconfigPath = path.Join(ginkgo.GinkgoT().TempDir(), "testing.kubeconfig")
configBites, err := utiltesting.RestConfigToKubeConfig(cfg)
Expand Down

0 comments on commit eca5f99

Please sign in to comment.