Skip to content

Commit

Permalink
Rearrange method and remove unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
beagles committed Jan 15, 2025
1 parent bce3dab commit 150f73c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 130 deletions.
141 changes: 71 additions & 70 deletions controllers/designate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,8 @@ func (r *DesignateReconciler) reconcileNormal(ctx context.Context, instance *des
return ctrl.Result{}, err
}

// While nsRecordsConfigMap is not used until much later in this function, it's valuable to check this early
// as it is an important precondition.
nsRecordsLabels := labels.GetLabels(instance, labels.GetGroupLabel(instance.ObjectMeta.Name), map[string]string{})
nsRecordsConfigMap, err := r.handleConfigMap(ctx, helper, instance, designate.NsRecordsConfigMap, nsRecordsLabels)
if err != nil {
Expand Down Expand Up @@ -827,76 +829,6 @@ func (r *DesignateReconciler) reconcileNormal(ctx context.Context, instance *des
return ctrl.Result{}, err
}

if err != nil {
return ctrl.Result{}, err
}
if len(nsRecordsConfigMap.Data) > 0 {
poolsYamlConfigMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: designate.PoolsYamlConfigMap,
Namespace: instance.GetNamespace(),
Labels: bindLabels,
},
Data: make(map[string]string),
}
poolsYaml, err := designate.GeneratePoolsYamlData(bindConfigMap.Data, mdnsConfigMap.Data, nsRecordsConfigMap.Data)
if err != nil {
return ctrl.Result{}, err
}
Log.Info(fmt.Sprintf("pools.yaml content is\n%v", poolsYaml))
updatedPoolsYaml := make(map[string]string)
updatedPoolsYaml[designate.PoolsYamlContent] = poolsYaml

_, err = controllerutil.CreateOrPatch(ctx, helper.GetClient(), poolsYamlConfigMap, func() error {
poolsYamlConfigMap.Labels = util.MergeStringMaps(poolsYamlConfigMap.Labels, bindLabels)
poolsYamlConfigMap.Data = updatedPoolsYaml
return controllerutil.SetControllerReference(instance, poolsYamlConfigMap, helper.GetScheme())
})
if err != nil {
Log.Info("Unable to create config map for pools.yaml file")
return ctrl.Result{}, err
}
configMaps := []interface{}{
poolsYamlConfigMap.Data,
}

poolsYamlsEnvVars := make(map[string]env.Setter)
_, changed, err := r.createHashOfInputHashes(ctx, instance, designate.PoolsYamlHash, poolsYamlsEnvVars, configMaps)
if err != nil {
return ctrl.Result{}, err
}
if changed {
Log.Info("PoolsYamlHash has changed, creating a pool update job")

var poolUpdateHash string
var ok bool
if poolUpdateHash, ok = instance.Status.Hash[designatev1beta1.PoolUpdateHash]; !ok {
instance.Status.Hash[designatev1beta1.PoolUpdateHash] = ""
poolUpdateHash = ""
}
jobDef := designate.PoolUpdateJob(instance, serviceLabels, serviceAnnotations)

Log.Info("Initializing pool update job")
poolUpdatejob := job.NewJob(
jobDef,
designatev1beta1.PoolUpdateHash,
instance.Spec.PreserveJobs,
time.Duration(15)*time.Second,
poolUpdateHash,
)
_, err = poolUpdatejob.DoJob(ctx, helper)
if err != nil {
return ctrl.Result{}, err
}
instance.Status.Hash[designatev1beta1.PoolUpdateHash] = poolUpdatejob.GetHash()
err = r.Client.Status().Update(ctx, instance)
if err != nil {
return ctrl.Result{}, err
}
Log.Info("Pool update job completed successfully")
}
}

