Skip to content

Commit

Permalink
Merge pull request #12 from bradmccoydev/fix-errors
Browse files Browse the repository at this point in the history
update errors
  • Loading branch information
bradmccoydev committed Feb 10, 2022
2 parents 8f6006b + 11d893e commit 83b9c6a
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 103 deletions.
4 changes: 2 additions & 2 deletions .ci_env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DOCKER_ORGANIZATION="keptnsandbox"
IMAGE="keptn-service-template-go"
DOCKER_ORGANIZATION="kubeshop"
IMAGE="testkube-executor-keptn"
33 changes: 33 additions & 0 deletions .github/workflows/helm-releaser.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
33 changes: 8 additions & 25 deletions eventhandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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())
}
}
2 changes: 0 additions & 2 deletions eventhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
26 changes: 4 additions & 22 deletions helm/testkube-executor-keptn/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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"
version: 0.11.8
17 changes: 5 additions & 12 deletions helm/testkube-executor-keptn/README.md
Original file line number Diff line number Diff line change
@@ -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 | `""` |
Expand All @@ -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 | `{}` |





9 changes: 1 addition & 8 deletions helm/testkube-executor-keptn/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 1 addition & 19 deletions main.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test-events/get-sli.triggered.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 83b9c6a

Please sign in to comment.