Skip to content

Commit

Permalink
Merge pull request #104 from jlevesy/jl/dev-env
Browse files Browse the repository at this point in the history
Makefile: add dev-env targets
  • Loading branch information
K-Phoen authored Dec 28, 2021
2 parents 8368815 + 642d965 commit 95014eb
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 4 deletions.
82 changes: 82 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Contributing Guidelines

`dark` is [MIT licensed](LICENSE) and accepts contributions via
GitHub pull requests. This document outlines some of the conventions on
development workflow, commit message formatting, contact points, and other
resources to make it easier to get your contribution accepted.

## Support Channels

The official support channels, for both users and contributors, are:

- GitHub [issues](https://github.com/K-Phoen/dark/issues)

## How to Contribute

Pull Requests (PRs) are the main and exclusive way to contribute to the project.

### Setup

[Fork][fork], then clone the repository:

```
git clone git@github.com:your_github_username/dark.git
cd dark
git remote add upstream https://github.com/K-Phoen/dark.git
git fetch upstream
```

Make sure you have the required tools:

```
make dev-env-check-binaries
```

Start a development environment:

```
make dev-env-start
```

This command will start a lightweight Kubernetes cluster using [k3d](https://k3d.io/v5.2.2/),
provisioned with Grafana, Prometheus and Loki.

The following command will run `dark` against this cluster.

```
make run
```

### Making Changes

Start by creating a new branch for your changes:

```
git checkout master
git fetch upstream
git rebase upstream/master
git checkout -b new-feature
```

Make your changes, then ensure that `make lint` and `make test` still pass. If
you're satisfied with your changes, push them to your fork.

```
git push origin new-feature
```

Then use the GitHub UI to open a pull request.

At this point, you're waiting on us to review your changes. We *try* to respond
to issues and pull requests within a few business days, and we may suggest some
improvements or alternatives. Once your changes are approved, one of the
project maintainers will merge them.

We're much more likely to approve your changes if you:

* Add tests for new functionality.
* Write a [good commit message][commit-message].
* Maintain backward compatibility.

[fork]: https://github.com/K-Phoen/dark/fork
[commit-message]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
52 changes: 48 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,54 @@ test: envtest ## Run tests.
lint: ## Lints the code base.
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.43.0 golangci-lint run -c build/golangci.yaml

DEV_CLUSTER_PORT?=8181
DEV_GRAFANA_HOST=grafana.dark.localhost
DEV_GRAFANA_PASSWORD=$(shell kubectl get secret loki-grafana -o go-template='{{ index . "data" "admin-password" | base64decode }}')
DEV_GRAFANA_API_KEY=$(shell curl --fail -XPOST -H "Content-Type: application/json" -d '{"name": "dark-dev-api-key-$(shell date +%s)", "role": "Admin"}' http://admin:$(DEV_GRAFANA_PASSWORD)@$(DEV_GRAFANA_HOST):$(DEV_CLUSTER_PORT)/api/auth/keys | jq .key)

.PHONY: dev-env-start
dev-env-start: dev-env-check-binaries dev-env-create-cluster dev-env-provision dev-env-info ## Start a development k3d cluster.

.PHONY: dev-env-create-cluster
dev-env-create-cluster: ## Create a development k3d cluster.
k3d cluster create \
--image="rancher/k3s:v1.21.7-k3s1" \
-p "$(DEV_CLUSTER_PORT):80@loadbalancer" \
dark-dev

.PHONY: dev-env-remove
dev-env-remove: ## Remove the development k3d cluster.
k3d cluster delete dark-dev

.PHONY: dev-env-provision
dev-env-provision: ## Provision the development k3d cluster with useful tools (Grafana, Prometheus, Loki, ...).
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
helm upgrade \
--install loki grafana/loki-stack \
--set grafana.enabled=true,prometheus.enabled=true,prometheus.alertmanager.persistentVolume.enabled=false,prometheus.server.persistentVolume.enabled=false
kubectl apply -f config/crd/bases
kubectl apply -f config/dev-env

.PHONY: dev-env-info
dev-env-info: ## Print useful information for the dev environment (URL, credentials, ...).
@echo "==============="
@echo "Grafana available at http://$(DEV_GRAFANA_HOST):$(DEV_CLUSTER_PORT)"
@kubectl get secret loki-grafana -o go-template='{{range $$k,$$v := .data}}{{printf "%s: " $$k}}{{if not $$v}}{{$$v}}{{else}}{{$$v | base64decode}}{{end}}{{"\n"}}{{end}}'

.PHONY: dev-env-check-binaires
dev-env-check-binaries: ## Check that the required binary are present.
@helm version >/dev/null 2>&1 || (echo "ERROR: helm is required."; exit 1)
@k3d version >/dev/null 2>&1 || (echo "ERROR: k3d is required."; exit 1)
@kubectl version --client >/dev/null 2>&1 || (echo "ERROR: kubectl is required."; exit 1)
@jq --version >/dev/null 2>&1 ||(echo "ERROR: jq is required."; exit 1)

.PHONY: run
run: ## Run a controller from your host.
GRAFANA_HOST=http://$(DEV_GRAFANA_HOST):$(DEV_CLUSTER_PORT) \
GRAFANA_TOKEN=$(DEV_GRAFANA_API_KEY) \
go run ./cmd/controller

##@ Build

.PHONY: build
Expand All @@ -83,10 +131,6 @@ build-manager: generate fmt vet ## Build manager binary.
build-converter: fmt vet ## Build converter binary.
go build -o bin/converter cmd/converter/main.go

.PHONY: run
run: ## Run a controller from your host.
go run cmd/controller/main.go

.PHONY: docker-build-manager
docker-build-manager: ## Build docker image with the manager.
DOCKER_BUILDKIT=1 docker build -f build/Dockerfile-controller -t ${CONTROLLER_IMAGE}:${VERSION} .
Expand Down
17 changes: 17 additions & 0 deletions config/dev-env/grafana-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: grafana-ingress
spec:
rules:
- host: 'grafana.dark.localhost'
http:
paths:
- path: "/"
pathType: Prefix
backend:
service:
name: loki-grafana
port:
number: 80

0 comments on commit 95014eb

Please sign in to comment.