Skip to content

Commit

Permalink
feat: ui installer
Browse files Browse the repository at this point in the history
Signed-off-by: ashutosh16 <[email protected]>

feat: ui installer

Signed-off-by: ashutosh16 <[email protected]>

feat: ui installer

Signed-off-by: ashutosh16 <[email protected]>
  • Loading branch information
ashutosh16 committed Oct 4, 2024
1 parent 9f4a4bc commit 87f687a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 31 deletions.
48 changes: 27 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,32 @@ and install the configured UI extension. All configuration is provided
as environment variables as part of the init container. Find below the
list of all environment variables that can be configured:

| Env Var | Required? | Default | Description |
|----------------------------|----------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| EXTENSION_NAME | Yes | "" | Extension Name |
| EXTENSION_ENABLED | No | true | If set to false will skip the installation. Noop |
| EXTENSION_URL | Yes | "" | Must be set to a valid URL where the UI extension can be downloaded from. <br>Argo CD API server needs to have network access to this URL. |
| EXTENSION_VERSION | Yes | "" | The version of the extension to be installed. |
| EXTENSION_CHECKSUM_URL | No | "" | Can be set to the file containing the checksum to validate the downloaded<br>extension. Will skip the checksum validation if not provided.<br>Argo CD API server needs to have network access to this URL. |
| MAX_DOWNLOAD_SEC | No | 30 | Total time in seconds allowed to download the extension. |
| EXTENSION_EXT_JS_VARS | No | "" | Export the variables to `extension-$EXTENSION_EXT_JS_VARS` in js file within the extension folder. These variables will be exported as env variables with key `ARGOCD_EXT_VARS`. <br/>The format should be `{key1=value1, key2=value2}`. |
| Env Var | Required? | Default | Description |
|---------------------------|----------|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| EXTENSION_NAME | Yes | "" | Extension Name |
| EXTENSION_ENABLED | No | true | If set to false will skip the installation. Noop |
| EXTENSION_URL | Yes | "" | Must be set to a valid URL where the UI extension can be downloaded from. <br>Argo CD API server needs to have network access to this URL. |
| EXTENSION_VERSION | Yes | "" | The version of the extension to be installed. |
| EXTENSION_CHECKSUM_URL | No | "" | Can be set to the file containing the checksum to validate the downloaded<br>extension. Will skip the checksum validation if not provided.<br>Argo CD API server needs to have network access to this URL. |
| MAX_DOWNLOAD_SEC | No | 30 | Total time in seconds allowed to download the extension. |
| EXTENSION_JS_VARS | No | "" | Export the variables to `extension-$EXTENSION_JS_VARS` in js file within the extension folder. These variables will be exported as env variables with key `${EXTENSION_NAME}_VARS`. <br/>The format should be `{key1=value1, key2=value2}`. |



```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-extension-cm
name: extension-cm
data:
extension.url: 'http://example.com/extension.tar.gz'
extension.version: 'v0.3.1'
# optional fields
extension.name: 'example'
extension.enabled: 'true'
extension.checksum_url: 'http://example.com/extension_checksums.txt'
extension.max_download_sec: '30'
extension.ext_js_vars : |
extension.js_vars : |
{
"key1": "value1",
"key2": "value2"
Expand Down Expand Up @@ -63,23 +64,28 @@ spec:
valueFrom:
configMapKeyRef:
key: extension.name
name: argocd-extension-cm
name: extension-cm
- name: EXTENSION_URL
valueFrom:
configMapKeyRef:
key: extension.url
name: argocd-extension-cm
name: extension-cm
- name: EXTENSION_VERSION
valueFrom:
configMapKeyRef:
key: extension.version
name: argocd-extension-cm
name: extension-cm
- name: EXTENSION_CHECKSUM_URL
valueFrom:
configMapKeyRef:
key: extension.checksum_url
name: extension-cm
## Optional fields
- name: EXTENSION_EXT_JS_VARS
- name: $EXTENSION_JS_VARS
valueFrom:
configMapKeyRef:
key: extension.js_vars
name: argocd-extension-cm
name: extension-cm
volumeMounts:
- name: extensions
mountPath: /tmp/extensions/
Expand All @@ -95,11 +101,11 @@ spec:
### Exporting env as js extensions
Add the below config in the `argocd-extension-cm`:
Add the below config in the `extension-cm`:
```yaml
#name should match with the extension name e.g 'Metrics', 'Rollout', 'EphemeralAccess'
extension.name: 'example'
extension.ext_js_vars : |
extension.js_vars : |
{
"key1": "value1",
"key2": "value2"
Expand All @@ -108,19 +114,19 @@ extension.ext_js_vars : |
Provide the config in argocd-server deployment as below:
```yaml
## Optional fields
- name: EXTENSION_EXT_JS_VARS
- name: $EXTENSION_JS_VARS
valueFrom:
configMapKeyRef:
key: extension.js_vars
name: argocd-extension-cm
name: extension-cm
```
output:
```js
((window) => {
const vars = {
"key1": "value1", "key2": "value2"
};
window.ARGOCD_EXT_VARS = vars;
window.Extension_VARS = vars;
})(window);
```
Exported envirnoment variables available in the widget:
Expand Down
Binary file modified image/exported_envirnoment_variables.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 13 additions & 10 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,18 @@ install_extension() {

create_extension_js_file_with_vars() {
echo "Generating extension vars js file..."
ext_js_file_path="/tmp/extensions/resources/extension-$ext_name.js"
ext_js_file_name="vars-$(date +"%Y%m%d%H%M%S")"
js_file_path="${ext_js_file_path}/extension-${ext_js_file_name}.js"
js_code=$(echo "$ext_vars" | jq -r 'to_entries | map("\"" + .key + "\": \"" + .value + "\"") | join(", ")')
js_code="((window) => {\n const vars = {\n $js_code\n };\n window.ARGOCD_EXT_VARS = vars;\n})(window);"
echo "Exporting extension vars file at $js_file_path"
echo "$js_code" > "$js_file_path"
ext_installed_path="/tmp/extensions/resources/extension-$ext_name.js"
ext_js_file_name="$ext_name-vars"
random_number=$((RANDOM % 10 + 1))
js_file_path="${ext_installed_path}/extension-${random_number}-${ext_js_file_name}.js"
js_variable=$(echo "$ext_vars" | jq -r 'to_entries | map("\"" + .key + "\": \"" + .value + "\"") | join(", ")')
js_vars_wrap="((window) => { const vars = { $js_variable }; window.${ext_name}_VARS = vars; })(window);"
if [ -d "$ext_installed_path" ]; then
echo "Exporting extension vars file at $js_file_path"
echo "$js_vars_wrap" > "$js_file_path"
else
echo "$ext_installed_path path doesn't exist, extension vars failed to be exported "
fi
}

## Script
Expand Down Expand Up @@ -108,9 +113,7 @@ if [ -f $ext_file ]; then
rm $ext_file
fi

ext_vars=$(echo "$EXTENSION_EXT_JS_VARS" | jq -c '.')
ext_js_file_path="${EXTENSION_EXT_JS_FILE_PATH:-}"

ext_vars=$(echo "$EXTENSION_JS_VARS" | jq -c '.')

download_extension
install_extension
Expand Down

0 comments on commit 87f687a

Please sign in to comment.