-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-38 validatie record on deletion #72
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,9 +81,16 @@ func (r *DNSRecordReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( | |
dnsRecord := previous.DeepCopy() | ||
|
||
if dnsRecord.DeletionTimestamp != nil && !dnsRecord.DeletionTimestamp.IsZero() { | ||
if err = r.deleteRecord(ctx, dnsRecord); err != nil { | ||
requeueTime, err := r.deleteRecord(ctx, dnsRecord) | ||
if err != nil { | ||
logger.Error(err, "Failed to delete DNSRecord") | ||
return ctrl.Result{}, err | ||
return ctrl.Result{RequeueAfter: requeueTime}, err | ||
} | ||
// if requeueTime returned is the same as validationRequeueTime - the deleteRecord has successfully applied changes | ||
// in this case we need to queue for validation to ensure DNS Provider retained changes | ||
// before removing finalizer and deleting the DNS Record CR | ||
if requeueTime == validationRequeueTime { | ||
return ctrl.Result{RequeueAfter: requeueTime}, nil | ||
} | ||
logger.Info("Removing Finalizer", "name", DNSRecordFinalizer) | ||
controllerutil.RemoveFinalizer(dnsRecord, DNSRecordFinalizer) | ||
|
@@ -138,7 +145,7 @@ func (r *DNSRecordReconciler) updateStatus(ctx context.Context, previous, curren | |
if apierrors.IsConflict(updateError) { | ||
return ctrl.Result{Requeue: true}, nil | ||
} | ||
return ctrl.Result{}, updateError | ||
return ctrl.Result{RequeueAfter: requeueAfter}, updateError | ||
} | ||
return ctrl.Result{RequeueAfter: requeueAfter}, nil | ||
} | ||
|
@@ -155,7 +162,7 @@ func (r *DNSRecordReconciler) SetupWithManager(mgr ctrl.Manager, requeueIn, vali | |
|
||
// deleteRecord deletes record(s) in the DNSPRovider(i.e. route53) configured by the ManagedZone assigned to this | ||
// DNSRecord (dnsRecord.Status.ParentManagedZone). | ||
func (r *DNSRecordReconciler) deleteRecord(ctx context.Context, dnsRecord *v1alpha1.DNSRecord) error { | ||
func (r *DNSRecordReconciler) deleteRecord(ctx context.Context, dnsRecord *v1alpha1.DNSRecord) (time.Duration, error) { | ||
logger := log.FromContext(ctx) | ||
|
||
managedZone := &v1alpha1.ManagedZone{ | ||
|
@@ -167,28 +174,28 @@ func (r *DNSRecordReconciler) deleteRecord(ctx context.Context, dnsRecord *v1alp | |
err := r.Get(ctx, client.ObjectKeyFromObject(managedZone), managedZone, &client.GetOptions{}) | ||
if err != nil { | ||
// If the Managed Zone isn't found, just continue | ||
return client.IgnoreNotFound(err) | ||
return noRequeueDuration, client.IgnoreNotFound(err) | ||
} | ||
managedZoneReady := meta.IsStatusConditionTrue(managedZone.Status.Conditions, "Ready") | ||
|
||
if !managedZoneReady { | ||
return fmt.Errorf("the managed zone is not in a ready state : %s", managedZone.Name) | ||
return validationRequeueTime, fmt.Errorf("the managed zone is not in a ready state : %s", managedZone.Name) | ||
} | ||
|
||
_, err = r.applyChanges(ctx, dnsRecord, managedZone, true) | ||
requeueTime, err := r.applyChanges(ctx, dnsRecord, managedZone, true) | ||
if err != nil { | ||
if strings.Contains(err.Error(), "was not found") || strings.Contains(err.Error(), "notFound") { | ||
logger.Info("Record not found in managed zone, continuing", "dnsRecord", dnsRecord.Name, "managedZone", managedZone.Name) | ||
return nil | ||
return noRequeueDuration, nil | ||
} else if strings.Contains(err.Error(), "no endpoints") { | ||
logger.Info("DNS record had no endpoint, continuing", "dnsRecord", dnsRecord.Name, "managedZone", managedZone.Name) | ||
return nil | ||
return noRequeueDuration, nil | ||
} | ||
return err | ||
return noRequeueDuration, err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes. The way it is interpreted: if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no leave as is for now and can follow up with improvements |
||
} | ||
logger.Info("Deleted DNSRecord in manage zone", "dnsRecord", dnsRecord.Name, "managedZone", managedZone.Name) | ||
|
||
return nil | ||
return requeueTime, nil | ||
} | ||
|
||
// publishRecord publishes record(s) to the DNSPRovider(i.e. route53) configured by the ManagedZone assigned to this | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok so delete was successful but we need to revalidate. Hmm this took me a while to figure out. Could we add a comment explaining that is what is happening here and why we do this comparison?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added more detailed comment