forked from joeholley/supergloo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreconciler.go
50 lines (40 loc) · 1.13 KB
/
reconciler.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
package appmesh
import (
"context"
translator "github.com/solo-io/supergloo/pkg/translator/appmesh"
"github.com/pkg/errors"
v1 "github.com/solo-io/supergloo/pkg/api/v1"
)
type Reconciler interface {
Reconcile(ctx context.Context, mesh *v1.Mesh, desiredResources *translator.ResourceSnapshot) error
}
func NewReconciler(builder ClientBuilder) Reconciler {
return &reconciler{
clientBuilder: builder,
}
}
type reconciler struct {
clientBuilder ClientBuilder
}
func (r *reconciler) Reconcile(ctx context.Context, mesh *v1.Mesh, snapshot *translator.ResourceSnapshot) error {
// Get instance of AppMesh API client
client, err := r.clientBuilder.GetClientInstance(mesh.GetAwsAppMesh().AwsSecret, mesh.GetAwsAppMesh().Region)
if err != nil {
return errors.Wrapf(err, "failed to retrieve AppMesh API client instance")
}
existingMesh, err := client.GetMesh(ctx, mesh.Metadata.Name)
if err != nil {
return err
}
helper := newHelper(ctx, client, snapshot)
if existingMesh == nil {
if err := helper.createAll(); err != nil {
return err
}
} else {
if err := helper.reconcile(); err != nil {
return err
}
}
return nil
}