Skip to content

Commit

Permalink
fix: Add missing PipelinesSkipped status (kube-cicd/pipelines-feedbac…
Browse files Browse the repository at this point in the history
  • Loading branch information
keskad committed May 21, 2024
1 parent b59960f commit 6ceb4f9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pkgs/config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ 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"
"github.com/kube-cicd/pipelines-feedback-core/pkgs/store"
"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 {
Expand Down
7 changes: 7 additions & 0 deletions pkgs/contract/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -93,6 +97,9 @@ func (pi PipelineInfo) GetStatus() Status {
if allStages == succeeded {
return PipelineSucceeded
}
if skipped > 0 {
return PipelineSucceeded
}
return PipelineErrored
}

Expand Down
2 changes: 1 addition & 1 deletion pkgs/contract/wiring/di.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions pkgs/controller/generic_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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{}{}),
Expand Down
23 changes: 23 additions & 0 deletions pkgs/fake/config.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}

0 comments on commit 6ceb4f9

Please sign in to comment.