-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jim Fitzpatrick <jfitzpat@redhat.com>
- Loading branch information
Showing
2 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters