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

Added hosted images and chart #16

Merged
merged 1 commit into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ helm-docs:
$(LOCALBIN)/helm-docs --template-files "${GITROOT}/chart/README.md.gotmpl"
cat "${GITROOT}/Header.md" "${GITROOT}/chart/README.md" > "${GITROOT}/README.md"

create_kind:
new_kind:
./scripts/create_kind.sh

delete_kind:
kind delete clusters "${DEPLOYMENT_NAME}-cluster"

init: fmt vet

deploy_debug: init
Expand All @@ -43,6 +40,18 @@ deploy_e2e_debug: init
deploy_local: init
./scripts/deploy.sh

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

release-docker:
GITHUB_TOKEN="${GITHUB_TOKEN}" VERSION="${VERSION}" ./scripts/release-docker.sh

release: release-docker helm-docs
# ex. make GITHUB_TOKEN=asdfasdf VERSION=1.0.0 release
helm package chart --destination chart
helm repo index --merge index.yaml chart/.

release-github:
# ex. make VERSION=1.0.0 release-github
gh auth login --web
gh release create ${VERSION} --generate-notes
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,31 @@ Currently, this image is not being hosted and so you have to build it yourself a

## Helm Install

```bash
helm repo add k8s-ephemeral-storage-metrics https://jmcgrath207.github.io/k8s-ephemeral-storage-metrics/chart
helm install my-deployment k8s-ephemeral-storage-metrics/k8s-ephemeral-storage-metrics
```

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| deploy_type | string | `"DaemonSet"` | |
| dev.enabled | bool | `false` | |
| image.imagePullPolicy | string | `"ifNotPresent"` | |
| image.repository | string | `"registry.lab.com/k8s-ephemeral-storage-metrics"` | |
| image.tag | string | `"asdf"` | |
| image.repository | string | `"ghcr.io/jmcgrath207/k8s-ephermeral-storage-metrics"` | |
| image.tag | string | `"1.0.0"` | |
| interval | int | `15` | |
| log_level | string | `"info"` | |
| prometheus.release | string | `"kube-prometheus"` | |
| prometheus.release | string | `"kube-prometheus-stack"` | |

## Contribute

### Start Kind
```bash
make new_kind
```

### Run locally
```bash
make deploy_local
Expand Down
3 changes: 2 additions & 1 deletion chart/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
.idea/
*.tmproj
.vscode/
README.md.gotmpl
README.md.gotmpl
*.tgz
2 changes: 1 addition & 1 deletion chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: k8s-ephemeral-storage-metrics
version: 1.0.0
appVersion: "1.0.0"
appVersion: 1.0.0
kubeVersion: ">=1.21.0-0"
description: Ephemeral storage metrics for prometheus operator.
home: https://github.com/jmcgrath207/k8s-ephemeral-storage-metrics
Expand Down
16 changes: 13 additions & 3 deletions chart/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
## Helm Install

```bash
helm repo add k8s-ephemeral-storage-metrics https://jmcgrath207.github.io/k8s-ephemeral-storage-metrics/chart
helm install my-deployment k8s-ephemeral-storage-metrics/k8s-ephemeral-storage-metrics
```

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| deploy_type | string | `"DaemonSet"` | |
| dev.enabled | bool | `false` | |
| image.imagePullPolicy | string | `"ifNotPresent"` | |
| image.repository | string | `"registry.lab.com/k8s-ephemeral-storage-metrics"` | |
| image.tag | string | `"asdf"` | |
| image.repository | string | `"ghcr.io/jmcgrath207/k8s-ephermeral-storage-metrics"` | |
| image.tag | string | `"1.0.0"` | |
| interval | int | `15` | |
| log_level | string | `"info"` | |
| prometheus.release | string | `"kube-prometheus"` | |
| prometheus.release | string | `"kube-prometheus-stack"` | |

## Contribute

### Start Kind
```bash
make new_kind
```

### Run locally
```bash
make deploy_local
Expand Down
10 changes: 10 additions & 0 deletions chart/README.md.gotmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
## Helm Install

```bash
helm repo add k8s-ephemeral-storage-metrics https://jmcgrath207.github.io/k8s-ephemeral-storage-metrics/chart
helm install my-deployment k8s-ephemeral-storage-metrics/k8s-ephemeral-storage-metrics
```

