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

import (
18
	"github.com/kubernetes/dashboard/src/app/backend/errors"
19
	metricapi "github.com/kubernetes/dashboard/src/app/backend/integration/metric/api"
20 21
	"github.com/kubernetes/dashboard/src/app/backend/resource/common"
	"github.com/kubernetes/dashboard/src/app/backend/resource/dataselect"
22
	"github.com/kubernetes/dashboard/src/app/backend/resource/event"
M
Marcin Maciaszczyk 已提交
23
	"github.com/kubernetes/dashboard/src/app/backend/resource/pod"
S
Sebastian Florek 已提交
24
	metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
M
Marcin Maciaszczyk 已提交
25
	client "k8s.io/client-go/kubernetes"
26 27
)

28
// GetDeploymentPods returns list of pods targeting deployment.
29
func GetDeploymentPods(client client.Interface, metricClient metricapi.MetricClient,
30
	dsQuery *dataselect.DataSelectQuery, namespace, deploymentName string) (*pod.PodList, error) {
31

32
	deployment, err := client.AppsV1().Deployments(namespace).Get(deploymentName, metaV1.GetOptions{})
33
	if err != nil {
34
		return pod.EmptyPodList, err
35 36 37
	}

	channels := &common.ResourceChannels{
38
		PodList:        common.GetPodListChannel(client, common.NewSameNamespaceQuery(namespace), 1),
39
		ReplicaSetList: common.GetReplicaSetListChannel(client, common.NewSameNamespaceQuery(namespace), 1),
40 41 42 43
	}

	rawPods := <-channels.PodList.List
	if err := <-channels.PodList.Error; err != nil {
44
		return pod.EmptyPodList, err
45 46
	}

47
	rawRs := <-channels.ReplicaSetList.List
48 49 50 51
	err = <-channels.ReplicaSetList.Error
	nonCriticalErrors, criticalError := errors.HandleError(err)
	if criticalError != nil {
		return pod.EmptyPodList, criticalError
52 53 54
	}

	pods := common.FilterDeploymentPodsByOwnerReference(*deployment, rawRs.Items, rawPods.Items)
55
	events, err := event.GetPodsEvents(client, namespace, pods)
56 57 58
	nonCriticalErrors, criticalError = errors.AppendError(err, nonCriticalErrors)
	if criticalError != nil {
		return pod.EmptyPodList, criticalError
59
	}
60

61
	podList := pod.ToPodList(pods, events, nonCriticalErrors, dsQuery, metricClient)
62 63
	return &podList, nil
}