Skip to content

Commit

Permalink
Merge pull request #10 from rcarrillocruz/add_extra_settings_capability
Browse files Browse the repository at this point in the history
Add extra_settings logic for EDA server
  • Loading branch information
rooftopcellist authored Mar 21, 2023
2 parents 5dd2e59 + ddd76b0 commit 79d7cef
Show file tree
Hide file tree
Showing 4 changed files with 261 additions and 0 deletions.
10 changes: 10 additions & 0 deletions config/crd/bases/eda.ansible.com_edas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ spec:
nodeport_port:
description: Port to use for the nodeport
type: integer
extra_settings:
description: Extra settings to specify for the API
items:
properties:
setting:
type: string
value:
x-kubernetes-preserve-unknown-fields: true
type: object
type: array
status:
description: Status defines the observed state of EDA
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ spec:
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:io.kubernetes:Secret
- displayName: API Extra Settings
path: extra_settings
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:hidden
- displayName: No Log Configuration
path: no_log
x-descriptors:
Expand Down
12 changes: 12 additions & 0 deletions roles/eda/templates/eda-api.deployment.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,16 @@ spec:
ports:
- containerPort: 8000
resources: {{ api.resource_requirements }}
volumeMounts:
- name: {{ ansible_operator_meta.name }}-settings
mountPath: /app/src/src/aap_eda/settings/default.py
subPath: default.py
readOnly: true
restartPolicy: Always
volumes:
- name: {{ ansible_operator_meta.name }}-settings
configMap:
name: '{{ ansible_operator_meta.name }}-{{ deployment_type }}-configmap'
items:
- key: settings
path: default.py
234 changes: 234 additions & 0 deletions roles/eda/templates/eda.configmap.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,240 @@ metadata:
labels:
{{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(width=4) | trim }}
data:
settings: |
import dynaconf

settings = dynaconf.Dynaconf(envvar_prefix="EDA")

# ---------------------------------------------------------
# DJANGO SETTINGS
# ---------------------------------------------------------

SECRET_KEY = settings.get("SECRET_KEY")

DEBUG = settings.get("DEBUG", False)

ALLOWED_HOSTS = settings.get("ALLOWED_HOSTS", [])
ALLOWED_HOSTS = (
ALLOWED_HOSTS.split(",")
if isinstance(ALLOWED_HOSTS, str)
else ALLOWED_HOSTS
)


# Application definition
INSTALLED_APPS = [
"daphne",
# Django apps
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.staticfiles",
# Third party apps
"rest_framework",
"drf_spectacular",
"django_rq",
"django_filters",
# Local apps
"aap_eda.api",
"aap_eda.core",
]

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "aap_eda.urls"

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
],
},
},
]

WSGI_APPLICATION = "aap_eda.wsgi.application"

ASGI_APPLICATION = "aap_eda.asgi.application"


# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"HOST": settings.get("DB_HOST", "127.0.0.1"),
"PORT": settings.get("DB_PORT", 5432),
"USER": settings.get("DB_USER", "postgres"),
"PASSWORD": settings.get("DB_PASSWORD"),
"NAME": settings.get("DB_NAME", "eda"),
}
}


# Password validation
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", # noqa: E501
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", # noqa: E501
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", # noqa: E501
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", # noqa: E501
},
]


# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/

STATIC_URL = "static/"

MEDIA_ROOT = settings.get("MEDIA_ROOT", "/var/lib/eda/files")

# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

AUTH_USER_MODEL = "core.User"

REST_FRAMEWORK = {
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
"DEFAULT_PAGINATION_CLASS": "aap_eda.api.pagination.DefaultPagination", # noqa: E501
"PAGE_SIZE": 20,
"DEFAULT_AUTHENTICATION_CLASSES": [
"rest_framework.authentication.SessionAuthentication",
"rest_framework.authentication.BasicAuthentication",
],
"DEFAULT_PERMISSION_CLASSES": [
"rest_framework.permissions.IsAuthenticated",
],
"TEST_REQUEST_DEFAULT_FORMAT": "json",
}

# ---------------------------------------------------------
# TASKING SETTINGS
# ---------------------------------------------------------
RQ = {
"QUEUE_CLASS": "aap_eda.core.tasking.Queue",
"JOB_CLASS": "aap_eda.core.tasking.Job",
}

RQ_UNIX_SOCKET_PATH = settings.get("MQ_UNIX_SOCKET_PATH", None)

if RQ_UNIX_SOCKET_PATH:
RQ_QUEUES = {
"default": {
"UNIX_SOCKET_PATH": RQ_UNIX_SOCKET_PATH,
},
}
else:
RQ_QUEUES = {
"default": {
"HOST": settings.get("MQ_HOST", "localhost"),
"PORT": settings.get("MQ_PORT", 6379),
}
}
RQ_QUEUES["default"]["DB"] = settings.get("MQ_DB", 0)

# ---------------------------------------------------------
# APPLICATION SETTINGS
# ---------------------------------------------------------

API_PREFIX = settings.get("API_PREFIX", "api/eda").strip("/")

SPECTACULAR_SETTINGS = {
"TITLE": "Event Driven Ansible API",
"VERSION": "1.0.0",
"SERVE_INCLUDE_SCHEMA": False,
"SCHEMA_PATH_PREFIX": f"/{API_PREFIX}/v[0-9]",
"SCHEMA_PATH_PREFIX_TRIM": True,
"SERVERS": [{"url": f"/{API_PREFIX}/v1"}],
"PREPROCESSING_HOOKS": [
"aap_eda.api.openapi.preprocess_filter_api_routes"
],
}

# ---------------------------------------------------------
# LOGGING SETTINGS
# ---------------------------------------------------------

APP_LOG_LEVEL = settings.get("APP_LOG_LEVEL", "INFO")

LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"simple": {
"format": "{asctime} {levelname:<8} {message}",
"style": "{",
},
},
"handlers": {
"console": {"class": "logging.StreamHandler", "formatter": "simple"},
},
"root": {"handlers": ["console"], "level": "WARNING"},
"loggers": {
"django": {
"handlers": ["console"],
"level": "WARNING",
"propagate": False,
},
"django.request": {
"handlers": ["console"],
"level": "INFO",
"propagate": False,
},
"django.channels.server": {
"handlers": ["console"],
"level": "INFO",
"propagate": False,
},
"aap_eda": {
"handlers": ["console"],
"level": APP_LOG_LEVEL,
"propagate": False,
},
},
}
{% for item in extra_settings | default([]) %}
{{ item.setting }} = {{ item.value }}
{% endfor %}
nginx_conf: |
events {
worker_connections 1024;
Expand Down

0 comments on commit 79d7cef

Please sign in to comment.