-
Notifications
You must be signed in to change notification settings - Fork 110
/
conditions.go
51 lines (47 loc) · 1.67 KB
/
conditions.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
package virtualservice
import (
appmesh "github.com/aws/aws-app-mesh-controller-for-k8s/apis/appmesh/v1beta2"
"github.com/aws/aws-sdk-go/aws"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// getCondition will get pointer to virtualService's existing condition.
func getCondition(vs *appmesh.VirtualService, conditionType appmesh.VirtualServiceConditionType) *appmesh.VirtualServiceCondition {
for i := range vs.Status.Conditions {
if vs.Status.Conditions[i].Type == conditionType {
return &vs.Status.Conditions[i]
}
}
return nil
}
// updateCondition will update virtualService's condition. returns whether it's updated.
func updateCondition(vs *appmesh.VirtualService, conditionType appmesh.VirtualServiceConditionType, status corev1.ConditionStatus, reason *string, message *string) bool {
now := metav1.Now()
existingCondition := getCondition(vs, conditionType)
if existingCondition == nil {
newCondition := appmesh.VirtualServiceCondition{
Type: conditionType,
Status: status,
LastTransitionTime: &now,
Reason: reason,
Message: message,
}
vs.Status.Conditions = append(vs.Status.Conditions, newCondition)
return true
}
hasChanged := false
if existingCondition.Status != status {
existingCondition.Status = status
existingCondition.LastTransitionTime = &now
hasChanged = true
}
if aws.StringValue(existingCondition.Reason) != aws.StringValue(reason) {
existingCondition.Reason = reason
hasChanged = true
}
if aws.StringValue(existingCondition.Message) != aws.StringValue(message) {
existingCondition.Message = message
hasChanged = true
}
return hasChanged
}