Skip to content

Commit

Permalink
Merge branch 'main' into konflux/references/main
Browse files Browse the repository at this point in the history
  • Loading branch information
clyang82 authored Jun 4, 2024
2 parents fcdff24 + be8dc75 commit d1a36f1
Show file tree
Hide file tree
Showing 41 changed files with 4,590 additions and 166 deletions.
235 changes: 235 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,26 @@ ocm post /api/maestro/v1/resources << EOF
}
}
}
},
"update_strategy": {
"type": "ServerSideApply"
},
"delete_option": {
"propagationPolicy": "Foreground"
}
}
EOF

```
delete_option defines the option to delete the resource. It is optional when creating a resource. The propagationPolicy of `delete_option` can be:
- `Foreground` represents that the resource should be fourground deleted. This is a default value.
- `Orphan` represents that the resource is orphaned when deleting the resource.

update_strategy defines the strategy to update the resource. It is optional when creating a resource. The type of `update_strategy` can be:
- `ServerSideApply` means to update resource using server side apply with work-controller as the field manager. This is a default value.
- `Update` means to update resource by an update call.
- `CreateOnly` means do not update resource based on current manifest.
- `ReadOnly` means only check the existence of the resource based on the resource's metadata.

#### Get your Resource

Expand All @@ -219,6 +234,9 @@ ocm get /api/maestro/v1/resources
{
"consumer_name": "cluster1",
"created_at": "2023-11-23T09:26:13.43061Z",
"delete_option": {
"propagationPolicy":"Foreground"
},
"href": "/api/maestro/v1/resources/f428e21d-71cb-47a4-8d7f-82a65d9a4048",
"id": "f428e21d-71cb-47a4-8d7f-82a65d9a4048",
"kind": "Resource",
Expand Down Expand Up @@ -307,6 +325,9 @@ ocm get /api/maestro/v1/resources
"SequenceID": "1744926882802962432"
}
},
"update_strategy": {
"type":"ServerSideApply"
},
"updated_at": "2023-11-23T09:26:13.457419Z",
"version": 1
}
Expand All @@ -318,6 +339,220 @@ ocm get /api/maestro/v1/resources
}
```

#### Create/Get resource bundle with multiple resources

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 &
```

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
```

4. Get the resource bundle with multiple resources, for example:

