Skip to content

Commit f44cd85

Browse files
committed
refactor with argocd application set
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
1 parent 34bc16b commit f44cd85

File tree

15 files changed

+171
-115
lines changed

15 files changed

+171
-115
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.cache
22
.build
33
.downloads
4+
.DS_Store

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,14 @@
33
GitOps environment repo for OpenSearch and OpenSearch-Dashboards development
44

55
> OpenSearch and OpenSearch-Dashboards helm charts are from the official [helm-charts](https://github.com/opensearch-project/helm-charts)
6+
7+
## Create an OpenSearch cluster
8+
9+
1. fork this repo
10+
2. create a empty folder in `deployments/`, for example `deployments/my-app`, you can name it as you like
11+
3. create a `config.json` file in `my-app` folder, take `deployments/demo` for example
12+
4. update `owner` with your email address in `config.json`, you will be notified on slack once the cluster is created
13+
5. create a pull request with above changes to `main`
14+
6. once the PR is merged, the opensearch cluster will be deployed automatically(default is a 2 nodes opensearch cluster) and you will receive slack notifications about the endpoints
15+
16+
## Customize the deployment

appset/opensearch-appset.yaml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: ApplicationSet
3+
metadata:
4+
name: opensearch
5+
namespace: argocd
6+
spec:
7+
generators:
8+
- matrix:
9+
generators:
10+
- list:
11+
elements:
12+
- appName: opensearch
13+
- appName: opensearch-dashboards
14+
- git:
15+
repoURL: https://github.com/ruanyl/ml-commons-dev-env.git
16+
revision: argocd-appset
17+
files:
18+
- path: "deployments/**/config.json"
19+
20+
template:
21+
metadata:
22+
name: '{{appName}}-{{path.basename}}'
23+
annotations:
24+
owner: '{{owner}}'
25+
notifications.argoproj.io/subscribe.on-deployed.slack_webhook: ""
26+
notifications.argoproj.io/subscribe.on-health-degraded.slack_webhook: ""
27+
notifications.argoproj.io/subscribe.on-sync-failed.slack_webhook: ""
28+
notifications.argoproj.io/subscribe.on-deleted.slack_webhook_deleted: ""
29+
spec:
30+
project: default
31+
source:
32+
repoURL: https://github.com/ruanyl/ml-commons-dev-env.git
33+
targetRevision: argocd-appset
34+
path: "charts/{{appName}}"
35+
plugin:
36+
name: helm-argocd-vault-replacer
37+
env:
38+
- name: VALUE_FILES
39+
value: "../../deployments/{{path.basename}}/{{appName}}.yaml"
40+
destination:
41+
server: "https://kubernetes.default.svc"
42+
namespace: '{{path.basename}}'
43+
syncPolicy:
44+
automated: {}
45+
syncOptions:
46+
- CreateNamespace=true

charts/opensearch-dashboards/plugins/README.md

-35
This file was deleted.

charts/opensearch-dashboards/plugins/artifacts.json

-3
This file was deleted.

charts/opensearch-dashboards/templates/deployment.yaml

+5-7
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,13 @@ spec:
161161
#!/usr/bin/bash
162162
set -e
163163
164-
{{- $artifacts := .Files.Get "plugins/artifacts.json" | fromJson }}
165-
{{- range $plugin := $artifacts.plugins }}
166-
if ./bin/opensearch-dashboards-plugin list | grep -q {{ $plugin.name }}; then
167-
./bin/opensearch-dashboards-plugin remove {{ $plugin.name }}
164+
{{- if .Values.plugins.enabled }}
165+
{{- range $plugin := .Values.plugins.removeList }}
166+
if ./bin/opensearch-dashboards-plugin list | grep -q {{ $plugin }}; then
167+
./bin/opensearch-dashboards-plugin remove {{ $plugin }}
168168
fi
169-
./bin/opensearch-dashboards-plugin install {{ $plugin.url }}
170-
{{- end }}
169+
{{- end }}
171170
172-
{{- if .Values.plugins.enabled }}
173171
{{- range $plugin := .Values.plugins.installList }}
174172
./bin/opensearch-dashboards-plugin install {{ $plugin }}
175173
{{- end }}

charts/opensearch-dashboards/values.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77

88
opensearchHosts: "https://opensearch-cluster-master:9200"
99
replicaCount: 1
10-
global:
10+
# global:
1111
# Set if you want to change the default docker registry, e.g. a private one.
1212
# dockerRegistry: "public.ecr.aws"
13-
dockerRegistry: "public.ecr.aws"
1413
image:
15-
repository: "r9h9r7k4/opensearch-dashboards-dev"
14+
repository: "opensearchproject/opensearch-dashboards"
1615
# override image tag, which is .Chart.AppVersion by default
17-
tag: "7523695040"
16+
tag: ""
1817
pullPolicy: "IfNotPresent"
1918
startupProbe:
2019
tcpSocket:

charts/opensearch/plugins/README.md

-42
This file was deleted.

charts/opensearch/plugins/artifacts.json

-8
This file was deleted.

charts/opensearch/templates/statefulset.yaml

+5-7
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,13 @@ spec:
316316
#!/usr/bin/env bash
317317
set -euo pipefail
318318
319-
{{- $artifacts := .Files.Get "plugins/artifacts.json" | fromJson }}
320-
{{- range $plugin := $artifacts.plugins }}
321-
if ./bin/opensearch-plugin list | grep -q {{ $plugin.name }}; then
322-
./bin/opensearch-plugin remove {{ $plugin.name }}
319+
{{- if .Values.plugins.enabled }}
320+
{{- range $plugin := .Values.plugins.removeList }}
321+
if ./bin/opensearch-plugin list | grep -q {{ $plugin }}; then
322+
./bin/opensearch-plugin remove {{ $plugin }}
323323
fi
324-
./bin/opensearch-plugin install --batch {{ $plugin.url }}
325-
{{- end }}
324+
{{- end }}
326325
327-
{{- if .Values.plugins.enabled }}
328326
{{- range $plugin := .Values.plugins.installList }}
329327
./bin/opensearch-plugin install -b {{ $plugin }}
330328
{{- end }}

charts/opensearch/values.yaml

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ roles:
1717
- remote_cluster_client
1818
replicas: 2
1919
# if not set, falls back to parsing .Values.imageTag, then .Chart.appVersion.
20-
majorVersion: "7"
21-
global:
20+
majorVersion: ""
21+
# global:
2222
# Set if you want to change the default docker registry, e.g. a private one.
2323
# dockerRegistry: "public.ecr.aws"
24-
dockerRegistry: "public.ecr.aws"
2524
# Allows you to add any config files in {{ .Values.opensearchHome }}/config
2625
opensearchHome: /usr/share/opensearch
2726
# such as opensearch.yml and log4j2.properties
@@ -259,9 +258,9 @@ hostAliases: []
259258
# - "bar.local"
260259

261260
image:
262-
repository: "r9h9r7k4/opensearch-dev"
261+
repository: "opensearchproject/opensearch"
263262
# override image tag, which is .Chart.AppVersion by default
264-
tag: "7549061222"
263+
tag: ""
265264
pullPolicy: "IfNotPresent"
266265
podAnnotations: {}
267266
# iam.amazonaws.com/role: es-cluster
@@ -1288,6 +1287,8 @@ sysctlInit:
12881287
## Enable to add 3rd Party / Custom plugins not offered in the default OpenSearch image.
12891288
plugins:
12901289
enabled: false
1290+
removeList: []
1291+
# - opensearch-example-plugin
12911292
installList: []
12921293
# - example-fake-plugin
12931294
sampleData:

deployments/demo/opensearch-dashboards.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
replicaCount: 1
22

3+
image:
4+
tag: "2.11.0"
5+
36
resources:
47
requests:
58
cpu: "1"

deployments/demo/opensearch.yaml

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
replicas: 2
22

33
image:
4-
repository: "r9h9r7k4/opensearch-dev"
5-
# override image tag, which is .Chart.AppVersion by default
6-
tag: "7622430882"
7-
pullPolicy: "IfNotPresent"
4+
tag: "2.11.0"
85

96
opensearchJavaOpts: "-Xmx2G -Xms2G"
107

118
resources:
129
requests:
1310
cpu: "2"
1411
memory: "4Gi"
12+
13+
plugins:
14+
enabled: true
15+
removeList:
16+
- opensearch-ml
17+
installList:
18+
- https://github.com/ruanyl/security.zip

kustomize/argocd/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## ArgoCD notifications setup
2+
1. update config map `argocd-notifications-cm`
3+
```
4+
k apply -f kustomize/argocd/argocd-notifications-cm.yaml
5+
```
6+
7+
2. update ArgoCD application annotations
8+
```
9+
metadata:
10+
annotations:
11+
notifications.argoproj.io/subscribe.on-deployed.slack_webhook: ""
12+
notifications.argoproj.io/subscribe.on-health-degraded.slack_webhook: ""
13+
notifications.argoproj.io/subscribe.on-sync-failed.slack_webhook: ""
14+
notifications.argoproj.io/subscribe.on-deleted.slack_webhook_deleted: ""
15+
```
16+
17+
Then run: `argocd appset create appset/opensearch-appset.yaml --upsert`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: argocd-notifications-cm
5+
namespace: argocd
6+
data:
7+
service.webhook.slack_webhook: |
8+
url: https://hooks.slack.com/workflows/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
9+
headers:
10+
- name: Content-Type
11+
value: application/json
12+
13+
service.webhook.slack_webhook_deleted: |
14+
url: https://hooks.slack.com/workflows/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
15+
headers:
16+
- name: Content-Type
17+
value: application/json
18+
19+
template.send-slack: |
20+
webhook:
21+
slack_webhook:
22+
method: POST
23+
body: |
24+
{
25+
"name": "{{.app.metadata.name}}",
26+
"email": "{{.app.metadata.annotations.owner}}",
27+
"url": "{{index .app.status.summary.externalURLs 0}}",
28+
"syncStatus": "{{.app.status.sync.status}}",
29+
"healthStatus": "{{.app.status.health.status}}",
30+
"operationPhase": "{{.app.status.operationState.phase}}",
31+
"content": "{{.app.status.operationState.message}}"
32+
}
33+
34+
template.send-slack-deleted: |
35+
webhook:
36+
slack_webhook_deleted:
37+
method: POST
38+
body: |
39+
{
40+
"name": "{{.app.metadata.name}}",
41+
"email": "{{.app.metadata.annotations.owner}}",
42+
}
43+
44+
trigger.on-deployed: |
45+
- description: Application is synced and healthy. Triggered once per commit.
46+
oncePer: app.status.operationState.syncResult.revision
47+
send:
48+
- send-slack
49+
when: app.status.operationState.phase in ['Succeeded'] and app.status.health.status
50+
== 'Healthy'
51+
trigger.on-health-degraded: |
52+
- description: Application has degraded
53+
send:
54+
- send-slack
55+
when: app.status.health.status == 'Degraded'
56+
trigger.on-sync-failed: |
57+
- description: Application syncing has failed
58+
send:
59+
- send-slack
60+
when: app.status.operationState.phase in ['Error', 'Failed']
61+
trigger.on-deleted: |
62+
- description: Application is deleted.
63+
oncePer: app.metadata.name
64+
send:
65+
- send-slack-deleted
66+
when: app.metadata.deletionTimestamp != nil

0 commit comments

Comments
 (0)