-
Notifications
You must be signed in to change notification settings - Fork 2
/
status.go
45 lines (41 loc) · 1.59 KB
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package environment
import (
"context"
"fmt"
radixv1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/util/retry"
)
func (env *Environment) syncStatus(ctx context.Context, re *radixv1.RadixEnvironment, time metav1.Time) error {
err := env.updateRadixEnvironmentStatus(ctx, re, func(currStatus *radixv1.RadixEnvironmentStatus) {
currStatus.Orphaned = !existsInAppConfig(env.appConfig, re.Spec.EnvName)
// time is parameterized for testability
currStatus.Reconciled = time
})
if err != nil {
return fmt.Errorf("failed to update status on environment %s: %v", re.Spec.EnvName, err)
}
return nil
}
func (env *Environment) updateRadixEnvironmentStatus(ctx context.Context, re *radixv1.RadixEnvironment, changeStatusFunc func(currStatus *radixv1.RadixEnvironmentStatus)) error {
radixEnvironmentInterface := env.radixclient.RadixV1().RadixEnvironments()
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
name := re.GetName()
currentEnv, err := radixEnvironmentInterface.Get(ctx, name, metav1.GetOptions{})
if err != nil {
return err
}
changeStatusFunc(¤tEnv.Status)
updated, err := radixEnvironmentInterface.UpdateStatus(ctx, currentEnv, metav1.UpdateOptions{})
if err == nil && env.config.GetName() == name {
currentEnv, err = radixEnvironmentInterface.Get(ctx, name, metav1.GetOptions{})
if err != nil {
return err
}
env.config = currentEnv
env.logger.Debug().Msgf("updated status of RadixEnvironment (revision %s)", updated.GetResourceVersion())
return nil
}
return err
})
}