Skip to content

Commit

Permalink
Merge pull request #40 from steadybit/feat/collection_discovery
Browse files Browse the repository at this point in the history
Feat/collection discovery
  • Loading branch information
ansgarschulte authored Jan 17, 2024
2 parents 22cdc5a + 7608613 commit 657a190
Show file tree
Hide file tree
Showing 20 changed files with 598 additions and 87 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## v2.0.0

- Breaking Changes
- Configure ApiKey in the extension configuration
- Discovery of Postman Collections
- Support for Postman Environments to select the correct environment for the collection by name
- Use a Postman Collection a target for the action

## v1.5.8

- Update dependencies
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ Learn about the capabilities of this extension in our [Reliability Hub](https://

## Configuration


Postman_Api_Key
## Configuration

| Environment Variable | Helm value | Meaning | Required | Default |
|---------------------------------------|--------------------------|-----------------------------------------------------------|----------|---------|
| `HTTPS_PROXY` | via extraEnv variables | Configure the proxy to be used for Postman communication. | no | |
| Environment Variable | Helm value | Meaning | Required | Default |
|---------------------------------------|------------------------|-------------------------------------------------------------|----------|---------|
| `HTTPS_PROXY` | via extraEnv variables | Configure the proxy to be used for Postman communication. | no | |
| `STEADYBIT_EXTENSION_POSTMAN_API_KEY` | postman.apiKey | Configure the api-key to be used for Postman communication. | yes | |

The extension supports all environment variables provided by [steadybit/extension-kit](https://github.com/steadybit/extension-kit#environment-variables).

Expand All @@ -46,6 +47,7 @@ helm upgrade steadybit-extension-postman \
--timeout 5m0s \
--create-namespace \
--namespace steadybit-extension \
--set postman.apiKey=<YOUR_API_KEY> \
steadybit-extension-postman/steadybit-extension-postman
```

Expand Down
4 changes: 3 additions & 1 deletion charts/steadybit-extension-postman/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
apiVersion: v2
name: steadybit-extension-postman
description: Steadybit Postman extension Helm chart for Kubernetes.
version: 1.6.27
version: 1.6.28
appVersion: latest
home: https://www.steadybit.com/
icon: https://steadybit-website-assets.s3.amazonaws.com/logo-symbol-transparent.png
maintainers:
- email: [email protected]
name: reuda
- email: [email protected]
name: ansgarschulte
sources:
- https://github.com/steadybit/extension-postman
annotations:
Expand Down
8 changes: 8 additions & 0 deletions charts/steadybit-extension-postman/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{/* vim: set filetype=mustache: */}}

{{/*
Expand the name of the chart.
*/}}
{{- define "postman.secret.name" -}}
{{- default "steadybit-extension-postman" .Values.postman.existingSecret -}}
{{- end -}}
5 changes: 5 additions & 0 deletions charts/steadybit-extension-postman/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ spec:
memory: {{ .Values.resources.limits.memory }}
cpu: {{ .Values.resources.limits.cpu }}
env:
- name: STEADYBIT_EXTENSION_POSTMAN_API_KEY
valueFrom:
secretKeyRef:
name: {{ include "postman.secret.name" . }}
key: apiKey
{{- include "extensionlib.deployment.env" (list .) | nindent 12 }}
{{- with .Values.extraEnv }}
{{- toYaml . | nindent 12 }}
Expand Down
14 changes: 14 additions & 0 deletions charts/steadybit-extension-postman/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{- if not .Values.postman.existingSecret -}}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "postman.secret.name" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- range $key, $value := .Values.extraLabels }}
{{ $key }}: {{ $value }}
{{- end }}
type: Opaque
data:
apiKey: {{ .Values.postman.apiKey | b64enc | quote }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ manifest should match snapshot using podAnnotations and Labels:
spec:
containers:
- env:
- name: STEADYBIT_EXTENSION_POSTMAN_API_KEY
valueFrom:
secretKeyRef:
key: apiKey
name: steadybit-extension-postman
- name: STEADYBIT_LOG_LEVEL
value: INFO
- name: STEADYBIT_LOG_FORMAT
Expand Down Expand Up @@ -104,6 +109,11 @@ manifest should match snapshot with TLS:
spec:
containers:
- env:
- name: STEADYBIT_EXTENSION_POSTMAN_API_KEY
valueFrom:
secretKeyRef:
key: apiKey
name: steadybit-extension-postman
- name: STEADYBIT_LOG_LEVEL
value: INFO
- name: STEADYBIT_LOG_FORMAT
Expand Down Expand Up @@ -191,6 +201,11 @@ manifest should match snapshot with extra env vars:
spec:
containers:
- env:
- name: STEADYBIT_EXTENSION_POSTMAN_API_KEY
valueFrom:
secretKeyRef:
key: apiKey
name: steadybit-extension-postman
- name: STEADYBIT_LOG_LEVEL
value: INFO
- name: STEADYBIT_LOG_FORMAT
Expand Down Expand Up @@ -276,6 +291,11 @@ manifest should match snapshot with extra labels:
spec:
containers:
- env:
- name: STEADYBIT_EXTENSION_POSTMAN_API_KEY
valueFrom:
secretKeyRef:
key: apiKey
name: steadybit-extension-postman
- name: STEADYBIT_LOG_LEVEL
value: INFO
- name: STEADYBIT_LOG_FORMAT
Expand Down Expand Up @@ -352,6 +372,11 @@ manifest should match snapshot with mutual TLS:
spec:
containers:
- env:
- name: STEADYBIT_EXTENSION_POSTMAN_API_KEY
valueFrom:
secretKeyRef:
key: apiKey
name: steadybit-extension-postman
- name: STEADYBIT_LOG_LEVEL
value: INFO
- name: STEADYBIT_LOG_FORMAT
Expand Down Expand Up @@ -448,6 +473,11 @@ manifest should match snapshot with mutual TLS using containerPaths:
spec:
containers:
- env:
- name: STEADYBIT_EXTENSION_POSTMAN_API_KEY
valueFrom:
secretKeyRef:
key: apiKey
name: steadybit-extension-postman
- name: STEADYBIT_LOG_LEVEL
value: INFO
- name: STEADYBIT_LOG_FORMAT
Expand Down Expand Up @@ -530,6 +560,11 @@ manifest should match snapshot with podSecurityContext:
spec:
containers:
- env:
- name: STEADYBIT_EXTENSION_POSTMAN_API_KEY
valueFrom:
secretKeyRef:
key: apiKey
name: steadybit-extension-postman
- name: STEADYBIT_LOG_LEVEL
value: INFO
- name: STEADYBIT_LOG_FORMAT
Expand Down Expand Up @@ -608,6 +643,11 @@ manifest should match snapshot with priority class:
spec:
containers:
- env:
- name: STEADYBIT_EXTENSION_POSTMAN_API_KEY
valueFrom:
secretKeyRef:
key: apiKey
name: steadybit-extension-postman
- name: STEADYBIT_LOG_LEVEL
value: INFO
- name: STEADYBIT_LOG_FORMAT
Expand Down Expand Up @@ -685,6 +725,11 @@ manifest should match snapshot without TLS:
spec:
containers:
- env:
- name: STEADYBIT_EXTENSION_POSTMAN_API_KEY
valueFrom:
secretKeyRef:
key: apiKey
name: steadybit-extension-postman
- name: STEADYBIT_LOG_LEVEL
value: INFO
- name: STEADYBIT_LOG_FORMAT
Expand Down
5 changes: 5 additions & 0 deletions charts/steadybit-extension-postman/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,8 @@ extraEnv: []
# - secretRef:
# name: env-secrets
extraEnvFrom: []

postman:
apiKey: ""
# postman.existingSecret -- If defined, will skip secret creation and instead assume that the referenced secret contains the apiKey
existingSecret: null
1 change: 1 addition & 0 deletions config/specification.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ package config

type Specification struct {
PostmanBaseUrl string `json:"postmanBaseUrl" split_words:"true" required:"false" default:"https://api.getpostman.com"`
PostmanApiKey string `json:"postmanApiKey" split_words:"true" required:"true"`
}
97 changes: 91 additions & 6 deletions e2e/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
package e2e

import (
"context"
"fmt"
"github.com/rs/zerolog/log"
"github.com/steadybit/action-kit/go/action_kit_api/v2"
"github.com/steadybit/action-kit/go/action_kit_test/e2e"
"github.com/steadybit/discovery-kit/go/discovery_kit_api"
"github.com/steadybit/discovery-kit/go/discovery_kit_test/validate"
"github.com/steadybit/extension-kit/extlogging"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"strings"
"testing"
Expand All @@ -26,31 +32,110 @@ func TestWithMinikube(t *testing.T) {
ExtraArgs: func(m *e2e.Minikube) []string {
return []string{
"--set", "logging.level=debug",
"--set", "postman.apiKey=testApiKey",
"--set", "extraEnv[0].name=STEADYBIT_EXTENSION_POSTMAN_BASE_URL",
"--set", fmt.Sprintf("extraEnv[0].value=%s:%s", "http://host.minikube.internal:", port),
"--set", fmt.Sprintf("extraEnv[0].value=%s:%s", "http://host.minikube.internal", port),
}
},
}

e2e.WithDefaultMinikube(t, &extFactory, []e2e.WithMinikubeTestCase{
{
Name: "validate discovery",
Test: validateDiscovery,
},
{
Name: "target discovery",
Test: testDiscovery,
},
{
Name: "run postman",
Test: testRunPostman,
},
{
Name: "run postman with env name",
Test: testRunPostmanWithEnvName,
},
{
Name: "run postman with env id",
Test: testRunPostmanWithEnvId,
},
})
}

func validateDiscovery(t *testing.T, _ *e2e.Minikube, e *e2e.Extension) {
assert.NoError(t, validate.ValidateEndpointReferences("/", e.Client))
}

func testDiscovery(t *testing.T, _ *e2e.Minikube, e *e2e.Extension) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

target, err := e2e.PollForTarget(ctx, e, "com.steadybit.extension_postman.collection", func(target discovery_kit_api.Target) bool {
log.Info().Msgf("Checking target: %s", target)
return e2e.HasAttribute(target, "steadybit.label", "shopping-demo")
})

require.NoError(t, err)
assert.Equal(t, target.TargetType, "com.steadybit.extension_postman.collection")
assert.Equal(t, target.Attributes["postman.collection.id"], []string{collectionId})
assert.Equal(t, target.Attributes["postman.collection.name"], []string{"shopping-demo"})
}

func testRunPostman(t *testing.T, m *e2e.Minikube, e *e2e.Extension) {
config := struct {
CollectionId string
ApiKey string
}{}

target := action_kit_api.Target{
Attributes: map[string][]string{
"postman.collection.id": {collectionId},
},
}

exec, err := e.RunAction("com.steadybit.extension_postman.collection.run.v2", &target, config, nil)
require.NoError(t, err)
e2e.AssertLogContainsWithTimeout(t, m, e.Pod, "Starting newman!", 90*time.Second)
e2e.AssertLogContainsWithTimeout(t, m, e.Pod, "Postman run completed successfully", 90*time.Second)
require.NoError(t, exec.Cancel())
}

func testRunPostmanWithEnvId(t *testing.T, m *e2e.Minikube, e *e2e.Extension) {
config := struct {
EnvironmentIdOrName string
}{
CollectionId: "testCollectionId",
ApiKey: "testApiKey",
EnvironmentIdOrName: "70cb2138-3443-4c33-a45c-73477a5fd903",
}

target := action_kit_api.Target{
Attributes: map[string][]string{
"postman.collection.id": {collectionId},
},
}

exec, err := e.RunAction("com.steadybit.extension_postman.collection.run.v2", &target, config, nil)
require.NoError(t, err)
e2e.AssertLogContainsWithTimeout(t, m, e.Pod, "--environment", 90*time.Second)
e2e.AssertLogContainsWithTimeout(t, m, e.Pod, "Starting newman!", 90*time.Second)
e2e.AssertLogContainsWithTimeout(t, m, e.Pod, "Postman run completed successfully", 90*time.Second)
require.NoError(t, exec.Cancel())
}

func testRunPostmanWithEnvName(t *testing.T, m *e2e.Minikube, e *e2e.Extension) {
config := struct {
EnvironmentIdOrName string
}{
EnvironmentIdOrName: "dev",
}

target := action_kit_api.Target{
Attributes: map[string][]string{
"postman.collection.id": {collectionId},
},
}

exec, err := e.RunAction("com.steadybit.extension_postman.collection.run", nil, config, nil)
exec, err := e.RunAction("com.steadybit.extension_postman.collection.run.v2", &target, config, nil)
require.NoError(t, err)
e2e.AssertLogContainsWithTimeout(t, m, e.Pod, "--environment", 90*time.Second)
e2e.AssertLogContainsWithTimeout(t, m, e.Pod, "Starting newman!", 90*time.Second)
e2e.AssertLogContainsWithTimeout(t, m, e.Pod, "Postman run completed successfully", 90*time.Second)
require.NoError(t, exec.Cancel())
Expand Down
Loading

0 comments on commit 657a190

Please sign in to comment.