Skip to content

Commit d754c7d

Browse files
committed
tests: add scripts for creating and deleting domain member
Signed-off-by: Michael Adam <[email protected]>
1 parent 57f587f commit d754c7d

File tree

4 files changed

+284
-0
lines changed

4 files changed

+284
-0
lines changed

tests/common.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ BASE_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
55

66
AD_DEPLOYMENT_YAML="${SCRIPT_DIR}/files/samba-ad-server-deployment.yml"
77
AD_DEPLOYMENT_NAME="samba-ad-server"
8+
MEMBER_POD_YAML="${SCRIPT_DIR}/files/samba-domain-member-pod.yml"
9+
MEMBER_POD_NAME="samba-dm"
10+
MEMBER_CM_NAME="samba-container-config"
11+
MEMBER_SECRET_NAME="ad-join-secret"
812

913
KEEP=${KEEP:-0}
1014

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
---
2+
# Configuration for the samba domain member pod.
3+
apiVersion: v1
4+
kind: ConfigMap
5+
metadata:
6+
name: samba-container-config
7+
data:
8+
config.json: |
9+
{
10+
"samba-container-config": "v0",
11+
"configs": {
12+
"sambadm1": {
13+
"shares": [
14+
"share"
15+
],
16+
"globals": [
17+
"noprinting",
18+
"sambadm1"
19+
],
20+
"instance_name": "SMBDM1"
21+
}
22+
},
23+
"shares": {
24+
"share": {
25+
"options": {
26+
"path": "/share",
27+
"read only": "no"
28+
}
29+
}
30+
},
31+
"_NOTE": "Change the security and workgroup keys to match your domain.",
32+
"globals": {
33+
"noprinting": {
34+
"options": {
35+
"load printers": "no",
36+
"printing": "bsd",
37+
"printcap name": "/dev/null",
38+
"disable spoolss": "yes"
39+
}
40+
},
41+
"sambadm1": {
42+
"options": {
43+
"log level": "10",
44+
"security": "ads",
45+
"workgroup": "DOMAIN1",
46+
"realm": "DOMAIN1.SINK.TEST",
47+
"server min protocol": "SMB2",
48+
"idmap config * : backend": "autorid",
49+
"idmap config * : range": "2000-9999999"
50+
}
51+
}
52+
}
53+
}
54+
---
55+
# Secret used to pass a AD join password to the winbind pod.
56+
apiVersion: v1
57+
kind: Secret
58+
metadata:
59+
name: ad-join-secret
60+
type: Opaque
61+
stringData:
62+
# Change the value below to match the username and password for a user that
63+
# can join systems your test AD Domain
64+
join.json: |
65+
{"username": "Administrator", "password": "Passw0rd"}
66+
---
67+
# The pod itself.
68+
apiVersion: v1
69+
kind: Pod
70+
metadata:
71+
labels:
72+
app: samba-dm-example
73+
name: samba-dm
74+
spec:
75+
shareProcessNamespace: true
76+
containers:
77+
- image: samba-container:latest
78+
# Need imagePullPolicy Never for working with local images.
79+
# Otherwise we get "ErrImagePull".
80+
imagePullPolicy: Never
81+
name: smb
82+
command:
83+
- "samba-container"
84+
- "--debug-delay=1"
85+
- "run"
86+
- "smbd"
87+
env:
88+
- name: SAMBACC_CONFIG
89+
value: /etc/samba-container/config.json
90+
- name: SAMBA_CONTAINER_ID
91+
value: sambadm1
92+
- name: SAMBACC_VERSION
93+
value: "0.1"
94+
- name: HOSTNAME
95+
value: sambadm1
96+
ports:
97+
- containerPort: 445
98+
hostPort: 455
99+
protocol: TCP
100+
name: "smb"
101+
securityContext:
102+
allowPrivilegeEscalation: true
103+
volumeMounts:
104+
- mountPath: "/share"
105+
name: samba-sharedir
106+
- mountPath: "/etc/samba-container"
107+
name: samba-container-config
108+
- mountPath: "/var/lib/samba"
109+
name: samba-state-dir
110+
- mountPath: "/run/samba/winbindd"
111+
name: samba-sockets-dir
112+
- image: quay.io/samba.org/samba-server:latest
113+
name: winbind
114+
command:
115+
- "samba-container"
116+
- "run"
117+
- "winbindd"
118+
env:
119+
- name: SAMBACC_VERSION
120+
value: "0.1"
121+
- name: SAMBACC_CONFIG
122+
value: /etc/samba-container/config.json
123+
- name: SAMBA_CONTAINER_ID
124+
value: sambadm1
125+
- name: HOSTNAME
126+
value: sambadm1
127+
securityContext:
128+
allowPrivilegeEscalation: true
129+
volumeMounts:
130+
- mountPath: "/etc/samba-container"
131+
name: samba-container-config
132+
- mountPath: "/var/lib/samba"
133+
name: samba-state-dir
134+
- mountPath: "/run/samba/winbindd"
135+
name: samba-sockets-dir
136+
initContainers:
137+
- image: quay.io/samba.org/samba-server:latest
138+
name: init
139+
args:
140+
- "init"
141+
env:
142+
- name: SAMBACC_VERSION
143+
value: "0.1"
144+
- name: SAMBACC_CONFIG
145+
value: /etc/samba-container/config.json
146+
- name: SAMBA_CONTAINER_ID
147+
value: sambadm1
148+
- name: HOSTNAME
149+
value: sambadm1
150+
securityContext:
151+
allowPrivilegeEscalation: true
152+
volumeMounts:
153+
- mountPath: "/etc/samba-container"
154+
name: samba-container-config
155+
- mountPath: "/var/lib/samba"
156+
name: samba-state-dir
157+
- image: quay.io/samba.org/samba-server:latest
158+
name: must-join
159+
args:
160+
- "must-join"
161+
- "--files"
162+
- "--join-file=/etc/join-data/join.json"
163+
env:
164+
- name: SAMBACC_VERSION
165+
value: "0.1"
166+
- name: SAMBACC_CONFIG
167+
value: /etc/samba-container/config.json
168+
- name: SAMBA_CONTAINER_ID
169+
value: sambadm1
170+
- name: HOSTNAME
171+
value: sambadm1
172+
securityContext:
173+
allowPrivilegeEscalation: true
174+
volumeMounts:
175+
- mountPath: "/etc/samba-container"
176+
name: samba-container-config
177+
- mountPath: "/var/lib/samba"
178+
name: samba-state-dir
179+
- mountPath: "/etc/join-data"
180+
name: samba-join-data
181+
readOnly: true
182+
volumes:
183+
- configMap:
184+
name: samba-container-config
185+
name: samba-container-config
186+
- secret:
187+
secretName: ad-join-secret
188+
items:
189+
- key: join.json
190+
path: join.json
191+
name: samba-join-data
192+
- emptyDir:
193+
medium: Memory
194+
name: samba-sockets-dir
195+
- emptyDir: {}
196+
name: samba-state-dir
197+
# Comment out the section below to skip using a PVC for the share
198+
# - persistentVolumeClaim:
199+
# claimName: mypvc
200+
# name: samba-sharedir
201+
# Uncomment the section below to use an empty dir for the share
202+
- emptyDir:
203+
medium: Memory
204+
name: samba-sharedir

