Skip to content

Commit

Permalink
working locally
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcgrath207 committed Oct 15, 2023
1 parent 7f8b5d4 commit e21500d
Show file tree
Hide file tree
Showing 31 changed files with 994 additions and 542 deletions.
33 changes: 33 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
### Go template
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

chart
.github
.gitignore
scripts
img
Dockerfile
DockerfileDebug
README.md


24 changes: 24 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: ci

on:
pull_request:


jobs:
e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Create k8s Kind Cluster
uses: helm/kind-action@v1.7.0
with:
install_only: true
- uses: azure/setup-helm@v3
- name: Run e2e
run: |
make deploy_e2e
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.19.2 as builder
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.21 as builder

ARG TARGETPLATFORM
ARG BUILDPLATFORM
Expand Down
15 changes: 9 additions & 6 deletions DockerfileDebug
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
FROM golang:1.19.2 as builder
FROM golang:1.21 as builder

WORKDIR /code

COPY . .

RUN go mod download
RUN go build -gcflags="all=-N -l" -o /app main.go

RUN go install github.com/go-delve/delve/cmd/dlv@latest
RUN go build -gcflags="all=-N -l" -o /app main.go

FROM debian:buster
ENV GOTRACEBACK=single
FROM nicolaka/netshoot:latest
ENV GOTRACEBACK=crash
WORKDIR /
COPY --from=builder /app .
COPY --from=builder /go/bin/dlv .

ENTRYPOINT ["/dlv", "exec", "--listen=:56268", "--headless=true", "--api-version=2", "--accept-multiclient", "/app"]
ENV LOG_LEVEL=debug
EXPOSE 9999

ENTRYPOINT ["/dlv", "exec", "--listen=:9999", "--headless=true", "--api-version=2", "--accept-multiclient", "/app"]
#ENTRYPOINT ["/dlv", "exec", "--listen=:9999", "--headless=true", "--api-version=2", "--accept-multiclient", "/app"]

7 changes: 7 additions & 0 deletions DockerfileTestGrow
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM ubuntu:22.04
RUN apt-get update -y && apt-get install watch

COPY tests/scripts/growing_epheremal_storage.sh growing_epheremal_storage.sh

SHELL ["/usr/bin/bash", "-c"]
ENTRYPOINT ["./growing_epheremal_storage.sh"]
7 changes: 7 additions & 0 deletions DockerfileTestShrink
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM ubuntu:22.04
RUN apt-get update -y && apt-get install watch

COPY tests/scripts/shrinking_epheremal_storage.sh shrinking_epheremal_storage.sh

SHELL ["/usr/bin/bash", "-c"]
ENTRYPOINT ["./shrinking_epheremal_storage.sh"]
15 changes: 15 additions & 0 deletions Header.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# K8s Ephemeral Storage Metrics.


