Skip to content

Commit

Permalink
Initial Query API (armadaproject#3370)
Browse files Browse the repository at this point in the history
* F/chrisma/queryapi first cut (armadaproject#59)

* wip

* wip

* wip

* wip

* wip

Signed-off-by: Chris Martin <[email protected]>

* wip

Signed-off-by: Chris Martin <[email protected]>

---------

Signed-off-by: Chris Martin <[email protected]>
Co-authored-by: Christopher Martin <[email protected]>
Co-authored-by: Chris Martin <[email protected]>
  • Loading branch information
3 people authored Feb 5, 2024
1 parent ef34b56 commit 906db96
Show file tree
Hide file tree
Showing 28 changed files with 1,476 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Armada adheres to the CNCF [Code of Conduct](https://github.com/cncf/foundation/

For an overview of the architecture and design of Armada, and instructions for submitting jobs, see:


- [Components overview](./docs/design/relationships_diagram.md)
- [Scheduler](./docs/design/scheduler.md)
- [Architecture](./docs/design/architecture.md)
Expand Down
13 changes: 13 additions & 0 deletions build/queryapi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM alpine:3.18.3

RUN addgroup -S -g 2000 armada && adduser -S -u 1000 armada -G armada

USER armada

COPY ./queryapi /app/

COPY /config/ /app/config/queyapi

WORKDIR /app

ENTRYPOINT ["./queryapi"]
15 changes: 15 additions & 0 deletions build_goreleaser/queryapi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ARG BASE_IMAGE=alpine:3.18.3
FROM ${BASE_IMAGE}
LABEL org.opencontainers.image.title=queryapi
LABEL org.opencontainers.image.description="queryapi"
LABEL org.opencontainers.image.url=https://hub.docker.com/r/gresearchdev/queryapi

RUN addgroup -S -g 2000 armada && adduser -S -u 1000 armada -G armada
USER armada

COPY queryapi /app/
COPY config/queriapi/config.yaml /app/config/queryapi/config.yaml

WORKDIR /app

ENTRYPOINT ["./queryapi"]
39 changes: 39 additions & 0 deletions cmd/queryapi/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"fmt"
"os"

"github.com/spf13/pflag"
"github.com/spf13/viper"

"github.com/armadaproject/armada/internal/common"
"github.com/armadaproject/armada/internal/queryapi"
)

const (
CustomConfigLocation = "config"
)

func init() {
pflag.StringSlice(
CustomConfigLocation,
[]string{},
"Fully qualified path to application configuration file (for multiple config files repeat this arg or separate paths with commas)",
)
pflag.Parse()
}

func main() {
common.ConfigureLogging()
common.BindCommandlineArguments()

var config queryapi.Configuration
userSpecifiedConfigs := viper.GetStringSlice(CustomConfigLocation)

common.LoadConfig(&config, "./config/queryapi", userSpecifiedConfigs)
if err := queryapi.Run(config); err != nil {
fmt.Println(err)
os.Exit(-1)
}
}
21 changes: 21 additions & 0 deletions config/queryapi/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
http:
port: 8080
grpc:
port: 50052
keepaliveParams:
maxConnectionIdle: 5m
time: 120s
timeout: 20s
keepaliveEnforcementPolicy:
minTime: 10s
permitWithoutStream: true
tls:
enabled: false
postgres:
connection:
host: postgres
port: 5432
user: postgres
password: psw
dbname: postgres
sslmode: disable
5 changes: 5 additions & 0 deletions deployment/queryapi/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
description: A helm chart for Armada Query API component
name: armada-query-api
version: 0.0.0-latest
appVersion: 0.0.0-latest
43 changes: 43 additions & 0 deletions deployment/queryapi/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

{{- define "queryapi.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "queryapi.config.name" -}}
{{- printf "%s-%s" ( include "queryapi.name" .) "config" -}}
{{- end }}

{{- define "queryapi.config.filename" -}}
{{- printf "%s%s" ( include "queryapi.config.name" .) ".yaml" -}}
{{- end }}

{{- define "queryapi.users.name" -}}
{{- printf "%s-%s" ( include "queryapi.name" .) "users" -}}
{{- end }}

{{- define "queryapi.users.filename" -}}
{{- printf "%s%s" ( include "queryapi.users.name" .) ".yaml" -}}
{{- end }}

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

{{- define "queryapi.labels.identity" -}}
app: {{ include "queryapi.name" . }}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "queryapi.labels.all" -}}
{{ include "queryapi.labels.identity" . }}
chart: {{ include "queryapi.chart" . }}
release: {{ .Release.Name }}
{{- if .Values.additionalLabels }}
{{ toYaml .Values.additionalLabels }}
{{- end }}
{{- end -}}
109 changes: 109 additions & 0 deletions deployment/queryapi/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "queryapi.name" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "queryapi.labels.all" . | nindent 4 }}
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
{{- include "queryapi.labels.identity" . | nindent 6 }}
{{- if .Values.strategy }}
strategy:
{{- toYaml .Values.strategy | nindent 4 }}
{{- end }}
template:
metadata:
name: {{ include "queryapi.name" . }}
annotations:
checksum/config: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
labels:
{{- include "queryapi.labels.all" . | nindent 8 }}
spec:
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
serviceAccountName: {{ .Values.customServiceAccount | default (include "queryapi.name" .) }}
securityContext:
runAsUser: 1000
runAsGroup: 2000
{{- if .Values.tolerations }}
tolerations:
{{- toYaml .Values.tolerations | nindent 8 }}
{{- end }}
containers:
- name: queryapi
imagePullPolicy: IfNotPresent
image: {{ .Values.image.repository }}:{{ required "A value is required for .Values.image.tag" .Values.image.tag }}
args:
- --config
- /config/application_config.yaml
{{- if .Values.env }}
env:
{{- toYaml .Values.env | nindent 12 -}}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
ports:
- containerPort: {{ .Values.applicationConfig.grpcPort }}
protocol: TCP
name: grpc
- containerPort: {{ .Values.applicationConfig.metricsPort }}
protocol: TCP
name: metrics
- containerPort: {{ .Values.applicationConfig.httpPort }}
protocol: TCP
name: web
volumeMounts:
- name: user-config
mountPath: /config/application_config.yaml
subPath: {{ include "queryapi.config.filename" . }}
readOnly: true
{{- if .Values.applicationConfig.grpc.tls.enabled }}
- name: tls-certs
mountPath: /certs
readOnly: true
{{- end }}
{{- if .Values.additionalVolumeMounts }}
{{- toYaml .Values.additionalVolumeMounts | nindent 12 -}}
{{- end }}
securityContext:
allowPrivilegeEscalation: false
readinessProbe:
httpGet:
path: /health
port: web
initialDelaySeconds: 5
timeoutSeconds: 5
failureThreshold: 2
livenessProbe:
httpGet:
path: /health
port: web
initialDelaySeconds: 10
timeoutSeconds: 10
failureThreshold: 3
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- {{ include "queryapi.name" . }}
topologyKey: kubernetes.io/hostname
volumes:
- name: user-config
secret:
secretName: {{ include "queryapi.config.name" . }}
{{- if .Values.applicationConfig.grpc.tls.enabled }}
- name: tls-certs
secret:
secretName: queryapi-service-tls
{{- end }}
{{- if .Values.additionalVolumes }}
{{- toYaml .Values.additionalVolumes | nindent 8 }}
{{- end }}
43 changes: 43 additions & 0 deletions deployment/queryapi/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "queryapi.name" . }}
namespace: {{ .Release.Namespace }}
annotations:
kubernetes.io/ingress.class: {{ required "A value is required for .Values.ingressClass" .Values.ingressClass }}
nginx.ingress.kubernetes.io/ssl-redirect: "true"
{{- if .Values.applicationConfig.grpc.tls.enabled }}
nginx.ingress.kubernetes.io/backend-protocol: "GRPCS"
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
{{- else }}
nginx.ingress.kubernetes.io/backend-protocol: "GRPC"
{{- end }}
certmanager.k8s.io/cluster-issuer: {{ required "A value is required for .Values.clusterIssuer" .Values.clusterIssuer }}
cert-manager.io/cluster-issuer: {{ required "A value is required for .Values.clusterIssuer" .Values.clusterIssuer }}
{{- if .Values.ingress.annotations }}
{{- toYaml .Values.ingress.annotations | nindent 4 }}
{{- end }}
labels:
{{- include "queryapi.labels.all" . | nindent 4 }}
{{- if .Values.ingress.labels }}
{{- toYaml .Values.ingress.labels | nindent 4 }}
{{- end }}
spec:
rules:
{{- $root := . -}}
{{ range required "A value is required for .Values.hostnames" .Values.hostnames }}
- host: {{ . }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: {{ include "queryapi.name" $root }}
port:
number: {{ $root.Values.applicationConfig.grpcPort }}
{{ end }}
tls:
- hosts:
{{- toYaml .Values.hostnames | nindent 8 }}
secretName: queryapi-service-tls
13 changes: 13 additions & 0 deletions deployment/queryapi/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ include "queryapi.config.name" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "queryapi.labels.all" . | nindent 4 }}
type: Opaque
data:
{{ include "queryapi.config.filename" . }}: |
{{- if .Values.applicationConfig }}
{{ toYaml .Values.applicationConfig | b64enc | indent 4 }}
{{- end }}
29 changes: 29 additions & 0 deletions deployment/queryapi/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "queryapi.name" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "queryapi.labels.all" . | nindent 4 }}
spec:
{{- if .Values.nodePort }}
type: NodePort
{{- end }}
selector:
{{- include "queryapi.labels.identity" . | nindent 4 }}
ports:
- name: grpc
protocol: TCP
port: {{ .Values.applicationConfig.grpcPort }}
{{- if .Values.nodePort }}
nodePort: {{ .Values.nodePort }}
{{- end }}
- name: web
protocol: TCP
port: {{ .Values.applicationConfig.httpPort }}
{{- if .Values.httpNodePort }}
nodePort: {{ .Values.httpNodePort }}
{{- end }}
- name: metrics
protocol: TCP
port: {{ .Values.applicationConfig.metricsPort }}
12 changes: 12 additions & 0 deletions deployment/queryapi/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{ if not .Values.customServiceAccount }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "queryapi.name" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "queryapi.labels.all" . | nindent 4 }}
{{ if .Values.serviceAccount }}
{{ toYaml .Values.serviceAccount }}
{{ end }}
{{ end }}
Loading

0 comments on commit 906db96

Please sign in to comment.