Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Commit c75b6ed

Browse files
committed
feat: Add Helm & Skaffold configuration for dhclientd, fix multiple statik embeds
1 parent 712279f commit c75b6ed

File tree

9 files changed

+219
-22
lines changed

9 files changed

+219
-22
lines changed

charts/dhclientd/Chart.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
name: dhclientd
3+
version: 0.0.1
4+
description: An ISC DHCP client management daemon.
5+
type: application
6+
home: https://pojntfx.github.io/go-isc-dhcp/
7+
sources:
8+
- [email protected]:pojntfx/go-isc-dhcp.git
9+
maintainers:
10+
- name: Felix Pojtinger
11+
12+
url: https://felix.pojtinger.com
13+
appVersion: 0.0.1
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: dhclient-{{ .Release.Name }}{{ if .Values.meta.dev }}-dev{{ end }}
5+
data:
6+
DIBS_TARGET: "{{ .Values.meta.target }}"
7+
TARGETPLATFORM: "{{ .Values.meta.platform }}"
8+
{{ if and .Values.meta.dev .Values.meta.debug }}
9+
DIBS_DEBUG: "true"
10+
{{end}}
11+
12+
---
13+
apiVersion: apps/v1
14+
kind: Deployment
15+
metadata:
16+
name: dhclientd-{{ .Release.Name }}{{ if .Values.meta.dev }}-dev{{ end }}
17+
spec:
18+
selector:
19+
matchLabels:
20+
app: dhclientd-{{ .Release.Name }}{{ if .Values.meta.dev }}-dev{{ end }}
21+
template:
22+
metadata:
23+
labels:
24+
app: dhclientd-{{ .Release.Name }}{{ if .Values.meta.dev }}-dev{{ end }}
25+
spec:
26+
hostNetwork: true
27+
dnsPolicy: ClusterFirstWithHostNet
28+
{{ if .Values.resources.nodeSelector }}
29+
nodeSelector:
30+
{{ toYaml .Values.resources.nodeSelector }}
31+
{{ end }}
32+
containers:
33+
- name: dhclientd{{ if .Values.meta.dev }}-dev{{ end }}
34+
image: {{ .Values.meta.image }}
35+
envFrom:
36+
- configMapRef:
37+
name: dhclient-{{ .Release.Name }}{{ if .Values.meta.dev }}-dev{{ end }}
38+
{{ if not .Values.meta.dev }}
39+
resources:
40+
limits:
41+
memory: {{ .Values.resources.memory }}
42+
cpu: {{ .Values.resources.cpu }}
43+
{{ end }}
44+
ports:
45+
- containerPort: 1241
46+
{{ if and .Values.meta.dev .Values.meta.debug }}
47+
- containerPort: {{ .Values.meta.debugPort }}
48+
{{end}}
49+
{{ if .Values.meta.dev }}
50+
51+
---
52+
apiVersion: v1
53+
kind: Service
54+
metadata:
55+
name: dhclientd-{{ .Release.Name }}-dev
56+
spec:
57+
selector:
58+
app: dhclientd-{{ .Release.Name }}-dev
59+
type: NodePort
60+
ports:
61+
- name: grpc
62+
port: 1241
63+
targetPort: 1241
64+
nodePort: {{ .Values.ingress.nodePort }}
65+
- name: debug
66+
port: {{ .Values.meta.debugNodePort }}
67+
targetPort: {{ .Values.meta.debugPort }}
68+
nodePort: {{ .Values.meta.debugNodePort }}
69+
{{ else }}
70+
71+
---
72+
apiVersion: autoscaling/v2beta1
73+
kind: HorizontalPodAutoscaler
74+
metadata:
75+
name: dhclientd-{{ .Release.Name }}
76+
spec:
77+
maxReplicas: {{ .Values.resources.maxReplicas }}
78+
minReplicas: 1
79+
scaleTargetRef:
80+
apiVersion: apps/v1
81+
kind: Deployment
82+
name: dhclientd-{{ .Release.Name }}
83+
metrics:
84+
- type: Resource
85+
resource:
86+
name: cpu
87+
targetAverageUtilization: 60
88+
89+
---
90+
apiVersion: v1
91+
kind: Service
92+
metadata:
93+
name: dhclientd-{{ .Release.Name }}
94+
spec:
95+
selector:
96+
app: dhclientd-{{ .Release.Name }}
97+
ports:
98+
- name: grpc
99+
port: 1241
100+
targetPort: 1241
101+
102+
---
103+
apiVersion: networking.k8s.io/v1beta1
104+
kind: Ingress
105+
metadata:
106+
name: dhclientd-{{ .Release.Name }}
107+
annotations:
108+
ingress.kubernetes.io/protocol: h2c
109+
spec:
110+
rules:
111+
- host: {{ .Values.ingress.domain }}
112+
http:
113+
paths:
114+
- path: {{ .Values.ingress.path }}
115+
backend:
116+
serviceName: dhclientd-{{ .Release.Name }}
117+
servicePort: grpc
118+
{{ end }}

