-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add document for resource bundle API.
Signed-off-by: morvencao <[email protected]>
- Loading branch information
Showing
3 changed files
with
365 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"flag" | ||
"log" | ||
"os" | ||
|
||
cloudevents "github.com/cloudevents/sdk-go/v2" | ||
"github.com/cloudevents/sdk-go/v2/binding" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials" | ||
"google.golang.org/grpc/credentials/insecure" | ||
pbv1 "open-cluster-management.io/sdk-go/pkg/cloudevents/generic/options/grpc/protobuf/v1" | ||
grpcprotocol "open-cluster-management.io/sdk-go/pkg/cloudevents/generic/options/grpc/protocol" | ||
) | ||
|
||
var ( | ||
tls = flag.Bool("tls", false, "Connection uses TLS if true, else plain TCP") | ||
caFile = flag.String("ca_file", "", "The absolute file path containing the CA root cert file") | ||
serverAddr = flag.String("grpc_server", "localhost:8090", "The server address in the format of host:port") | ||
serverHostOverride = flag.String("server_host_override", "x.test.example.com", "The server name used to verify the hostname returned by the TLS handshake") | ||
cloudEventFile = flag.String("cloudevents_json_file", "", "The absolute file path containing the CloudEvent resource") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
var opts []grpc.DialOption | ||
if *tls { | ||
creds, err := credentials.NewClientTLSFromFile(*caFile, *serverHostOverride) | ||
if err != nil { | ||
log.Fatalf("Failed to create TLS credentials: %v", err) | ||
} | ||
opts = append(opts, grpc.WithTransportCredentials(creds)) | ||
} else { | ||
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
} | ||
|
||
conn, err := grpc.Dial(*serverAddr, opts...) | ||
if err != nil { | ||
log.Fatalf("fail to dial: %v", err) | ||
} | ||
defer conn.Close() | ||
|
||
client := pbv1.NewCloudEventServiceClient(conn) | ||
|
||
cloudeventJSON, err := os.ReadFile(*cloudEventFile) | ||
if err != nil { | ||
log.Fatalf("failed to read cloudevent file: %v", err) | ||
} | ||
|
||
evt := &cloudevents.Event{} | ||
if err := json.Unmarshal(cloudeventJSON, evt); err != nil { | ||
log.Fatalf("failed to unmarshal cloudevent: %v", err) | ||
} | ||
|
||
ctx := context.TODO() | ||
pbEvt := &pbv1.CloudEvent{} | ||
if err = grpcprotocol.WritePBMessage(ctx, binding.ToMessage(evt), pbEvt); err != nil { | ||
log.Fatalf("failed to convert spec from cloudevent to protobuf: %v", err) | ||
} | ||
|
||
if _, err = client.Publish(ctx, &pbv1.PublishRequest{Event: pbEvt}); err != nil { | ||
log.Fatalf("failed to publish: %v", err) | ||
} | ||
|
||
log.Printf("=======================================") | ||
log.Printf("Published spec with cloudevent:\n%v\n\n", evt) | ||
log.Printf("=======================================") | ||
} |