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
/
status.go
115 lines (98 loc) · 3.14 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package masters
import (
providerv1alpha1 "github.com/giantswarm/apiextensions/pkg/apis/provider/v1alpha1"
"github.com/giantswarm/microerror"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
// Types
Stage = "Stage"
DeploymentTemplateChecksum = "TemplateChecksum"
DeploymentParametersChecksum = "ParametersChecksum"
// States
BlockAPICalls = "BlockAPICalls"
CheckFlatcarMigrationNeeded = "CheckFlatcarMigrationNeeded"
ClusterUpgradeRequirementCheck = "ClusterUpgradeRequirementCheck"
DeallocateLegacyInstance = "DeallocateLegacyInstance"
DeleteLegacyVMSS = "DeleteLegacyVMSS"
DeploymentUninitialized = "DeploymentUninitialized"
DeploymentInitialized = "DeploymentInitialized"
DeploymentCompleted = "DeploymentCompleted"
Empty = ""
ManualInterventionRequired = "ManualInterventionRequired"
MasterInstancesUpgrading = "MasterInstancesUpgrading"
ProvisioningSuccessful = "ProvisioningSuccessful"
RestartKubeletOnWorkers = "RestartKubeletOnWorkers"
UnblockAPICalls = "UnblockAPICalls"
WaitForBackupConfirmation = "WaitForBackupConfirmation"
WaitForMastersToBecomeReady = "WaitForMastersToBecomeReady"
WaitForRestore = "WaitForRestore"
)
func (r *Resource) setResourceStatus(customObject providerv1alpha1.AzureConfig, t string, s 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
//
{
c, err := r.g8sClient.ProviderV1alpha1().AzureConfigs(customObject.Namespace).Get(customObject.Name, metav1.GetOptions{})
if err != nil {
return microerror.Mask(err)
}
customObject = *c
}
resourceStatus := providerv1alpha1.StatusClusterResource{
Conditions: []providerv1alpha1.StatusClusterResourceCondition{
{
Status: s,
Type: t,
},
},
Name: Name,
}
var set bool
for i, r := range customObject.Status.Cluster.Resources {
if r.Name != Name {
continue
}
for _, c := range r.Conditions {
if c.Type == t {
continue
}
resourceStatus.Conditions = append(resourceStatus.Conditions, c)
}
customObject.Status.Cluster.Resources[i] = resourceStatus
set = true
}
if !set {
customObject.Status.Cluster.Resources = append(customObject.Status.Cluster.Resources, resourceStatus)
}
{
n := customObject.GetNamespace()
_, err := r.g8sClient.ProviderV1alpha1().AzureConfigs(n).UpdateStatus(&customObject)
if err != nil {
return microerror.Mask(err)
}
}
return nil
}
func (r *Resource) getResourceStatus(customObject providerv1alpha1.AzureConfig, t string) (string, error) {
{
c, err := r.g8sClient.ProviderV1alpha1().AzureConfigs(customObject.Namespace).Get(customObject.Name, metav1.GetOptions{})
if err != nil {
return "", microerror.Mask(err)
}
customObject = *c
}
for _, r := range customObject.Status.Cluster.Resources {
if r.Name != Name {
continue
}
for _, c := range r.Conditions {
if c.Type == t {
return c.Status, nil
}
}
}
return "", nil
}