charts/dhclientd/values.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
meta:
2+
image: pojntfx/dhclientd:latest
3+
dev: false
4+
debugPort: 31441
5+
debugNodePort: 31441
6+
target: "{{ .DIBS_TARGET }}"
7+
platform: "{{ .TARGETPLATFORM }}"
8+
debug: "{{ .DIBS_DEBUG }}"
9+
10+
resources:
11+
nodeSelector: {}
12+
memory: "128Mi"
13+
cpu: "256m"
14+
maxReplicas: 10
15+
16+
ingress:
17+
nodePort: 31241
18+
domain: dhclientd.felix.pojtinger.com
19+
path: /

cmd/dhclientd/main.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
package main
22

33
import (
4+
"net"
5+
"os"
6+
"os/signal"
7+
"path/filepath"
8+
"strings"
9+
"syscall"
10+
411
constants "github.com/pojntfx/go-isc-dhcp/cmd"
512
goISCDHCP "github.com/pojntfx/go-isc-dhcp/pkg/proto/generated"
6-
"github.com/pojntfx/go-isc-dhcp/pkg/svc"
13+
"github.com/pojntfx/go-isc-dhcp/pkg/svc/dhclient"
714
"github.com/pojntfx/go-isc-dhcp/pkg/workers"
815
"github.com/spf13/cobra"
916
"github.com/spf13/viper"
1017
"gitlab.com/bloom42/libs/rz-go"
1118
"gitlab.com/bloom42/libs/rz-go/log"
1219
"google.golang.org/grpc"
1320
"google.golang.org/grpc/reflection"
14-
"net"
15-
"os"
16-
"os/signal"
17-
"path/filepath"
18-
"strings"
19-
"syscall"
2021
)
2122

