Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.

Commit dbd950d

Browse files
authored
Resolved offerings (#2369)
Signed-off-by: Grant Linville <grant@acorn.io>
1 parent 264244f commit dbd950d

File tree

274 files changed

+2114
-1300
lines changed

Some content is hidden

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

274 files changed

+2114
-1300
lines changed

docs/docs/40-admin/03-computeclasses.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ affinity: # The same affinity fields for Pods
4040
operator: In
4141
values:
4242
- bar
43+
supportedRegions: ["local"] # should always be set to ["local"]
4344
```
4445
4546
If `memory.min`, `memory.max`, `memory.values`, `affinity`, and `tolerations` are not given, then there are no scheduling rules for workloads using the compute class.

pkg/apis/api.acorn.io/v1/types.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ func (in *App) GetStopped() bool {
2323
}
2424

2525
func (in *App) GetRegion() string {
26-
if in.Spec.Region != "" {
27-
return in.Spec.Region
28-
}
29-
return in.Status.Defaults.Region
26+
return in.Status.ResolvedOfferings.Region
3027
}
3128

3229
type Acornfile v1.AppSpec

pkg/apis/internal.acorn.io/v1/appinstance.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type AppInstanceCondition string
1414

1515
var (
1616
AppInstanceConditionDefined = "defined"
17-
AppInstanceConditionDefaults = "defaults"
17+
AppInstanceConditionResolvedOfferings = "resolved-offerings"
1818
AppInstanceConditionScheduling = "scheduling"
1919
AppInstanceConditionNamespace = "namespace"
2020
AppInstanceConditionParsed = "parsed"
@@ -52,23 +52,18 @@ type AppInstance struct {
5252
}
5353

5454
func (in *AppInstance) HasRegion(region string) bool {
55-
return in.Status.Defaults.Region == region || in.Spec.Region == region
55+
return in.Status.ResolvedOfferings.Region == region
5656
}
5757

5858
func (in *AppInstance) GetRegion() string {
59-
if in.Spec.Region != "" {
60-
return in.Spec.Region
61-
}
62-
return in.Status.Defaults.Region
59+
return in.Status.ResolvedOfferings.Region
6360
}
6461

6562
func (in *AppInstance) SetDefaultRegion(region string) {
66-
if in.Spec.Region == "" {
67-
if in.Status.Defaults.Region == "" {
68-
in.Status.Defaults.Region = region
69-
}
70-
} else {
71-
in.Status.Defaults.Region = ""
63+
if in.Spec.Region != "" {
64+
in.Status.ResolvedOfferings.Region = in.Spec.Region
65+
} else if in.Status.ResolvedOfferings.Region == "" {
66+
in.Status.ResolvedOfferings.Region = region
7267
}
7368
}
7469

@@ -209,7 +204,7 @@ type AppInstanceStatus struct {
209204
AppStatus AppStatus `json:"appStatus,omitempty"`
210205
Scheduling map[string]Scheduling `json:"scheduling,omitempty"`
211206
Conditions []Condition `json:"conditions,omitempty"`
212-
Defaults Defaults `json:"defaults,omitempty"`
207+
ResolvedOfferings ResolvedOfferings `json:"resolvedOfferings,omitempty"`
213208
Summary CommonSummary `json:"summary,omitempty"`
214209
Permissions []Permissions `json:"permissions,omitempty"` // Permissions given to this appInstance (only containers within, not nested Acorns/Services)
215210
DeniedConsumerPermissions []Permissions `json:"deniedConsumerPermissions,omitempty"` // Permissions given to this appInstance by a consumed service, which it is not authorized to have
@@ -229,19 +224,25 @@ type AppStatusStaged struct {
229224
ImageAllowed *bool `json:"imageAllowed,omitempty"`
230225
}
231226

232-
type Defaults struct {
233-
VolumeSize *resource.Quantity `json:"volumeSize,omitempty"`
234-
Volumes map[string]VolumeDefault `json:"volumes,omitempty"`
235-
Memory map[string]*int64 `json:"memory,omitempty"`
236-
Region string `json:"region,omitempty"`
227+
type ResolvedOfferings struct {
228+
Volumes map[string]VolumeResolvedOffering `json:"volumes,omitempty"`
229+
VolumeSize *resource.Quantity `json:"volumeSize,omitempty"`
230+
Containers map[string]ContainerResolvedOffering `json:"containers,omitempty"`
231+
Region string `json:"region,omitempty"`
237232
}
238233

239-
type VolumeDefault struct {
234+
type VolumeResolvedOffering struct {
240235
Class string `json:"class,omitempty"`
241236
Size Quantity `json:"size,omitempty"`
242237
AccessModes AccessModes `json:"accessModes,omitempty"`
243238
}
244239

240+
type ContainerResolvedOffering struct {
241+
Class string `json:"class,omitempty"`
242+
Memory *int64 `json:"memory,omitempty"`
243+
CPUScaler *float64 `json:"cpuScaler,omitempty"`
244+
}
245+
245246
type Scheduling struct {
246247
Requirements corev1.ResourceRequirements `json:"requirements,omitempty"`
247248
Affinity *corev1.Affinity `json:"affinity,omitempty"`

pkg/apis/internal.acorn.io/v1/zz_generated.deepcopy.go

Lines changed: 80 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cli/testdata/TestAll/acorn_all_-o_json.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ACORNS:
3131
},
3232
"appSpec": {},
3333
"appStatus": {},
34-
"defaults": {},
34+
"resolvedOfferings": {},
3535
"summary": {}
3636
}
3737
}

pkg/cli/testdata/TestAll/acorn_all_-o_yaml.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ items:
1717
appSpec: {}
1818
appStatus: {}
1919
columns: {}
20-
defaults: {}
20+
resolvedOfferings: {}
2121
staged:
2222
appImage:
2323
buildContext: {}

pkg/controller/appdefinition/deploy.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,12 +597,34 @@ func containerAnnotation(container v1.Container) string {
597597
return string(json)
598598
}
599599

600+
func resolvedOfferingsAnnotation(appInstance *v1.AppInstance, container v1.Container) (string, error) {
601+
if resolved, exists := appInstance.Status.ResolvedOfferings.Containers[container.Name]; exists {
602+
data, err := convert.EncodeToMap(resolved)
603+
if err != nil {
604+
return "", err
605+
}
606+
607+
j, err := json.Marshal(data)
608+
if err != nil {
609+
return "", err
610+
}
611+
612+
return string(j), nil
613+
}
614+
return "", nil
615+
}
616+
600617
func podAnnotations(appInstance *v1.AppInstance, container v1.Container) map[string]string {
601618
annotations := map[string]string{
602619
labels.AcornContainerSpec: containerAnnotation(container),
603620
}
604621
addPrometheusAnnotations(annotations, container)
605622

623+
offerings, err := resolvedOfferingsAnnotation(appInstance, container)
624+
if err == nil && offerings != "" {
625+
annotations[labels.AcornContainerResolvedOfferings] = offerings
626+
}
627+
606628
images := map[string]string{}
607629
addImageAnnotations(images, appInstance, container)
608630

pkg/controller/appdefinition/testdata/TestComputeMem.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ status:
116116
appSpec: {}
117117
appStatus: {}
118118
columns: {}
119-
defaults: {}
119+
resolvedOfferings: {}
120120
staged:
121121
appImage:
122122
buildContext: {}
@@ -157,7 +157,7 @@ status:
157157
appSpec: {}
158158
appStatus: {}
159159
columns: {}
160-
defaults: {}
160+
resolvedOfferings: {}
161161
staged:
162162
appImage:
163163
buildContext: {}
@@ -200,8 +200,8 @@ status:
200200
status: "True"
201201
success: true
202202
type: defined
203-
defaults: {}
204203
namespace: app-created-namespace
204+
resolvedOfferings: {}
205205
staged:
206206
appImage:
207207
buildContext: {}

pkg/controller/appdefinition/testdata/acorn/basic/expected.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ status:
132132
appSpec: {}
133133
appStatus: {}
134134
columns: {}
135-
defaults: {}
135+
resolvedOfferings: {}
136136
staged:
137137
appImage:
138138
buildContext: {}
@@ -212,8 +212,8 @@ status:
212212
status: "True"
213213
success: true
214214
type: defined
215-
defaults: {}
216215
namespace: app-created-namespace
216+
resolvedOfferings: {}
217217
staged:
218218
appImage:
219219
buildContext: {}

0 commit comments

Comments
 (0)