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

Commit 01ccd48

Browse files
authored
fix: resolved offerings: calculate if a container is missing (#2480)
Signed-off-by: Grant Linville <[email protected]>
1 parent 7515a20 commit 01ccd48

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

pkg/controller/appdefinition/deploy.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,8 @@ func containerAnnotation(container v1.Container) string {
628628
return string(json)
629629
}
630630

631-
func resolvedOfferingsAnnotation(appInstance *v1.AppInstance, container v1.Container) (string, error) {
632-
if resolved, exists := appInstance.Status.ResolvedOfferings.Containers[container.Name]; exists {
631+
func resolvedOfferingsAnnotation(appInstance *v1.AppInstance, containerName string) (string, error) {
632+
if resolved, exists := appInstance.Status.ResolvedOfferings.Containers[containerName]; exists {
633633
data, err := convert.EncodeToMap(resolved)
634634
if err != nil {
635635
return "", err
@@ -645,13 +645,13 @@ func resolvedOfferingsAnnotation(appInstance *v1.AppInstance, container v1.Conta
645645
return "", nil
646646
}
647647

648-
func podAnnotations(appInstance *v1.AppInstance, container v1.Container) map[string]string {
648+
func podAnnotations(appInstance *v1.AppInstance, containerName string, container v1.Container) map[string]string {
649649
annotations := map[string]string{
650650
labels.AcornContainerSpec: containerAnnotation(container),
651651
}
652652
addPrometheusAnnotations(annotations, container)
653653

654-
offerings, err := resolvedOfferingsAnnotation(appInstance, container)
654+
offerings, err := resolvedOfferingsAnnotation(appInstance, containerName)
655655
if err == nil && offerings != "" {
656656
annotations[labels.AcornContainerResolvedOfferings] = offerings
657657
}
@@ -814,7 +814,7 @@ func toFunctionDeployment(req router.Request, appInstance *v1.AppInstance, tag n
814814
Template: corev1.PodTemplateSpec{
815815
ObjectMeta: metav1.ObjectMeta{
816816
Labels: podLabels,
817-
Annotations: typed.Concat(deploymentAnnotations, podAnnotations(appInstance, container), secretAnnotations),
817+
Annotations: typed.Concat(deploymentAnnotations, podAnnotations(appInstance, name, container), secretAnnotations),
818818
},
819819
Spec: corev1.PodSpec{
820820
Affinity: appInstance.Status.Scheduling[name].Affinity,
@@ -906,7 +906,7 @@ func toDeployment(req router.Request, appInstance *v1.AppInstance, tag name.Refe
906906
Template: corev1.PodTemplateSpec{
907907
ObjectMeta: metav1.ObjectMeta{
908908
Labels: podLabels,
909-
Annotations: typed.Concat(deploymentAnnotations, podAnnotations(appInstance, container), secretAnnotations),
909+
Annotations: typed.Concat(deploymentAnnotations, podAnnotations(appInstance, name, container), secretAnnotations),
910910
},
911911
Spec: corev1.PodSpec{
912912
Affinity: appInstance.Status.Scheduling[name].Affinity,

pkg/controller/appdefinition/jobs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func toJob(req router.Request, appInstance *v1.AppInstance, pullSecrets *PullSec
147147
Template: corev1.PodTemplateSpec{
148148
ObjectMeta: metav1.ObjectMeta{
149149
Labels: podLabels,
150-
Annotations: labels.Merge(podAnnotations(appInstance, container), baseAnnotations),
150+
Annotations: labels.Merge(podAnnotations(appInstance, name, container), baseAnnotations),
151151
},
152152
Spec: corev1.PodSpec{
153153
Affinity: appInstance.Status.Scheduling[name].Affinity,

pkg/controller/resolvedofferings/resolvedofferings.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ import (
88
)
99

1010
// Calculate is a handler that sets the resolved offerings for an AppInstance to its status.
11-
//
12-
// This is necessary because querying for resolved offerings will result in all running
13-
// AppInstances using that default to redeploy when a default changes. By
14-
// calculating the resolved offerings only when the generation changes, we can ensure that
15-
// updated resolved offerings are only applied when an AppInstance is updated directly.
1611
func Calculate(req router.Request, resp router.Response) (err error) {
1712
appInstance := req.Object.(*internalv1.AppInstance)
1813
status := condition.Setter(appInstance, resp, internalv1.AppInstanceConditionResolvedOfferings)
@@ -34,7 +29,10 @@ func Calculate(req router.Request, resp router.Response) (err error) {
3429
return err
3530
}
3631

37-
if appInstance.Generation != appInstance.Status.ObservedGeneration {
32+
// Calculate the resolved offerings for the AppInstance if its generation changed, or if at least one of
33+
// the containers has not been resolved yet. The generation check prevents the app from redeploying
34+
// if its compute class gets changed.
35+
if appInstance.Generation != appInstance.Status.ObservedGeneration || needsCalculation(appInstance) {
3836
if err = calculate(req, appInstance); err != nil {
3937
return err
4038
}
@@ -61,3 +59,12 @@ func calculate(req router.Request, appInstance *internalv1.AppInstance) error {
6159

6260
return nil
6361
}
62+
63+
func needsCalculation(appInstance *internalv1.AppInstance) bool {
64+
for _, name := range appInstance.GetAllContainerNames() {
65+
if _, ok := appInstance.Status.ResolvedOfferings.Containers[name]; !ok {
66+
return true
67+
}
68+
}
69+
return false
70+
}

0 commit comments

Comments
 (0)