Skip to content

Commit

Permalink
Initially working version without logs reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
keskad committed Jul 14, 2023
1 parent 70a65d0 commit 9dd89ed
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 10 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
SUDO=
ENV_CLUSTER_NAME=pft

.PHONY: all
all: build

Expand Down Expand Up @@ -29,3 +32,12 @@ ensure-go-junit-report:

test: ensure-go-junit-report
export PATH=$$PATH:~/go/bin:$$GOROOT/bin:$$(pwd)/.build; go test -v ./... -covermode=count -coverprofile=coverage.out 2>&1 | go-junit-report -set-exit-code -out junit.xml -iocopy

k3d:
(${SUDO} docker ps | grep k3d-${ENV_CLUSTER_NAME}-server-0 > /dev/null 2>&1) || ${SUDO} k3d cluster create ${ENV_CLUSTER_NAME} --registry-create ${ENV_CLUSTER_NAME}-registry:0.0.0.0:5000 --agents 0
k3d kubeconfig merge ${ENV_CLUSTER_NAME}

k3d-install-tekton:
export KUBECONFIG=~/.k3d/kubeconfig-${ENV_CLUSTER_NAME}.yaml; \
kubectl create ns tekton-pipelines || true; \
kubectl apply -f https://storage.googleapis.com/tekton-releases/pipeline/previous/v0.44.4/release.yaml
35 changes: 35 additions & 0 deletions examples/pipelinerun-inline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
generateName: hello-
annotations:
pipelinesfeedback.keskad.pl/https-repo-url: "https://github.com/keskad/jx-gitops"
pipelinesfeedback.keskad.pl/commit: "76ea7c746d4e4ac42c44bf72946d3b0d399553dd"
pipelinesfeedback.keskad.pl/ref: "refs/heads/test-pr"
pipelinesfeedback.keskad.pl/pr-id: "2"
spec:
pipelineSpec:
tasks:
- name: clone
taskSpec:
params:
- name: username
default: $(params.username)
steps:
- image: busybox
name: print
script: |
echo "Bread for you, $(params.username)"
- name: test
taskSpec:
steps:
- image: busybox
name: print
script: |
sleep 10
/bin/true
params:
- name: username
value: "Kropotkin"
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require (
github.com/jenkins-x/go-scm v1.13.13 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kube-cicd/pipelines-feedback-core v0.0.0-20230713063808-4053dcf98e8c // indirect
github.com/kube-cicd/pipelines-feedback-core v0.0.0-20230714055547-ca1edfb89119 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ github.com/kube-cicd/pipelines-feedback-core v0.0.0-20230713054653-19c16a7b5591
github.com/kube-cicd/pipelines-feedback-core v0.0.0-20230713054653-19c16a7b5591/go.mod h1:niA2xneogLheMkmLJoSoG85sWI4ZIKKwnfDFP+q3Ij8=
github.com/kube-cicd/pipelines-feedback-core v0.0.0-20230713063808-4053dcf98e8c h1:d2xLHfJzXA3N0zYBwDYb18uSHkbbw/YUA0QC3Fmfgmo=
github.com/kube-cicd/pipelines-feedback-core v0.0.0-20230713063808-4053dcf98e8c/go.mod h1:niA2xneogLheMkmLJoSoG85sWI4ZIKKwnfDFP+q3Ij8=
github.com/kube-cicd/pipelines-feedback-core v0.0.0-20230714055547-ca1edfb89119 h1:yaSgYyBXsY7q9b4AWb0Ah8iyuk8oHQDThQ11aEJfq4A=
github.com/kube-cicd/pipelines-feedback-core v0.0.0-20230714055547-ca1edfb89119/go.mod h1:niA2xneogLheMkmLJoSoG85sWI4ZIKKwnfDFP+q3Ij8=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import (
"github.com/kube-cicd/pipelines-feedback-core/pkgs/cli"
"github.com/kube-cicd/pipelines-feedback-core/pkgs/controller"
"github.com/kube-cicd/pipelines-feedback-tekton/pkgs/core"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"os"
)

func main() {

pfcApp := app.PipelinesFeedbackApp{
JobController: core.CreateTektonController(),
ConfigController: &controller.ConfigurationController{},
KubernetesSchemeSetters: []app.SchemeSetter{
v1.AddToScheme,
},
}
cmd := cli.NewRootCommand(&pfcApp)
args := os.Args
Expand Down
36 changes: 27 additions & 9 deletions pkgs/core/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/kube-cicd/pipelines-feedback-core/pkgs/logging"
"github.com/kube-cicd/pipelines-feedback-core/pkgs/provider"
"github.com/kube-cicd/pipelines-feedback-core/pkgs/store"
"github.com/kube-cicd/pipelines-feedback-core/pkgs/templating"
"github.com/pkg/errors"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
v1Client "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/typed/pipeline/v1"
Expand Down Expand Up @@ -56,7 +57,7 @@ func (prp *PipelineRunProvider) fetchTaskRuns(ctx context.Context, pipelineRun *

// ReceivePipelineInfo is tracking tekton.dev/v1, kind: PipelineRun type objects
func (prp *PipelineRunProvider) ReceivePipelineInfo(ctx context.Context, name string, namespace string) (contract.PipelineInfo, error) {
// globalCfg := prp.confProvider.FetchGlobal("global")
globalCfg := prp.confProvider.FetchGlobal("global")

pipelineRun, err := prp.client.PipelineRuns(namespace).Get(ctx, name, metav1.GetOptions{})
if err != nil {
Expand Down Expand Up @@ -89,6 +90,13 @@ func (prp *PipelineRunProvider) ReceivePipelineInfo(ctx context.Context, name st
return contract.PipelineInfo{}, errors.Wrap(fetchErr, "cannot fetch stages list")
}

dashboardUrl, dashboardTplErr := templating.TemplateDashboardUrl(
globalCfg.Get("dashboard-url"), pipelineRun, pipelineRun.TypeMeta,
)
if dashboardTplErr != nil {
prp.logger.Warningf("Cannot render dashboard template URL '%s': '%s'", dashboardUrl, dashboardTplErr.Error())
}

pi := contract.NewPipelineInfo(
scm,
namespace,
Expand All @@ -98,15 +106,23 @@ func (prp *PipelineRunProvider) ReceivePipelineInfo(ctx context.Context, name st
stages,
labels.Set(pipelineRun.GetLabels()),
labels.Set(pipelineRun.GetAnnotations()),
contract.PipelineInfoWithUrl(dashboardUrl),
// todo: logs collection
)
return *pi, nil
}
func (prp *PipelineRunProvider) collectStatus(ctx context.Context, pipelineRun *v1.PipelineRun) ([]contract.PipelineStage, error) {
// Collect all tasks in valid order
orderedTasks := make([]contract.PipelineStage, 0)
for _, task := range pipelineRun.Spec.TaskRunSpecs {

if pipelineRun.Status.PipelineSpec == nil {
return []contract.PipelineStage{}, errors.New("Pipeline is not ready yet - " +
"we should wait a little bit until it not be picked by Tekton Controller")
}

for _, task := range pipelineRun.Status.PipelineSpec.Tasks {
orderedTasks = append(orderedTasks, contract.PipelineStage{
Name: task.PipelineTaskName,
Name: task.Name,
Status: contract.PipelinePending,
})
}
Expand Down Expand Up @@ -163,15 +179,17 @@ func receivePipelineName(pipelineRun *v1.PipelineRun) string {

func translateTaskStatus(task *v1.TaskRun) contract.Status {
if task.IsCancelled() {
// todo
return contract.PipelineErrored
return contract.PipelineCancelled
}
if !task.HasStarted() {
return contract.PipelinePending
}
if task.IsSuccessful() {
return contract.PipelineSucceeded
} else {
return contract.PipelineFailed
if task.IsDone() {
if task.IsSuccessful() {
return contract.PipelineSucceeded
} else {
return contract.PipelineFailed
}
}
return contract.PipelineRunning
}

0 comments on commit 9dd89ed

Please sign in to comment.