tests/test-deploy-ad-member.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
4+
5+
source "${SCRIPT_DIR}/common.sh"
6+
7+
echo "Creating ad member pod..."
8+
ERROR_MSG=$(kubectl create -f "${MEMBER_POD_YAML}" 2>&1 1>/dev/null)
9+
if [ $? -ne 0 ] ; then
10+
if [[ "${ERROR_MSG}" =~ "AlreadyExists" ]] ; then
11+
echo "pod exists already. Continuing."
12+
else
13+
_error "Error creating member pod."
14+
fi
15+
fi
16+
17+
kubectl get pod
18+
19+
podname="$(kubectl get pod | grep "${MEMBER_POD_NAME}" | awk '{ print $1 }')"
20+
[ $? -eq 0 ] || _error "Error getting podname"
21+
22+
echo "Samba ad member pod is $podname"
23+
24+
echo "waiting for pod to be in Running state"
25+
tries=0
26+
podstatus="none"
27+
until [ $tries -ge 120 ] || echo $podstatus | grep -q 'Running'; do
28+
sleep 1
29+
echo -n "."
30+
tries=$(( tries + 1 ))
31+
podstatus="$(kubectl get pod $podname -o go-template='{{.status.phase}}')"
32+
done
33+
echo
34+
kubectl get pod
35+
echo
36+
echo $podstatus | grep -q 'Running' || _error "Pod did not reach Running state"
37+
38+
echo "waiting for samba to become reachable"
39+
tries=0
40+
rc=1
41+
while [ $tries -lt 120 ] && [ $rc -ne 0 ]; do
42+
sleep 1
43+
tries=$(( tries + 1 ))
44+
kubectl exec "${podname}" -c "smb" -- smbclient -N -L 127.0.0.1 2>/dev/null 1>/dev/null
45+
rc=$?
46+
echo -n "."
47+
done
48+
echo
49+
[ $rc -eq 0 ] || _error "Error: samba ad did not become reachable"
50+
51+
echo "member setup done"

tests/test-remove-ad-member.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
4+
5+
source "${SCRIPT_DIR}/common.sh"
6+
7+
if [ ${KEEP} -eq 1 ]; then
8+
echo "keeping ad member pod (KEEP=1)"
9+
exit 0
10+
fi
11+
12+
echo "removing ad member pod..."
13+
kubectl delete pod "${MEMBER_POD_NAME}"
14+
[ $? -eq 0 ] || _error "Error deleting pod"
15+
echo
16+
17+
kubectl delete cm "${MEMBER_CM_NAME}"
18+
[ $? -eq 0 ] || _error "Error deleting configmap"
19+
echo
20+
21+
kubectl delete secret "${MEMBER_SECRET_NAME}"
22+
[ $? -eq 0 ] || _error "Error deleting secret"
23+
echo
24+
25+
echo "ad member pod removed"

0 commit comments

Comments
 (0)