Skip to content

Commit

Permalink
Add methods to get pods and containers list (kanisterio#418)
Browse files Browse the repository at this point in the history
Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>
  • Loading branch information
PrasadG193 authored and tdmanv committed Nov 19, 2019
1 parent 75f3adb commit 88b2014
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pkg/kube/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ func StatefulSetReady(ctx context.Context, kubeCli kubernetes.Interface, namespa
return len(runningPods) == int(*ss.Spec.Replicas), nil
}

// StatefulSetPods returns list of running and notrunning pods created by the deployment.
func StatefulSetPods(ctx context.Context, kubeCli kubernetes.Interface, namespace string, name string) ([]v1.Pod, []v1.Pod, error) {
ss, err := kubeCli.AppsV1().StatefulSets(namespace).Get(name, metav1.GetOptions{})
if err != nil {
return nil, nil, errors.Wrapf(err, "could not get StatefulSet{Namespace: %s, Name: %s}", namespace, name)
}
return FetchPods(kubeCli, namespace, ss.GetUID())
}

// WaitOnStatefulSetReady waits for the stateful set to be ready
func WaitOnStatefulSetReady(ctx context.Context, kubeCli kubernetes.Interface, namespace string, name string) error {
return poll.Wait(ctx, func(ctx context.Context) (bool, error) {
Expand Down Expand Up @@ -129,6 +138,19 @@ func DeploymentReady(ctx context.Context, kubeCli kubernetes.Interface, namespac
return len(notRunningPods) == 0, nil
}

// DeploymentPods returns list of running and notrunning pods created by the deployment.
func DeploymentPods(ctx context.Context, kubeCli kubernetes.Interface, namespace string, name string) ([]v1.Pod, []v1.Pod, error) {
d, err := kubeCli.AppsV1().Deployments(namespace).Get(name, metav1.GetOptions{})
if err != nil {
return nil, nil, errors.Wrapf(err, "could not get Deployment{Namespace: %s, Name: %s}", namespace, name)
}
rs, err := FetchReplicaSet(kubeCli, namespace, d.GetUID(), d.Annotations[RevisionAnnotation])
if err != nil {
return nil, nil, err
}
return FetchPods(kubeCli, namespace, rs.GetUID())
}

// WaitOnDeploymentReady waits for the deployment to be ready
func WaitOnDeploymentReady(ctx context.Context, kubeCli kubernetes.Interface, namespace string, name string) error {
return poll.Wait(ctx, func(ctx context.Context) (bool, error) {
Expand Down Expand Up @@ -228,6 +250,15 @@ func DeploymentVolumes(cli kubernetes.Interface, d *appsv1.Deployment) (volNameT
return volNameToPvc
}

// PodContainers returns list of containers specified by the pod
func PodContainers(ctx context.Context, kubeCli kubernetes.Interface, namespace string, name string) ([]v1.Container, error) {
p, err := kubeCli.CoreV1().Pods(namespace).Get(name, metav1.GetOptions{})
if err != nil {
return nil, errors.Wrapf(err, "could not get Pod{Namespace: %s, Name: %s}", namespace, name)
}
return p.Spec.Containers, nil
}

// From getPersistentVolumeClaimName() in stateful_set_utils.go in the K8s repository
// Format is "<claim name>-<stateful set name>-<ordinal>"
const (
Expand Down

0 comments on commit 88b2014

Please sign in to comment.