Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: jetzlstorfer <[email protected]>
  • Loading branch information
jetzlstorfer committed Sep 3, 2021
1 parent 4a6709e commit dfacf50
Show file tree
Hide file tree
Showing 16 changed files with 571 additions and 540 deletions.
2 changes: 1 addition & 1 deletion .ci_env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DOCKER_ORGANIZATION="keptnsandbox"
IMAGE="keptn-service-template-go"
IMAGE="crossplane-service"
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
crossplane-service

# IDE specific folders
.vscode
Expand Down

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

1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
# https://help.github.com/en/articles/about-code-owners
#

@jetzlstorfer
17 changes: 13 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FROM golang:1.16.2-alpine as builder

RUN apk add --no-cache gcc libc-dev git

WORKDIR /src/keptn-service-template-go
WORKDIR /src/crossplane-service

ARG version=develop
ENV VERSION="${version}"
Expand All @@ -32,7 +32,7 @@ COPY . .

# Build the command inside the container.
# (You may fetch or manage dependencies here, either manually or with a tool like "godep".)
RUN GOOS=linux go build -ldflags '-linkmode=external' $BUILDFLAGS -v -o keptn-service-template-go
RUN GOOS=linux go build -ldflags '-linkmode=external' $BUILDFLAGS -v -o crossplane-service

# Use a Docker multi-stage build to create a lean production image.
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
Expand All @@ -42,6 +42,15 @@ ENV ENV=production
# Install extra packages
# See https://github.com/gliderlabs/docker-alpine/issues/136#issuecomment-272703023

ARG KUBE_VERSION=1.20.0
RUN wget -q https://storage.googleapis.com/kubernetes-release/release/v$KUBE_VERSION/bin/linux/amd64/kubectl -O /bin/kubectl && \
chmod +x /bin/kubectl

ARG HELM_VERSION=3.6.3
RUN wget -q https://get.helm.sh/helm-v$HELM_VERSION-linux-amd64.tar.gz && \
tar -zxvf helm-v$HELM_VERSION-linux-amd64.tar.gz && \
mv linux-amd64/helm /bin/helm

RUN apk update && apk upgrade \
&& apk add ca-certificates libc6-compat \
&& update-ca-certificates \
Expand All @@ -51,7 +60,7 @@ ARG version=develop
ENV VERSION="${version}"

# Copy the binary to the production image from the builder stage.
COPY --from=builder /src/keptn-service-template-go/keptn-service-template-go /keptn-service-template-go
COPY --from=builder /src/crossplane-service/crossplane-service /crossplane-service

EXPOSE 8080

Expand All @@ -64,4 +73,4 @@ ENV GOTRACEBACK=all
#build-uncomment ENTRYPOINT ["/entrypoint.sh"]

# Run the web service on container startup.
CMD ["/keptn-service-template-go"]
CMD ["/crossplane-service"]
56 changes: 29 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# README

# WORK IN PROGRESS

This is a Keptn Service Template written in GoLang. Follow the instructions below for writing your own Keptn integration.

Quick start:

