From dd4ac90e721ebdaf67f353eee28d1f69fcc22a3e Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Mon, 8 Jan 2024 13:07:38 +0100 Subject: [PATCH] remove unused cluster refs --- controller/api/v1alpha1/pipeline_types.go | 6 - .../api/v1alpha1/zz_generated.deepcopy.go | 25 ++-- .../deployments.plural.sh_pipelines.yaml | 88 +------------ controller/internal/client/console.go | 2 +- controller/internal/client/service.go | 2 +- .../internal/test/mocks/ConsoleClient_mock.go | 118 ++++++++++++++++-- 6 files changed, 128 insertions(+), 113 deletions(-) diff --git a/controller/api/v1alpha1/pipeline_types.go b/controller/api/v1alpha1/pipeline_types.go index 39c7a6c5e4..28cc2dfa6a 100644 --- a/controller/api/v1alpha1/pipeline_types.go +++ b/controller/api/v1alpha1/pipeline_types.go @@ -46,9 +46,6 @@ type PipelineStage struct { // PipelineStageService is the configuration of a service within a pipeline stage, // including optional promotion criteria. type PipelineStageService struct { - // ClusterRef of this service. - ClusterRef *v1.ObjectReference `json:"clusterRef,omitempty"` - ServiceRef *v1.ObjectReference `json:"serviceRef,omitempty"` Criteria *PipelineStageServicePromotionCriteria `json:"criteria,omitempty"` @@ -56,9 +53,6 @@ type PipelineStageService struct { // PipelineStageServicePromotionCriteria represents actions to perform if this stage service were promoted. type PipelineStageServicePromotionCriteria struct { - // ClusterRef of the Cluster for the source service. - ClusterRef *v1.ObjectReference `json:"clusterRef,omitempty"` - // ServiceRef pointing to source service to promote from. ServiceRef *v1.ObjectReference `json:"serviceRef,omitempty"` diff --git a/controller/api/v1alpha1/zz_generated.deepcopy.go b/controller/api/v1alpha1/zz_generated.deepcopy.go index 079c542c69..f844cec7ac 100644 --- a/controller/api/v1alpha1/zz_generated.deepcopy.go +++ b/controller/api/v1alpha1/zz_generated.deepcopy.go @@ -1007,11 +1007,6 @@ func (in *PipelineStage) DeepCopy() *PipelineStage { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PipelineStageService) DeepCopyInto(out *PipelineStageService) { *out = *in - if in.ClusterRef != nil { - in, out := &in.ClusterRef, &out.ClusterRef - *out = new(v1.ObjectReference) - **out = **in - } if in.ServiceRef != nil { in, out := &in.ServiceRef, &out.ServiceRef *out = new(v1.ObjectReference) @@ -1037,20 +1032,26 @@ func (in *PipelineStageService) DeepCopy() *PipelineStageService { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PipelineStageServicePromotionCriteria) DeepCopyInto(out *PipelineStageServicePromotionCriteria) { *out = *in - if in.ClusterRef != nil { - in, out := &in.ClusterRef, &out.ClusterRef - *out = new(v1.ObjectReference) - **out = **in - } if in.ServiceRef != nil { in, out := &in.ServiceRef, &out.ServiceRef *out = new(v1.ObjectReference) **out = **in } + if in.SourceID != nil { + in, out := &in.SourceID, &out.SourceID + *out = new(string) + **out = **in + } if in.Secrets != nil { in, out := &in.Secrets, &out.Secrets - *out = make([]string, len(*in)) - copy(*out, *in) + *out = make([]*string, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(string) + **out = **in + } + } } } diff --git a/controller/config/crd/bases/deployments.plural.sh_pipelines.yaml b/controller/config/crd/bases/deployments.plural.sh_pipelines.yaml index 60a85cf8b9..b82a8f4077 100644 --- a/controller/config/crd/bases/deployments.plural.sh_pipelines.yaml +++ b/controller/config/crd/bases/deployments.plural.sh_pipelines.yaml @@ -202,96 +202,10 @@ spec: a service within a pipeline stage, including optional promotion criteria. properties: - clusterRef: - description: ClusterRef of this service. - properties: - apiVersion: - description: API version of the referent. - type: string - fieldPath: - description: 'If referring to a piece of an object - instead of an entire object, this string should - contain a valid JSON/Go field access statement, - such as desiredState.manifest.containers[2]. For - example, if the object reference is to a container - within a pod, this would take on a value like: "spec.containers{name}" - (where "name" refers to the name of the container - that triggered the event) or if no container name - is specified "spec.containers[2]" (container with - index 2 in this pod). This syntax is chosen only - to have some well-defined way of referencing a part - of an object. TODO: this design is not final and - this field is subject to change in the future.' - type: string - kind: - description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - name: - description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' - type: string - namespace: - description: 'Namespace of the referent. More info: - https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/' - type: string - resourceVersion: - description: 'Specific resourceVersion to which this - reference is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency' - type: string - uid: - description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids' - type: string - type: object - x-kubernetes-map-type: atomic criteria: description: PipelineStageServicePromotionCriteria represents actions to perform if this stage service were promoted. properties: - clusterRef: - description: ClusterRef of the Cluster for the source - service. - properties: - apiVersion: - description: API version of the referent. - type: string - fieldPath: - description: 'If referring to a piece of an object - instead of an entire object, this string should - contain a valid JSON/Go field access statement, - such as desiredState.manifest.containers[2]. - For example, if the object reference is to a - container within a pod, this would take on a - value like: "spec.containers{name}" (where "name" - refers to the name of the container that triggered - the event) or if no container name is specified - "spec.containers[2]" (container with index 2 - in this pod). This syntax is chosen only to - have some well-defined way of referencing a - part of an object. TODO: this design is not - final and this field is subject to change in - the future.' - type: string - kind: - description: 'Kind of the referent. More info: - https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - name: - description: 'Name of the referent. More info: - https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' - type: string - namespace: - description: 'Namespace of the referent. More - info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/' - type: string - resourceVersion: - description: 'Specific resourceVersion to which - this reference is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency' - type: string - uid: - description: 'UID of the referent. More info: - https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids' - type: string - type: object - x-kubernetes-map-type: atomic secrets: description: Secrets to copy over in a promotion. items: @@ -343,6 +257,8 @@ spec: type: string type: object x-kubernetes-map-type: atomic + sourceID: + type: string type: object serviceRef: description: "ObjectReference contains enough information diff --git a/controller/internal/client/console.go b/controller/internal/client/console.go index e7162926f4..5195c26c49 100644 --- a/controller/internal/client/console.go +++ b/controller/internal/client/console.go @@ -35,7 +35,7 @@ type ConsoleClient interface { UpdateRepository(id string, attrs console.GitAttributes) (*console.UpdateGitRepository, error) DeleteRepository(id string) error GetRepository(url *string) (*console.GetGitRepository, error) - CreateService(clusterId *string, attributes console.ServiceDeploymentAttributes) (*console.ServiceDeploymentFragment, error) + CreateService(clusterId *string, attributes console.ServiceDeploymentAttributes) (*console.ServiceDeploymentExtended, error) GetCluster(id *string) (*console.ClusterFragment, error) GetClusterByHandle(handle *string) (*console.ClusterFragment, error) CreateCluster(attrs console.ClusterAttributes) (*console.ClusterFragment, error) diff --git a/controller/internal/client/service.go b/controller/internal/client/service.go index 4ee8699230..955ee4438e 100644 --- a/controller/internal/client/service.go +++ b/controller/internal/client/service.go @@ -24,7 +24,7 @@ func (c *client) GetService(clusterID, serviceName string) (*console.ServiceDepl return resp.ServiceDeployment, nil } -func (c *client) CreateService(clusterId *string, attributes console.ServiceDeploymentAttributes) (*console.ServiceDeploymentFragment, error) { +func (c *client) CreateService(clusterId *string, attributes console.ServiceDeploymentAttributes) (*console.ServiceDeploymentExtended, error) { if clusterId == nil { return nil, fmt.Errorf("clusterId and clusterName can not be null") } diff --git a/controller/internal/test/mocks/ConsoleClient_mock.go b/controller/internal/test/mocks/ConsoleClient_mock.go index 2214c97068..ff865fdb34 100644 --- a/controller/internal/test/mocks/ConsoleClient_mock.go +++ b/controller/internal/test/mocks/ConsoleClient_mock.go @@ -221,23 +221,23 @@ func (_c *ConsoleClientMock_CreateRepository_Call) RunAndReturn(run func(string, } // CreateService provides a mock function with given fields: clusterId, attributes -func (_m *ConsoleClientMock) CreateService(clusterId *string, attributes gqlclient.ServiceDeploymentAttributes) (*gqlclient.ServiceDeploymentFragment, error) { +func (_m *ConsoleClientMock) CreateService(clusterId *string, attributes gqlclient.ServiceDeploymentAttributes) (*gqlclient.ServiceDeploymentExtended, error) { ret := _m.Called(clusterId, attributes) if len(ret) == 0 { panic("no return value specified for CreateService") } - var r0 *gqlclient.ServiceDeploymentFragment + var r0 *gqlclient.ServiceDeploymentExtended var r1 error - if rf, ok := ret.Get(0).(func(*string, gqlclient.ServiceDeploymentAttributes) (*gqlclient.ServiceDeploymentFragment, error)); ok { + if rf, ok := ret.Get(0).(func(*string, gqlclient.ServiceDeploymentAttributes) (*gqlclient.ServiceDeploymentExtended, error)); ok { return rf(clusterId, attributes) } - if rf, ok := ret.Get(0).(func(*string, gqlclient.ServiceDeploymentAttributes) *gqlclient.ServiceDeploymentFragment); ok { + if rf, ok := ret.Get(0).(func(*string, gqlclient.ServiceDeploymentAttributes) *gqlclient.ServiceDeploymentExtended); ok { r0 = rf(clusterId, attributes) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*gqlclient.ServiceDeploymentFragment) + r0 = ret.Get(0).(*gqlclient.ServiceDeploymentExtended) } } @@ -269,12 +269,12 @@ func (_c *ConsoleClientMock_CreateService_Call) Run(run func(clusterId *string, return _c } -func (_c *ConsoleClientMock_CreateService_Call) Return(_a0 *gqlclient.ServiceDeploymentFragment, _a1 error) *ConsoleClientMock_CreateService_Call { +func (_c *ConsoleClientMock_CreateService_Call) Return(_a0 *gqlclient.ServiceDeploymentExtended, _a1 error) *ConsoleClientMock_CreateService_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *ConsoleClientMock_CreateService_Call) RunAndReturn(run func(*string, gqlclient.ServiceDeploymentAttributes) (*gqlclient.ServiceDeploymentFragment, error)) *ConsoleClientMock_CreateService_Call { +func (_c *ConsoleClientMock_CreateService_Call) RunAndReturn(run func(*string, gqlclient.ServiceDeploymentAttributes) (*gqlclient.ServiceDeploymentExtended, error)) *ConsoleClientMock_CreateService_Call { _c.Call.Return(run) return _c } @@ -337,6 +337,64 @@ func (_c *ConsoleClientMock_DeleteCluster_Call) RunAndReturn(run func(string) (* return _c } +// DeletePipeline provides a mock function with given fields: id +func (_m *ConsoleClientMock) DeletePipeline(id string) (*gqlclient.PipelineFragment, error) { + ret := _m.Called(id) + + if len(ret) == 0 { + panic("no return value specified for DeletePipeline") + } + + var r0 *gqlclient.PipelineFragment + var r1 error + if rf, ok := ret.Get(0).(func(string) (*gqlclient.PipelineFragment, error)); ok { + return rf(id) + } + if rf, ok := ret.Get(0).(func(string) *gqlclient.PipelineFragment); ok { + r0 = rf(id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*gqlclient.PipelineFragment) + } + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ConsoleClientMock_DeletePipeline_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeletePipeline' +type ConsoleClientMock_DeletePipeline_Call struct { + *mock.Call +} + +// DeletePipeline is a helper method to define mock.On call +// - id string +func (_e *ConsoleClientMock_Expecter) DeletePipeline(id interface{}) *ConsoleClientMock_DeletePipeline_Call { + return &ConsoleClientMock_DeletePipeline_Call{Call: _e.mock.On("DeletePipeline", id)} +} + +func (_c *ConsoleClientMock_DeletePipeline_Call) Run(run func(id string)) *ConsoleClientMock_DeletePipeline_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *ConsoleClientMock_DeletePipeline_Call) Return(_a0 *gqlclient.PipelineFragment, _a1 error) *ConsoleClientMock_DeletePipeline_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ConsoleClientMock_DeletePipeline_Call) RunAndReturn(run func(string) (*gqlclient.PipelineFragment, error)) *ConsoleClientMock_DeletePipeline_Call { + _c.Call.Return(run) + return _c +} + // DeleteProvider provides a mock function with given fields: ctx, id, options func (_m *ConsoleClientMock) DeleteProvider(ctx context.Context, id string, options ...gqlgencclient.HTTPRequestOption) error { _va := make([]interface{}, len(options)) @@ -1079,6 +1137,52 @@ func (_c *ConsoleClientMock_IsClusterExisting_Call) RunAndReturn(run func(*strin return _c } +// IsPipelineExisting provides a mock function with given fields: id +func (_m *ConsoleClientMock) IsPipelineExisting(id string) bool { + ret := _m.Called(id) + + if len(ret) == 0 { + panic("no return value specified for IsPipelineExisting") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(string) bool); ok { + r0 = rf(id) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// ConsoleClientMock_IsPipelineExisting_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsPipelineExisting' +type ConsoleClientMock_IsPipelineExisting_Call struct { + *mock.Call +} + +// IsPipelineExisting is a helper method to define mock.On call +// - id string +func (_e *ConsoleClientMock_Expecter) IsPipelineExisting(id interface{}) *ConsoleClientMock_IsPipelineExisting_Call { + return &ConsoleClientMock_IsPipelineExisting_Call{Call: _e.mock.On("IsPipelineExisting", id)} +} + +func (_c *ConsoleClientMock_IsPipelineExisting_Call) Run(run func(id string)) *ConsoleClientMock_IsPipelineExisting_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *ConsoleClientMock_IsPipelineExisting_Call) Return(_a0 bool) *ConsoleClientMock_IsPipelineExisting_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ConsoleClientMock_IsPipelineExisting_Call) RunAndReturn(run func(string) bool) *ConsoleClientMock_IsPipelineExisting_Call { + _c.Call.Return(run) + return _c +} + // IsProviderDeleting provides a mock function with given fields: ctx, id func (_m *ConsoleClientMock) IsProviderDeleting(ctx context.Context, id string) bool { ret := _m.Called(ctx, id)