Skip to content

Commit 1a00a6c

Browse files
committed
feat: implement helm chart v2
Add a brand new, more powerful helm chart. Signed-off-by: Utku Ozdemir <[email protected]>
1 parent 2a69059 commit 1a00a6c

File tree

20 files changed

+914
-40
lines changed

20 files changed

+914
-40
lines changed

cmd/omni/cmd/cmd.go

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/spf13/cobra"
2020
"go.uber.org/zap"
2121
"go.uber.org/zap/zapcore"
22+
"go.yaml.in/yaml/v4"
2223

2324
"github.com/siderolabs/omni/client/pkg/constants"
2425
"github.com/siderolabs/omni/client/pkg/panichandler"
@@ -37,28 +38,14 @@ var rootCmd = &cobra.Command{
3738
SilenceUsage: true,
3839
Version: version.Tag,
3940
RunE: func(*cobra.Command, []string) error {
40-
var loggerConfig zap.Config
41-
42-
if constants.IsDebugBuild {
43-
loggerConfig = zap.NewDevelopmentConfig()
44-
loggerConfig.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
45-
} else {
46-
loggerConfig = zap.NewProductionConfig()
47-
}
48-
49-
if !rootCmdArgs.debug {
50-
loggerConfig.Level.SetLevel(zap.InfoLevel)
51-
} else {
52-
loggerConfig.Level.SetLevel(zap.DebugLevel)
53-
}
54-
55-
logger, err := loggerConfig.Build(
56-
zap.AddStacktrace(zapcore.FatalLevel), // only print stack traces for fatal errors
57-
)
41+
logger, err := buildLogger()
5842
if err != nil {
5943
return fmt.Errorf("failed to set up logging: %w", err)
6044
}
6145

46+
zap.ReplaceGlobals(logger)
47+
zap.RedirectStdLog(logger)
48+
6249
signals := make(chan os.Signal, 1)
6350

6451
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
@@ -75,11 +62,24 @@ var rootCmd = &cobra.Command{
7562
cancel()
7663
}, logger)
7764

78-
config, err := app.PrepareConfig(logger, cmdConfig)
65+
skipConfigValidation := rootCmdArgs.printConfigAndExit
66+
67+
config, err := app.PrepareConfig(skipConfigValidation, logger, cmdConfig)
7968
if err != nil {
8069
return err
8170
}
8271

72+
if rootCmdArgs.printConfigAndExit {
73+
encoder := yaml.NewEncoder(os.Stdout)
74+
encoder.SetIndent(2)
75+
76+
if err := encoder.Encode(config); err != nil {
77+
return err
78+
}
79+
80+
return nil
81+
}
82+
8383
ctx = actor.MarkContextAsInternalActor(ctx)
8484

8585
state, err := omni.NewState(ctx, config, logger, prometheus.DefaultRegisterer)
@@ -106,8 +106,9 @@ var rootCmd = &cobra.Command{
106106
}
107107

108108
var rootCmdArgs struct {
109-
configPath string
110-
debug bool
109+
configPath string
110+
debug bool
111+
printConfigAndExit bool
111112
}
112113

113114
// Execute the command.
@@ -140,6 +141,9 @@ var cmdConfig = config.Default()
140141
func newCommand() *cobra.Command {
141142
rootCmd.Flags().BoolVar(&rootCmdArgs.debug, "debug", constants.IsDebugBuild, "enable debug logs.")
142143

144+
rootCmd.Flags().BoolVar(&rootCmdArgs.printConfigAndExit, "print-config-and-exit", false, "print the final configuration and exit.")
145+
rootCmd.Flags().MarkHidden("print-config-and-exit") //nolint:errcheck
146+
143147
rootCmd.Flags().StringVar(&cmdConfig.Account.ID, "account-id", cmdConfig.Account.ID, "instance account ID, should never be changed.")
144148
rootCmd.Flags().StringVar(&cmdConfig.Account.Name, "name", cmdConfig.Account.Name, "instance user-facing name.")
145149
rootCmd.Flags().StringVar(&cmdConfig.Account.UserPilot.AppToken, "user-pilot-app-token", cmdConfig.Account.UserPilot.AppToken, "user pilot app token.")
@@ -156,6 +160,36 @@ func newCommand() *cobra.Command {
156160
return rootCmd
157161
}
158162

163+
func buildLogger() (*zap.Logger, error) {
164+
if rootCmdArgs.printConfigAndExit {
165+
return zap.NewNop(), nil
166+
}
167+
168+
var loggerConfig zap.Config
169+
170+
if constants.IsDebugBuild {
171+
loggerConfig = zap.NewDevelopmentConfig()
172+
loggerConfig.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
173+
} else {
174+
loggerConfig = zap.NewProductionConfig()
175+
}
176+
177+
if !rootCmdArgs.debug {
178+
loggerConfig.Level.SetLevel(zap.InfoLevel)
179+
} else {
180+
loggerConfig.Level.SetLevel(zap.DebugLevel)
181+
}
182+
183+
logger, err := loggerConfig.Build(
184+
zap.AddStacktrace(zapcore.FatalLevel), // only print stack traces for fatal errors
185+
)
186+
if err != nil {
187+
return nil, fmt.Errorf("failed to set up logging: %w", err)
188+
}
189+
190+
return logger, nil
191+
}
192+
159193
func defineServiceFlags() {
160194
// API
161195
rootCmd.Flags().StringVar(

cmd/omni/pkg/app/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ import (
4141
)
4242

4343
// PrepareConfig prepare the Omni configuration.
44-
func PrepareConfig(logger *zap.Logger, params ...*config.Params) (*config.Params, error) {
44+
func PrepareConfig(skipValidation bool, logger *zap.Logger, params ...*config.Params) (*config.Params, error) {
4545
var err error
4646

47-
config.Config, err = config.Init(logger, params...)
47+
config.Config, err = config.Init(skipValidation, logger, params...)
4848
if err != nil {
4949
return nil, err
5050
}

deploy/helm/omni-v2/.helmignore

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/

deploy/helm/omni-v2/Chart.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v2
2+
name: omni-v2
3+
description: A helm chart to deploy Omni on a Kubernetes cluster
4+
type: application
5+
version: 2.0.0
6+
appVersion: "v1.32.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 "omni-v2.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 "omni-v2.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 "omni-v2.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "omni-v2.labels" -}}
37+
helm.sh/chart: {{ include "omni-v2.chart" . }}
38+
{{ include "omni-v2.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 "omni-v2.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "omni-v2.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 "omni-v2.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "omni-v2.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ include "omni-v2.fullname" . }}
5+
labels:
6+
{{- include "omni-v2.labels" . | nindent 4 }}
7+
data:
8+
config.yaml: |
9+
{{- .Values.config | toYamlPretty | nindent 4 }}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "omni-v2.fullname" . }}
5+
labels:
6+
{{- include "omni-v2.labels" . | nindent 4 }}
7+
spec:
8+
{{- with .Values.strategy }}
9+
strategy:
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
12+
replicas: {{ .Values.replicaCount }}
13+
selector:
14+
matchLabels:
15+
{{- include "omni-v2.selectorLabels" . | nindent 6 }}
16+
template:
17+
metadata:
18+
annotations:
19+
# https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
20+
checksum/configmap: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
21+
checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
22+
{{- with .Values.podAnnotations }}
23+
{{- toYaml . | nindent 8 }}
24+
{{- end }}
25+
labels:
26+
{{- include "omni-v2.labels" . | nindent 8 }}
27+
{{- with .Values.podLabels }}
28+
{{- toYaml . | nindent 8 }}
29+
{{- end }}
30+
spec:
31+
{{- with .Values.imagePullSecrets }}
32+
imagePullSecrets:
33+
{{- toYaml . | nindent 8 }}
34+
{{- end }}
35+
serviceAccountName: {{ include "omni-v2.serviceAccountName" . }}
36+
{{- with .Values.podSecurityContext }}
37+
securityContext:
38+
{{- toYaml . | nindent 8 }}
39+
{{- end }}
40+
containers:
41+
- name: {{ .Chart.Name }}
42+
{{- with .Values.securityContext }}
43+
securityContext:
44+
{{- toYaml . | nindent 12 }}
45+
{{- end }}
46+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
47+
imagePullPolicy: {{ .Values.image.pullPolicy }}
48+
envFrom:
49+
- secretRef:
50+
name: {{ include "omni-v2.fullname" . }}
51+
{{- if .Values.existingSecret }}
52+
- secretRef:
53+
name: {{ .Values.existingSecret }}
54+
{{- end }}
55+
{{- with .Values.args }}
56+
args:
57+
{{- toYaml . | nindent 12 }}
58+
{{- end }}
59+
ports:
60+
- name: omni
61+
containerPort: 8080
62+
protocol: TCP
63+
- name: siderolink-api
64+
containerPort: 8090
65+
protocol: TCP
66+
- name: k8s-proxy
67+
containerPort: 8095
68+
protocol: TCP
69+
- name: wireguard
70+
containerPort: 50180
71+
protocol: UDP
72+
{{- with .Values.livenessProbe }}
73+
livenessProbe:
74+
{{- toYaml . | nindent 12 }}
75+
{{- end }}
76+
{{- with .Values.readinessProbe }}
77+
readinessProbe:
78+
{{- toYaml . | nindent 12 }}
79+
{{- end }}
80+
{{- with .Values.resources }}
81+
resources:
82+
{{- toYaml . | nindent 12 }}
83+
{{- end }}
84+
volumeMounts:
85+
- name: config
86+
mountPath: /config
87+
- name: data
88+
mountPath: /data
89+
{{- with .Values.volumeMounts }}
90+
{{- toYaml . | nindent 12 }}
91+
{{- end }}
92+
volumes:
93+
- name: config
94+
configMap:
95+
name: {{ include "omni-v2.fullname" . }}
96+
- name: data
97+
{{- if .Values.persistence.enabled }}
98+
persistentVolumeClaim:
99+
claimName: {{ .Values.persistence.existingClaim | default (include "omni-v2.fullname" .) }}
100+
{{- else }}
101+
emptyDir: {}
102+
{{- end }}
103+
{{- with .Values.volumes }}
104+
{{- toYaml . | nindent 8 }}
105+
{{- end }}
106+
{{- with .Values.nodeSelector }}
107+
nodeSelector:
108+
{{- toYaml . | nindent 8 }}
109+
{{- end }}
110+
{{- with .Values.affinity }}
111+
affinity:
112+
{{- toYaml . | nindent 8 }}
113+
{{- end }}
114+
{{- with .Values.tolerations }}
115+
tolerations:
116+
{{- toYaml . | nindent 8 }}
117+
{{- end }}

0 commit comments

Comments
 (0)