forked from keikoproj/aws-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.go
57 lines (48 loc) · 1.14 KB
/
example.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
package main
import (
"fmt"
"os"
awsauth "github.com/dmitryint/aws-auth/pkg/mapper"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)
func main() {
kubePath := os.Getenv("KUBECONFIG")
config, err := clientcmd.BuildConfigFromFlags("", kubePath)
if err != nil {
os.Exit(1)
}
client, err := kubernetes.NewForConfig(config)
if err != nil {
os.Exit(1)
}
awsAuth := awsauth.New(client, false)
myUpsertRole := &awsauth.MapperArguments{
MapRoles: true,
RoleARN: "arn:aws:iam::555555555555:role/my-new-node-group-NodeInstanceRole-74RF4UBDUKL6",
Username: "system:node:{{EC2PrivateDNSName}}",
Groups: []string{
"system:bootstrappers",
"system:nodes",
},
}
err = awsAuth.Upsert(myUpsertRole)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
myDeleteRole := &awsauth.MapperArguments{
MapRoles: true,
RoleARN: "arn:aws:iam::555555555555:role/my-new-node-group-NodeInstanceRole-74RF4UBDUKL6",
Username: "system:node:{{EC2PrivateDNSName}}",
Groups: []string{
"system:bootstrappers",
"system:nodes",
},
}
err = awsAuth.Remove(myDeleteRole)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}