Skip to content

Commit 2225237

Browse files
Merge pull request #11152 from owncloud/run-test-on-kubernetes
[tests-only][full-ci] run tests on kubernetes
2 parents 4d5fba1 + b302665 commit 2225237

File tree

6 files changed

+321
-35
lines changed

6 files changed

+321
-35
lines changed

.drone.star

Lines changed: 127 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,23 @@ config = {
138138
],
139139
"skip": False,
140140
},
141-
"davOperations": {
141+
"davOperations1": {
142142
"suites": [
143143
"apiSpacesDavOperation",
144-
"apiArchiver",
145144
"apiDownloads",
146-
"apiActivities",
147145
"apiAsyncUpload",
148146
"apiDepthInfinity",
149147
],
150148
"skip": False,
151149
},
150+
"davOperations2": {
151+
"suites": [
152+
"apiArchiver",
153+
"apiActivities",
154+
],
155+
"skip": False,
156+
"k3d": True,
157+
},
152158
"groupAndSearch1": {
153159
"suites": [
154160
"apiSearch1",
@@ -1068,6 +1074,7 @@ def localApiTestPipeline(ctx):
10681074
"collaborationServiceNeeded": False,
10691075
"extraCollaborationEnvironment": {},
10701076
"withRemotePhp": with_remote_php,
1077+
"k3d": False,
10711078
}
10721079

10731080
if "localApiTests" in config:
@@ -1078,6 +1085,11 @@ def localApiTestPipeline(ctx):
10781085
params[item] = matrix[item] if item in matrix else defaults[item]
10791086
for storage in params["storages"]:
10801087
for run_with_remote_php in params["withRemotePhp"]:
1088+
run_on_k3d = params["k3d"] and ctx.build.event == "cron"
1089+
ocis_url = OCIS_URL
1090+
if run_on_k3d:
1091+
ocis_url = "https://%s" % OCIS_SERVER_NAME
1092+
10811093
pipeline = {
10821094
"kind": "pipeline",
10831095
"type": "docker",
@@ -1090,18 +1102,19 @@ def localApiTestPipeline(ctx):
10901102
restoreBuildArtifactCache(ctx, "ocis-binary-amd64", "ocis/bin") +
10911103
(tikaService() if params["tikaNeeded"] else []) +
10921104
(waitForServices("online-offices", ["collabora:9980", "onlyoffice:443", "fakeoffice:8080"]) if params["collaborationServiceNeeded"] else []) +
1093-
ocisServer(storage, extra_server_environment = params["extraServerEnvironment"], with_wrapper = True, tika_enabled = params["tikaNeeded"], volumes = ([stepVolumeOcisStorage] if name.startswith("cli") else [])) +
1105+
(waitK3sCluster() + deployOcis() + waitForOcis(ocis_url = ocis_url) + ocisServicePods() if run_on_k3d else ocisServer(storage, extra_server_environment = params["extraServerEnvironment"], with_wrapper = True, tika_enabled = params["tikaNeeded"], volumes = ([stepVolumeOcisStorage]))) +
10941106
(waitForClamavService() if params["antivirusNeeded"] else []) +
10951107
(waitForEmailService() if params["emailNeeded"] else []) +
10961108
(ocisServer(storage, deploy_type = "federation", extra_server_environment = params["extraServerEnvironment"]) if params["federationServer"] else []) +
10971109
((wopiCollaborationService("fakeoffice") + wopiCollaborationService("collabora") + wopiCollaborationService("onlyoffice")) if params["collaborationServiceNeeded"] else []) +
10981110
(ocisHealthCheck("wopi", ["wopi-collabora:9304", "wopi-onlyoffice:9304", "wopi-fakeoffice:9304"]) if params["collaborationServiceNeeded"] else []) +
1099-
localApiTests(ctx, name, params["suites"], storage, params["extraEnvironment"], run_with_remote_php) +
1111+
localApiTests(ctx, name, params["suites"], storage, params["extraEnvironment"], run_with_remote_php, ocis_url = ocis_url) +
11001112
apiTestFailureLog() +
1101-
generateCoverageFromAPITest(ctx, name),
1113+
(generateCoverageFromAPITest(ctx, name) if not run_on_k3d else []),
11021114
"services": (emailService() if params["emailNeeded"] else []) +
11031115
(clamavService() if params["antivirusNeeded"] else []) +
1104-
((fakeOffice() + collaboraService() + onlyofficeService()) if params["collaborationServiceNeeded"] else []),
1116+
((fakeOffice() + collaboraService() + onlyofficeService()) if params["collaborationServiceNeeded"] else []) +
1117+
(k3sCluster() if run_on_k3d else []),
11051118
"depends_on": getPipelineNames(buildOcisBinaryForTesting(ctx)),
11061119
"trigger": {
11071120
"ref": [
@@ -1155,12 +1168,12 @@ def generateCoverageFromAPITest(ctx, name):
11551168
},
11561169
]
11571170

1158-
def localApiTests(ctx, name, suites, storage = "ocis", extra_environment = {}, with_remote_php = False):
1171+
def localApiTests(ctx, name, suites, storage = "ocis", extra_environment = {}, with_remote_php = False, ocis_url = OCIS_URL):
11591172
test_dir = "%s/tests/acceptance" % dirs["base"]
11601173
expected_failures_file = "%s/expected-failures-localAPI-on-%s-storage.md" % (test_dir, storage.upper())
11611174

11621175
environment = {
1163-
"TEST_SERVER_URL": OCIS_URL,
1176+
"TEST_SERVER_URL": ocis_url,
11641177
"TEST_SERVER_FED_URL": OCIS_FED_URL,
11651178
"OCIS_REVA_DATA_ROOT": "%s" % (dirs["ocisRevaDataRoot"] if storage == "owncloud" else ""),
11661179
"STORAGE_DRIVER": storage,
@@ -2617,19 +2630,9 @@ def ocisServer(storage = "ocis", volumes = [], depends_on = [], deploy_type = ""
26172630
"%s/bin/ociswrapper serve --bin %s --url %s --admin-username admin --admin-password admin" % (dirs["ocisWrapper"], ocis_bin, environment["OCIS_URL"]),
26182631
]
26192632

2620-
wait_for_ocis = waitForServices("ocis", [OCIS_DOMAIN])[0]
2621-
if not external_idp:
2622-
wait_for_ocis = {
2623-
"name": "wait-for-%s" % (container_name),
2624-
"image": OC_CI_ALPINE,
2625-
"commands": [
2626-
# wait for ocis-server to be ready (5 minutes)
2627-
"timeout 300 bash -c 'while [ $(curl -sk -uadmin:admin " +
2628-
"%s/graph/v1.0/users/admin " % environment["OCIS_URL"] +
2629-
"-w %{http_code} -o /dev/null) != 200 ]; do sleep 1; done'",
2630-
],
2631-
"depends_on": depends_on,
2632-
}
2633+
wait_for_ocis = waitForOcis(container_name, environment["OCIS_URL"], depends_on)
2634+
if external_idp:
2635+
wait_for_ocis = waitForServices("ocis", [OCIS_DOMAIN])
26332636

26342637
commands = [
26352638
"mkdir -p $GOCOVERDIR",
@@ -2638,19 +2641,16 @@ def ocisServer(storage = "ocis", volumes = [], depends_on = [], deploy_type = ""
26382641
"cp tests/config/drone/app-registry.yaml /root/.ocis/config/app-registry.yaml",
26392642
] + (build_and_run_commands)
26402643

2641-
return [
2642-
{
2643-
"name": container_name,
2644-
"image": OC_CI_GOLANG,
2645-
"detach": True,
2646-
"environment": environment,
2647-
"user": user,
2648-
"commands": commands,
2649-
"volumes": volumes,
2650-
"depends_on": depends_on,
2651-
},
2652-
wait_for_ocis,
2653-
]
2644+
return [{
2645+
"name": container_name,
2646+
"image": OC_CI_GOLANG,
2647+
"detach": True,
2648+
"environment": environment,
2649+
"user": user,
2650+
"commands": commands,
2651+
"volumes": volumes,
2652+
"depends_on": depends_on,
2653+
}] + wait_for_ocis
26542654

26552655
def startOcisService(service = None, name = None, environment = {}, volumes = []):
26562656
"""
@@ -3576,6 +3576,19 @@ def k6LoadTests(ctx):
35763576
},
35773577
}]
35783578

3579+
def waitForOcis(name = "ocis", ocis_url = OCIS_URL, depends_on = []):
3580+
return [{
3581+
"name": "wait-for-%s" % name,
3582+
"image": OC_CI_ALPINE,
3583+
"commands": [
3584+
# wait for ocis-server to be ready (5 minutes)
3585+
"timeout 300 bash -c 'while [ $(curl -sk -uadmin:admin " +
3586+
"%s/graph/v1.0/users/admin " % ocis_url +
3587+
"-w %{http_code} -o /dev/null) != 200 ]; do sleep 1; done'",
3588+
],
3589+
"depends_on": depends_on,
3590+
}]
3591+
35793592
def waitForServices(name, services = []):
35803593
services = ",".join(services)
35813594
return [{
@@ -3754,3 +3767,82 @@ def trivyScan(ctx):
37543767
],
37553768
},
37563769
}
3770+
3771+
def k3sCluster():
3772+
return [{
3773+
"name": OCIS_SERVER_NAME,
3774+
"image": "ghcr.io/k3d-io/k3d:5-dind",
3775+
"user": "root",
3776+
"privileged": True,
3777+
"commands": [
3778+
"git clone --single-branch --branch main --depth 1 https://github.com/owncloud/ocis-charts.git",
3779+
"nohup dockerd-entrypoint.sh &",
3780+
"until docker ps 2>&1 > /dev/null; do sleep 1s; done",
3781+
# create cluster
3782+
"k3d cluster create drone --api-port %s:33199 " % OCIS_SERVER_NAME +
3783+
"-p '80:80@loadbalancer' -p '443:443@loadbalancer' " +
3784+
"--k3s-arg '--tls-san=k3d@server:*' --k3s-arg '--disable=metrics-server@server:*'",
3785+
# wait for services to be ready
3786+
"until kubectl get deployment coredns -n kube-system -o go-template='{{.status.availableReplicas}}' | grep -v -e '<no value>'; do sleep 1s; done",
3787+
"until kubectl get deployment traefik -n kube-system -o go-template='{{.status.availableReplicas}}' | grep -v -e '<no value>'; do sleep 1s; done",
3788+
"k3d kubeconfig get drone > kubeconfig-$${DRONE_BUILD_NUMBER}.yaml",
3789+
"chmod 0600 kubeconfig-$${DRONE_BUILD_NUMBER}.yaml",
3790+
"printf '@@@@@@@@@@@@@@@@@@@@@@@\n@@@@ k3d is ready @@@@\n@@@@@@@@@@@@@@@@@@@@@@@\n'",
3791+
# add dns rewrite rule
3792+
"kubectl create configmap coredns-custom --namespace kube-system " +
3793+
"--from-literal='rewritehost.override=rewrite name exact %s host.k3d.internal'" % OCIS_SERVER_NAME,
3794+
"kubectl -n kube-system rollout restart deployment coredns",
3795+
# watch events
3796+
"kubectl get events -Aw",
3797+
],
3798+
}]
3799+
3800+
def waitK3sCluster():
3801+
return [{
3802+
"name": "wait-cluster",
3803+
"image": "docker.io/bitnami/kubectl:1.31",
3804+
"user": "root",
3805+
"commands": [
3806+
"export KUBECONFIG=kubeconfig-$${DRONE_BUILD_NUMBER}.yaml",
3807+
"until test -f $${KUBECONFIG}; do sleep 1s; done",
3808+
"kubectl config view",
3809+
"kubectl get pods -A",
3810+
],
3811+
}]
3812+
3813+
def deployOcis():
3814+
return [{
3815+
"name": "deploy-ocis",
3816+
"image": "owncloudci/golang:latest",
3817+
"commands": [
3818+
"mv %s/tests/config/drone/k3s/values.yaml %s/ocis-charts/charts/ocis/ci/deployment-values.yaml" % (dirs["base"], dirs["base"]),
3819+
"cp -r %s/tests/config/drone/k3s/authbasic %s/ocis-charts/charts/ocis/templates/" % (dirs["base"], dirs["base"]),
3820+
"cd %s/ocis-charts" % dirs["base"],
3821+
"sed -i '/{{- define \"ocis.basicServiceTemplates\" -}}/a\\\\ {{- $_ := set .scope \"appNameAuthBasic\" \"authbasic\" -}}' ./charts/ocis/templates/_common/_tplvalues.tpl",
3822+
"sed -i '/- name: IDM_ADMIN_PASSWORD/{n;N;N;N;d;}' ./charts/ocis/templates/idm/deployment.yaml",
3823+
"sed -i '/- name: IDM_ADMIN_PASSWORD/a\\\\\\n value: \"admin\"' ./charts/ocis/templates/idm/deployment.yaml",
3824+
"sed -i '/- name: PROXY_HTTP_ADDR/i\\\\ - name: PROXY_ENABLE_BASIC_AUTH\\\n value: \"true\"' ./charts/ocis/templates/proxy/deployment.yaml",
3825+
"export KUBECONFIG=%s/kubeconfig-$${DRONE_BUILD_NUMBER}.yaml" % dirs["base"],
3826+
"make helm-install-atomic",
3827+
],
3828+
"volumes": [
3829+
{
3830+
"name": "gopath",
3831+
"path": "/go",
3832+
},
3833+
],
3834+
}]
3835+
3836+
def ocisServicePods():
3837+
return [{
3838+
"name": "ocis-pods",
3839+
"image": "ghcr.io/k3d-io/k3d:5-dind",
3840+
"user": "root",
3841+
"commands": [
3842+
"export KUBECONFIG=kubeconfig-$${DRONE_BUILD_NUMBER}.yaml",
3843+
"until test -f $${KUBECONFIG}; do sleep 1s; done",
3844+
"kubectl get pods -A",
3845+
"kubectl get ingress -A",
3846+
"kubectl get svc -A",
3847+
],
3848+
}]
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
{{- include "ocis.basicServiceTemplates" (dict "scope" . "appName" "appNameAuthBasic" "appNameSuffix" "") -}}
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
{{ include "ocis.metadata" . }}
5+
spec:
6+
{{- include "ocis.selector" . | nindent 2 }}
7+
{{- if and (not .Values.autoscaling.enabled) (.Values.replicas) }}
8+
replicas: {{ .Values.replicas }}
9+
{{- end }}
10+
{{- include "ocis.deploymentStrategy" . | nindent 2 }}
11+
template:
12+
{{- include "ocis.templateMetadata" (dict "scope" $ "configCheck" false) | nindent 4 }}
13+
spec:
14+
{{- include "ocis.affinity" $ | nindent 6 }}
15+
{{- include "ocis.securityContextAndtopologySpreadConstraints" . | nindent 6 }}
16+
{{- include "ocis.priorityClassName" $.priorityClassName | nindent 6 }}
17+
{{- include "ocis.hostAliases" $ | nindent 6 }}
18+
nodeSelector: {{ toYaml $.nodeSelector | nindent 8 }}
19+
containers:
20+
- name: {{ .appName }}
21+
{{- include "ocis.image" $ | nindent 10 }}
22+
command: ["ocis"]
23+
args: ["auth-basic", "server"]
24+
{{- include "ocis.containerSecurityContext" . | nindent 10 }}
25+
env:
26+
{{- include "ocis.serviceRegistry" . | nindent 12 }}
27+
28+
- name: AUTH_BASIC_LOG_COLOR
29+
value: {{ .Values.logging.color | quote }}
30+
- name: AUTH_BASIC_LOG_LEVEL
31+
value: {{ .Values.logging.level | quote }}
32+
- name: AUTH_BASIC_LOG_PRETTY
33+
value: {{ .Values.logging.pretty | quote }}
34+
35+
- name: AUTH_BASIC_TRACING_ENABLED
36+
value: "{{ .Values.tracing.enabled }}"
37+
- name: AUTH_BASIC_TRACING_TYPE
38+
value: {{ .Values.tracing.type | quote }}
39+
- name: AUTH_BASIC_TRACING_ENDPOINT
40+
value: {{ .Values.tracing.endpoint | quote }}
41+
- name: AUTH_BASIC_TRACING_COLLECTOR
42+
value: {{ .Values.tracing.collector | quote }}
43+
44+
- name: AUTH_BASIC_DEBUG_PPROF
45+
value: {{ .Values.debug.profiling | quote }}
46+
47+
# ----------------------------------------------------
48+
- name: OCIS_URL
49+
value: "https://{{ .Values.externalDomain }}"
50+
51+
- name: AUTH_BASIC_LDAP_URI
52+
value: ldaps://{{ .appNameIdm }}:9235
53+
54+
- name: AUTH_BASIC_LDAP_CACERT
55+
value: /etc/ocis/ldap-ca/ldap-ca.crt
56+
57+
- name: AUTH_BASIC_LDAP_BIND_PASSWORD
58+
valueFrom:
59+
secretKeyRef:
60+
name: {{ include "secrets.ldapBindSecret" . }}
61+
key: reva-ldap-bind-password
62+
# ----------------------------------------------------
63+
64+
- name: AUTH_BASIC_GRPC_ADDR
65+
value: 0.0.0.0:9146
66+
- name: AUTH_BASIC_DEBUG_ADDR
67+
value: 0.0.0.0:9147
68+
69+
- name: AUTH_BASIC_JWT_SECRET
70+
valueFrom:
71+
secretKeyRef:
72+
name: {{ include "secrets.jwtSecret" . }}
73+
key: jwt-secret
74+
75+
{{- include "ocis.caEnv" $ | nindent 12}}
76+
77+
{{- include "ocis.livenessProbe" . | nindent 10 }}
78+
79+
resources: {{ toYaml .resources | nindent 12 }}
80+
81+
ports:
82+
- name: grpc
83+
containerPort: 9146
84+
- name: metrics-debug
85+
containerPort: 9147
86+
87+
volumeMounts:
88+
- name: tmp-volume
89+
mountPath: /tmp
90+
- name: ldap-ca
91+
mountPath: /etc/ocis/ldap-ca
92+
readOnly: true
93+
{{- include "ocis.caPath" $ | nindent 12}}
94+
95+
{{- include "ocis.imagePullSecrets" $ | nindent 6 }}
96+
volumes:
97+
- name: tmp-volume
98+
emptyDir: {}
99+
- name: ldap-ca
100+
secret:
101+
secretName: {{ include "secrets.ldapCASecret" . }}
102+
{{- include "ocis.caVolume" $ | nindent 8}}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{{- include "ocis.basicServiceTemplates" (dict "scope" . "appName" "appNameAuthBasic" "appNameSuffix" "") -}}
2+
{{- $_ := set . "autoscaling" (default (default (dict) .Values.autoscaling) .Values.services.authservice.autoscaling) -}}
3+
{{ include "ocis.hpa" . }}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{- include "ocis.basicServiceTemplates" (dict "scope" . "appName" "appNameAuthBasic" "appNameSuffix" "") -}}
2+
{{ include "ocis.pdb" . }}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{{- include "ocis.basicServiceTemplates" (dict "scope" . "appName" "appNameAuthBasic" "appNameSuffix" "") -}}
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: {{ .appName }}
6+
namespace: {{ template "ocis.namespace" . }}
7+
labels:
8+
app: {{ .appName }}
9+
ocis-metrics: enabled
10+
{{- include "ocis.labels" . | nindent 4 }}
11+
spec:
12+
selector:
13+
app: {{ .appName }}
14+
ports:
15+
- name: grpc
16+
port: 9146
17+
protocol: TCP
18+
appProtocol: {{ .Values.service.appProtocol.grpc | quote}}
19+
- name: metrics-debug
20+
port: 9147
21+
protocol: TCP
22+
appProtocol: {{ .Values.service.appProtocol.http | quote}}

0 commit comments

Comments
 (0)