From fc24c4f82103aed0c91a96428d5af8504d7e3ac5 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Mon, 23 Sep 2024 08:19:28 +0200 Subject: [PATCH 1/7] Added resources endpoint --- .../client/application/application_client.go | 41 ++ .../application/get_resources_parameters.go | 373 ++++++++++++++++++ .../application/get_resources_responses.go | 168 ++++++++ generated-client/models/used_resource.go | 71 ++++ generated-client/models/used_resources.go | 200 ++++++++++ 5 files changed, 853 insertions(+) create mode 100644 generated-client/client/application/get_resources_parameters.go create mode 100644 generated-client/client/application/get_resources_responses.go create mode 100644 generated-client/models/used_resource.go create mode 100644 generated-client/models/used_resources.go diff --git a/generated-client/client/application/application_client.go b/generated-client/client/application/application_client.go index 42f7e0f..42bfc77 100644 --- a/generated-client/client/application/application_client.go +++ b/generated-client/client/application/application_client.go @@ -76,6 +76,8 @@ type ClientService interface { GetPrivateImageHubs(params *GetPrivateImageHubsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetPrivateImageHubsOK, error) + GetResources(params *GetResourcesParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetResourcesOK, error) + IsDeployKeyValid(params *IsDeployKeyValidParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*IsDeployKeyValidOK, error) ListPipelines(params *ListPipelinesParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ListPipelinesOK, error) @@ -501,6 +503,45 @@ func (a *Client) GetPrivateImageHubs(params *GetPrivateImageHubsParams, authInfo panic(msg) } +/* +GetResources gets used resources for the application +*/ +func (a *Client) GetResources(params *GetResourcesParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetResourcesOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewGetResourcesParams() + } + op := &runtime.ClientOperation{ + ID: "getResources", + Method: "GET", + PathPattern: "/applications/{appName}/resources", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http", "https"}, + Params: params, + Reader: &GetResourcesReader{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.(*GetResourcesOK) + 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 getResources: API contract not enforced by server. Client expected to get an error, but got: %T", result) + panic(msg) +} + /* IsDeployKeyValid checks if the deploy key is correctly setup for application by cloning the repository */ diff --git a/generated-client/client/application/get_resources_parameters.go b/generated-client/client/application/get_resources_parameters.go new file mode 100644 index 0000000..3cf88ef --- /dev/null +++ b/generated-client/client/application/get_resources_parameters.go @@ -0,0 +1,373 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package application + +// 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" +) + +// NewGetResourcesParams creates a new GetResourcesParams 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 NewGetResourcesParams() *GetResourcesParams { + return &GetResourcesParams{ + timeout: cr.DefaultTimeout, + } +} + +// NewGetResourcesParamsWithTimeout creates a new GetResourcesParams object +// with the ability to set a timeout on a request. +func NewGetResourcesParamsWithTimeout(timeout time.Duration) *GetResourcesParams { + return &GetResourcesParams{ + timeout: timeout, + } +} + +// NewGetResourcesParamsWithContext creates a new GetResourcesParams object +// with the ability to set a context for a request. +func NewGetResourcesParamsWithContext(ctx context.Context) *GetResourcesParams { + return &GetResourcesParams{ + Context: ctx, + } +} + +// NewGetResourcesParamsWithHTTPClient creates a new GetResourcesParams object +// with the ability to set a custom HTTPClient for a request. +func NewGetResourcesParamsWithHTTPClient(client *http.Client) *GetResourcesParams { + return &GetResourcesParams{ + HTTPClient: client, + } +} + +/* +GetResourcesParams contains all the parameters to send to the API endpoint + + for the get resources operation. + + Typically these are written to a http.Request. +*/ +type GetResourcesParams 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 the application + */ + AppName string + + /* Component. + + Name of the application component in an environment + */ + Component *string + + /* Duration. + + Duration of the period, default is 30d (30 days). Example 10m, 1h, 2d, 3w, where m-minutes, h-hours, d-days, w-weeks + */ + Duration *string + + /* Environment. + + Name of the application environment + */ + Environment *string + + /* Ignorezero. + + Ignore metrics with zero value if true, default is false + + Format: boolean + */ + Ignorezero *string + + /* Since. + + End time-point of the period in the past, default is now. Example 10m, 1h, 2d, 3w, where m-minutes, h-hours, d-days, w-weeks + */ + Since *string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithDefaults hydrates default values in the get resources params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *GetResourcesParams) WithDefaults() *GetResourcesParams { + o.SetDefaults() + return o +} + +// SetDefaults hydrates default values in the get resources params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *GetResourcesParams) SetDefaults() { + // no default values defined for this parameter +} + +// WithTimeout adds the timeout to the get resources params +func (o *GetResourcesParams) WithTimeout(timeout time.Duration) *GetResourcesParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get resources params +func (o *GetResourcesParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get resources params +func (o *GetResourcesParams) WithContext(ctx context.Context) *GetResourcesParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get resources params +func (o *GetResourcesParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get resources params +func (o *GetResourcesParams) WithHTTPClient(client *http.Client) *GetResourcesParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get resources params +func (o *GetResourcesParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithImpersonateGroup adds the impersonateGroup to the get resources params +func (o *GetResourcesParams) WithImpersonateGroup(impersonateGroup *string) *GetResourcesParams { + o.SetImpersonateGroup(impersonateGroup) + return o +} + +// SetImpersonateGroup adds the impersonateGroup to the get resources params +func (o *GetResourcesParams) SetImpersonateGroup(impersonateGroup *string) { + o.ImpersonateGroup = impersonateGroup +} + +// WithImpersonateUser adds the impersonateUser to the get resources params +func (o *GetResourcesParams) WithImpersonateUser(impersonateUser *string) *GetResourcesParams { + o.SetImpersonateUser(impersonateUser) + return o +} + +// SetImpersonateUser adds the impersonateUser to the get resources params +func (o *GetResourcesParams) SetImpersonateUser(impersonateUser *string) { + o.ImpersonateUser = impersonateUser +} + +// WithAppName adds the appName to the get resources params +func (o *GetResourcesParams) WithAppName(appName string) *GetResourcesParams { + o.SetAppName(appName) + return o +} + +// SetAppName adds the appName to the get resources params +func (o *GetResourcesParams) SetAppName(appName string) { + o.AppName = appName +} + +// WithComponent adds the component to the get resources params +func (o *GetResourcesParams) WithComponent(component *string) *GetResourcesParams { + o.SetComponent(component) + return o +} + +// SetComponent adds the component to the get resources params +func (o *GetResourcesParams) SetComponent(component *string) { + o.Component = component +} + +// WithDuration adds the duration to the get resources params +func (o *GetResourcesParams) WithDuration(duration *string) *GetResourcesParams { + o.SetDuration(duration) + return o +} + +// SetDuration adds the duration to the get resources params +func (o *GetResourcesParams) SetDuration(duration *string) { + o.Duration = duration +} + +// WithEnvironment adds the environment to the get resources params +func (o *GetResourcesParams) WithEnvironment(environment *string) *GetResourcesParams { + o.SetEnvironment(environment) + return o +} + +// SetEnvironment adds the environment to the get resources params +func (o *GetResourcesParams) SetEnvironment(environment *string) { + o.Environment = environment +} + +// WithIgnorezero adds the ignorezero to the get resources params +func (o *GetResourcesParams) WithIgnorezero(ignorezero *string) *GetResourcesParams { + o.SetIgnorezero(ignorezero) + return o +} + +// SetIgnorezero adds the ignorezero to the get resources params +func (o *GetResourcesParams) SetIgnorezero(ignorezero *string) { + o.Ignorezero = ignorezero +} + +// WithSince adds the since to the get resources params +func (o *GetResourcesParams) WithSince(since *string) *GetResourcesParams { + o.SetSince(since) + return o +} + +// SetSince adds the since to the get resources params +func (o *GetResourcesParams) SetSince(since *string) { + o.Since = since +} + +// WriteToRequest writes these params to a swagger request +func (o *GetResourcesParams) 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 + } + + if o.Component != nil { + + // query param component + var qrComponent string + + if o.Component != nil { + qrComponent = *o.Component + } + qComponent := qrComponent + if qComponent != "" { + + if err := r.SetQueryParam("component", qComponent); err != nil { + return err + } + } + } + + if o.Duration != nil { + + // query param duration + var qrDuration string + + if o.Duration != nil { + qrDuration = *o.Duration + } + qDuration := qrDuration + if qDuration != "" { + + if err := r.SetQueryParam("duration", qDuration); err != nil { + return err + } + } + } + + if o.Environment != nil { + + // query param environment + var qrEnvironment string + + if o.Environment != nil { + qrEnvironment = *o.Environment + } + qEnvironment := qrEnvironment + if qEnvironment != "" { + + if err := r.SetQueryParam("environment", qEnvironment); err != nil { + return err + } + } + } + + if o.Ignorezero != nil { + + // query param ignorezero + var qrIgnorezero string + + if o.Ignorezero != nil { + qrIgnorezero = *o.Ignorezero + } + qIgnorezero := qrIgnorezero + if qIgnorezero != "" { + + if err := r.SetQueryParam("ignorezero", qIgnorezero); err != nil { + return err + } + } + } + + if o.Since != nil { + + // query param since + var qrSince string + + if o.Since != nil { + qrSince = *o.Since + } + qSince := qrSince + if qSince != "" { + + if err := r.SetQueryParam("since", qSince); err != nil { + return err + } + } + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/generated-client/client/application/get_resources_responses.go b/generated-client/client/application/get_resources_responses.go new file mode 100644 index 0000000..99ea44a --- /dev/null +++ b/generated-client/client/application/get_resources_responses.go @@ -0,0 +1,168 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package application + +// 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" +) + +// GetResourcesReader is a Reader for the GetResources structure. +type GetResourcesReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *GetResourcesReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewGetResourcesOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + case 404: + result := NewGetResourcesNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + default: + return nil, runtime.NewAPIError("[GET /applications/{appName}/resources] getResources", response, response.Code()) + } +} + +// NewGetResourcesOK creates a GetResourcesOK with default headers values +func NewGetResourcesOK() *GetResourcesOK { + return &GetResourcesOK{} +} + +/* +GetResourcesOK describes a response with status code 200, with default header values. + +Successful trigger pipeline +*/ +type GetResourcesOK struct { + Payload *models.UsedResources +} + +// IsSuccess returns true when this get resources o k response has a 2xx status code +func (o *GetResourcesOK) IsSuccess() bool { + return true +} + +// IsRedirect returns true when this get resources o k response has a 3xx status code +func (o *GetResourcesOK) IsRedirect() bool { + return false +} + +// IsClientError returns true when this get resources o k response has a 4xx status code +func (o *GetResourcesOK) IsClientError() bool { + return false +} + +// IsServerError returns true when this get resources o k response has a 5xx status code +func (o *GetResourcesOK) IsServerError() bool { + return false +} + +// IsCode returns true when this get resources o k response a status code equal to that given +func (o *GetResourcesOK) IsCode(code int) bool { + return code == 200 +} + +// Code gets the status code for the get resources o k response +func (o *GetResourcesOK) Code() int { + return 200 +} + +func (o *GetResourcesOK) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[GET /applications/{appName}/resources][%d] getResourcesOK %s", 200, payload) +} + +func (o *GetResourcesOK) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[GET /applications/{appName}/resources][%d] getResourcesOK %s", 200, payload) +} + +func (o *GetResourcesOK) GetPayload() *models.UsedResources { + return o.Payload +} + +func (o *GetResourcesOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(models.UsedResources) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetResourcesNotFound creates a GetResourcesNotFound with default headers values +func NewGetResourcesNotFound() *GetResourcesNotFound { + return &GetResourcesNotFound{} +} + +/* +GetResourcesNotFound describes a response with status code 404, with default header values. + +Not found +*/ +type GetResourcesNotFound struct { +} + +// IsSuccess returns true when this get resources not found response has a 2xx status code +func (o *GetResourcesNotFound) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this get resources not found response has a 3xx status code +func (o *GetResourcesNotFound) IsRedirect() bool { + return false +} + +// IsClientError returns true when this get resources not found response has a 4xx status code +func (o *GetResourcesNotFound) IsClientError() bool { + return true +} + +// IsServerError returns true when this get resources not found response has a 5xx status code +func (o *GetResourcesNotFound) IsServerError() bool { + return false +} + +// IsCode returns true when this get resources not found response a status code equal to that given +func (o *GetResourcesNotFound) IsCode(code int) bool { + return code == 404 +} + +// Code gets the status code for the get resources not found response +func (o *GetResourcesNotFound) Code() int { + return 404 +} + +func (o *GetResourcesNotFound) Error() string { + return fmt.Sprintf("[GET /applications/{appName}/resources][%d] getResourcesNotFound", 404) +} + +func (o *GetResourcesNotFound) String() string { + return fmt.Sprintf("[GET /applications/{appName}/resources][%d] getResourcesNotFound", 404) +} + +func (o *GetResourcesNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + return nil +} diff --git a/generated-client/models/used_resource.go b/generated-client/models/used_resource.go new file mode 100644 index 0000000..abdcd66 --- /dev/null +++ b/generated-client/models/used_resource.go @@ -0,0 +1,71 @@ +// 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" +) + +// UsedResource UsedResource holds information about used resource +// +// swagger:model UsedResource +type UsedResource struct { + + // Average resource used + // Example: 120m + Average string `json:"average,omitempty"` + + // AvgActual actual precise resource used + // Example: 0.00012 + AvgActual float64 `json:"avgActual,omitempty"` + + // Max resource used + // Example: 120m + Max string `json:"max,omitempty"` + + // MaxActual actual precise resource used + // Example: 0.00037 + MaxActual float64 `json:"maxActual,omitempty"` + + // Min resource used + // Example: 120m + Min string `json:"min,omitempty"` + + // MinActual actual precise resource used + // Example: 0.00012 + MinActual float64 `json:"minActual,omitempty"` +} + +// Validate validates this used resource +func (m *UsedResource) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this used resource based on context it is used +func (m *UsedResource) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *UsedResource) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *UsedResource) UnmarshalBinary(b []byte) error { + var res UsedResource + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/generated-client/models/used_resources.go b/generated-client/models/used_resources.go new file mode 100644 index 0000000..4402ad4 --- /dev/null +++ b/generated-client/models/used_resources.go @@ -0,0 +1,200 @@ +// 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/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// UsedResources UsedResources holds information about used resources +// +// swagger:model UsedResources +type UsedResources struct { + + // From timestamp + // Example: 2006-01-02T15:04:05Z + // Required: true + From *string `json:"from"` + + // To timestamp + // Example: 2006-01-02T15:04:05Z + // Required: true + To *string `json:"to"` + + // Warning messages + Warnings []string `json:"warnings"` + + // cpu + CPU *UsedResource `json:"cpu,omitempty"` + + // memory + Memory *UsedResource `json:"memory,omitempty"` +} + +// Validate validates this used resources +func (m *UsedResources) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateFrom(formats); err != nil { + res = append(res, err) + } + + if err := m.validateTo(formats); err != nil { + res = append(res, err) + } + + if err := m.validateCPU(formats); err != nil { + res = append(res, err) + } + + if err := m.validateMemory(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *UsedResources) validateFrom(formats strfmt.Registry) error { + + if err := validate.Required("from", "body", m.From); err != nil { + return err + } + + return nil +} + +func (m *UsedResources) validateTo(formats strfmt.Registry) error { + + if err := validate.Required("to", "body", m.To); err != nil { + return err + } + + return nil +} + +func (m *UsedResources) validateCPU(formats strfmt.Registry) error { + if swag.IsZero(m.CPU) { // not required + return nil + } + + if m.CPU != nil { + if err := m.CPU.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("cpu") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("cpu") + } + return err + } + } + + return nil +} + +func (m *UsedResources) validateMemory(formats strfmt.Registry) error { + if swag.IsZero(m.Memory) { // not required + return nil + } + + if m.Memory != nil { + if err := m.Memory.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("memory") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("memory") + } + return err + } + } + + return nil +} + +// ContextValidate validate this used resources based on the context it is used +func (m *UsedResources) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateCPU(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateMemory(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *UsedResources) contextValidateCPU(ctx context.Context, formats strfmt.Registry) error { + + if m.CPU != nil { + + if swag.IsZero(m.CPU) { // not required + return nil + } + + if err := m.CPU.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("cpu") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("cpu") + } + return err + } + } + + return nil +} + +func (m *UsedResources) contextValidateMemory(ctx context.Context, formats strfmt.Registry) error { + + if m.Memory != nil { + + if swag.IsZero(m.Memory) { // not required + return nil + } + + if err := m.Memory.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("memory") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("memory") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (m *UsedResources) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *UsedResources) UnmarshalBinary(b []byte) error { + var res UsedResources + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} From 4beda5c1065a14e308a281d3562d066d196232e8 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Mon, 23 Sep 2024 09:12:24 +0200 Subject: [PATCH 2/7] Added resources endpoint --- cmd/getResources.go | 106 +++++++++++++++++++++++++++++++++++++++ pkg/flagnames/names.go | 2 + pkg/settings/settings.go | 1 + 3 files changed, 109 insertions(+) create mode 100644 cmd/getResources.go diff --git a/cmd/getResources.go b/cmd/getResources.go new file mode 100644 index 0000000..a1bb587 --- /dev/null +++ b/cmd/getResources.go @@ -0,0 +1,106 @@ +// Copyright © 2023 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cmd + +import ( + "errors" + "fmt" + + "github.com/equinor/radix-cli/generated-client/client/application" + "github.com/equinor/radix-cli/pkg/client" + "github.com/equinor/radix-cli/pkg/flagnames" + "github.com/equinor/radix-cli/pkg/settings" + "github.com/equinor/radix-cli/pkg/utils/json" + "github.com/equinor/radix-common/utils/pointers" + "github.com/spf13/cobra" +) + +// getResourcesCmd represents the getResourcesCmd command +var getResourcesCmd = &cobra.Command{ + Use: "resources", + Short: "Gets resources used by the Radix application", + Long: `Gets resources used by the Radix application or its environment or a component`, + RunE: func(cmd *cobra.Command, args []string) error { + appName, err := getAppNameFromConfigOrFromParameter(cmd, flagnames.Application) + if err != nil { + return err + } + if appName == nil || *appName == "" { + return errors.New("application name is required field") + } + envName, err := cmd.Flags().GetString(flagnames.Environment) + if err != nil { + return err + } + componentName, err := cmd.Flags().GetString(flagnames.Component) + if err != nil { + return err + } + since, err := cmd.Flags().GetDuration(flagnames.Since) + if err != nil { + return err + } + duration, err := cmd.Flags().GetDuration(flagnames.Duration) + if err != nil { + return err + } + ignoreZeros, err := cmd.Flags().GetBool(flagnames.IgnoreZeros) + if err != nil { + return err + } + + getResourcesParams := application.NewGetResourcesParams() + getResourcesParams.SetAppName(*appName) + getResourcesParams.SetEnvironment(&envName) + getResourcesParams.SetComponent(&componentName) + if duration != settings.ZeroDuration { + getResourcesParams.SetDuration(pointers.Ptr(duration.String())) + } + if since != settings.ZeroDuration { + getResourcesParams.SetDuration(pointers.Ptr(since.String())) + } + if ignoreZeros { + getResourcesParams.SetIgnorezero(pointers.Ptr("true")) + } + + cmd.SilenceUsage = true + + apiClient, err := client.GetForCommand(cmd) + if err != nil { + return err + } + resp, err := apiClient.Application.GetResources(getResourcesParams, nil) + if err != nil { + return err + } + prettyJSON, err := json.Pretty(resp.Payload) + if err != nil { + return err + } + fmt.Println(*prettyJSON) + return nil + }, +} + +func init() { + getCmd.AddCommand(getResourcesCmd) + getResourcesCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application") + getResourcesCmd.Flags().StringP(flagnames.Environment, "e", "", "Optional, name of the environment") + getResourcesCmd.Flags().StringP(flagnames.Component, "n", "", "Optional, name of the component") + getResourcesCmd.Flags().Duration(flagnames.Duration, settings.ZeroDuration, "If set, get resources during the specified period (default is 30 days), eg. 5m or 12h") + getResourcesCmd.Flags().DurationP(flagnames.Since, "s", settings.ZeroDuration, "If set, get resources from the specified time, eg. 5m or 12h") + getResourcesCmd.Flags().Bool(flagnames.IgnoreZeros, false, "If set, metrics with zero value are not included to the output (default is false)") + setContextSpecificPersistentFlags(getResourcesCmd) +} diff --git a/pkg/flagnames/names.go b/pkg/flagnames/names.go index b731e15..a65b23d 100644 --- a/pkg/flagnames/names.go +++ b/pkg/flagnames/names.go @@ -35,6 +35,7 @@ const ( Schema = "schema" Secret = "secret" SharedSecret = "shared-secret" + Duration = "duration" Since = "since" SkipValidation = "skip-validation" StrictValidation = "strict-validation" @@ -48,4 +49,5 @@ const ( Variable = "variable" Verbose = "verbose" Value = "value" + IgnoreZeros = "ignorezero" ) diff --git a/pkg/settings/settings.go b/pkg/settings/settings.go index 8683f4e..b30f484 100644 --- a/pkg/settings/settings.go +++ b/pkg/settings/settings.go @@ -5,4 +5,5 @@ import "time" const ( DeltaRefreshApplication = 3 * time.Second DeltaTimeout = 30 * time.Second + ZeroDuration = 0 * time.Second ) From 9bdc13ff9b1f37713fe9e595391e276040038227 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Tue, 1 Oct 2024 15:58:02 +0200 Subject: [PATCH 3/7] Corrected resources command arguments --- cmd/getResources.go | 48 ++++---- .../application/get_resources_parameters.go | 36 ------ .../models/application_registration.go | 48 ++++++++ .../models/application_registration_patch.go | 6 + generated-client/models/component.go | 51 ++++++++ generated-client/models/ingress.go | 109 ++++++++++++++++++ generated-client/models/ingress_public.go | 71 ++++++++++++ generated-client/models/network.go | 109 ++++++++++++++++++ generated-client/models/port.go | 34 +++++- generated-client/models/used_resource.go | 22 +--- generated-client/models/used_resources.go | 2 +- pkg/settings/settings.go | 1 - 12 files changed, 461 insertions(+), 76 deletions(-) create mode 100644 generated-client/models/ingress.go create mode 100644 generated-client/models/ingress_public.go create mode 100644 generated-client/models/network.go diff --git a/cmd/getResources.go b/cmd/getResources.go index a1bb587..b4013d7 100644 --- a/cmd/getResources.go +++ b/cmd/getResources.go @@ -20,8 +20,8 @@ import ( "github.com/equinor/radix-cli/generated-client/client/application" "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/settings" "github.com/equinor/radix-cli/pkg/utils/json" "github.com/equinor/radix-common/utils/pointers" "github.com/spf13/cobra" @@ -32,12 +32,28 @@ var getResourcesCmd = &cobra.Command{ Use: "resources", Short: "Gets resources used by the Radix application", Long: `Gets resources used by the Radix application or its environment or a component`, + Example: ` +# Get resources used by the application for the last 30 days +rx get resources -a myapp + +# Get resources used by the application in the environment for the last 30 days +rx get resources -a myapp -e dev + +# Get resources used by the application in the environment for a component for the last 30 days +rx get resources -a myapp -e dev -n mycomponent + +# Get resources used by the application in the environment for a component for the last 5 minutes +rx get resources -a myapp -e dev -n mycomponent --duration 5m + +# Get resources used by the application in the environment for a component for the last 12 hours starting with two days ago +rx get resources -a myapp -e dev -n mycomponent --duration 12h --since 2d +`, RunE: func(cmd *cobra.Command, args []string) error { - appName, err := getAppNameFromConfigOrFromParameter(cmd, flagnames.Application) + appName, err := config.GetAppNameFromConfigOrFromParameter(cmd, flagnames.Application) if err != nil { return err } - if appName == nil || *appName == "" { + if appName == "" { return errors.New("application name is required field") } envName, err := cmd.Flags().GetString(flagnames.Environment) @@ -48,31 +64,24 @@ var getResourcesCmd = &cobra.Command{ if err != nil { return err } - since, err := cmd.Flags().GetDuration(flagnames.Since) + since, err := cmd.Flags().GetString(flagnames.Since) if err != nil { return err } - duration, err := cmd.Flags().GetDuration(flagnames.Duration) - if err != nil { - return err - } - ignoreZeros, err := cmd.Flags().GetBool(flagnames.IgnoreZeros) + duration, err := cmd.Flags().GetString(flagnames.Duration) if err != nil { return err } getResourcesParams := application.NewGetResourcesParams() - getResourcesParams.SetAppName(*appName) + getResourcesParams.SetAppName(appName) getResourcesParams.SetEnvironment(&envName) getResourcesParams.SetComponent(&componentName) - if duration != settings.ZeroDuration { - getResourcesParams.SetDuration(pointers.Ptr(duration.String())) - } - if since != settings.ZeroDuration { - getResourcesParams.SetDuration(pointers.Ptr(since.String())) + if duration != "" { + getResourcesParams.SetDuration(pointers.Ptr(duration)) } - if ignoreZeros { - getResourcesParams.SetIgnorezero(pointers.Ptr("true")) + if since != "" { + getResourcesParams.SetSince(pointers.Ptr(since)) } cmd.SilenceUsage = true @@ -99,8 +108,7 @@ func init() { getResourcesCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application") getResourcesCmd.Flags().StringP(flagnames.Environment, "e", "", "Optional, name of the environment") getResourcesCmd.Flags().StringP(flagnames.Component, "n", "", "Optional, name of the component") - getResourcesCmd.Flags().Duration(flagnames.Duration, settings.ZeroDuration, "If set, get resources during the specified period (default is 30 days), eg. 5m or 12h") - getResourcesCmd.Flags().DurationP(flagnames.Since, "s", settings.ZeroDuration, "If set, get resources from the specified time, eg. 5m or 12h") - getResourcesCmd.Flags().Bool(flagnames.IgnoreZeros, false, "If set, metrics with zero value are not included to the output (default is false)") + getResourcesCmd.Flags().String(flagnames.Duration, "", "If set, get resources during the specified period (default is 30 days), eg. 5m or 12h") + getResourcesCmd.Flags().String(flagnames.Since, "", "If set, get resources starting from the specified time in the past, eg. 5m or 12h") setContextSpecificPersistentFlags(getResourcesCmd) } diff --git a/generated-client/client/application/get_resources_parameters.go b/generated-client/client/application/get_resources_parameters.go index 3cf88ef..03639e3 100644 --- a/generated-client/client/application/get_resources_parameters.go +++ b/generated-client/client/application/get_resources_parameters.go @@ -97,14 +97,6 @@ type GetResourcesParams struct { */ Environment *string - /* Ignorezero. - - Ignore metrics with zero value if true, default is false - - Format: boolean - */ - Ignorezero *string - /* Since. End time-point of the period in the past, default is now. Example 10m, 1h, 2d, 3w, where m-minutes, h-hours, d-days, w-weeks @@ -230,17 +222,6 @@ func (o *GetResourcesParams) SetEnvironment(environment *string) { o.Environment = environment } -// WithIgnorezero adds the ignorezero to the get resources params -func (o *GetResourcesParams) WithIgnorezero(ignorezero *string) *GetResourcesParams { - o.SetIgnorezero(ignorezero) - return o -} - -// SetIgnorezero adds the ignorezero to the get resources params -func (o *GetResourcesParams) SetIgnorezero(ignorezero *string) { - o.Ignorezero = ignorezero -} - // WithSince adds the since to the get resources params func (o *GetResourcesParams) WithSince(since *string) *GetResourcesParams { o.SetSince(since) @@ -332,23 +313,6 @@ func (o *GetResourcesParams) WriteToRequest(r runtime.ClientRequest, reg strfmt. } } - if o.Ignorezero != nil { - - // query param ignorezero - var qrIgnorezero string - - if o.Ignorezero != nil { - qrIgnorezero = *o.Ignorezero - } - qIgnorezero := qrIgnorezero - if qIgnorezero != "" { - - if err := r.SetQueryParam("ignorezero", qIgnorezero); err != nil { - return err - } - } - } - if o.Since != nil { // query param since diff --git a/generated-client/models/application_registration.go b/generated-client/models/application_registration.go index 6f567e1..0835fc1 100644 --- a/generated-client/models/application_registration.go +++ b/generated-client/models/application_registration.go @@ -23,6 +23,10 @@ type ApplicationRegistration struct { // Required: true AdGroups []string `json:"adGroups"` + // AdUsers the users/service-principals that should be able to access the application + // Required: true + AdUsers []string `json:"adUsers"` + // ConfigBranch information // Required: true ConfigBranch *string `json:"configBranch"` @@ -49,8 +53,13 @@ type ApplicationRegistration struct { RadixConfigFullName string `json:"radixConfigFullName,omitempty"` // ReaderAdGroups the groups that should be able to read the application + // Required: true ReaderAdGroups []string `json:"readerAdGroups"` + // ReaderAdUsers the users/service-principals that should be able to read the application + // Required: true + ReaderAdUsers []string `json:"readerAdUsers"` + // Repository the github repository // Example: https://github.com/equinor/radix-canary-golang // Required: true @@ -72,6 +81,10 @@ func (m *ApplicationRegistration) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateAdUsers(formats); err != nil { + res = append(res, err) + } + if err := m.validateConfigBranch(formats); err != nil { res = append(res, err) } @@ -88,6 +101,14 @@ func (m *ApplicationRegistration) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateReaderAdGroups(formats); err != nil { + res = append(res, err) + } + + if err := m.validateReaderAdUsers(formats); err != nil { + res = append(res, err) + } + if err := m.validateRepository(formats); err != nil { res = append(res, err) } @@ -111,6 +132,15 @@ func (m *ApplicationRegistration) validateAdGroups(formats strfmt.Registry) erro return nil } +func (m *ApplicationRegistration) validateAdUsers(formats strfmt.Registry) error { + + if err := validate.Required("adUsers", "body", m.AdUsers); err != nil { + return err + } + + return nil +} + func (m *ApplicationRegistration) validateConfigBranch(formats strfmt.Registry) error { if err := validate.Required("configBranch", "body", m.ConfigBranch); err != nil { @@ -147,6 +177,24 @@ func (m *ApplicationRegistration) validateOwner(formats strfmt.Registry) error { return nil } +func (m *ApplicationRegistration) validateReaderAdGroups(formats strfmt.Registry) error { + + if err := validate.Required("readerAdGroups", "body", m.ReaderAdGroups); err != nil { + return err + } + + return nil +} + +func (m *ApplicationRegistration) validateReaderAdUsers(formats strfmt.Registry) error { + + if err := validate.Required("readerAdUsers", "body", m.ReaderAdUsers); err != nil { + return err + } + + return nil +} + func (m *ApplicationRegistration) validateRepository(formats strfmt.Registry) error { if err := validate.Required("repository", "body", m.Repository); err != nil { diff --git a/generated-client/models/application_registration_patch.go b/generated-client/models/application_registration_patch.go index 308bd98..0038eed 100644 --- a/generated-client/models/application_registration_patch.go +++ b/generated-client/models/application_registration_patch.go @@ -20,6 +20,9 @@ type ApplicationRegistrationPatch struct { // AdGroups the groups that should be able to access the application AdGroups []string `json:"adGroups"` + // AdUsers the users/service-principals that should be able to access the application + AdUsers []string `json:"adUsers"` + // ConfigBranch information ConfigBranch string `json:"configBranch,omitempty"` @@ -37,6 +40,9 @@ type ApplicationRegistrationPatch struct { // ReaderAdGroups the groups that should be able to read the application ReaderAdGroups []string `json:"readerAdGroups"` + // ReaderAdUsers the users/service-principals that should be able to read the application + ReaderAdUsers []string `json:"readerAdUsers"` + // Repository the github repository Repository string `json:"repository,omitempty"` diff --git a/generated-client/models/component.go b/generated-client/models/component.go index 2d7e74d..8184c0e 100644 --- a/generated-client/models/component.go +++ b/generated-client/models/component.go @@ -92,6 +92,9 @@ type Component struct { // identity Identity *Identity `json:"identity,omitempty"` + // network + Network *Network `json:"network,omitempty"` + // notifications Notifications *Notifications `json:"notifications,omitempty"` @@ -145,6 +148,10 @@ func (m *Component) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateNetwork(formats); err != nil { + res = append(res, err) + } + if err := m.validateNotifications(formats); err != nil { res = append(res, err) } @@ -395,6 +402,25 @@ func (m *Component) validateIdentity(formats strfmt.Registry) error { return nil } +func (m *Component) validateNetwork(formats strfmt.Registry) error { + if swag.IsZero(m.Network) { // not required + return nil + } + + if m.Network != nil { + if err := m.Network.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("network") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("network") + } + return err + } + } + + return nil +} + func (m *Component) validateNotifications(formats strfmt.Registry) error { if swag.IsZero(m.Notifications) { // not required return nil @@ -495,6 +521,10 @@ func (m *Component) ContextValidate(ctx context.Context, formats strfmt.Registry res = append(res, err) } + if err := m.contextValidateNetwork(ctx, formats); err != nil { + res = append(res, err) + } + if err := m.contextValidateNotifications(ctx, formats); err != nil { res = append(res, err) } @@ -634,6 +664,27 @@ func (m *Component) contextValidateIdentity(ctx context.Context, formats strfmt. return nil } +func (m *Component) contextValidateNetwork(ctx context.Context, formats strfmt.Registry) error { + + if m.Network != nil { + + if swag.IsZero(m.Network) { // not required + return nil + } + + if err := m.Network.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("network") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("network") + } + return err + } + } + + return nil +} + func (m *Component) contextValidateNotifications(ctx context.Context, formats strfmt.Registry) error { if m.Notifications != nil { diff --git a/generated-client/models/ingress.go b/generated-client/models/ingress.go new file mode 100644 index 0000000..51ec661 --- /dev/null +++ b/generated-client/models/ingress.go @@ -0,0 +1,109 @@ +// 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/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// Ingress Ingress describes ingress configuration for a component +// +// swagger:model Ingress +type Ingress struct { + + // public + Public *IngressPublic `json:"public,omitempty"` +} + +// Validate validates this ingress +func (m *Ingress) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validatePublic(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *Ingress) validatePublic(formats strfmt.Registry) error { + if swag.IsZero(m.Public) { // not required + return nil + } + + if m.Public != nil { + if err := m.Public.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("public") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("public") + } + return err + } + } + + return nil +} + +// ContextValidate validate this ingress based on the context it is used +func (m *Ingress) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidatePublic(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *Ingress) contextValidatePublic(ctx context.Context, formats strfmt.Registry) error { + + if m.Public != nil { + + if swag.IsZero(m.Public) { // not required + return nil + } + + if err := m.Public.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("public") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("public") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (m *Ingress) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *Ingress) UnmarshalBinary(b []byte) error { + var res Ingress + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/generated-client/models/ingress_public.go b/generated-client/models/ingress_public.go new file mode 100644 index 0000000..3e629f5 --- /dev/null +++ b/generated-client/models/ingress_public.go @@ -0,0 +1,71 @@ +// 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/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// IngressPublic IngressPublic describes public ingress configuration for a component +// +// swagger:model IngressPublic +type IngressPublic struct { + + // List of allowed IP addresses or CIDRs. All traffic is allowed if list is empty. + // Required: true + Allow []string `json:"allow"` +} + +// Validate validates this ingress public +func (m *IngressPublic) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateAllow(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *IngressPublic) validateAllow(formats strfmt.Registry) error { + + if err := validate.Required("allow", "body", m.Allow); err != nil { + return err + } + + return nil +} + +// ContextValidate validates this ingress public based on context it is used +func (m *IngressPublic) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *IngressPublic) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *IngressPublic) UnmarshalBinary(b []byte) error { + var res IngressPublic + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/generated-client/models/network.go b/generated-client/models/network.go new file mode 100644 index 0000000..ead516c --- /dev/null +++ b/generated-client/models/network.go @@ -0,0 +1,109 @@ +// 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/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// Network Network describes network configuration for a component +// +// swagger:model Network +type Network struct { + + // ingress + Ingress *Ingress `json:"ingress,omitempty"` +} + +// Validate validates this network +func (m *Network) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateIngress(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *Network) validateIngress(formats strfmt.Registry) error { + if swag.IsZero(m.Ingress) { // not required + return nil + } + + if m.Ingress != nil { + if err := m.Ingress.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("ingress") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("ingress") + } + return err + } + } + + return nil +} + +// ContextValidate validate this network based on the context it is used +func (m *Network) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateIngress(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *Network) contextValidateIngress(ctx context.Context, formats strfmt.Registry) error { + + if m.Ingress != nil { + + if swag.IsZero(m.Ingress) { // not required + return nil + } + + if err := m.Ingress.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("ingress") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("ingress") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (m *Network) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *Network) UnmarshalBinary(b []byte) error { + var res Network + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/generated-client/models/port.go b/generated-client/models/port.go index 7bd1f64..58a1727 100644 --- a/generated-client/models/port.go +++ b/generated-client/models/port.go @@ -19,6 +19,11 @@ import ( // swagger:model Port type Port struct { + // IsPublic indicates that the port is accessible from the Internet by proxying traffic from 443 + // Example: true + // Required: true + IsPublic *bool `json:"isPublic"` + // Component port name. From radixconfig.yaml // Example: http // Required: true @@ -26,23 +31,41 @@ type Port struct { // Component port number. From radixconfig.yaml // Example: 8080 - Port int32 `json:"port,omitempty"` + // Required: true + Port *int32 `json:"port"` } // Validate validates this port func (m *Port) Validate(formats strfmt.Registry) error { var res []error + if err := m.validateIsPublic(formats); err != nil { + res = append(res, err) + } + if err := m.validateName(formats); err != nil { res = append(res, err) } + if err := m.validatePort(formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil } +func (m *Port) validateIsPublic(formats strfmt.Registry) error { + + if err := validate.Required("isPublic", "body", m.IsPublic); err != nil { + return err + } + + return nil +} + func (m *Port) validateName(formats strfmt.Registry) error { if err := validate.Required("name", "body", m.Name); err != nil { @@ -52,6 +75,15 @@ func (m *Port) validateName(formats strfmt.Registry) error { return nil } +func (m *Port) validatePort(formats strfmt.Registry) error { + + if err := validate.Required("port", "body", m.Port); err != nil { + return err + } + + return nil +} + // ContextValidate validates this port based on context it is used func (m *Port) ContextValidate(ctx context.Context, formats strfmt.Registry) error { return nil diff --git a/generated-client/models/used_resource.go b/generated-client/models/used_resource.go index abdcd66..f8fd8e8 100644 --- a/generated-client/models/used_resource.go +++ b/generated-client/models/used_resource.go @@ -17,29 +17,17 @@ import ( // swagger:model UsedResource type UsedResource struct { - // Average resource used - // Example: 120m - Average string `json:"average,omitempty"` - - // AvgActual actual precise resource used - // Example: 0.00012 - AvgActual float64 `json:"avgActual,omitempty"` + // Avg Average resource used + // Example: 0.00023 + Avg float64 `json:"avg,omitempty"` // Max resource used - // Example: 120m - Max string `json:"max,omitempty"` - - // MaxActual actual precise resource used // Example: 0.00037 - MaxActual float64 `json:"maxActual,omitempty"` + Max float64 `json:"max,omitempty"` // Min resource used - // Example: 120m - Min string `json:"min,omitempty"` - - // MinActual actual precise resource used // Example: 0.00012 - MinActual float64 `json:"minActual,omitempty"` + Min float64 `json:"min,omitempty"` } // Validate validates this used resource diff --git a/generated-client/models/used_resources.go b/generated-client/models/used_resources.go index 4402ad4..461f9ba 100644 --- a/generated-client/models/used_resources.go +++ b/generated-client/models/used_resources.go @@ -25,7 +25,7 @@ type UsedResources struct { From *string `json:"from"` // To timestamp - // Example: 2006-01-02T15:04:05Z + // Example: 2006-01-03T15:04:05Z // Required: true To *string `json:"to"` diff --git a/pkg/settings/settings.go b/pkg/settings/settings.go index b30f484..8683f4e 100644 --- a/pkg/settings/settings.go +++ b/pkg/settings/settings.go @@ -5,5 +5,4 @@ import "time" const ( DeltaRefreshApplication = 3 * time.Second DeltaTimeout = 30 * time.Second - ZeroDuration = 0 * time.Second ) From 6b34a7462826e55faeef84bdc456606957f35865 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Tue, 1 Oct 2024 15:59:31 +0200 Subject: [PATCH 4/7] Removed outdated const --- pkg/flagnames/names.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/flagnames/names.go b/pkg/flagnames/names.go index a65b23d..d79a6e9 100644 --- a/pkg/flagnames/names.go +++ b/pkg/flagnames/names.go @@ -49,5 +49,4 @@ const ( Variable = "variable" Verbose = "verbose" Value = "value" - IgnoreZeros = "ignorezero" ) From 2c915300adf105d3469e8888014868c1a9fc524a Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Wed, 2 Oct 2024 09:33:24 +0200 Subject: [PATCH 5/7] Added flag completion --- cmd/getResources.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/getResources.go b/cmd/getResources.go index b4013d7..af2fc56 100644 --- a/cmd/getResources.go +++ b/cmd/getResources.go @@ -22,6 +22,7 @@ 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/utils/completion" "github.com/equinor/radix-cli/pkg/utils/json" "github.com/equinor/radix-common/utils/pointers" "github.com/spf13/cobra" @@ -110,5 +111,6 @@ func init() { getResourcesCmd.Flags().StringP(flagnames.Component, "n", "", "Optional, name of the component") getResourcesCmd.Flags().String(flagnames.Duration, "", "If set, get resources during the specified period (default is 30 days), eg. 5m or 12h") getResourcesCmd.Flags().String(flagnames.Since, "", "If set, get resources starting from the specified time in the past, eg. 5m or 12h") + _ = restartApplicationCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.ApplicationCompletion) setContextSpecificPersistentFlags(getResourcesCmd) } From 4d9cdf8794160712688a07fd2fb05bc027880c89 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Wed, 2 Oct 2024 14:32:50 +0200 Subject: [PATCH 6/7] Added flag completion --- cmd/getResources.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/getResources.go b/cmd/getResources.go index af2fc56..0e89a1b 100644 --- a/cmd/getResources.go +++ b/cmd/getResources.go @@ -112,5 +112,7 @@ func init() { getResourcesCmd.Flags().String(flagnames.Duration, "", "If set, get resources during the specified period (default is 30 days), eg. 5m or 12h") getResourcesCmd.Flags().String(flagnames.Since, "", "If set, get resources starting from the specified time in the past, eg. 5m or 12h") _ = restartApplicationCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.ApplicationCompletion) + _ = restartApplicationCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.EnvironmentCompletion) + _ = restartApplicationCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.ComponentCompletion) setContextSpecificPersistentFlags(getResourcesCmd) } From e23eaf3298eeaf80815f426f1ec7fde71afc56ec Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Wed, 2 Oct 2024 14:33:17 +0200 Subject: [PATCH 7/7] Added flag completion --- cmd/getResources.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/getResources.go b/cmd/getResources.go index 0e89a1b..a407a00 100644 --- a/cmd/getResources.go +++ b/cmd/getResources.go @@ -111,8 +111,8 @@ func init() { getResourcesCmd.Flags().StringP(flagnames.Component, "n", "", "Optional, name of the component") getResourcesCmd.Flags().String(flagnames.Duration, "", "If set, get resources during the specified period (default is 30 days), eg. 5m or 12h") getResourcesCmd.Flags().String(flagnames.Since, "", "If set, get resources starting from the specified time in the past, eg. 5m or 12h") - _ = restartApplicationCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.ApplicationCompletion) - _ = restartApplicationCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.EnvironmentCompletion) - _ = restartApplicationCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.ComponentCompletion) + _ = getResourcesCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.ApplicationCompletion) + _ = getResourcesCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.EnvironmentCompletion) + _ = getResourcesCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.ComponentCompletion) setContextSpecificPersistentFlags(getResourcesCmd) }