This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
create.go
76 lines (66 loc) · 2.86 KB
/
create.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
70
71
72
73
74
75
76
package masters
import (
"context"
"fmt"
"github.com/giantswarm/microerror"
"github.com/giantswarm/azure-operator/service/controller/internal/state"
"github.com/giantswarm/azure-operator/service/controller/key"
)
// configureStateMachine configures and returns state machine that is driven by
// EnsureCreated.
func (r *Resource) configureStateMachine() {
sm := state.Machine{
Empty: r.emptyStateTransition,
CheckFlatcarMigrationNeeded: r.checkFlatcarMigrationNeededTransition,
WaitForBackupConfirmation: r.waitForBackupConfirmationTransition,
DeallocateLegacyInstance: r.deallocateLegacyInstanceTransition,
BlockAPICalls: r.blockAPICallsTransition,
DeploymentUninitialized: r.deploymentUninitializedTransition,
DeploymentInitialized: r.deploymentInitializedTransition,
ManualInterventionRequired: r.manualInterventionRequiredTransition,
ProvisioningSuccessful: r.provisioningSuccessfulTransition,
ClusterUpgradeRequirementCheck: r.clusterUpgradeRequirementCheckTransition,
MasterInstancesUpgrading: r.masterInstancesUpgradingTransition,
WaitForMastersToBecomeReady: r.waitForMastersToBecomeReadyTransition,
WaitForRestore: r.waitForRestoreTransition,
DeleteLegacyVMSS: r.deleteLegacyVMSSTransition,
UnblockAPICalls: r.unblockAPICallsTransition,
RestartKubeletOnWorkers: r.restartKubeletOnWorkersTransition,
DeploymentCompleted: r.deploymentCompletedTransition,
}
r.stateMachine = sm
}
// This resource applies the ARM template for the master instances, monitors the process and handles upgrades.
func (r *Resource) EnsureCreated(ctx context.Context, obj interface{}) error {
cr, err := key.ToCustomResource(obj)
if err != nil {
return microerror.Mask(err)
}
var newState state.State
var currentState state.State
{
s, err := r.getResourceStatus(cr, Stage)
if err != nil {
return microerror.Mask(err)
}
currentState = state.State(s)
r.logger.LogCtx(ctx, "level", "debug", "message", fmt.Sprintf("current state: %s", currentState))
newState, err = r.stateMachine.Execute(ctx, obj, currentState)
if err != nil {
return microerror.Mask(err)
}
}
if newState != currentState {
r.logger.LogCtx(ctx, "level", "debug", "message", fmt.Sprintf("new state: %s", newState))
r.logger.LogCtx(ctx, "level", "debug", "message", fmt.Sprintf("setting resource status to '%s/%s'", Stage, newState))
err = r.setResourceStatus(cr, Stage, string(newState))
if err != nil {
return microerror.Mask(err)
}
r.logger.LogCtx(ctx, "level", "debug", "message", fmt.Sprintf("set resource status to '%s/%s'", Stage, newState))
r.logger.LogCtx(ctx, "level", "debug", "message", "canceling reconciliation")
} else {
r.logger.LogCtx(ctx, "level", "debug", "message", "no state change")
}
return nil
}