generated from padok-team/yatas-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gkeConditions.go
50 lines (40 loc) · 1.2 KB
/
gkeConditions.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 gke
import (
"net"
"regexp"
"github.com/padok-team/yatas/plugins/commons"
)
// A region name is always composed of two parts separated by a dash, and ends with a number.
// For example us-central1.
func isValidRegionName(name string) bool {
regionPattern := regexp.MustCompile(`^[a-z]+-[a-z]+\d+$`)
return regionPattern.MatchString(name)
}
func GKEControlPlaneIsRegional(resource commons.Resource) bool {
cluster, ok := resource.(*GKECluster)
if !ok {
return false
}
return isValidRegionName(cluster.Cluster.Location)
}
func GKEIsUsingWorkloadIdentity(resource commons.Resource) bool {
cluster, ok := resource.(*GKECluster)
if !ok {
return false
}
return cluster.Cluster.WorkloadIdentityConfig != nil && cluster.Cluster.WorkloadIdentityConfig.WorkloadPool != ""
}
func isPublicIP(ip string) bool {
parsedIP := net.ParseIP(ip)
if parsedIP == nil {
return false
}
return !parsedIP.IsPrivate()
}
func GKEIsNotExposedOnPublicEndpoint(resource commons.Resource) bool {
cluster, ok := resource.(*GKECluster)
if !ok {
return false
}
return cluster.Cluster.PrivateClusterConfig != nil && cluster.Cluster.PrivateClusterConfig.EnablePrivateEndpoint && !isPublicIP(cluster.Cluster.Endpoint)
}