diff --git a/internal/advertisementoperator/controller.go b/internal/advertisementoperator/controller.go index 7703fd4c97..121524651a 100644 --- a/internal/advertisementoperator/controller.go +++ b/internal/advertisementoperator/controller.go @@ -83,8 +83,8 @@ type AdvertisementReconciler struct { // +kubebuilder:rbac:groups=core,resources=events/status,verbs=get // +kubebuilder:rbac:groups=core,resources=serviceaccounts,verbs=get;list;watch;create;update;patch;delete +// Reconcile reconciles requests occurred on Advertisement objects. func (r *AdvertisementReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - // initialize the checkRemoteCluster map if r.checkRemoteCluster == nil { r.checkRemoteCluster = make(map[string]*sync.Once) diff --git a/internal/crdReplicator/crdReplicator-operator.go b/internal/crdReplicator/crdReplicator-operator.go index dcbaea1185..3e92672144 100644 --- a/internal/crdReplicator/crdReplicator-operator.go +++ b/internal/crdReplicator/crdReplicator-operator.go @@ -72,6 +72,7 @@ type Controller struct { // +kubebuilder:rbac:groups=core,namespace="do-not-care",resources=secrets,verbs=get;list // +kubebuilder:rbac:groups=core,namespace="do-not-care",resources=configmaps,verbs=get;list +// Reconcile handles requests for subscribed types of object. func (c *Controller) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { var fc v1alpha1.ForeignCluster c.StartWatchers() diff --git a/internal/discovery/foreign-cluster-operator/foreign-cluster-controller.go b/internal/discovery/foreign-cluster-operator/foreign-cluster-controller.go index b1285f91ec..58f95b6136 100644 --- a/internal/discovery/foreign-cluster-operator/foreign-cluster-controller.go +++ b/internal/discovery/foreign-cluster-operator/foreign-cluster-controller.go @@ -107,6 +107,7 @@ type ForeignClusterReconciler struct { // +kubebuilder:rbac:groups=rbac.authorization.k8s.io,namespace="liqo",resources=rolebindings,verbs=get;create // Reconcile reconciles ForeignCluster resources. +// nolint:gocyclo // (palexster): Suppressing for now, it will part of a major refactoring before v0.3 func (r *ForeignClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { klog.V(4).Infof("Reconciling ForeignCluster %s", req.Name) diff --git a/internal/liqonet/route-operator/route-operator.go b/internal/liqonet/route-operator/route-operator.go index e289e26d2c..2dbc29b616 100644 --- a/internal/liqonet/route-operator/route-operator.go +++ b/internal/liqonet/route-operator/route-operator.go @@ -115,6 +115,7 @@ func NewRouteController(mgr ctrl.Manager, wgc wireguard.Client, nl wireguard.Net // +kubebuilder:rbac:groups=core,namespace="do-not-care",resources=pods,verbs=update;patch;get;list;watch // +kubebuilder:rbac:groups=core,namespace="do-not-care",resources=services,verbs=update;patch;get;list;watch +// Reconcile handle requests on TunnelEndpoint object to create and configure routes on Nodes. func (r *RouteController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { var tep netv1alpha1.TunnelEndpoint // name of our finalizer @@ -138,7 +139,7 @@ func (r *RouteController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl // The object is not being deleted, so if it does not have our finalizer, // then lets add the finalizer and update the object. This is equivalent // registering our finalizer. - tep.ObjectMeta.Finalizers = append(tep.Finalizers, routeOperatorFinalizer) + tep.ObjectMeta.Finalizers = append(tep.ObjectMeta.Finalizers, routeOperatorFinalizer) if err := r.Update(ctx, &tep); err != nil { klog.Errorf("%s -> unable to add finalizers to resource %s: %s", clusterID, req.String(), err) return result, err @@ -196,19 +197,21 @@ func (r *RouteController) SetupWithManager(mgr ctrl.Manager) error { // SetupSignalHandlerForRouteOperator registers for SIGTERM, SIGINT. A stop channel is returned // which is closed on one of these signals. -func (r *RouteController) SetupSignalHandlerForRouteOperator() (stopCh <-chan struct{}) { - stop := make(chan struct{}) +func (r *RouteController) SetupSignalHandlerForRouteOperator() context.Context { + ctx, done := context.WithCancel(context.Background()) c := make(chan os.Signal, 1) signal.Notify(c, utils.ShutdownSignals...) go func(r *RouteController) { <-c r.deleteOverlayIFace() - close(stop) + done() }(r) - return stop + return ctx } -func (r *RouteController) Watcher(sharedDynFactory dynamicinformer.DynamicSharedInformerFactory, resourceType schema.GroupVersionResource, handlerFuncs cache.ResourceEventHandlerFuncs, stopCh chan struct{}) { +// Watcher initializes a dynamic informer for a resourceType passed as parameter with the handlerFuncs passed as parameters. +func (r *RouteController) Watcher(sharedDynFactory dynamicinformer.DynamicSharedInformerFactory, + resourceType schema.GroupVersionResource, handlerFuncs cache.ResourceEventHandlerFuncs, stopCh chan struct{}) { klog.Infof("starting watcher for %s", resourceType.String()) dynInformer := sharedDynFactory.ForResource(resourceType) // adding handlers to the informer diff --git a/internal/liqonet/tunnel-operator/tunnel-operator.go b/internal/liqonet/tunnel-operator/tunnel-operator.go index 72fe752985..0887599a93 100644 --- a/internal/liqonet/tunnel-operator/tunnel-operator.go +++ b/internal/liqonet/tunnel-operator/tunnel-operator.go @@ -81,7 +81,7 @@ type TunnelController struct { // +kubebuilder:rbac:groups=core,namespace="do-not-care",resources=services,verbs=get;list;watch;update // +kubebuilder:rbac:groups=core,namespace="do-not-care",resources=pods,verbs=get;list;watch;update -// Instantiates and initializes the tunnel controller. +// NewTunnelController instantiates and initializes the tunnel controller. func NewTunnelController(mgr ctrl.Manager, wgc wireguard.Client, nl wireguard.Netlinker) (*TunnelController, error) { clientSet := k8s.NewForConfigOrDie(mgr.GetConfig()) namespace, err := utils.GetPodNamespace() @@ -141,6 +141,7 @@ func NewTunnelController(mgr ctrl.Manager, wgc wireguard.Client, nl wireguard.Ne return tc, nil } +// Reconcile reconciles requests occurred on TunnelEndpoint objects. func (tc *TunnelController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { if !tc.isConfigured { <-tc.configChan @@ -301,8 +302,8 @@ func (tc *TunnelController) EnsureIPTablesRulesPerCluster(tep *netv1alpha1.Tunne // SetupSignalHandlerForRouteOperator registers for SIGTERM, SIGINT, SIGKILL. A stop channel is returned // which is closed on one of these signals. -func (tc *TunnelController) SetupSignalHandlerForTunnelOperator() (stopCh <-chan struct{}) { - stop := make(chan struct{}) +func (tc *TunnelController) SetupSignalHandlerForTunnelOperator() context.Context { + ctx, done := context.WithCancel(context.Background()) c := make(chan os.Signal, 1) signal.Notify(c, utils.ShutdownSignals...) go func(r *TunnelController) { @@ -312,9 +313,9 @@ func (tc *TunnelController) SetupSignalHandlerForTunnelOperator() (stopCh <-chan close(tc.stopPWChan) r.RemoveAllTunnels() <-c - close(stop) + done() }(tc) - return stop + return ctx } func (tc *TunnelController) SetupWithManager(mgr ctrl.Manager) error { diff --git a/internal/peering-request-operator/peering-request-controller.go b/internal/peering-request-operator/peering-request-controller.go index a89b73d72a..ed3700a65e 100644 --- a/internal/peering-request-operator/peering-request-controller.go +++ b/internal/peering-request-operator/peering-request-controller.go @@ -60,6 +60,7 @@ type PeeringRequestReconciler struct { // +kubebuilder:rbac:groups=core,namespace="liqo",resources=configmaps,verbs=get;list;watch;create;update // +kubebuilder:rbac:groups=core,namespace="liqo",resources=secrets,verbs=get;patch;create +// Reconcile reconciles requests occurred on PeeringRequest objects. func (r *PeeringRequestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { klog.Info("Reconciling PeeringRequest " + req.Name) diff --git a/internal/resource-request-operator/resourceRequest_controller.go b/internal/resource-request-operator/resourceRequest_controller.go index 6659fcd381..1cb48490de 100644 --- a/internal/resource-request-operator/resourceRequest_controller.go +++ b/internal/resource-request-operator/resourceRequest_controller.go @@ -40,7 +40,6 @@ const ( // Reconcile is the main function of the controller which reconciles ResourceRequest resources. func (r *ResourceRequestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - var resourceRequest discoveryv1alpha1.ResourceRequest err := r.Get(ctx, req.NamespacedName, &resourceRequest) if err != nil { diff --git a/pkg/liqonet/ipam_test.go b/pkg/liqonet/ipam_test.go index 96215961e9..721821013c 100644 --- a/pkg/liqonet/ipam_test.go +++ b/pkg/liqonet/ipam_test.go @@ -4,10 +4,13 @@ import ( . "github.com/onsi/ginkgo" "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/dynamic" "k8s.io/client-go/dynamic/fake" "github.com/liqotech/liqo/pkg/liqonet" + + liqonetapi "github.com/liqotech/liqo/apis/net/v1alpha1" ) var ipam *liqonet.IPAM @@ -43,7 +46,20 @@ func fillNetworkPool(pool string, ipam *liqonet.IPAM) error { var _ = Describe("Ipam", func() { BeforeEach(func() { - dynClient = fake.NewSimpleDynamicClient(runtime.NewScheme()) + scheme := runtime.NewScheme() + scheme.AddKnownTypeWithName(schema.GroupVersionKind{ + Group: "net.liqo.io", + Version: "v1alpha1", + Kind: "ipamstorages", + }, &liqonetapi.IpamStorage{}) + s := schema.GroupVersionResource{ + Group: "net.liqo.io", + Version: "v1alpha1", + Resource: "ipamstorages", + } + var m = make(map[schema.GroupVersionResource]string) + m[s] = "ipamstoragesList" + dynClient = fake.NewSimpleDynamicClientWithCustomListKinds(scheme, m, &liqonetapi.IpamStorage{}) ipam = liqonet.NewIPAM() err := ipam.Init(liqonet.Pools, dynClient) gomega.Expect(err).To(gomega.BeNil()) diff --git a/pkg/virtualKubelet/node/module/api/exec.go b/pkg/virtualKubelet/node/module/api/exec.go index e0c98ea122..f0cfb9c9b0 100644 --- a/pkg/virtualKubelet/node/module/api/exec.go +++ b/pkg/virtualKubelet/node/module/api/exec.go @@ -163,9 +163,9 @@ type containerExecContext struct { ctx context.Context } -// ExecInContainer Implements remotecommand.Executor -// This is called by remotecommand.ServeExec. -func (c *containerExecContext) ExecInContainer(name string, uid types.UID, container string, cmd []string, in io.Reader, out, err io.WriteCloser, tty bool, resize <-chan remotecommandclient.TerminalSize, timeout time.Duration) error { +// ExecInContainer Implements remotecommand.Executor. This is called by remotecommand.ServeExec. +func (c *containerExecContext) ExecInContainer(name string, uid types.UID, container string, cmd []string, + in io.Reader, out, err io.WriteCloser, tty bool, resize <-chan remotecommandclient.TerminalSize, timeout time.Duration) error { eio := &execIO{ tty: tty, stdin: in, diff --git a/pkg/virtualKubelet/node/module/node.go b/pkg/virtualKubelet/node/module/node.go index e313b8ad6a..404ed17fa7 100644 --- a/pkg/virtualKubelet/node/module/node.go +++ b/pkg/virtualKubelet/node/module/node.go @@ -39,7 +39,7 @@ import ( // // Note: Implementers can choose to manage a node themselves, in which case // it is not needed to provide an implementation for this interface. -type NodeProvider interface { //nolint:golint +type NodeProvider interface { // Ping checks if the node is still active. // This is intended to be lightweight as it will be called periodically as a // heartbeat to keep the node marked as ready in Kubernetes. @@ -74,7 +74,7 @@ func NewNodeController(p NodeProvider, node *corev1.Node, nodes v1.NodeInterface } // NodeControllerOpt are the functional options used for configuring a node. -type NodeControllerOpt func(*NodeController) error // nolint:golint +type NodeControllerOpt func(*NodeController) error // WithNodeEnableLeaseV1Beta1 enables support for v1beta1 leases. // If client is nil, leases will not be enabled. @@ -142,7 +142,7 @@ type ErrorHandler func(context.Context, error) error // NodeController deals with creating and managing a node object in Kubernetes. // It can register a node with Kubernetes and periodically update its status. // NodeController manages a single node entity. -type NodeController struct { // nolint: golint +type NodeController struct { p NodeProvider n *corev1.Node diff --git a/pkg/virtualKubelet/provider/node.go b/pkg/virtualKubelet/provider/node.go index f4f99e54e9..13f8721a2f 100644 --- a/pkg/virtualKubelet/provider/node.go +++ b/pkg/virtualKubelet/provider/node.go @@ -11,7 +11,7 @@ import ( ) func (p *LiqoProvider) ConfigureNode(ctx context.Context, n *v1.Node) { - _, span := trace.StartSpan(ctx, "kubernetes.ConfigureNode") //nolint:ineffassign + _, span := trace.StartSpan(ctx, "kubernetes.ConfigureNode") defer span.End() n.Status.Capacity = v1.ResourceList{} diff --git a/test/unit/advertisement-operator/broadcaster_test.go b/test/unit/advertisement-operator/broadcaster_test.go index f6cfcffd71..0cb14d9d2d 100644 --- a/test/unit/advertisement-operator/broadcaster_test.go +++ b/test/unit/advertisement-operator/broadcaster_test.go @@ -4,12 +4,11 @@ import ( "context" "fmt" - "github.com/liqotech/liqo/internal/advertisementoperator/broadcaster" - configv1alpha1 "github.com/liqotech/liqo/apis/config/v1alpha1" discoveryv1alpha1 "github.com/liqotech/liqo/apis/discovery/v1alpha1" advtypes "github.com/liqotech/liqo/apis/sharing/v1alpha1" advop "github.com/liqotech/liqo/internal/advertisementoperator" + "github.com/liqotech/liqo/internal/advertisementoperator/broadcaster" liqoconst "github.com/liqotech/liqo/pkg/consts" crdclient "github.com/liqotech/liqo/pkg/crdClient" @@ -215,8 +214,11 @@ func TestGetClusterResources(t *testing.T) { sumM := sum.DeepCopy() sumM.SetScaled(sumM.Value(), resource.Mega) res, images2 := broadcaster.GetClusterResources(pNodes.Items) + //q.Format = resource.BinarySI + q := resource.Quantity{} + q.Format = resource.BinarySI - assert.Empty(t, res.StorageEphemeral(), "StorageEphemeral was not set so it should be null") + assert.Equal(t, &q, res.StorageEphemeral(), "StorageEphemeral was not set so it should be null") assert.Equal(t, *res.Cpu(), sum) assert.Equal(t, *res.Memory(), sumM) assert.Equal(t, *res.Pods(), sum)