Skip to content

Commit ca6fbd8

Browse files
committed
test run in cluster
1 parent 1e6e480 commit ca6fbd8

23 files changed

Lines changed: 548 additions & 118 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*.dll
77
*.so
88
*.dylib
9+
.kluster.rc
910
bin/*
1011
Dockerfile.cross
1112

.kluster.rc

Lines changed: 0 additions & 1 deletion
This file was deleted.

config/kcp/create-kc

Lines changed: 115 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,114 @@
11
#!/bin/bash -e
22

3+
# set KUBECONFIG to your datapalane cluster
4+
# or provider workspace for KCP.
5+
# It creates a kubeconfig in $KC for
6+
# a controller working on resources in this
7+
# environment.
8+
39
SA=apiexport-serviceaccount-coredns
410
SN=kcp-controller-token
511
NS=dns-service
612
KC=gen/controller.kubeconfig
13+
RT=
14+
TS=
15+
TN=dns-system
16+
17+
error()
18+
{
19+
echo "error: $*" >&2
20+
exit 1
21+
}
22+
23+
args=( "$@" )
24+
consume()
25+
{
26+
local n=$1
27+
if [ $# -eq 0 ]; then
28+
n=1
29+
fi
30+
args=( "${args[@]:$n}")
31+
}
32+
33+
getArg()
34+
{
35+
if [ ${#args[@]} -lt 2 ]; then
36+
error "$1 requires an argument"
37+
fi
38+
local -n target=$1
39+
target="${args[1]}"
40+
consume 2
41+
}
42+
43+
help()
44+
{
45+
echo "create a kubeconfig for a controller using a adataplane to access"
46+
echo "the DNS resources"
47+
echo "--dp <kubeconfig>: dataplane/provider workspace kubeconfig"
48+
echo "--sa <serviceaccount>: service account for created kubeconfig"
49+
echo "--sn <secret name>: service account secret in dataplane and target secret"
50+
echo "--ns <namespace>: namespace in dataplane and target secret"
51+
echo "--kc <target>: file name for target kubeconfig"
52+
echo "--rt <kubeconfig>: target kubeconfig used to create target secret (if set)"
53+
echo "--ts <secret name>: target secret name (defaults to sn)"
54+
echo "--tn <target namespace>: target namespace(defaults to ns)"
55+
exit 0
56+
}
57+
58+
while [ ${#args[@]} -gt 0 ]; do
59+
case "${args[0]}" in
60+
--dry-run)
61+
D=X
62+
consume;;
63+
--restserver)
64+
TS=controller-manager-restdataplane
65+
consume;;
66+
--kubedns)
67+
TS=controller-manager-dataplane
68+
consume;;
69+
--dp) getArg KUBECONFIG
70+
export KUBECONFIG;;
71+
--sa) getArg SA;;
72+
--sn) getArg SN;;
73+
--ns) getArg NS;;
74+
--kc) getArg KC;;
75+
--rt) getArg RT
76+
KC=;;
77+
--ts) getArg TS;;
78+
--tn) getArg TN;;
79+
--help|-h) help;;
80+
--*|-*) error "invalid argument ${args[0]}"
81+
esac
82+
done
83+
84+
echo "kubeconfig: $KUBECONFIG"
85+
echo "service account: $SA"
86+
echo "secret name: $SN"
87+
echo "namespace: $NS"
88+
echo "target file: $KC"
89+
if [ -n "$RT" ]; then
90+
if [ -z "$TS" ]; then
91+
TS="$SN"
92+
fi
93+
if [ -z "$TN" ]; then
94+
TN="$NS"
95+
fi
96+
echo "runtime kubeconfig: $RT"
97+
echo "runtime secret: $TS"
98+
echo "runtime namespace: $TN"
99+
fi
100+
101+
if [ -n "$D" ]; then
102+
exit 1
103+
fi
104+
7105

8106
SRV="$(kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}')"
9107
echo "server is $SRV"
10108

11109
if ! kubectl -n "$NS" get serviceaccount "$SA" >/dev/null 2>&1; then
12110
echo creating serviceaccount $NS/$SA
111+
kubectl apply -f - <<EOF
13112
apiVersion: v1
14113
kind: ServiceAccount
15114
metadata:
@@ -48,19 +147,23 @@ while true; do
48147
fi
49148
done
50149

150+
C="$(basename "$KC")"
151+
if [ -z "$C" ]; then
152+
C=dataplane
153+
fi
51154

52-
cat <<EOF > "$KC"
155+
CONFIG="$(cat <<EOF
53156
apiVersion: v1
54157
kind: Config
55158
clusters:
56-
- name: $(basename "$KC")
159+
- name: $C
57160
cluster:
58161
certificate-authority-data: ${cert}
59162
server: ${SRV}
60163
contexts:
61164
- name: sa-context
62165
context:
63-
cluster: $(basename "$KC")
166+
cluster: $C
64167
user: $A
65168
namespace: $NS
66169
current-context: sa-context
@@ -69,23 +172,29 @@ users:
69172
user:
70173
token: ${token}
71174
EOF
175+
)"
176+
if [ -n "$KC" ]; then
177+
echo "$CONFIG" > "$KC"
72178
echo "Generated $KC"
179+
fi
73180

74181
if [ -n "$RT" ]; then
182+
echo creating secret in target $TN
75183
SECRET="$(cat <<EOF
76184
apiVersion: v1
77185
kind: Secret
78186
type: Opaque
79187
metadata:
80-
name: $SN
81-
namespace: $NS
188+
name: $TS
189+
namespace: $TN
82190
data:
83-
kubeconfig: $(base64 -w 0 "$A.kubeconfig")
191+
kubeconfig: $(base64 -w 0 <<<"$CONFIG")
84192
token: $(base64 -w 0 <<<"$token")
85193
ca.crt: $cert
86194
EOF
87195
)"
88196
echo "$SECRET"
89197
kubectl --kubeconfig "$RT" apply -f - <<<"$SECRET"
198+
echo "Created kubeconfig secret $SN"
90199
fi
91200

config/restapi/deployment.yaml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
apiVersion: v1
3+
kind: Namespace
4+
metadata:
5+
name: dns-system
6+
---
7+
apiVersion: v1
8+
kind: Service
9+
metadata:
10+
name: dns-service-restserver
11+
namespace: dns-system
12+
13+
labels:
14+
target: runtime
15+
app: dns-service-restserver
16+
spec:
17+
type: ClusterIP
18+
19+
# Selects the pods created by the Deployment
20+
selector:
21+
app: dns-service-restserver
22+
23+
ports:
24+
- name: api
25+
protocol: TCP
26+
port: 80 # The port the Service exposes
27+
targetPort: 80 # The containerPort defined in the Deployment
28+
---
29+
apiVersion: apps/v1
30+
kind: Deployment
31+
metadata:
32+
labels:
33+
app: dns-service-restserver
34+
name: dns-service-restserver
35+
namespace: dns-system
36+
spec:
37+
progressDeadlineSeconds: 600
38+
replicas: 1
39+
revisionHistoryLimit: 10
40+
selector:
41+
matchLabels:
42+
app: dns-service-restserver
43+
strategy:
44+
rollingUpdate:
45+
maxSurge: 25%
46+
maxUnavailable: 25%
47+
type: RollingUpdate
48+
template:
49+
metadata:
50+
labels:
51+
app: dns-service-restserver
52+
spec:
53+
automountServiceAccountToken: false
54+
containers:
55+
- args:
56+
- --log-level=info
57+
- --kubeconfig=/etc/coredns/dataplane/kubeconfig
58+
- --kubeconfig-endpointslice=coredns.mandelsoft.org # required for KCP
59+
- --kubeconfig-identity=demo
60+
- --controllers=server
61+
- --dnsapi=:80
62+
image: mandelsoft/kubedns:latest
63+
imagePullPolicy: Always
64+
name: dns-container
65+
ports:
66+
- containerPort: 80
67+
name: api
68+
protocol: TCP
69+
volumeMounts:
70+
- mountPath: /etc/coredns/dataplane
71+
name: secret-volume
72+
readOnly: true
73+
dnsPolicy: ClusterFirst
74+
restartPolicy: Always
75+
securityContext: {}
76+
terminationGracePeriodSeconds: 30
77+
volumes:
78+
- name: secret-volume
79+
secret:
80+
defaultMode: 420
81+
items:
82+
- key: kubeconfig
83+
path: kubeconfig
84+
secretName: controller-manager-restdataplane
85+

config/restapi/forward.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
kubectl port-forward svc/dns-service-restapi 8085:80 -n dns-system

config/restapi/request.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
if [ "$1" == --raw ]; then
2+
URL="$2"
3+
else
4+
WS=1fhyywfw31te2v9c
5+
CL="demo%23$WS"
6+
URL=api/v1/zones/$CL/$1
7+
fi
8+
9+
kubectl get --raw /api/v1/namespaces/dns-system/services/http:dns-service-restserver:api/proxy/"$URL"

go.mod

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ require (
88
github.com/golang-jwt/jwt/v5 v5.2.2
99
github.com/kcp-dev/sdk v0.30.0
1010
github.com/lestrrat-go/jwx/v2 v2.1.6
11-
github.com/mandelsoft/flagutils v0.0.0-20260411162530-8fa8704c866e
11+
github.com/mandelsoft/flagutils v0.0.0-20260501194609-8a50fcdc8aa7
1212
github.com/mandelsoft/goutils v0.0.0-20260419151859-e28bee9b7032
13-
github.com/mandelsoft/kubecrtutils v0.0.0-20260325101220-db841a30ce37
13+
github.com/mandelsoft/kubecrtutils v0.0.0-20260503123820-cca22d376086
1414
github.com/mandelsoft/logging v0.0.0-20260220094735-62d1006ceeb4
1515
github.com/mandelsoft/spiff v1.3.0-beta-7.0.20251217160149-636218617943
1616
github.com/miekg/dns v1.1.72
@@ -22,6 +22,7 @@ require (
2222
k8s.io/client-go v0.35.0
2323
sigs.k8s.io/controller-runtime v0.23.1
2424
sigs.k8s.io/multicluster-runtime v0.23.1
25+
sigs.k8s.io/yaml v1.6.0
2526
)
2627

2728
require (
@@ -61,7 +62,7 @@ require (
6162
github.com/json-iterator/go v1.1.12 // indirect
6263
github.com/kcp-dev/apimachinery/v2 v2.30.0 // indirect
6364
github.com/kcp-dev/logicalcluster/v3 v3.0.5 // indirect
64-
github.com/kcp-dev/multicluster-provider v0.5.0 // indirect
65+
github.com/kcp-dev/multicluster-provider v0.6.0 // indirect
6566
github.com/lestrrat-go/blackmagic v1.0.3 // indirect
6667
github.com/lestrrat-go/httpcc v1.0.1 // indirect
6768
github.com/lestrrat-go/httprc v1.0.6 // indirect
@@ -128,9 +129,9 @@ require (
128129
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
129130
sigs.k8s.io/randfill v1.0.0 // indirect
130131
sigs.k8s.io/structured-merge-diff/v6 v6.3.2-0.20260122202528-d9cc6641c482 // indirect
131-
sigs.k8s.io/yaml v1.6.0 // indirect
132132
)
133133

134-
replace github.com/mandelsoft/kubecrtutils => ../kubecrtutils
134+
//replace github.com/mandelsoft/kubecrtutils => ../kubecrtutils
135135

136-
replace github.com/kcp-dev/multicluster-provider => ../../../github.com/kcp-dev/multicluster-provider
136+
//replace github.com/kcp-dev/multicluster-provider => ../../../github.com/kcp-dev/multicluster-provider
137+
replace github.com/kcp-dev/multicluster-provider => github.com/mandelsoft/multicluster-provider v0.0.0-20260304155307-cdb2c159df23

go.sum

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,18 @@ github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4
124124
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
125125
github.com/mandelsoft/filepath v0.0.0-20240223090642-3e2777258aa3 h1:oo9nIgnyiBgYPbcZslRT4y29siuL5EoNJ/t1tr0xEVQ=
126126
github.com/mandelsoft/filepath v0.0.0-20240223090642-3e2777258aa3/go.mod h1:LxhqC7khDoRENwooP6f/vWvia9ivj6TqLYrR39zqkN0=
127-
github.com/mandelsoft/flagutils v0.0.0-20260411162530-8fa8704c866e h1:vONfGq4bB5FEwqiQAX97gCgsoI7Jiru5VpJGpkk9v6U=
128-
github.com/mandelsoft/flagutils v0.0.0-20260411162530-8fa8704c866e/go.mod h1:C1jdsUdm5TRsaojE8c0phX4127XnxYSgCtavEDvVueI=
127+
github.com/mandelsoft/flagutils v0.0.0-20260501194609-8a50fcdc8aa7 h1:WmmsnQNPY3N7pBJsE20+iwuDA7nvkl0IstTIgAaPsSU=
128+
github.com/mandelsoft/flagutils v0.0.0-20260501194609-8a50fcdc8aa7/go.mod h1:C1jdsUdm5TRsaojE8c0phX4127XnxYSgCtavEDvVueI=
129129
github.com/mandelsoft/goutils v0.0.0-20260419151859-e28bee9b7032 h1:7ToFG9TJfl1kRMz6+MWHDRqbenGHzYp/FahcEoip+A4=
130130
github.com/mandelsoft/goutils v0.0.0-20260419151859-e28bee9b7032/go.mod h1:fTCyGFCMm+ugUn1FqcHeWelCjoSYtkJaqnJvSmgkx1M=
131+
github.com/mandelsoft/kubecrtutils v0.0.0-20260430105017-c1f3a05997de h1:cleK5TbDotTX0SQ9dzs6vZ6r7eo/KJmVPk+bB2cX4HE=
132+
github.com/mandelsoft/kubecrtutils v0.0.0-20260430105017-c1f3a05997de/go.mod h1:x8sKU6UctRixOW+Iz7B766OMEqWGLM9H2DVU09vnXN4=
133+
github.com/mandelsoft/kubecrtutils v0.0.0-20260503123820-cca22d376086 h1:ATogd+Wcz7k86Pi0kdHDFjs9YdrX2HP63mn8FXbX8Y8=
134+
github.com/mandelsoft/kubecrtutils v0.0.0-20260503123820-cca22d376086/go.mod h1:u7xikgvxQxaHI26mYuBGNtRzIggZ/yaYP2cEq1Y2CW8=
131135
github.com/mandelsoft/logging v0.0.0-20260220094735-62d1006ceeb4 h1:wkcH/MKmgUiqvvq+KueAXaQ8iCoVWKghLEof7LGDPM4=
132136
github.com/mandelsoft/logging v0.0.0-20260220094735-62d1006ceeb4/go.mod h1:uO460C1lIB3IOOgrbXhAlz3AKsOv4T2K6ALBn3PwuSg=
137+
github.com/mandelsoft/multicluster-provider v0.0.0-20260304155307-cdb2c159df23 h1:08YofMLtE/dXFcg2LwXrhiFi1NJWdDToLu6JIdprmt8=
138+
github.com/mandelsoft/multicluster-provider v0.0.0-20260304155307-cdb2c159df23/go.mod h1:eJohrSXqLmpjfTSFBbZMoq4Osr57UKg9ZokvhCPNmHc=
133139
github.com/mandelsoft/spiff v1.3.0-beta-7.0.20251217160149-636218617943 h1:tmpp0H3rzMWSoal2Rh9e2jgieNbqk4+naDuCKJdhSHw=
134140
github.com/mandelsoft/spiff v1.3.0-beta-7.0.20251217160149-636218617943/go.mod h1:JcrRfzfeZ/YfT/ssmypC4UeIliR2HHf5qcJVb4wHuZE=
135141
github.com/mandelsoft/vfs v0.4.5-0.20250514111339-d7b067920e91 h1:11lzvnGwbdzG9yURbVnBo6sLk1peCrZr4UlEQKYzb1g=

0 commit comments

Comments
 (0)