-
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
Open
JYisus
wants to merge
19
commits into
stackitcloud:main
Choose a base branch
from
JYisus:oas-bot-34598867041/sca
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
bf87be5
Generate sca
stackit-pipeline d18a149
feat(sca): add examples
e992e08
feat(sca): add waiters
aa0e1d7
chore(sca): add initial changelog
df458b6
chore(sca): add missing meta files
98e03c0
doc(sca): update changelogs
0eca262
fix(sca): fix copy paste example
a1ca4a6
fix(sca): add examples to go work
ddd0a4b
fix(sca): delete token auth from example
9bd210d
Merge branch 'main' into oas-bot-34598867041/sca
JYisus d42044a
fix(sca): fix testing
30c8ca0
fix(sca): test logs and use created env id
9c3a614
fix(sca): add os exit on api call errors
57633d0
fix(sca): add warning comment
a951bfd
doc(sca): fix license
84567b7
fix(sca): apply code review
f1f0ffd
fix(sca): add missing query params in example
3730ed0
fix(sca): inline environment id
e0d0ed7
fix(sca): linter and comment
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,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 | ||
| ) |
This file contains hidden or 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,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= |
This file contains hidden or 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,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) | ||
| } | ||
|
SerseusWasTaken marked this conversation as resolved.
|
||
|
|
||
| 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()) | ||
| } | ||
This file contains hidden or 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 hidden or 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,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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.