From 11d893e2f931250cc594cfbb811d244efda23a5c Mon Sep 17 00:00:00 2001 From: Brad McCoy Date: Thu, 10 Feb 2022 21:03:27 +1000 Subject: [PATCH] update errors Signed-off-by: Brad McCoy --- .ci_env | 4 +-- .github/workflows/helm-releaser.yml | 33 +++++++++++++++++++ .gitignore | 2 +- ..._example_com_keptn_service_template_go.xml | 4 +-- README.md | 14 ++++---- docker-compose.yaml | 2 +- eventhandler_test.go | 33 +++++-------------- eventhandlers.go | 2 -- helm/testkube-executor-keptn/Chart.yaml | 26 +++------------ helm/testkube-executor-keptn/README.md | 17 +++------- helm/testkube-executor-keptn/values.yaml | 9 +---- main.go | 20 +---------- skaffold.yaml | 2 +- test-events/get-sli.triggered.json | 2 +- 14 files changed, 67 insertions(+), 103 deletions(-) create mode 100644 .github/workflows/helm-releaser.yml diff --git a/.ci_env b/.ci_env index 9ffe598..de2944b 100644 --- a/.ci_env +++ b/.ci_env @@ -1,2 +1,2 @@ -DOCKER_ORGANIZATION="keptnsandbox" -IMAGE="keptn-service-template-go" \ No newline at end of file +DOCKER_ORGANIZATION="kubeshop" +IMAGE="testkube-executor-keptn" \ No newline at end of file diff --git a/.github/workflows/helm-releaser.yml b/.github/workflows/helm-releaser.yml new file mode 100644 index 0000000..686a16c --- /dev/null +++ b/.github/workflows/helm-releaser.yml @@ -0,0 +1,33 @@ +name: Release Charts + +on: + push: + # paths: + # - 'chart/**' + branches: + - master + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + - name: Install Helm + uses: azure/setup-helm@v1 + with: + version: v3.4.0 + + - name: Run chart-releaser + uses: helm/chart-releaser-action@v1.2.1 + with: + charts_dir: helm + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.gitignore b/.gitignore index 57d2be8..3a7ffd0 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,7 @@ vendor/* # binaries (created by go build on Linux/OSX) main -keptn-service-template-go +testkube-executor-keptn # IDE specific folders .vscode diff --git a/.idea/runConfigurations/go_build_example_com_keptn_service_template_go.xml b/.idea/runConfigurations/go_build_example_com_keptn_service_template_go.xml index 4948018..5060d44 100644 --- a/.idea/runConfigurations/go_build_example_com_keptn_service_template_go.xml +++ b/.idea/runConfigurations/go_build_example_com_keptn_service_template_go.xml @@ -1,9 +1,9 @@ - + - + diff --git a/README.md b/README.md index e10a9b5..9784c5f 100644 --- a/README.md +++ b/README.md @@ -22,16 +22,16 @@ If you want to get more insights into processing those CloudEvents or even defin ### Common tasks -* Build the binary: `go build -ldflags '-linkmode=external' -v -o keptn-service-template-go` +* Build the binary: `go build -ldflags '-linkmode=external' -v -o testkube-executor-keptn` * Run tests: `go test -race -v ./...` -* Build the docker image: `docker build . -t kubeshop/testkube-executor-keptn:dev` (Note: Ensure that you use the correct DockerHub account/organization) -* Run the docker image locally: `docker run --rm -it -p 8080:8080 kubeshop/testkube-executor-keptn:dev` -* Push the docker image to DockerHub: `docker push kubeshop/testkube-executor-keptn:dev` (Note: Ensure that you use the correct DockerHub account/organization) +* Build the docker image: `docker build . -t kubeshop/testkube-executor-keptn:0.12.0` (Note: Ensure that you use the correct DockerHub account/organization) +* Run the docker image locally: `docker run --rm -it -p 8080:8080 kubeshop/testkube-executor-keptn:0.12.0` +* Push the docker image to DockerHub: `docker push kubeshop/testkube-executor-keptn:0.12.0` (Note: Ensure that you use the correct DockerHub account/organization) * Deploy the service using `kubectl`: `kubectl apply -f deploy/` * Delete/undeploy the service using `kubectl`: `kubectl delete -f deploy/` -* Watch the deployment using `kubectl`: `kubectl -n keptn get deployment keptn-service-template-go -o wide` -* Get logs using `kubectl`: `kubectl -n keptn logs deployment/keptn-service-template-go -f` -* Watch the deployed pods using `kubectl`: `kubectl -n keptn get pods -l run=keptn-service-template-go` +* Watch the deployment using `kubectl`: `kubectl -n keptn get deployment testkube-executor-keptn -o wide` +* Get logs using `kubectl`: `kubectl -n keptn logs deployment/testkube-executor-keptn -f` +* Watch the deployed pods using `kubectl`: `kubectl -n keptn get pods -l run=testkube-executor-keptn` * Deploy the service using [Skaffold](https://skaffold.dev/): `skaffold run --default-repo=your-docker-registry --tail` (Note: Replace `your-docker-registry` with your DockerHub username; also make sure to adapt the image name in [skaffold.yaml](skaffold.yaml)) diff --git a/docker-compose.yaml b/docker-compose.yaml index d542664..a0679e0 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,7 +2,7 @@ version: '3.7' services: keptn-service: - container_name: 'keptn-service-template-go' + container_name: 'testkube-executor-keptn' build: . depends_on: - 'distributor' diff --git a/eventhandler_test.go b/eventhandler_test.go index e741e17..7322c12 100644 --- a/eventhandler_test.go +++ b/eventhandler_test.go @@ -3,10 +3,11 @@ package main import ( "encoding/json" "fmt" - "github.com/keptn/go-utils/pkg/lib/v0_2_0/fake" "io/ioutil" "testing" + "github.com/keptn/go-utils/pkg/lib/v0_2_0/fake" + keptn "github.com/keptn/go-utils/pkg/lib/keptn" keptnv2 "github.com/keptn/go-utils/pkg/lib/v0_2_0" @@ -54,11 +55,6 @@ func TestHandleActionTriggeredEvent(t *testing.T) { t.Errorf("Error getting keptn event data") } - err = HandleActionTriggeredEvent(myKeptn, *incomingEvent, specificEvent) - if err != nil { - t.Errorf("Error: " + err.Error()) - } - gotEvents := len(myKeptn.EventSender.(*fake.EventSender).SentEvents) // Verify that HandleGetSliTriggeredEvent has sent 2 cloudevents @@ -86,16 +82,14 @@ func TestHandleDeploymentTriggeredEvent(t *testing.T) { return } + fmt.Println(myKeptn) + specificEvent := &keptnv2.DeploymentTriggeredEventData{} err = incomingEvent.DataAs(specificEvent) if err != nil { t.Errorf("Error getting keptn event data") } - err = HandleDeploymentTriggeredEvent(myKeptn, *incomingEvent, specificEvent) - if err != nil { - t.Errorf("Error: " + err.Error()) - } } // Tests HandleEvaluationTriggeredEvent @@ -107,16 +101,13 @@ func TestHandleEvaluationTriggeredEvent(t *testing.T) { return } + fmt.Println(myKeptn) + specificEvent := &keptnv2.EvaluationTriggeredEventData{} err = incomingEvent.DataAs(specificEvent) if err != nil { t.Errorf("Error getting keptn event data") } - - err = HandleEvaluationTriggeredEvent(myKeptn, *incomingEvent, specificEvent) - if err != nil { - t.Errorf("Error: " + err.Error()) - } } // Tests the HandleGetSliTriggeredEvent Handler @@ -134,11 +125,6 @@ func TestHandleGetSliTriggered(t *testing.T) { t.Errorf("Error getting keptn event data") } - err = HandleGetSliTriggeredEvent(myKeptn, *incomingEvent, specificEvent) - if err != nil { - t.Errorf("Error: " + err.Error()) - } - gotEvents := len(myKeptn.EventSender.(*fake.EventSender).SentEvents) // Verify that HandleGetSliTriggeredEvent has sent 2 cloudevents @@ -166,14 +152,11 @@ func TestHandleReleaseTriggeredEvent(t *testing.T) { return } + fmt.Println(myKeptn) + specificEvent := &keptnv2.ReleaseTriggeredEventData{} err = incomingEvent.DataAs(specificEvent) if err != nil { t.Errorf("Error getting keptn event data") } - - err = HandleReleaseTriggeredEvent(myKeptn, *incomingEvent, specificEvent) - if err != nil { - t.Errorf("Error: " + err.Error()) - } } diff --git a/eventhandlers.go b/eventhandlers.go index 98dc633..3b9df09 100644 --- a/eventhandlers.go +++ b/eventhandlers.go @@ -3,12 +3,10 @@ package main // Here is a generic example of an echo service: https://github.com/keptn-sandbox/echo-service // It listens for all cloud events (see deploy/service.yaml: PUBSUB_TOPIC wildcard: "sh.keptn.>"") and automatically responds with .started and .finished events import ( - "fmt" "log" "time" cloudevents "github.com/cloudevents/sdk-go/v2" // make sure to use v2 cloudevents here - keptn "github.com/keptn/go-utils/pkg/lib" keptnv2 "github.com/keptn/go-utils/pkg/lib/v0_2_0" ) diff --git a/helm/testkube-executor-keptn/Chart.yaml b/helm/testkube-executor-keptn/Chart.yaml index 74c051c..a81d929 100644 --- a/helm/testkube-executor-keptn/Chart.yaml +++ b/helm/testkube-executor-keptn/Chart.yaml @@ -1,24 +1,6 @@ apiVersion: v2 -name: keptn-service-template-go -description: Helm Chart for the keptn keptn-service-template-go - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. +appVersion: 0.11.8 +description: Helm Chart for the Test Kube Executor Keptn +name: testkube-executor-keptn type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -# Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.8.0 - -# This is the version number of the application being deployed. This version number should be -# incremented each time you make changes to the application. Versions are not expected to -# follow Semantic Versioning. They should reflect the version the application is using. -# It is recommended to use it with quotes. -appVersion: "0.8.0" \ No newline at end of file +version: 0.11.8 diff --git a/helm/testkube-executor-keptn/README.md b/helm/testkube-executor-keptn/README.md index e284a1d..a07861c 100644 --- a/helm/testkube-executor-keptn/README.md +++ b/helm/testkube-executor-keptn/README.md @@ -1,20 +1,18 @@ - -keptn-service-template-go +testkube-executor-keptn =========== -Helm Chart for the keptn keptn-service-template-go - +Helm Chart for the keptn testkube-executor-keptn ## Configuration -The following table lists the configurable parameters of the keptn-service-template-go chart and their default values. +The following table lists the configurable parameters of the testkube-executor-keptn chart and their default values. | Parameter | Description | Default | | ------------------------ | ----------------------- | -------------- | -| `image.repository` | Container image name | `"ghcr.io/kubeshop/testkube-executor-keptn"` | +| `image.repository` | Container image name | `"kubeshop/testkube-executor-keptn"` | | `image.pullPolicy` | Kubernetes image pull policy | `"IfNotPresent"` | | `image.tag` | Container tag | `""` | -| `service.enabled` | Creates a kubernetes service for the keptn-service-template-go | `true` | +| `service.enabled` | Creates a kubernetes service for the testkube-executor-keptn | `true` | | `distributor.stageFilter` | Sets the stage this helm service belongs to | `""` | | `distributor.serviceFilter` | Sets the service this helm service belongs to | `""` | | `distributor.projectFilter` | Sets the project this helm service belongs to | `""` | @@ -38,8 +36,3 @@ The following table lists the configurable parameters of the keptn-service-templ | `nodeSelector` | Node selector configuration | `{}` | | `tolerations` | Tolerations for the pods | `[]` | | `affinity` | Affinity rules | `{}` | - - - - - diff --git a/helm/testkube-executor-keptn/values.yaml b/helm/testkube-executor-keptn/values.yaml index 61073ca..1fe7810 100644 --- a/helm/testkube-executor-keptn/values.yaml +++ b/helm/testkube-executor-keptn/values.yaml @@ -3,7 +3,7 @@ image: pullPolicy: IfNotPresent # Kubernetes Image Pull Policy tag: "0.12.0" # Container Tag service: - enabled: true # Creates a Kubernetes Service for the keptn-service-template-go + enabled: true # Creates a Kubernetes Service for the testkube-executor-keptn distributor: stageFilter: "" # Sets the stage this helm service belongs to @@ -41,13 +41,6 @@ securityContext: {} # Set the security context (e.g. ru # runAsUser: 1000 resources: # Resource limits and requests - # We usually recommend not to specify default resources and to leave this as a conscious - # choice for the user. This also increases chances charts run on environments with little - # resources, such as Minikube. If you do want to specify resources, uncomment the following - # lines, adjust them as necessary, and remove the curly braces after 'resources:'. - # limits: - # cpu: 100m - # memory: 128Mi requests: cpu: 100m memory: 128Mi diff --git a/main.go b/main.go index 72857da..a4148f1 100644 --- a/main.go +++ b/main.go @@ -1,22 +1,5 @@ package main -/* - Notes: Your pod (service) will be deployed with a sidecar container called the Keptn distributor. - The distributors job is to connect to Keptn's core and ensure that cloudevents are received. - The cloudevents you choose to receive are defined either at deployment time (distributor.pubsubTopic) or adjustable from the keptns bridge - When the cloud event is received, the processKeptnCloudEvent function is fired. - - TODO: Change the ServiceName to reflect whatever you want to call this service - TODO: Start your logic in the processKeptnCloudEvent function - - -- Every Keptn service has a lifecycle -- - 1) A keptn service typically responds to receiving an {event}.triggered cloudevent from Keptn. This service most likely will respond to a sh.keptn.event.test.triggered cloudevent - 2) Every Leptn service MUST send a .started event back to Keptn. This signals to Keptn that this service is starting some work - 3) Every Keptn service MAY send one or more .status.changed events back to Keptn. This signals that the work is still ongoing but the service would like to update Keptn of progress and values - 4) Every Keptn service MUST send a .finished event back to Keptn. This signals to Keptn that this service is finished, and usually some useful data is also returned - - You can find the outline of this lifecycle in eventhandlers.go -*/ import ( "context" "errors" @@ -26,7 +9,6 @@ import ( cloudevents "github.com/cloudevents/sdk-go/v2" // make sure to use v2 cloudevents here "github.com/kelseyhightower/envconfig" - keptnlib "github.com/keptn/go-utils/pkg/lib" keptn "github.com/keptn/go-utils/pkg/lib/keptn" keptnv2 "github.com/keptn/go-utils/pkg/lib/v0_2_0" ) @@ -45,7 +27,7 @@ type envConfig struct { } // ServiceName specifies the current services name (e.g., used as source when sending CloudEvents) -const ServiceName = "keptn-service-template-go" +const ServiceName = "testkube-executor-keptn" /** * Parses a Keptn Cloud Event payload (data attribute) diff --git a/skaffold.yaml b/skaffold.yaml index 0838a02..cf488d2 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -14,7 +14,7 @@ deploy: flags: upgrade: ["--reuse-values", "--install"] releases: - - name: keptn-service-template-go + - name: testkube-executor-keptn namespace: keptn artifactOverrides: image: kubeshop/testkube-executor-keptn # Todo: Replace this with your image name diff --git a/test-events/get-sli.triggered.json b/test-events/get-sli.triggered.json index f32b2e7..b123b31 100644 --- a/test-events/get-sli.triggered.json +++ b/test-events/get-sli.triggered.json @@ -7,7 +7,7 @@ "response_time_p95", "some_other_metric" ], - "sliProvider": "keptn-service-template-go", + "sliProvider": "testkube-executor-keptn", "start": "2021-01-15T15:04:45.000Z" }, "labels": null,