/
managedcluster.go
58 lines (47 loc) · 1.26 KB
/
managedcluster.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
// Copyright Contributors to the Open Cluster Management project
package managedcluster
import (
"fmt"
"strconv"
"github.com/stolostron/cm-cli/pkg/helpers"
clusterv1 "open-cluster-management.io/api/cluster/v1"
)
const (
ConsoleURLClusterClaim string = "consoleurl.cluster.open-cluster-management.io"
HostedClusterClusterClaim string = "hostedcluster.hypershift.openshift.io"
HostedType string = "hosted"
ClusterClaimType string = "clusterclaim"
)
func GetConsoleURL(mc *clusterv1.ManagedCluster) (string, error) {
for _, c := range mc.Status.ClusterClaims {
if c.Name == ConsoleURLClusterClaim {
return c.Value, nil
}
}
return "", fmt.Errorf("console url not found for cluster %s", mc.Name)
}
func IsHosted(mc *clusterv1.ManagedCluster) bool {
for _, c := range mc.Status.ClusterClaims {
if c.Name == HostedClusterClusterClaim {
b, err := strconv.ParseBool(c.Value)
if err != nil {
return false
}
return b
}
}
return false
}
func GetClusterType(mc *clusterv1.ManagedCluster) string {
if IsHosted(mc) {
return HostedType
}
return ClusterClaimType
}
func OpenManagedCluster(mc *clusterv1.ManagedCluster) error {
consoleURL, err := GetConsoleURL(mc)
if err != nil {
return err
}
return helpers.Openbrowser(consoleURL)
}