func listConfigmapsByName()

in contrib/cmd/runkperf/commands/data/configmaps/configmap.go [366:415]


func listConfigmapsByName(clientset *kubernetes.Clientset, labelSelector string, namespace string, cmMap map[string][]int) error {
	configMaps, err := listConfigmaps(clientset, labelSelector, namespace)

	if err != nil {
		return err
	}

	for _, cm := range configMaps.Items {
		name, ok := cm.Labels["cmName"]
		if !ok {
			return fmt.Errorf("failed to find the cmName of configmap %s", cm.Name)
		}

		_, ok = cmMap[name]
		if !ok {
			// Initialize the map with default values
			// size, group-size, total in int list
			cmMap[name] = []int{0, 0, 0}

			// Get the size of the configmap
			_, ok = cm.Data["data"]
			if ok {
				cmMap[name][0] = len(cm.Data["data"])
			}
		}

		// Increment the total count of configmaps
		cmMap[name][2]++

		if cmMap[name][1] != 0 {
			continue
		}

		ownerID, ok := cm.Labels["ownerID"]
		if !ok {
			return fmt.Errorf("failed to find the ownerID of configmap %s", name)
		}

		if ownerIDInt, err := strconv.Atoi(ownerID); err == nil {
			// Use the ownerID to get the group size
			if ownerIDInt > cmMap[name][1] {
				cmMap[name][1] = ownerIDInt
			}
		} else {
			return fmt.Errorf("failed to convert ownerID %s to int: %v", ownerID, err)
		}

	}
	return nil
}