Skip to content

Commit 52a2466

Browse files
JYisusJuan Jesús Padrón Hernández
andauthored
feat(sca): onboard sca service (#11373)
Co-authored-by: Juan Jesús Padrón Hernández <juan.padron@scrm.lidl>
1 parent 897ab22 commit 52a2466

59 files changed

Lines changed: 12901 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@
194194
- [v1.10.0](services/runcommand/CHANGELOG.md#v1100)
195195
- `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`.
196196
- **Dependencies:** Add `github.com/google/go-cmp v0.7.0`
197+
- `sca`:
198+
- [v0.1.0](services/sca/CHANGELOG.md#v010)
199+
- **New:** SDK module for STACKIT Container Applications (SCA) service.
200+
- `v1alphaapi`: New package which can be used for communication with the sca v1 alpha API
197201
- `scf`:
198202
- [v0.10.2](services/scf/CHANGELOG.md#v0102)
199203
- **Dependencies:** Bump STACKIT SDK core module from `v0.26.0` to `v0.27.0`

‎examples/sca/go.mod‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module github.com/stackitcloud/stackit-sdk-go/examples/sca
2+
3+
go 1.25
4+
5+
// 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.
6+
replace github.com/stackitcloud/stackit-sdk-go/services/sca => ../../services/sca
7+
8+
require (
9+
github.com/stackitcloud/stackit-sdk-go/core v0.27.0
10+
github.com/stackitcloud/stackit-sdk-go/services/sca v0.15.0
11+
)
12+
13+
require (
14+
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
15+
github.com/google/uuid v1.6.0 // indirect
16+
)

‎examples/sca/go.sum‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
2+
github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
3+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
4+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
5+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
6+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
7+
github.com/stackitcloud/stackit-sdk-go/core v0.27.0 h1:7lc6qStcFDFf8zHP4ORPa9joybw+Sa2LtB6BVjKQ+ek=
8+
github.com/stackitcloud/stackit-sdk-go/core v0.27.0/go.mod h1:WU1hhxnjXw2EV7CYa1nlEvNpMiRY6CvmIOaHuL3pOaA=

‎examples/sca/sca.go‎

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
8+
"github.com/stackitcloud/stackit-sdk-go/core/config"
9+
sca "github.com/stackitcloud/stackit-sdk-go/services/sca/v1alphaapi"
10+
"github.com/stackitcloud/stackit-sdk-go/services/sca/v1alphaapi/wait"
11+
)
12+
13+
func main() {
14+
region := "eu01" // Region where the resources will be created
15+
projectID := "PROJECT_ID" // the uuid of your STACKIT project
16+
17+
// Create a new API client, that uses default authentication and configuration
18+
scaClient, err := sca.NewAPIClient(config.WithRegion(region))
19+
if err != nil {
20+
fmt.Fprintf(os.Stderr, "Creating API client: %v\n", err)
21+
os.Exit(1)
22+
}
23+
24+
// Create environment
25+
// WARNING: Keep in mind that there is no endpoint to delete environments right now.
26+
createEnvironmentPayload := sca.CreateEnvironmentPayload{
27+
DisplayName: "environment-name",
28+
}
29+
env, err := scaClient.DefaultAPI.CreateEnvironment(context.Background(), projectID).
30+
CreateEnvironmentPayload(createEnvironmentPayload).Execute()
31+
if err != nil {
32+
fmt.Fprintf(os.Stderr, "Error when calling `CreateEnvironment`: %v\n", err)
33+
os.Exit(1)
34+
}
35+
36+
fmt.Printf("Created environment with id %q\n", env.GetId())
37+
38+
// Get environment
39+
getEnvResp, err := scaClient.DefaultAPI.GetEnvironment(context.Background(), projectID, env.GetId()).Execute()
40+
if err != nil {
41+
fmt.Fprintf(os.Stderr, "Error when calling `GetEnvironment`: %v\n", err)
42+
os.Exit(1)
43+
}
44+
45+
fmt.Printf("Got environment with id %q\n", getEnvResp.GetId())
46+
47+
// List environments
48+
listEnvsResp, err := scaClient.DefaultAPI.ListEnvironments(context.Background(), projectID).Execute()
49+
if err != nil {
50+
fmt.Fprintf(os.Stderr, "Error when calling `ListEnvironments`: %v\n", err)
51+
os.Exit(1)
52+
}
53+
54+
fmt.Printf("Number of environments in project: %d\n", len(listEnvsResp.Items))
55+
56+
// List all applications of a given project
57+
listAppsResp, err := scaClient.DefaultAPI.ListProjectApplications(context.Background(), projectID).Execute()
58+
if err != nil {
59+
fmt.Fprintf(os.Stderr, "Error when calling `ListProjectApplications`: %v\n", err)
60+
os.Exit(1)
61+
}
62+
63+
fmt.Printf("Number of applications in project: %d\n", len(listAppsResp.Items))
64+
65+
// Create an application within an environment
66+
createApplicationPayload := sca.CreateApplicationPayload{
67+
DisplayName: "application-name",
68+
Containers: []sca.Container{{
69+
Name: "nginx-container",
70+
Image: "nginxinc/nginx-unprivileged",
71+
Memory: sca.PtrInt32(1000),
72+
Cpu: sca.PtrInt32(1000),
73+
}},
74+
Network: sca.Network{
75+
PublicIngress: true,
76+
Port: sca.PtrInt32(8080),
77+
},
78+
Scaling: sca.Scaling{
79+
Type: sca.SCALINGTYPE_SCALING_TYPE_MANUAL,
80+
ManualScaling: &sca.ManualScaling{
81+
Instances: 1,
82+
},
83+
},
84+
}
85+
86+
app, err := scaClient.DefaultAPI.CreateApplication(context.Background(), projectID, env.GetId()).
87+
CreateApplicationPayload(createApplicationPayload).Execute()
88+
if err != nil {
89+
fmt.Fprintf(os.Stderr, "Error when calling `CreateApplication`: %v\n", err)
90+
os.Exit(1)
91+
}
92+
93+
fmt.Printf("Triggered application creation with id %q\n", app.GetId())
94+
95+
_, err = wait.CreateApplicationWaitHandler(context.Background(), scaClient.DefaultAPI, projectID, env.GetId(), app.GetId()).WaitWithContext(context.Background())
96+
if err != nil {
97+
fmt.Fprintf(os.Stderr, "Error when calling `CreateApplicationWaitHandler`: %v\n", err)
98+
os.Exit(1)
99+
}
100+
101+
fmt.Printf("Application created with id %q\n", app.GetId())
102+
103+
// Get application's details
104+
getAppResp, err := scaClient.DefaultAPI.GetApplication(context.Background(), projectID, env.GetId(), app.GetId()).Execute()
105+
if err != nil {
106+
fmt.Fprintf(os.Stderr, "Error when calling `GetApplication`: %v\n", err)
107+
os.Exit(1)
108+
}
109+
110+
fmt.Printf("Got application with id %q\n", getAppResp.GetId())
111+
112+
// List applications in an environment
113+
listEnvAppsResp, err := scaClient.DefaultAPI.ListApplications(context.Background(), projectID, env.GetId()).Execute()
114+
if err != nil {
115+
fmt.Fprintf(os.Stderr, "Error when calling `ListApplications`: %v\n", err)
116+
os.Exit(1)
117+
}
118+
119+
fmt.Printf("Number of applications in environment: %d\n", len(listEnvAppsResp.Items))
120+
121+
logs, err := scaClient.DefaultAPI.GetApplicationLogs(context.Background(), projectID, env.GetId(), app.GetId()).
122+
Instance(getAppResp.RuntimeStatus.Instances[0].GetName()).
123+
Container(getAppResp.Containers[0].GetName()).
124+
Execute()
125+
if err != nil {
126+
fmt.Fprintf(os.Stderr, "Error when calling `GetApplicationLogs`: %v\n", err)
127+
os.Exit(1)
128+
}
129+
130+
fmt.Printf("Found %d logs for application %q\n", len(logs.GetLogs()), app.GetId())
131+
132+
events, err := scaClient.DefaultAPI.GetApplicationEvents(context.Background(), projectID, env.GetId(), app.GetId()).Execute()
133+
if err != nil {
134+
fmt.Fprintf(os.Stderr, "Error when calling `GetApplicationEvents`: %v\n", err)
135+
os.Exit(1)
136+
}
137+
138+
fmt.Printf("Found %d events for application %q\n", len(events.GetEvents()), app.GetId())
139+
140+
// Update application
141+
updateApplicationPayload := sca.UpdateApplicationPayload{
142+
Scaling: &sca.Scaling{
143+
Type: sca.SCALINGTYPE_SCALING_TYPE_AUTO,
144+
AutoScaling: &sca.AutoScaling{
145+
AllowScaleToZero: sca.PtrBool(true),
146+
MinInstances: 1,
147+
MaxInstances: 2,
148+
Rules: []sca.ScaleRule{{
149+
Name: "http-scaling-rule",
150+
Type: sca.RULETYPE_RULE_TYPE_HTTP,
151+
HttpRule: &sca.HttpScaleRule{
152+
Concurrency: sca.PtrInt32(10),
153+
Rps: sca.PtrInt32(10),
154+
},
155+
}},
156+
},
157+
},
158+
}
159+
updateAppResp, err := scaClient.DefaultAPI.UpdateApplication(context.Background(), projectID, env.GetId(), app.GetId()).
160+
UpdateApplicationPayload(updateApplicationPayload).Execute()
161+
if err != nil {
162+
fmt.Fprintf(os.Stderr, "Error when calling `UpdateApplication`: %v\n", err)
163+
os.Exit(1)
164+
}
165+
166+
fmt.Printf("Triggered application update with id %q\n", app.GetId())
167+
168+
_, err = wait.UpdateApplicationWaitHandler(context.Background(), scaClient.DefaultAPI, projectID, env.GetId(), app.GetId()).WaitWithContext(context.Background())
169+
if err != nil {
170+
fmt.Fprintf(os.Stderr, "Error when calling `UpdatedApplicationWaitHandler`: %v\n", err)
171+
os.Exit(1)
172+
}
173+
174+
fmt.Printf("Updated application with id %q\n", updateAppResp.GetId())
175+
176+
deleteApplicationResp, err := scaClient.DefaultAPI.DeleteApplication(context.Background(), projectID, env.GetId(), app.GetId()).Execute()
177+
if err != nil {
178+
fmt.Fprintf(os.Stderr, "Error when calling `DeleteApplication`: %v\n", err)
179+
os.Exit(1)
180+
}
181+
182+
fmt.Printf("Triggered application deletion with id %q\n", *deleteApplicationResp.Id)
183+
184+
_, err = wait.DeleteApplicationWaitHandler(context.Background(), scaClient.DefaultAPI, projectID, env.GetId(), app.GetId()).WaitWithContext(context.Background())
185+
if err != nil {
186+
fmt.Fprintf(os.Stderr, "Error when calling `DeleteApplicationWaitHandler`: %v\n", err)
187+
os.Exit(1)
188+
}
189+
190+
fmt.Printf("Application deleted with id %q\n", app.GetId())
191+
}

‎go.work‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use (
3232
./examples/resourcemanager
3333
./examples/runcommand
3434
./examples/runtime
35+
./examples/sca
3536
./examples/secretsmanager
3637
./examples/serviceaccount
3738
./examples/serviceenablement
@@ -73,6 +74,7 @@ use (
7374
./services/redis
7475
./services/resourcemanager
7576
./services/runcommand
77+
./services/sca
7678
./services/scf
7779
./services/secretsmanager
7880
./services/serverbackup

‎services/sca/CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## v0.1.0
2+
- **New:** SDK module for STACKIT Container Applications (SCA) service.
3+
- `v1alphaapi`: New package which can be used for communication with the sca v1 alpha API

0 commit comments

Comments
 (0)