```shell
ocm get /api/maestro/v1/resource-bundles
{
"items": [
{
"consumer_name": "cluster1",
"created_at": "2024-05-30T05:03:08.493083Z",
"delete_option": {
"propagationPolicy": "Foreground"
},
"href": "/api/maestro/v1/resource-bundles/68ebf474-6709-48bb-b760-386181268060",
"id": "68ebf474-6709-48bb-b760-386181268060",
"kind": "ResourceBundle",
"manifest_configs": [
{
"feedbackRules": [
{
"jsonPaths": [
{
"name": "status",
"path": ".status"
}
],
"type": "JSONPaths"
}
],
"resourceIdentifier": {
"group": "apps",
"name": "web",
"namespace": "default",
"resource": "deployments"
},
"updateStrategy": {
"type": "ServerSideApply"
}
}
],
"manifests": [
{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": {
"name": "web",
"namespace": "default"
}
},
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "web",
"namespace": "default"
},
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"app": "web"
}
},
"template": {
"metadata": {
"labels": {
"app": "web"
}
},
"spec": {
"containers": [
{
"image": "nginxinc/nginx-unprivileged",
"name": "nginx"
}
]
}
}
}
}
],
"name": "68ebf474-6709-48bb-b760-386181268060",
"status": {
"ObservedVersion": 1,
"SequenceID": "1796044690592632832",
"conditions": [
{
"lastTransitionTime": "2024-05-30T05:03:08Z",
"message": "Apply manifest work complete",
"reason": "AppliedManifestWorkComplete",
"status": "True",
"type": "Applied"
},
{
"lastTransitionTime": "2024-05-30T05:03:08Z",
"message": "All resources are available",
"reason": "ResourcesAvailable",
"status": "True",
"type": "Available"
}
],
"resourceStatus": [
{
"conditions": [
{
"lastTransitionTime": "2024-05-30T05:03:08Z",
"message": "Apply manifest complete",
"reason": "AppliedManifestComplete",
"status": "True",
"type": "Applied"
},
{
"lastTransitionTime": "2024-05-30T05:03:08Z",
"message": "Resource is available",
"reason": "ResourceAvailable",
"status": "True",
"type": "Available"
},
{
"lastTransitionTime": "2024-05-30T05:03:08Z",
"message": "",
"reason": "NoStatusFeedbackSynced",
"status": "True",
"type": "StatusFeedbackSynced"
}
],
"resourceMeta": {
"group": "",
"kind": "ConfigMap",
"name": "web",
"namespace": "default",
"ordinal": 0,
"resource": "configmaps",
"version": "v1"
},
"statusFeedback": {}
},
{
"conditions": [
{
"lastTransitionTime": "2024-05-30T05:03:08Z",
"message": "Apply manifest complete",
"reason": "AppliedManifestComplete",
"status": "True",
"type": "Applied"
},
{
"lastTransitionTime": "2024-05-30T05:03:08Z",
"message": "Resource is available",
"reason": "ResourceAvailable",
"status": "True",
"type": "Available"
},
{
"lastTransitionTime": "2024-05-30T05:03:08Z",
"message": "",
"reason": "StatusFeedbackSynced",
"status": "True",
"type": "StatusFeedbackSynced"
}
],
"resourceMeta": {
"group": "apps",
"kind": "Deployment",
"name": "web",
"namespace": "default",
"ordinal": 1,
"resource": "deployments",
"version": "v1"
},
"statusFeedback": {
"values": [
{
"fieldValue": {
"jsonRaw": "{\"availableReplicas\":1,\"conditions\":[{\"lastTransitionTime\":\"2024-05-30T05:03:13Z\",\"lastUpdateTime\":\"2024-05-30T05:03:13Z\",\"message\":\"Deployment has minimum availability.\",\"reason\":\"MinimumReplicasAvailable\",\"status\":\"True\",\"type\":\"Available\"},{\"lastTransitionTime\":\"2024-05-30T05:03:08Z\",\"lastUpdateTime\":\"2024-05-30T05:03:13Z\",\"message\":\"ReplicaSet \\\"web-dcffc4f85\\\" has successfully progressed.\",\"reason\":\"NewReplicaSetAvailable\",\"status\":\"True\",\"type\":\"Progressing\"}],\"observedGeneration\":1,\"readyReplicas\":1,\"replicas\":1,\"updatedReplicas\":1}",
"type": "JsonRaw"
},
"name": "status"
}
]
}
}
]
},
"updated_at": "2024-05-30T05:03:17.796496Z",
"version": 1
}
],
"kind": "ResourceBundleList",
"page": 1,
"size": 1,
"total": 1
}
```

#### Run in OpenShift

Take OpenShift Local as an example to deploy the maestro. If you want to deploy maestro in an OpenShift cluster, you need to set the `external_apps_domain` environment variable to point your cluster.
Expand Down
8 changes: 7 additions & 1 deletion cmd/maestro/server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,15 @@ func (s *apiServer) routes() *mux.Router {
apiV1ResourceRouter.HandleFunc("/{id}", resourceHandler.Patch).Methods(http.MethodPatch)
apiV1ResourceRouter.HandleFunc("/{id}", resourceHandler.Delete).Methods(http.MethodDelete)
apiV1ResourceRouter.Use(authMiddleware.AuthenticateAccountJWT)

apiV1ResourceRouter.Use(authzMiddleware.AuthorizeApi)

// /api/maestro/v1/resource-bundles
apiV1ResourceBundleRouter := apiV1Router.PathPrefix("/resource-bundles").Subrouter()
apiV1ResourceBundleRouter.HandleFunc("", resourceHandler.ListBundle).Methods(http.MethodGet)
apiV1ResourceBundleRouter.HandleFunc("/{id}", resourceHandler.GetBundle).Methods(http.MethodGet)
apiV1ResourceBundleRouter.Use(authMiddleware.AuthenticateAccountJWT)
apiV1ResourceBundleRouter.Use(authzMiddleware.AuthorizeApi)

// /api/maestro/v1/consumers
apiV1ConsumersRouter := apiV1Router.PathPrefix("/consumers").Subrouter()
apiV1ConsumersRouter.HandleFunc("", consumerHandler.List).Methods(http.MethodGet)
Expand Down
4 changes: 2 additions & 2 deletions data/generated/openapi/openapi.go

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions examples/cloudevent-bundle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"specversion": "1.0",
"id": "0192bd68-8444-4743-b02b-4a6605ec0413",
"type": "io.open-cluster-management.works.v1alpha1.manifestbundles.spec.create_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": 1,
"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"
}
}
]
}
}
Loading

0 comments on commit d1a36f1

Please sign in to comment.