Skip to content

Commit

Permalink
Add demo helm template to run service with google android emulators.
Browse files Browse the repository at this point in the history
Refactor basic-auth config.
Add dockerfile.
Add logback configuration to config map.
Add CRD install to local-install.sh script.

Update README docs.
  • Loading branch information
rtorsten committed Mar 30, 2023
1 parent 7927259 commit 3678148
Show file tree
Hide file tree
Showing 37 changed files with 872 additions and 237 deletions.
5 changes: 5 additions & 0 deletions .deploy/demo/helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
name: droidherd-service
description: Tinkoff Android Farm
version: 1.0.0
appVersion: "1.0"
61 changes: 61 additions & 0 deletions .deploy/demo/helm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Demo helm template

This is template designed for demo purposes.

## Overview

Template contains necessary manifests to deploy droidherd-service itself and minimal required configuration
to run android emulators.

All configuration deployed as configmaps so you can change it in k8s directly for any
testing. But droidherd-service currently cannot refresh configuration on fly so don't forget to restart it.

## How to apply

Use local-install.sh script as template and configure required values in values.yaml.

Before install also need to apply CRD for cluster, it is placed crd-model:

```bash
kubectl apply -f crd-model/src/main/crd/testops.tinkoff.ru_droidherdsessions.yaml
```

## How to use

Swagger:

By default basic-auth provided with several test clients.
They are placed in config/basic-auth.json file.

Client id 'droidherd-default' available to use without password.

## Docker android images

