-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservicelist.go
80 lines (63 loc) · 2.9 KB
/
servicelist.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package service
import (
"log"
"k8s.io/kubernetes/pkg/api"
client "k8s.io/kubernetes/pkg/client/unversioned"
"github.com/kubernetes/dashboard/src/app/backend/resource/common"
"github.com/kubernetes/dashboard/src/app/backend/resource/dataselect"
)
// Service is a representation of a service.
type Service struct {
ObjectMeta common.ObjectMeta `json:"objectMeta"`
TypeMeta common.TypeMeta `json:"typeMeta"`
// InternalEndpoint of all Kubernetes services that have the same label selector as connected Replication
// Controller. Endpoint is DNS name merged with ports.
InternalEndpoint common.Endpoint `json:"internalEndpoint"`
// ExternalEndpoints of all Kubernetes services that have the same label selector as connected Replication
// Controller. Endpoint is external IP address name merged with ports.
ExternalEndpoints []common.Endpoint `json:"externalEndpoints"`
// Label selector of the service.
Selector map[string]string `json:"selector"`
// Type determines how the service will be exposed. Valid options: ClusterIP, NodePort, LoadBalancer
Type api.ServiceType `json:"type"`
// ClusterIP is usually assigned by the master. Valid values are None, empty string (""), or
// a valid IP address. None can be specified for headless services when proxying is not required
ClusterIP string `json:"clusterIP"`
}
// ServiceList contains a list of services in the cluster.
type ServiceList struct {
ListMeta common.ListMeta `json:"listMeta"`
// Unordered list of services.
Services []Service `json:"services"`
}
// GetServiceList returns a list of all services in the cluster.
func GetServiceList(client client.Interface, nsQuery *common.NamespaceQuery,
dsQuery *dataselect.DataSelectQuery) (*ServiceList, error) {
log.Printf("Getting list of all services in the cluster")
channels := &common.ResourceChannels{
ServiceList: common.GetServiceListChannel(client, nsQuery, 1),
}
return GetServiceListFromChannels(channels, dsQuery)
}
// GetServiceListFromChannels returns a list of all services in the cluster.
func GetServiceListFromChannels(channels *common.ResourceChannels,
dsQuery *dataselect.DataSelectQuery) (*ServiceList, error) {
services := <-channels.ServiceList.List
if err := <-channels.ServiceList.Error; err != nil {
return nil, err
}
return CreateServiceList(services.Items, dsQuery), nil
}