From f0c15745744304583868f53ef17c20cb19d5afad Mon Sep 17 00:00:00 2001 From: Jeremy Clerc Date: Wed, 4 Mar 2026 10:51:38 +0100 Subject: [PATCH] Rename close hook as terminate hook It has been decided that terminate had a better explanatory intent. --- .../applicationdisruptionbudget_types.go | 2 +- app_manager_openapi.yml | 4 +- .../applicationdisruptionbudget-crd.yaml | 2 +- ...iteo.com_applicationdisruptionbudgets.yaml | 2 +- .../disruption/close_disruption_parameters.go | 153 ---------------- .../disruption/close_disruption_responses.go | 172 ------------------ .../appmgrcli/disruption/disruption_client.go | 36 ++-- .../terminate_disruption_parameters.go | 153 ++++++++++++++++ .../terminate_disruption_responses.go | 172 ++++++++++++++++++ .../applicationdisruptionbudget_controller.go | 4 +- internal/controller/budget.go | 6 +- internal/controller/budget_test.go | 2 +- .../controller/nodedisruption_controller.go | 20 +- .../nodedisruption_controller_test.go | 4 +- .../nodedisruptionbudget_controller.go | 2 +- 15 files changed, 367 insertions(+), 367 deletions(-) delete mode 100644 internal/appmgrcli/disruption/close_disruption_parameters.go delete mode 100644 internal/appmgrcli/disruption/close_disruption_responses.go create mode 100644 internal/appmgrcli/disruption/terminate_disruption_parameters.go create mode 100644 internal/appmgrcli/disruption/terminate_disruption_responses.go diff --git a/api/v1alpha1/applicationdisruptionbudget_types.go b/api/v1alpha1/applicationdisruptionbudget_types.go index 09ac061..51fe9f0 100644 --- a/api/v1alpha1/applicationdisruptionbudget_types.go +++ b/api/v1alpha1/applicationdisruptionbudget_types.go @@ -44,7 +44,7 @@ type ApplicationDisruptionBudgetSpec struct { // +kubebuilder:validation:Optional HealthHook HookSpec `json:"healthHook,omitempty"` - // HookV2BasePath holds the base path for the prepare, ready, cancel hooks that will be + // HookV2BasePath holds the base path for the prepare, ready, terminate hooks that will be // called at different stages of the NodeDisruption lifecycle. // A POST http request containing a Disruption that is being reconciled is sent ot each of the hooks. // +kubebuilder:validation:Optional diff --git a/app_manager_openapi.yml b/app_manager_openapi.yml index fbbc48b..ca550d5 100644 --- a/app_manager_openapi.yml +++ b/app_manager_openapi.yml @@ -128,10 +128,10 @@ paths: $ref: '#/responses/RetryAfter' default: $ref: '#/responses/UnexpectedError' - /close: + /terminate: post: summary: Notify the end of a disruption if the application needs to unprepare. - operationId: closeDisruption + operationId: terminateDisruption tags: - disruption consumes: diff --git a/chart/templates/applicationdisruptionbudget-crd.yaml b/chart/templates/applicationdisruptionbudget-crd.yaml index 4a0760f..946f74b 100644 --- a/chart/templates/applicationdisruptionbudget-crd.yaml +++ b/chart/templates/applicationdisruptionbudget-crd.yaml @@ -72,7 +72,7 @@ spec: type: object hookV2BasePath: description: |- - HookV2BasePath holds the base path for the prepare, ready, cancel hooks that will be + HookV2BasePath holds the base path for the prepare, ready, terminate hooks that will be called at different stages of the NodeDisruption lifecycle. A POST http request containing a Disruption that is being reconciled is sent ot each of the hooks. properties: diff --git a/config/crd/bases/nodedisruption.criteo.com_applicationdisruptionbudgets.yaml b/config/crd/bases/nodedisruption.criteo.com_applicationdisruptionbudgets.yaml index f81d12d..15a1e6f 100644 --- a/config/crd/bases/nodedisruption.criteo.com_applicationdisruptionbudgets.yaml +++ b/config/crd/bases/nodedisruption.criteo.com_applicationdisruptionbudgets.yaml @@ -71,7 +71,7 @@ spec: type: object hookV2BasePath: description: |- - HookV2BasePath holds the base path for the prepare, ready, cancel hooks that will be + HookV2BasePath holds the base path for the prepare, ready, terminate hooks that will be called at different stages of the NodeDisruption lifecycle. A POST http request containing a Disruption that is being reconciled is sent ot each of the hooks. properties: diff --git a/internal/appmgrcli/disruption/close_disruption_parameters.go b/internal/appmgrcli/disruption/close_disruption_parameters.go deleted file mode 100644 index a0210e4..0000000 --- a/internal/appmgrcli/disruption/close_disruption_parameters.go +++ /dev/null @@ -1,153 +0,0 @@ -// Code generated by go-swagger; DO NOT EDIT. - -package disruption - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -import ( - "context" - "net/http" - "time" - - "github.com/go-openapi/errors" - "github.com/go-openapi/runtime" - cr "github.com/go-openapi/runtime/client" - "github.com/go-openapi/strfmt" - - "github.com/criteo/node-disruption-controller/internal/appmgr" -) - -// NewCloseDisruptionParams creates a new CloseDisruptionParams object, -// with the default timeout for this client. -// -// Default values are not hydrated, since defaults are normally applied by the API server side. -// -// To enforce default values in parameter, use SetDefaults or WithDefaults. -func NewCloseDisruptionParams() *CloseDisruptionParams { - return &CloseDisruptionParams{ - timeout: cr.DefaultTimeout, - } -} - -// NewCloseDisruptionParamsWithTimeout creates a new CloseDisruptionParams object -// with the ability to set a timeout on a request. -func NewCloseDisruptionParamsWithTimeout(timeout time.Duration) *CloseDisruptionParams { - return &CloseDisruptionParams{ - timeout: timeout, - } -} - -// NewCloseDisruptionParamsWithContext creates a new CloseDisruptionParams object -// with the ability to set a context for a request. -func NewCloseDisruptionParamsWithContext(ctx context.Context) *CloseDisruptionParams { - return &CloseDisruptionParams{ - Context: ctx, - } -} - -// NewCloseDisruptionParamsWithHTTPClient creates a new CloseDisruptionParams object -// with the ability to set a custom HTTPClient for a request. -func NewCloseDisruptionParamsWithHTTPClient(client *http.Client) *CloseDisruptionParams { - return &CloseDisruptionParams{ - HTTPClient: client, - } -} - -/* -CloseDisruptionParams contains all the parameters to send to the API endpoint - - for the close disruption operation. - - Typically these are written to a http.Request. -*/ -type CloseDisruptionParams struct { - - /* Body. - - Disruption - */ - Body *appmgr.Disruption - - timeout time.Duration - Context context.Context - HTTPClient *http.Client -} - -// WithDefaults hydrates default values in the close disruption params (not the query body). -// -// All values with no default are reset to their zero value. -func (o *CloseDisruptionParams) WithDefaults() *CloseDisruptionParams { - o.SetDefaults() - return o -} - -// SetDefaults hydrates default values in the close disruption params (not the query body). -// -// All values with no default are reset to their zero value. -func (o *CloseDisruptionParams) SetDefaults() { - // no default values defined for this parameter -} - -// WithTimeout adds the timeout to the close disruption params -func (o *CloseDisruptionParams) WithTimeout(timeout time.Duration) *CloseDisruptionParams { - o.SetTimeout(timeout) - return o -} - -// SetTimeout adds the timeout to the close disruption params -func (o *CloseDisruptionParams) SetTimeout(timeout time.Duration) { - o.timeout = timeout -} - -// WithContext adds the context to the close disruption params -func (o *CloseDisruptionParams) WithContext(ctx context.Context) *CloseDisruptionParams { - o.SetContext(ctx) - return o -} - -// SetContext adds the context to the close disruption params -func (o *CloseDisruptionParams) SetContext(ctx context.Context) { - o.Context = ctx -} - -// WithHTTPClient adds the HTTPClient to the close disruption params -func (o *CloseDisruptionParams) WithHTTPClient(client *http.Client) *CloseDisruptionParams { - o.SetHTTPClient(client) - return o -} - -// SetHTTPClient adds the HTTPClient to the close disruption params -func (o *CloseDisruptionParams) SetHTTPClient(client *http.Client) { - o.HTTPClient = client -} - -// WithBody adds the body to the close disruption params -func (o *CloseDisruptionParams) WithBody(body *appmgr.Disruption) *CloseDisruptionParams { - o.SetBody(body) - return o -} - -// SetBody adds the body to the close disruption params -func (o *CloseDisruptionParams) SetBody(body *appmgr.Disruption) { - o.Body = body -} - -// WriteToRequest writes these params to a swagger request -func (o *CloseDisruptionParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { - - if err := r.SetTimeout(o.timeout); err != nil { - return err - } - var res []error - if o.Body != nil { - if err := r.SetBodyParam(o.Body); err != nil { - return err - } - } - - if len(res) > 0 { - return errors.CompositeValidationError(res...) - } - return nil -} diff --git a/internal/appmgrcli/disruption/close_disruption_responses.go b/internal/appmgrcli/disruption/close_disruption_responses.go deleted file mode 100644 index 6bfaa44..0000000 --- a/internal/appmgrcli/disruption/close_disruption_responses.go +++ /dev/null @@ -1,172 +0,0 @@ -// Code generated by go-swagger; DO NOT EDIT. - -package disruption - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -import ( - "encoding/json" - stderrors "errors" - "fmt" - "io" - - "github.com/go-openapi/runtime" - "github.com/go-openapi/strfmt" - - "github.com/criteo/node-disruption-controller/internal/appmgr" -) - -// CloseDisruptionReader is a Reader for the CloseDisruption structure. -type CloseDisruptionReader struct { - formats strfmt.Registry -} - -// ReadResponse reads a server response into the received o. -func (o *CloseDisruptionReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { - switch response.Code() { - case 200: - result := NewCloseDisruptionOK() - if err := result.readResponse(response, consumer, o.formats); err != nil { - return nil, err - } - return result, nil - default: - result := NewCloseDisruptionDefault(response.Code()) - if err := result.readResponse(response, consumer, o.formats); err != nil { - return nil, err - } - if response.Code()/100 == 2 { - return result, nil - } - return nil, result - } -} - -// NewCloseDisruptionOK creates a CloseDisruptionOK with default headers values -func NewCloseDisruptionOK() *CloseDisruptionOK { - return &CloseDisruptionOK{} -} - -/* -CloseDisruptionOK describes a response with status code 200, with default header values. - -Acknowledged. -*/ -type CloseDisruptionOK struct { -} - -// IsSuccess returns true when this close disruption o k response has a 2xx status code -func (o *CloseDisruptionOK) IsSuccess() bool { - return true -} - -// IsRedirect returns true when this close disruption o k response has a 3xx status code -func (o *CloseDisruptionOK) IsRedirect() bool { - return false -} - -// IsClientError returns true when this close disruption o k response has a 4xx status code -func (o *CloseDisruptionOK) IsClientError() bool { - return false -} - -// IsServerError returns true when this close disruption o k response has a 5xx status code -func (o *CloseDisruptionOK) IsServerError() bool { - return false -} - -// IsCode returns true when this close disruption o k response a status code equal to that given -func (o *CloseDisruptionOK) IsCode(code int) bool { - return code == 200 -} - -// Code gets the status code for the close disruption o k response -func (o *CloseDisruptionOK) Code() int { - return 200 -} - -func (o *CloseDisruptionOK) Error() string { - return fmt.Sprintf("[POST /close][%d] closeDisruptionOK", 200) -} - -func (o *CloseDisruptionOK) String() string { - return fmt.Sprintf("[POST /close][%d] closeDisruptionOK", 200) -} - -func (o *CloseDisruptionOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { - - return nil -} - -// NewCloseDisruptionDefault creates a CloseDisruptionDefault with default headers values -func NewCloseDisruptionDefault(code int) *CloseDisruptionDefault { - return &CloseDisruptionDefault{ - _statusCode: code, - } -} - -/* -CloseDisruptionDefault describes a response with status code -1, with default header values. - -Unexpected error -*/ -type CloseDisruptionDefault struct { - _statusCode int - - Payload appmgr.Error -} - -// IsSuccess returns true when this close disruption default response has a 2xx status code -func (o *CloseDisruptionDefault) IsSuccess() bool { - return o._statusCode/100 == 2 -} - -// IsRedirect returns true when this close disruption default response has a 3xx status code -func (o *CloseDisruptionDefault) IsRedirect() bool { - return o._statusCode/100 == 3 -} - -// IsClientError returns true when this close disruption default response has a 4xx status code -func (o *CloseDisruptionDefault) IsClientError() bool { - return o._statusCode/100 == 4 -} - -// IsServerError returns true when this close disruption default response has a 5xx status code -func (o *CloseDisruptionDefault) IsServerError() bool { - return o._statusCode/100 == 5 -} - -// IsCode returns true when this close disruption default response a status code equal to that given -func (o *CloseDisruptionDefault) IsCode(code int) bool { - return o._statusCode == code -} - -// Code gets the status code for the close disruption default response -func (o *CloseDisruptionDefault) Code() int { - return o._statusCode -} - -func (o *CloseDisruptionDefault) Error() string { - payload, _ := json.Marshal(o.Payload) - return fmt.Sprintf("[POST /close][%d] closeDisruption default %s", o._statusCode, payload) -} - -func (o *CloseDisruptionDefault) String() string { - payload, _ := json.Marshal(o.Payload) - return fmt.Sprintf("[POST /close][%d] closeDisruption default %s", o._statusCode, payload) -} - -func (o *CloseDisruptionDefault) GetPayload() appmgr.Error { - return o.Payload -} - -func (o *CloseDisruptionDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { - - // response payload - if err := consumer.Consume(response.Body(), &o.Payload); err != nil && !stderrors.Is(err, io.EOF) { - return err - } - - return nil -} diff --git a/internal/appmgrcli/disruption/disruption_client.go b/internal/appmgrcli/disruption/disruption_client.go index 9e356bc..ee84a90 100644 --- a/internal/appmgrcli/disruption/disruption_client.go +++ b/internal/appmgrcli/disruption/disruption_client.go @@ -56,10 +56,10 @@ type ClientOption func(*runtime.ClientOperation) type ClientService interface { CheckReadiness(params *CheckReadinessParams, opts ...ClientOption) (*CheckReadinessOK, error) - CloseDisruption(params *CloseDisruptionParams, opts ...ClientOption) (*CloseDisruptionOK, error) - PrepareApplication(params *PrepareApplicationParams, opts ...ClientOption) (*PrepareApplicationOK, error) + TerminateDisruption(params *TerminateDisruptionParams, opts ...ClientOption) (*TerminateDisruptionOK, error) + SetTransport(transport runtime.ClientTransport) } @@ -106,22 +106,22 @@ func (a *Client) CheckReadiness(params *CheckReadinessParams, opts ...ClientOpti } /* -CloseDisruption notifies the end of a disruption if the application needs to unprepare +PrepareApplication prepares application for a disruption */ -func (a *Client) CloseDisruption(params *CloseDisruptionParams, opts ...ClientOption) (*CloseDisruptionOK, error) { +func (a *Client) PrepareApplication(params *PrepareApplicationParams, opts ...ClientOption) (*PrepareApplicationOK, error) { // NOTE: parameters are not validated before sending if params == nil { - params = NewCloseDisruptionParams() + params = NewPrepareApplicationParams() } op := &runtime.ClientOperation{ - ID: "closeDisruption", + ID: "prepareApplication", Method: "POST", - PathPattern: "/close", + PathPattern: "/prepare", ProducesMediaTypes: []string{"application/json"}, ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"https"}, Params: params, - Reader: &CloseDisruptionReader{formats: a.formats}, + Reader: &PrepareApplicationReader{formats: a.formats}, Context: params.Context, Client: params.HTTPClient, } @@ -134,7 +134,7 @@ func (a *Client) CloseDisruption(params *CloseDisruptionParams, opts ...ClientOp } // only one success response has to be checked - success, ok := result.(*CloseDisruptionOK) + success, ok := result.(*PrepareApplicationOK) if ok { return success, nil } @@ -142,28 +142,28 @@ func (a *Client) CloseDisruption(params *CloseDisruptionParams, opts ...ClientOp // unexpected success response. // // a default response is provided: fill this and return an error - unexpectedSuccess := result.(*CloseDisruptionDefault) + unexpectedSuccess := result.(*PrepareApplicationDefault) return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } /* -PrepareApplication prepares application for a disruption +TerminateDisruption notifies the end of a disruption if the application needs to unprepare */ -func (a *Client) PrepareApplication(params *PrepareApplicationParams, opts ...ClientOption) (*PrepareApplicationOK, error) { +func (a *Client) TerminateDisruption(params *TerminateDisruptionParams, opts ...ClientOption) (*TerminateDisruptionOK, error) { // NOTE: parameters are not validated before sending if params == nil { - params = NewPrepareApplicationParams() + params = NewTerminateDisruptionParams() } op := &runtime.ClientOperation{ - ID: "prepareApplication", + ID: "terminateDisruption", Method: "POST", - PathPattern: "/prepare", + PathPattern: "/terminate", ProducesMediaTypes: []string{"application/json"}, ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"https"}, Params: params, - Reader: &PrepareApplicationReader{formats: a.formats}, + Reader: &TerminateDisruptionReader{formats: a.formats}, Context: params.Context, Client: params.HTTPClient, } @@ -176,7 +176,7 @@ func (a *Client) PrepareApplication(params *PrepareApplicationParams, opts ...Cl } // only one success response has to be checked - success, ok := result.(*PrepareApplicationOK) + success, ok := result.(*TerminateDisruptionOK) if ok { return success, nil } @@ -184,7 +184,7 @@ func (a *Client) PrepareApplication(params *PrepareApplicationParams, opts ...Cl // unexpected success response. // // a default response is provided: fill this and return an error - unexpectedSuccess := result.(*PrepareApplicationDefault) + unexpectedSuccess := result.(*TerminateDisruptionDefault) return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } diff --git a/internal/appmgrcli/disruption/terminate_disruption_parameters.go b/internal/appmgrcli/disruption/terminate_disruption_parameters.go new file mode 100644 index 0000000..19a711a --- /dev/null +++ b/internal/appmgrcli/disruption/terminate_disruption_parameters.go @@ -0,0 +1,153 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package disruption + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" + + "github.com/criteo/node-disruption-controller/internal/appmgr" +) + +// NewTerminateDisruptionParams creates a new TerminateDisruptionParams object, +// with the default timeout for this client. +// +// Default values are not hydrated, since defaults are normally applied by the API server side. +// +// To enforce default values in parameter, use SetDefaults or WithDefaults. +func NewTerminateDisruptionParams() *TerminateDisruptionParams { + return &TerminateDisruptionParams{ + timeout: cr.DefaultTimeout, + } +} + +// NewTerminateDisruptionParamsWithTimeout creates a new TerminateDisruptionParams object +// with the ability to set a timeout on a request. +func NewTerminateDisruptionParamsWithTimeout(timeout time.Duration) *TerminateDisruptionParams { + return &TerminateDisruptionParams{ + timeout: timeout, + } +} + +// NewTerminateDisruptionParamsWithContext creates a new TerminateDisruptionParams object +// with the ability to set a context for a request. +func NewTerminateDisruptionParamsWithContext(ctx context.Context) *TerminateDisruptionParams { + return &TerminateDisruptionParams{ + Context: ctx, + } +} + +// NewTerminateDisruptionParamsWithHTTPClient creates a new TerminateDisruptionParams object +// with the ability to set a custom HTTPClient for a request. +func NewTerminateDisruptionParamsWithHTTPClient(client *http.Client) *TerminateDisruptionParams { + return &TerminateDisruptionParams{ + HTTPClient: client, + } +} + +/* +TerminateDisruptionParams contains all the parameters to send to the API endpoint + + for the terminate disruption operation. + + Typically these are written to a http.Request. +*/ +type TerminateDisruptionParams struct { + + /* Body. + + Disruption + */ + Body *appmgr.Disruption + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithDefaults hydrates default values in the terminate disruption params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *TerminateDisruptionParams) WithDefaults() *TerminateDisruptionParams { + o.SetDefaults() + return o +} + +// SetDefaults hydrates default values in the terminate disruption params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *TerminateDisruptionParams) SetDefaults() { + // no default values defined for this parameter +} + +// WithTimeout adds the timeout to the terminate disruption params +func (o *TerminateDisruptionParams) WithTimeout(timeout time.Duration) *TerminateDisruptionParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the terminate disruption params +func (o *TerminateDisruptionParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the terminate disruption params +func (o *TerminateDisruptionParams) WithContext(ctx context.Context) *TerminateDisruptionParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the terminate disruption params +func (o *TerminateDisruptionParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the terminate disruption params +func (o *TerminateDisruptionParams) WithHTTPClient(client *http.Client) *TerminateDisruptionParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the terminate disruption params +func (o *TerminateDisruptionParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithBody adds the body to the terminate disruption params +func (o *TerminateDisruptionParams) WithBody(body *appmgr.Disruption) *TerminateDisruptionParams { + o.SetBody(body) + return o +} + +// SetBody adds the body to the terminate disruption params +func (o *TerminateDisruptionParams) SetBody(body *appmgr.Disruption) { + o.Body = body +} + +// WriteToRequest writes these params to a swagger request +func (o *TerminateDisruptionParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + if o.Body != nil { + if err := r.SetBodyParam(o.Body); err != nil { + return err + } + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/internal/appmgrcli/disruption/terminate_disruption_responses.go b/internal/appmgrcli/disruption/terminate_disruption_responses.go new file mode 100644 index 0000000..e465baf --- /dev/null +++ b/internal/appmgrcli/disruption/terminate_disruption_responses.go @@ -0,0 +1,172 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package disruption + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "encoding/json" + stderrors "errors" + "fmt" + "io" + + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + + "github.com/criteo/node-disruption-controller/internal/appmgr" +) + +// TerminateDisruptionReader is a Reader for the TerminateDisruption structure. +type TerminateDisruptionReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *TerminateDisruptionReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { + switch response.Code() { + case 200: + result := NewTerminateDisruptionOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + default: + result := NewTerminateDisruptionDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewTerminateDisruptionOK creates a TerminateDisruptionOK with default headers values +func NewTerminateDisruptionOK() *TerminateDisruptionOK { + return &TerminateDisruptionOK{} +} + +/* +TerminateDisruptionOK describes a response with status code 200, with default header values. + +Acknowledged. +*/ +type TerminateDisruptionOK struct { +} + +// IsSuccess returns true when this terminate disruption o k response has a 2xx status code +func (o *TerminateDisruptionOK) IsSuccess() bool { + return true +} + +// IsRedirect returns true when this terminate disruption o k response has a 3xx status code +func (o *TerminateDisruptionOK) IsRedirect() bool { + return false +} + +// IsClientError returns true when this terminate disruption o k response has a 4xx status code +func (o *TerminateDisruptionOK) IsClientError() bool { + return false +} + +// IsServerError returns true when this terminate disruption o k response has a 5xx status code +func (o *TerminateDisruptionOK) IsServerError() bool { + return false +} + +// IsCode returns true when this terminate disruption o k response a status code equal to that given +func (o *TerminateDisruptionOK) IsCode(code int) bool { + return code == 200 +} + +// Code gets the status code for the terminate disruption o k response +func (o *TerminateDisruptionOK) Code() int { + return 200 +} + +func (o *TerminateDisruptionOK) Error() string { + return fmt.Sprintf("[POST /terminate][%d] terminateDisruptionOK", 200) +} + +func (o *TerminateDisruptionOK) String() string { + return fmt.Sprintf("[POST /terminate][%d] terminateDisruptionOK", 200) +} + +func (o *TerminateDisruptionOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + return nil +} + +// NewTerminateDisruptionDefault creates a TerminateDisruptionDefault with default headers values +func NewTerminateDisruptionDefault(code int) *TerminateDisruptionDefault { + return &TerminateDisruptionDefault{ + _statusCode: code, + } +} + +/* +TerminateDisruptionDefault describes a response with status code -1, with default header values. + +Unexpected error +*/ +type TerminateDisruptionDefault struct { + _statusCode int + + Payload appmgr.Error +} + +// IsSuccess returns true when this terminate disruption default response has a 2xx status code +func (o *TerminateDisruptionDefault) IsSuccess() bool { + return o._statusCode/100 == 2 +} + +// IsRedirect returns true when this terminate disruption default response has a 3xx status code +func (o *TerminateDisruptionDefault) IsRedirect() bool { + return o._statusCode/100 == 3 +} + +// IsClientError returns true when this terminate disruption default response has a 4xx status code +func (o *TerminateDisruptionDefault) IsClientError() bool { + return o._statusCode/100 == 4 +} + +// IsServerError returns true when this terminate disruption default response has a 5xx status code +func (o *TerminateDisruptionDefault) IsServerError() bool { + return o._statusCode/100 == 5 +} + +// IsCode returns true when this terminate disruption default response a status code equal to that given +func (o *TerminateDisruptionDefault) IsCode(code int) bool { + return o._statusCode == code +} + +// Code gets the status code for the terminate disruption default response +func (o *TerminateDisruptionDefault) Code() int { + return o._statusCode +} + +func (o *TerminateDisruptionDefault) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[POST /terminate][%d] terminateDisruption default %s", o._statusCode, payload) +} + +func (o *TerminateDisruptionDefault) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[POST /terminate][%d] terminateDisruption default %s", o._statusCode, payload) +} + +func (o *TerminateDisruptionDefault) GetPayload() appmgr.Error { + return o.Payload +} + +func (o *TerminateDisruptionDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), &o.Payload); err != nil && !stderrors.Is(err, io.EOF) { + return err + } + + return nil +} diff --git a/internal/controller/applicationdisruptionbudget_controller.go b/internal/controller/applicationdisruptionbudget_controller.go index 1d4c520..b54976a 100644 --- a/internal/controller/applicationdisruptionbudget_controller.go +++ b/internal/controller/applicationdisruptionbudget_controller.go @@ -283,13 +283,13 @@ func (r *ApplicationDisruptionBudgetResolver) CallReadyHook(ctx context.Context, return err } -func (r *ApplicationDisruptionBudgetResolver) CallCloseHook(ctx context.Context, nd nodedisruptionv1alpha1.NodeDisruption, timeout time.Duration) error { +func (r *ApplicationDisruptionBudgetResolver) CallTerminateHook(ctx context.Context, nd nodedisruptionv1alpha1.NodeDisruption, timeout time.Duration) error { svc, err := r.hookClient() if err != nil { return err } - _, err = svc.CloseDisruption(&disruption.CloseDisruptionParams{ + _, err = svc.TerminateDisruption(&disruption.TerminateDisruptionParams{ Body: r.hookBody(nd), HTTPClient: &http.Client{Timeout: timeout}, }) diff --git a/internal/controller/budget.go b/internal/controller/budget.go index 3d31e44..3b49023 100644 --- a/internal/controller/budget.go +++ b/internal/controller/budget.go @@ -17,14 +17,14 @@ type Budget interface { IsImpacted(resolver.NodeSet) bool // Return the number of disruption allowed considering a list of current node disruptions TolerateDisruption(resolver.NodeSet) bool - // Return true if the budget has v2 hooks configured (for prepare, ready, close) + // Return true if the budget has v2 hooks configured (for prepare, ready, terminate) V2HooksReady() bool // Call the prepare hook to trigger the preparation of the application for disruption CallPrepareHook(context.Context, nodedisruptionv1alpha1.NodeDisruption, time.Duration) error // Call the ready hook to validate that the application is ready for disruption CallReadyHook(context.Context, nodedisruptionv1alpha1.NodeDisruption, time.Duration) error - // Call the close hook to close any disruption - CallCloseHook(context.Context, nodedisruptionv1alpha1.NodeDisruption, time.Duration) error + // Call the terminate hook to terminate any disruption + CallTerminateHook(context.Context, nodedisruptionv1alpha1.NodeDisruption, time.Duration) error // Call a lifecycle hook in order to synchronously validate a Node Disruption CallHealthHook(context.Context, nodedisruptionv1alpha1.NodeDisruption, time.Duration) error // Apply the budget's status to Kubernetes diff --git a/internal/controller/budget_test.go b/internal/controller/budget_test.go index d7055fc..879d639 100644 --- a/internal/controller/budget_test.go +++ b/internal/controller/budget_test.go @@ -49,7 +49,7 @@ func (m *MockBudget) CallReadyHook(context.Context, nodedisruptionv1alpha1.NodeD return nil } -func (m *MockBudget) CallCloseHook(context.Context, nodedisruptionv1alpha1.NodeDisruption, time.Duration) error { +func (m *MockBudget) CallTerminateHook(context.Context, nodedisruptionv1alpha1.NodeDisruption, time.Duration) error { return nil } diff --git a/internal/controller/nodedisruption_controller.go b/internal/controller/nodedisruption_controller.go index 3eeb0fd..03c7bdd 100644 --- a/internal/controller/nodedisruption_controller.go +++ b/internal/controller/nodedisruption_controller.go @@ -44,7 +44,7 @@ import ( const ( DefaultRetryInterval = time.Minute DefaultHealthHookTimeout = time.Minute - FinalizerName = "node-disruption-controller/close-propagation" + FinalizerName = "node-disruption-controller/terminate-propagation" ) type NodeDisruptionReconcilerConfig struct { @@ -145,8 +145,8 @@ func (r *NodeDisruptionReconciler) handleFinalizer(ctx context.Context, nd *node } if controllerutil.ContainsFinalizer(nd, FinalizerName) { - // Disruption is being deleted, call all close hooks for all impacted budgets. - if err := sndr.closeAllImpactedBudgets(ctx); err != nil { + // Disruption is being deleted, call all terminate hooks for all impacted budgets. + if err := sndr.terminateAllImpactedBudgets(ctx); err != nil { return false, err } @@ -322,8 +322,8 @@ func (ndr *SingleNodeDisruptionReconciler) tryTransitionToGranted(ctx context.Co return nil } -// closeAllImpactedBudgets notify for all impacted budgets the associated application managers that the node disruption has ended. -func (ndr *SingleNodeDisruptionReconciler) closeAllImpactedBudgets(ctx context.Context) error { +// terminateAllImpactedBudgets notify for all impacted budgets the associated application managers that the node disruption has ended. +func (ndr *SingleNodeDisruptionReconciler) terminateAllImpactedBudgets(ctx context.Context) error { logger := log.FromContext(ctx) anyFailed := false @@ -332,7 +332,7 @@ func (ndr *SingleNodeDisruptionReconciler) closeAllImpactedBudgets(ctx context.C continue } - // Only ApplicationDisruptionBudget can handle close notifications + // Only ApplicationDisruptionBudget can handle terminate notifications if budgetStatus.Reference.Kind != "ApplicationDisruptionBudget" { continue } @@ -341,7 +341,7 @@ func (ndr *SingleNodeDisruptionReconciler) closeAllImpactedBudgets(ctx context.C adb := &nodedisruptionv1alpha1.ApplicationDisruptionBudget{} if err := ndr.Client.Get(ctx, client.ObjectKey{Namespace: budgetStatus.Reference.Namespace, Name: budgetStatus.Reference.Name}, adb); err != nil { if errors.IsNotFound(err) { - logger.Info("budget has been deleted, skipping close hook", "budget", refStr) + logger.Info("budget has been deleted, skipping terminate hook", "budget", refStr) continue } anyFailed = true @@ -359,13 +359,13 @@ func (ndr *SingleNodeDisruptionReconciler) closeAllImpactedBudgets(ctx context.C continue } - if err := budgetResolver.CallCloseHook(ctx, ndr.NodeDisruption, 10*time.Second); err != nil { - logger.Error(err, "failed to call close hook", "budget", refStr) + if err := budgetResolver.CallTerminateHook(ctx, ndr.NodeDisruption, 10*time.Second); err != nil { + logger.Error(err, "failed to call terminate hook", "budget", refStr) anyFailed = true } } if anyFailed { - return stderrors.New("failed to close all budgets") + return stderrors.New("failed to terminate all budgets") } return nil diff --git a/internal/controller/nodedisruption_controller_test.go b/internal/controller/nodedisruption_controller_test.go index 5b6c162..50c2a3c 100644 --- a/internal/controller/nodedisruption_controller_test.go +++ b/internal/controller/nodedisruption_controller_test.go @@ -263,7 +263,7 @@ var _ = Describe("NodeDisruption controller", func() { prepareCalledCnt++ case mockBasePath + "/ready": readyCalledCnt++ - case mockBasePath + "/close": + case mockBasePath + "/terminate": closeCalledCnt++ } err := json.NewDecoder(req.Body).Decode(&dis) @@ -349,7 +349,7 @@ var _ = Describe("NodeDisruption controller", func() { By("deleting the NodeDisruption") Expect(k8sClient.Delete(ctx, createdDisruption.DeepCopy())).Should(Succeed()) - By("calling the close hook through finalizer") + By("calling the terminate hook through finalizer") Eventually(func() int { return closeCalledCnt }, timeout, interval).Should(Equal(1)) diff --git a/internal/controller/nodedisruptionbudget_controller.go b/internal/controller/nodedisruptionbudget_controller.go index a2fc0e7..a1a5d64 100644 --- a/internal/controller/nodedisruptionbudget_controller.go +++ b/internal/controller/nodedisruptionbudget_controller.go @@ -233,7 +233,7 @@ func (r *NodeDisruptionBudgetResolver) CallReadyHook(ctx context.Context, nd nod return nil } -func (r *NodeDisruptionBudgetResolver) CallCloseHook(ctx context.Context, nd nodedisruptionv1alpha1.NodeDisruption, timeout time.Duration) error { +func (r *NodeDisruptionBudgetResolver) CallTerminateHook(ctx context.Context, nd nodedisruptionv1alpha1.NodeDisruption, timeout time.Duration) error { return nil }