Skip to content

Commit

Permalink
Various fixes after 2nd review:
Browse files Browse the repository at this point in the history
- Adding README.md instructions on how to run on kind
- Removing OpenShift instructions
- Cleaning env files
- Adding Copyright header in .js and .go files
- Aligning image builders and golang versions
  • Loading branch information
akram committed Dec 4, 2024
1 parent 4205f37 commit d86e34b
Show file tree
Hide file tree
Showing 41 changed files with 583 additions and 78 deletions.
2 changes: 2 additions & 0 deletions cmd/experimental/kueue-viz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kubeconfig

2 changes: 1 addition & 1 deletion cmd/experimental/kueue-viz/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@

END OF TERMS AND CONDITIONS

Copyright 2014 Red Hat, Inc.
Copyright 2024, The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
85 changes: 53 additions & 32 deletions cmd/experimental/kueue-viz/README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,83 @@
# Build and run on OpenShift
# Build and Run locally

## Prerequisites
You need a kubernetes cluster running kueue.
If you don't have a running cluster, you can create one using kind and install kueue using helm.

```
git clone https://github.com/akram/kueue-viz.git
oc new-project kueue-viz
KUEUE_VIZ_HOME=$PWD/kueue-viz
kind create cluster
kind get kubeconfig > kubeconfig
export KUBECONFIG=$PWD/kubeconfig
helm install kueue oci://us-central1-docker.pkg.dev/k8s-staging-images/charts/kueue \
--version="v0.9.1" --create-namespace --namespace=kueue-system
```

then:
## Build
Clone the kueue repository and build the projects:

```
git clone https://github.com/kubernetes-sigs/kueue
cd kueue/cmd/experimental/kueue-viz
KUEUE_VIZ_HOME=$PWD
kubectl create ns kueue-viz
cd backend && make && cd ..
cd frontend && make && cd ..
```

## Authorize
Creating a cluster role that just has read only access on
Create a cluster role that just has read only access on
`kueue` objects and pods, nodes and events.

Create the cluster role:

```
oc create clusterrole kueue-backend-read-access --verb=get,list,watch \
--resource=workloads,clusterqueues,localqueues,resourceflavors,pods,workloadpriorityclass,events,nodes
oc adm policy add-cluster-role-to-user kueue-backend-read-access -z default
kubectl create clusterrole kueue-backend-read-access --verb=get,list,watch \
--resource=workloads,clusterqueues,localqueues,resourceflavors,pods,workloadpriorityclass,events,nodes
```

## Build
and bind it to the service account `default` in the `kueue-viz` namespace:

```
for i in backend frontend
do
oc new-build . --name $i --context-dir=$i
done
kubectl create -f - << EOF
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kueue-backend-read-access-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kueue-backend-read-access
subjects:
- kind: ServiceAccount
name: default
namespace: kueue-viz
EOF
```
## Run

## Deploy
In a first terminal run:
```
oc new-app backend --name=backend
oc new-app frontend --name=frontend
cd backend && make debug
```

## Expose
```
oc create route edge --service=svc/backend
oc create route edge --service=svc/frontend
```
In another terminal run:

## Configure
```
BACKEND_URL=$(oc get route backend -o jsonpath='{.spec.host}')
FRONTEND_URL=$(oc get route frontend -o jsonpath='{.spec.host}')
oc set env deployment/backend FRONTEND_URL=https://$FRONTEND_URL
oc set env deployment/frontend REACT_APP_BACKEND_URL=https://$BACKEND_URL \
REACT_APP_WEBSOCKET_URL=wss://$BACKEND_URL
cd frontend && make debug
```


## Test
Create test data using the resources in `examples/` directory.

```
oc create -f https://raw.githubusercontent.com/opendatahub-io/distributed-workloads/2c6a14f792b8d94ad3fc2146316e52ace33b6a1e/examples/kueue-usage/kueue-with-jobs/00-common.yaml
oc create -f examples/
```
And check that you have some data in the Resource Flavors tab of the application.
And check that you have some data on the dashboard.