2223
const (
@@ -55,7 +56,7 @@ https://pojntfx.github.io/go-isc-dhcp/`,
5556
server := grpc.NewServer()
5657
reflection.Register(server)
5758

58-
DHClientService := svc.DHClientManager{
59+
DHClientService := dhclient.DHClientManager{
5960
BinaryDir: binaryDir,
6061
DHClientsManaged: make(map[string]*workers.DHClient),
6162
}

cmd/dhcpdd/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
constants "github.com/pojntfx/go-isc-dhcp/cmd"
1212
goISCDHCP "github.com/pojntfx/go-isc-dhcp/pkg/proto/generated"
13-
"github.com/pojntfx/go-isc-dhcp/pkg/svc"
13+
"github.com/pojntfx/go-isc-dhcp/pkg/svc/dhcpd"
1414
"github.com/pojntfx/go-isc-dhcp/pkg/workers"
1515
"github.com/spf13/cobra"
1616
"github.com/spf13/viper"
@@ -56,7 +56,7 @@ https://pojntfx.github.io/go-isc-dhcp/`,
5656
server := grpc.NewServer()
5757
reflection.Register(server)
5858

59-
DHCPDService := svc.DHCPDManager{
59+
DHCPDService := dhcpd.DHCPDManager{
6060
BinaryDir: binaryDir,
6161
StateDir: filepath.Join(os.TempDir(), "go-isc-dhcp", "dhcpd"),
6262
DHCPDsManaged: make(map[string]*workers.DHCPD),

pkg/svc/dhclient.go renamed to pkg/svc/dhclient/dhclient.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package svc
1+
package dhclient
22

33
import (
44
"context"
55
"os"
66

77
goISCDHCP "github.com/pojntfx/go-isc-dhcp/pkg/proto/generated"
8+
_ "github.com/pojntfx/go-isc-dhcp/pkg/svc/statikDhclient" // Embedded ISC DHCP client binary
89
"github.com/pojntfx/go-isc-dhcp/pkg/workers"
910
"github.com/rakyll/statik/fs"
1011
uuid "github.com/satori/go.uuid"

pkg/svc/dhcpd.go renamed to pkg/svc/dhcpd/dhcpd.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
package svc
2-
3-
//go:generate mkdir -p ../proto/generated
4-
//go:generate sh -c "protoc --go_out=paths=source_relative,plugins=grpc:../proto/generated -I=../proto ../proto/*.proto"
5-
//go:generate rm -rf dhcp statikDhcpd statikDhclient
6-
//go:generate git clone https://gitlab.isc.org/isc-projects/dhcp.git
7-
//go:generate sh -c "cd dhcp; ./configure; make; cd .."
8-
//go:generate statik -src dhcp/server -include dhcpd -p statikDhcpd
9-
//go:generate statik -src dhcp/client -include dhclient -p statikDhclient
1+
package dhcpd
102

113
import (
124
"context"
135
"os"
146
"path/filepath"
157

168
goISCDHCP "github.com/pojntfx/go-isc-dhcp/pkg/proto/generated"
17-
_ "github.com/pojntfx/go-isc-dhcp/pkg/svc/statikDhclient" // Embedded ISC DHCP client binary
18-
_ "github.com/pojntfx/go-isc-dhcp/pkg/svc/statikDhcpd" // Embedded ISC DHCP server binary
9+
_ "github.com/pojntfx/go-isc-dhcp/pkg/svc/statikDhcpd" // Embedded ISC DHCP server binary
1910
"github.com/pojntfx/go-isc-dhcp/pkg/workers"
2011
"github.com/rakyll/statik/fs"
2112
uuid "github.com/satori/go.uuid"

pkg/svc/generate.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package svc
2+
3+
//go:generate mkdir -p ../proto/generated
4+
//go:generate sh -c "protoc --go_out=paths=source_relative,plugins=grpc:../proto/generated -I=../proto ../proto/*.proto"
5+
//go:generate rm -rf dhcp statikDhcpd statikDhclient
6+
//go:generate git clone https://gitlab.isc.org/isc-projects/dhcp.git
7+
//go:generate sh -c "cd dhcp; ./configure; make; cd .."
8+
//go:generate statik -src dhcp/server -include dhcpd -p statikDhcpd
9+
//go:generate statik -src dhcp/client -include dhclient -p statikDhclient

skaffold.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,48 @@ profiles:
4848
setValueTemplates:
4949
meta.platform: "{{ .TARGETPLATFORM }}"
5050
meta.debug: "{{ .DIBS_DEBUG }}"
51+
- name: dhclientd
52+
build:
53+
artifacts:
54+
- image: pojntfx/dhclientd
55+
context: .
56+
docker:
57+
dockerfile: Dockerfile.dhclientd
58+
buildArgs:
59+
DIBS_TARGET: dhclientd-linux
60+
local:
61+
useBuildkit: true
62+
deploy:
63+
helm:
64+
releases:
65+
- name: dhclientd
66+
chartPath: charts/dhclientd
67+
values:
68+
meta.image: pojntfx/dhclientd
69+
- name: dhclientd-dev
70+
build:
71+
artifacts:
72+
- image: pojntfx/dhclientd-dev
73+
context: .
74+
docker:
75+
dockerfile: Dockerfile.dev
76+
buildArgs:
77+
DIBS_TARGET: dhclientd-linux
78+
sync:
79+
infer:
80+
- "**/*" # Re-deploy manually to apply k8s changes
81+
local:
82+
useBuildkit: true
83+
deploy:
84+
helm:
85+
releases:
86+
- name: dhclientd-dev
87+
chartPath: charts/dhclientd
88+
values:
89+
meta.image: pojntfx/dhclientd-dev
90+
setValues:
91+
meta.dev: true
92+
meta.target: dhclientd-linux
93+
setValueTemplates:
94+
meta.platform: "{{ .TARGETPLATFORM }}"
95+
meta.debug: "{{ .DIBS_DEBUG }}"

0 commit comments

Comments
 (0)