-
Notifications
You must be signed in to change notification settings - Fork 110
/
manager.go
70 lines (60 loc) · 2.05 KB
/
manager.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
package backendgroup
import (
"context"
appmesh "github.com/aws/aws-app-mesh-controller-for-k8s/apis/appmesh/v1beta2"
"github.com/aws/aws-app-mesh-controller-for-k8s/pkg/aws/services"
"github.com/aws/aws-app-mesh-controller-for-k8s/test/framework/k8s"
"github.com/aws/aws-app-mesh-controller-for-k8s/test/framework/utils"
apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client"
)
type Manager interface {
WaitUntilBackendGroupActive(ctx context.Context, bg *appmesh.BackendGroup) (*appmesh.BackendGroup, error)
WaitUntilBackendGroupDeleted(ctx context.Context, bg *appmesh.BackendGroup) error
}
func NewManager(k8sClient client.Client, appMeshSDK services.AppMesh) Manager {
return &defaultManager{
k8sClient: k8sClient,
appMeshSDK: appMeshSDK,
}
}
type defaultManager struct {
k8sClient client.Client
appMeshSDK services.AppMesh
}
func (m *defaultManager) WaitUntilBackendGroupActive(ctx context.Context, bg *appmesh.BackendGroup) (*appmesh.BackendGroup, error) {
observedBG := &appmesh.BackendGroup{}
retryCount := 0
return observedBG, wait.PollImmediateUntil(utils.PollIntervalShort, func() (bool, error) {
err := m.k8sClient.Get(ctx, k8s.NamespacedName(bg), observedBG)
if err != nil {
if retryCount >= utils.PollRetries {
return false, err
}
retryCount++
return false, nil
}
/*
for _, condition := range observedBG.Status.Conditions {
if condition.Type == appmesh.BackendGroupActive && condition.Status == corev1.ConditionTrue {
return true, nil
}
}
*/
//return false, nil
return true, nil
}, ctx.Done())
}
func (m *defaultManager) WaitUntilBackendGroupDeleted(ctx context.Context, bg *appmesh.BackendGroup) error {
observedBG := &appmesh.BackendGroup{}
return wait.PollImmediateUntil(utils.PollIntervalShort, func() (bool, error) {
if err := m.k8sClient.Get(ctx, k8s.NamespacedName(bg), observedBG); err != nil {
if apierrs.IsNotFound(err) {
return true, nil
}
return false, err
}
return false, nil
}, ctx.Done())
}