## Improve

See [contribution guide](CONTRIBUTING.md)





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

41 changes: 10 additions & 31 deletions cmd/experimental/kueue-viz/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Build stage
FROM golang:latest as builder

# Install necessary tools for building
# RUN apk add --no-cache gcc musl-dev

# Set the working directory
WORKDIR /app
ARG BUILDER_IMAGE=golang:1.23
ARG BASE_IMAGE=gcr.io/distroless/static:nonroot
FROM --platform=${BUILDPLATFORM} ${BUILDER_IMAGE} AS builder

# Copy Go modules manifests and download dependencies
COPY go.mod go.sum ./
Expand All @@ -15,38 +11,21 @@ RUN go mod download
COPY . .

# Build the application
RUN go build -o app .
RUN CGO_ENABLED=0 go build -o /kueue-viz

# Runtime stage
FROM golang:latest
USER root
# Install CA certificates for HTTPS support
# RUN apk add --no-cache ca-certificates

# Set environment variables
ENV PORT=8080

# Create a non-root user
# RUN adduser -D appuser
# USER nobody

# Set the working directory
WORKDIR /app
FROM --platform=${BUILDPLATFORM} ${BASE_IMAGE}
USER 65532:65532

# Copy the built application from the builder stage
COPY --from=builder /app/app .

# Change ownership to the non-root user
RUN useradd nobody || true && groupadd nobody || true
RUN chown -R nobody:nobody /app

# Run as the non-root user
USER nobody
COPY --from=builder /kueue-viz /

# Set environment variables
ENV PORT=8080
# Expose the application port
EXPOSE 8080

# Command to run the application
ENTRYPOINT ["./app"]
ENTRYPOINT ["/kueue-viz"]


6 changes: 3 additions & 3 deletions cmd/experimental/kueue-viz/backend/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Makefile for kueue-viz-go

APP_NAME := kueue_ws_app
MODULE_NAME := github.com/akram/kueue-viz-go
APP_NAME := kueue-viz
MODULE_NAME := kueue-viz

.PHONY: all build run test tidy clean help

Expand All @@ -21,7 +21,7 @@ run: build
## Run debug
debug: build
@echo "Running in debug mode with hot code replacement enabled..."
CompileDaemon --build="make" --command=./bin/kueue_ws_app
CompileDaemon --build="make" --command=./bin/$(APP_NAME)

## Run tests
test:
Expand Down
6 changes: 2 additions & 4 deletions cmd/experimental/kueue-viz/backend/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/akram/kueue-viz-go
module kueue-viz

go 1.22.0

toolchain go1.22.5
go 1.23.0

require (
github.com/gin-gonic/gin v1.10.0
Expand Down
15 changes: 15 additions & 0 deletions cmd/experimental/kueue-viz/backend/handlers/cluster_queues.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package handlers

import (
Expand Down
15 changes: 15 additions & 0 deletions cmd/experimental/kueue-viz/backend/handlers/cohorts.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package handlers

import (
Expand Down
15 changes: 15 additions & 0 deletions cmd/experimental/kueue-viz/backend/handlers/gvr.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package handlers

import (
Expand Down
15 changes: 15 additions & 0 deletions cmd/experimental/kueue-viz/backend/handlers/handlers.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package handlers

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package handlers

import (
Expand Down
15 changes: 15 additions & 0 deletions cmd/experimental/kueue-viz/backend/handlers/local_queues.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package handlers

import (
Expand Down
15 changes: 15 additions & 0 deletions cmd/experimental/kueue-viz/backend/handlers/resource_flavors.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package handlers

import (
Expand Down
15 changes: 15 additions & 0 deletions cmd/experimental/kueue-viz/backend/handlers/websocket_handler.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package handlers

import (
Expand Down
15 changes: 15 additions & 0 deletions cmd/experimental/kueue-viz/backend/handlers/workloads.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package handlers

import (
Expand Down
Loading

0 comments on commit d86e34b

Please sign in to comment.