-
Notifications
You must be signed in to change notification settings - Fork 9
/
prepareeks.go
77 lines (61 loc) · 2.14 KB
/
prepareeks.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
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package main
import (
"context"
"log"
"google.golang.org/grpc"
"namespacelabs.dev/foundation/framework/kubernetes/kubedef"
"namespacelabs.dev/foundation/framework/kubernetes/kubetool"
"namespacelabs.dev/foundation/framework/provisioning"
"namespacelabs.dev/foundation/internal/fnerrors"
"namespacelabs.dev/foundation/internal/planning/tool/protocol"
"namespacelabs.dev/foundation/universe/aws/eks"
)
func main() {
if err := provisioning.HandleInvocation(context.Background(), func(sr grpc.ServiceRegistrar) {
h := provisioning.NewHandlers()
h.Any().HandleStack(provisionHook{})
protocol.RegisterInvocationServiceServer(sr, h.ServiceHandler())
}); err != nil {
log.Fatal(err)
}
}
type provisionHook struct{}
func (provisionHook) Apply(ctx context.Context, r provisioning.StackRequest, out *provisioning.ApplyOutput) error {
if r.Env.Runtime != "kubernetes" {
return fnerrors.BadInputError("universe/aws/irsa only supports kubernetes")
}
serviceAccount := &kubedef.ServiceAccountDetails{}
if err := r.UnpackInput(serviceAccount); err != nil {
return err
}
eksCluster := &eks.EKSCluster{}
if ok, err := r.CheckUnpackInput(eksCluster); err != nil {
return err
} else if !ok {
return nil
}
eksServerDetails := &eks.EKSServerDetails{}
if err := r.UnpackInput(eksServerDetails); err != nil {
return err
}
kr, err := kubetool.MustNamespace(r)
if err != nil {
return err
}
result, err := eks.PrepareIrsa(eksCluster, eksServerDetails.ComputedIamRoleName, kr.Namespace, serviceAccount.ServiceAccountName, r.Focus.Server)
if err != nil {
return err
}
out.Invocations = append(out.Invocations, result.Invocations...)
out.Extensions = append(out.Extensions, result.Extensions...)
return nil
}
func (provisionHook) Delete(ctx context.Context, r provisioning.StackRequest, out *provisioning.DeleteOutput) error {
if r.Env.Runtime != "kubernetes" {
return fnerrors.BadInputError("universe/aws/irsa only supports kubernetes")
}
return nil
}