diff --git a/controllers/fenceagentsremediation_controller.go b/controllers/fenceagentsremediation_controller.go index c4faea8c..46224873 100644 --- a/controllers/fenceagentsremediation_controller.go +++ b/controllers/fenceagentsremediation_controller.go @@ -22,6 +22,7 @@ import ( "fmt" "github.com/go-logr/logr" + commonAnnotations "github.com/medik8s/common/pkg/annotations" apiErrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" @@ -35,6 +36,7 @@ import ( ) const ( + // errors errorMissingParams = "nodeParameters or sharedParameters or both are missing, and they cannot be empty" errorMissingNodeParams = "node parameter is required, and cannot be empty" SuccessFAResponse = "Success: Rebooted" @@ -103,6 +105,13 @@ func (r *FenceAgentsRemediationReconciler) Reconcile(ctx context.Context, req ct return emptyResult, nil } + // Check NHC timeout annotation + if isTimedOutByNHC(far) { + r.Log.Info("FAR remediation was stopped by Node Healthcheck Operator") + // TODO: update status and return its error + return emptyResult, nil + } + // Add finalizer when the CR is created if !controllerutil.ContainsFinalizer(far, v1alpha1.FARFinalizer) && far.ObjectMeta.DeletionTimestamp.IsZero() { controllerutil.AddFinalizer(far, v1alpha1.FARFinalizer) @@ -176,6 +185,15 @@ func (r *FenceAgentsRemediationReconciler) Reconcile(ctx context.Context, req ct return emptyResult, nil } +// isTimedOutByNHC checks if NHC set a timeout annotation on the CR +func isTimedOutByNHC(far *v1alpha1.FenceAgentsRemediation) bool { + if far != nil && far.Annotations != nil && far.DeletionTimestamp == nil { + _, isTimeoutIssued := far.Annotations[commonAnnotations.NhcTimedOut] + return isTimeoutIssued + } + return false +} + // buildFenceAgentParams collects the FAR's parameters for the node based on FAR CR, and if the CR is missing parameters // or the CR's name don't match nodeParamter name or it has an action which is different than reboot, then return an error func buildFenceAgentParams(far *v1alpha1.FenceAgentsRemediation) ([]string, error) { diff --git a/go.mod b/go.mod index e8f33ed2..33571c84 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/go-logr/logr v1.2.4 - github.com/medik8s/common v1.2.0 + github.com/medik8s/common v1.7.0 github.com/onsi/ginkgo/v2 v2.11.0 github.com/onsi/gomega v1.27.8 github.com/openshift/api v0.0.0-20230621174358-ea40115b9fa6 diff --git a/go.sum b/go.sum index 6a7a8d03..6aa52862 100644 --- a/go.sum +++ b/go.sum @@ -97,8 +97,8 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0 github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= -github.com/medik8s/common v1.2.0 h1:xgQOijD3rEn+PfCd4lJuV3WFdt5QA6SIaqF01rRp2as= -github.com/medik8s/common v1.2.0/go.mod h1:ZT/3hfMXJLmZEcqmxRWB5LGC8Wl+qKGGQ4zM8hOE7PY= +github.com/medik8s/common v1.7.0 h1:JwimhWigPTAszGG2jYJmh+uVHq2nFUPRRljw7ZhlQhg= +github.com/medik8s/common v1.7.0/go.mod h1:ZT/3hfMXJLmZEcqmxRWB5LGC8Wl+qKGGQ4zM8hOE7PY= github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8= github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= diff --git a/vendor/github.com/medik8s/common/pkg/annotations/annotations.go b/vendor/github.com/medik8s/common/pkg/annotations/annotations.go new file mode 100644 index 00000000..739e694f --- /dev/null +++ b/vendor/github.com/medik8s/common/pkg/annotations/annotations.go @@ -0,0 +1,6 @@ +package annotations + +const ( + // NhcTimeOut is the annotation set by NHC to signal the operator that it surpassed its timeout and shall stop its remediation + NhcTimedOut = "remediation.medik8s.io/nhc-timed-out" +) diff --git a/vendor/modules.txt b/vendor/modules.txt index 67415dff..6b199f8f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -92,8 +92,9 @@ github.com/mailru/easyjson/jwriter # github.com/matttproud/golang_protobuf_extensions v1.0.4 ## explicit; go 1.9 github.com/matttproud/golang_protobuf_extensions/pbutil -# github.com/medik8s/common v1.2.0 +# github.com/medik8s/common v1.7.0 ## explicit; go 1.20 +github.com/medik8s/common/pkg/annotations github.com/medik8s/common/pkg/labels # github.com/moby/spdystream v0.2.0 ## explicit; go 1.13