1. In case you want to contribute your service to keptn-sandbox or keptn-contrib, make sure you have read and understood the [Contributing Guidelines](https://github.com/keptn-sandbox/contributing).
1. Click [Use this template](https://github.com/keptn-sandbox/keptn-service-template-go/generate) on top of the repository, or download the repo as a zip-file, extract it into a new folder named after the service you want to create (e.g., simple-service)
1. Replace every occurrence of (docker) image names and tags from `keptnsandbox/keptn-service-template-go` to your docker organization and image name (e.g., `yourorganization/simple-service`)
1. Replace every occurrence of `keptn-service-template-go` with the name of your service (e.g., `simple-service`)
1. Click [Use this template](https://github.com/keptn-sandbox/crossplane-service/generate) on top of the repository, or download the repo as a zip-file, extract it into a new folder named after the service you want to create (e.g., simple-service)
1. Replace every occurrence of (docker) image names and tags from `keptnsandbox/crossplane-service` to your docker organization and image name (e.g., `yourorganization/simple-service`)
1. Replace every occurrence of `crossplane-service` with the name of your service (e.g., `simple-service`)
1. Optional (but recommended): Create a git repo (e.g., on `github.com/your-username/simple-service`)
1. Àdapt the [go.mod](go.mod) file and change `example.com/` to the actual package name (e.g., `github.com/your-username/simple-service`)
1. Add yourself to the [CODEOWNERS](CODEOWNERS) file
Expand All @@ -21,52 +23,52 @@ Quick start:

---

# keptn-service-template-go
![GitHub release (latest by date)](https://img.shields.io/github/v/release/keptn-sandbox/keptn-service-template-go)
[![Go Report Card](https://goreportcard.com/badge/github.com/keptn-sandbox/keptn-service-template-go)](https://goreportcard.com/report/github.com/keptn-sandbox/keptn-service-template-go)
# crossplane-service
![GitHub release (latest by date)](https://img.shields.io/github/v/release/keptn-sandbox/crossplane-service)
[![Go Report Card](https://goreportcard.com/badge/github.com/keptn-sandbox/crossplane-service)](https://goreportcard.com/report/github.com/keptn-sandbox/crossplane-service)

This implements a keptn-service-template-go for Keptn. If you want to learn more about Keptn visit us on [keptn.sh](https://keptn.sh)
This implements a crossplane-service for Keptn. If you want to learn more about Keptn visit us on [keptn.sh](https://keptn.sh)

## Compatibility Matrix

*Please fill in your versions accordingly*

| Keptn Version | [Keptn-Service-Template-Go Docker Image](https://hub.docker.com/r/keptnsandbox/keptn-service-template-go/tags) |
| Keptn Version | [crossplane-service Docker Image](https://hub.docker.com/r/keptnsandbox/crossplane-service/tags) |
|:----------------:|:----------------------------------------:|
| 0.6.1 | keptnsandbox/keptn-service-template-go:0.1.0 |
| 0.7.1 | keptnsandbox/keptn-service-template-go:0.1.1 |
| 0.7.2 | keptnsandbox/keptn-service-template-go:0.1.2 |
| 0.6.1 | keptnsandbox/crossplane-service:0.1.0 |
| 0.7.1 | keptnsandbox/crossplane-service:0.1.1 |
| 0.7.2 | keptnsandbox/crossplane-service:0.1.2 |

## Installation

The *keptn-service-template-go* can be installed as a part of [Keptn's uniform](https://keptn.sh).
The *crossplane-service* can be installed as a part of [Keptn's uniform](https://keptn.sh).

### Deploy in your Kubernetes cluster

To deploy the current version of the *keptn-service-template-go* in your Keptn Kubernetes cluster, apply the [`deploy/service.yaml`](deploy/service.yaml) file:
To deploy the current version of the *crossplane-service* in your Keptn Kubernetes cluster, apply the [`deploy/service.yaml`](deploy/service.yaml) file:

```console
kubectl apply -f deploy/service.yaml
```

This should install the `keptn-service-template-go` together with a Keptn `distributor` into the `keptn` namespace, which you can verify using
This should install the `crossplane-service` together with a Keptn `distributor` into the `keptn` namespace, which you can verify using

```console
kubectl -n keptn get deployment keptn-service-template-go -o wide
kubectl -n keptn get pods -l run=keptn-service-template-go
kubectl -n keptn get deployment crossplane-service -o wide
kubectl -n keptn get pods -l run=crossplane-service
```

### Up- or Downgrading

Adapt and use the following command in case you want to up- or downgrade your installed version (specified by the `$VERSION` placeholder):

```console
kubectl -n keptn set image deployment/keptn-service-template-go keptn-service-template-go=keptnsandbox/keptn-service-template-go:$VERSION --record
kubectl -n keptn set image deployment/crossplane-service crossplane-service=keptnsandbox/crossplane-service:$VERSION --record
```

### Uninstall

To delete a deployed *keptn-service-template-go*, use the file `deploy/*.yaml` files from this repository and delete the Kubernetes resources:
To delete a deployed *crossplane-service*, use the file `deploy/*.yaml` files from this repository and delete the Kubernetes resources:

```console
kubectl delete -f deploy/service.yaml
Expand Down Expand Up @@ -99,16 +101,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 crossplane-service`
* Run tests: `go test -race -v ./...`
* Build the docker image: `docker build . -t keptnsandbox/keptn-service-template-go:dev` (Note: Ensure that you use the correct DockerHub account/organization)
* Run the docker image locally: `docker run --rm -it -p 8080:8080 keptnsandbox/keptn-service-template-go:dev`
* Push the docker image to DockerHub: `docker push keptnsandbox/keptn-service-template-go:dev` (Note: Ensure that you use the correct DockerHub account/organization)
* Build the docker image: `docker build . -t keptnsandbox/crossplane-service:dev` (Note: Ensure that you use the correct DockerHub account/organization)
* Run the docker image locally: `docker run --rm -it -p 8080:8080 keptnsandbox/crossplane-service:dev`
* Push the docker image to DockerHub: `docker push keptnsandbox/crossplane-service:dev` (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 crossplane-service -o wide`
* Get logs using `kubectl`: `kubectl -n keptn logs deployment/crossplane-service -f`
* Watch the deployed pods using `kubectl`: `kubectl -n keptn get pods -l run=crossplane-service`
* 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 All @@ -134,7 +136,7 @@ You can find the details in [.github/workflows/tests.yml](.github/workflows/test

This repo uses GH Actions and Workflows to test the code and automatically build docker images.

Docker Images are automatically pushed based on the configuration done in [.ci_env](.ci_env) and the two [GitHub Secrets](https://github.com/keptn-sandbox/keptn-service-template-go/settings/secrets/actions)
Docker Images are automatically pushed based on the configuration done in [.ci_env](.ci_env) and the two [GitHub Secrets](https://github.com/keptn-sandbox/crossplane-service/settings/secrets/actions)
* `REGISTRY_USER` - your DockerHub username
* `REGISTRY_PASSWORD` - a DockerHub [access token](https://hub.docker.com/settings/security) (alternatively, your DockerHub password)

Expand All @@ -155,7 +157,7 @@ If any problems occur, fix them in the release branch and test them again.

Once you have confirmed that everything works and your version is ready to go, you should

* create a new release on the release branch using the [GitHub releases page](https://github.com/keptn-sandbox/keptn-service-template-go/releases), and
* create a new release on the release branch using the [GitHub releases page](https://github.com/keptn-sandbox/crossplane-service/releases), and
* merge any changes from the release branch back to the master branch.

## License
Expand Down
88 changes: 75 additions & 13 deletions deploy/service.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,67 @@
---
# Deployment of our keptn-service-template-go
apiVersion: v1
kind: ServiceAccount
metadata:
name: keptn-crossplane-service
namespace: keptn
labels:
name: keptn-crossplane-service
---
# Source: openebs/templates/clusterrole.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: keptn-crossplane-service
labels:
name: keptn-crossplane-service
rules:
- apiGroups: ["","cluster.civo.crossplane.io","devopstoolkitseries.com"]
resources: ["*"]
verbs: ["create","delete","get","list","patch","update"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: keptn-crossplane-service
labels:
name: keptn-crossplane-service
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: keptn-crossplane-service
subjects:
- kind: ServiceAccount
name: keptn-crossplane-service
namespace: keptn
---
# Deployment of our crossplane-service
apiVersion: apps/v1
kind: Deployment
metadata:
name: keptn-service-template-go
name: crossplane-service
namespace: keptn
spec:
selector:
matchLabels:
run: keptn-service-template-go
run: crossplane-service
replicas: 1
template:
metadata:
labels:
run: keptn-service-template-go
run: crossplane-service
app.kubernetes.io/name: crossplane-service
app.kubernetes.io/version: dev
spec:
containers:
- name: keptn-service-template-go
image: keptnsandbox/keptn-service-template-go:latest # Todo: Replace this with your image name
- name: crossplane-service
image: keptnsandbox/crossplane-service # Todo: Replace this with your image name
ports:
- containerPort: 8080
env:
- name: CONFIGURATION_SERVICE
value: 'http://configuration-service:8080'
- name: distributor
image: keptn/distributor:0.8.3
image: keptn/distributor:0.8.7
livenessProbe:
httpGet:
path: /health
Expand All @@ -45,23 +82,48 @@ spec:
- name: PUBSUB_URL
value: 'nats://keptn-nats-cluster'
- name: PUBSUB_TOPIC
value: 'sh.keptn.>'
value: 'sh.keptn.event.environment-setup.>,sh.keptn.event.environment-teardown.>'
- name: PUBSUB_RECIPIENT
value: '127.0.0.1'
serviceAccountName: keptn-default
- name: VERSION
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: 'metadata.labels[''app.kubernetes.io/version'']'
- name: K8S_DEPLOYMENT_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: 'metadata.labels[''app.kubernetes.io/name'']'
- name: K8S_POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: K8S_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: K8S_NODE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
serviceAccountName: keptn-crossplane-service
---
# Expose keptn-service-template-go via Port 8080 within the cluster
# Expose crossplane-service via Port 8080 within the cluster
apiVersion: v1
kind: Service
metadata:
name: keptn-service-template-go
name: crossplane-service
namespace: keptn
labels:
run: keptn-service-template-go
run: crossplane-service
spec:
ports:
- port: 8080
protocol: TCP
selector:
run: keptn-service-template-go
run: crossplane-service

Loading

0 comments on commit dfacf50

Please sign in to comment.