set ref to owner when using kube secrets
@@ -224,13 +224,22 @@ func (r *AzureSqlServerReconciler) reconcileExternal(instance *azurev1alpha1.Azu
r.Recorder.Event(instance, v1.EventTypeNormal, "Provisioned", msg)
}
- // @todo: figure out owner ref for kube secret
+ // create or update the secret
key := types.NamespacedName{Name: instance.Name, Namespace: instance.Namespace}
err = r.SecretClient.Upsert(ctx, key, secret)
if err != nil {
return err
}
+ // attempt to set owner, gracefully fail
+ kSecret := &v1.Secret{}
+ if err := r.Get(ctx, key, kSecret); err == nil {
+ if err := controllerutil.SetControllerReference(instance, kSecret, r.Scheme); err != nil {
+ return err
+ }
+ return r.Update(ctx, kSecret)
+ }
+
// write information back to instance
if updateerr := r.Status().Update(ctx, instance); updateerr != nil {
r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance")
