func (f *PodsFetcher) FetchFuncWithCache() data.FetchFunc {
	return func() (definition.RawGroups, error) {
		f.once.Do(func() {
			f.cachedPods, f.fetchError = f.doPodsFetch()
		})
		return f.cachedPods, f.fetchError
	}
}
FetchFuncWithCache creates a data.FetchFunc that fetches data from the
kubelet pods path. The results are cached in memory, this means that
the cache is maintain per integration execution.
package metric
import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"strings"
	"sync"
	"time"
	"github.com/newrelic/infra-integrations-sdk/log"
	v1 "k8s.io/api/core/v1"
	"github.com/newrelic/nri-kubernetes/v2/src/client"
	"github.com/newrelic/nri-kubernetes/v2/src/data"
	"github.com/newrelic/nri-kubernetes/v2/src/definition"
)
const KubeletPodsPath = "/pods"
type PodsFetcher struct {
	once       sync.Once
	cachedPods definition.RawGroups
	fetchError error
	logger     log.Logger
	client     client.HTTPGetter
}
func (f *PodsFetcher) doPodsFetch() (definition.RawGroups, error) {
	r, err := f.client.Get(KubeletPodsPath)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = r.Body.Close()
	}()
	if r.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("error calling kubelet %s path. Status code %d", KubeletPodsPath, r.StatusCode)
	}
	rawPods, err := ioutil.ReadAll(r.Body)
	if err != nil {
		return nil, fmt.Errorf("error reading response from kubelet %s path. %s", KubeletPodsPath, err)
	}
	if len(rawPods) == 0 {
		return nil, fmt.Errorf("error reading response from kubelet %s path. Response is empty", KubeletPodsPath)
	}
	var pods v1.PodList
	err = json.Unmarshal(rawPods, &pods)
	if err != nil {
		return nil, fmt.Errorf("error decoding response from kubelet %s path. %s", KubeletPodsPath, err)
	}
	raw := definition.RawGroups{
		"pod":       make(map[string]definition.RawMetrics),
		"container": make(map[string]definition.RawMetrics),
	}
	var missingNodeIPContainerIDs []string
	var missingNodeIPPodIDs []string
	var nodeIP string
	for _, p := range pods.Items {
		id := podID(&p)
		raw["pod"][id] = f.fetchPodData(&p)
		if _, ok := raw["pod"][id]["nodeIP"]; ok && nodeIP == "" {
			nodeIP = raw["pod"][id]["nodeIP"].(string)
		}
		if nodeIP == "" {
			missingNodeIPPodIDs = append(missingNodeIPPodIDs, id)
		} else {
			raw["pod"][id]["nodeIP"] = nodeIP
		}
		containers := f.fetchContainersData(&p)
		for id, c := range containers {
			raw["container"][id] = c
			if _, ok := c["nodeIP"]; ok && nodeIP == "" {
				nodeIP = c["nodeIP"].(string)
			}
			if nodeIP == "" {
				missingNodeIPContainerIDs = append(missingNodeIPContainerIDs, id)
			} else {
				raw["container"][id]["nodeIP"] = nodeIP
			}
		}
	}
	for _, id := range missingNodeIPPodIDs {
		raw["pod"][id]["nodeIP"] = nodeIP
	}
	for _, id := range missingNodeIPContainerIDs {
		raw["container"][id]["nodeIP"] = nodeIP
	}
	return raw, nil
}