Skip to content

Commit

Permalink
feat: Add "debug" feedback receiver and parametrize controller name f…
Browse files Browse the repository at this point in the history
…or improved testing experience
  • Loading branch information
keskad committed May 22, 2024
1 parent dbeb87e commit 18acf64
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
1 change: 1 addition & 0 deletions charts/pipelines-feedback-common/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ spec:
- "--requeue-delay-after-error-count={{ .Values.controller.tweaks.requeueDelayAfterErrorCount }}"
- "--requeue-delay-secs={{ .Values.controller.tweaks.requeueDelaySecs }}"
- "--requeue-stop-after-error-count={{ .Values.controller.tweaks.requeueStopAfterErrorCount }}"
- "--controller-name={{ include "app.fullname" . }}"

{{- with .Values.controller.deployment.env }}
env:
Expand Down
10 changes: 7 additions & 3 deletions pkgs/app/core.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package app

import (
"os"

pipelinesfeedbackv1alpha1scheme "github.com/kube-cicd/pipelines-feedback-core/pkgs/client/clientset/versioned/scheme"
"github.com/kube-cicd/pipelines-feedback-core/pkgs/config"
"github.com/kube-cicd/pipelines-feedback-core/pkgs/controller"
"github.com/kube-cicd/pipelines-feedback-core/pkgs/feedback"
debugFeedback "github.com/kube-cicd/pipelines-feedback-core/pkgs/feedback/debug"
"github.com/kube-cicd/pipelines-feedback-core/pkgs/feedback/jxscm"
"github.com/kube-cicd/pipelines-feedback-core/pkgs/logging"
"github.com/kube-cicd/pipelines-feedback-core/pkgs/store"
Expand All @@ -14,7 +17,6 @@ import (
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"os"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
Expand All @@ -34,6 +36,7 @@ type PipelinesFeedbackApp struct {
JobController *controller.GenericController
ConfigController *controller.ConfigurationController
Debug bool
ControllerName string
MetricsBindAddress string
HealthProbeBindAddress string
LeaderElect bool
Expand Down Expand Up @@ -93,14 +96,14 @@ func (app *PipelinesFeedbackApp) Run() error {
},
HealthProbeBindAddress: app.HealthProbeBindAddress,
LeaderElection: app.LeaderElect,
LeaderElectionID: app.LeaderElectId + ".keskad.pl",
LeaderElectionID: app.LeaderElectId + app.ControllerName + ".keskad.pl",
LeaderElectionReleaseOnCancel: true,
})
if err != nil {
return err
}

recorder := mgr.GetEventRecorderFor("pipelines-feedback")
recorder := mgr.GetEventRecorderFor(app.ControllerName)
kubeconfig, err := createKubeConfiguration(os.Getenv("KUBECONFIG"))
if err != nil {
panic(err.Error())
Expand Down Expand Up @@ -172,6 +175,7 @@ func (app *PipelinesFeedbackApp) populateFeedbackReceiver() error {
if app.AvailableFeedbackReceivers == nil {
app.AvailableFeedbackReceivers = []feedback.Receiver{
&jxscm.Receiver{},
&debugFeedback.Receiver{},
}
}
for _, pluggable := range app.AvailableFeedbackReceivers {
Expand Down
3 changes: 2 additions & 1 deletion pkgs/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func NewRootCommand(app *app.PipelinesFeedbackApp) *cobra.Command {
command.Flags().StringVarP(&app.MetricsBindAddress, "metrics-bind-address", "m", ":8080", "Metrics bind address")
command.Flags().StringVarP(&app.HealthProbeBindAddress, "health-probe-bind-address", "p", ":8081", "Health probe bind address")
command.Flags().BoolVarP(&app.LeaderElect, "leader-elect", "l", false, "Enable leader election")
command.Flags().StringVarP(&app.LeaderElectId, "instance-id", "", "aSaMKO0", "Leader election ID (if running multiple controller instances with different configuration)")
command.Flags().StringVarP(&app.ControllerName, "controller-name", "", "pipelines-feedback", "Controller name - useful when running multiple controllers on the same cluster")
command.Flags().StringVarP(&app.LeaderElectId, "instance-id", "", "aSaMKO0", "Leader election ID (should not be changed, unless you know what you are doing)")

// error handling
command.Flags().IntVarP(&app.DelayAfterErrorNum, "requeue-delay-after-error-count", "", 100, "Delay reconciliation of this resource, after it failed X times")
Expand Down
49 changes: 49 additions & 0 deletions pkgs/feedback/debug/receiver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package debug

import (
"context"

"github.com/kube-cicd/pipelines-feedback-core/pkgs/contract"
"github.com/kube-cicd/pipelines-feedback-core/pkgs/contract/wiring"
"github.com/kube-cicd/pipelines-feedback-core/pkgs/logging"
"github.com/sirupsen/logrus"
)

type Receiver struct{}

func (d *Receiver) InitializeWithContext(sc *wiring.ServiceContext) error {
return nil
}

func (d *Receiver) WhenCreated(ctx context.Context, pipeline contract.PipelineInfo, log *logging.InternalLogger) error {
log.Info("debug.WhenCreated()")

return nil
}

func (d *Receiver) WhenStarted(ctx context.Context, pipeline contract.PipelineInfo, log *logging.InternalLogger) error {
log.Info("debug.WhenStarted()")

return nil
}

func (d *Receiver) UpdateProgress(ctx context.Context, pipeline contract.PipelineInfo, log *logging.InternalLogger) error {
log.Info("debug.UpdateProgress()")
logrus.Info(pipeline)

return nil
}

func (d *Receiver) WhenFinished(ctx context.Context, pipeline contract.PipelineInfo, log *logging.InternalLogger) error {
log.Info("debug.WhenFinished()")

return nil
}

func (d *Receiver) CanHandle(name string) bool {
return true
}

func (d *Receiver) GetImplementationName() string {
return "debug"
}

0 comments on commit 18acf64

Please sign in to comment.