Skip to content

Commit 337651e

Browse files
authored
Merge pull request #51 from keptn-sandbox/feat/47/add-tests
feat(actions): github workflow for integration tests 2
2 parents 6d7cf18 + 3cac6b3 commit 337651e

File tree

7 files changed

+547
-20
lines changed

7 files changed

+547
-20
lines changed

.github/workflows/integration-tests.yaml

Lines changed: 409 additions & 0 deletions
Large diffs are not rendered by default.

go.mod

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/vadasambar/datadog-service
22

3-
go 1.16
3+
go 1.17
44

55
require (
66
github.com/DataDog/datadog-api-client-go v1.6.0
@@ -13,3 +13,58 @@ require (
1313
github.com/stretchr/testify v1.7.1
1414
k8s.io/client-go v0.24.3
1515
)
16+
17+
require (
18+
github.com/PuerkitoBio/purell v1.1.1 // indirect
19+
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
20+
github.com/benbjohnson/clock v1.3.0 // indirect
21+
github.com/cloudevents/sdk-go/observability/opentelemetry/v2 v2.0.0-20211001212819-74757a691209 // indirect
22+
github.com/davecgh/go-spew v1.1.1 // indirect
23+
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
24+
github.com/felixge/httpsnoop v1.0.2 // indirect
25+
github.com/go-logr/logr v1.2.0 // indirect
26+
github.com/go-openapi/jsonpointer v0.19.5 // indirect
27+
github.com/go-openapi/jsonreference v0.19.5 // indirect
28+
github.com/go-openapi/swag v0.19.14 // indirect
29+
github.com/gogo/protobuf v1.3.2 // indirect
30+
github.com/golang/protobuf v1.5.2 // indirect
31+
github.com/google/gnostic v0.5.7-v3refs // indirect
32+
github.com/google/gofuzz v1.1.0 // indirect
33+
github.com/google/uuid v1.3.0 // indirect
34+
github.com/imdario/mergo v0.3.5 // indirect
35+
github.com/josharian/intern v1.0.0 // indirect
36+
github.com/json-iterator/go v1.1.12 // indirect
37+
github.com/mailru/easyjson v0.7.6 // indirect
38+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
39+
github.com/modern-go/reflect2 v1.0.2 // indirect
40+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
41+
github.com/pmezard/go-difflib v1.0.0 // indirect
42+
github.com/spf13/pflag v1.0.5 // indirect
43+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.27.0 // indirect
44+
go.opentelemetry.io/otel v1.2.0 // indirect
45+
go.opentelemetry.io/otel/internal/metric v0.25.0 // indirect
46+
go.opentelemetry.io/otel/metric v0.25.0 // indirect
47+
go.opentelemetry.io/otel/trace v1.2.0 // indirect
48+
go.uber.org/atomic v1.4.0 // indirect
49+
go.uber.org/multierr v1.1.0 // indirect
50+
go.uber.org/zap v1.10.0 // indirect
51+
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
52+
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
53+
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
54+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
55+
golang.org/x/text v0.3.7 // indirect
56+
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
57+
google.golang.org/appengine v1.6.7 // indirect
58+
google.golang.org/protobuf v1.27.1 // indirect
59+
gopkg.in/inf.v0 v0.9.1 // indirect
60+
gopkg.in/yaml.v2 v2.4.0 // indirect
61+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
62+
k8s.io/api v0.24.3 // indirect
63+
k8s.io/apimachinery v0.24.3 // indirect
64+
k8s.io/klog/v2 v2.60.1 // indirect
65+
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
66+
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
67+
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
68+
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
69+
sigs.k8s.io/yaml v1.2.0 // indirect
70+
)

test/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
### Creating everything manually for debugging
2+
#### While running a local cluster
3+
password=$(date +%s | sha256sum | base64 | head -c 32)
4+
export GITEA_ADMIN_PASSWORD=$password
5+
export GITEA_ADMIN_USERNAME=GiteaAdmin
6+
export GITEA_NAMESPACE=gitea
7+
export GITEA_ENDPOINT="http://gitea-http.${GITEA_NAMESPACE}:3000"
8+
helm repo add gitea-charts https://dl.gitea.io/charts/
9+
helm repo update
10+
helm install -n ${GITEA_NAMESPACE} gitea gitea-charts/gitea \
11+
--create-namespace \
12+
--set memcached.enabled=false \
13+
--set postgresql.enabled=false \
14+
--set gitea.config.database.DB_TYPE=sqlite3 \
15+
--set gitea.admin.username=${GITEA_ADMIN_USERNAME} \
16+
--set gitea.admin.password=${GITEA_ADMIN_PASSWORD} \
17+
--set gitea.config.server.OFFLINE_MODE=true \
18+
--set gitea.config.server.ROOT_URL=${GITEA_ENDPOINT}/ \
19+
--wait
20+
helm install keptn-gitea-provisioner-service https://github.com/keptn-sandbox/keptn-gitea-provisioner-service/releases/download/0.1.0/keptn-gitea-provisioner-service-0.1.0.tgz \
21+
--set gitea.endpoint=${GITEA_ENDPOINT} \
22+
--set gitea.admin.create=true \
23+
--set gitea.admin.username=${GITEA_ADMIN_USERNAME} \
24+
--set gitea.admin.password=${GITEA_ADMIN_PASSWORD} \
25+
--wait -ndefault
26+
27+
#### After cluster is created and Keptn has been installed
28+
keptn create project e2e-project --shipyard=shipyard/podtatohead.deployment.yaml
29+
30+
keptn create service podtatoserver --project=e2e-project
31+
32+
keptn add-resource --project="e2e-project" --stage="staging" --service="podtatoserver" --resource=data/podtatohead.sli.yaml --resourceUri=datadog/sli.yaml
33+
34+
keptn add-resource --project=e2e-project --service=podtatoserver --all-stages --resource=data/podtatoserver-0.1.0.tgz --resourceUri=helm/podtatoserver.tgz
35+
36+
keptn add-resource --project="e2e-project" --stage="staging" --service="podtatoserver" --resource=data/podtatohead.slo.yaml --resourceUri=slo.yaml
37+
38+
keptn configure monitoring datadog --project=e2e-project --service=podtatoserver
39+
40+
keptn send event -f events/podtatohead.deploy-v0.1.1.triggered.json
41+
42+
#### To install job executor service
43+
JES_NAMESPACE=keptn-jes
44+
KEPTN_API_PROTOCOL=http
45+
KEPTN_API_TOKEN=$(kubectl get secret keptn-api-token -n keptn -ojsonpath='{.data.keptn-api-token}' | base64 -d)
46+
export KEPTN_ENDPOINT=api-gateway-nginx.keptn
47+
TASK_SUBSCRIPTION="sh.keptn.event.deployment.triggered\\,sh.keptn.event.test.triggered"
48+
JES_VERSION="0.2.3"
49+
helm upgrade --install \
50+
--create-namespace -n ${JES_NAMESPACE} \
51+
job-executor-service \
52+
"https://github.com/keptn-contrib/job-executor-service/releases/download/${JES_VERSION}/job-executor-service-${JES_VERSION}.tgz" \
53+
--set remoteControlPlane.autoDetect.enabled="false" \
54+
--set remoteControlPlane.topicSubscription=${TASK_SUBSCRIPTION} \
55+
--set remoteControlPlane.api.token=${KEPTN_API_TOKEN} \
56+
--set remoteControlPlane.api.hostname=${KEPTN_ENDPOINT} \
57+
--set remoteControlPlane.api.protocol=${KEPTN_API_PROTOCOL} \
58+
--wait
59+
60+
kubectl apply \
61+
-f test/data/helm-serviceAccount.yaml \
62+
-f test/data/helm-clusterRole.yaml \
63+
-f test/data/helm-clusterRoleBinding.yaml

test/data/podtatohead.jes-config.yaml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,15 @@ actions:
1717
cmd: [ "helm" ]
1818
args: [ "upgrade", "--install",
1919
"--create-namespace", "-n", "$(KEPTN_PROJECT)-$(KEPTN_STAGE)",
20-
"$(KEPTN_SERVICE)", "/keptn/charts/$(KEPTN_SERVICE).tgz",
20+
"$(KEPTN_SERVICE)", "/keptn/charts/podtatoserver.tgz",
2121
"--set", "image=$(IMAGE)",
2222
"--set", "keptn.project=$(KEPTN_PROJECT)",
2323
"--set", "keptn.stage=$(KEPTN_STAGE)",
2424
"--set", "keptn.service=$(KEPTN_SERVICE)",
2525
"--set", "keptn.deployment=direct",
26+
"--set", "name=$(KEPTN_SERVICE)",
2627
"--wait"
2728
]
2829

29-
- name: "Run tests using locust"
30-
events:
31-
- name: "sh.keptn.event.test.triggered"
32-
tasks:
33-
- name: "Run locust"
34-
maxPollDuration: 360
35-
files:
36-
- locust/basic.py
37-
- locust/locust.conf
38-
image: "locustio/locust"
39-
cmd: [ "locust" ]
40-
args: [ "--config", "/keptn/locust/locust.conf",
41-
"-f", "/keptn/locust/basic.py",
42-
"--host", "http://podtatoserver.$(KEPTN_PROJECT)-$(KEPTN_STAGE):80",
43-
"--only-summary"
44-
]
30+
# TODO: Create an issue to add tests sequence
31+

test/data/podtatoserver-0.1.0.tgz

-47 Bytes
Binary file not shown.

test/e2e/podtatohead_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package e2e
22

33
import (
4-
"fmt"
54
"io/ioutil"
65
"testing"
76
"time"
@@ -28,7 +27,9 @@ func TestPodtatoheadEvaluation(t *testing.T) {
2827
FilePath string
2928
ResourceName string
3029
}{
31-
{FilePath: "../data/podtatoserver-0.1.0.tgz", ResourceName: fmt.Sprintf("helm/%s.tgz", testEnv.EventData.Service)},
30+
{FilePath: "../data/podtatoserver-0.1.0.tgz", ResourceName: "charts/podtatoserver.tgz"},
31+
// {FilePath: "../data/locust.basic.py", ResourceName: "locust/basic.py"},
32+
// {FilePath: "../data/locust.conf", ResourceName: "locust/locust.conf"},
3233
{FilePath: "../data/podtatohead.sli.yaml", ResourceName: "datadog/sli.yaml"},
3334
{FilePath: "../data/podtatohead.slo.yaml", ResourceName: "slo.yaml"},
3435
}

test/e2e/utils.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"path/filepath"
99
"strconv"
10+
"strings"
1011
"testing"
1112
"time"
1213

@@ -71,6 +72,17 @@ func readKeptnContextExtendedCE(path string) (*models.KeptnContextExtendedCE, er
7172
return nil, fmt.Errorf("unable to parse event: %w", err)
7273
}
7374

75+
// we run github actions integration tests in parallel (based on Keptn version and run)
76+
// having a service name for each run (using prefix) ensures that
77+
// SLI results from one run don't mess up with another run of the integration tests
78+
// github action job
79+
prefix := strings.TrimSpace(os.Getenv("PREFIX"))
80+
if prefix != "" {
81+
d := keptnContextExtendedCE.Data.(map[string]interface{})
82+
d["service"] = d["service"].(string) + prefix
83+
keptnContextExtendedCE.Data = d
84+
}
85+
7486
return &keptnContextExtendedCE, nil
7587
}
7688

0 commit comments

Comments
 (0)