Skip to content

Commit

Permalink
Clarify the client generation process
Browse files Browse the repository at this point in the history
  • Loading branch information
ejweber committed Jul 28, 2023
1 parent 5a65207 commit 1d35e1d
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions client/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,58 @@
# Longhorn API Client
# Longhorn API client

The code in this package are generated by [rancher/go-rancher](https://github.com/rancher/go-rancher).
But in order to fix some compatibility issues, you need to use this [repo](https://github.com/niusmallnan/go-rancher), and you should checkout the `longhorn-v1` branch.
The code in this package is generated by [rancher/go-rancher](https://github.com/rancher/go-rancher). But in order to
fix some compatibility issues, you must use the `longhorn-v1` branch of this
[repo](https://github.com/niusmallnan/go-rancher) instead.

## Generate code in go-rancher

If you have a longhorn api URL, you can use this script:
The version of go-rancher we use does not have Go module support. It must be cloned onto the correct location on the
GOPATH and the Go tools must be executed with `GO111MODULE=off`. This might be unusual for developers used to working
with modern Go.

1. Run longhorn-manager. There may be an easier way, but generally, this means deploy Longhorn to a cluster using a
development version of the longhorn-manager container.
2. Expose the longhorn-manager API. If running in a cluster, change the `spec.type` of the `longhorn-backend` service
from `ClusterIP` to `NodePort`. The IP is the IP of any node and the port is given by `spec.ports.nodePort`.
3. Clone go-rancher to the correct location on your GOPATH and check out the correct branch.

```bash
cd $GOPATH/src/github.com/niusmallnan/
git clone https://github.com/niusmallnan/go-rancher
cd go-rancher
```
./scripts/generate-longhorn-schemas.sh http://manager-api-ip:port

4. Get dependencies.

```bash
```

5. Generate code.

```bash
GO111MODULE=off scripts/generate-longhorn-schemas.sh http://<ip>:<port>
```

## Copy code to longhorn-manager

Just use cp to copy these code is fine, but you should update package name in `longhorn-manager`:
1. Copy the client to your project directory.

```bash
cp $GOPATH/src/github.com/niusmallnan/go-rancher/longhorn/*.go <project_directory>/client/
```
cd longhorn-manager/client

2. Correct the package name.

```bash
cd <project_directory>/client
sed -i -e 's/package longhorn/package client/g' *.go
```

3. Check the `git diff`. There are likely unrelated changes you did not intend. For now, just revert any changes that
don't appear to be directly related to your work. Maybe we can make the process more idempotent in the future.

## Notes:

The generator currently no longer generates actions, so you need to ensure not to overwrite the `ActionUpdateAccessMode`
in `generated_volume.go`. I currently don't have the time to look into this and since we are planning on reworking the api
down the line, this is a low priority issue for now.
in `generated_volume.go`. I currently don't have the time to look into this and since we are planning on reworking the
api down the line, this is a low priority issue for now.

0 comments on commit 1d35e1d

Please sign in to comment.