servicecommon.go 1.8 KB
Newer Older
S
Sebastian Florek 已提交
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
// 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 (
	"k8s.io/kubernetes/pkg/api"

	"github.com/kubernetes/dashboard/resource/common"
)

// ToService returns api service object based on kubernetes service object
func ToService(service *api.Service) Service {
	return Service{
B
bryk 已提交
26 27
		ObjectMeta:       common.NewObjectMeta(service.ObjectMeta),
		TypeMeta:         common.NewTypeMeta(common.ResourceKindService),
S
Sebastian Florek 已提交
28 29 30 31
		InternalEndpoint: common.GetInternalEndpoint(service.Name, service.Namespace, service.Spec.Ports),
		// TODO(maciaszczykm): Fill ExternalEndpoints with data.
		Selector:  service.Spec.Selector,
		ClusterIP: service.Spec.ClusterIP,
32
		Type:      service.Spec.Type,
S
Sebastian Florek 已提交
33 34 35 36 37 38
	}
}

// ToServiceDetails returns api service object based on kubernetes service object
func ToServiceDetail(service *api.Service) ServiceDetail {
	return ServiceDetail{
B
bryk 已提交
39 40
		ObjectMeta:       common.NewObjectMeta(service.ObjectMeta),
		TypeMeta:         common.NewTypeMeta(common.ResourceKindService),
S
Sebastian Florek 已提交
41 42 43 44 45 46 47
		InternalEndpoint: common.GetInternalEndpoint(service.Name, service.Namespace, service.Spec.Ports),
		// TODO(maciaszczykm): Fill ExternalEndpoints with data.
		Selector:  service.Spec.Selector,
		ClusterIP: service.Spec.ClusterIP,
		Type:      service.Spec.Type,
	}
}