generated from keptn-sandbox/keptn-service-template-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
eventhandlers.go
129 lines (105 loc) · 4.61 KB
/
eventhandlers.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import (
"fmt"
"log"
"github.com/cloudevents/sdk-go/pkg/cloudevents"
keptn "github.com/keptn/go-utils/pkg/lib"
)
/**
* Here are all the handler functions for the individual event
See https://github.com/keptn/spec/blob/0.1.3/cloudevents.md for details on the payload
-> "sh.keptn.event.configuration.change"
-> "sh.keptn.events.deployment-finished"
-> "sh.keptn.events.tests-finished"
-> "sh.keptn.event.start-evaluation"
-> "sh.keptn.events.evaluation-done"
-> "sh.keptn.event.problem.open"
-> "sh.keptn.events.problem"
*/
func handleEvent(eventname string, event cloudevents.Event, keptnEvent baseKeptnEvent, logger *keptn.Logger) error {
gitlabConfigFile, err := getGitLabConfiguration(keptnEvent, logger)
if err != nil {
return err
}
logger.Info("Loaded GitLab Config File")
eventMapConfig, err := getEventMappingConfig(gitlabConfigFile, eventname)
if err != nil {
logger.Info(fmt.Sprintf("No event mapping found for %s. Therefore executing no GitLab Pipeline", eventname))
return nil
}
logger.Info(fmt.Sprintf("Event Mapping %s points to action %s", eventname, eventMapConfig.Action))
var pipelineConfig *PipelineConfig
pipelineConfig, err = getPipelineConfig(gitlabConfigFile, eventMapConfig.Action)
if err != nil {
return fmt.Errorf("No Action Config found for: %s", eventMapConfig.Action)
}
var instanceConfig *GitLabInstanceConfig
instanceConfig, err = getGitLabInstanceConfig(gitlabConfigFile, pipelineConfig.Instance)
if err != nil {
return fmt.Errorf("No Server Config found for: %s", pipelineConfig.Instance)
}
var success bool
var keptnResult *KeptnResultArtifact
success, keptnResult, err = executeGitLabPipelineAndWaitForCompletion(eventMapConfig, pipelineConfig, instanceConfig)
success, err = sendKeptnEventForEventConfig(
&keptnEvent, &event,
eventMapConfig,
success, keptnResult,
logger)
return err
}
//
// Handles ConfigurationChangeEventType = "sh.keptn.event.configuration.change"
// TODO: add in your handler code
//
func HandleConfigurationChangeEvent(myKeptn *keptn.Keptn, keptnEvent baseKeptnEvent, incomingEvent cloudevents.Event, data *keptn.ConfigurationChangeEventData, logger *keptn.Logger) error {
log.Printf("Handling Configuration Changed Event: %s", incomingEvent.Context.GetID())
return handleEvent("configuration.change", incomingEvent, keptnEvent, logger)
}
//
// Handles DeploymentFinishedEventType = "sh.keptn.events.deployment-finished"
// TODO: add in your handler code
//
func HandleDeploymentFinishedEvent(myKeptn *keptn.Keptn, keptnEvent baseKeptnEvent, incomingEvent cloudevents.Event, data *keptn.DeploymentFinishedEventData, logger *keptn.Logger) error {
log.Printf("Handling Deployment Finished Event: %s", incomingEvent.Context.GetID())
return handleEvent("deployment.finished", incomingEvent, keptnEvent, logger)
// capture start time for tests
// startTime := time.Now()
// run tests
// ToDo: Implement your tests here
// Send Test Finished Event
// return myKeptn.SendTestsFinishedEvent(&incomingEvent, "", "", startTime, "pass", nil, "gitlab-service")
}
//
// Handles TestsFinishedEventType = "sh.keptn.events.tests-finished"
// TODO: add in your handler code
//
func HandleTestsFinishedEvent(myKeptn *keptn.Keptn, keptnEvent baseKeptnEvent, incomingEvent cloudevents.Event, data *keptn.TestsFinishedEventData, logger *keptn.Logger) error {
log.Printf("Handling Tests Finished Event: %s", incomingEvent.Context.GetID())
return handleEvent("test.finished", incomingEvent, keptnEvent, logger)
}
//
// Handles EvaluationDoneEventType = "sh.keptn.events.evaluation-done"
// TODO: add in your handler code
//
func HandleStartEvaluationEvent(myKeptn *keptn.Keptn, keptnEvent baseKeptnEvent, incomingEvent cloudevents.Event, data *keptn.StartEvaluationEventData, logger *keptn.Logger) error {
log.Printf("Handling Start Evaluation Event: %s", incomingEvent.Context.GetID())
return handleEvent("start.evaluation", incomingEvent, keptnEvent, logger)
}
//
// Handles DeploymentFinishedEventType = "sh.keptn.events.deployment-finished"
// TODO: add in your handler code
//
func HandleEvaluationDoneEvent(myKeptn *keptn.Keptn, incomingEvent cloudevents.Event, data *keptn.EvaluationDoneEventData) error {
log.Printf("Handling Evaluation Done Event: %s", incomingEvent.Context.GetID())
return nil
}
//
// Handles ProblemOpenEventType = "sh.keptn.event.problem.open"
// Handles ProblemEventType = "sh.keptn.events.problem"
// TODO: add in your handler code
//
func HandleProblemEvent(myKeptn *keptn.Keptn, incomingEvent cloudevents.Event, data *keptn.ProblemEventData) error {
log.Printf("Handling Problem Event: %s", incomingEvent.Context.GetID())
return nil
}