Skip to content

Commit

Permalink
Ignore IsNotFound errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckal777 committed Mar 27, 2024
1 parent 9938481 commit 456a8ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
14 changes: 10 additions & 4 deletions management/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/sapcc/runtime-extension-maintenance-controller/constants"
"github.com/sapcc/runtime-extension-maintenance-controller/state"
"github.com/sapcc/runtime-extension-maintenance-controller/workload"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
corev1_informers "k8s.io/client-go/informers/core/v1"
clusterv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -50,7 +51,12 @@ type MachineReconciler struct {

func (r *MachineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
var machine clusterv1beta1.Machine
if err := r.Client.Get(ctx, req.NamespacedName, &machine); err != nil {
err := r.Client.Get(ctx, req.NamespacedName, &machine)
if errors.IsNotFound(err) {
r.Log.Info("failed to get machine, was it deleted?", "machine", req.String())
return ctrl.Result{}, nil
}
if err != nil {
return ctrl.Result{}, err
}
clusterName := machine.Spec.ClusterName
Expand All @@ -69,7 +75,7 @@ func (r *MachineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
workloadController, err := makeNodeCtrl(ctx, NodeControllerParamaters{
cluster: clusterKey,
managementClient: r.Client,
log: ctrl.Log.WithName("workload"),
log: ctrl.Log.WithName("workload").WithValues("cluster", clusterKey.String()),
connections: r.ClusterConnections,
workloadCtx: workloadCtx,
})
Expand Down Expand Up @@ -106,7 +112,7 @@ func (r *MachineReconciler) cleanupMachine(ctx context.Context, machine *cluster
if err := r.Client.Patch(ctx, machine, client.MergeFrom(original)); err != nil {
return fmt.Errorf("failed to remove pre-drain hook for machine %s", machine.Name)
}
r.Log.Info("removed pre-drain hook")
r.Log.Info("removed pre-drain hook", "machine", machine.Name, "cluster", cluster)
// cleanup workload node reconciler, if no machine uses maintenance-controller
selector := client.MatchingLabels{
clusterv1beta1.ClusterNameLabel: cluster,
Expand Down Expand Up @@ -172,7 +178,7 @@ func makeNodeCtrl(ctx context.Context, params NodeControllerParamaters) (*worklo
func(ni corev1_informers.NodeInformer) {
err := controller.AttachTo(ni)
if err != nil {
params.log.Error(err, "failed to attach workload node controller to informer", "cluster", params.cluster.String())
params.log.Error(err, "failed to attach workload node controller to informer")
}
},
)
Expand Down
5 changes: 5 additions & 0 deletions workload/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/sapcc/runtime-extension-maintenance-controller/clusters"
"github.com/sapcc/runtime-extension-maintenance-controller/state"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
corev1_informers "k8s.io/client-go/informers/core/v1"
"k8s.io/client-go/tools/cache"
Expand Down Expand Up @@ -131,6 +132,10 @@ 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{Log: c.log, Cluster: c.cluster, Name: req.Name})
if errors.IsNotFound(err) {
c.log.Info("failed to get workload node, was it deleted?", "node", req.Name)
return nil
}
if err != nil {
return err
}
Expand Down

0 comments on commit 456a8ea

Please sign in to comment.