From 6ceb4f9ce73a746054dad6ce3acc06bc5d76b0f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20K=C4=99ska?= <372403+keskad@users.noreply.github.com> Date: Tue, 21 May 2024 22:18:56 +0200 Subject: [PATCH] fix: Add missing PipelinesSkipped status (https://github.com/kube-cicd/pipelines-feedback-tekton/issues/29) --- pkgs/config/provider.go | 3 ++- pkgs/contract/pipeline.go | 7 +++++++ pkgs/contract/wiring/di.go | 2 +- pkgs/controller/generic_controller.go | 7 ++++--- pkgs/fake/config.go | 23 +++++++++++++++++++++++ 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/pkgs/config/provider.go b/pkgs/config/provider.go index a2be8d6..e5247ce 100644 --- a/pkgs/config/provider.go +++ b/pkgs/config/provider.go @@ -3,6 +3,8 @@ package config import ( "context" "fmt" + "strings" + "github.com/kube-cicd/pipelines-feedback-core/internal/config" "github.com/kube-cicd/pipelines-feedback-core/pkgs/contract" "github.com/kube-cicd/pipelines-feedback-core/pkgs/logging" @@ -10,7 +12,6 @@ import ( "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/client-go/kubernetes/typed/core/v1" - "strings" ) type ConfigurationProviderInterface interface { diff --git a/pkgs/contract/pipeline.go b/pkgs/contract/pipeline.go index aba7d88..9a8ce7b 100644 --- a/pkgs/contract/pipeline.go +++ b/pkgs/contract/pipeline.go @@ -59,6 +59,7 @@ func (pi PipelineInfo) GetStatus() Status { succeeded := 0 running := 0 cancelled := 0 + skipped := 0 allStages := len(pi.stages) for _, stage := range pi.stages { @@ -80,6 +81,9 @@ func (pi PipelineInfo) GetStatus() Status { if stage.Status == PipelineCancelled { cancelled += 1 } + if stage.Status == PipelineSkipped { + skipped += 1 + } } if cancelled > 0 { return PipelineCancelled @@ -93,6 +97,9 @@ func (pi PipelineInfo) GetStatus() Status { if allStages == succeeded { return PipelineSucceeded } + if skipped > 0 { + return PipelineSucceeded + } return PipelineErrored } diff --git a/pkgs/contract/wiring/di.go b/pkgs/contract/wiring/di.go index d470c5a..ed150aa 100644 --- a/pkgs/contract/wiring/di.go +++ b/pkgs/contract/wiring/di.go @@ -15,7 +15,7 @@ type WithInitialization interface { } type ServiceContext struct { - Recorder *record.EventRecorder + Recorder record.EventRecorder KubeConfig *rest.Config Config config.ConfigurationProviderInterface Log *logging.InternalLogger diff --git a/pkgs/controller/generic_controller.go b/pkgs/controller/generic_controller.go index 9c7f9a2..ea5a65d 100644 --- a/pkgs/controller/generic_controller.go +++ b/pkgs/controller/generic_controller.go @@ -3,6 +3,9 @@ package controller import ( "context" "fmt" + "strings" + "time" + "github.com/kube-cicd/pipelines-feedback-core/pkgs/config" "github.com/kube-cicd/pipelines-feedback-core/pkgs/contract" "github.com/kube-cicd/pipelines-feedback-core/pkgs/contract/wiring" @@ -18,8 +21,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/predicate" - "strings" - "time" ) type GenericController struct { @@ -204,7 +205,7 @@ func (gc *GenericController) InjectDependencies(recorder record.EventRecorder, k gc.kubeConfig = kubeConfig gc.logger = logger sc := wiring.ServiceContext{ - Recorder: &recorder, + Recorder: recorder, KubeConfig: kubeConfig, Config: configProvider, Log: logger.ForkWithFields(context.TODO(), map[string]interface{}{}), diff --git a/pkgs/fake/config.go b/pkgs/fake/config.go index 8b8c801..729f466 100644 --- a/pkgs/fake/config.go +++ b/pkgs/fake/config.go @@ -1,8 +1,12 @@ package fake import ( + "context" + "github.com/kube-cicd/pipelines-feedback-core/pkgs/apis/pipelinesfeedback.keskad.pl/v1alpha1" "github.com/kube-cicd/pipelines-feedback-core/pkgs/config" + "github.com/kube-cicd/pipelines-feedback-core/pkgs/contract" + "github.com/kube-cicd/pipelines-feedback-core/pkgs/logging" ) // NullValidator is an empty implementation used in unit tests @@ -18,3 +22,22 @@ func (nv *NullValidator) ValidateConfig(data v1alpha1.Data) error { func (nv *NullValidator) Add(schema config.Schema) { } + +type FakeConfigurationProvider struct { +} + +func (f *FakeConfigurationProvider) FetchContextual(component string, namespace string, pipeline contract.PipelineInfo) config.Data { + return config.NewData(component, map[string]string{}, &NullValidator{}, logging.CreateLogger(true)) +} + +func (f *FakeConfigurationProvider) FetchGlobal(component string) config.Data { + return config.NewData(component, map[string]string{}, &NullValidator{}, logging.CreateLogger(true)) +} + +func (f *FakeConfigurationProvider) FetchSecretKey(ctx context.Context, name string, namespace string, key string, cache bool) (string, error) { + return "", nil +} + +func (f *FakeConfigurationProvider) FetchFromFieldOrSecret(ctx context.Context, data *config.Data, namespace string, fieldKey string, referenceKey string, referenceSecretNameKey string) (string, error) { + return "", nil +}