func()

in runner/group/handler.go [125:160]


func (h *Handler) uploadLoadProfileAsConfigMap(ctx context.Context) error {
	cli := h.clientset.CoreV1().ConfigMaps(h.namespace)

	cm, err := cli.Get(ctx, h.name, metav1.GetOptions{})
	if err == nil {
		// FIXME: should we check the content?
		if _, ok := cm.Data[configMapDataKeyLoadProfile]; !ok {
			return fmt.Errorf("configmap %s doesn't have load profile", h.name)
		}
		return nil
	}
	if !apierrors.IsNotFound(err) {
		return err
	}

	raw, err := yaml.Marshal(h.spec.Profile)
	if err != nil {
		return fmt.Errorf("failed to marshal load profile into yaml: %w", err)
	}

	cm = &corev1.ConfigMap{
		ObjectMeta: metav1.ObjectMeta{
			Name:      h.name,
			Namespace: h.namespace,
		},
		Immutable: toPtr(true),
		Data: map[string]string{
			configMapDataKeyLoadProfile: string(raw),
		},
	}
	if h.ownerRef != nil {
		cm.OwnerReferences = append(cm.OwnerReferences, *h.ownerRef)
	}
	_, err = cli.Create(ctx, cm, metav1.CreateOptions{})
	return err
}