@@ -618,21 +618,17 @@ func (r *DNSRecordReconciler) applyChanges(ctx context.Context, dnsRecord *v1alp
618
618
return r .applyExternalDNSChanges (ctx , dnsRecord , probes , dnsProvider , isDelete )
619
619
}
620
620
621
- // core dns stuff
622
- // centeralise
623
- const localZoneDomain = "kdrnt"
624
-
625
621
func computeLocalEndpointSet (original * v1alpha1.DNSRecord ) []* externaldnsendpoint.Endpoint {
626
622
var localEndpoints []* externaldnsendpoint.Endpoint
627
623
rootDomainName := original .Spec .RootHost
628
624
for _ , originalEP := range original .Spec .Endpoints {
629
625
localEP := originalEP .DeepCopy ()
630
- localEP .DNSName = fmt .Sprintf ("%s.%s" , localEP .DNSName , localZoneDomain )
626
+ localEP .DNSName = fmt .Sprintf ("%s.%s" , localEP .DNSName , provider . KuadrantTLD )
631
627
if len (localEP .ProviderSpecific ) > 0 {
632
628
for _ , ps := range localEP .ProviderSpecific {
633
629
if ps .Name == "weight" {
634
630
weightEP := externaldnsendpoint.Endpoint {
635
- DNSName : "w." + fmt .Sprintf ("%s.%s" , rootDomainName , localZoneDomain ),
631
+ DNSName : "w." + fmt .Sprintf ("%s.%s" , rootDomainName , provider . KuadrantTLD ),
636
632
Targets : []string {fmt .Sprintf ("%s,%s" , ps .Value , localEP .DNSName )},
637
633
RecordType : "TXT" ,
638
634
}
@@ -641,10 +637,10 @@ func computeLocalEndpointSet(original *v1alpha1.DNSRecord) []*externaldnsendpoin
641
637
}
642
638
}
643
639
for i , target := range localEP .Targets {
644
- if ! strings .HasSuffix (target , localZoneDomain ) {
640
+ if ! strings .HasSuffix (target , provider . KuadrantTLD ) {
645
641
// ignore IPs
646
642
if net .ParseIP (target ) == nil {
647
- localEP .Targets [i ] = fmt .Sprintf ("%s.%s" , target , localZoneDomain )
643
+ localEP .Targets [i ] = fmt .Sprintf ("%s.%s" , target , provider . KuadrantTLD )
648
644
}
649
645
}
650
646
}
@@ -690,7 +686,6 @@ func (r *DNSRecordReconciler) applyLocalChanges(ctx context.Context, dnsRecord *
690
686
691
687
if err := r .Client .Get (ctx , client .ObjectKeyFromObject (mergeCopy ), mergeCopy ); err != nil {
692
688
if apierrors .IsNotFound (err ) {
693
- fmt .Println ("creating merged copy " , mergeCopy .Name )
694
689
mergeCopy .Spec = original .Spec
695
690
mergeCopy .Spec .Endpoints = endpointSet
696
691
mergeCopy .Labels = map [string ]string {"kuadrant.io/type" : "merged" , "kuadrant.io/zone-name" : original .Status .ZoneDomainName }
@@ -706,7 +701,6 @@ func (r *DNSRecordReconciler) applyLocalChanges(ctx context.Context, dnsRecord *
706
701
707
702
}
708
703
mergeCopy .Spec .Endpoints = endpointSet
709
- fmt .Println ("Updating merged copy " , mergeCopy .Name )
710
704
if err := r .Client .Update (ctx , mergeCopy , & client.UpdateOptions {}); err != nil {
711
705
return fmt .Errorf ("failed to update core dns merged copy %w" , err )
712
706
}
@@ -728,8 +722,8 @@ func (r *DNSRecordReconciler) applyLocalChanges(ctx context.Context, dnsRecord *
728
722
if apierrors .IsNotFound (err ) {
729
723
// create
730
724
kdrntLocalCopy .Spec = original .Spec
731
- kdrntLocalCopy .Labels = map [string ]string {"kuadrant.io/type" : "local" , "kuadrant.io/zone-name" : localZoneDomain }
732
- kdrntLocalCopy .Spec .RootHost = fmt .Sprintf ("%s.%s" , original .Spec .RootHost , localZoneDomain )
725
+ kdrntLocalCopy .Labels = map [string ]string {"kuadrant.io/type" : "local" , "kuadrant.io/zone-name" : provider . KuadrantTLD }
726
+ kdrntLocalCopy .Spec .RootHost = fmt .Sprintf ("%s.%s" , original .Spec .RootHost , provider . KuadrantTLD )
733
727
kdrntLocalCopy .Spec .Endpoints = computeLocalEndpointSet (original )
734
728
if err := controllerutil .SetOwnerReference (dnsRecord , kdrntLocalCopy , r .Scheme ); err != nil {
735
729
return err
@@ -777,141 +771,6 @@ func (r *DNSRecordReconciler) applyLocalChanges(ctx context.Context, dnsRecord *
777
771
}
778
772
}
779
773
return hadChanges , []string {}, nil
780
-
781
- // if dnsRecord.Labels != nil {
782
- // if provider, ok := dnsRecord.Labels["type"]; ok {
783
- // if provider == "coredns" {
784
- // beforeMerge := dnsRecord.DeepCopy()
785
- // // trigger dns look up of host against configured nameservers
786
- // remoteEndpoints, err := dnsProvider.RecordsForHost(ctx, rootDomainName)
787
- // if err != nil {
788
- // logger.Error(err, " failed to get endponts from nameservers")
789
- // return hadChanges, []string{}, err
790
- // }
791
- // // add the remote and local records to the same resource
792
- // for _, remoteEp := range remoteEndpoints {
793
- // alreadyExists := false
794
- // for _, localEP := range dnsRecord.Spec.Endpoints {
795
-
796
- // if localEP.DNSName == remoteEp.DNSName && slices.Equal(localEP.Targets, remoteEp.Targets) {
797
- // alreadyExists = true
798
- // break
799
- // }
800
- // }
801
- // if !alreadyExists {
802
- // fmt.Println("endpoint doesn't exist adding it ", remoteEp)
803
- // dnsRecord.Spec.Endpoints = append(dnsRecord.Spec.Endpoints, remoteEp)
804
- // }
805
-
806
- // }
807
- // if !slices.Equal(dnsRecord.Spec.Endpoints, beforeMerge.Spec.Endpoints) {
808
- // fmt.Println("updating core dns records as endpoints have changed")
809
- // if err := r.Client.Update(ctx, dnsRecord, &client.UpdateOptions{}); err != nil {
810
- // return hadChanges, []string{}, err
811
- // }
812
- // }
813
-
814
- // return hadChanges, []string{}, nil
815
- // }
816
- // }
817
- // }
818
- // localZoneDomain := "local.kdrnt"
819
- // // if we get to this point we are handling an original copy
820
- // localName := fmt.Sprintf("%s-%s", "local", dnsRecord.Name)
821
- // kdrntLocalCopy := &v1alpha1.DNSRecord{
822
- // ObjectMeta: metav1.ObjectMeta{
823
- // Name: localName,
824
- // Namespace: dnsRecord.Namespace,
825
- // Labels: map[string]string{" kuadrant.io/zone-name": localZoneDomain},
826
- // },
827
- // }
828
-
829
- // var localEndpoints []*externaldnsendpoint.Endpoint
830
-
831
- // for _, originalEP := range dnsRecord.Spec.Endpoints {
832
- // localEP := originalEP.DeepCopy()
833
- // localEP.DNSName = fmt.Sprintf("%s.%s", localEP.DNSName, localZoneDomain)
834
- // if len(localEP.ProviderSpecific) > 0 {
835
- // for _, ps := range localEP.ProviderSpecific {
836
- // if ps.Name == "weight" {
837
- // weightEP := externaldnsendpoint.Endpoint{
838
- // DNSName: "w." + rootDomainName,
839
- // Targets: []string{fmt.Sprintf("%s,%s", ps.Value, localEP.DNSName)},
840
- // RecordType: "TXT",
841
- // }
842
- // localEndpoints = append(localEndpoints, &weightEP)
843
- // }
844
- // }
845
- // }
846
- // for i, target := range localEP.Targets {
847
- // if !strings.HasSuffix(target, localZoneDomain) {
848
- // // ignore IPs
849
- // if net.ParseIP(target) == nil {
850
- // localEP.Targets[i] = fmt.Sprintf("m.%s", target)
851
- // }
852
- // }
853
- // }
854
- // localEP.ProviderSpecific = []externaldnsendpoint.ProviderSpecificProperty{}
855
- // localEndpoints = append(localEndpoints, localEP)
856
- // }
857
-
858
- // //update or create
859
- // if err := r.Client.Get(ctx, client.ObjectKeyFromObject(kdrntLocalCopy), kdrntLocalCopy); err != nil {
860
- // if apierrors.IsNotFound(err) {
861
- // // create
862
- // kdrntLocalCopy.Spec.Endpoints = localEndpoints
863
- // if err := r.Client.Create(ctx, kdrntLocalCopy, &client.CreateOptions{}); err != nil {
864
- // return hadChanges, []string{}, fmt.Errorf("failed to create kuadrant local copy %w", err)
865
- // }
866
- // }
867
- // return hadChanges, []string{}, err
868
- // }
869
- // // have copy from cluster update endpoints
870
- // // todo check if already equal before assinging and updating
871
- // kdrntLocalCopy.Spec.Endpoints = localEndpoints
872
-
873
- // if err := r.Client.Update(ctx, kdrntLocalCopy, &client.UpdateOptions{}); err != nil {
874
- // return hadChanges, []string{}, fmt.Errorf("failed to update kuadrant local copy %w", err)
875
- // }
876
-
877
- // // create of "merged" record. First thing is to copy over existing endpoints. Updates to the endpoints are handled above we just want to create
878
- // logger.Info("core dns: kuadrant record creating merged record as it doesn't exist " + dnsRecord.Name)
879
- // // kuadrant dns record create a new core dns one if needed
880
- // mergedRecordName := fmt.Sprintf("%s-%s", dnsProvider.Name(), dnsRecord.Name)
881
- // mergedRecord := &v1alpha1.DNSRecord{
882
- // ObjectMeta: metav1.ObjectMeta{
883
- // Name: mergedRecordName,
884
- // Namespace: dnsRecord.Namespace,
885
- // Labels: map[string]string{"provider": "coredns", " kuadrant.io/zone-name": dnsRecord.Status.ZoneDomainName},
886
- // },
887
- // }
888
- // doCreate := false
889
- // if err := r.Client.Get(ctx, client.ObjectKeyFromObject(mergedRecord), mergedRecord); err != nil {
890
- // doCreate = apierrors.IsNotFound(err)
891
- // }
892
- // mergedRecord.Spec = v1alpha1.DNSRecordSpec{
893
- // RootHost: rootDomainName,
894
- // ProviderRef: dnsRecord.Spec.ProviderRef,
895
- // Endpoints: dnsRecord.Spec.Endpoints,
896
- // }
897
-
898
- // mergedRecord.Status.ZoneDomainName = dnsRecord.Status.ZoneDomainName
899
- // mergedRecord.Status.ZoneID = dnsRecord.Status.ZoneID
900
- // if err := controllerutil.SetOwnerReference(dnsRecord, mergedRecord, r.Scheme); err != nil {
901
- // return hadChanges, []string{}, err
902
- // }
903
- // logger.Info("core dns: creating core dns clone")
904
- // if doCreate {
905
- // if err := r.Client.Create(ctx, mergedRecord, &client.CreateOptions{}); err != nil {
906
- // return hadChanges, []string{}, err
907
- // }
908
- // } else {
909
- // if err := r.Client.Update(ctx, mergedRecord, &client.UpdateOptions{}); err != nil {
910
- // return hadChanges, []string{}, err
911
- // }
912
- // }
913
-
914
- //return hadChanges, []string{}, nil
915
774
}
916
775
917
776
// applyExternalDNSChanges creates the Plan and applies it to the registry. This is used only for external cloud provider DNS. Returns true only if the Plan had no errors and there were changes to apply.
0 commit comments