-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the elasticsearch helm chart for cluster-level ES
- Loading branch information
Showing
14 changed files
with
224 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ infra-*/.terraform* | |
infra-*/secrets.auto.tfvars | ||
my-notes | ||
values.yaml | ||
tutor-multi-chart/charts/*.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
tutor-contrib-multi-plugin/tutor_multi_k8s_plugin/commands.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
|
||
import click | ||
from tutor import config as tutor_config | ||
from tutor import env as tutor_env | ||
from tutor.commands.k8s import K8sContext, kubectl_exec | ||
from .elasticsearch import ElasticSearchAPI | ||
|
||
@click.group(help="Commands and subcommands of the openedx-k8s-harmony.") | ||
@click.pass_context | ||
def harmony(context: click.Context) -> None: | ||
context.obj = K8sContext(context.obj.root) | ||
|
||
|
||
@click.command(help="Create or update Elasticsearch users") | ||
@click.pass_obj | ||
def create_elasticsearch_user(context: click.Context): | ||
""" | ||
Creates or updates the Elasticsearch user | ||
""" | ||
config = tutor_config.load(context.root) | ||
namespace = config["K8S_HARMONY_NAMESPACE"] | ||
api = ElasticSearchAPI(namespace) | ||
username, password = config["ELASTICSEARCH_HTTP_AUTH"].split(":", 1) | ||
role_name = f"{username}_role" | ||
|
||
prefix = config["ELASTICSEARCH_INDEX_PREFIX"] | ||
api.post( | ||
f"_security/role/{role_name}", | ||
{"indices": [{"names": [f"{prefix}*"], "privileges": ["all"]}]}, | ||
) | ||
|
||
api.post( | ||
f"_security/user/{username}", | ||
{ | ||
"password": password, | ||
"enabled": True, | ||
"roles": [role_name], | ||
"full_name": username, | ||
}, | ||
) | ||
|
||
|
||
harmony.add_command(create_elasticsearch_user) |
42 changes: 42 additions & 0 deletions
42
tutor-contrib-multi-plugin/tutor_multi_k8s_plugin/elasticsearch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import json | ||
from tutor import utils | ||
|
||
class ElasticSearchAPI: | ||
def __init__(self, namespace): | ||
self._command_base = [ | ||
"kubectl", | ||
"exec", | ||
"--stdin", | ||
"--tty", | ||
"--namespace", | ||
namespace, | ||
"elasticsearch-master-0", | ||
"--", | ||
"bash", | ||
"-c", | ||
] | ||
self._curl_base = ["curl", "--insecure", "-u", "elastic:${ELASTIC_PASSWORD}"] | ||
|
||
def run_command(self, curl_options): | ||
response = utils.check_output( | ||
*self._command_base, " ".join(self._curl_base + curl_options) | ||
) | ||
try: | ||
return json.loads(response) | ||
except (TypeError, ValueError) as e: | ||
return response | ||
|
||
def get(self, url): | ||
return self.run_command(["-XGET", f"https://localhost:9200/{url}"]) | ||
|
||
def post(self, endpoint, data): | ||
return self.run_command( | ||
[ | ||
"-XPOST", | ||
f"https://localhost:9200/{endpoint}", | ||
"-d", | ||
f"'{json.dumps(data)}'", | ||
"-H", | ||
'"Content-Type: application/json"', | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tutor-contrib-multi-plugin/tutor_multi_k8s_plugin/patches/openedx-common-settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{% if K8S_HARMONY_ENABLE_SHARED_ELASTICSEARCH %} | ||
ELASTICSEARCH_INDEX_PREFIX = "{{ELASTICSEARCH_INDEX_PREFIX}}" | ||
ELASTIC_SEARCH_CONFIG = [{ | ||
"use_ssl": True, | ||
"host": "elasticsearch-master.{{K8S_HARMONY_NAMESPACE}}.svc.cluster.local", | ||
"verify_certs": False, | ||
"port": 9200, | ||
"http_auth": "{{ ELASTICSEARCH_HTTP_AUTH }}" | ||
}] | ||
{% endif %} |
7 changes: 7 additions & 0 deletions
7
...b-multi-plugin/tutor_multi_k8s_plugin/patches/openedx-dockerfile-post-python-requirements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% if K8S_HARMONY_ENABLE_SHARED_ELASTICSEARCH %} | ||
# This is needed otherwise the previously installed edx-search | ||
# package doesn't get replaced. Once the below branch is merged | ||
# upstream it will no longer be needed. | ||
RUN pip uninstall -y edx-search | ||
RUN pip install --upgrade git+https://github.com/open-craft/edx-search.git@keith/prefixed-index-names | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
{{- $ca := genCA "elasticca" 1825 }} | ||
{{- $cert := genSignedCert "elasticsearch-master.{{ Release.Namespace }}.local" nil (list "elasticsearch-master.{{ Release.Namespace }}.local") 1825 $ca }} | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: elasticsearch-certificates | ||
type: Opaque | ||
data: | ||
"ca.crt": {{ $ca.Cert | b64enc | toYaml | indent 4}} | ||
"tls.key": {{ $cert.Key | b64enc | toYaml | indent 4}} | ||
"tls.crt": {{ print $cert.Cert $ca.Cert | b64enc | toYaml | indent 4}} | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: elasticsearch-credentials | ||
type: Opaque | ||
data: | ||
"password": {{ randAlphaNum 32 | b64enc | quote }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,6 @@ ingress-nginx: | |
cert-manager: | ||
# Set your email address here so auto-generated HTTPS certs will work: | ||
email: "[email protected]" | ||
|
||
elasticsearch: | ||
enabled: false |