detail.go 2.3 KB
Newer Older
1
// Copyright 2017 The Kubernetes Authors.
2 3 4 5 6 7 8 9 10 11 12 13 14
//
// 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.

M
Marcin Maciaszczyk 已提交
15
package daemonset
16 17 18 19

import (
	"log"

20
	metricapi "github.com/kubernetes/dashboard/src/app/backend/integration/metric/api"
21
	"github.com/kubernetes/dashboard/src/app/backend/resource/common"
S
Sebastian Florek 已提交
22
	metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23
	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
S
Sebastian Florek 已提交
24
	k8sClient "k8s.io/client-go/kubernetes"
25 26 27 28
)

// DaemonSeDetail represents detailed information about a Daemon Set.
type DaemonSetDetail struct {
29 30
	// Extends list item structure.
	DaemonSet `json:",inline"`
31

S
Sebastian Florek 已提交
32
	LabelSelector *v1.LabelSelector `json:"labelSelector,omitempty"`
33

34 35
	// List of non-critical errors, that occurred during resource retrieval.
	Errors []error `json:"errors"`
36 37 38
}

// Returns detailed information about the given daemon set in the given namespace.
39
func GetDaemonSetDetail(client k8sClient.Interface, metricClient metricapi.MetricClient,
B
Batikan Urcan 已提交
40
	namespace, name string) (*DaemonSetDetail, error) {
41

M
Marcin Maciaszczyk 已提交
42
	log.Printf("Getting details of %s daemon set in %s namespace", name, namespace)
43
	daemonSet, err := client.AppsV1().DaemonSets(namespace).Get(name, metaV1.GetOptions{})
44 45 46 47
	if err != nil {
		return nil, err
	}

48 49 50
	channels := &common.ResourceChannels{
		EventList: common.GetEventListChannel(client, common.NewSameNamespaceQuery(namespace), 1),
		PodList:   common.GetPodListChannel(client, common.NewSameNamespaceQuery(namespace), 1),
51 52
	}

53 54 55
	eventList := <-channels.EventList.List
	if err := <-channels.EventList.Error; err != nil {
		return nil, err
56 57
	}

58 59 60
	podList := <-channels.PodList.List
	if err := <-channels.PodList.Error; err != nil {
		return nil, err
61 62
	}

63 64
	return &DaemonSetDetail{
		DaemonSet:     toDaemonSet(*daemonSet, podList.Items, eventList.Items),
65
		LabelSelector: daemonSet.Spec.Selector,
66 67
		Errors:        []error{},
	}, nil
68
}