diff --git a/charts/pipelines-feedback-common/templates/deployment.yaml b/charts/pipelines-feedback-common/templates/deployment.yaml index 06325f8..43181da 100644 --- a/charts/pipelines-feedback-common/templates/deployment.yaml +++ b/charts/pipelines-feedback-common/templates/deployment.yaml @@ -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: diff --git a/pkgs/app/core.go b/pkgs/app/core.go index 0db5f08..8979267 100644 --- a/pkgs/app/core.go +++ b/pkgs/app/core.go @@ -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" @@ -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" @@ -34,6 +36,7 @@ type PipelinesFeedbackApp struct { JobController *controller.GenericController ConfigController *controller.ConfigurationController Debug bool + ControllerName string MetricsBindAddress string HealthProbeBindAddress string LeaderElect bool @@ -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()) @@ -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 { diff --git a/pkgs/cli/root.go b/pkgs/cli/root.go index 233454d..8f3262f 100644 --- a/pkgs/cli/root.go +++ b/pkgs/cli/root.go @@ -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") diff --git a/pkgs/feedback/debug/receiver.go b/pkgs/feedback/debug/receiver.go new file mode 100644 index 0000000..990638c --- /dev/null +++ b/pkgs/feedback/debug/receiver.go @@ -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" +}