Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion internal/clientutil/clientutil.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

// Package clientutil provides a client wrapper for the controller-runtime client with convenience functions.
package clientutil

import (
"context"
"crypto/tls"
"errors"
"fmt"
"slices"

corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -50,7 +53,9 @@ func (c *Client) Get(ctx context.Context, key client.ObjectKey, obj client.Objec
// returned from the Server. It will automatically restrict the request to the
// namespace that is set in the Client.
func (c *Client) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error {
opts = append(opts, client.InNamespace(c.DefaultNamespace))
if slices.ContainsFunc(opts, func(opt client.ListOption) bool { _, ok := opt.(client.InNamespace); return ok }) {
opts = append(opts, client.InNamespace(c.DefaultNamespace))
}
return c.r.List(ctx, list, opts...)
}

Expand Down
4 changes: 1 addition & 3 deletions internal/controller/core/device_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,8 @@ func (r *DeviceReconciler) reconcile(ctx context.Context, device *v1alpha1.Devic
return fmt.Errorf("failed to list device ports: %w", err)
}

c := clientutil.NewClient(r.Client, device.Namespace)

interfaces := new(v1alpha1.InterfaceList)
if err := c.List(ctx, interfaces, client.InNamespace(device.Namespace), client.MatchingLabels{v1alpha1.DeviceLabel: device.Name}); err != nil {
if err := r.List(ctx, interfaces, client.InNamespace(device.Namespace), client.MatchingLabels{v1alpha1.DeviceLabel: device.Name}); err != nil {
return fmt.Errorf("failed to list interface resources for device: %w", err)
}

Expand Down
5 changes: 1 addition & 4 deletions internal/controller/core/isis_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"

"github.com/ironcore-dev/network-operator/api/core/v1alpha1"
"github.com/ironcore-dev/network-operator/internal/clientutil"
"github.com/ironcore-dev/network-operator/internal/conditions"
"github.com/ironcore-dev/network-operator/internal/deviceutil"
"github.com/ironcore-dev/network-operator/internal/provider"
Expand Down Expand Up @@ -223,12 +222,10 @@ func (r *ISISReconciler) reconcile(ctx context.Context, s *isisScope) (_ ctrl.Re
}
}

c := clientutil.NewClient(r, s.ISIS.Namespace)

var interfaces []provider.ISISInterface
for _, iface := range s.ISIS.Spec.Interfaces {
res := new(v1alpha1.Interface)
if err := c.Get(ctx, client.ObjectKey{Name: iface.Ref.Name}, res); err != nil {
if err := r.Get(ctx, client.ObjectKey{Name: iface.Ref.Name, Namespace: s.ISIS.Namespace}, res); err != nil {
return ctrl.Result{}, err
}

Expand Down
Loading