Skip to content

Commit

Permalink
add more examples. (#204)
Browse files Browse the repository at this point in the history
Signed-off-by: morvencao <[email protected]>
  • Loading branch information
morvencao authored Oct 24, 2024
1 parent 8ed6055 commit 85faa5f
Show file tree
Hide file tree
Showing 13 changed files with 541 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ $ oc -n maestro port-forward svc/maestro-grpc 8090 &
3. Create a resource bundle with multiple resources using the gRPC client, for example:

```shell
go run ./examples/grpcclient.go -cloudevents_json_file ./examples/cloudevent-bundle.json -grpc_server localhost:8090
go run ./examples/grpc/grpcclient.go -cloudevents_json_file ./examples/grpc/cloudevent-bundle.json -grpc_server localhost:8090
```

4. Get the resource bundle with multiple resources, for example:
Expand Down
41 changes: 41 additions & 0 deletions examples/grpc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# CURD Resource/Bundle with gRPC Client

## Preparation

1. Enable gRPC server by passing `--enable-grpc-server=true` to the maestro server start command, for example:

```shell
$ oc -n maestro patch deploy/maestro --type=json -p='[{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "--enable-grpc-server=true"}]'
```

2. Port-forward the gRPC service to your local machine, for example:

```shell
$ oc -n maestro port-forward svc/maestro-grpc 8090 &
```

## Operate Resource with gRPC client

```shell
# create
go run ./grpcclient.go -grpc_server localhost:8090 -cloudevents_json_file ./cloudevent.json

# update
go run ./grpcclient.go -grpc_server localhost:8090 -cloudevents_json_file ./cloudevent-update.json

# delete
go run ./grpcclient.go -grpc_server localhost:8090 -cloudevents_json_file ./cloudevent-delete.json
```

## Operate Resource Bundle with gRPC client

```shell
# create
go run ./grpcclient.go -grpc_server localhost:8090 -cloudevents_json_file ./cloudevent-bundle.json

# update
go run ./grpcclient.go -grpc_server localhost:8090 -cloudevents_json_file ./cloudevent-bundle-update.json

# delete
go run ./grpcclient.go -grpc_server localhost:8090 -cloudevents_json_file ./cloudevent-bundle-delete.json
```
12 changes: 12 additions & 0 deletions examples/grpc/cloudevent-bundle-delete.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"specversion": "1.0",
"id": "aa27051a-5578-4e03-b737-5d6416d09694",
"type": "io.open-cluster-management.works.v1alpha1.manifestbundles.spec.delete_request",
"source": "grpc",
"clustername": "cluster1",
"resourceid": "68ebf474-6709-48bb-b760-386181268064",
"resourceversion": 1,
"deletiontimestamp": "2024-10-15T09:54:06.582625606Z",
"datacontenttype": "application/json",
"data": {}
}
13 changes: 13 additions & 0 deletions examples/grpc/cloudevent-bundle-status-resync.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"specversion": "1.0",
"id": "ff8b8e9b-d433-4707-bedd-66d52bbfb9f1",
"type": "io.open-cluster-management.works.v1alpha1.manifestbundles.status.resync_request",
"source": "grpc",
"time": "2024-10-15T17:31:05Z",
"clustername": "",
"originalsource": "",
"datacontenttype": "application/json",
"data": {
"statusHashes": []
}
}
80 changes: 80 additions & 0 deletions examples/grpc/cloudevent-bundle-update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"specversion": "1.0",
"id": "9dbcc8ec-c92e-4686-8ea3-0a0def70fa06",
"type": "io.open-cluster-management.works.v1alpha1.manifestbundles.spec.update_request",
"source": "grpc",
"clustername": "cluster1",
"resourceid": "68ebf474-6709-48bb-b760-386181268064",
"resourceversion": 1,
"datacontenttype": "application/json",
"data": {
"manifests": [
{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": {
"name": "web",
"namespace": "default"
}
},
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "web",
"namespace": "default"
},
"spec": {
"replicas": 2,
"selector": {
"matchLabels": {
"app": "web"
}
},
"template": {
"metadata": {
"labels": {
"app": "web"
}
},
"spec": {
"containers": [
{
"image": "nginxinc/nginx-unprivileged",
"name": "nginx"
}
]
}
}
}
}
],
"deleteOption": {
"propagationPolicy": "Foreground"
},
"manifestConfigs": [
{
"resourceIdentifier": {
"group": "apps",
"resource": "deployments",
"namespace": "default",
"name": "web"
},
"feedbackRules": [
{
"type": "JSONPaths",
"jsonPaths": [
{
"name": "status",
"path": ".status"
}
]
}
],
"updateStrategy": {
"type": "ServerSideApply"
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,36 @@
}
},
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "web",
"namespace": "default"
},
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"app": "web"
}
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "web",
"namespace": "default"
},
"template": {
"metadata": {
"labels": {
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"app": "web"
}
},
"spec": {
"containers": [
{
"image": "nginxinc/nginx-unprivileged",
"name": "nginx"
"template": {
"metadata": {
"labels": {
"app": "web"
}
]
},
"spec": {
"containers": [
{
"image": "nginxinc/nginx-unprivileged",
"name": "nginx"
}
]
}
}
}
}
}
],
"deleteOption": {
"propagationPolicy": "Foreground"
Expand Down
12 changes: 12 additions & 0 deletions examples/grpc/cloudevent-delete.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"specversion": "1.0",
"id": "e718bb21-e8c8-436f-b6a4-16a5afd17caf",
"type": "io.open-cluster-management.works.v1alpha1.manifests.spec.delete_request",
"source": "grpc",
"clustername": "cluster1",
"resourceid": "eec95cda-03d6-4514-a9bd-29da9cf7ede2",
"deletiontimestamp": "2024-10-15T09:46:06.582625606Z",
"resourceversion": 1,
"datacontenttype": "application/json",
"data": {}
}
13 changes: 13 additions & 0 deletions examples/grpc/cloudevent-status-resync.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"specversion": "1.0",
"id": "ff8b8e9b-d433-4707-bedd-66d52bbfb9f1",
"type": "io.open-cluster-management.works.v1alpha1.manifests.status.resync_request",
"source": "grpc",
"time": "2024-02-05T17:31:05Z",
"clustername": "",
"originalsource": "",
"datacontenttype": "application/json",
"data": {
"statusHashes": []
}
}
62 changes: 62 additions & 0 deletions examples/grpc/cloudevent-update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"specversion": "1.0",
"id": "ec41ece3-84f5-42b7-92fd-ad478c6e0be6",
"type": "io.open-cluster-management.works.v1alpha1.manifests.spec.update_request",
"source": "grpc",
"clustername": "cluster1",
"resourceid": "eec95cda-03d6-4514-a9bd-29da9cf7ede2",
"resourceversion": 1,
"datacontenttype": "application/json",
"data": {
"manifest": {
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "nginx",
"namespace": "default"
},
"spec": {
"replicas": 2,
"selector": {
"matchLabels": {
"app": "nginx"
}
},
"template": {
"metadata": {
"labels": {
"app": "nginx"
}
},
"spec": {
"containers": [
{
"image": "nginxinc/nginx-unprivileged",
"name": "nginx"
}
]
}
}
}
},
"deleteOption": {
"propagationPolicy": "Foreground"
},
"configOption": {
"feedbackRules": [
{
"type": "JSONPaths",
"jsonPaths": [
{
"name": "status",
"path": ".status"
}
]
}
],
"updateStrategy": {
"type": "ServerSideApply"
}
}
}
}
62 changes: 62 additions & 0 deletions examples/grpc/cloudevent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"specversion": "1.0",
"id": "8beb9296-f423-4bd2-932c-01015e7034dc",
"type": "io.open-cluster-management.works.v1alpha1.manifests.spec.create_request",
"source": "grpc",
"clustername": "cluster1",
"resourceid": "eec95cda-03d6-4514-a9bd-29da9cf7ede2",
"resourceversion": 1,
"datacontenttype": "application/json",
"data": {
"manifest": {
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "nginx",
"namespace": "default"
},
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"app": "nginx"
}
},
"template": {
"metadata": {
"labels": {
"app": "nginx"
}
},
"spec": {
"containers": [
{
"image": "nginxinc/nginx-unprivileged",
"name": "nginx"
}
]
}
}
}
},
"deleteOption": {
"propagationPolicy": "Foreground"
},
"configOption": {
"feedbackRules": [
{
"type": "JSONPaths",
"jsonPaths": [
{
"name": "status",
"path": ".status"
}
]
}
],
"updateStrategy": {
"type": "ServerSideApply"
}
}
}
}
Loading

0 comments on commit 85faa5f

Please sign in to comment.