keptn-sandbox / crossplane-service

Apache License 2.0
4 stars 0 forks source link

Crossplane Service

GitHub release (latest by date) Go Report Card

This service interacts with Crossplane to manage infrastructure via declarative YAML files. The current implementation aims to create Kubernetes clusters on demand via Crossplane (triggered by Keptn) and to delete the clusters (also triggered via Keptn). Therefore, the services makes us of two kind of Keptn cloud events:

A simple shipyard that makes use of this:

apiVersion: "spec.keptn.sh/0.2.0"
kind: "Shipyard"
metadata:
  name: "keptn-crossplane"
spec:
  stages:
    - name: "perf-test"
      sequences:
        - name: "delivery"
          tasks:
            - name: "environment-setup"
              properties:
                size: "medium"
            - name: "deployment"
              properties:
                deploymentstrategy: "user_managed"
            - name: "test"
              properties:
                teststrategy: "performance"
            - name: "evaluation"
             - name: "environment-teardown"

The crossplane-service will look for a resource crossplane/cluster.yaml in the Keptn managed git-repository and will basically execute a kubectl apply or kubectl delete on this resource to either create or delete the cluster. In the example, the created cluster is already equipped with additional Keptn services, such as the job-executor and the helm-service.

Demo

Instructions how to install Crossplane can be found here: https://crossplane.io/docs/v1.4/getting-started/install-configure.html

Instructions how to install the Crossplane Civo Provider can found here: https://github.com/crossplane-contrib/provider-civo

Please find demo resources in the demo/ folder of this repo.

Compatibility Matrix

Please fill in your versions accordingly

Keptn Version crossplane-service Docker Image
0.9.2 keptnsandbox/crossplane-service:0.1.0 under development

Installation

The crossplane-service can be installed as a part of Keptn's uniform.

Deploy in your Kubernetes cluster

To deploy the current version of the crossplane-service in your Keptn Kubernetes cluster, apply the deploy/service.yaml file:

kubectl apply -f deploy/service.yaml

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

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):

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

Uninstall

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

kubectl delete -f deploy/service.yaml

Development

Development can be conducted using any GoLang compatible IDE/editor (e.g., Jetbrains GoLand, VSCode with Go plugins).

It is recommended to make use of branches as follows:

When writing code, it is recommended to follow the coding style suggested by the Golang community.

Where to start

If you don't care about the details, your first entrypoint is eventhandlers.go. Within this file you can add implementation for pre-defined Keptn Cloud events.

To better understand all variants of Keptn CloudEvents, please look at the Keptn Spec.

If you want to get more insights into processing those CloudEvents or even defining your own CloudEvents in code, please look into main.go (specifically processKeptnCloudEvent), deploy/service.yaml, consult the Keptn docs as well as existing Keptn Core and Keptn Contrib services.

Common tasks

Testing Cloud Events

We have dummy cloud-events in the form of RFC 2616 requests in the test-events/ directory. These can be easily executed using third party plugins such as the Huachao Mao REST Client in VS Code.

Automation

GitHub Actions: Automated Pull Request Review

This repo uses reviewdog for automated reviews of Pull Requests.

You can find the details in .github/workflows/reviewdog.yml.

GitHub Actions: Unit Tests

This repo has automated unit tests for pull requests.

You can find the details in .github/workflows/tests.yml.

GH Actions/Workflow: Build Docker Images

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 and the two GitHub Secrets

How to release a new version of this service

It is assumed that the current development takes place in the master branch (either via Pull Requests or directly).

To make use of the built-in automation using GH Actions for releasing a new version of this service, you should

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

License

Please find more information in the LICENSE file.