Merge pull request #121065 from byako/issue121063

DRA: notify ResourceClaim or ResourceClass of params error
This commit is contained in:
Kubernetes Prow Robot 2023-10-30 22:41:41 +01:00 committed by GitHub
commit 4106366b6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 10 deletions

View File

@ -94,7 +94,7 @@ type Driver interface {
// If selectedNode is set, the driver must attempt to allocate for that
// node. If that is not possible, it must return an error. The
// controller will call UnsuitableNodes and pass the new information to
// the scheduler, which then will lead to selecting a diffent node
// the scheduler, which then will lead to selecting a different node
// if the current one is not suitable.
//
// The Claim, ClaimParameters, Class, ClassParameters fields of "claims" parameter
@ -357,7 +357,6 @@ func (ctrl *controller) Run(workers int) {
var errRequeue = errors.New("requeue")
// errPeriodic is a special error instance that functions can return
// to request silent instance that functions can return
// to request silent retrying at a fixed rate.
var errPeriodic = errors.New("periodic")
@ -536,8 +535,9 @@ func (ctrl *controller) syncClaim(ctx context.Context, claim *resourcev1alpha2.R
return errRequeue
}
// Check parameters.
claimParameters, classParameters, err := ctrl.getParameters(ctx, claim, class)
// Check parameters. Do not record event to Claim if its parameters are invalid,
// syncKey will record the error.
claimParameters, classParameters, err := ctrl.getParameters(ctx, claim, class, false)
if err != nil {
return err
}
@ -558,14 +558,18 @@ func (ctrl *controller) syncClaim(ctx context.Context, claim *resourcev1alpha2.R
return nil
}
func (ctrl *controller) getParameters(ctx context.Context, claim *resourcev1alpha2.ResourceClaim, class *resourcev1alpha2.ResourceClass) (claimParameters, classParameters interface{}, err error) {
func (ctrl *controller) getParameters(ctx context.Context, claim *resourcev1alpha2.ResourceClaim, class *resourcev1alpha2.ResourceClass, notifyClaim bool) (claimParameters, classParameters interface{}, err error) {
classParameters, err = ctrl.driver.GetClassParameters(ctx, class)
if err != nil {
ctrl.eventRecorder.Event(class, v1.EventTypeWarning, "Failed", err.Error())
err = fmt.Errorf("class parameters %s: %v", class.ParametersRef, err)
return
}
claimParameters, err = ctrl.driver.GetClaimParameters(ctx, claim, class, classParameters)
if err != nil {
if notifyClaim {
ctrl.eventRecorder.Event(claim, v1.EventTypeWarning, "Failed", err.Error())
}
err = fmt.Errorf("claim parameters %s: %v", claim.Spec.ParametersRef, err)
return
}
@ -688,9 +692,10 @@ func (ctrl *controller) checkPodClaim(ctx context.Context, pod *v1.Pod, podClaim
if class.DriverName != ctrl.name {
return nil, nil
}
// Check parameters.
claimParameters, classParameters, err := ctrl.getParameters(ctx, claim, class)
// Check parameters. Record event to claim and pod if parameters are invalid.
claimParameters, classParameters, err := ctrl.getParameters(ctx, claim, class, true)
if err != nil {
ctrl.eventRecorder.Event(pod, v1.EventTypeWarning, "Failed", fmt.Sprintf("claim %v: %v", claim.Name, err.Error()))
return nil, err
}
return &ClaimAllocation{

View File

@ -482,7 +482,7 @@ const _ = grpc.SupportPackageIsVersion4
type NodeClient interface {
// NodePrepareResources prepares several ResourceClaims
// for use on the node. If an error is returned, the
// response is ignored. Failures for individidual claims
// response is ignored. Failures for individual claims
// can be reported inside NodePrepareResourcesResponse.
NodePrepareResources(ctx context.Context, in *NodePrepareResourcesRequest, opts ...grpc.CallOption) (*NodePrepareResourcesResponse, error)
// NodeUnprepareResources is the opposite of NodePrepareResources.
@ -520,7 +520,7 @@ func (c *nodeClient) NodeUnprepareResources(ctx context.Context, in *NodeUnprepa
type NodeServer interface {
// NodePrepareResources prepares several ResourceClaims
// for use on the node. If an error is returned, the
// response is ignored. Failures for individidual claims
// response is ignored. Failures for individual claims
// can be reported inside NodePrepareResourcesResponse.
NodePrepareResources(context.Context, *NodePrepareResourcesRequest) (*NodePrepareResourcesResponse, error)
// NodeUnprepareResources is the opposite of NodePrepareResources.

View File

@ -34,7 +34,7 @@ option (gogoproto.goproto_unrecognized_all) = false;
service Node {
// NodePrepareResources prepares several ResourceClaims
// for use on the node. If an error is returned, the
// response is ignored. Failures for individidual claims
// response is ignored. Failures for individual claims
// can be reported inside NodePrepareResourcesResponse.
rpc NodePrepareResources (NodePrepareResourcesRequest)
returns (NodePrepareResourcesResponse) {}