Skip to content

Commit

Permalink
chore: added changes requested from review
Browse files Browse the repository at this point in the history
  • Loading branch information
keithgg committed Feb 26, 2023
1 parent b8e4cbe commit 4440ccf
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,15 @@ K8S_HARMONY_ENABLE_SHARED_ELASTICSEARCH: true
RUN_ELASTICSEARCH: false
```
- And create the user on the cluster with `k8s harmony create-elasticsearch-user`.
- And create the user on the cluster with `tutor k8s harmony create-elasticsearch-user`.
- Rebuild your Open edX image `tutor images build openedx`.
- Finally, redeploy your changes: `tutor k8s start && tutor k8s init`.

#### Caveats

- In order for SSL to work without warnings the CA certificate needs to be mounted in the relevant pods. This is out of scope for this PR as it needs to be an instance level change, which requires more work than intended.
- It's not possible to mount the CA certificate for the forum due to an [outstanding issue in tutor](https://github.com/overhangio/tutor/issues/791).

## Appendix : how to uninstall this chart

Just run `helm uninstall --namespace tutor-multi tutor-multi` to uninstall this.
Expand Down
38 changes: 33 additions & 5 deletions tutor-contrib-multi-plugin/tutor_multi_k8s_plugin/elasticsearch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import json
import typing

from tutor import utils


class ElasticSearchAPI:
"""
Helper class to interact with the ElasticSearch
API on the deployed cluster.
"""

def __init__(self, namespace):
self._command_base = [
"kubectl",
Expand All @@ -17,19 +25,39 @@ def __init__(self, namespace):
]
self._curl_base = ["curl", "--insecure", "-u", "elastic:${ELASTIC_PASSWORD}"]

def run_command(self, curl_options):
def run_command(self, curl_options) -> typing.Union[dict, bytes]:
"""
Invokes a curl command on the first Elasticsearch pod.
If possible returns the parsed json from the Elasticsearch response.
Otherwise, the raw bytes from the curl command are returned.
"""
response = utils.check_output(
*self._command_base, " ".join(self._curl_base + curl_options)
)
try:
return json.loads(response)
except (TypeError, ValueError) as e:
except (TypeError, ValueError):
return response

def get(self, url):
return self.run_command(["-XGET", f"https://localhost:9200/{url}"])
def get(self, endpoint):
"""
Runs a GET request on the Elasticsearch cluster with the specified
endpoint.
If possible returns the parsed json from the Elasticsearch response.
Otherwise, the raw bytes from the curl command are returned.
"""
return self.run_command(["-XGET", f"https://localhost:9200/{endpoint}"])

def post(self, endpoint: str, data: dict) -> typing.Union[dict, bytes]:
"""
Runs a POST request on the Elasticsearch cluster with the specified
endpoint.
def post(self, endpoint, data):
If possible returns the parsed json from the Elasticsearch response.
Otherwise, the raw bytes from the curl command are returned.
"""
return self.run_command(
[
"-XPOST",
Expand Down
10 changes: 4 additions & 6 deletions tutor-contrib-multi-plugin/tutor_multi_k8s_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# when installing additional plugins such as tutor-ecommerce or tutor-minio.
# The workaround is to manually add a list of hosts to be routed to the caddy
# instance.
"INGRESS_HOST_LIST": [ ]
"INGRESS_HOST_LIST": [],
},
"overrides": {
# Don't use Caddy as a per-instance external web proxy, but do still use it
Expand All @@ -31,8 +31,8 @@
},
"unique": {
"ELASTICSEARCH_HTTP_AUTH": "{{K8S_NAMESPACE}}:{{ 24|random_string }}",
"ELASTICSEARCH_INDEX_PREFIX": "{{K8S_NAMESPACE}}-{{ 4|random_string }}",
}
"ELASTICSEARCH_INDEX_PREFIX": "{{K8S_NAMESPACE}}-{{ 4|random_string }}-",
},
}

# Load all configuration entries
Expand All @@ -41,9 +41,7 @@
)

hooks.Filters.CONFIG_OVERRIDES.add_items(list(config["overrides"].items()))
hooks.Filters.CONFIG_UNIQUE.add_items(
list(config["unique"].items())
)
hooks.Filters.CONFIG_UNIQUE.add_items(list(config["unique"].items()))

# Load all patches from the "patches" folder
for path in glob(
Expand Down
4 changes: 2 additions & 2 deletions tutor-multi-chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ elasticsearch:
# MULTI_K8S_USE_SHARED_ELASTICSEARCH: true
# ELASTICSEARCH_AUTH: "username:actual_password"

# The chart will handle certificate creation so that the CA can be used
# in other pods/namespaces.
# We will create the relevant certs, because they need to shared
# with pods in other namespaces.
createCert: false
# Authentication is only available in https
protocol: https
Expand Down

0 comments on commit 4440ccf

Please sign in to comment.