Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@
- [v1.10.0](services/runcommand/CHANGELOG.md#v1100)
- `v2api`: **Feature:** Add `RunCommandWaitHandler` wait handler for polling a command until it reaches a terminal state. `failed` is an error state; the handler returns a non-nil error along with the `CommandDetails`.
- **Dependencies:** Add `github.com/google/go-cmp v0.7.0`
- `sca`:
- [v0.1.0](services/sca/CHANGELOG.md#v010)
- **New:** SDK module for STACKIT Container Applications (SCA) service.
- `v1alphaapi`: New package which can be used for communication with the sca v1 alpha API
- `scf`:
- [v0.10.2](services/scf/CHANGELOG.md#v0102)
- **Dependencies:** Bump STACKIT SDK core module from `v0.26.0` to `v0.27.0`
Expand Down
16 changes: 16 additions & 0 deletions examples/sca/go.mod
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
)
8 changes: 8 additions & 0 deletions examples/sca/go.sum
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=
191 changes: 191 additions & 0 deletions examples/sca/sca.go
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() {
Comment thread
SerseusWasTaken marked this conversation as resolved.
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)
Comment thread
SerseusWasTaken marked this conversation as resolved.
os.Exit(1)
}
Comment thread
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

@SerseusWasTaken SerseusWasTaken Sep 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.Exit(1) is missing here.
also when running the example i run into this error here:
Error when calling GetApplicationLogs: instance is required and must be specified
Did the updated example run for you or could this be related to my environment?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. I tested the examples with an outdated version of the API.
I also commented the error state in the createOrUpdateApplication waiter because of an internal behaviour of our operator and Kubernetes. We are working on a workaround to solve it, but we would like to merge this and open a new PR with this fix to unlock other tasks that depends on merging and releasing the first version of the sdk.


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())
}
2 changes: 2 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use (
./examples/resourcemanager
./examples/runcommand
./examples/runtime
./examples/sca
./examples/secretsmanager
./examples/serviceaccount
./examples/serviceenablement
Expand Down Expand Up @@ -73,6 +74,7 @@ use (
./services/redis
./services/resourcemanager
./services/runcommand
./services/sca
Comment thread
SerseusWasTaken marked this conversation as resolved.
./services/scf
./services/secretsmanager
./services/serverbackup
Expand Down
3 changes: 3 additions & 0 deletions services/sca/CHANGELOG.md
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
Loading
Loading