-
Notifications
You must be signed in to change notification settings - Fork 41
feat(sca): onboard sca service #11373
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
base: main
Are you sure you want to change the base?
Changes from all commits
bf87be5
d18a149
e992e08
aa0e1d7
df458b6
98e03c0
0eca262
a1ca4a6
ddd0a4b
9bd210d
d42044a
30c8ca0
9c3a614
57633d0
a951bfd
84567b7
f1f0ffd
3730ed0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| module github.com/stackitcloud/stackit-sdk-go/examples/sca | ||
|
|
||
| go 1.25 | ||
|
|
||
| // This is not needed in production. This is only here to point the golangci linter to the local version instead of the last release on GitHub. | ||
| replace github.com/stackitcloud/stackit-sdk-go/services/sca => ../../services/sca | ||
|
|
||
| require ( | ||
| github.com/stackitcloud/stackit-sdk-go/core v0.27.0 | ||
| github.com/stackitcloud/stackit-sdk-go/services/sca v0.15.0 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/golang-jwt/jwt/v5 v5.3.1 // indirect | ||
| github.com/google/uuid v1.6.0 // indirect | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY= | ||
| github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= | ||
| github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= | ||
| github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= | ||
| github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||
| github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
| github.com/stackitcloud/stackit-sdk-go/core v0.27.0 h1:7lc6qStcFDFf8zHP4ORPa9joybw+Sa2LtB6BVjKQ+ek= | ||
| github.com/stackitcloud/stackit-sdk-go/core v0.27.0/go.mod h1:WU1hhxnjXw2EV7CYa1nlEvNpMiRY6CvmIOaHuL3pOaA= |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
|
|
||
| "github.com/stackitcloud/stackit-sdk-go/core/config" | ||
| sca "github.com/stackitcloud/stackit-sdk-go/services/sca/v1alphaapi" | ||
| "github.com/stackitcloud/stackit-sdk-go/services/sca/v1alphaapi/wait" | ||
| ) | ||
|
|
||
| func main() { | ||
| region := "eu01" // Region where the resources will be created | ||
| projectID := "PROJECT_ID" // the uuid of your STACKIT project | ||
|
|
||
| // Create a new API client, that uses default authentication and configuration | ||
| scaClient, err := sca.NewAPIClient(config.WithRegion(region)) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Creating API client: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| // Create environment | ||
| // WARNING: Keep in mind that there is no endpoint to delete environments right now. | ||
| createEnvironmentPayload := sca.CreateEnvironmentPayload{ | ||
| DisplayName: "environment-name", | ||
| } | ||
| env, err := scaClient.DefaultAPI.CreateEnvironment(context.Background(), projectID). | ||
| CreateEnvironmentPayload(createEnvironmentPayload).Execute() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `CreateEnvironment`: %v\n", err) | ||
|
SerseusWasTaken marked this conversation as resolved.
|
||
| os.Exit(1) | ||
| } | ||
|
SerseusWasTaken marked this conversation as resolved.
|
||
|
|
||
| fmt.Printf("Created environment with id %q\n", env.GetId()) | ||
|
|
||
| // Get environment | ||
| getEnvResp, err := scaClient.DefaultAPI.GetEnvironment(context.Background(), projectID, env.GetId()).Execute() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `GetEnvironment`: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| fmt.Printf("Got environment with id %q\n", getEnvResp.GetId()) | ||
|
|
||
| // List environments | ||
| listEnvsResp, err := scaClient.DefaultAPI.ListEnvironments(context.Background(), projectID).Execute() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `ListEnvironments`: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| fmt.Printf("Number of environments in project: %d\n", len(listEnvsResp.Items)) | ||
|
|
||
| // List all applications of a given project | ||
| listAppsResp, err := scaClient.DefaultAPI.ListProjectApplications(context.Background(), projectID).Execute() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `ListProjectApplications`: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| fmt.Printf("Number of applications in project: %d\n", len(listAppsResp.Items)) | ||
|
|
||
| // Create an application within an environment | ||
| createApplicationPayload := sca.CreateApplicationPayload{ | ||
| DisplayName: "application-name", | ||
| Containers: []sca.Container{{ | ||
| Name: "nginx-container", | ||
| Image: "nginxinc/nginx-unprivileged", | ||
| Memory: sca.PtrInt32(1000), | ||
| Cpu: sca.PtrInt32(1000), | ||
| }}, | ||
| Network: sca.Network{ | ||
| PublicIngress: true, | ||
| Port: sca.PtrInt32(8080), | ||
| }, | ||
| Scaling: sca.Scaling{ | ||
| Type: sca.SCALINGTYPE_SCALING_TYPE_MANUAL, | ||
| ManualScaling: &sca.ManualScaling{ | ||
| Instances: 1, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| app, err := scaClient.DefaultAPI.CreateApplication(context.Background(), projectID, env.GetId()). | ||
| CreateApplicationPayload(createApplicationPayload).Execute() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `CreateApplication`: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| fmt.Printf("Triggered application creation with id %q\n", app.GetId()) | ||
|
|
||
| _, err = wait.CreateApplicationWaitHandler(context.Background(), scaClient.DefaultAPI, projectID, env.GetId(), app.GetId()).WaitWithContext(context.Background()) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `CreateApplicationWaitHandler`: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| fmt.Printf("Application created with id %q\n", app.GetId()) | ||
|
|
||
| // Get application's details | ||
| getAppResp, err := scaClient.DefaultAPI.GetApplication(context.Background(), projectID, env.GetId(), app.GetId()).Execute() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `GetApplication`: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| fmt.Printf("Got application with id %q\n", getAppResp.GetId()) | ||
|
|
||
| // List applications in an environment | ||
| listEnvAppsResp, err := scaClient.DefaultAPI.ListApplications(context.Background(), projectID, env.GetId()).Execute() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `ListApplications`: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| fmt.Printf("Number of applications in environment: %d\n", len(listEnvAppsResp.Items)) | ||
|
|
||
| logs, err := scaClient.DefaultAPI.GetApplicationLogs(context.Background(), projectID, env.GetId(), app.GetId()). | ||
| Instance(getAppResp.RuntimeStatus.Instances[0].GetName()). | ||
| Container(getAppResp.Containers[0].GetName()). | ||
| Execute() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `GetApplicationLogs`: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
Comment on lines
+125
to
+128
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. I tested the examples with an outdated version of the API. |
||
|
|
||
| fmt.Printf("Found %d logs for application %q\n", len(logs.GetLogs()), app.GetId()) | ||
|
|
||
| events, err := scaClient.DefaultAPI.GetApplicationEvents(context.Background(), projectID, env.GetId(), app.GetId()).Execute() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `GetApplicationEvents`: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| fmt.Printf("Found %d events for application %q\n", len(events.GetEvents()), app.GetId()) | ||
|
|
||
| // Update application | ||
| updateApplicationPayload := sca.UpdateApplicationPayload{ | ||
| Scaling: &sca.Scaling{ | ||
| Type: sca.SCALINGTYPE_SCALING_TYPE_AUTO, | ||
| AutoScaling: &sca.AutoScaling{ | ||
| AllowScaleToZero: sca.PtrBool(true), | ||
| MinInstances: 1, | ||
| MaxInstances: 2, | ||
| Rules: []sca.ScaleRule{{ | ||
| Name: "http-scaling-rule", | ||
| Type: sca.RULETYPE_RULE_TYPE_HTTP, | ||
| HttpRule: &sca.HttpScaleRule{ | ||
| Concurrency: sca.PtrInt32(10), | ||
| Rps: sca.PtrInt32(10), | ||
| }, | ||
| }}, | ||
| }, | ||
| }, | ||
| } | ||
| updateAppResp, err := scaClient.DefaultAPI.UpdateApplication(context.Background(), projectID, env.GetId(), app.GetId()). | ||
| UpdateApplicationPayload(updateApplicationPayload).Execute() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `UpdateApplication`: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| fmt.Printf("Triggered application update with id %q\n", app.GetId()) | ||
|
|
||
| _, err = wait.UpdateApplicationWaitHandler(context.Background(), scaClient.DefaultAPI, projectID, env.GetId(), app.GetId()).WaitWithContext(context.Background()) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `UpdatedApplicationWaitHandler`: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| fmt.Printf("Updated application with id %q\n", updateAppResp.GetId()) | ||
|
|
||
| deleteApplicationResp, err := scaClient.DefaultAPI.DeleteApplication(context.Background(), projectID, env.GetId(), app.GetId()).Execute() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `DeleteApplication`: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| fmt.Printf("Triggered application deletion with id %q\n", *deleteApplicationResp.Id) | ||
|
|
||
| _, err = wait.DeleteApplicationWaitHandler(context.Background(), scaClient.DefaultAPI, projectID, env.GetId(), app.GetId()).WaitWithContext(context.Background()) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `DeleteApplicationWaitHandler`: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| fmt.Printf("Application deleted with id %q\n", app.GetId()) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ## v0.1.0 | ||
| - **New:** SDK module for STACKIT Container Applications (SCA) service. | ||
| - `v1alphaapi`: New package which can be used for communication with the sca v1 alpha API |
Uh oh!
There was an error while loading. Please reload this page.