This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
/
status.go
69 lines (55 loc) · 1.99 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package nodepool
import (
"context"
"github.com/giantswarm/microerror"
capzexp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/giantswarm/azure-operator/v5/pkg/annotation"
)
const (
// Types
Stage = "Stage"
// States
DeploymentUninitialized = ""
ScaleUpWorkerVMSS = "ScaleUpWorkerVMSS" // nolint:gosec
CordonOldWorkerInstances = "CordonOldWorkerInstances"
DrainOldWorkerInstances = "DrainOldWorkerInstances"
TerminateOldWorkerInstances = "TerminateOldWorkerInstances"
WaitForWorkersToBecomeReady = "WaitForWorkersToBecomeReady"
)
func (r *Resource) saveCurrentState(ctx context.Context, customObject capzexp.AzureMachinePool, state string) error {
// Get the newest CR version. Otherwise status update may fail because of:
//
// the object has been modified; please apply your changes to the
// latest version and try again
//
azureMachinePool := &capzexp.AzureMachinePool{}
err := r.CtrlClient.Get(ctx, client.ObjectKey{Namespace: customObject.Namespace, Name: customObject.Name}, azureMachinePool)
if err != nil {
return microerror.Mask(err)
}
if azureMachinePool.Annotations == nil {
azureMachinePool.Annotations = map[string]string{}
}
azureMachinePool.Annotations[annotation.StateMachineCurrentState] = state
err = r.CtrlClient.Update(ctx, azureMachinePool)
if err != nil {
return microerror.Mask(err)
}
return nil
}
func (r *Resource) getCurrentState(ctx context.Context, customObject capzexp.AzureMachinePool) (string, error) {
azureMachinePool := &capzexp.AzureMachinePool{}
err := r.CtrlClient.Get(ctx, client.ObjectKey{Namespace: customObject.Namespace, Name: customObject.Name}, azureMachinePool)
if err != nil {
return "", microerror.Mask(err)
}
if azureMachinePool.Annotations == nil {
azureMachinePool.Annotations = map[string]string{}
}
status, exists := azureMachinePool.Annotations[annotation.StateMachineCurrentState]
if !exists {
return "", nil
}
return status, nil
}