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

Commit

Permalink
Resolved offerings second try
Browse files Browse the repository at this point in the history
Signed-off-by: Grant Linville <[email protected]>
  • Loading branch information
g-linville committed Dec 14, 2023
1 parent 8b9acb4 commit acd4a24
Show file tree
Hide file tree
Showing 231 changed files with 3,811 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/docs/40-admin/03-computeclasses.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ affinity: # The same affinity fields for Pods
operator: In
values:
- bar
supportedRegions: ["local"] # should always be set to ["local"]
```
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.
Expand Down
21 changes: 21 additions & 0 deletions pkg/apis/internal.acorn.io/v1/appinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type AppInstanceCondition string
var (
AppInstanceConditionDefined = "defined"
AppInstanceConditionDefaults = "defaults"
AppInstanceConditionResolvedOfferings = "resolved-offerings"
AppInstanceConditionScheduling = "scheduling"
AppInstanceConditionNamespace = "namespace"
AppInstanceConditionParsed = "parsed"
Expand Down Expand Up @@ -210,6 +211,7 @@ type AppInstanceStatus struct {
Scheduling map[string]Scheduling `json:"scheduling,omitempty"`
Conditions []Condition `json:"conditions,omitempty"`
Defaults Defaults `json:"defaults,omitempty"`
ResolvedOfferings ResolvedOfferings `json:"resolvedOfferings,omitempty"`
Summary CommonSummary `json:"summary,omitempty"`
Permissions []Permissions `json:"permissions,omitempty"` // Permissions given to this appInstance (only containers within, not nested Acorns/Services)
DeniedConsumerPermissions []Permissions `json:"deniedConsumerPermissions,omitempty"` // Permissions given to this appInstance by a consumed service, which it is not authorized to have
Expand Down Expand Up @@ -242,6 +244,25 @@ type VolumeDefault struct {
AccessModes AccessModes `json:"accessModes,omitempty"`
}

type ResolvedOfferings struct {
Volumes map[string]VolumeResolvedOffering `json:"volumes,omitempty"`
VolumeSize *resource.Quantity `json:"volumeSize,omitempty"`
Containers map[string]ContainerResolvedOffering `json:"containers,omitempty"`
Region string `json:"region,omitempty"`
}

type VolumeResolvedOffering struct {
Class string `json:"class,omitempty"`
Size Quantity `json:"size,omitempty"`
AccessModes AccessModes `json:"accessModes,omitempty"`
}

type ContainerResolvedOffering struct {
Class string `json:"class,omitempty"`
Memory *int64 `json:"memory,omitempty"`
CPUScaler *float64 `json:"cpuScaler,omitempty"`
}

type Scheduling struct {
Requirements corev1.ResourceRequirements `json:"requirements,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
Expand Down
80 changes: 80 additions & 0 deletions pkg/apis/internal.acorn.io/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/cli/testdata/TestAll/acorn_all_-o_json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ACORNS:
"appSpec": {},
"appStatus": {},
"defaults": {},
"resolvedOfferings": {},
"summary": {}
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/testdata/TestAll/acorn_all_-o_yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ items:
appStatus: {}
columns: {}
defaults: {}
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down
22 changes: 22 additions & 0 deletions pkg/controller/appdefinition/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,12 +597,34 @@ func containerAnnotation(container v1.Container) string {
return string(json)
}

func resolvedOfferingsAnnotation(appInstance *v1.AppInstance, container v1.Container) (string, error) {
if resolved, exists := appInstance.Status.ResolvedOfferings.Containers[container.Name]; exists {
data, err := convert.EncodeToMap(resolved)
if err != nil {
return "", err
}

j, err := json.Marshal(data)
if err != nil {
return "", err
}

return string(j), nil
}
return "", nil
}

func podAnnotations(appInstance *v1.AppInstance, container v1.Container) map[string]string {
annotations := map[string]string{
labels.AcornContainerSpec: containerAnnotation(container),
}
addPrometheusAnnotations(annotations, container)

offerings, err := resolvedOfferingsAnnotation(appInstance, container)
if err == nil && offerings != "" {
annotations[labels.AcornContainerResolvedOfferings] = offerings
}

images := map[string]string{}
addImageAnnotations(images, appInstance, container)

Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/appdefinition/testdata/TestComputeMem.golden
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ status:
appStatus: {}
columns: {}
defaults: {}
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down Expand Up @@ -158,6 +159,7 @@ status:
appStatus: {}
columns: {}
defaults: {}
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down Expand Up @@ -202,6 +204,7 @@ status:
type: defined
defaults: {}
namespace: app-created-namespace
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ status:
appStatus: {}
columns: {}
defaults: {}
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down Expand Up @@ -214,6 +215,7 @@ status:
type: defined
defaults: {}
namespace: app-created-namespace
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ status:
appStatus: {}
columns: {}
defaults: {}
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down Expand Up @@ -256,6 +257,7 @@ status:
type: defined
defaults: {}
namespace: app-created-namespace
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ status:
type: namespace
defaults: {}
namespace: default-1234567890ab
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down Expand Up @@ -52,6 +53,7 @@ status:
type: namespace
defaults: {}
namespace: default-1234567890ab
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ status:
type: image-pull
defaults: {}
namespace: app-created-namespace
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ status:
oneimage: 2097152
namespace: app-created-namespace
observedGeneration: 1
resolvedOfferings: {}
scheduling:
left:
requirements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ status:
oneimage: 1048576
namespace: app-created-namespace
observedGeneration: 1
resolvedOfferings: {}
scheduling:
left:
requirements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ status:
oneimage: 1048576
namespace: app-created-namespace
observedGeneration: 1
resolvedOfferings: {}
scheduling:
left:
requirements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ status:
twoimage: 1048576
namespace: app-created-namespace
observedGeneration: 1
resolvedOfferings: {}
scheduling:
oneimage:
affinity:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ status:
oneimage: 1048576
namespace: app-created-namespace
observedGeneration: 1
resolvedOfferings: {}
scheduling:
left:
requirements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ status:
oneimage: 1048576
namespace: app-created-namespace
observedGeneration: 1
resolvedOfferings: {}
scheduling:
left:
requirements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ status:
twoimage: 0
namespace: app-created-namespace
observedGeneration: 1
resolvedOfferings: {}
scheduling:
oneimage:
affinity:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ status:
oneimage: 1048576
namespace: app-created-namespace
observedGeneration: 1
resolvedOfferings: {}
scheduling:
left:
requirements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ status:
type: defined
defaults: {}
namespace: app-created-namespace
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ status:
type: defined
defaults: {}
namespace: app-created-namespace
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ status:
type: defined
defaults: {}
namespace: app-created-namespace
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ status:
type: defined
defaults: {}
namespace: app-created-namespace
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ status:
type: defined
defaults: {}
namespace: app-created-namespace
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down
Loading

0 comments on commit acd4a24

Please sign in to comment.