Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add makefile to vagrant to install collection, receiver-mock, grafana and supports avalanche #815

Merged
merged 12 commits into from
Aug 20, 2020
100 changes: 100 additions & 0 deletions vagrant/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/make -f

# mkfile_path is absolute path of this file
# The intention is to be able to run this file from any location
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity why do we need this construct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted this Makefile to be executable, so need to get absolute path of the file and later abs path of the repository. I will add comments to clarify that

# root_dir is a root directory of the project (github repo)
root_dir := $(dir $(abspath $(mkfile_path)/..))
helm_path = ${root_dir}deploy/helm/sumologic
k8s_path = ${root_dir}vagrant/k8s
dashboards_path = ${root_dir}vagrant/dashboards

# Collector configuration
name = collection
namespace = sumologic

# Collector section
## Collector upgrade
upgrade:
${mkfile_path} \
patch-context \
remove-tmp \
apply-namespace \
apply-receiver-mock \
create-secrets \
grafana-dashboards \
helm-dependencies \
helm-upgrade \
apply-service-monitors

# Remove temporary charts
remove-tmp:
rm -rf ${helm_path}/tmpcharts

apply-namespace:
kubectl apply -f ${k8s_path}/sumologic.yaml

apply-receiver-mock:
kubectl apply -f ${k8s_path}/receiver-mock.yaml

helm-dependencies:
helm dependency update "${helm_path}"

helm-upgrade:
helm upgrade "${name}" "${helm_path}" \
--namespace "${namespace}" \
--install \
-f "${root_dir}vagrant/values.yaml"

apply-service-monitors:
kubectl apply -f ${k8s_path}/service-monitors.yaml

apply-avalanche:
kubectl apply -f ${k8s_path}/avalanche.yaml

## Collector removing
clean:
${mkfile_path} \
remove-collector \
remove-service-monitors remove-receiver-mock remove-prometheus-crds remove-namespace

remove-namespace:
kubectl delete -f ${k8s_path}/sumologic.yaml --ignore-not-found=true

remove-prometheus-crds:
kubectl delete customresourcedefinitions.apiextensions.k8s.io --ignore-not-found=true \
{alertmanagers,podmonitors,prometheuses,prometheusrules,servicemonitors,thanosrulers}.monitoring.coreos.com

remove-receiver-mock:
kubectl delete -f ${k8s_path}/receiver-mock.yaml --ignore-not-found=true

remove-collector:
helm delete -n "${namespace}" "${name}"

remove-service-monitors:
kubectl delete -f ${k8s_path}/service-monitors.yaml --ignore-not-found=true

## k8s commands
expose-prometheus:
kubectl port-forward -n "${namespace}" service/collection-prometheus-oper-prometheus --address=0.0.0.0 9090

expose-grafana:
echo "Grafana credentials\n login: admin\n password: prom-operator"
kubectl port-forward -n "${namespace}" service/collection-grafana --address=0.0.0.0 8080:80

# Load grafana dashboards as configmaps
grafana-dashboards:
kubectl delete configmap -n "${namespace}" sumologic-dashboards || true
kubectl create configmap -n "${namespace}" sumologic-dashboards --from-file="${dashboards_path}"

# Create secrets with microk8s certs
create-secrets:
kubectl delete secret -n "${namespace}" microk8s-certs || true
kubectl create secret -n "${namespace}" generic microk8s-certs \
--from-file=/var/snap/microk8s/current/certs/server.key \
--from-file=/var/snap/microk8s/current/certs/server.crt \
--from-file=/var/snap/microk8s/current/certs/ca.crt

# patch context to use sumologic namespace as default
patch-context:
kubectl config set-context --current --namespace "${namespace}"
36 changes: 36 additions & 0 deletions vagrant/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Vagrant

Please install [Vagrant](https://www.vagrantup.com/) and [VirtualBox](https://www.virtualbox.org/).
After that you can run the Vagrant environment with just one command:

```bash
vagrant up
```

After successfull installation you can ssh to the virtual machine with:

```bash
vagrant ssh
```

## Collector

To install or upgrade collector please type:

```bash
/sumologic/vagrant/Makefile upgrade
```

This command will prepare environment (namespaces, receiver-mock, etc.)
and after that it will install/upgrade collector in the vagrant environment.

To remove collector please use:

```bash
/sumologic/vagrant/Makefile clean
```

List of other useful commands in the Makefile:
- `expose-prometheus` - exposes prometheus on port 9090 of virtual machine
- `expose-grafana` - exposes grafana on port 8080 of virtual machine
- `apply-avalanche` - run one pod deployment of avalanche (metrics generator)
Loading