in controllers/etcdadmconfig_controller.go [387:428]
func (r *EtcdadmConfigReconciler) storeBootstrapData(ctx context.Context, config *etcdbootstrapv1.EtcdadmConfig, data []byte, clusterName string) error {
log := r.Log
se := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: config.Name,
Namespace: config.Namespace,
Labels: map[string]string{
clusterv1.ClusterNameLabel: clusterName,
},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: etcdbootstrapv1.GroupVersion.String(),
Kind: config.Kind,
Name: config.Name,
UID: config.UID,
Controller: ptr.To(true),
},
},
},
Data: map[string][]byte{
"value": data,
},
Type: clusterv1.ClusterSecretType,
}
// as secret creation and scope.Config status patch are not atomic operations
// it is possible that secret creation happens but the config.Status patches are not applied
if err := r.Client.Create(ctx, se); err != nil {
if !apierrors.IsAlreadyExists(err) {
return errors.Wrapf(err, "failed to create bootstrap data secret for EtcdadmConfig %s/%s", config.Namespace, config.Name)
}
log.Info("bootstrap data secret for EtcdadmConfig already exists, updating", "secret", se.Name, "EtcdadmConfig", config.Name)
if err := r.Client.Update(ctx, se); err != nil {
return errors.Wrapf(err, "failed to update bootstrap data secret for EtcdadmConfig %s/%s", config.Namespace, config.Name)
}
}
config.Status.DataSecretName = ptr.To(se.Name)
config.Status.Ready = true
conditions.MarkTrue(config, bootstrapv1.DataSecretAvailableCondition)
return nil
}