kubelet_pods.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. Copyright 2019 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package kubelet
  14. import (
  15. v1 "k8s.io/api/core/v1"
  16. clientset "k8s.io/client-go/kubernetes"
  17. "k8s.io/kubernetes/pkg/master/ports"
  18. )
  19. // GetKubeletPods retrieves the list of pods on the kubelet.
  20. func GetKubeletPods(c clientset.Interface, node string) (*v1.PodList, error) {
  21. return getKubeletPods(c, node, "pods")
  22. }
  23. // GetKubeletRunningPods retrieves the list of running pods on the kubelet. The pods
  24. // includes necessary information (e.g., UID, name, namespace for
  25. // pods/containers), but do not contain the full spec.
  26. func GetKubeletRunningPods(c clientset.Interface, node string) (*v1.PodList, error) {
  27. return getKubeletPods(c, node, "runningpods")
  28. }
  29. func getKubeletPods(c clientset.Interface, node, resource string) (*v1.PodList, error) {
  30. result := &v1.PodList{}
  31. client, err := ProxyRequest(c, node, resource, ports.KubeletPort)
  32. if err != nil {
  33. return &v1.PodList{}, err
  34. }
  35. if err = client.Into(result); err != nil {
  36. return &v1.PodList{}, err
  37. }
  38. return result, nil
  39. }