Use images from [google](https://github.com/google/android-emulator-container-scripts) which is public available.

Be aware that some configuration for them added to pod-emulator.yml template which can be significantly differ
if you will be run other android images.

Also, special script emulator-startup-probe is mounted to emulator and used
to check that emulator is ready. It is important part because
droidherd-service use 'ready' attribute to determine that emulator can be accessible by client.

### Android images are 'heavy'

Be aware that android images require a lot of space (especially created by google) and during initial run on k8s node
it may cause a lot of traffic in your network.

Recommended way to pre-pull required images to your k8s nodes manually
before open public access to service.


# Troubleshooting

## Dry run failed - k8s fails with 404 error

It its caused because CRD is not installed.

Install CRD which is placed in crd-model to your cluster.
```bash
kubectl apply -f crd-model/src/main/crd/testops.tinkoff.ru_droidherdsessions.yaml
```
34 changes: 34 additions & 0 deletions .deploy/demo/helm/config/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
droidherd {
namespace = "droidherd-service"
namespace= ${?NAMESPACE}
sessionValidationExpiredAfterSeconds = 10800
lastSeenMaxDeltaSeconds = 600
invalidateSessionsPeriodSeconds = 60
operatorResyncPeriodMinutes = 1
listResourcesTimeoutSeconds = 11
superuser = "superuser"
superuser = ${?AUTH_SUPERUSER}
crdTemplatePath = "/operator/crd-template.yml"
podTemplatePath = "/operator/pod-template.yml"
serviceTemplatePath = "/operator/service-template.yml"

allowedImages {
android-29 = "us-docker.pkg.dev/android-emulator-268719/images/29-google-x64-no-metrics"
android-30 = "us-docker.pkg.dev/android-emulator-268719/images/30-google-x64-no-metrics"
}

requeueAfterDefaultSeconds = 15
requeueAfterPendingSeconds = 10
requeueAfterCreationSeconds = 30
applyCrdAtStartup = false
dryRun = true
droidherdHost = "localhost:8080"
droidherdHost = ${?DROIDHERD_HOST}
}

quota {
defaultQuota = 5
quotaConfigPath = "/config/quotas.conf"
allowMissingConfig = false
refreshPeriodMinutes = 5
}
38 changes: 38 additions & 0 deletions .deploy/demo/helm/config/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
spring:
main:
banner-mode: "off"
application:
name: droidherd-service

server:
port: ${APP_PORT:8080}

management:
server:
port: ${APP_SYSTEM_PORT:8085}
endpoints:
web:
exposure:
include: health,prometheus
base-path: /system
endpoint:
health:
probes:
enabled: true
health:
readinessstate:
enabled: true
livenessstate:
enabled: true

logging.level:
org.zalando.logbook: TRACE
com.zaxxer.hikari.HikariConfig: INFO

logbook:
format:
style: http
strategy: without-body
minimum-status: 200
exclude:
- /system/**
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
{
"client": "droidherd-default",
"password": "",
"info": "Default droidherd client for test"
"info": "Default droidherd client for demo purposes"
},
{
"client": "fork-client-1",
"password": "test",
"info": "Client for test"
"password": "test"
},
{
"client": "fork-client-2",
Expand Down
14 changes: 14 additions & 0 deletions .deploy/demo/helm/config/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration scan="false">
<statusListener class="ch.qos.logback.core.status.NopStatusListener"/>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
4 changes: 4 additions & 0 deletions .deploy/demo/helm/config/quotas.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
clients {
droidherd-default=10
}

9 changes: 9 additions & 0 deletions .deploy/demo/helm/local-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

# this is helper script to quick install helm template

# register droidherd CRD in k8s cluster
kubectl apply -f ../../../crd-model/src/main/crd/testops.tinkoff.ru_droidherdsessions.yaml

# deploy service
helm -n droidherd-service upgrade --install droidherd-service .
24 changes: 24 additions & 0 deletions .deploy/demo/helm/operator/crd-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: testops.tinkoff.ru/v1
kind: DroidherdSession
metadata:
name: "{{Name}}"
labels:
droidherdId: "{{Name}}"
droidherdClientId: "{{ClientId}}"
droidherdSessionId: "{{SessionId}}"
spec:
client:
ci:
jobUrl: "{{ciJobUrl}}"
name: "{{ciName}}"
reference: "{{ciReference}}"
repository: "{{ciRepository}}"
triggeredBy: "{{ciTriggeredBy}}"
id: {{ClientId}}
info: {{ClientInfo}}
ip: {{ClientIp}}
version: {{ClientVersion}}
sessionId: {{SessionId}}
isDebug: {{IsDebug}}
emulators: []
parameters: []
83 changes: 83 additions & 0 deletions .deploy/demo/helm/operator/pod-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{Name}}"
labels:
droidherdId: "{{Name}}"
droidherdSessionName: "{{DroidherdSessionName}}"
droidherdClientId: "{{ClientId}}"
droidherdSessionId: "{{SessionId}}"
image: "{{Image}}"
ownerReferences:
- apiVersion: testops.tinkoff.ru/v1
kind: DroidherdSession
name: "{{DroidherdSessionName}}"
uid: "{{UID}}"
blockOwnerDeletion: false
spec:
automountServiceAccountToken: false
restartPolicy: Always
containers:
- name: emulator
image: "{{FullQualifiedImage}}"
securityContext:
privileged: true
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: /dev/kvm
name: dev-kvm
- mountPath: /dev/shm
name: dev-shm
- name: emulators-config
mountPath: /emulator-startup-probe.sh
subPath: emulator-startup-probe.sh
ports:
- containerPort: 5555
name: tcp-adb
protocol: TCP
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ANDROID_AVD_HOME
value: "/android-home"
- name: EMULATOR_ID
value: '{{Name}}'
- name: CLIENT_ID
value: '{{ClientId}}'
- name: ANDROID_VERSION
value: '{{Image}}'
- name: DROIDHERD_HOST
value: '{{DroidherdHost}}'
- name: EMULATOR_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
startupProbe:
exec:
command:
- /emulator-startup-probe.sh
initialDelaySeconds: 20
timeoutSeconds: 5
periodSeconds: 5
successThreshold: 1
failureThreshold: 30
resources:
requests:
cpu: 3000m
memory: 4Gi
limits:
cpu: 3000m
volumes:
- name: dev-kvm
hostPath:
path: /dev/kvm
- name: dev-shm
hostPath:
path: /dev/shm
- name: emulators-config
configMap:
name: emulators-config
defaultMode: 0777
terminationGracePeriodSeconds: 0
25 changes: 25 additions & 0 deletions .deploy/demo/helm/operator/service-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: v1
kind: Service
metadata:
name: "{{Name}}"
labels:
droidherdId: "{{Name}}"
droidherdSessionName: "{{DroidherdSessionName}}"
droidherdClientId: "{{ClientId}}"
droidherdSessionId: "{{SessionId}}"
image: "{{Image}}"
ownerReferences:
- apiVersion: testops.tinkoff.ru/v1
kind: DroidherdSession
name: "{{DroidherdSessionName}}"
uid: "{{UID}}"
blockOwnerDeletion: false
spec:
selector:
droidherdId: "{{Name}}"
droidherdSessionName: "{{DroidherdSessionName}}"
type: NodePort
ports:
- name: tcp-adb
port: 5555
protocol: TCP
8 changes: 8 additions & 0 deletions .deploy/demo/helm/resources/emulator-startup-probe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

while [ "$(${ANDROID_SDK_ROOT}/platform-tools/adb shell getprop sys.boot_completed | tr -d '\r')" != "1" ]; do
echo "Still waiting for boot.."
exit 1
done

exit 0
10 changes: 10 additions & 0 deletions .deploy/demo/helm/start-emulator-in-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

# this helper script to check how emulator is running in docker
# it can be used for debug and testing purposes

EMULATOR_IMAGE="us-docker.pkg.dev/android-emulator-268719/images/29-google-x64-no-metrics"

docker run --rm -it --privileged \
-v /dev/kvm:/dev/kvm -v /dev/shm:/dev/shm \
$EMULATOR_IMAGE bash
15 changes: 15 additions & 0 deletions .deploy/demo/helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "droidherd-service.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "droidherd-service.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

18 changes: 18 additions & 0 deletions .deploy/demo/helm/templates/configmap-application-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: droidherd-config
labels:
chart: {{ .Chart.Name }}
release: {{ .Release.Name }}
data:
application.conf: |
{{ .Files.Get "config/application.conf" | indent 4 }}
application.yaml: |
{{ .Files.Get "config/application.yaml" | indent 4 }}
basic-auth.json: |
{{ .Files.Get "config/basic-auth.json" | indent 4 }}
quotas.conf: |
{{ .Files.Get "config/quotas.conf" | indent 4 }}
logback.xml: |
{{ .Files.Get "config/logback.xml" | indent 4 }}
7 changes: 7 additions & 0 deletions .deploy/demo/helm/templates/configmap-emulator-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: emulators-config
data:
emulator-startup-probe.sh: |
{{ tpl (.Files.Get "resources/emulator-startup-probe.sh") . | indent 4 }}
Loading

0 comments on commit 3678148

Please sign in to comment.