[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Actions Status](https://github.com/jmcgrath207/k8s-ephemeral-storage-metrics/workflows/ci/badge.svg)](https://github.com/jmcgrath207/k8s-ephemeral-storage-metrics/actions)

The goal of this project is to export ephemeral storage metric usage per pod to Prometheus that is address in this
issue [Here](https://github.com/kubernetes/kubernetes/issues/69507)

Currently, this image is not being hosted and so you have to build it yourself at the moment.


![main image](img/screenshot.png)


45 changes: 45 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.EXPORT_ALL_VARIABLES:

GITROOT ?= $(shell pwd)
DEPLOYMENT_NAME = ephemeral-metrics
K8S_VERSION ?= 1.26.0

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)


ginkgo:
test -s $(LOCALBIN)/ginkgo || GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/v2/ginkgo@v2.9.7

.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...

.PHONY: vet
vet: ## Run go vet against code.
go vet ./...

helm-docs:
test -s $(LOCALBIN)/helm-docs || GOBIN=$(LOCALBIN) go install github.com/norwoodj/helm-docs/cmd/helm-docs@latest
$(LOCALBIN)/helm-docs --template-files "${GITROOT}/chart/README.md.gotmpl"
cat "${GITROOT}/Header.md" "${GITROOT}/chart/README.md" > "${GITROOT}/README.md"

create_kind:
./scripts/create_kind.sh

init: fmt vet

deploy_debug: init
ENV='debug' ./scripts/deploy.sh

deploy_e2e_debug: init
ENV='e2e-debug' ./scripts/deploy.sh

deploy_local: init
./scripts/deploy.sh

deploy_e2e: init ginkgo
ENV='e2e' ./scripts/deploy.sh

46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,49 @@ Currently, this image is not being hosted and so you have to build it yourself a
![main image](img/screenshot.png)


## Helm Install

```bash
helm repo add par https://jmcgrath207.github.io/par/chart
helm install par par/Par
```

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| deploy_type | string | `"DaemonSet"` | |
| image.imagePullPolicy | string | `"ifNotPresent"` | |
| image.repository | string | `"registry.lab.com/k8s-ephemeral-storage-metrics"` | |
| image.tag | string | `""` | |
| interval | string | `"15s"` | |
| log_level | string | `"info"` | |
| prometheus.release | string | `"kube-prometheus"` | |

## Contribute

### Run locally
```bash
make deploy_local
```

### Run locally with Delve Debug
```bash
make deploy_debug
```
Then connect to `localhost:30002` with [delve](https://github.com/go-delve/delve) or your IDE.

### Run e2e Test
```bash
make deploy_e2e
```

### Debug e2e
```bash
make deploy_e2e_debug
```
Then run a debug against [deployment_test.go](tests/e2e/deployment_test.go)

## License

This project is licensed under the [MIT License](https://opensource.org/licenses/MIT). See the `LICENSE` file for more details.
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
.idea/
*.tmproj
.vscode/
README.md.gotmpl
File renamed without changes.
46 changes: 46 additions & 0 deletions chart/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## Helm Install

```bash
helm repo add par https://jmcgrath207.github.io/par/chart
helm install par par/Par
```

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| deploy_type | string | `"DaemonSet"` | |
| image.imagePullPolicy | string | `"ifNotPresent"` | |
| image.repository | string | `"registry.lab.com/k8s-ephemeral-storage-metrics"` | |
| image.tag | string | `""` | |
| interval | string | `"15s"` | |
| log_level | string | `"info"` | |
| prometheus.release | string | `"kube-prometheus"` | |

## Contribute

### Run locally
```bash
make deploy_local
```

### Run locally with Delve Debug
```bash
make deploy_debug
```
Then connect to `localhost:30002` with [delve](https://github.com/go-delve/delve) or your IDE.

### Run e2e Test
```bash
make deploy_e2e
```

### Debug e2e
```bash
make deploy_e2e_debug
```
Then run a debug against [deployment_test.go](tests/e2e/deployment_test.go)

## License

This project is licensed under the [MIT License](https://opensource.org/licenses/MIT). See the `LICENSE` file for more details.
31 changes: 31 additions & 0 deletions chart/README.md.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Helm Install

{{ template "chart.valuesSection" . }}

## Contribute

### Run locally
```bash
make deploy_local
```

### Run locally with Delve Debug
```bash
make deploy_debug
```
Then connect to `localhost:30002` with [delve](https://github.com/go-delve/delve) or your IDE.

### Run e2e Test
```bash
make deploy_e2e
```

### Debug e2e
```bash
make deploy_e2e_debug
```
Then run a debug against [deployment_test.go](tests/e2e/deployment_test.go)

## License

This project is licensed under the [MIT License](https://opensource.org/licenses/MIT). See the `LICENSE` file for more details.
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@ metadata:
name: k8s-ephemeral-storage-metrics
namespace: {{ .Release.Namespace }}
labels:
k8s-app: {{ .Release.Name }}
{{- include "chart.labels" . | nindent 4 }}
spec:
{{- if eq .Values.deploy_type "Deployment" }}
replicas: 1
{{- end }}
selector:
matchLabels:
k8s-app: {{ .Release.Name }}
{{- include "chart.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
k8s-app: {{ .Release.Name }}
{{- include "chart.labels" . | nindent 8 }}
spec:
serviceAccountName: k8s-ephemeral-storage-metrics
containers:
- name: metrics
image: {{ .Values.image }}
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.imagePullPolicy }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
ports:
- name: http
- name: metrics
containerPort: 9100
protocol: TCP
livenessProbe:
Expand All @@ -47,6 +48,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
env:
- name: SCRAPE_INTERVAL
value: "{{ .Values.interval }}"
- name: LOG_LEVEL
value: "{{ .Values.log_level }}"
- name: CURRENT_NODE_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: k8s-ephemeral-storage-metrics
labels:
{{- include "chart.labels" . | nindent 4 }}
rules:
- apiGroups: [""]
resources: ["nodes/proxy"]
Expand All @@ -15,6 +17,7 @@ kind: ServiceAccount
metadata:
labels:
k8s-app: {{ .Release.Name }}
{{- include "chart.labels" . | nindent 4 }}
name: k8s-ephemeral-storage-metrics
namespace: {{ .Release.Namespace }}

Expand All @@ -24,6 +27,8 @@ kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: k8s-ephemeral-storage-metrics
labels:
{{- include "chart.labels" . | nindent 4 }}
subjects:
- kind: ServiceAccount
name: k8s-ephemeral-storage-metrics
Expand Down
Loading

0 comments on commit e21500d

Please sign in to comment.