Skip to content

Commit 9a6df1a

Browse files
committed
implement K8s node data broker
Signed-off-by: Dmitry Shmulevich <dshmulevich@nvidia.com>
1 parent 65b6e4e commit 9a6df1a

20 files changed

Lines changed: 794 additions & 59 deletions

File tree

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 := topograph node-observer toposim
17+
TARGETS := topograph node-observer toposim node-data-broker
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-data-broker
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: 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-data-broker.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-data-broker.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-data-broker.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "node-data-broker.labels" -}}
37+
helm.sh/chart: {{ include "node-data-broker.chart" . }}
38+
{{ include "node-data-broker.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-data-broker.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "node-data-broker.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-data-broker.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "node-data-broker.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
apiVersion: apps/v1
2+
kind: DaemonSet
3+
metadata:
4+
name: {{ include "node-data-broker.fullname" . }}
5+
labels:
6+
{{- include "node-data-broker.labels" . | nindent 4 }}
7+
spec:
8+
selector:
9+
matchLabels:
10+
{{- include "node-data-broker.selectorLabels" . | nindent 6 }}
11+
template:
12+
metadata:
13+
labels:
14+
{{- include "node-data-broker.labels" . | nindent 8 }}
15+
spec:
16+
{{- with .Values.imagePullSecrets }}
17+
imagePullSecrets:
18+
{{- toYaml . | nindent 8 }}
19+
{{- end }}
20+
containers:
21+
- name: {{ .Chart.Name }}
22+
securityContext:
23+
{{- toYaml .Values.securityContext | nindent 12 }}
24+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
25+
imagePullPolicy: {{ .Values.image.pullPolicy }}
26+
command:
27+
- tail
28+
args:
29+
- -f
30+
- /dev/null
31+
resources:
32+
{{- toYaml .Values.resources | nindent 12 }}
33+
{{- with .Values.volumeMounts }}
34+
volumeMounts:
35+
{{- toYaml . | nindent 12 }}
36+
{{- end }}
37+
{{- with .Values.volumes }}
38+
volumes:
39+
{{- toYaml . | nindent 8 }}
40+
{{- end }}
41+
{{- with .Values.nodeSelector }}
42+
nodeSelector:
43+
{{- toYaml . | nindent 8 }}
44+
{{- end }}
45+
{{- with .Values.affinity }}
46+
affinity:
47+
{{- toYaml . | nindent 8 }}
48+
{{- end }}
49+
{{- with .Values.tolerations }}
50+
tolerations:
51+
{{- toYaml . | nindent 8 }}
52+
{{- end }}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Default values for node-data-broker.
2+
# This is a YAML-formatted file.
3+
# Declare variables to be passed into your templates.
4+
5+
image:
6+
repository: curlimages/curl
7+
pullPolicy: IfNotPresent
8+
# Overrides the image tag whose default is the chart appVersion.
9+
tag: 8.13.0
10+
11+
imagePullSecrets: []
12+
nameOverride: ""
13+
fullnameOverride: ""
14+
15+
podAnnotations: {}
16+
podLabels: {}
17+
18+
podSecurityContext: {}
19+
# fsGroup: 2000
20+
21+
securityContext: {}
22+
# capabilities:
23+
# drop:
24+
# - ALL
25+
# readOnlyRootFilesystem: true
26+
# runAsNonRoot: true
27+
# runAsUser: 1000
28+
29+
resources:
30+
limits:
31+
cpu: 100m
32+
memory: 128Mi
33+
requests:
34+
cpu: 100m
35+
memory: 128Mi
36+
37+
# Additional volumes on the output Deployment definition.
38+
volumes: []
39+
# - name: foo
40+
# secret:
41+
# secretName: mysecret
42+
# optional: false
43+
44+
# Additional volumeMounts on the output Deployment definition.
45+
volumeMounts: []
46+
# - name: foo
47+
# mountPath: "/etc/foo"
48+
# readOnly: true
49+
50+
nodeSelector: {}
51+
52+
tolerations:
53+
- operator: Exists
54+
55+
affinity: {}

cmd/node-data-broker/main.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2024-2025, NVIDIA CORPORATION. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"context"
21+
"flag"
22+
"os"
23+
"syscall"
24+
25+
"github.com/oklog/run"
26+
"k8s.io/klog/v2"
27+
28+
server "github.com/NVIDIA/topograph/pkg/node_data_broker"
29+
)
30+
31+
func main() {
32+
var port int
33+
flag.IntVar(&port, "p", 8181, "service port")
34+
35+
klog.InitFlags(nil)
36+
flag.Parse()
37+
defer klog.Flush()
38+
39+
if err := mainInternal(port); err != nil {
40+
klog.Error(err.Error())
41+
os.Exit(1)
42+
}
43+
}
44+
45+
func mainInternal(port int) error {
46+
ctx, cancel := context.WithCancel(context.Background())
47+
defer cancel()
48+
49+
srv := server.NewServer(ctx, port)
50+
51+
var g run.Group
52+
// Signal handler
53+
g.Add(run.SignalHandler(ctx, os.Interrupt, syscall.SIGTERM))
54+
// Server endpoint
55+
g.Add(srv.Start, srv.Stop)
56+
57+
return g.Run()
58+
}

cmd/node-data-broker/main_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"syscall"
5+
"testing"
6+
"time"
7+
8+
"github.com/stretchr/testify/require"
9+
10+
"github.com/NVIDIA/topograph/pkg/test"
11+
)
12+
13+
func TestMain(t *testing.T) {
14+
port, err := test.GetAvailablePort()
15+
require.NoError(t, err)
16+
17+
ch := make(chan error)
18+
go func() {
19+
ch <- mainInternal(port)
20+
}()
21+
time.Sleep(time.Second)
22+
23+
err = syscall.Kill(syscall.Getpid(), syscall.SIGINT)
24+
require.NoError(t, err)
25+
26+
err = <-ch
27+
require.EqualError(t, err, "received signal interrupt")
28+
}

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,17 @@ require (
6565
github.com/google/gofuzz v1.2.0 // indirect
6666
github.com/google/s2a-go v0.1.9 // indirect
6767
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
68+
github.com/gorilla/websocket v1.5.0 // indirect
6869
github.com/josharian/intern v1.0.0 // indirect
6970
github.com/json-iterator/go v1.1.12 // indirect
7071
github.com/klauspost/compress v1.17.11 // indirect
7172
github.com/leodido/go-urn v1.4.0 // indirect
7273
github.com/mailru/easyjson v0.7.7 // indirect
74+
github.com/moby/spdystream v0.4.0 // indirect
7375
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
7476
github.com/modern-go/reflect2 v1.0.2 // indirect
7577
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
78+
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
7679
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
7780
github.com/prometheus/client_model v0.6.1 // indirect
7881
github.com/prometheus/common v0.60.1 // indirect

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ cloud.google.com/go/compute/metadata v0.6.0 h1:A6hENjEsCDtC1k8byVsgwvVcioamEHvZ4
66
cloud.google.com/go/compute/metadata v0.6.0/go.mod h1:FjyFAW1MW0C203CEOMDTu3Dk1FlqW3Rga40jzHL4hfg=
77
github.com/agrea/ptr v0.2.0 h1:QSyCkddC52uOrIvkypI8vTqUFw0KAnP71u1JU36EvBk=
88
github.com/agrea/ptr v0.2.0/go.mod h1:O85aMmwHY6iqdSLPiaHMVz9AI7qvsZk3JPZ/i13Ec3Y=
9+
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
10+
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
911
github.com/aws/aws-sdk-go-v2/config v1.28.1 h1:oxIvOUXy8x0U3fR//0eq+RdCKimWI900+SV+10xsCBw=
1012
github.com/aws/aws-sdk-go-v2/config v1.28.1/go.mod h1:bRQcttQJiARbd5JZxw6wG0yIK3eLeSCPdg6uqmmlIiI=
1113
github.com/aws/aws-sdk-go-v2/credentials v1.17.42 h1:sBP0RPjBU4neGpIYyx8mkU2QqLPl5u9cmdTWVzIpHkM=
@@ -94,6 +96,8 @@ github.com/googleapis/enterprise-certificate-proxy v0.3.6 h1:GW/XbdyBFQ8Qe+YAmFU
9496
github.com/googleapis/enterprise-certificate-proxy v0.3.6/go.mod h1:MkHOF77EYAE7qfSuSS9PU6g4Nt4e11cnsDUowfwewLA=
9597
github.com/googleapis/gax-go/v2 v2.14.1 h1:hb0FFeiPaQskmvakKu5EbCbpntQn48jyHuvrkurSS/Q=
9698
github.com/googleapis/gax-go/v2 v2.14.1/go.mod h1:Hb/NubMaVM88SrNkvl8X/o8XWwDJEPqouaLeN2IUxoA=
99+
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
100+
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
97101
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
98102
github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
99103
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
@@ -116,13 +120,17 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
116120
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
117121
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
118122
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
123+
github.com/moby/spdystream v0.4.0 h1:Vy79D6mHeJJjiPdFEL2yku1kl0chZpJfZcPpb16BRl8=
124+
github.com/moby/spdystream v0.4.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI=
119125
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
120126
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
121127
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
122128
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
123129
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
124130
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
125131
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
132+
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
133+
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
126134
github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
127135
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
128136
github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA=

0 commit comments

Comments
 (0)