@@ -816,6 +816,8 @@ func (r *DesignateReconciler) reconcileNormal(ctx context.Context, instance *des
816816 return ctrl.Result {}, err
817817 }
818818
819+ Log .Info ("Before creating bind configmap" )
820+
819821 _ , err = controllerutil .CreateOrPatch (ctx , helper .GetClient (), bindConfigMap , func () error {
820822 bindConfigMap .Labels = util .MergeStringMaps (bindConfigMap .Labels , bindLabels )
821823 bindConfigMap .Data = updatedBindMap
@@ -827,25 +829,26 @@ func (r *DesignateReconciler) reconcileNormal(ctx context.Context, instance *des
827829 return ctrl.Result {}, err
828830 }
829831
830- if err != nil {
831- return ctrl. Result {}, err
832- }
833- if len (nsRecordsConfigMap .Data ) > 0 {
832+ Log . Info ( "Bind configmap was created successfully" )
833+
834+ if len ( nsRecordsConfigMap . Data ) > 0 && instance . Status . DesignateCentralReadyCount > 0 {
835+ Log . Info ( " len(nsRecordsConfigMap.Data) > 0" )
834836 poolsYamlConfigMap := & corev1.ConfigMap {
835837 ObjectMeta : metav1.ObjectMeta {
836- Name : designate .PoolsYamlsConfigMap ,
838+ Name : designate .PoolsYamlConfigMap ,
837839 Namespace : instance .GetNamespace (),
838840 Labels : bindLabels ,
839841 },
840842 Data : make (map [string ]string ),
841843 }
844+ Log .Info ("before designate.GeneratePoolsYamlData" )
842845 poolsYaml , err := designate .GeneratePoolsYamlData (bindConfigMap .Data , mdnsConfigMap .Data , nsRecordsConfigMap .Data )
843846 if err != nil {
844847 return ctrl.Result {}, err
845848 }
846849 Log .Info (fmt .Sprintf ("pools.yaml content is\n %v" , poolsYaml ))
847850 updatedPoolsYaml := make (map [string ]string )
848- updatedPoolsYaml [designate .PoolsYamlsConfigMap ] = poolsYaml
851+ updatedPoolsYaml [designate .PoolsYamlContent ] = poolsYaml
849852
850853 _ , err = controllerutil .CreateOrPatch (ctx , helper .GetClient (), poolsYamlConfigMap , func () error {
851854 poolsYamlConfigMap .Labels = util .MergeStringMaps (poolsYamlConfigMap .Labels , bindLabels )
@@ -864,9 +867,36 @@ func (r *DesignateReconciler) reconcileNormal(ctx context.Context, instance *des
864867 _ , changed , err := r .createHashOfInputHashes (ctx , instance , designate .PoolsYamlHash , poolsYamlsEnvVars , configMaps )
865868 if err != nil {
866869 return ctrl.Result {}, err
867- } else if changed {
868- // launch the pool update job
869- Log .Info ("Creating a pool update job" )
870+ }
871+ if changed {
872+ Log .Info ("PoolsYamlHash has changed, creating a pool update job" )
873+
874+ var poolUpdateHash string
875+ var ok bool
876+ if poolUpdateHash , ok = instance .Status .Hash [designatev1beta1 .PoolUpdateHash ]; ! ok {
877+ instance .Status .Hash [designatev1beta1 .PoolUpdateHash ] = ""
878+ poolUpdateHash = ""
879+ }
880+ jobDef := designate .PoolUpdateJob (instance , serviceLabels , serviceAnnotations )
881+
882+ Log .Info ("Initializing pool update job" )
883+ poolUpdatejob := job .NewJob (
884+ jobDef ,
885+ designatev1beta1 .PoolUpdateHash ,
886+ instance .Spec .PreserveJobs ,
887+ time .Duration (15 )* time .Second ,
888+ poolUpdateHash ,
889+ )
890+ _ , err = poolUpdatejob .DoJob (ctx , helper )
891+ if err != nil {
892+ return ctrl.Result {}, err
893+ }
894+ instance .Status .Hash [designatev1beta1 .PoolUpdateHash ] = poolUpdatejob .GetHash ()
895+ err = r .Client .Status ().Update (ctx , instance )
896+ if err != nil {
897+ return ctrl.Result {}, err
898+ }
899+ Log .Info ("Pool update job completed successfully" )
870900 }
871901 }
872902
0 commit comments