-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathrelative_resource_name.go
43 lines (37 loc) · 1.65 KB
/
relative_resource_name.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
package gke
import (
"fmt"
)
// Location returns the region or zone depending on which is not set to empty.
// Cluster creation validation should ensure that only one of region or zone is set, not both.
func Location(region, zone string) string {
ret := region
if zone != "" {
ret = zone
}
return ret
}
// LocationRRN returns a Relative Resource Name representing a location. This
// RRN can either represent a Region or a Zone. It can be used as the parent
// attribute during cluster creation to create a zonal or regional cluster, or
// be used to generate more specific RRNs like an RRN representing a cluster.
//
// https://cloud.google.com/apis/design/resource_names#relative_resource_name
func LocationRRN(projectID, location string) string {
return fmt.Sprintf("projects/%s/locations/%s", projectID, location)
}
// ClusterRRN returns an Relative Resource Name of a cluster in the specified
// region or zone
func ClusterRRN(projectID, location, clusterName string) string {
return fmt.Sprintf("%s/clusters/%s", LocationRRN(projectID, location), clusterName)
}
// NodePoolRRN returns a Relative Resource Name of a node pool in a cluster in the
// region or zone for the specified project
func NodePoolRRN(projectID, location, clusterName, nodePool string) string {
return fmt.Sprintf("%s/nodePools/%s", ClusterRRN(projectID, location, clusterName), nodePool)
}
// BootDiskRRN returns a Relative Resource Name of a disk key in the region or zone for the
// specified project
func BootDiskRRN(projectID, location, ringName, keyName string) string {
return fmt.Sprintf("projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s", projectID, location, ringName, keyName)
}