Skip to content

Commit

Permalink
add more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
simonoff committed Sep 12, 2024
1 parent e39748d commit 0743bcb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ spec:
- --leader-elect
- --health-probe-bind-address=:8081
- --config-map-name=$(OPERATOR_DEPLOYMENT_NAME)-config
- --zap-log-level=1
- --secret-name=$(OPERATOR_DEPLOYMENT_NAME)-config
env:
- name: OPERATOR_NAMESPACE
Expand Down
20 changes: 16 additions & 4 deletions internal/controller/domain/domain_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func (r *DomainReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr

domainName := mailgunDomain.Spec.Domain

log.V(1).Info("Start to reconcile domain", "domain", domainName)

mg := r.Config.MailgunClient(domainName)

// examine DeletionTimestamp to determine if object is under deletion
Expand All @@ -104,6 +106,7 @@ func (r *DomainReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
// If its a new domain we should create it on mailgun and update status
if len(mailgunDomain.Status.State) == 0 {
// Set domain as processing
log.V(1).Info("Change status to processing", "domain", domainName)
mailgunDomain.Status.State = domainv1.DomainProcessing

// Update status
Expand All @@ -113,6 +116,7 @@ func (r *DomainReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
}

// try to search domain on Mailgun
log.V(1).Info("Get domain from mailgun", "domain", domainName)
_, err := mg.GetDomain(ctx, domainName)
if err == nil {
errorMgs := "Domain already exists on Mailgun"
Expand All @@ -130,6 +134,7 @@ func (r *DomainReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
return ctrl.Result{}, nil
}

log.V(1).Info("Create domain on mailgun", "domain", domainName)
err = r.createDomain(ctx, mailgunDomain, mg)
if err != nil {
log.Error(err, "Unable to create domain on mailgun")
Expand All @@ -151,32 +156,37 @@ func (r *DomainReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
}

if mailgunDomain.Spec.ExternalDNS != nil && *mailgunDomain.Spec.ExternalDNS {
log.V(1).Info("Create external dns records", "domain", domainName)
err := r.createExternalDNSEntity(ctx, mailgunDomain)
if err != nil {
return ctrl.Result{}, err
}
}

return ctrl.Result{
RequeueAfter: time.Duration(r.Config.DomainVerifyDuration),
RequeueAfter: time.Duration(r.Config.DomainVerifyDuration) * time.Second,
}, nil
}

// its not a new record and a new tick of the loop

if mailgunDomain.Status.State == domainv1.DomainFailed {
log.V(1).Info("Domain state failed - no continue", "domain", domainName)
// if the state is failed and we have an error message, return it
return ctrl.Result{}, nil
}

// verify domain
log.V(1).Info("Call a verifying domain on mailgun", "domain", domainName)
status, err := mg.VerifyDomain(ctx, domainName)
if err != nil {
log.Error(err, "unable to verify domain", "domain", domainName)
return ctrl.Result{}, err
return ctrl.Result{
RequeueAfter: time.Duration(r.Config.DomainVerifyDuration) * time.Second,
}, err
}

if status == "active" {
log.V(1).Info("Domain activated on mailgun", "domain", domainName)
mailgunDomain.Status.State = domainv1.DomainActivated
if err := r.Status().Update(ctx, mailgunDomain); err != nil {
log.Error(err, "unable to update Domain status")
Expand All @@ -185,8 +195,10 @@ func (r *DomainReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
return ctrl.Result{}, nil
}

log.V(1).Info("Domain is activated on mailgun - calling for a next tick", "domain", domainName)

return ctrl.Result{
RequeueAfter: time.Duration(r.Config.DomainVerifyDuration),
RequeueAfter: time.Duration(r.Config.DomainVerifyDuration) * time.Second,
}, nil
}

Expand Down

0 comments on commit 0743bcb

Please sign in to comment.