Skip to content

Commit 912e183

Browse files
committed
convert to arrays
1 parent 333c83e commit 912e183

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

cmd/ctrlc/root/apply/apply.go

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,43 @@ import (
2020

2121
// Config represents the structure of the YAML file
2222
type Config struct {
23-
Systems map[string]System `yaml:"systems"`
23+
Systems []System `yaml:"systems"`
2424
Providers ResourceProvider `yaml:"resourceProvider"`
2525
}
2626

2727
type System struct {
28-
Name string `yaml:"name"`
29-
Description string `yaml:"description"`
30-
Deployments map[string]Deployment `yaml:"deployments"`
28+
Slug string `yaml:"slug"`
29+
Name string `yaml:"name"`
30+
Description string `yaml:"description"`
31+
Deployments []Deployment `yaml:"deployments"`
32+
Environments []Environment `yaml:"environments"`
3133
}
3234

33-
type JobAgent struct {
34-
Id string `yaml:"id"`
35-
Config map[string]any `yaml:"config"`
35+
type Environment struct {
36+
Name string `yaml:"name"`
37+
Description string `yaml:"description"`
38+
ResourceSelector map[string]any `yaml:"resourceSelector"`
3639
}
3740

3841
type Deployment struct {
42+
Slug string `yaml:"slug"`
3943
Name string `yaml:"name"`
4044
Description *string `yaml:"description"`
4145
JobAgent *JobAgent `yaml:"jobAgent,omitempty"`
4246
}
4347

48+
type JobAgent struct {
49+
Id string `yaml:"id"`
50+
Config map[string]any `yaml:"config"`
51+
}
52+
4453
type ResourceProvider struct {
45-
Name string `yaml:"name"`
46-
Resources map[string]Resource `yaml:"resources"`
54+
Name string `yaml:"name"`
55+
Resources []Resource `yaml:"resources"`
4756
}
4857

4958
type Resource struct {
59+
Identifer string `yaml:"identifer"`
5060
Name string `yaml:"name"`
5161
Version string `yaml:"version"`
5262
Kind string `yaml:"kind"`
@@ -109,9 +119,9 @@ func processResourceProvider(ctx context.Context, client *api.ClientWithResponse
109119
}
110120

111121
resources := make([]api.AgentResource, 0)
112-
for id, resource := range provider.Resources {
122+
for _, resource := range provider.Resources {
113123
resources = append(resources, api.AgentResource{
114-
Identifier: id,
124+
Identifier: resource.Identifer,
115125
Name: resource.Name,
116126
Version: resource.Version,
117127
Kind: resource.Kind,
@@ -151,17 +161,16 @@ func processAllSystems(
151161
ctx context.Context,
152162
client *api.ClientWithResponses,
153163
workspaceID uuid.UUID,
154-
systems map[string]System,
164+
systems []System,
155165
) {
156166
var systemWg sync.WaitGroup
157167

158-
for slug, system := range systems {
168+
for _, system := range systems {
159169
systemWg.Add(1)
160170
go processSystem(
161171
ctx,
162172
client,
163173
workspaceID,
164-
slug,
165174
system,
166175
&systemWg,
167176
)
@@ -174,14 +183,13 @@ func processSystem(
174183
ctx context.Context,
175184
client *api.ClientWithResponses,
176185
workspaceID uuid.UUID,
177-
slug string,
178186
system System,
179187
systemWg *sync.WaitGroup,
180188
) {
181189
defer systemWg.Done()
182190

183191
log.Info("Upserting system", "name", system.Name)
184-
systemID, err := upsertSystem(ctx, client, workspaceID, slug, system)
192+
systemID, err := upsertSystem(ctx, client, workspaceID, system)
185193
if err != nil {
186194
log.Error("Failed to upsert system", "name", system.Name, "error", err)
187195
return
@@ -204,14 +212,13 @@ func processSystemDeployments(
204212
system System,
205213
) {
206214
var deploymentWg sync.WaitGroup
207-
for deploymentSlug, deployment := range system.Deployments {
215+
for _, deployment := range system.Deployments {
208216
deploymentWg.Add(1)
209217
log.Info("Creating deployment", "system", system.Name, "name", deployment.Name)
210218
go processDeployment(
211219
ctx,
212220
client,
213221
systemID,
214-
deploymentSlug,
215222
deployment,
216223
&deploymentWg,
217224
)
@@ -223,13 +230,12 @@ func processDeployment(
223230
ctx context.Context,
224231
client *api.ClientWithResponses,
225232
systemID uuid.UUID,
226-
deploymentSlug string,
227233
deployment Deployment,
228234
deploymentWg *sync.WaitGroup,
229235
) {
230236
defer deploymentWg.Done()
231237

232-
body := createDeploymentRequestBody(systemID, deploymentSlug, deployment)
238+
body := createDeploymentRequestBody(systemID, deployment)
233239

234240
if deployment.JobAgent != nil {
235241
jobAgentUUID, err := uuid.Parse(deployment.JobAgent.Id)
@@ -247,10 +253,10 @@ func processDeployment(
247253
}
248254
}
249255

250-
func createDeploymentRequestBody(systemID uuid.UUID, slug string, deployment Deployment) api.CreateDeploymentJSONBody {
256+
func createDeploymentRequestBody(systemID uuid.UUID, deployment Deployment) api.CreateDeploymentJSONBody {
251257
return api.CreateDeploymentJSONBody{
252-
Slug: slug,
253258
SystemId: systemID,
259+
Slug: deployment.Slug,
254260
Name: deployment.Name,
255261
Description: deployment.Description,
256262
}
@@ -282,13 +288,12 @@ func upsertSystem(
282288
ctx context.Context,
283289
client *api.ClientWithResponses,
284290
workspaceID uuid.UUID,
285-
slug string,
286291
system System,
287292
) (string, error) {
288293
resp, err := client.CreateSystemWithResponse(ctx, api.CreateSystemJSONRequestBody{
289-
Slug: slug,
290294
WorkspaceId: workspaceID,
291295
Name: system.Name,
296+
Slug: system.Slug,
292297
Description: &system.Description,
293298
})
294299

0 commit comments

Comments
 (0)