@@ -21,28 +21,7 @@ import (
21
21
"k8s.io/kubernetes/pkg/api/unversioned"
22
22
)
23
23
24
- type ResourceType string
25
-
26
- const (
27
- ResourceTypeReplicaSet = "replicaset"
28
- ResourceTypeReplicationController = "replicationcontroller"
29
- )
30
-
31
- func CreateObjectMeta (k8SObjectMeta api.ObjectMeta ) ObjectMeta {
32
- return ObjectMeta {
33
- Name : k8SObjectMeta .Name ,
34
- Namespace : k8SObjectMeta .Namespace ,
35
- Labels : k8SObjectMeta .Labels ,
36
- CreationTimestamp : k8SObjectMeta .CreationTimestamp ,
37
- }
38
- }
39
-
40
- func CreateTypeMeta (k8STypeMeta unversioned.TypeMeta ) TypeMeta {
41
- return TypeMeta {
42
- Kind : k8STypeMeta .Kind ,
43
- }
44
- }
45
-
24
+ // ObjectMeta is metadata about an instance of a resource.
46
25
type ObjectMeta struct {
47
26
// Name is unique within a namespace. Name is primarily intended for creation
48
27
// idempotence and configuration definition.
@@ -83,7 +62,7 @@ type TypeMeta struct {
83
62
// Servers may infer this from the endpoint the client submits requests to.
84
63
// In smalllettercase.
85
64
// More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds
86
- Kind string `json:"kind,omitempty"`
65
+ Kind ResourceKind `json:"kind,omitempty"`
87
66
}
88
67
89
68
// Endpoint describes an endpoint that is host and a list of available ports for that host.
@@ -148,6 +127,49 @@ type Event struct {
148
127
}
149
128
150
129
// Returns internal endpoint name for the given service properties, e.g.,
130
+ // NewObjectMeta creates a new instance of ObjectMeta struct based on K8s object meta.
131
+ func NewObjectMeta (k8SObjectMeta api.ObjectMeta ) ObjectMeta {
132
+ return ObjectMeta {
133
+ Name : k8SObjectMeta .Name ,
134
+ Namespace : k8SObjectMeta .Namespace ,
135
+ Labels : k8SObjectMeta .Labels ,
136
+ CreationTimestamp : k8SObjectMeta .CreationTimestamp ,
137
+ }
138
+ }
139
+
140
+ // NewTypeMeta creates new type mete for the resource kind.
141
+ func NewTypeMeta (kind ResourceKind ) TypeMeta {
142
+ return TypeMeta {
143
+ Kind : kind ,
144
+ }
145
+ }
146
+
147
+ // ResourceKind is an unique name for each resource. It can used for API discovery and generic
148
+ // code that does things based on the kind. For example, there may be a generic "deleter"
149
+ // that based on resource kind, name and namespace deletes it.
150
+ type ResourceKind string
151
+
152
+ // List of all resource kinds supported by the UI.
153
+ const (
154
+ ResourceKindReplicaSet = "replicaset"
155
+ ResourceKindService = "service"
156
+ ResourceKindDeployment = "deployment"
157
+ ResourceKindPod = "pod"
158
+ ResourceKindReplicationController = "replicationcontroller"
159
+ )
160
+
161
+ // Mapping from resource kind to K8s apiserver API path. This is mostly pluralization, because
162
+ // K8s apiserver uses plural paths and this project singular.
163
+ // Must be kept in sync with the list of supported kinds.
164
+ var kindToAPIPathMapping = map [string ]string {
165
+ ResourceKindService : "services" ,
166
+ ResourceKindPod : "pods" ,
167
+ ResourceKindReplicationController : "replicationcontrollers" ,
168
+ ResourceKindDeployment : "deployments" ,
169
+ ResourceKindReplicaSet : "replicasets" ,
170
+ }
171
+
172
+ // GetInternalEndpoint returns internal endpoint name for the given service properties, e.g.,
151
173
// "my-service.namespace 80/TCP" or "my-service 53/TCP,53/UDP".
152
174
func GetInternalEndpoint (serviceName , namespace string , ports []api.ServicePort ) Endpoint {
153
175
@@ -165,7 +187,7 @@ func GetInternalEndpoint(serviceName, namespace string, ports []api.ServicePort)
165
187
}
166
188
}
167
189
168
- // Gets human readable name for the given service ports list.
190
+ // GetServicePorts returns human readable name for the given service ports list.
169
191
func GetServicePorts (apiPorts []api.ServicePort ) []ServicePort {
170
192
var ports []ServicePort
171
193
for _ , port := range apiPorts {
0 commit comments