diff --git a/controllers/designate_controller.go b/controllers/designate_controller.go index 127f6db7..818c27bc 100644 --- a/controllers/designate_controller.go +++ b/controllers/designate_controller.go @@ -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 { @@ -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 { @@ -1143,6 +1075,76 @@ func (r *DesignateReconciler) reconcileNormal(ctx context.Context, instance *des } Log.Info("Deployment Unbound task reconciled") + 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, + } + + if designateCentral.Status.Conditions.IsTrue(condition.ReadyCondition) && + designateCentral.Status.ReadyCount == *designateCentral.Spec.Replicas { + 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 { diff --git a/pkg/designatecentral/deployment.go b/pkg/designatecentral/deployment.go index 9dfab6d6..baf9fe0b 100644 --- a/pkg/designatecentral/deployment.go +++ b/pkg/designatecentral/deployment.go @@ -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 @@ -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 diff --git a/pkg/designatecentral/volumes.go b/pkg/designatecentral/volumes.go deleted file mode 100644 index b5c7f3c0..00000000 --- a/pkg/designatecentral/volumes.go +++ /dev/null @@ -1,53 +0,0 @@ -/* - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package designatecentral - -import ( - designate "github.com/openstack-k8s-operators/designate-operator/pkg/designate" - corev1 "k8s.io/api/core/v1" -) - -func getServicePodVolumes(serviceName string) []corev1.Volume { - // var configMode int32 = 0640 - // return append(designate.GetVolumes(serviceName), corev1.Volume{ - // Name: "pools-yaml-config", - // VolumeSource: corev1.VolumeSource{ - // ConfigMap: &corev1.ConfigMapVolumeSource{ - // LocalObjectReference: corev1.LocalObjectReference{ - // Name: designate.PoolsYamlConfigMap, - // }, - // Items: []corev1.KeyToPath{ - // { - // Key: designate.PoolsYamlContent, - // Path: "pools.yaml", - // }, - // }, - // DefaultMode: &configMode, - // }, - // }, - // }) - return designate.GetVolumes(serviceName) -} - -func getServicePodVolumeMounts(serviceName string) []corev1.VolumeMount { - // return append(designate.GetVolumeMounts(serviceName), corev1.VolumeMount{ - // Name: "pools-yaml-config", - // MountPath: "/etc/designate/pools.yaml", - // SubPath: "pools.yaml", - // ReadOnly: true, - // }) - return designate.GetVolumeMounts(serviceName) -} diff --git a/templates/designatebackendbind9/config-named/options.conf b/templates/designatebackendbind9/config-named/options.conf index 1f89b184..71592ec9 100644 --- a/templates/designatebackendbind9/config-named/options.conf +++ b/templates/designatebackendbind9/config-named/options.conf @@ -9,10 +9,10 @@ options { # TODO: The '*'s need to be replaced by actual addresses. {{ if eq .IPVersion "4" }} - listen-on port 53 { *; }; + listen-on port 53 { any; }; listen-on-v6 { none; }; {{ else if eq .IPVersion "6" }} - listen-on-v6 port 53 { *; }; + listen-on-v6 port 53 { any; }; listen-on { none; }; {{ end }}