/
utils.go
49 lines (42 loc) · 1.06 KB
/
utils.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
package kube
import (
"fmt"
"os"
"strings"
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/duration"
)
func GetClusterName(clusterName string) (string, error) {
if clusterName == "" {
clusterName = os.Getenv("AWS_EKS_CLUSTER")
if clusterName == "" {
clusterName, err := getClusterFromKubeconfig()
if err != nil {
return "", err
}
// if clusterName is ARN
if strings.HasPrefix(clusterName, "arn") {
return strings.Split(clusterName, "/")[len(strings.Split(clusterName, "/"))-1], nil
}
return clusterName, nil
}
return clusterName, nil
}
return clusterName, nil
}
func GetRegion(region string) (string, error) {
if region == "" {
region = os.Getenv("AWS_REGION")
if region == "" {
return "", fmt.Errorf("please pass region name with --region or with AWS_REGION environment variable")
}
return region, nil
}
return region, nil
}
func GetAge(creationStamp metav1.Time) string {
currentTime := time.Now()
diff := currentTime.Sub(creationStamp.Time)
return duration.HumanDuration(diff)
}