// writeToSecret will patch an existing secret to add an exported field value.
// By default the key will be "<namespace>.<name>" using values from the
// exporter that created it.
writeToSecret will patch an existing secret to add an exported field value.
By default the key will be "." using values from the
exporter that created it.
// writeToSecret will patch an existing secret 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) writeToSecret(
	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
	}
	secret := &corev1.Secret{}
	err := r.apiReader.Get(ctx, nsn, secret)
	if err != nil {
		return errors.Wrap(err, ackerr.FieldExportMissingSecret.Error())
	}
	patch := client.StrategicMergeFrom(secret.DeepCopy())
	if secret.Data == nil {
		secret.Data = make(map[string][]byte, 1)
	}
	secret.Data[key] = []byte(sourceValue)
	ackrtlog.DebugFieldExport(r.log, desired, "patching target secret")
	err = r.kc.Patch(ctx, secret, patch)
	if err != nil {
		return err
	}
	ackrtlog.InfoFieldExport(r.log, desired, "patched target secret")
	return nil
}
func ( r * fieldExportReconciler ) writeToSecret ( 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 } secret := & corev1 . Secret { } err := r . apiReader . Get ( ctx , nsn , secret ) if err != nil { return errors . Wrap ( err , ackerr . FieldExportMissingSecret . Error ( ) ) } patch := client . StrategicMergeFrom ( secret . DeepCopy ( ) ) if secret . Data == nil { secret . Data = make ( map [ string ] [ ] byte , 1 ) } secret . Data [ key ] = [ ] byte ( sourceValue ) ackrtlog . DebugFieldExport ( r . log , desired , " " ) err = r . kc . Patch ( ctx , secret , patch ) if err != nil { return err } ackrtlog . InfoFieldExport ( r . log , desired , " " ) return nil }
writeToSecret will patch an existing secret to add an exported field value.
writeToSecret will patch an existing secret to add an exported field value .
// Construct the data key // Get the initial secret // Update the field