func()

in pkg/appmgmt/general/general.go [213:248]


func (os *Manager) ListPods() ([]*v1.Pod, error) {
	log.Log(log.ShimAppMgmtGeneral).Info("Retrieving pod list")
	// list all pods on this cluster
	appPods, err := os.apiProvider.GetAPIs().PodInformer.Lister().List(labels.NewSelector())
	if err != nil {
		return nil, err
	}
	log.Log(log.ShimAppMgmtGeneral).Info("Pod list retrieved from api server", zap.Int("nr of pods", len(appPods)))
	// get existing apps
	existingApps := make(map[string]struct{})
	podsRecovered := 0
	podsWithoutMetaData := 0
	pods := make([]*v1.Pod, 0)
	for _, pod := range appPods {
		log.Log(log.ShimAppMgmtGeneral).Debug("Looking at pod for recovery candidates", zap.String("podNamespace", pod.Namespace), zap.String("podName", pod.Name))
		// general filter passes, and pod is assigned
		// this means the pod is already scheduled by scheduler for an existing app
		if utils.GetApplicationIDFromPod(pod) != "" && utils.IsAssignedPod(pod) {
			if meta, ok := getAppMetadata(pod, true); ok {
				podsRecovered++
				pods = append(pods, pod)
				log.Log(log.ShimAppMgmtGeneral).Debug("Adding appID as recovery candidate", zap.String("appID", meta.ApplicationID))
				existingApps[meta.ApplicationID] = struct{}{}
			} else {
				podsWithoutMetaData++
			}
		}
	}
	log.Log(log.ShimAppMgmtGeneral).Info("Application recovery statistics",
		zap.Int("nr of recoverable apps", len(existingApps)),
		zap.Int("nr of total pods", len(appPods)),
		zap.Int("nr of pods without application metadata", podsWithoutMetaData),
		zap.Int("nr of pods to be recovered", podsRecovered))

	return pods, nil
}