{{ template "chart.valuesSection" . }}

## Contribute

### Start Kind
```bash
make new_kind
```

### Run locally
```bash
make deploy_local
Expand Down
26 changes: 26 additions & 0 deletions chart/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: v1
entries:
k8s-ephemeral-storage-metrics:
- annotations:
artifacthub.io/license: MIT
artifacthub.io/links: |
- name: Documentation
url: https://github.com/jmcgrath207/k8s-ephemeral-storage-metrics
artifacthub.io/prerelease: "false"
apiVersion: v2
appVersion: 1.0.0
created: "2023-10-15T15:00:31.42811114-05:00"
description: Ephemeral storage metrics for prometheus operator.
digest: 1429b287b53e9bffe50db3cd3a9cd7e7d0ab8e645faa709aaa598959080e8d94
home: https://github.com/jmcgrath207/k8s-ephemeral-storage-metrics
keywords:
- kubernetes
- metrics
kubeVersion: '>=1.21.0-0'
name: k8s-ephemeral-storage-metrics
sources:
- https://github.com/jmcgrath207/k8s-ephemeral-storage-metrics
urls:
- k8s-ephemeral-storage-metrics-1.0.0.tgz
version: 1.0.0
generated: "2023-10-15T15:00:31.427665652-05:00"
Binary file added chart/k8s-ephemeral-storage-metrics-1.0.0.tgz
Binary file not shown.
8 changes: 5 additions & 3 deletions chart/templates/localDebugService.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{{ if .Values.dev }}
{{ if .Values.dev.enabled }}
apiVersion: v1
kind: Service
metadata:
name: debug
labels:
{{- include "chart.labels" . | nindent 4 }}
{{- include "chart.labels" . | nindent 4 }}
app.kubernetes.io/name: k8s-ephemeral-storage-metrics-debug
spec:
type: NodePort
selector:
{{- include "chart.selectorLabels" . | nindent 6 }}
{{- include "chart.selectorLabels" . | nindent 4 }}
app.kubernetes.io/name: k8s-ephemeral-storage-metrics-debug
ports:
- protocol: TCP
port: 9999
Expand Down
8 changes: 2 additions & 6 deletions chart/templates/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ kind: ServiceMonitor
metadata:
name: k8s-ephemeral-storage-metrics
labels:
app.kubernetes.io/component: metrics
app.kubernetes.io/created-by: par
app.kubernetes.io/part-of: par
control-plane: controller-manager
{{- include "chart.labels" . | nindent 4 }}
spec:
endpoints:
Expand All @@ -19,7 +15,7 @@ spec:
- {{ .Release.Namespace }}
selector:
matchLabels:
control-plane: controller-manager
{{- include "chart.selectorLabels" . | nindent 6 }}

---

Expand All @@ -28,7 +24,7 @@ kind: Service
metadata:
name: k8s-ephemeral-storage-metrics
labels:
{{- include "chart.labels" . | nindent 4 }}
{{- include "chart.labels" . | nindent 6 }}
spec:
type: ClusterIP
selector:
Expand Down
2 changes: 1 addition & 1 deletion chart/templates/test_deployments.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ if .Values.dev }}
{{ if .Values.dev.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down
6 changes: 3 additions & 3 deletions chart/values.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
image:
repository: registry.lab.com/k8s-ephemeral-storage-metrics
tag: "asdf"
repository: ghcr.io/jmcgrath207/k8s-ephermeral-storage-metrics
tag: 1.0.0
imagePullPolicy: ifNotPresent
log_level: info
deploy_type: DaemonSet
# Note in testing, Kube API does not refresh faster than 10 seconds
interval: 15 # Seconds
prometheus:
release: kube-prometheus
release: kube-prometheus-stack

# For local development and testing
dev:
Expand Down
29 changes: 0 additions & 29 deletions charts/k8s-ephemeral-storage-metrics/templates/PodMonitor.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions charts/k8s-ephemeral-storage-metrics/values.yaml

This file was deleted.

Binary file modified img/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
apiVersion: v1
entries: {}
generated: "2023-10-15T12:07:02.648748624-05:00"
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func getMetrics() {
log.Debug().Msg(fmt.Sprintf("pod %s/%s on %s with usedBytes: %f", podNamespace, podName, nodeName, usedBytes))
}

// TODO: Fix Sleep time for polling.
elapsedTime := time.Now().Sub(start).Milliseconds() / 1000
adjustTime := sampleInterval - elapsedTime
log.Debug().Msgf("Adjusted Poll time: %d seconds", adjustTime)
Expand Down
19 changes: 19 additions & 0 deletions scripts/create_kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function trap_func_kind() {
trap 'trap_func_kind' ERR


kind delete clusters "${DEPLOYMENT_NAME}-cluster"

kind create cluster \
--verbosity=6 \
Expand All @@ -22,3 +23,21 @@ kubectl get nodes -o wide

# Deploy Service Monitor CRD
kubectl apply --server-side -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_servicemonitors.yaml

if [[ ! $ENV =~ "e2e" ]]; then
# Deploy Prometheus
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm upgrade --install kube-prometheus-stack prometheus-community/kube-prometheus-stack --version 46.8.0 -n "${DEPLOYMENT_NAME}" --create-namespace \
--set grafana.enabled=false \
--set kubeApiServer.enabled=false \
--set kubernetesServiceMonitors.enabled=false \
--set kubelet.enabled=false \
--set kubeControllerManager.enabled=false \
--set kube-state-metrics.enabled=false \
--set prometheus-node-exporter.enabled=false \
--set alertmanager.enabled=false\
--set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false \
--set prometheus.prometheusSpec.podMonitorSelectorNilUsesHelmValues=false \
--set prometheus.prometheusSpec.probeSelectorNilUsesHelmValues=false
fi
17 changes: 15 additions & 2 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function main() {
"image.imagePullPolicy=Never",
"deploy_type=Deployment",
"log_level=debug"
"dev.enabled=true"
)

if [[ $ENV =~ "e2e" ]]; then
Expand All @@ -37,7 +38,7 @@ function main() {
docker build --build-arg TARGETOS=linux --build-arg TARGETARCH=amd64 -f DockerfileTestShrink -t local.io/local/shrink-test:latest .
kind load docker-image -v 9 --name "${DEPLOYMENT_NAME}-cluster" --nodes "${DEPLOYMENT_NAME}-cluster-worker" "local.io/local/shrink-test:latest"

e2e_values_arr=("test.enabled=true", "interval=1")
e2e_values_arr=("interval=5")
common_set_values_arr+=("${e2e_values_arr[@]}")
fi

Expand All @@ -46,6 +47,8 @@ function main() {
docker build --build-arg TARGETOS=linux --build-arg TARGETARCH=amd64 -f ${dockerfile} -t local.io/local/$DEPLOYMENT_NAME:$image_tag .
kind load docker-image -v 9 --name "${DEPLOYMENT_NAME}-cluster" --nodes "${DEPLOYMENT_NAME}-cluster-worker" "local.io/local/${DEPLOYMENT_NAME}:${image_tag}"



# Install Par Chart
helm upgrade --install $DEPLOYMENT_NAME ./chart \
--set "${common_set_values}" \
Expand All @@ -59,15 +62,25 @@ function main() {
'{ "spec": {"template": { "spec":{"securityContext": null, "containers":[{"name":"metrics", "livenessProbe": null, "readinessProbe": null, "securityContext": null, "command": null, "args": null }]}}}}'
fi


# kill dangling port forwards if found.
# Exporter Porter
sudo ss -aK '( dport = :9100 or sport = :9100 )' | true
# Prometheus Port
sudo ss -aK '( dport = :9090 or sport = :9090 )' | true

# Start Prometheus Port Forward
# Start Exporter Port Forward
(
sleep 10
printf "\n\n" && while :; do kubectl port-forward -n $DEPLOYMENT_NAME service/k8s-ephemeral-storage-metrics 9100:9100 || sleep 5; done
) &

# Start Prometheus Port Forward
(
sleep 10
printf "\n\n" && while :; do kubectl port-forward -n $DEPLOYMENT_NAME service/prometheus-operated 9090:9090 || sleep 5; done
) &

if [[ $ENV == "debug" ]]; then
# Background log following for manager
(
Expand Down
Loading
Loading