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

Resolved offerings #2369

Merged
merged 8 commits into from
Dec 13, 2023
Merged
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
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
5 changes: 1 addition & 4 deletions pkg/apis/api.acorn.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ func (in *App) GetStopped() bool {
}

func (in *App) GetRegion() string {
if in.Spec.Region != "" {
return in.Spec.Region
}
return in.Status.Defaults.Region
return in.Status.ResolvedOfferings.Region
StrongMonkey marked this conversation as resolved.
Show resolved Hide resolved
}

type Acornfile v1.AppSpec
Expand Down
39 changes: 20 additions & 19 deletions pkg/apis/internal.acorn.io/v1/appinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type AppInstanceCondition string

var (
AppInstanceConditionDefined = "defined"
AppInstanceConditionDefaults = "defaults"
AppInstanceConditionResolvedOfferings = "resolved-offerings"
AppInstanceConditionScheduling = "scheduling"
AppInstanceConditionNamespace = "namespace"
AppInstanceConditionParsed = "parsed"
Expand Down Expand Up @@ -52,23 +52,18 @@ type AppInstance struct {
}

func (in *AppInstance) HasRegion(region string) bool {
return in.Status.Defaults.Region == region || in.Spec.Region == region
return in.Status.ResolvedOfferings.Region == region
}

func (in *AppInstance) GetRegion() string {
if in.Spec.Region != "" {
return in.Spec.Region
}
return in.Status.Defaults.Region
return in.Status.ResolvedOfferings.Region
}

func (in *AppInstance) SetDefaultRegion(region string) {
if in.Spec.Region == "" {
if in.Status.Defaults.Region == "" {
in.Status.Defaults.Region = region
}
} else {
in.Status.Defaults.Region = ""
if in.Spec.Region != "" {
in.Status.ResolvedOfferings.Region = in.Spec.Region
} else if in.Status.ResolvedOfferings.Region == "" {
in.Status.ResolvedOfferings.Region = region
}
}

Expand Down Expand Up @@ -209,7 +204,7 @@ type AppInstanceStatus struct {
AppStatus AppStatus `json:"appStatus,omitempty"`
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 All @@ -229,19 +224,25 @@ type AppStatusStaged struct {
ImageAllowed *bool `json:"imageAllowed,omitempty"`
}

type Defaults struct {
VolumeSize *resource.Quantity `json:"volumeSize,omitempty"`
Volumes map[string]VolumeDefault `json:"volumes,omitempty"`
Memory map[string]*int64 `json:"memory,omitempty"`
Region string `json:"region,omitempty"`
type ResolvedOfferings struct {
Volumes map[string]VolumeResolvedOffering `json:"volumes,omitempty"`
VolumeSize *resource.Quantity `json:"volumeSize,omitempty"`
Containers map[string]ContainerResolvedOffering `json:"containers,omitempty"`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of storing a map of container name to memory request, we're storing a map of container name to a struct containing the following info:

  • memory request
  • computeclass name
  • cpuscaler value

Region string `json:"region,omitempty"`
}

type VolumeDefault struct {
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
143 changes: 80 additions & 63 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.

2 changes: 1 addition & 1 deletion pkg/cli/testdata/TestAll/acorn_all_-o_json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ACORNS:
},
"appSpec": {},
"appStatus": {},
"defaults": {},
"resolvedOfferings": {},
"summary": {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/testdata/TestAll/acorn_all_-o_yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ items:
appSpec: {}
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this error is still not handled...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Below this line there is a check for if err == nil, and then we attach the annotation. I don't actually want to return this error if it happens, since we can safely just ignore it and keep going.

if err == nil && offerings != "" {
annotations[labels.AcornContainerResolvedOfferings] = offerings
}

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

Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/appdefinition/testdata/TestComputeMem.golden
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ status:
appSpec: {}
appStatus: {}
columns: {}
defaults: {}
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down Expand Up @@ -157,7 +157,7 @@ status:
appSpec: {}
appStatus: {}
columns: {}
defaults: {}
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down Expand Up @@ -200,8 +200,8 @@ status:
status: "True"
success: true
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 @@ -132,7 +132,7 @@ status:
appSpec: {}
appStatus: {}
columns: {}
defaults: {}
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down Expand Up @@ -212,8 +212,8 @@ status:
status: "True"
success: true
type: defined
defaults: {}
namespace: app-created-namespace
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
Expand Down
Loading
Loading