Skip to content

Commit b669ba7

Browse files
committed
Some refactor notes.
1 parent aa4831d commit b669ba7

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

controllers/designate_controller.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ func getOrDefault(source string, def string) string {
6767
return source
6868
}
6969

70+
// NOTE(beagles): refactoring this is a little tricky because it has multiple
71+
// side-effects. It sets a parameter in conditions, sets a hash in the envVars,
72+
// and returns results. The function name is a little misleading as well because
73+
// it doesn't actually get the secret. It's more that it checks for it and gets
74+
// the hash. At the very least a rename to"ensureSecret" is warranted. It might
75+
// also be better to move into a separate file along with other helper
76+
// functions.
77+
7078
// helper function for retrieving a secret.
7179
func getSecret(
7280
ctx context.Context,
@@ -701,6 +709,9 @@ func (r *DesignateReconciler) reconcileNormal(ctx context.Context, instance *des
701709
return ctrlResult, nil
702710
}
703711

712+
// NOTE(beagles): consider moving the API reconcile until after the pools
713+
// yaml can be created. This avoid the "no servers" error that occurs when
714+
// there aren't any configured DNS servers.
704715
//
705716
// normal reconcile tasks
706717
//
@@ -748,6 +759,8 @@ func (r *DesignateReconciler) reconcileNormal(ctx context.Context, instance *des
748759
}
749760
Log.Info("Deployment API task reconciled")
750761

762+
// NOTE(beagles): Consider moving IP Map construction into a separate function.
763+
751764
// Handle Mdns predictable IPs configmap
752765
nad, err := nad.GetNADWithName(ctx, helper, instance.Spec.DesignateNetworkAttachment, instance.Namespace)
753766
if err != nil {
@@ -850,6 +863,8 @@ func (r *DesignateReconciler) reconcileNormal(ctx context.Context, instance *des
850863
return ctrl.Result{}, err
851864
}
852865

866+
// NOTE(beagles): Consider moving pools yaml generation into a separate function.
867+
853868
Log.Info("Bind configmap was created successfully")
854869
if len(nsRecords) > 0 && instance.Status.DesignateCentralReadyCount > 0 {
855870
Log.Info("NS records data found")
@@ -908,7 +923,10 @@ func (r *DesignateReconciler) reconcileNormal(ctx context.Context, instance *des
908923
}
909924
}
910925

911-
// deploy designate-central
926+
// NOTE(beagles): Kind of makes you wish for macros. These are all the same
927+
// pattern with just different names.
928+
//
929+
// deploy designate-central
912930
designateCentral, op, err := r.centralDeploymentCreateOrUpdate(ctx, instance)
913931
if err != nil {
914932
instance.Status.Conditions.Set(condition.FalseCondition(

pkg/designate/generate_bind9_pools_yaml.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,15 @@ func GeneratePoolsYamlDataAndHash(BindMap, MdnsMap map[string]string, nsRecords
9191
return nsRecords[i].Priority < nsRecords[j].Priority
9292
})
9393

94+
// Create an ordered list of IPs for the BIND's predictable IPs.
9495
bindIPs := make([]string, len(BindMap))
9596
keyTmpl := "bind_address_%d"
96-
for i := 0; i < len(BindMap); i++ {
97-
bindIPs[i] = BindMap[fmt.Sprintf(keyTmpl, i)]
97+
for i := range len(BindMap) {
98+
if ip, ok := BindMap[fmt.Sprintf(keyTmpl, i)]; ok {
99+
bindIPs[i] = ip
100+
} else {
101+
return "", "", fmt.Errorf("bind IP not found for index %d", i)
102+
}
98103
}
99104

100105
masterHosts := make([]string, 0, len(MdnsMap))

0 commit comments

Comments
 (0)