forked from vmware-archive/octant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath.go
61 lines (53 loc) · 2.55 KB
/
path.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
59
60
61
/*
Copyright (c) 2019 the Octant contributors. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package printer
import (
"path"
corev1 "k8s.io/api/core/v1"
)
type objectReferenceKey struct {
apiVersion string
kind string
}
var (
objectReferenceLookup = map[objectReferenceKey]string{
objectReferenceKey{apiVersion: "batch/v1beta1", kind: "CronJob"}: "workloads/cron-jobs",
objectReferenceKey{apiVersion: "apps/v1", kind: "DaemonSet"}: "workloads/daemon-sets",
objectReferenceKey{apiVersion: "apps/v1", kind: "Deployment"}: "workloads/deployments",
objectReferenceKey{apiVersion: "batch/v1", kind: "Job"}: "workloads/jobs",
objectReferenceKey{apiVersion: "v1", kind: "Pod"}: "workloads/pods",
objectReferenceKey{apiVersion: "apps/v1", kind: "ReplicaSet"}: "workloads/replica-sets",
objectReferenceKey{apiVersion: "v1", kind: "ReplicationController"}: "workloads/replication-controllers",
objectReferenceKey{apiVersion: "apps/v1", kind: "StatefulSet"}: "workloads/stateful-sets",
objectReferenceKey{apiVersion: "extensions/v1beta1", kind: "Ingress"}: "discovery-and-load-balancing/ingresses",
objectReferenceKey{apiVersion: "v1", kind: "Service"}: "discovery-and-load-balancing/services",
objectReferenceKey{apiVersion: "v1", kind: "ConfigMap"}: "config-and-storage/config-maps",
objectReferenceKey{apiVersion: "v1", kind: "PersistentVolumeClaim"}: "config-and-storage/persistent-volume-claims",
objectReferenceKey{apiVersion: "v1", kind: "Secret"}: "config-and-storage/secrets",
objectReferenceKey{apiVersion: "v1", kind: "ServiceAccount"}: "config-and-storage/service-accounts",
objectReferenceKey{apiVersion: "v1", kind: "Role"}: "rbac/roles",
objectReferenceKey{apiVersion: "v1", kind: "RoleBinding"}: "rbac/role-bindings",
objectReferenceKey{apiVersion: "v1", kind: "Event"}: "events",
}
)
// ObjectReferencePath returns the overview path for an object reference.
// Currently, this does not support custom resources.
func ObjectReferencePath(or corev1.ObjectReference) (string, error) {
key := objectReferenceKey{
apiVersion: or.APIVersion,
kind: or.Kind,
}
section, ok := objectReferenceLookup[key]
if !ok {
return "", nil
}
var objectPath string
if or.Namespace != "" {
objectPath = path.Join("/overview/namespace", or.Namespace, section, or.Name)
} else {
objectPath = path.Join("/overview", section, or.Name)
}
return objectPath, nil
}