Skip to content

Commit

Permalink
Log workload cluster re-authentications
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckal777 committed Mar 27, 2024
1 parent 6e1afda commit 74bd433
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions clusters/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"sync"
"time"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -141,6 +142,7 @@ func (cc *Connections) DeleteConn(cluster types.NamespacedName) {
}

type GetNodeParams struct {
Log logr.Logger
Cluster types.NamespacedName
Name string
}
Expand All @@ -157,7 +159,7 @@ func (cc *Connections) GetNode(ctx context.Context, params GetNodeParams) (*core
if !errors.IsUnauthorized(err) {
return nil, err
}
// auth expired recreate conn
params.Log.Info("authentication expired, trying reauth", "cluster", params.Cluster)
workloadClient, err := MakeClient(ctx, cc.managementClient, types.NamespacedName{})
if err != nil {
return nil, err
Expand All @@ -169,6 +171,7 @@ func (cc *Connections) GetNode(ctx context.Context, params GetNodeParams) (*core
}

type PatchNodeParams struct {
Log logr.Logger
Cluster types.NamespacedName
Name string
MergePatch []byte
Expand All @@ -192,7 +195,7 @@ func (cc *Connections) PatchNode(ctx context.Context, params PatchNodeParams) er
if !errors.IsUnauthorized(err) {
return err
}
// auth expired recreate conn
params.Log.Info("authentication expired, trying reauth", "cluster", params.Cluster)
workloadClient, err := MakeClient(ctx, cc.managementClient, types.NamespacedName{})
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion management/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (r *MachineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
return ctrl.Result{}, nil
}
nodeName := machine.Status.NodeRef.Name
node, err := r.ClusterConnections.GetNode(ctx, clusters.GetNodeParams{Cluster: clusterKey, Name: nodeName})
node, err := r.ClusterConnections.GetNode(ctx, clusters.GetNodeParams{Log: r.Log, Cluster: clusterKey, Name: nodeName})
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to get node %s in workload cluster %s node: %w", nodeName, clusterName, err)
}
Expand Down
1 change: 1 addition & 0 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (r *Reconciler) PatchState(ctx context.Context, machine *clusterv1beta1.Mac
return err
}
patchParams := clusters.PatchNodeParams{
Log: r.Log,
Cluster: r.Cluster,
Name: node.Name,
MergePatch: patch,
Expand Down
2 changes: 1 addition & 1 deletion workload/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (c *NodeController) Run(ctx context.Context) {
}

func (c *NodeController) Reconcile(ctx context.Context, req ctrl.Request) error {
node, err := c.connections.GetNode(ctx, clusters.GetNodeParams{Cluster: c.cluster, Name: req.Name})
node, err := c.connections.GetNode(ctx, clusters.GetNodeParams{Log: c.log, Cluster: c.cluster, Name: req.Name})
if err != nil {
return err
}
Expand Down

0 comments on commit 74bd433

Please sign in to comment.