Skip to content

Commit

Permalink
keptn#2983 added keptn spec version to events sent by shipyard-contro…
Browse files Browse the repository at this point in the history
…ller (keptn#3294)

* keptn#2983 added keptn spec versino to events sent by shipyard-controller

Signed-off-by: Florian Bacher <[email protected]>

* keptn#2983 added a little unit test

Signed-off-by: Florian Bacher <[email protected]>

* keptn#2983 get tag name of specification

Signed-off-by: Florian Bacher <[email protected]>

* keptn#2983 remove gitmodules

Signed-off-by: Florian Bacher <[email protected]>

* keptn#2983 re-added specification submodule

Signed-off-by: Florian Bacher <[email protected]>

* keptn#2983 check out submodules

Signed-off-by: Florian Bacher <[email protected]>

* keptn#2983 removed --exact-match from describe tags command

Signed-off-by: Florian Bacher <[email protected]>

* keptn#2983 update models in mongodb-datastore

Signed-off-by: Florian Bacher <[email protected]>

* keptn#2983 update deployment yaml of mongodb-datastore

Signed-off-by: Florian Bacher <[email protected]>

* keptn#2983 removed duplications

Signed-off-by: Florian Bacher <[email protected]>

* keptn#2983 reverted changes to deployment.yaml

Signed-off-by: Florian Bacher <[email protected]>
  • Loading branch information
bacherfl authored Feb 19, 2021
1 parent c4f4813 commit 8498f60
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 24 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
BRANCH: ${{ steps.extract_branch.outputs.BRANCH }}
BRANCH_SLUG: ${{ steps.extract_branch.outputs.BRANCH_SLUG }}
VERSION: ${{ steps.get_version.outputs.VERSION }}
KEPTN_SPEC_VERSION: ${{ steps.get_version.outputs.KEPTN_SPEC_VERSION }}
DATE: ${{ steps.get_datetime.outputs.DATE }}
TIME: ${{ steps.get_datetime.outputs.TIME }}
DATETIME: ${{ steps.get_datetime.outputs.DATETIME }}
Expand All @@ -55,6 +56,7 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0 # need to checkout "all commits" for certain features to work (e.g., get all changed files)
submodules: 'true'

- name: Load CI Environemnt from .ci_env
id: load_ci_env
Expand Down Expand Up @@ -229,9 +231,16 @@ jobs:
fi
fi
# determine keptn spec version
git submodule update --init
cd specification
KEPTN_SPEC_VERSION=$(git describe --tags)
echo "VERSION=${VERSION}"
echo "KEPTN_SPEC_VERSION=${KEPTN_SPEC_VERSION}"
echo "##[set-output name=VERSION;]$(echo ${VERSION})"
echo "##[set-output name=KEPTN_SPEC_VERSION;]$(echo ${KEPTN_SPEC_VERSION})"
- name: Get current date and time
id: get_datetime
run: |
Expand Down Expand Up @@ -548,6 +557,7 @@ jobs:
env:
BRANCH: ${{ needs.prepare_ci_run.outputs.BRANCH }}
VERSION: ${{ needs.prepare_ci_run.outputs.VERSION }}
KEPTN_SPEC_VERSION: ${{ needs.prepare_ci_run.outputs.KEPTN_SPEC_VERSION }}
DATETIME: ${{ needs.prepare_ci_run.outputs.DATE }}${{ needs.prepare_ci_run.outputs.TIME }}
GIT_SHA: ${{ needs.prepare_ci_run.outputs.GIT_SHA }}
steps:
Expand All @@ -565,10 +575,10 @@ jobs:
run: |
if [[ "$BRANCH" == "master" ]]; then
# use VERSION.DATETIME for the image tag (e.g., nightly build)
./gh-actions-scripts/build_installer_helm_chart.sh "${VERSION}" "${VERSION}.${DATETIME}"
./gh-actions-scripts/build_installer_helm_chart.sh "${VERSION}" "${VERSION}.${DATETIME}" "${KEPTN_SPEC_VERSION}"
else
# just use VERSION for the image tag
./gh-actions-scripts/build_installer_helm_chart.sh "${VERSION}" "${VERSION}"
./gh-actions-scripts/build_installer_helm_chart.sh "${VERSION}" "${VERSION}" "${KEPTN_SPEC_VERSION}"
fi
- name: Upload Helm Chart as an artifact
Expand Down
3 changes: 2 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

[submodule "specification"]
path = specification
url = https://github.com/keptn/spec.git
url = https://github.com/keptn/spec
4 changes: 4 additions & 0 deletions gh-actions-scripts/build_installer_helm_chart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

VERSION=$1
IMAGE_TAG=$2
KEPTN_SPEC_VERSION=$3

if [ -z "$VERSION" ]; then
echo "No Version set, exiting..."
Expand All @@ -22,6 +23,9 @@ helm dependency build ${BASE_PATH}/keptn/charts/control-plane
find -name Chart.yaml -exec sed -i -- "s/appVersion: latest/appVersion: ${IMAGE_TAG}/g" {} \;
find -name Chart.yaml -exec sed -i -- "s/version: latest/version: ${VERSION}/g" {} \;

# replace "keptnSpecVersion: latest" with "keptnSpecVersion: $KEPTN_SPEC_VERSION" in all values.yaml files
find -name values.yaml -exec sed -i -- "s/keptnSpecVersion: latest/keptnSpecVersion: ${KEPTN_SPEC_VERSION}/g" {} \;

helm package ${BASE_PATH}/keptn --app-version $VERSION --version $VERSION
if [ $? -ne 0 ]; then
echo "Error packing installer, exiting..."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ spec:
key: password
- name: MONGO_DB_NAME
value: 'keptn'
- name: KEPTN_SPEC_VERSION
value: {{ .Values.keptnSpecVersion }}
ports:
- containerPort: 8080
livenessProbe:
Expand Down
2 changes: 2 additions & 0 deletions installer/manifests/keptn/charts/control-plane/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ mongodb:

prefixPath: ""

keptnSpecVersion: latest

nats:
nameOverride: keptn-nats-cluster
nats.cluster.replicas: 3
Expand Down
6 changes: 3 additions & 3 deletions mongodb-datastore/deploy/mongodb-datastore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ spec:
- containerPort: 8080
resources:
requests:
memory: "128Mi"
memory: "256Mi"
cpu: "100m"
limits:
memory: "256Mi"
cpu: "1000m"
memory: "512Mi"
cpu: "5000m"
env:
- name: DT_CUSTOM_PROP
value: 'keptn_service=mongodb-datastore'
Expand Down
16 changes: 13 additions & 3 deletions mongodb-datastore/models/keptn_context_extended_c_e.go

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

6 changes: 6 additions & 0 deletions mongodb-datastore/restapi/embedded_spec.go

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

2 changes: 2 additions & 0 deletions mongodb-datastore/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ definitions:
type: string
triggeredid:
type: string
shkeptnspecversion:
type: string
error:
type: object
required:
Expand Down
29 changes: 14 additions & 15 deletions shipyard-controller/common/keptn_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (

const defaultKeptnNamespace = "keptn"

const keptnSpecVersionEnvVar = "KEPTN_SPEC_VERSION"

// GetKeptnNamespace godoc
func GetKeptnNamespace() string {
ns := os.Getenv("POD_NAMESPACE")
Expand Down Expand Up @@ -78,6 +80,11 @@ func ValidateShipyardStages(shipyard *keptnv2.Shipyard) error {
return nil
}

// GetKeptnSpecVersion returns the Keptn Spec version the shipyard controller is based on
func GetKeptnSpecVersion() string {
return os.Getenv(keptnSpecVersionEnvVar)
}

// SendEvent godoc
func SendEvent(event cloudevents.Event) error {
ebEndpoint, err := keptncommon.GetServiceEndpoint("EVENTBROKER")
Expand All @@ -90,7 +97,9 @@ func SendEvent(event cloudevents.Event) error {
if err != nil {
return errors.New("Could not initialize Keptn handler: " + err.Error())
}

if specVersion := GetKeptnSpecVersion(); specVersion != "" {
event.SetExtension("shkeptnspecversion", specVersion)
}
err = k.SendCloudEvent(event)
if err != nil {
return errors.New("Could not send CloudEvent: " + err.Error())
Expand All @@ -101,20 +110,7 @@ func SendEvent(event cloudevents.Event) error {
// SendEventWithPayload godoc
// Deprecated will be removed, use functionality from go-utils instead
func SendEventWithPayload(keptnContext, triggeredID, eventType string, payload interface{}) error {
source, _ := url.Parse("shipyard-controller")
event := cloudevents.NewEvent()
event.SetType(eventType)
event.SetSource(source.String())
event.SetDataContentType(cloudevents.ApplicationJSON)
if keptnContext == "" {
event.SetExtension("shkeptncontext", uuid.New().String())
} else {
event.SetExtension("shkeptncontext", keptnContext)
}
if triggeredID != "" {
event.SetExtension("triggeredid", triggeredID)
}
event.SetData(cloudevents.ApplicationJSON, payload)
event := CreateEventWithPayload(keptnContext, triggeredID, eventType, payload)

ebEndpoint, err := keptncommon.GetServiceEndpoint("EVENTBROKER")
if err != nil {
Expand Down Expand Up @@ -148,6 +144,9 @@ func CreateEventWithPayload(keptnContext, triggeredID, eventType string, payload
if triggeredID != "" {
event.SetExtension("triggeredid", triggeredID)
}
if specVersion := GetKeptnSpecVersion(); specVersion != "" {
event.SetExtension("shkeptnspecversion", specVersion)
}
event.SetData(cloudevents.ApplicationJSON, payload)
return event
}
16 changes: 16 additions & 0 deletions shipyard-controller/common/keptn_helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package common

import (
"github.com/stretchr/testify/assert"
"os"
"testing"
)

func TestGetKeptnSpecVersion(t *testing.T) {
specVersion := GetKeptnSpecVersion()
assert.Equal(t, "", specVersion)

os.Setenv(keptnSpecVersionEnvVar, "0.2.0")
specVersion = GetKeptnSpecVersion()
assert.Equal(t, "0.2.0", specVersion)
}
2 changes: 2 additions & 0 deletions shipyard-controller/deploy/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ spec:
key: password
- name: MONGO_DB_NAME
value: 'keptn'
- name: KEPTN_SPEC_VERSION
value: "0.2.0"
ports:
- containerPort: 8080
resources:
Expand Down
1 change: 1 addition & 0 deletions specification
Submodule specification added at b14dc2

0 comments on commit 8498f60

Please sign in to comment.