Skip to content

Commit

Permalink
Rebase edit
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Fitzpatrick <jfitzpat@redhat.com>
  • Loading branch information
Boomatang committed Oct 18, 2024
1 parent af8c51c commit 01d0322
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 5 deletions.
65 changes: 65 additions & 0 deletions controllers/orphaned_dnsrecord_reconciler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package controllers

//import (
// "context"
// "fmt"
// "sync"
//
// kuadrantdnsv1alpha1 "github.com/kuadrant/dns-operator/api/v1alpha1"
// "github.com/kuadrant/policy-machinery/controller"
// "github.com/kuadrant/policy-machinery/machinery"
// "github.com/samber/lo"
// apierrors "k8s.io/apimachinery/pkg/api/errors"
// metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// "k8s.io/client-go/dynamic"
// "k8s.io/utils/ptr"
//
// kuadrantv1alpha1 "github.com/kuadrant/kuadrant-operator/api/v1alpha1"
//)
//
//func NewOrphanedDNSRecordReconciler(client *dynamic.DynamicClient) *OrphanedDNSRecordReconciler {
// return &OrphanedDNSRecordReconciler{client: client}
//}
//
//type OrphanedDNSRecordReconciler struct {
// client *dynamic.DynamicClient
//}
//
//func (r *OrphanedDNSRecordReconciler) Subscription() controller.Subscription {
// return controller.Subscription{
// ReconcileFunc: r.reconcile,
// Events: []controller.ResourceEventMatcher{
// {Kind: &machinery.GatewayGroupKind, EventType: ptr.To(controller.UpdateEvent)},
// {Kind: &machinery.GatewayGroupKind, EventType: ptr.To(controller.DeleteEvent)},
// {Kind: &kuadrantv1alpha1.DNSPolicyGroupKind, EventType: ptr.To(controller.UpdateEvent)},
// },
// }
//}
//
//func (r *OrphanedDNSRecordReconciler) reconcile(ctx context.Context, _ []controller.ResourceEvent, topology *machinery.Topology, _ error, _ *sync.Map) error {
// logger := controller.LoggerFromContext(ctx).WithName("orphanedDNSRecordReconciler")
// logger.Info("deleting orphan policy DNS records")
//
// orphanRecords := lo.FilterMap(topology.Objects().Items(), func(item machinery.Object, _ int) (machinery.Object, bool) {
// if item.GroupVersionKind().GroupKind() == DNSRecordGroupKind && item.(controller.Object).GetDeletionTimestamp() != nil {
// policyOwnerRef := getObjectPolicyOwnerReference(item, kuadrantv1alpha1.DNSPolicyGroupKind)
// // Any DNSRecord that does not have a link in the topology back to its owner DNSPolicy should be removed
// if len(topology.All().Paths(policyOwnerRef, item)) == 0 {
// logger.Info(fmt.Sprintf("dnsrecord object is no longer linked to it's policy owner, dnsrecord: %v, policy: %v", item.GetLocator(), policyOwnerRef.GetLocator()))
// return item, true
// }
// }
// return nil, false
// })
//
// for i := range orphanRecords {
// record := orphanRecords[i].(*controller.RuntimeObject).Object.(*kuadrantdnsv1alpha1.DNSRecord)
// logger.Info(fmt.Sprintf("deleting DNSRecord: %v", orphanRecords[i].GetLocator()))
// resource := r.client.Resource(DNSRecordResource).Namespace(record.GetNamespace())
// if err := resource.Delete(ctx, record.GetName(), metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
// logger.Error(err, "failed to delete DNSRecord")
// }
// }
//
// return nil
//}
6 changes: 1 addition & 5 deletions tests/commons.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ import (
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"

limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1"

kuadrantdnsv1alpha1 "github.com/kuadrant/dns-operator/api/v1alpha1"
kuadrantdnsbuilder "github.com/kuadrant/dns-operator/pkg/builder"

kuadrantv1alpha1 "github.com/kuadrant/kuadrant-operator/api/v1alpha1"
kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1"
kuadrantv1beta3 "github.com/kuadrant/kuadrant-operator/api/v1beta3"
kuadrantgatewayapi "github.com/kuadrant/kuadrant-operator/pkg/library/gatewayapi"
Expand Down

0 comments on commit 01d0322

Please sign in to comment.