From cb655f35a03e3682f0a5717955c823bc4894d49a Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Mon, 11 Nov 2024 15:53:11 +0100 Subject: [PATCH 1/4] Added build deploy option environment --- cmd/createBuildDeployPipelineJob.go | 32 ++- cmd/createBuildPipelineJob.go | 32 ++- .../client/environment/environment_client.go | 82 ++++++ .../get_component_events_parameters.go | 245 ++++++++++++++++ .../get_component_events_responses.go | 228 +++++++++++++++ .../get_replica_events_parameters.go | 267 ++++++++++++++++++ .../get_replica_events_responses.go | 228 +++++++++++++++ generated-client/models/deployment.go | 4 + generated-client/models/deployment_summary.go | 4 + .../deployment_summary_pipeline_job_info.go | 4 + generated-client/models/ingress_rule.go | 59 ++++ generated-client/models/job.go | 4 + generated-client/models/object_state.go | 63 +++++ .../models/pipeline_parameters_build.go | 4 + go.mod | 4 +- go.sum | 8 +- 16 files changed, 1248 insertions(+), 20 deletions(-) create mode 100644 generated-client/client/environment/get_component_events_parameters.go create mode 100644 generated-client/client/environment/get_component_events_responses.go create mode 100644 generated-client/client/environment/get_replica_events_parameters.go create mode 100644 generated-client/client/environment/get_replica_events_responses.go create mode 100644 generated-client/models/ingress_rule.go diff --git a/cmd/createBuildDeployPipelineJob.go b/cmd/createBuildDeployPipelineJob.go index e1e7b3c..3ceaf3a 100644 --- a/cmd/createBuildDeployPipelineJob.go +++ b/cmd/createBuildDeployPipelineJob.go @@ -29,7 +29,7 @@ import ( "github.com/spf13/cobra" ) -var overrideUseBuildCache model.BoolPtr +var overrideUseBuildCacheForBuildDeploy model.BoolPtr // createBuildDeployApplicationCmd represents the buildApplication command var createBuildDeployApplicationCmd = &cobra.Command{ @@ -37,17 +37,31 @@ var createBuildDeployApplicationCmd = &cobra.Command{ Short: "Will trigger build-deploy of a Radix application", Long: `Triggers build-deploy of Radix application, if branch to environment map exists for the branch in the Radix config`, RunE: func(cmd *cobra.Command, args []string) error { + var errs []error appName, err := config.GetAppNameFromConfigOrFromParameter(cmd, flagnames.Application) if err != nil { - return err + errs = append(errs, err) } - branch, _ := cmd.Flags().GetString(flagnames.Branch) - commitID, _ := cmd.Flags().GetString(flagnames.CommitID) - follow, _ := cmd.Flags().GetBool(flagnames.Follow) + branch, err := cmd.Flags().GetString(flagnames.Branch) + if err != nil { + errs = append(errs, err) + } + commitID, err := cmd.Flags().GetString(flagnames.CommitID) + if err != nil { + errs = append(errs, err) + } + targetEnvironment, err := cmd.Flags().GetString(flagnames.Environment) + if err != nil { + errs = append(errs, err) + } + follow, err := cmd.Flags().GetBool(flagnames.Follow) + if err != nil { + errs = append(errs, err) + } if appName == "" || branch == "" { - return errors.New("application name and branch are required") + errs = append(errs, errors.New("application name and branch are required")) } cmd.SilenceUsage = true @@ -60,8 +74,9 @@ var createBuildDeployApplicationCmd = &cobra.Command{ triggerPipelineParams.SetAppName(appName) triggerPipelineParams.SetPipelineParametersBuild(&models.PipelineParametersBuild{ Branch: branch, + ToEnvironment: targetEnvironment, CommitID: commitID, - OverrideUseBuildCache: overrideUseBuildCache.Get(), + OverrideUseBuildCache: overrideUseBuildCacheForBuildDeploy.Get(), }) newJob, err := apiClient.Application.TriggerPipelineBuildDeploy(triggerPipelineParams, nil) @@ -82,9 +97,10 @@ func init() { createJobCmd.AddCommand(createBuildDeployApplicationCmd) createBuildDeployApplicationCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application to build-deploy") createBuildDeployApplicationCmd.Flags().StringP(flagnames.Branch, "b", "master", "Branch to build-deploy from") + createBuildDeployApplicationCmd.Flags().StringP(flagnames.Environment, "e", "", "Optional. Target environment to deploy in ('prod', 'dev', 'playground'), when multiple environments are built from the selected branch.") createBuildDeployApplicationCmd.Flags().StringP(flagnames.CommitID, "i", "", "Commit id") createBuildDeployApplicationCmd.Flags().BoolP(flagnames.Follow, "f", false, "Follow build-deploy") - createBuildDeployApplicationCmd.Flags().Var(&overrideUseBuildCache, flagnames.UseBuildCache, "Optional. Overrides configured or default useBuildCache option. It is applicable when the useBuildKit option is set as true.") + createBuildDeployApplicationCmd.Flags().Var(&overrideUseBuildCacheForBuildDeploy, flagnames.UseBuildCache, "Optional. Overrides configured or default useBuildCache option. It is applicable when the useBuildKit option is set as true.") _ = createBuildDeployApplicationCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.ApplicationCompletion) setContextSpecificPersistentFlags(createBuildDeployApplicationCmd) diff --git a/cmd/createBuildPipelineJob.go b/cmd/createBuildPipelineJob.go index 3e042c6..f8f99a0 100644 --- a/cmd/createBuildPipelineJob.go +++ b/cmd/createBuildPipelineJob.go @@ -22,26 +22,42 @@ import ( "github.com/equinor/radix-cli/pkg/client" "github.com/equinor/radix-cli/pkg/config" "github.com/equinor/radix-cli/pkg/flagnames" + "github.com/equinor/radix-cli/pkg/model" "github.com/equinor/radix-cli/pkg/utils/completion" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) -// createBuildPipelineJobCmd represents the createBuildPipelineJob command +var overrideUseBuildCacheForBuild model.BoolPtr + var createBuildPipelineJobCmd = &cobra.Command{ Use: "build", Short: "Will trigger build of a Radix application", Long: `Triggers build of Radix application, for branches that are mapped to a environment in the Radix config`, RunE: func(cmd *cobra.Command, args []string) error { + var errs []error appName, err := config.GetAppNameFromConfigOrFromParameter(cmd, flagnames.Application) if err != nil { - return err + errs = append(errs, err) } if appName == "" { - return errors.New("application name is required") + errs = append(errs, errors.New("application name is required")) + } + branch, err := cmd.Flags().GetString(flagnames.Branch) + if err != nil { + errs = append(errs, err) + } + targetEnvironment, err := cmd.Flags().GetString(flagnames.Environment) + if err != nil { + errs = append(errs, err) + } + follow, err := cmd.Flags().GetBool(flagnames.Follow) + if err != nil { + errs = append(errs, err) + } + if len(errs) > 0 { + return errors.Join(errs...) } - branch, _ := cmd.Flags().GetString(flagnames.Branch) - follow, _ := cmd.Flags().GetBool(flagnames.Follow) cmd.SilenceUsage = true @@ -52,7 +68,9 @@ var createBuildPipelineJobCmd = &cobra.Command{ triggerDeployParams := application.NewTriggerPipelineBuildParams() triggerDeployParams.SetAppName(appName) triggerDeployParams.SetPipelineParametersBuild(&models.PipelineParametersBuild{ - Branch: branch, + Branch: branch, + ToEnvironment: targetEnvironment, + OverrideUseBuildCache: overrideUseBuildCacheForBuild.Get(), }) newJob, err := apiClient.Application.TriggerPipelineBuild(triggerDeployParams, nil) if err != nil { @@ -73,7 +91,9 @@ func init() { createJobCmd.AddCommand(createBuildPipelineJobCmd) createBuildPipelineJobCmd.Flags().StringP(flagnames.Branch, "b", "master", "Branch to build from") createBuildPipelineJobCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application to build") + createBuildPipelineJobCmd.Flags().StringP(flagnames.Environment, "e", "", "Optional. Target environment to deploy in ('prod', 'dev', 'playground'), when multiple environments are built from the selected branch.") createBuildPipelineJobCmd.Flags().BoolP(flagnames.Follow, "f", false, "Follow build") + createBuildPipelineJobCmd.Flags().Var(&overrideUseBuildCacheForBuild, flagnames.UseBuildCache, "Optional. Overrides configured or default useBuildCache option. It is applicable when the useBuildKit option is set as true.") if err := createBuildPipelineJobCmd.MarkFlagRequired(flagnames.Branch); err != nil { log.Fatalf("Error during command initialization: %v", err) } diff --git a/generated-client/client/environment/environment_client.go b/generated-client/client/environment/environment_client.go index 4670e8e..9f60704 100644 --- a/generated-client/client/environment/environment_client.go +++ b/generated-client/client/environment/environment_client.go @@ -70,6 +70,8 @@ type ClientService interface { GetAzureKeyVaultSecretVersions(params *GetAzureKeyVaultSecretVersionsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetAzureKeyVaultSecretVersionsOK, error) + GetComponentEvents(params *GetComponentEventsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetComponentEventsOK, error) + GetEnvironment(params *GetEnvironmentParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetEnvironmentOK, error) GetEnvironmentAlertingConfig(params *GetEnvironmentAlertingConfigParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetEnvironmentAlertingConfigOK, error) @@ -78,6 +80,8 @@ type ClientService interface { GetEnvironmentSummary(params *GetEnvironmentSummaryParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetEnvironmentSummaryOK, error) + GetReplicaEvents(params *GetReplicaEventsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetReplicaEventsOK, error) + ResetManuallyScaledComponentsInEnvironment(params *ResetManuallyScaledComponentsInEnvironmentParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ResetManuallyScaledComponentsInEnvironmentOK, error) RestartEnvironment(params *RestartEnvironmentParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RestartEnvironmentOK, error) @@ -364,6 +368,45 @@ func (a *Client) GetAzureKeyVaultSecretVersions(params *GetAzureKeyVaultSecretVe panic(msg) } +/* +GetComponentEvents lists events for an application environment +*/ +func (a *Client) GetComponentEvents(params *GetComponentEventsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetComponentEventsOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewGetComponentEventsParams() + } + op := &runtime.ClientOperation{ + ID: "getComponentEvents", + Method: "GET", + PathPattern: "/applications/{appName}/environments/{envName}/events/components/{componentName}", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http", "https"}, + Params: params, + Reader: &GetComponentEventsReader{formats: a.formats}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + } + for _, opt := range opts { + opt(op) + } + + result, err := a.transport.Submit(op) + if err != nil { + return nil, err + } + success, ok := result.(*GetComponentEventsOK) + if ok { + return success, nil + } + // unexpected success response + // safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue + msg := fmt.Sprintf("unexpected success response for getComponentEvents: API contract not enforced by server. Client expected to get an error, but got: %T", result) + panic(msg) +} + /* GetEnvironment gets details for an application environment */ @@ -520,6 +563,45 @@ func (a *Client) GetEnvironmentSummary(params *GetEnvironmentSummaryParams, auth panic(msg) } +/* +GetReplicaEvents lists events for an application environment +*/ +func (a *Client) GetReplicaEvents(params *GetReplicaEventsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetReplicaEventsOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewGetReplicaEventsParams() + } + op := &runtime.ClientOperation{ + ID: "getReplicaEvents", + Method: "GET", + PathPattern: "/applications/{appName}/environments/{envName}/events/components/{componentName}/replicas/{podName}", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http", "https"}, + Params: params, + Reader: &GetReplicaEventsReader{formats: a.formats}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + } + for _, opt := range opts { + opt(op) + } + + result, err := a.transport.Submit(op) + if err != nil { + return nil, err + } + success, ok := result.(*GetReplicaEventsOK) + if ok { + return success, nil + } + // unexpected success response + // safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue + msg := fmt.Sprintf("unexpected success response for getReplicaEvents: API contract not enforced by server. Client expected to get an error, but got: %T", result) + panic(msg) +} + /* ResetManuallyScaledComponentsInEnvironment resets all manually scaled component and resumes normal operation in environment */ diff --git a/generated-client/client/environment/get_component_events_parameters.go b/generated-client/client/environment/get_component_events_parameters.go new file mode 100644 index 0000000..bdaf408 --- /dev/null +++ b/generated-client/client/environment/get_component_events_parameters.go @@ -0,0 +1,245 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package environment + +// 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" +) + +// NewGetComponentEventsParams creates a new GetComponentEventsParams 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 NewGetComponentEventsParams() *GetComponentEventsParams { + return &GetComponentEventsParams{ + timeout: cr.DefaultTimeout, + } +} + +// NewGetComponentEventsParamsWithTimeout creates a new GetComponentEventsParams object +// with the ability to set a timeout on a request. +func NewGetComponentEventsParamsWithTimeout(timeout time.Duration) *GetComponentEventsParams { + return &GetComponentEventsParams{ + timeout: timeout, + } +} + +// NewGetComponentEventsParamsWithContext creates a new GetComponentEventsParams object +// with the ability to set a context for a request. +func NewGetComponentEventsParamsWithContext(ctx context.Context) *GetComponentEventsParams { + return &GetComponentEventsParams{ + Context: ctx, + } +} + +// NewGetComponentEventsParamsWithHTTPClient creates a new GetComponentEventsParams object +// with the ability to set a custom HTTPClient for a request. +func NewGetComponentEventsParamsWithHTTPClient(client *http.Client) *GetComponentEventsParams { + return &GetComponentEventsParams{ + HTTPClient: client, + } +} + +/* +GetComponentEventsParams contains all the parameters to send to the API endpoint + + for the get component events operation. + + Typically these are written to a http.Request. +*/ +type GetComponentEventsParams struct { + + /* ImpersonateGroup. + + Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set) + */ + ImpersonateGroup *string + + /* ImpersonateUser. + + Works only with custom setup of cluster. Allow impersonation of test users (Required if Impersonate-Group is set) + */ + ImpersonateUser *string + + /* AppName. + + name of Radix application + */ + AppName string + + /* ComponentName. + + Name of component + */ + ComponentName string + + /* EnvName. + + name of environment + */ + EnvName string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithDefaults hydrates default values in the get component events params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *GetComponentEventsParams) WithDefaults() *GetComponentEventsParams { + o.SetDefaults() + return o +} + +// SetDefaults hydrates default values in the get component events params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *GetComponentEventsParams) SetDefaults() { + // no default values defined for this parameter +} + +// WithTimeout adds the timeout to the get component events params +func (o *GetComponentEventsParams) WithTimeout(timeout time.Duration) *GetComponentEventsParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get component events params +func (o *GetComponentEventsParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get component events params +func (o *GetComponentEventsParams) WithContext(ctx context.Context) *GetComponentEventsParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get component events params +func (o *GetComponentEventsParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get component events params +func (o *GetComponentEventsParams) WithHTTPClient(client *http.Client) *GetComponentEventsParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get component events params +func (o *GetComponentEventsParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithImpersonateGroup adds the impersonateGroup to the get component events params +func (o *GetComponentEventsParams) WithImpersonateGroup(impersonateGroup *string) *GetComponentEventsParams { + o.SetImpersonateGroup(impersonateGroup) + return o +} + +// SetImpersonateGroup adds the impersonateGroup to the get component events params +func (o *GetComponentEventsParams) SetImpersonateGroup(impersonateGroup *string) { + o.ImpersonateGroup = impersonateGroup +} + +// WithImpersonateUser adds the impersonateUser to the get component events params +func (o *GetComponentEventsParams) WithImpersonateUser(impersonateUser *string) *GetComponentEventsParams { + o.SetImpersonateUser(impersonateUser) + return o +} + +// SetImpersonateUser adds the impersonateUser to the get component events params +func (o *GetComponentEventsParams) SetImpersonateUser(impersonateUser *string) { + o.ImpersonateUser = impersonateUser +} + +// WithAppName adds the appName to the get component events params +func (o *GetComponentEventsParams) WithAppName(appName string) *GetComponentEventsParams { + o.SetAppName(appName) + return o +} + +// SetAppName adds the appName to the get component events params +func (o *GetComponentEventsParams) SetAppName(appName string) { + o.AppName = appName +} + +// WithComponentName adds the componentName to the get component events params +func (o *GetComponentEventsParams) WithComponentName(componentName string) *GetComponentEventsParams { + o.SetComponentName(componentName) + return o +} + +// SetComponentName adds the componentName to the get component events params +func (o *GetComponentEventsParams) SetComponentName(componentName string) { + o.ComponentName = componentName +} + +// WithEnvName adds the envName to the get component events params +func (o *GetComponentEventsParams) WithEnvName(envName string) *GetComponentEventsParams { + o.SetEnvName(envName) + return o +} + +// SetEnvName adds the envName to the get component events params +func (o *GetComponentEventsParams) SetEnvName(envName string) { + o.EnvName = envName +} + +// WriteToRequest writes these params to a swagger request +func (o *GetComponentEventsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if o.ImpersonateGroup != nil { + + // header param Impersonate-Group + if err := r.SetHeaderParam("Impersonate-Group", *o.ImpersonateGroup); err != nil { + return err + } + } + + if o.ImpersonateUser != nil { + + // header param Impersonate-User + if err := r.SetHeaderParam("Impersonate-User", *o.ImpersonateUser); err != nil { + return err + } + } + + // path param appName + if err := r.SetPathParam("appName", o.AppName); err != nil { + return err + } + + // path param componentName + if err := r.SetPathParam("componentName", o.ComponentName); err != nil { + return err + } + + // path param envName + if err := r.SetPathParam("envName", o.EnvName); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/generated-client/client/environment/get_component_events_responses.go b/generated-client/client/environment/get_component_events_responses.go new file mode 100644 index 0000000..57d5817 --- /dev/null +++ b/generated-client/client/environment/get_component_events_responses.go @@ -0,0 +1,228 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package environment + +// 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" + "fmt" + "io" + + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + + "github.com/equinor/radix-cli/generated-client/models" +) + +// GetComponentEventsReader is a Reader for the GetComponentEvents structure. +type GetComponentEventsReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *GetComponentEventsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewGetComponentEventsOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + case 401: + result := NewGetComponentEventsUnauthorized() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + case 404: + result := NewGetComponentEventsNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + default: + return nil, runtime.NewAPIError("[GET /applications/{appName}/environments/{envName}/events/components/{componentName}] getComponentEvents", response, response.Code()) + } +} + +// NewGetComponentEventsOK creates a GetComponentEventsOK with default headers values +func NewGetComponentEventsOK() *GetComponentEventsOK { + return &GetComponentEventsOK{} +} + +/* +GetComponentEventsOK describes a response with status code 200, with default header values. + +Successful get environment events +*/ +type GetComponentEventsOK struct { + Payload []*models.Event +} + +// IsSuccess returns true when this get component events o k response has a 2xx status code +func (o *GetComponentEventsOK) IsSuccess() bool { + return true +} + +// IsRedirect returns true when this get component events o k response has a 3xx status code +func (o *GetComponentEventsOK) IsRedirect() bool { + return false +} + +// IsClientError returns true when this get component events o k response has a 4xx status code +func (o *GetComponentEventsOK) IsClientError() bool { + return false +} + +// IsServerError returns true when this get component events o k response has a 5xx status code +func (o *GetComponentEventsOK) IsServerError() bool { + return false +} + +// IsCode returns true when this get component events o k response a status code equal to that given +func (o *GetComponentEventsOK) IsCode(code int) bool { + return code == 200 +} + +// Code gets the status code for the get component events o k response +func (o *GetComponentEventsOK) Code() int { + return 200 +} + +func (o *GetComponentEventsOK) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[GET /applications/{appName}/environments/{envName}/events/components/{componentName}][%d] getComponentEventsOK %s", 200, payload) +} + +func (o *GetComponentEventsOK) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[GET /applications/{appName}/environments/{envName}/events/components/{componentName}][%d] getComponentEventsOK %s", 200, payload) +} + +func (o *GetComponentEventsOK) GetPayload() []*models.Event { + return o.Payload +} + +func (o *GetComponentEventsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetComponentEventsUnauthorized creates a GetComponentEventsUnauthorized with default headers values +func NewGetComponentEventsUnauthorized() *GetComponentEventsUnauthorized { + return &GetComponentEventsUnauthorized{} +} + +/* +GetComponentEventsUnauthorized describes a response with status code 401, with default header values. + +Unauthorized +*/ +type GetComponentEventsUnauthorized struct { +} + +// IsSuccess returns true when this get component events unauthorized response has a 2xx status code +func (o *GetComponentEventsUnauthorized) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this get component events unauthorized response has a 3xx status code +func (o *GetComponentEventsUnauthorized) IsRedirect() bool { + return false +} + +// IsClientError returns true when this get component events unauthorized response has a 4xx status code +func (o *GetComponentEventsUnauthorized) IsClientError() bool { + return true +} + +// IsServerError returns true when this get component events unauthorized response has a 5xx status code +func (o *GetComponentEventsUnauthorized) IsServerError() bool { + return false +} + +// IsCode returns true when this get component events unauthorized response a status code equal to that given +func (o *GetComponentEventsUnauthorized) IsCode(code int) bool { + return code == 401 +} + +// Code gets the status code for the get component events unauthorized response +func (o *GetComponentEventsUnauthorized) Code() int { + return 401 +} + +func (o *GetComponentEventsUnauthorized) Error() string { + return fmt.Sprintf("[GET /applications/{appName}/environments/{envName}/events/components/{componentName}][%d] getComponentEventsUnauthorized", 401) +} + +func (o *GetComponentEventsUnauthorized) String() string { + return fmt.Sprintf("[GET /applications/{appName}/environments/{envName}/events/components/{componentName}][%d] getComponentEventsUnauthorized", 401) +} + +func (o *GetComponentEventsUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + return nil +} + +// NewGetComponentEventsNotFound creates a GetComponentEventsNotFound with default headers values +func NewGetComponentEventsNotFound() *GetComponentEventsNotFound { + return &GetComponentEventsNotFound{} +} + +/* +GetComponentEventsNotFound describes a response with status code 404, with default header values. + +Not found +*/ +type GetComponentEventsNotFound struct { +} + +// IsSuccess returns true when this get component events not found response has a 2xx status code +func (o *GetComponentEventsNotFound) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this get component events not found response has a 3xx status code +func (o *GetComponentEventsNotFound) IsRedirect() bool { + return false +} + +// IsClientError returns true when this get component events not found response has a 4xx status code +func (o *GetComponentEventsNotFound) IsClientError() bool { + return true +} + +// IsServerError returns true when this get component events not found response has a 5xx status code +func (o *GetComponentEventsNotFound) IsServerError() bool { + return false +} + +// IsCode returns true when this get component events not found response a status code equal to that given +func (o *GetComponentEventsNotFound) IsCode(code int) bool { + return code == 404 +} + +// Code gets the status code for the get component events not found response +func (o *GetComponentEventsNotFound) Code() int { + return 404 +} + +func (o *GetComponentEventsNotFound) Error() string { + return fmt.Sprintf("[GET /applications/{appName}/environments/{envName}/events/components/{componentName}][%d] getComponentEventsNotFound", 404) +} + +func (o *GetComponentEventsNotFound) String() string { + return fmt.Sprintf("[GET /applications/{appName}/environments/{envName}/events/components/{componentName}][%d] getComponentEventsNotFound", 404) +} + +func (o *GetComponentEventsNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + return nil +} diff --git a/generated-client/client/environment/get_replica_events_parameters.go b/generated-client/client/environment/get_replica_events_parameters.go new file mode 100644 index 0000000..85108fa --- /dev/null +++ b/generated-client/client/environment/get_replica_events_parameters.go @@ -0,0 +1,267 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package environment + +// 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" +) + +// NewGetReplicaEventsParams creates a new GetReplicaEventsParams 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 NewGetReplicaEventsParams() *GetReplicaEventsParams { + return &GetReplicaEventsParams{ + timeout: cr.DefaultTimeout, + } +} + +// NewGetReplicaEventsParamsWithTimeout creates a new GetReplicaEventsParams object +// with the ability to set a timeout on a request. +func NewGetReplicaEventsParamsWithTimeout(timeout time.Duration) *GetReplicaEventsParams { + return &GetReplicaEventsParams{ + timeout: timeout, + } +} + +// NewGetReplicaEventsParamsWithContext creates a new GetReplicaEventsParams object +// with the ability to set a context for a request. +func NewGetReplicaEventsParamsWithContext(ctx context.Context) *GetReplicaEventsParams { + return &GetReplicaEventsParams{ + Context: ctx, + } +} + +// NewGetReplicaEventsParamsWithHTTPClient creates a new GetReplicaEventsParams object +// with the ability to set a custom HTTPClient for a request. +func NewGetReplicaEventsParamsWithHTTPClient(client *http.Client) *GetReplicaEventsParams { + return &GetReplicaEventsParams{ + HTTPClient: client, + } +} + +/* +GetReplicaEventsParams contains all the parameters to send to the API endpoint + + for the get replica events operation. + + Typically these are written to a http.Request. +*/ +type GetReplicaEventsParams struct { + + /* ImpersonateGroup. + + Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set) + */ + ImpersonateGroup *string + + /* ImpersonateUser. + + Works only with custom setup of cluster. Allow impersonation of test users (Required if Impersonate-Group is set) + */ + ImpersonateUser *string + + /* AppName. + + name of Radix application + */ + AppName string + + /* ComponentName. + + Name of component + */ + ComponentName string + + /* EnvName. + + name of environment + */ + EnvName string + + /* PodName. + + Name of pod + */ + PodName string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithDefaults hydrates default values in the get replica events params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *GetReplicaEventsParams) WithDefaults() *GetReplicaEventsParams { + o.SetDefaults() + return o +} + +// SetDefaults hydrates default values in the get replica events params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *GetReplicaEventsParams) SetDefaults() { + // no default values defined for this parameter +} + +// WithTimeout adds the timeout to the get replica events params +func (o *GetReplicaEventsParams) WithTimeout(timeout time.Duration) *GetReplicaEventsParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get replica events params +func (o *GetReplicaEventsParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get replica events params +func (o *GetReplicaEventsParams) WithContext(ctx context.Context) *GetReplicaEventsParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get replica events params +func (o *GetReplicaEventsParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get replica events params +func (o *GetReplicaEventsParams) WithHTTPClient(client *http.Client) *GetReplicaEventsParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get replica events params +func (o *GetReplicaEventsParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithImpersonateGroup adds the impersonateGroup to the get replica events params +func (o *GetReplicaEventsParams) WithImpersonateGroup(impersonateGroup *string) *GetReplicaEventsParams { + o.SetImpersonateGroup(impersonateGroup) + return o +} + +// SetImpersonateGroup adds the impersonateGroup to the get replica events params +func (o *GetReplicaEventsParams) SetImpersonateGroup(impersonateGroup *string) { + o.ImpersonateGroup = impersonateGroup +} + +// WithImpersonateUser adds the impersonateUser to the get replica events params +func (o *GetReplicaEventsParams) WithImpersonateUser(impersonateUser *string) *GetReplicaEventsParams { + o.SetImpersonateUser(impersonateUser) + return o +} + +// SetImpersonateUser adds the impersonateUser to the get replica events params +func (o *GetReplicaEventsParams) SetImpersonateUser(impersonateUser *string) { + o.ImpersonateUser = impersonateUser +} + +// WithAppName adds the appName to the get replica events params +func (o *GetReplicaEventsParams) WithAppName(appName string) *GetReplicaEventsParams { + o.SetAppName(appName) + return o +} + +// SetAppName adds the appName to the get replica events params +func (o *GetReplicaEventsParams) SetAppName(appName string) { + o.AppName = appName +} + +// WithComponentName adds the componentName to the get replica events params +func (o *GetReplicaEventsParams) WithComponentName(componentName string) *GetReplicaEventsParams { + o.SetComponentName(componentName) + return o +} + +// SetComponentName adds the componentName to the get replica events params +func (o *GetReplicaEventsParams) SetComponentName(componentName string) { + o.ComponentName = componentName +} + +// WithEnvName adds the envName to the get replica events params +func (o *GetReplicaEventsParams) WithEnvName(envName string) *GetReplicaEventsParams { + o.SetEnvName(envName) + return o +} + +// SetEnvName adds the envName to the get replica events params +func (o *GetReplicaEventsParams) SetEnvName(envName string) { + o.EnvName = envName +} + +// WithPodName adds the podName to the get replica events params +func (o *GetReplicaEventsParams) WithPodName(podName string) *GetReplicaEventsParams { + o.SetPodName(podName) + return o +} + +// SetPodName adds the podName to the get replica events params +func (o *GetReplicaEventsParams) SetPodName(podName string) { + o.PodName = podName +} + +// WriteToRequest writes these params to a swagger request +func (o *GetReplicaEventsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if o.ImpersonateGroup != nil { + + // header param Impersonate-Group + if err := r.SetHeaderParam("Impersonate-Group", *o.ImpersonateGroup); err != nil { + return err + } + } + + if o.ImpersonateUser != nil { + + // header param Impersonate-User + if err := r.SetHeaderParam("Impersonate-User", *o.ImpersonateUser); err != nil { + return err + } + } + + // path param appName + if err := r.SetPathParam("appName", o.AppName); err != nil { + return err + } + + // path param componentName + if err := r.SetPathParam("componentName", o.ComponentName); err != nil { + return err + } + + // path param envName + if err := r.SetPathParam("envName", o.EnvName); err != nil { + return err + } + + // path param podName + if err := r.SetPathParam("podName", o.PodName); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/generated-client/client/environment/get_replica_events_responses.go b/generated-client/client/environment/get_replica_events_responses.go new file mode 100644 index 0000000..b29ada8 --- /dev/null +++ b/generated-client/client/environment/get_replica_events_responses.go @@ -0,0 +1,228 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package environment + +// 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" + "fmt" + "io" + + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + + "github.com/equinor/radix-cli/generated-client/models" +) + +// GetReplicaEventsReader is a Reader for the GetReplicaEvents structure. +type GetReplicaEventsReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *GetReplicaEventsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewGetReplicaEventsOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + case 401: + result := NewGetReplicaEventsUnauthorized() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + case 404: + result := NewGetReplicaEventsNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + default: + return nil, runtime.NewAPIError("[GET /applications/{appName}/environments/{envName}/events/components/{componentName}/replicas/{podName}] getReplicaEvents", response, response.Code()) + } +} + +// NewGetReplicaEventsOK creates a GetReplicaEventsOK with default headers values +func NewGetReplicaEventsOK() *GetReplicaEventsOK { + return &GetReplicaEventsOK{} +} + +/* +GetReplicaEventsOK describes a response with status code 200, with default header values. + +Successful get environment events +*/ +type GetReplicaEventsOK struct { + Payload []*models.Event +} + +// IsSuccess returns true when this get replica events o k response has a 2xx status code +func (o *GetReplicaEventsOK) IsSuccess() bool { + return true +} + +// IsRedirect returns true when this get replica events o k response has a 3xx status code +func (o *GetReplicaEventsOK) IsRedirect() bool { + return false +} + +// IsClientError returns true when this get replica events o k response has a 4xx status code +func (o *GetReplicaEventsOK) IsClientError() bool { + return false +} + +// IsServerError returns true when this get replica events o k response has a 5xx status code +func (o *GetReplicaEventsOK) IsServerError() bool { + return false +} + +// IsCode returns true when this get replica events o k response a status code equal to that given +func (o *GetReplicaEventsOK) IsCode(code int) bool { + return code == 200 +} + +// Code gets the status code for the get replica events o k response +func (o *GetReplicaEventsOK) Code() int { + return 200 +} + +func (o *GetReplicaEventsOK) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[GET /applications/{appName}/environments/{envName}/events/components/{componentName}/replicas/{podName}][%d] getReplicaEventsOK %s", 200, payload) +} + +func (o *GetReplicaEventsOK) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[GET /applications/{appName}/environments/{envName}/events/components/{componentName}/replicas/{podName}][%d] getReplicaEventsOK %s", 200, payload) +} + +func (o *GetReplicaEventsOK) GetPayload() []*models.Event { + return o.Payload +} + +func (o *GetReplicaEventsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetReplicaEventsUnauthorized creates a GetReplicaEventsUnauthorized with default headers values +func NewGetReplicaEventsUnauthorized() *GetReplicaEventsUnauthorized { + return &GetReplicaEventsUnauthorized{} +} + +/* +GetReplicaEventsUnauthorized describes a response with status code 401, with default header values. + +Unauthorized +*/ +type GetReplicaEventsUnauthorized struct { +} + +// IsSuccess returns true when this get replica events unauthorized response has a 2xx status code +func (o *GetReplicaEventsUnauthorized) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this get replica events unauthorized response has a 3xx status code +func (o *GetReplicaEventsUnauthorized) IsRedirect() bool { + return false +} + +// IsClientError returns true when this get replica events unauthorized response has a 4xx status code +func (o *GetReplicaEventsUnauthorized) IsClientError() bool { + return true +} + +// IsServerError returns true when this get replica events unauthorized response has a 5xx status code +func (o *GetReplicaEventsUnauthorized) IsServerError() bool { + return false +} + +// IsCode returns true when this get replica events unauthorized response a status code equal to that given +func (o *GetReplicaEventsUnauthorized) IsCode(code int) bool { + return code == 401 +} + +// Code gets the status code for the get replica events unauthorized response +func (o *GetReplicaEventsUnauthorized) Code() int { + return 401 +} + +func (o *GetReplicaEventsUnauthorized) Error() string { + return fmt.Sprintf("[GET /applications/{appName}/environments/{envName}/events/components/{componentName}/replicas/{podName}][%d] getReplicaEventsUnauthorized", 401) +} + +func (o *GetReplicaEventsUnauthorized) String() string { + return fmt.Sprintf("[GET /applications/{appName}/environments/{envName}/events/components/{componentName}/replicas/{podName}][%d] getReplicaEventsUnauthorized", 401) +} + +func (o *GetReplicaEventsUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + return nil +} + +// NewGetReplicaEventsNotFound creates a GetReplicaEventsNotFound with default headers values +func NewGetReplicaEventsNotFound() *GetReplicaEventsNotFound { + return &GetReplicaEventsNotFound{} +} + +/* +GetReplicaEventsNotFound describes a response with status code 404, with default header values. + +Not found +*/ +type GetReplicaEventsNotFound struct { +} + +// IsSuccess returns true when this get replica events not found response has a 2xx status code +func (o *GetReplicaEventsNotFound) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this get replica events not found response has a 3xx status code +func (o *GetReplicaEventsNotFound) IsRedirect() bool { + return false +} + +// IsClientError returns true when this get replica events not found response has a 4xx status code +func (o *GetReplicaEventsNotFound) IsClientError() bool { + return true +} + +// IsServerError returns true when this get replica events not found response has a 5xx status code +func (o *GetReplicaEventsNotFound) IsServerError() bool { + return false +} + +// IsCode returns true when this get replica events not found response a status code equal to that given +func (o *GetReplicaEventsNotFound) IsCode(code int) bool { + return code == 404 +} + +// Code gets the status code for the get replica events not found response +func (o *GetReplicaEventsNotFound) Code() int { + return 404 +} + +func (o *GetReplicaEventsNotFound) Error() string { + return fmt.Sprintf("[GET /applications/{appName}/environments/{envName}/events/components/{componentName}/replicas/{podName}][%d] getReplicaEventsNotFound", 404) +} + +func (o *GetReplicaEventsNotFound) String() string { + return fmt.Sprintf("[GET /applications/{appName}/environments/{envName}/events/components/{componentName}/replicas/{podName}][%d] getReplicaEventsNotFound", 404) +} + +func (o *GetReplicaEventsNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + return nil +} diff --git a/generated-client/models/deployment.go b/generated-client/models/deployment.go index 5675793..62176f6 100644 --- a/generated-client/models/deployment.go +++ b/generated-client/models/deployment.go @@ -28,6 +28,10 @@ type Deployment struct { // Example: 2006-01-02T15:04:05Z ActiveTo string `json:"activeTo,omitempty"` + // Name of the branch used to build the deployment + // Example: main + BuiltFromBranch string `json:"builtFromBranch,omitempty"` + // Array of components Components []*Component `json:"components"` diff --git a/generated-client/models/deployment_summary.go b/generated-client/models/deployment_summary.go index 46e9364..197ca3f 100644 --- a/generated-client/models/deployment_summary.go +++ b/generated-client/models/deployment_summary.go @@ -30,6 +30,10 @@ type DeploymentSummary struct { // Example: 2006-01-02T15:04:05Z ActiveTo string `json:"activeTo,omitempty"` + // Name of the branch used to build the deployment + // Example: main + BuiltFromBranch string `json:"builtFromBranch,omitempty"` + // CommitID the commit ID of the branch to build // Example: 4faca8595c5283a9d0f17a623b9255a0d9866a2e CommitID string `json:"commitID,omitempty"` diff --git a/generated-client/models/deployment_summary_pipeline_job_info.go b/generated-client/models/deployment_summary_pipeline_job_info.go index a826314..c89c60d 100644 --- a/generated-client/models/deployment_summary_pipeline_job_info.go +++ b/generated-client/models/deployment_summary_pipeline_job_info.go @@ -20,6 +20,10 @@ import ( // swagger:model DeploymentSummaryPipelineJobInfo type DeploymentSummaryPipelineJobInfo struct { + // Name of the branch used to build the deployment + // Example: main + BuiltFromBranch string `json:"builtFromBranch,omitempty"` + // CommitID the commit ID of the branch to build // Example: 4faca8595c5283a9d0f17a623b9255a0d9866a2e CommitID string `json:"commitID,omitempty"` diff --git a/generated-client/models/ingress_rule.go b/generated-client/models/ingress_rule.go new file mode 100644 index 0000000..d5b0eee --- /dev/null +++ b/generated-client/models/ingress_rule.go @@ -0,0 +1,59 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// IngressRule IngressRule specs +// +// swagger:model IngressRule +type IngressRule struct { + + // The host name of the ingress + Host string `json:"host,omitempty"` + + // The path of the ingress + Path string `json:"path,omitempty"` + + // The port of the ingress + Port int32 `json:"port,omitempty"` + + // The service name of the ingress + Service string `json:"service,omitempty"` +} + +// Validate validates this ingress rule +func (m *IngressRule) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this ingress rule based on context it is used +func (m *IngressRule) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *IngressRule) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *IngressRule) UnmarshalBinary(b []byte) error { + var res IngressRule + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/generated-client/models/job.go b/generated-client/models/job.go index 808707b..5f1175d 100644 --- a/generated-client/models/job.go +++ b/generated-client/models/job.go @@ -38,6 +38,10 @@ type Job struct { // Example: 2006-01-02T15:04:05Z Created string `json:"created,omitempty"` + // DeployedToEnvironment the name of the environment that was deployed to + // Example: qa + DeployedToEnvironment string `json:"deployedToEnvironment,omitempty"` + // Array of deployments Deployments []*DeploymentSummary `json:"deployments"` diff --git a/generated-client/models/object_state.go b/generated-client/models/object_state.go index f298cf5..a859992 100644 --- a/generated-client/models/object_state.go +++ b/generated-client/models/object_state.go @@ -7,6 +7,7 @@ package models import ( "context" + "strconv" "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" @@ -18,6 +19,9 @@ import ( // swagger:model ObjectState type ObjectState struct { + // Details about the ingress rules for an ingress related event + IngressRules []*IngressRule `json:"ingressRules"` + // pod Pod *PodState `json:"pod,omitempty"` } @@ -26,6 +30,10 @@ type ObjectState struct { func (m *ObjectState) Validate(formats strfmt.Registry) error { var res []error + if err := m.validateIngressRules(formats); err != nil { + res = append(res, err) + } + if err := m.validatePod(formats); err != nil { res = append(res, err) } @@ -36,6 +44,32 @@ func (m *ObjectState) Validate(formats strfmt.Registry) error { return nil } +func (m *ObjectState) validateIngressRules(formats strfmt.Registry) error { + if swag.IsZero(m.IngressRules) { // not required + return nil + } + + for i := 0; i < len(m.IngressRules); i++ { + if swag.IsZero(m.IngressRules[i]) { // not required + continue + } + + if m.IngressRules[i] != nil { + if err := m.IngressRules[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("ingressRules" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("ingressRules" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + func (m *ObjectState) validatePod(formats strfmt.Registry) error { if swag.IsZero(m.Pod) { // not required return nil @@ -59,6 +93,10 @@ func (m *ObjectState) validatePod(formats strfmt.Registry) error { func (m *ObjectState) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error + if err := m.contextValidateIngressRules(ctx, formats); err != nil { + res = append(res, err) + } + if err := m.contextValidatePod(ctx, formats); err != nil { res = append(res, err) } @@ -69,6 +107,31 @@ func (m *ObjectState) ContextValidate(ctx context.Context, formats strfmt.Regist return nil } +func (m *ObjectState) contextValidateIngressRules(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.IngressRules); i++ { + + if m.IngressRules[i] != nil { + + if swag.IsZero(m.IngressRules[i]) { // not required + return nil + } + + if err := m.IngressRules[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("ingressRules" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("ingressRules" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + func (m *ObjectState) contextValidatePod(ctx context.Context, formats strfmt.Registry) error { if m.Pod != nil { diff --git a/generated-client/models/pipeline_parameters_build.go b/generated-client/models/pipeline_parameters_build.go index 9edd0cc..3a26197 100644 --- a/generated-client/models/pipeline_parameters_build.go +++ b/generated-client/models/pipeline_parameters_build.go @@ -46,6 +46,10 @@ type PipelineParametersBuild struct { // Example: true PushImage string `json:"pushImage,omitempty"` + // Name of environment to build for + // Example: prod + ToEnvironment string `json:"toEnvironment,omitempty"` + // TriggeredBy of the job - if empty will use user token upn (user principle name) // Example: a_user@equinor.com TriggeredBy string `json:"triggeredBy,omitempty"` diff --git a/go.mod b/go.mod index 8f47952..e1fece0 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,8 @@ toolchain go1.22.5 require ( github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 - github.com/equinor/radix-common v1.9.4 - github.com/equinor/radix-operator v1.58.3 + github.com/equinor/radix-common v1.9.5 + github.com/equinor/radix-operator v1.66.0 github.com/fatih/color v1.17.0 github.com/go-openapi/errors v0.22.0 github.com/go-openapi/runtime v0.28.0 diff --git a/go.sum b/go.sum index 49d2363..f1307b6 100644 --- a/go.sum +++ b/go.sum @@ -18,10 +18,10 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/emicklei/go-restful/v3 v3.12.1 h1:PJMDIM/ak7btuL8Ex0iYET9hxM3CI2sjZtzpL63nKAU= github.com/emicklei/go-restful/v3 v3.12.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= -github.com/equinor/radix-common v1.9.4 h1:ErSnB2tqlRwaQuQdaA0qzsReDtHDgubcvqRO098ncEw= -github.com/equinor/radix-common v1.9.4/go.mod h1:+g0Wj0D40zz29DjNkYKVmCVeYy4OsFWKI7Qi9rA6kpY= -github.com/equinor/radix-operator v1.58.3 h1:F4YhNkQ4uRONP125OTfG8hdy9PiyKlOWVO8/p2NIi70= -github.com/equinor/radix-operator v1.58.3/go.mod h1:DTPXOxU3uHPvji7qBGSK1b03iXROpX3l94kYjcOHkPM= +github.com/equinor/radix-common v1.9.5 h1:p1xldkYUoavwIMguoxxOyVkOXLPA6K8qMsgzeztQtQw= +github.com/equinor/radix-common v1.9.5/go.mod h1:+g0Wj0D40zz29DjNkYKVmCVeYy4OsFWKI7Qi9rA6kpY= +github.com/equinor/radix-operator v1.66.0 h1:3gRM6mrmmaLMKnpF/hzfAFFuqeW8512XDlQRW1B0kXQ= +github.com/equinor/radix-operator v1.66.0/go.mod h1:bYXKrNGkeRL7ctqj4fwytRFsgHj4XR5ZRks7wXwqjXo= github.com/evanphx/json-patch v5.9.0+incompatible h1:fBXyNpNMuTTDdquAq/uisOr2lShz4oaXpDTX2bLe7ls= github.com/evanphx/json-patch v5.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg= From db7a0ef3337d0409893cbb6880d0f28c78507441 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Mon, 11 Nov 2024 16:13:14 +0100 Subject: [PATCH 2/4] Added external DNS aliases option to the apply-config --- cmd/createApplyConfigPipelineJob.go | 16 ++- generated-client/models/deployment_summary.go | 7 +- .../deployment_summary_pipeline_job_info.go | 7 +- generated-client/models/job.go | 13 ++- generated-client/models/job_summary.go | 10 +- .../pipeline_parameters_apply_config.go | 3 + .../models/pipeline_parameters_build.go | 3 + pkg/flagnames/names.go | 97 ++++++++++--------- 8 files changed, 96 insertions(+), 60 deletions(-) diff --git a/cmd/createApplyConfigPipelineJob.go b/cmd/createApplyConfigPipelineJob.go index 2f6af91..3fdcafd 100644 --- a/cmd/createApplyConfigPipelineJob.go +++ b/cmd/createApplyConfigPipelineJob.go @@ -22,21 +22,27 @@ import ( "github.com/equinor/radix-cli/pkg/client" "github.com/equinor/radix-cli/pkg/config" "github.com/equinor/radix-cli/pkg/flagnames" + "github.com/equinor/radix-cli/pkg/model" "github.com/equinor/radix-cli/pkg/utils/completion" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) +var deployExternalDNSAlias model.BoolPtr + var createApplyConfigPipelineJobCmd = &cobra.Command{ Use: "apply-config", Short: "Will trigger apply-config of a Radix application", Long: "Triggers applyConfig of a Radix application according to the radix config in its repository's master branch.", Example: ` # Create a Radix pipeline apply-config job to apply the radixconfig properties without re-building or re-deploying components. -Currently applied changes in properties DNS alias, build secrets, create new or soft-delete existing environments. +By default it is applied changes in properties DNS alias, build secrets, create new or soft-delete existing environments. rx create job apply-config --application radix-test - + # Create a Radix pipeline applyConfig-only job, short option versions - rx create job apply-config -a radix-test`, + rx create job apply-config -a radix-test + + # Create a Radix pipeline apply-config job with external DNS aliases + rx create job apply-config -a radix-test --deploy-external-dns-alias true`, RunE: func(cmd *cobra.Command, args []string) error { var errs []error appName, err := config.GetAppNameFromConfigOrFromParameter(cmd, flagnames.Application) @@ -68,7 +74,8 @@ Currently applied changes in properties DNS alias, build secrets, create new or triggerPipelineParams := application.NewTriggerPipelineApplyConfigParams() triggerPipelineParams.SetAppName(appName) parametersApplyConfig := models.PipelineParametersApplyConfig{ - TriggeredBy: triggeredByUser, + TriggeredBy: triggeredByUser, + DeployExternalDNS: deployExternalDNSAlias.Get(), } triggerPipelineParams.SetPipelineParametersApplyConfig(¶metersApplyConfig) @@ -89,6 +96,7 @@ Currently applied changes in properties DNS alias, build secrets, create new or func init() { createJobCmd.AddCommand(createApplyConfigPipelineJobCmd) createApplyConfigPipelineJobCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application to apply-config") + createApplyConfigPipelineJobCmd.Flags().Var(&deployExternalDNSAlias, flagnames.DeployExternalDNSAlias, "Optional. Deploy changes in External DNS aliases. Default is false.") createApplyConfigPipelineJobCmd.Flags().StringP(flagnames.User, "u", "", "The user who triggered the apply-config") createApplyConfigPipelineJobCmd.Flags().BoolP(flagnames.Follow, "f", false, "Follow applyConfig") _ = createApplyConfigPipelineJobCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.ApplicationCompletion) diff --git a/generated-client/models/deployment_summary.go b/generated-client/models/deployment_summary.go index 197ca3f..7d2ac57 100644 --- a/generated-client/models/deployment_summary.go +++ b/generated-client/models/deployment_summary.go @@ -64,7 +64,7 @@ type DeploymentSummary struct { // Type of pipeline job // Example: build-deploy - // Enum: ["build","build-deploy","promote","deploy"] + // Enum: ["build","build-deploy","promote","deploy","apply-config"] PipelineJobType string `json:"pipelineJobType,omitempty"` // Name of the environment the deployment was promoted from @@ -160,7 +160,7 @@ var deploymentSummaryTypePipelineJobTypePropEnum []interface{} func init() { var res []string - if err := json.Unmarshal([]byte(`["build","build-deploy","promote","deploy"]`), &res); err != nil { + if err := json.Unmarshal([]byte(`["build","build-deploy","promote","deploy","apply-config"]`), &res); err != nil { panic(err) } for _, v := range res { @@ -181,6 +181,9 @@ const ( // DeploymentSummaryPipelineJobTypeDeploy captures enum value "deploy" DeploymentSummaryPipelineJobTypeDeploy string = "deploy" + + // DeploymentSummaryPipelineJobTypeApplyDashConfig captures enum value "apply-config" + DeploymentSummaryPipelineJobTypeApplyDashConfig string = "apply-config" ) // prop value enum diff --git a/generated-client/models/deployment_summary_pipeline_job_info.go b/generated-client/models/deployment_summary_pipeline_job_info.go index c89c60d..09fbed7 100644 --- a/generated-client/models/deployment_summary_pipeline_job_info.go +++ b/generated-client/models/deployment_summary_pipeline_job_info.go @@ -33,7 +33,7 @@ type DeploymentSummaryPipelineJobInfo struct { // Type of pipeline job // Example: build-deploy - // Enum: ["build","build-deploy","promote","deploy"] + // Enum: ["build","build-deploy","promote","deploy","apply-config"] PipelineJobType string `json:"pipelineJobType,omitempty"` // Name of the environment the deployment was promoted from @@ -60,7 +60,7 @@ var deploymentSummaryPipelineJobInfoTypePipelineJobTypePropEnum []interface{} func init() { var res []string - if err := json.Unmarshal([]byte(`["build","build-deploy","promote","deploy"]`), &res); err != nil { + if err := json.Unmarshal([]byte(`["build","build-deploy","promote","deploy","apply-config"]`), &res); err != nil { panic(err) } for _, v := range res { @@ -81,6 +81,9 @@ const ( // DeploymentSummaryPipelineJobInfoPipelineJobTypeDeploy captures enum value "deploy" DeploymentSummaryPipelineJobInfoPipelineJobTypeDeploy string = "deploy" + + // DeploymentSummaryPipelineJobInfoPipelineJobTypeApplyDashConfig captures enum value "apply-config" + DeploymentSummaryPipelineJobInfoPipelineJobTypeApplyDashConfig string = "apply-config" ) // prop value enum diff --git a/generated-client/models/job.go b/generated-client/models/job.go index 5f1175d..83598bf 100644 --- a/generated-client/models/job.go +++ b/generated-client/models/job.go @@ -38,6 +38,9 @@ type Job struct { // Example: 2006-01-02T15:04:05Z Created string `json:"created,omitempty"` + // DeployExternalDNS deploy external DNS + DeployExternalDNS *bool `json:"deployExternalDNS,omitempty"` + // DeployedToEnvironment the name of the environment that was deployed to // Example: qa DeployedToEnvironment string `json:"deployedToEnvironment,omitempty"` @@ -57,9 +60,12 @@ type Job struct { // Example: radix-pipeline-20181029135644-algpv-6hznh Name string `json:"name,omitempty"` + // OverrideUseBuildCache override default or configured build cache option + OverrideUseBuildCache *bool `json:"overrideUseBuildCache,omitempty"` + // Name of the pipeline // Example: build-deploy - // Enum: ["build","build-deploy","promote","deploy"] + // Enum: ["build","build-deploy","promote","deploy","apply-config"] Pipeline string `json:"pipeline,omitempty"` // RadixDeployment name, which is promoted @@ -180,7 +186,7 @@ var jobTypePipelinePropEnum []interface{} func init() { var res []string - if err := json.Unmarshal([]byte(`["build","build-deploy","promote","deploy"]`), &res); err != nil { + if err := json.Unmarshal([]byte(`["build","build-deploy","promote","deploy","apply-config"]`), &res); err != nil { panic(err) } for _, v := range res { @@ -201,6 +207,9 @@ const ( // JobPipelineDeploy captures enum value "deploy" JobPipelineDeploy string = "deploy" + + // JobPipelineApplyDashConfig captures enum value "apply-config" + JobPipelineApplyDashConfig string = "apply-config" ) // prop value enum diff --git a/generated-client/models/job_summary.go b/generated-client/models/job_summary.go index f68ab14..0393f58 100644 --- a/generated-client/models/job_summary.go +++ b/generated-client/models/job_summary.go @@ -36,6 +36,9 @@ type JobSummary struct { // Example: 2006-01-02T15:04:05Z Created string `json:"created,omitempty"` + // DeployExternalDNS deploy external DNS + DeployExternalDNS *bool `json:"deployExternalDNS,omitempty"` + // Ended timestamp // Example: 2006-01-02T15:04:05Z Ended string `json:"ended,omitempty"` @@ -57,7 +60,7 @@ type JobSummary struct { // Name of the pipeline // Example: build-deploy - // Enum: ["build","build-deploy","promote","deploy"] + // Enum: ["build","build-deploy","promote","deploy","apply-config"] Pipeline string `json:"pipeline,omitempty"` // RadixDeployment name, which is promoted @@ -105,7 +108,7 @@ var jobSummaryTypePipelinePropEnum []interface{} func init() { var res []string - if err := json.Unmarshal([]byte(`["build","build-deploy","promote","deploy"]`), &res); err != nil { + if err := json.Unmarshal([]byte(`["build","build-deploy","promote","deploy","apply-config"]`), &res); err != nil { panic(err) } for _, v := range res { @@ -126,6 +129,9 @@ const ( // JobSummaryPipelineDeploy captures enum value "deploy" JobSummaryPipelineDeploy string = "deploy" + + // JobSummaryPipelineApplyDashConfig captures enum value "apply-config" + JobSummaryPipelineApplyDashConfig string = "apply-config" ) // prop value enum diff --git a/generated-client/models/pipeline_parameters_apply_config.go b/generated-client/models/pipeline_parameters_apply_config.go index a8cc72d..740b58f 100644 --- a/generated-client/models/pipeline_parameters_apply_config.go +++ b/generated-client/models/pipeline_parameters_apply_config.go @@ -17,6 +17,9 @@ import ( // swagger:model PipelineParametersApplyConfig type PipelineParametersApplyConfig struct { + // DeployExternalDNS deploy external DNS + DeployExternalDNS *bool `json:"deployExternalDNS,omitempty"` + // TriggeredBy of the job - if empty will use user token upn (user principle name) // Example: a_user@equinor.com TriggeredBy string `json:"triggeredBy,omitempty"` diff --git a/generated-client/models/pipeline_parameters_build.go b/generated-client/models/pipeline_parameters_build.go index 3a26197..e2b3168 100644 --- a/generated-client/models/pipeline_parameters_build.go +++ b/generated-client/models/pipeline_parameters_build.go @@ -27,6 +27,9 @@ type PipelineParametersBuild struct { // Example: 4faca8595c5283a9d0f17a623b9255a0d9866a2e CommitID string `json:"commitID,omitempty"` + // DeployExternalDNS deploy external DNS + DeployExternalDNS *bool `json:"deployExternalDNS,omitempty"` + // ImageName of the component, without repository name and image-tag // Example: radix-component ImageName string `json:"imageName,omitempty"` diff --git a/pkg/flagnames/names.go b/pkg/flagnames/names.go index d79a6e9..307314c 100644 --- a/pkg/flagnames/names.go +++ b/pkg/flagnames/names.go @@ -1,52 +1,53 @@ package flagnames const ( - AcknowledgeWarnings = "acknowledge-warnings" - AdminADGroups = "ad-groups" - Alias = "alias" - ApiEnvironment = "api-environment" - Application = "application" - AwaitReconcile = "await-reconcile" - Branch = "branch" - Certificate = "certificate" - CertificateFromFile = "certificate-from-file" - Cluster = "cluster" - CommitID = "commitID" - Component = "component" - ConfigurationItem = "configuration-item" - ConfigBranch = "config-branch" - ConfigFile = "config-file" - Context = "context" - Deployment = "deployment" - Environment = "environment" - Follow = "follow" - FromConfig = "from-config" - FromEnvironment = "from-environment" - ImageTagName = "image-tag-name" - Job = "job" - Previous = "previous" - Print = "print" - PrivateKey = "private-key" - PrivateKeyFromFile = "private-key-from-file" - ReaderADGroups = "reader-ad-groups" - Replicas = "replicas" - Reset = "reset" - Repository = "repository" - Schema = "schema" - Secret = "secret" - SharedSecret = "shared-secret" - Duration = "duration" - Since = "since" - SkipValidation = "skip-validation" - StrictValidation = "strict-validation" - ToEnvironment = "to-environment" - TokenEnvironment = "token-environment" - TokenStdin = "token-stdin" - UseActiveDeployment = "use-active-deployment" - UseBuildCache = "use-build-cache" - UseDeviceCode = "use-device-code" - User = "user" - Variable = "variable" - Verbose = "verbose" - Value = "value" + AcknowledgeWarnings = "acknowledge-warnings" + AdminADGroups = "ad-groups" + Alias = "alias" + ApiEnvironment = "api-environment" + Application = "application" + DeployExternalDNSAlias = "deploy-external-dns-alias" + AwaitReconcile = "await-reconcile" + Branch = "branch" + Certificate = "certificate" + CertificateFromFile = "certificate-from-file" + Cluster = "cluster" + CommitID = "commitID" + Component = "component" + ConfigurationItem = "configuration-item" + ConfigBranch = "config-branch" + ConfigFile = "config-file" + Context = "context" + Deployment = "deployment" + Environment = "environment" + Follow = "follow" + FromConfig = "from-config" + FromEnvironment = "from-environment" + ImageTagName = "image-tag-name" + Job = "job" + Previous = "previous" + Print = "print" + PrivateKey = "private-key" + PrivateKeyFromFile = "private-key-from-file" + ReaderADGroups = "reader-ad-groups" + Replicas = "replicas" + Reset = "reset" + Repository = "repository" + Schema = "schema" + Secret = "secret" + SharedSecret = "shared-secret" + Duration = "duration" + Since = "since" + SkipValidation = "skip-validation" + StrictValidation = "strict-validation" + ToEnvironment = "to-environment" + TokenEnvironment = "token-environment" + TokenStdin = "token-stdin" + UseActiveDeployment = "use-active-deployment" + UseBuildCache = "use-build-cache" + UseDeviceCode = "use-device-code" + User = "user" + Variable = "variable" + Verbose = "verbose" + Value = "value" ) From 7b28c46ce009ec6c0614a594b05ec71114404630 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Tue, 12 Nov 2024 09:33:30 +0100 Subject: [PATCH 3/4] Update cmd/createApplyConfigPipelineJob.go Co-authored-by: Richard Hagen --- cmd/createApplyConfigPipelineJob.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/createApplyConfigPipelineJob.go b/cmd/createApplyConfigPipelineJob.go index 3fdcafd..47eb204 100644 --- a/cmd/createApplyConfigPipelineJob.go +++ b/cmd/createApplyConfigPipelineJob.go @@ -35,7 +35,7 @@ var createApplyConfigPipelineJobCmd = &cobra.Command{ Short: "Will trigger apply-config of a Radix application", Long: "Triggers applyConfig of a Radix application according to the radix config in its repository's master branch.", Example: ` # Create a Radix pipeline apply-config job to apply the radixconfig properties without re-building or re-deploying components. -By default it is applied changes in properties DNS alias, build secrets, create new or soft-delete existing environments. +By default it applies changes to properties DNS alias, build secrets, and create new or soft-delete existing environments. rx create job apply-config --application radix-test # Create a Radix pipeline applyConfig-only job, short option versions From b1c3be43ff40b2148e8e2dbc5753a0eeae1d418c Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Tue, 12 Nov 2024 09:33:57 +0100 Subject: [PATCH 4/4] Added error handling --- cmd/createBuildDeployPipelineJob.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/createBuildDeployPipelineJob.go b/cmd/createBuildDeployPipelineJob.go index 3ceaf3a..6170add 100644 --- a/cmd/createBuildDeployPipelineJob.go +++ b/cmd/createBuildDeployPipelineJob.go @@ -63,6 +63,10 @@ var createBuildDeployApplicationCmd = &cobra.Command{ if appName == "" || branch == "" { errs = append(errs, errors.New("application name and branch are required")) } + if len(errs) > 0 { + return errors.Join(errs...) + } + cmd.SilenceUsage = true apiClient, err := client.GetForCommand(cmd)