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

Updates to apiserver swagger ui #1387

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4519007
Updates to apiserver swagger ui
z103cb Sep 4, 2023
f358de5
Fixed typo in response to PR comment.
z103cb Sep 6, 2023
b88d4bd
Swagger file path can be specified in command line
z103cb Sep 8, 2023
c58dc87
[GCS FT] Consider the case of sidecar containers (#1386)
kevin85421 Sep 5, 2023
d7ee145
[CI] Remove RayService tests from comopatibility-test.py (#1395)
kevin85421 Sep 5, 2023
93c9c78
[RayJob] Enable job log streaming by setting `PYTHONUNBUFFERED` in jo…
architkulkarni Sep 6, 2023
6be9d47
Update Volcano integration doc (#1380)
Sep 6, 2023
aef1e08
Update Autoscaler YAML for the Autoscaler tutorial (#1400)
kevin85421 Sep 6, 2023
23d8894
[Feature] Use image of Ray head container as the default Ray Autoscal…
kevin85421 Sep 7, 2023
e036fa4
[services] Add text ml rayservice yaml (#1402)
zcin Sep 7, 2023
44c11a5
[serve] Change text ml yaml to use french in user config (#1403)
zcin Sep 8, 2023
4c2cc45
fix: Issue #1391 - Custom labels not being pulled in (#1398)
rxraghu Sep 8, 2023
46ff061
implemented liveness/readyness probe for the API server (#1369)
blublinsky Sep 8, 2023
4a80a27
Bump golang.org/x/sys in /cli (#1347)
dependabot[bot] Sep 8, 2023
d46e449
Update GCS fault tolerance YAML (#1404)
kevin85421 Sep 8, 2023
8eb5b09
Bump github.com/emicklei/go-restful in /ray-operator (#1348)
dependabot[bot] Sep 8, 2023
b007e51
Bump golang.org/x/net in /cli (#1405)
dependabot[bot] Sep 8, 2023
8a6c516
Bump golang.org/x/sys in /proto (#1346)
dependabot[bot] Sep 8, 2023
8c7d172
Bump go.mongodb.org/mongo-driver from 1.3.4 to 1.5.1 in /apiserver (#…
dependabot[bot] Sep 8, 2023
a66d342
Bump golang.org/x/text from 0.3.5 to 0.3.8 in /proto (#1344)
dependabot[bot] Sep 8, 2023
4863b2e
Bump golang.org/x/net in /proto (#1345)
dependabot[bot] Sep 8, 2023
b1cc136
Swagger file path can be specified in command line
z103cb Sep 8, 2023
e267f99
Fixed bad merge
z103cb Sep 11, 2023
4c53e47
Merge branch 'master' into z103cb/issue1343
z103cb Sep 11, 2023
6946b04
[GCS FT] Consider the case of sidecar containers (#1386)
kevin85421 Sep 5, 2023
f34405c
[CI] Remove RayService tests from comopatibility-test.py (#1395)
kevin85421 Sep 5, 2023
7ad5de4
[services] Add text ml rayservice yaml (#1402)
zcin Sep 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@
# Dependency directories (remove the comment below to include it)
**/vendor/

.ipynb_checkpoints
.ipynb_checkpoints

# Any file with a .backup extension
**/*.backup
51 changes: 49 additions & 2 deletions apiserver/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Typing `make dev-tools` will download and install all of them. The `make clean-d
| kustomize | v3.8.7 | [install](https://kubectl.docs.kubernetes.io/installation/kustomize/) |
| gofumpt | v0.3.1 | To install `go install mvdan.cc/[email protected]` |
| goimports | latest | To install `go install golang.org/x/tools/cmd/goimports@latest` |
| go-bindata | v4.0.2 | To install `github.com/kevinburke/go-bindata/v4/[email protected]` |

## Purpose

Expand Down Expand Up @@ -60,6 +61,52 @@ make build
make test
```

#### Swagger UI updates

To update the swagger ui files deployed with the Kuberay API server, you'll need to:

* Manually run the [hack/update-swagger-ui.bash](hack/update-swagger-ui.bash) script. The script downloads the swagger ui release and copies the files
located in the [.../third_party/swagger-ui](../third_party/swagger-ui/) directory. It copies the [swagger-initializer.js](../third_party/swagger-ui/swagger-initializer.js)
to [swagger-initializer.js.backup](../third_party/swagger-ui/swagger-initializer.js.backup).
* Update the contents of the [swagger-initializer.js](../third_party/swagger-ui/swagger-initializer.js) to set the URLs for for the individual swagger docs. The content of the file is show below:

```javascript
window.onload = function() {
//<editor-fold desc="Changeable Configuration Block">

// the following lines will be replaced by docker/configurator, when it runs in a docker-container
window.ui = SwaggerUIBundle({
spec: location.host,
urls: [{"url":"http://"+location.host+"/swagger/serve.swagger.json","name":"RayServe Service"},
{"url":"http://"+location.host+"/swagger/error.swagger.json","name":"Errors API"},
{"url":"http://"+location.host+"/swagger/job.swagger.json","name":"RayJob Service"},
{"url":"http://"+location.host+"/swagger/config.swagger.json","name":"ComputeTemplate Service"},
{"url":"http://"+location.host+"/swagger/cluster.swagger.json","name":"Cluster Service"}],
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});

//</editor-fold>
};
```

* Execute `make build-swagger` target to update the contents of the [datafile.go](pkg/swagger/datafile.go) file. This will package the content of the [swagger-ui](../third_party/swagger-ui/) directory for serving by the api server (see [func serveSwaggerUI(mux *http.ServeMux)](https://github.com/ray-project/kuberay/blob/f1067378bc99987f3eba1e5b12b4cc797465336d/apiserver/cmd/main.go#L149) in [main.go](cmd/main.go))

The swagger ui is available at the following URLs:

* [local service -- http://localhost:8888/swagger-ui/](http://localhost:8888/swagger-ui/)
* [kind cluster -- http://localhost:31888/swagger-ui/](http://localhost:31888/swagger-ui/)

Please note that for the local service the directory containing the `*.swagger.files` is specified using the `-localSwaggerPath` command line argument. The `make run` command sets the value correctly.

#### Start Local Service

This will start the api server on your development machine. The golang race detector is turned on when starting the api server this way. It will use Kubernetes configuration file located at `~/.kube/config`. The service will not start if you do not have a connection to a Kubernetes cluster.
Expand Down Expand Up @@ -110,7 +157,7 @@ make uninstall

As a convenience for local development the following `make` targets are provided:

* `make cluster` -- creates a local kind cluster, using the configuration from `hack/kind-cluster-config.yaml`. It creates a port mapping allowing for the service running in the kind cluster to be accessed on `localhost:318888` for HTTP and `localhost:318887` for RPC.
* `make cluster` -- creates a local kind cluster, using the configuration from `hack/kind-cluster-config.yaml`. It creates a port mapping allowing for the service running in the kind cluster to be accessed on `localhost:31888` for HTTP and `localhost:31887` for RPC.
* `make clean-cluster` -- deletes the local kind cluster created with `make cluster`
* `load-image` -- loads the docker image defined by the `IMG` make variable into the kind cluster. The default value for variable is: `kuberay/apiserver:latest`. The name of the image can be changed by using `make load-image -e IMG=<your image name and tag>`
* `operator-image` -- Build the operator image to be loaded in your kind cluster. The tag for the operator image is `kuberay/operator:latest`. This step is optional.
Expand All @@ -130,4 +177,4 @@ make docker-image operator-image cluster load-image load-operator-image deploy d

#### Access API Server in the Cluster

Access the service at `localhost:318888` for http and `locahost:318887` for the RPC port.
Access the service at `localhost:31888` for http and `locahost:31887` for the RPC port.
19 changes: 16 additions & 3 deletions apiserver/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
BUILD_TIME := $(shell date "+%F %T")
COMMIT_SHA1 := $(shell git rev-parse HEAD )
REPO_ROOT_BIN := $(shell dirname ${PWD})/bin
REPO_ROOT := $(shell dirname ${PWD})
REPO_ROOT_BIN := $(REPO_ROOT)/bin

# Image URL to use all building/pushing image targets
IMG_TAG ?=latest
Expand Down Expand Up @@ -66,14 +67,18 @@ build: fmt vet fumpt imports lint ## Build api server binary.
go build -o ${REPO_ROOT_BIN}/kuberay-apiserver cmd/main.go

run: fmt vet fumpt imports lint ## Run the api server from your host.
go run -race cmd/main.go
go run -race cmd/main.go -localSwaggerPath ${REPO_ROOT}/proto/swagger

docker-image: test ## Build image with the api server.
${ENGINE} build -t ${IMG} -f Dockerfile ..

docker-push: ## Push image with the api server.
${ENGINE} push ${IMG}

.PHONY: build-swagger
build-swagger: go-bindata
cd $(REPO_ROOT) && $(GOBINDATA) --nocompress --pkg swagger -o apiserver/pkg/swagger/datafile.go third_party/swagger-ui/...

##@ Deployment
.PHONY: install
install: kustomize ## Install the kuberay api server to the K8s cluster specified in ~/.kube/config.
Expand Down Expand Up @@ -107,6 +112,7 @@ GOIMPORTS ?= $(REPO_ROOT_BIN)/goimports
GOFUMPT ?= $(REPO_ROOT_BIN)/gofumpt
GOLANGCI_LINT ?= $(REPO_ROOT_BIN)/golangci-lint
KIND ?= $(REPO_ROOT_BIN)/kind
GOBINDATA ?= $(REPO_ROOT_BIN)/go-bindata


## Tool Versions
Expand All @@ -115,6 +121,7 @@ GOFUMPT_VERSION ?= v0.3.1
GOIMPORTS_VERSION ?= latest
GOLANGCI_LINT_VERSION ?= v1.54.1
KIND_VERSION ?= v0.19.0
GOBINDATA_VERSION ?= v4.0.2

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
Expand Down Expand Up @@ -142,8 +149,13 @@ kind: $(KIND) ## Download kind locally if necessary.
$(KIND): $(REPO_ROOT_BIN)
test -s $(KIND) || GOBIN=$(REPO_ROOT_BIN) go install sigs.k8s.io/kind@$(KIND_VERSION)

.PHONY: go-bindata
go-bindata: $(GOBINDATA) ## Download the go-bindata executable if necessary.
$(GOBINDATA): $(REPO_ROOT_BIN)
test -s $(GOBINDATA) || GOBIN=$(REPO_ROOT_BIN) go install github.com/kevinburke/go-bindata/v4/...@$(GOBINDATA_VERSION)

.PHONY: dev-tools
dev-tools: kind golangci-lint gofumpt kustomize goimports ## Install all development tools
dev-tools: kind golangci-lint gofumpt kustomize goimports go-bindata ## Install all development tools

.PHONY: clean-dev-tools
clean-dev-tools: ## Remove all development tools
Expand All @@ -152,6 +164,7 @@ clean-dev-tools: ## Remove all development tools
rm -f $(REPO_ROOT_BIN)/kustomize
rm -f $(REPO_ROOT_BIN)/goimports
rm -f $(REPO_ROOT_BIN)/kind
rm -f $(REPO_ROOT_BIN)/go-bindata


##@ Testing Setup and Tools
Expand Down
12 changes: 8 additions & 4 deletions apiserver/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (
collectMetricsFlag = flag.Bool("collectMetricsFlag", true, "Whether to collect Prometheus metrics in API server.")
logFile = flag.String("logFilePath", "", "Synchronize logs to local file")
healthy int32
localSwaggerPath = flag.String("localSwaggerPath", "", "Specify the root directory for `*.swagger.json` the swagger files.")
)

func main() {
Expand Down Expand Up @@ -159,10 +160,13 @@ func serveSwaggerFile(w http.ResponseWriter, r *http.Request) {
}

p := strings.TrimPrefix(r.URL.Path, "/swagger/")
// Currently, we copy swagger.json to system root /workspace/proto/swagger/.
// For the development, you can change path to `../proto/swagger`.
// TODO(Jeffwan@): fix this later, we should not have dependency on system folder structure.
p = path.Join("/workspace/proto/swagger/", p)
if strings.TrimSpace(*localSwaggerPath) != "" {
// use the specified path, for development the is `${REPO_ROOT}/proto/swagger`.
p = path.Join(*localSwaggerPath, "/", p)
} else {
// In docker images the *.swagger.json are copied to `/workspace/proto/swagger/``.
p = path.Join("/workspace/proto/swagger/", p)
}

klog.Infof("Serving swagger-file: %s", p)
http.ServeFile(w, r, p)
Expand Down
20 changes: 20 additions & 0 deletions apiserver/hack/update-swagger-ui.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -e
set -x
readonly REPO_ROOT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )"/../.. &> /dev/null && pwd)
readonly TARGET_DIR="${REPO_ROOT_DIR}/third_party/swagger-ui"
readonly SWAGGER_UI_VERSION=${1:-"5.4.1"}
readonly SWAGGER_UI_TAR_URL="https://github.com/swagger-api/swagger-ui/archive/refs/tags/v${SWAGGER_UI_VERSION}.tar.gz"

if [ -f ${TARGET_DIR}/swagger-initializer.js ];then
cp -v ${TARGET_DIR}/swagger-initializer.js ${TARGET_DIR}/swagger-initializer.js.backup
fi
echo "Downloading '${SWAGGER_UI_TAR_URL}' to update ${TARGET_DIR}"
tmp="$(mktemp -d)"
#pushd .
curl --output-dir ${tmp} --fail --silent --location --remote-header-name --remote-name ${SWAGGER_UI_TAR_URL}
tar -xzvf ${tmp}/swagger-ui-${SWAGGER_UI_VERSION}.tar.gz -C ${tmp}
#popd
cp -rv "$tmp/swagger-ui-${SWAGGER_UI_VERSION}/dist/"* "${TARGET_DIR}"
rm -rf "$tmp"

Loading