Skip to content

Commit

Permalink
Various fixes after review:
Browse files Browse the repository at this point in the history
- add differenciated gitignore
- add nul and emptyness checks in frontend
- remove util.go
- document GVR uniformly
- use GVR when forgotten
- remove unused code
  • Loading branch information
akram committed Dec 4, 2024
1 parent dc2f8b3 commit 3a70689
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 61 deletions.
6 changes: 0 additions & 6 deletions cmd/experimental/kueue-viz/.gitignore

This file was deleted.

2 changes: 2 additions & 0 deletions cmd/experimental/kueue-viz/backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/

23 changes: 5 additions & 18 deletions cmd/experimental/kueue-viz/backend/handlers/cluster_queues.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@ import (
"github.com/gin-gonic/gin"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
)

// ClusterQueuesWebSocketHandler streams all cluster queues
func ClusterQueuesWebSocketHandler(dynamicClient dynamic.Interface) gin.HandlerFunc {
clusterQueuesGVR := schema.GroupVersionResource{
Group: "kueue.x-k8s.io",
Version: "v1beta1",
Resource: "clusterqueues",
}

return GenericWebSocketHandler(dynamicClient, clusterQueuesGVR, "", func() (interface{}, error) {
return GenericWebSocketHandler(dynamicClient, ClusterQueuesGVR(), "", func() (interface{}, error) {
return fetchClusterQueues(dynamicClient)
})
}
Expand All @@ -28,13 +21,7 @@ func ClusterQueuesWebSocketHandler(dynamicClient dynamic.Interface) gin.HandlerF
func ClusterQueueDetailsWebSocketHandler(dynamicClient dynamic.Interface) gin.HandlerFunc {
return func(c *gin.Context) {
clusterQueueName := c.Param("cluster_queue_name")
clusterQueuesGVR := schema.GroupVersionResource{
Group: "kueue.x-k8s.io",
Version: "v1beta1",
Resource: "clusterqueues",
}

GenericWebSocketHandler(dynamicClient, clusterQueuesGVR, "", func() (interface{}, error) {
GenericWebSocketHandler(dynamicClient, ClusterQueuesGVR(), "", func() (interface{}, error) {
return fetchClusterQueueDetails(dynamicClient, clusterQueueName)
})(c)
}
Expand All @@ -43,7 +30,7 @@ func ClusterQueueDetailsWebSocketHandler(dynamicClient dynamic.Interface) gin.Ha
// Fetch all cluster queues
func fetchClusterQueues(dynamicClient dynamic.Interface) ([]map[string]interface{}, error) {
// Fetch the list of ClusterQueue objects
clusterQueues, err := dynamicClient.Resource(ClusterQueueGVR()).List(context.TODO(), metav1.ListOptions{})
clusterQueues, err := dynamicClient.Resource(ClusterQueuesGVR()).List(context.TODO(), metav1.ListOptions{})
if err != nil {
return nil, fmt.Errorf("error fetching cluster queues: %v", err)
}
Expand Down Expand Up @@ -108,7 +95,7 @@ func fetchClusterQueues(dynamicClient dynamic.Interface) ([]map[string]interface
func fetchClusterQueueDetails(dynamicClient dynamic.Interface, clusterQueueName string) (map[string]interface{}, error) {

// Fetch the specific ClusterQueue
clusterQueue, err := dynamicClient.Resource(ClusterQueueGVR()).Get(context.TODO(), clusterQueueName, metav1.GetOptions{})
clusterQueue, err := dynamicClient.Resource(ClusterQueuesGVR()).Get(context.TODO(), clusterQueueName, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("error fetching cluster queue %s: %v", clusterQueueName, err)
}
Expand Down Expand Up @@ -158,6 +145,6 @@ func fetchClusterQueueDetails(dynamicClient dynamic.Interface, clusterQueueName
}

func fetchClusterQueuesList(dynamicClient dynamic.Interface) (*unstructured.UnstructuredList, error) {
clusterQueues, err := dynamicClient.Resource(ClusterQueueGVR()).List(context.TODO(), metav1.ListOptions{})
clusterQueues, err := dynamicClient.Resource(ClusterQueuesGVR()).List(context.TODO(), metav1.ListOptions{})
return clusterQueues, err
}
22 changes: 10 additions & 12 deletions cmd/experimental/kueue-viz/backend/handlers/gvr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,16 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
)

// Define the GroupVersionResource for ResourceFlavors
func ResourceFlavorGVR() schema.GroupVersionResource {
return schema.GroupVersionResource{
Group: "kueue.x-k8s.io",
Version: "v1beta1",
Resource: "resourceflavors",
}
}

// Define the GroupVersionResource for ClusterQueues
func ClusterQueueGVR() schema.GroupVersionResource {
// ClusterQueuesGVR defines the GroupVersionResource for ClusterQueues
func ClusterQueuesGVR() schema.GroupVersionResource {
return schema.GroupVersionResource{
Group: "kueue.x-k8s.io",
Version: "v1beta1",
Resource: "clusterqueues",
}
}

// WorkloadsGVR defines the GroupVersionResource for Workloads
func WorkloadsGVR() schema.GroupVersionResource {
workloadsGVR := schema.GroupVersionResource{
Group: "kueue.x-k8s.io",
Expand All @@ -31,6 +23,7 @@ func WorkloadsGVR() schema.GroupVersionResource {
return workloadsGVR
}

// LocalQueuesGVR defines the GroupVersionResource for LocalQueues
func LocalQueuesGVR() schema.GroupVersionResource {
localQueuesGVR := schema.GroupVersionResource{
Group: "kueue.x-k8s.io",
Expand All @@ -40,6 +33,7 @@ func LocalQueuesGVR() schema.GroupVersionResource {
return localQueuesGVR
}

// CohortsGVR defines the GroupVersionResource for Cohorts
func CohortsGVR() schema.GroupVersionResource {
cohortsGVR := schema.GroupVersionResource{
Group: "kueue.x-k8s.io",
Expand All @@ -49,6 +43,7 @@ func CohortsGVR() schema.GroupVersionResource {
return cohortsGVR
}

// ResourceFlavorsGVR defines the GroupVersionResource for ResourceFlavors
func ResourceFlavorsGVR() schema.GroupVersionResource {
resourceFlavorsGVR := schema.GroupVersionResource{
Group: "kueue.x-k8s.io",
Expand All @@ -58,7 +53,8 @@ func ResourceFlavorsGVR() schema.GroupVersionResource {
return resourceFlavorsGVR
}

func NodeGVR() schema.GroupVersionResource {
// NodesGVR defines the GroupVersionResource for Nodes
func NodesGVR() schema.GroupVersionResource {
nodeGVR := schema.GroupVersionResource{
Group: "",
Version: "v1",
Expand All @@ -67,6 +63,7 @@ func NodeGVR() schema.GroupVersionResource {
return nodeGVR
}

// EventsGVR defines the GroupVersionResource for Events
func EventsGVR() schema.GroupVersionResource {
eventsGVR := schema.GroupVersionResource{
Group: "",
Expand All @@ -76,6 +73,7 @@ func EventsGVR() schema.GroupVersionResource {
return eventsGVR
}

// PodsGVR defines the GroupVersionResource Pods
func PodsGVR() schema.GroupVersionResource {
podsGVR := schema.GroupVersionResource{
Group: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func fetchResourceFlavorDetails(dynamicClient dynamic.Interface, flavorName stri
}

// List all cluster queues
clusterQueues, err := dynamicClient.Resource(ClusterQueueGVR()).List(context.TODO(), metav1.ListOptions{})
clusterQueues, err := dynamicClient.Resource(ClusterQueuesGVR()).List(context.TODO(), metav1.ListOptions{})
if err != nil {
return nil, fmt.Errorf("error listing cluster queues: %v", err)
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func getNodesForFlavor(dynamicClient dynamic.Interface, flavorName string) ([]ma
}

// List all nodes
nodeList, err := dynamicClient.Resource(NodeGVR()).List(context.TODO(), metav1.ListOptions{})
nodeList, err := dynamicClient.Resource(NodesGVR()).List(context.TODO(), metav1.ListOptions{})
if err != nil {
return nil, fmt.Errorf("error fetching nodes: %v", err)
}
Expand Down
20 changes: 0 additions & 20 deletions cmd/experimental/kueue-viz/backend/utils/utils.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
---
apiVersion: kueue.x-k8s.io/v1beta1
kind: ResourceFlavor
metadata:
Expand Down
5 changes: 5 additions & 0 deletions cmd/experimental/kueue-viz/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
package-lock.json
build/
yarn.lock

4 changes: 2 additions & 2 deletions cmd/experimental/kueue-viz/frontend/src/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const Dashboard = () => {

useEffect(() => {
if (kueueData) {
setQueues(kueueData.queues.items || []);
setWorkloads(kueueData.workloads.items || []);
setQueues(kueueData.queues?.items || []);
setWorkloads(kueueData.workloads?.items || []);
setWorkloadsByUid(kueueData.workloads.workloads_by_uid || {});

kueueData.workloads?.items?.forEach(workload => {
Expand Down

0 comments on commit 3a70689

Please sign in to comment.