Skip to content

Commit

Permalink
KUBE-194: permissions might not be upgraded yet so silence forbidden …
Browse files Browse the repository at this point in the history
…error (#100)

* permissions might not be upgraded yet so silence forbidden error when patching node/status

* skip node/status patch as Warn

---------

Co-authored-by: Furkhat Kasymov Genii Uulu <[email protected]>
  • Loading branch information
furkhat and Furkhat Kasymov Genii Uulu authored Feb 26, 2024
1 parent 09f5c9c commit 892b653
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion actions/kubernetes_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/cenkalti/backoff/v4"
"github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apitypes "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/strategicpatch"
Expand Down Expand Up @@ -44,9 +45,14 @@ func patchNode(ctx context.Context, clientset kubernetes.Interface, node *v1.Nod
return nil
}

func patchNodeStatus(ctx context.Context, clientset kubernetes.Interface, name string, patch []byte) error {
func patchNodeStatus(ctx context.Context, log logrus.FieldLogger, clientset kubernetes.Interface, name string, patch []byte) error {
err := backoff.Retry(func() error {
_, err := clientset.CoreV1().Nodes().PatchStatus(ctx, name, patch)
if k8serrors.IsForbidden(err) {
// permissions might be of older version that can't patch node/status
log.WithField("node", name).WithError(err).Warn("skip patch node/status")
return nil
}
return err
}, defaultBackoff(ctx))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion actions/patch_node_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (h *patchNodeHandler) Handle(ctx context.Context, action *castai.ClusterAct
if err != nil {
return fmt.Errorf("marshal patch for status: %w", err)
}
return patchNodeStatus(ctx, h.clientset, node.Name, patch)
return patchNodeStatus(ctx, h.log, h.clientset, node.Name, patch)
}
return nil
}
Expand Down

0 comments on commit 892b653

Please sign in to comment.