// deploy designate-central
designateCentral, op, err := r.centralDeploymentCreateOrUpdate(ctx, instance)
if err != nil {
Expand Down Expand Up @@ -1143,6 +1075,75 @@ func (r *DesignateReconciler) reconcileNormal(ctx context.Context, instance *des
}
Log.Info("Deployment Unbound task reconciled")

if designateCentral.Status.Conditions.IsTrue(condition.ReadyCondition) &&
designateCentral.Status.ReadyCount == *designateCentral.Spec.Replicas &&
len(nsRecordsConfigMap.Data) > 0 {
poolsYamlConfigMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: designate.PoolsYamlConfigMap,
Namespace: instance.GetNamespace(),
Labels: bindLabels,
},
Data: make(map[string]string),
}
poolsYaml, err := designate.GeneratePoolsYamlData(bindConfigMap.Data, mdnsConfigMap.Data, nsRecordsConfigMap.Data)
if err != nil {
return ctrl.Result{}, err
}
Log.Info(fmt.Sprintf("pools.yaml content is\n%v", poolsYaml))
updatedPoolsYaml := make(map[string]string)
updatedPoolsYaml[designate.PoolsYamlContent] = poolsYaml

_, err = controllerutil.CreateOrPatch(ctx, helper.GetClient(), poolsYamlConfigMap, func() error {
poolsYamlConfigMap.Labels = util.MergeStringMaps(poolsYamlConfigMap.Labels, bindLabels)
poolsYamlConfigMap.Data = updatedPoolsYaml
return controllerutil.SetControllerReference(instance, poolsYamlConfigMap, helper.GetScheme())
})
if err != nil {
Log.Info("Unable to create config map for pools.yaml file")
return ctrl.Result{}, err
}
configMaps := []interface{}{
poolsYamlConfigMap.Data,
}

poolsYamlsEnvVars := make(map[string]env.Setter)
_, changed, err := r.createHashOfInputHashes(ctx, instance, designate.PoolsYamlHash, poolsYamlsEnvVars, configMaps)
if err != nil {
return ctrl.Result{}, err
}
if changed {
Log.Info("PoolsYamlHash has changed, creating a pool update job")

var poolUpdateHash string
var ok bool
if poolUpdateHash, ok = instance.Status.Hash[designatev1beta1.PoolUpdateHash]; !ok {
instance.Status.Hash[designatev1beta1.PoolUpdateHash] = ""
poolUpdateHash = ""
}
jobDef := designate.PoolUpdateJob(instance, serviceLabels, serviceAnnotations)

Log.Info("Initializing pool update job")
poolUpdatejob := job.NewJob(
jobDef,
designatev1beta1.PoolUpdateHash,
instance.Spec.PreserveJobs,
time.Duration(15)*time.Second,
poolUpdateHash,
)
_, err = poolUpdatejob.DoJob(ctx, helper)
if err != nil {
return ctrl.Result{}, err
}
instance.Status.Hash[designatev1beta1.PoolUpdateHash] = poolUpdatejob.GetHash()
err = r.Client.Status().Update(ctx, instance)
if err != nil {
return ctrl.Result{}, err
}
Log.Info("Pool update job completed successfully")
}
}

// remove finalizers from unused MariaDBAccount records
err = mariadbv1.DeleteUnusedMariaDBAccountFinalizers(ctx, helper, designate.DatabaseCRName, instance.Spec.DatabaseAccount, instance.Namespace)
if err != nil {
Expand Down
10 changes: 3 additions & 7 deletions pkg/designatecentral/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// "k8s.io/apimachinery/pkg/util/intstr"
)

// Deployment func
Expand All @@ -37,15 +36,12 @@ func Deployment(
labels map[string]string,
annotations map[string]string,
) *appsv1.Deployment {
// TODO(beagles): running as root should not be necessary here.
rootUser := int64(0)
// Designate's uid and gid magic numbers come from the 'designate-user' in
// https://github.com/openstack/kolla/blob/master/kolla/common/users.py
// designateUser := int64(42411)
// designateGroup := int64(42411)

serviceName := fmt.Sprintf("%s-central", designate.ServiceName)
volumes := getServicePodVolumes(serviceName)
volumeMounts := getServicePodVolumeMounts(serviceName)
volumes := designate.GetVolumes(serviceName)
volumeMounts := designate.GetVolumeMounts(serviceName)

livenessProbe := &corev1.Probe{
// TODO might need tuning
Expand Down
53 changes: 0 additions & 53 deletions pkg/designatecentral/volumes.go

This file was deleted.

0 comments on commit 150f73c

Please sign in to comment.