/
breakpoint.go
93 lines (82 loc) · 2.79 KB
/
breakpoint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package v1alpha1
import (
"github.com/jenkins-x/lighthouse/pkg/config/job"
tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// +kubebuilder:resource:shortName=lhbp
// LighthouseBreakpoint defines the debug breakpoints for Pipelines
type LighthouseBreakpoint struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec LighthouseBreakpointSpec `json:"spec,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// LighthouseBreakpointList represents a list of breakpoint options
type LighthouseBreakpointList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
Items []LighthouseBreakpoint `json:"items"`
}
// LighthouseBreakpointSpec the spec of a breakpoint request
type LighthouseBreakpointSpec struct {
// Filter filters which kinds of pipeilnes to apply this debug to
Filter LighthousePipelineFilter `json:"filter,omitempty"`
// Debug the debug configuration to apply
Debug tektonv1beta1.TaskRunDebug `json:"debug,omitempty"`
}
// LighthousePipelineFilter defines the filter to use to apply breakpoints to new breakpoints
type LighthousePipelineFilter struct {
// Type is the type of job and informs how
// the jobs is triggered
Type job.PipelineKind `json:"type,omitempty"`
// Owner is the git organisation or user that owns the repository
Owner string `json:"owner,omitempty"`
// Repository the name of the git repository within the owner
Repository string `json:"repository,omitempty"`
// Branch the name of the branch
Branch string `json:"branch,omitempty"`
// Context the name of the context
Context string `json:"context,omitempty"`
// Task the name of the task
Task string `json:"task,omitempty"`
}
// Matches returns true if this filter matches the given object data
func (f *LighthousePipelineFilter) Matches(o *LighthousePipelineFilter) bool {
if string(f.Type) != "" {
if f.Type != o.Type {
return false
}
}
if f.Owner != "" && f.Owner != o.Owner {
return false
}
if f.Repository != "" && f.Repository != o.Repository {
return false
}
if f.Branch != "" && f.Branch != o.Branch {
return false
}
if f.Context != "" && f.Context != o.Context {
return false
}
if f.Task != "" && f.Task != o.Task {
return false
}
return true
}
// ResolveDebug resolves the debug breakpoint
func (f *LighthousePipelineFilter) ResolveDebug(breakpoints []*LighthouseBreakpoint) *tektonv1beta1.TaskRunDebug {
// lets match the first breakpoint
for _, bp := range breakpoints {
if bp.Spec.Filter.Matches(f) {
return &bp.Spec.Debug
}
}
return nil
}