// writeToConfigMap will patch an existing config map to add an exported field
// value. By default the key will be "<namespace>.<name>" using values from the
// exporter that created it.
writeToConfigMap will patch an existing config map to add an exported field
value. By default the key will be "." using values from the
exporter that created it.
// writeToConfigMap will patch an existing config map to add an exported field // value . By default the key will be " <namespace > . <name > " using values from the // exporter that created it .
func (r *fieldExportReconciler) writeToConfigMap(
	ctx context.Context,
	sourceValue string,
	desired *ackv1alpha1.FieldExport,
) error {
	key := fmt.Sprintf("%s.%s", desired.Namespace, desired.Name)
	nsn := types.NamespacedName{
		Name: *desired.Spec.To.Name,
	}
	if desired.Spec.To.Namespace != nil {
		nsn.Namespace = *desired.Spec.To.Namespace
	} else {
		nsn.Namespace = desired.Namespace
	}
	cm := &corev1.ConfigMap{}
	err := r.apiReader.Get(ctx, nsn, cm)
	if err != nil {
		return errors.Wrap(err, ackerr.FieldExportMissingConfigMap.Error())
	}
	patch := client.StrategicMergeFrom(cm.DeepCopy())
	if cm.Data == nil {
		cm.Data = make(map[string]string, 1)
	}
	cm.Data[key] = sourceValue
	ackrtlog.DebugFieldExport(r.log, desired, "patching target config map")
	err = r.kc.Patch(ctx, cm, patch)
	if err != nil {
		return err
	}
	ackrtlog.InfoFieldExport(r.log, desired, "patched target config map")
	return nil
}
func ( r * fieldExportReconciler ) writeToConfigMap ( ctx context . Context , sourceValue string , desired * ackv1alpha1 . FieldExport , ) error { key := fmt . Sprintf ( " " , desired . Namespace , desired . Name ) nsn := types . NamespacedName { Name : * desired . Spec . To . Name , } if desired . Spec . To . Namespace != nil { nsn . Namespace = * desired . Spec . To . Namespace } else { nsn . Namespace = desired . Namespace } cm := & corev1 . ConfigMap { } err := r . apiReader . Get ( ctx , nsn , cm ) if err != nil { return errors . Wrap ( err , ackerr . FieldExportMissingConfigMap . Error ( ) ) } patch := client . StrategicMergeFrom ( cm . DeepCopy ( ) ) if cm . Data == nil { cm . Data = make ( map [ string ] string , 1 ) } cm . Data [ key ] = sourceValue ackrtlog . DebugFieldExport ( r . log , desired , " " ) err = r . kc . Patch ( ctx , cm , patch ) if err != nil { return err } ackrtlog . InfoFieldExport ( r . log , desired , " " ) return nil }
writeToConfigMap will patch an existing config map to add an exported field
value.
writeToConfigMap will patch an existing config map to add an exported field value .
// Construct the data key // Get the initial configmap // Update the field