Skip to content

Commit

Permalink
refactor: drop abstract from podLabelReconciler
Browse files Browse the repository at this point in the history
  • Loading branch information
gchiesa committed Nov 23, 2023
1 parent d1e29b1 commit d629339
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions controllers/podlabels/abstract.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (
capsulev1beta2 "github.com/projectcapsule/capsule/api/v1beta2"
)

type abstractPodLabelsReconciler struct {
type podLabelsReconciler struct {
obj client.Object
client client.Client
log logr.Logger
}

func (r *abstractPodLabelsReconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) {
func (r *podLabelsReconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) {
tenant, err := r.getTenant(ctx, request.NamespacedName, r.client)
if err != nil {
r.log.Error(err, fmt.Sprintf("Cannot get tenant for %T %s/%s", r.obj, request.Namespace, request.Name))
Expand Down Expand Up @@ -59,7 +59,7 @@ func (r *abstractPodLabelsReconciler) Reconcile(ctx context.Context, request ctr
return reconcile.Result{}, err
}

func (r *abstractPodLabelsReconciler) getTenant(ctx context.Context, namespacedName types.NamespacedName, client client.Client) (*capsulev1beta2.Tenant, error) {
func (r *podLabelsReconciler) getTenant(ctx context.Context, namespacedName types.NamespacedName, client client.Client) (*capsulev1beta2.Tenant, error) {
ns := &corev1.Namespace{}
tenant := &capsulev1beta2.Tenant{}

Expand All @@ -83,7 +83,7 @@ func (r *abstractPodLabelsReconciler) getTenant(ctx context.Context, namespacedN
return tenant, nil
}

func (r *abstractPodLabelsReconciler) sync(available map[string]string, tenantSpec map[string]string) map[string]string {
func (r *podLabelsReconciler) sync(available map[string]string, tenantSpec map[string]string) map[string]string {
if tenantSpec != nil {
if available == nil {
available = tenantSpec
Expand All @@ -99,13 +99,13 @@ func (r *abstractPodLabelsReconciler) sync(available map[string]string, tenantSp
return available
}

func (r *abstractPodLabelsReconciler) forOptionPerInstanceName(ctx context.Context) builder.ForOption {
func (r *podLabelsReconciler) forOptionPerInstanceName(ctx context.Context) builder.ForOption {
return builder.WithPredicates(predicate.NewPredicateFuncs(func(object client.Object) bool {
return r.IsNamespaceInTenant(ctx, object.GetNamespace())
}))
}

func (r *abstractPodLabelsReconciler) IsNamespaceInTenant(ctx context.Context, namespace string) bool {
func (r *podLabelsReconciler) IsNamespaceInTenant(ctx context.Context, namespace string) bool {
tl := &capsulev1beta2.TenantList{}
if err := r.client.List(ctx, tl, client.MatchingFieldsSelector{
Selector: fields.OneTermEqualSelector(".status.namespaces", namespace),
Expand Down
6 changes: 3 additions & 3 deletions controllers/podlabels/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import (
)

type PodLabelsReconciler struct {
abstractPodLabelsReconciler
podLabelsReconciler

Log logr.Logger
}

func (r *PodLabelsReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) error {
r.abstractPodLabelsReconciler = abstractPodLabelsReconciler{
r.podLabelsReconciler = podLabelsReconciler{
obj: &corev1.Pod{},
client: mgr.GetClient(),
log: r.Log,
}

return ctrl.NewControllerManagedBy(mgr).
For(r.abstractPodLabelsReconciler.obj, r.abstractPodLabelsReconciler.forOptionPerInstanceName(ctx)).
For(r.podLabelsReconciler.obj, r.podLabelsReconciler.forOptionPerInstanceName(ctx)).
Complete(r)
}

0 comments on commit d629339

Please sign in to comment.