Skip to content

Commit d9bdbf5

Browse files
authored
add Node Resource Exporter (#114)
Signed-off-by: Dmitry Shmulevich <[email protected]>
1 parent 88b3b5d commit d9bdbf5

File tree

25 files changed

+880
-46
lines changed

25 files changed

+880
-46
lines changed

.github/workflows/docker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Set up Go
2424
uses: actions/setup-go@v4
2525
with:
26-
go-version: '1.22'
26+
go-version: '1.23'
2727

2828
- name: Build
2929
run: make build

.github/workflows/go.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ jobs:
2424
- name: Set up Go
2525
uses: actions/setup-go@v4
2626
with:
27-
go-version: '1.22'
27+
go-version: '1.23'
2828

2929
- name: Lint
30-
uses: golangci/golangci-lint-action@v5
30+
uses: golangci/golangci-lint-action@v6
3131
with:
32-
version: 'v1.58.0'
32+
version: 'v1.60'
3333
args: -v --timeout 5m
3434
skip-cache: true
3535

@@ -49,7 +49,7 @@ jobs:
4949
- name: Set up Go
5050
uses: actions/setup-go@v4
5151
with:
52-
go-version: '1.22'
52+
go-version: '1.23'
5353

5454
- name: Test
5555
run: go test -v ./...
@@ -62,7 +62,7 @@ jobs:
6262
- name: Set up Go
6363
uses: actions/setup-go@v4
6464
with:
65-
go-version: '1.22'
65+
go-version: '1.23'
6666

6767
- name: Build
6868
run: make build
@@ -76,7 +76,7 @@ jobs:
7676
- name: Set up Go
7777
uses: actions/setup-go@v4
7878
with:
79-
go-version: '1.22'
79+
go-version: '1.23'
8080

8181
- name: Build
8282
run: make build

.github/workflows/nightly.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Set up Go
1818
uses: actions/setup-go@v4
1919
with:
20-
go-version: '1.22'
20+
go-version: '1.23'
2121

2222
- name: Build
2323
run: make build
@@ -37,7 +37,7 @@ jobs:
3737
- name: Set up Go
3838
uses: actions/setup-go@v4
3939
with:
40-
go-version: '1.22'
40+
go-version: '1.23'
4141

4242
- name: Build
4343
run: make build
@@ -57,7 +57,7 @@ jobs:
5757
- name: Set up Go
5858
uses: actions/setup-go@v4
5959
with:
60-
go-version: '1.22'
60+
go-version: '1.23'
6161

6262
- name: Build
6363
run: make build
@@ -77,7 +77,7 @@ jobs:
7777
- name: Set up Go
7878
uses: actions/setup-go@v4
7979
with:
80-
go-version: '1.22'
80+
go-version: '1.23'
8181

8282
- name: Build
8383
run: make build

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
LINTER_BIN ?= golangci-lint
1616
DOCKER_BIN ?= docker
17-
TARGETS := knavigator klient
17+
TARGETS := knavigator klient node-resource-exporter
1818
CMD_DIR := ./cmd
1919
OUTPUT_DIR := ./bin
2020

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: node-resource-exporter
3+
description: A Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "1.16.0"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
1. Get the application URL by running these commands:
2+
{{- if .Values.ingress.enabled }}
3+
{{- range $host := .Values.ingress.hosts }}
4+
{{- range .paths }}
5+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
6+
{{- end }}
7+
{{- end }}
8+
{{- else if contains "NodePort" .Values.service.type }}
9+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "node-resource-exporter.fullname" . }})
10+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
11+
echo http://$NODE_IP:$NODE_PORT
12+
{{- else if contains "LoadBalancer" .Values.service.type }}
13+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
14+
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "node-resource-exporter.fullname" . }}'
15+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "node-resource-exporter.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
16+
echo http://$SERVICE_IP:{{ .Values.service.port }}
17+
{{- else if contains "ClusterIP" .Values.service.type }}
18+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "node-resource-exporter.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
19+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
20+
echo "Visit http://127.0.0.1:8080 to use your application"
21+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
22+
{{- end }}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "node-resource-exporter.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "node-resource-exporter.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "node-resource-exporter.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "node-resource-exporter.labels" -}}
37+
helm.sh/chart: {{ include "node-resource-exporter.chart" . }}
38+
{{ include "node-resource-exporter.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "node-resource-exporter.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "node-resource-exporter.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "node-resource-exporter.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "node-resource-exporter.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "node-resource-exporter.fullname" . }}
5+
namespace: {{.Release.Namespace}}
6+
labels:
7+
{{- include "node-resource-exporter.labels" . | nindent 4 }}
8+
spec:
9+
{{- if not .Values.autoscaling.enabled }}
10+
replicas: {{ .Values.replicaCount }}
11+
{{- end }}
12+
selector:
13+
matchLabels:
14+
{{- include "node-resource-exporter.selectorLabels" . | nindent 6 }}
15+
template:
16+
metadata:
17+
{{- with .Values.podAnnotations }}
18+
annotations:
19+
{{- toYaml . | nindent 8 }}
20+
{{- end }}
21+
labels:
22+
{{- include "node-resource-exporter.labels" . | nindent 8 }}
23+
{{- with .Values.podLabels }}
24+
{{- toYaml . | nindent 8 }}
25+
{{- end }}
26+
spec:
27+
{{- with .Values.imagePullSecrets }}
28+
imagePullSecrets:
29+
{{- toYaml . | nindent 8 }}
30+
{{- end }}
31+
serviceAccountName: {{ include "node-resource-exporter.serviceAccountName" . }}
32+
securityContext:
33+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
34+
containers:
35+
- name: {{ .Chart.Name }}
36+
securityContext:
37+
{{- toYaml .Values.securityContext | nindent 12 }}
38+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
39+
imagePullPolicy: {{ .Values.image.pullPolicy }}
40+
command:
41+
- /usr/local/bin/node-resource-exporter
42+
args:
43+
- -p
44+
- "{{ .Values.cmd.port }}"
45+
- -r
46+
- {{ .Values.cmd.resources }}
47+
- -l
48+
- {{ .Values.cmd.nodeLabels }}
49+
- -v
50+
- "{{ .Values.cmd.verbosity }}"
51+
{{- if .Values.cmd.namespace }}
52+
- -n
53+
- {{ .Values.cmd.namespace }}
54+
{{- end }}
55+
ports:
56+
- name: metrics
57+
containerPort: {{ .Values.cmd.port }}
58+
protocol: TCP
59+
resources:
60+
{{- toYaml .Values.resources | nindent 12 }}
61+
{{- with .Values.volumeMounts }}
62+
volumeMounts:
63+
{{- toYaml . | nindent 12 }}
64+
{{- end }}
65+
{{- with .Values.volumes }}
66+
volumes:
67+
{{- toYaml . | nindent 8 }}
68+
{{- end }}
69+
{{- with .Values.nodeSelector }}
70+
nodeSelector:
71+
{{- toYaml . | nindent 8 }}
72+
{{- end }}
73+
{{- with .Values.affinity }}
74+
affinity:
75+
{{- toYaml . | nindent 8 }}
76+
{{- end }}
77+
{{- with .Values.tolerations }}
78+
tolerations:
79+
{{- toYaml . | nindent 8 }}
80+
{{- end }}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{- if .Values.autoscaling.enabled }}
2+
apiVersion: autoscaling/v2
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ include "node-resource-exporter.fullname" . }}
6+
namespace: {{.Release.Namespace}}
7+
labels:
8+
{{- include "node-resource-exporter.labels" . | nindent 4 }}
9+
spec:
10+
scaleTargetRef:
11+
apiVersion: apps/v1
12+
kind: Deployment
13+
name: {{ include "node-resource-exporter.fullname" . }}
14+
namespace: {{.Release.Namespace}}
15+
minReplicas: {{ .Values.autoscaling.minReplicas }}
16+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
17+
metrics:
18+
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
19+
- type: Resource
20+
resource:
21+
name: cpu
22+
target:
23+
type: Utilization
24+
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
25+
{{- end }}
26+
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
27+
- type: Resource
28+
resource:
29+
name: memory
30+
target:
31+
type: Utilization
32+
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
33+
{{- end }}
34+
{{- end }}

0 commit comments

Comments
 (0)