Skip to content

Commit 890b7f3

Browse files
feat: only deploy gitops essential apps on initial install (#1690)
Co-authored-by: jeho <[email protected]>
1 parent 3539829 commit 890b7f3

21 files changed

+104
-18
lines changed

.env.sample

+6
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ AWS_SECRET_ACCESS_KEY=''
2222

2323

2424
OTOMI_CHARTS_URL='https://github.com/linode/apl-charts.git'
25+
26+
27+
RETRIES=6
28+
RANDOM=false
29+
MIN_TIMEOUT=10000
30+
FACTOR=1

charts/otomi-pipelines/templates/tekton-otomi-git-clone.yaml

+8-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ spec:
5959
6060
# Cloning the values
6161
{{- if .Values.cloneUnsecure }}
62-
git clone -c http.sslVerify=false --depth 2 https://$GITEA_USERNAME:$GITEA_PASSWORD@$url
62+
git clone -c http.sslVerify=false --depth 2 http://$GITEA_USERNAME:$GITEA_PASSWORD@$url
6363
{{- else }}
6464
git clone --depth 2 https://$GITEA_USERNAME:$GITEA_PASSWORD@$url
6565
{{- end }}
@@ -82,5 +82,12 @@ spec:
8282
if git diff --name-only HEAD~1 | grep -v "env/teams/"; then
8383
echo -n "1" > $(results.TRIGGER_PLATFORM_PIPELINE.path)
8484
fi
85+
86+
# Allows to trigger pipeline without making any change in the values repo
87+
if [[ ! $COMMIT_MESSAGE == "[apl-trigger]" ]]; then
88+
echo -n "1" > $(results.TRIGGER_PLATFORM_PIPELINE.path)
89+
echo -n "1" > $(results.TRIGGER_TEAMS_PIPELINE.path)
90+
fi
91+
8592
args:
8693
- '$(params["commitMessage"])'

charts/otomi-pipelines/templates/tekton-otomi-task-teams.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ spec:
5757
5858
# Cloning the values
5959
{{- if .Values.cloneUnsecure }}
60-
git clone -c http.sslVerify=false --depth 1 https://$GITEA_USERNAME:$GITEA_PASSWORD@$url $ENV_DIR
60+
git clone -c http.sslVerify=false --depth 1 http://$GITEA_USERNAME:$GITEA_PASSWORD@$url $ENV_DIR
6161
{{- else}}
6262
git clone --depth 1 https://$GITEA_USERNAME:$GITEA_PASSWORD@$url $ENV_DIR
6363
{{- end }}

charts/otomi-pipelines/templates/tekton-otomi-task.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ spec:
5757
5858
# Cloning the values
5959
{{- if .Values.cloneUnsecure }}
60-
git clone -c http.sslVerify=false --depth 1 https://$GITEA_USERNAME:$GITEA_PASSWORD@$url $ENV_DIR
60+
git clone -c http.sslVerify=false --depth 1 http://$GITEA_USERNAME:$GITEA_PASSWORD@$url $ENV_DIR
6161
{{- else}}
6262
git clone --depth 1 https://$GITEA_USERNAME:$GITEA_PASSWORD@$url $ENV_DIR
6363
{{- end }}

charts/otomi-pipelines/templates/tekton-pipeline.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ spec:
1818
- name: otomi-git-clone
1919
params:
2020
- name: repoUrl
21-
value: '$(params.repoUrl)'
21+
value: 'gitea-http.gitea.svc.cluster.local:3000/otomi/values.git/'
2222
- name: commitMessage
2323
value: '$(params.commitMessage)'
2424
- name: giteaCredentialsSecretName
@@ -34,7 +34,7 @@ spec:
3434
- name: otomi-task
3535
params:
3636
- name: repoUrl
37-
value: '$(params.repoUrl)'
37+
value: 'gitea-http.gitea.svc.cluster.local:3000/otomi/values.git/'
3838
- name: OTOMI_VERSION
3939
value: $(tasks.otomi-git-clone.results.OTOMI_VERSION)
4040
- name: CI
@@ -61,7 +61,7 @@ spec:
6161
- name: otomi-task-teams
6262
params:
6363
- name: repoUrl
64-
value: '$(params.repoUrl)'
64+
value: 'gitea-http.gitea.svc.cluster.local:3000/otomi/values.git/'
6565
- name: OTOMI_VERSION
6666
value: $(tasks.otomi-git-clone.results.OTOMI_VERSION)
6767
- name: CI

helmfile.d/helmfile-02.init.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ releases:
4444
namespace: cnpg-system
4545
labels:
4646
pkg: cloudnative-pg
47+
app: core
4748
<<: *default

helmfile.d/helmfile-03.init.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ releases:
1515
- name: argocd
1616
installed: {{ $a | get "argocd.enabled" }}
1717
namespace: argocd
18+
labels:
19+
app: core
1820
<<: *default
1921
- name: otomi-operator
2022
installed: true
@@ -39,18 +41,21 @@ releases:
3941
namespace: gitea
4042
labels:
4143
pkg: gitea
44+
app: core
4245
<<: *raw
4346
- name: apl-gitea-operator-artifacts
4447
installed: {{ $a | get "gitea.enabled" }}
4548
namespace: apl-gitea-operator
4649
labels:
4750
pkg: apl-gitea-operator
51+
app: core
4852
<<: *raw
4953
- name: apl-gitea-operator
5054
installed: {{ $a | get "gitea.enabled" }}
5155
namespace: apl-gitea-operator
5256
labels:
5357
pkg: apl-gitea-operator
58+
app: core
5459
<<: *default
5560
- name: apl-harbor-operator-artifacts
5661
installed: {{ $a | get "harbor.enabled" }}
@@ -106,12 +111,14 @@ releases:
106111
namespace: tekton-pipelines
107112
labels:
108113
pkg: tekton-pipelines
114+
app: core
109115
<<: *default
110116
- name: tekton-dashboard
111117
installed: true
112118
namespace: tekton-pipelines
113119
labels:
114120
pkg: tekton-pipelines
121+
app: core
115122
chart: ../charts/tekton-dashboard
116123
values:
117124
- ../values/tekton-dashboard/tekton-dashboard.gotmpl

helmfile.d/helmfile-04.databases.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ releases:
3131
namespace: gitea
3232
labels:
3333
pkg: gitea
34+
app: core
3435
<<: *otomiDb

helmfile.d/helmfile-05.init.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ releases:
1717
namespace: argocd
1818
labels:
1919
pkg: argocd
20+
app: core
2021
<<: *raw
2122
- name: istio-operator
2223
installed: true
2324
namespace: istio-operator
2425
labels:
2526
pkg: istio
27+
app: core
2628
<<: *default
2729
- name: keycloak-artifacts
2830
installed: true

helmfile.d/helmfile-06.init.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ releases:
2929
namespace: istio-operator
3030
labels:
3131
pkg: istio
32+
app: core
3233
chart: ../charts/raw
3334
values:
3435
- ../values/istio-operator/istio-operator-raw.gotmpl

helmfile.d/helmfile-09.init.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ releases:
5151
namespace: tekton-pipelines
5252
labels:
5353
pkg: tekton-triggers
54+
app: core
5455
<<: *default
5556
- name: otomi-pipelines
5657
installed: true
5758
namespace: otomi-pipelines
59+
labels:
60+
app: core
5861
<<: *default

helmfile.d/helmfile-50.services.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ releases:
2121
namespace: gitea
2222
labels:
2323
pkg: gitea
24+
app: core
2425
<<: *default
2526
- name: velero
2627
installed: {{ $a | get "velero.enabled" }}

helmfile.d/helmfile-70.shared.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ releases:
4848
labels:
4949
tag: ingress
5050
pkg: oauth2-proxy
51+
app: core
5152
<<: *raw
5253
- name: otomi-api
5354
installed: true

helmfile.d/helmfile-90.artifacts.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ releases:
1717
namespace: istio-system
1818
labels:
1919
pkg: istio
20+
app: core
2021
chart: ../charts/raw
2122
values:
2223
- ../values/raw/istio-raw.gotmpl

helmfile.d/helmfile-91.artifacts.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ releases:
1717
namespace: istio-system
1818
labels:
1919
pkg: istio
20+
app: core
2021
<<: *raw

src/cmd/apply-as-apps.ts

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ const getArgocdAppManifest = (release: HelmRelease, values: Record<string, any>,
5252
'otomi.io/app': 'managed',
5353
},
5454
namespace: 'argocd',
55+
annotations: ['tempo', 'thanos'].includes(release.name)
56+
? {
57+
'argocd.argoproj.io/compare-options': 'ServerSideDiff=true,IncludeMutationWebhook=true',
58+
}
59+
: {},
5560
},
5661
spec: {
5762
syncPolicy: {

src/cmd/apply.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { ProcessOutputTrimmed } from 'src/common/zx-enhance'
1414
import { Argv, CommandModule } from 'yargs'
1515
import { $, nothrow } from 'zx'
1616
import { applyAsApps } from './apply-as-apps'
17-
import { cloneOtomiChartsInGitea, commit, printWelcomeMessage } from './commit'
17+
import { cloneOtomiChartsInGitea, commit, printWelcomeMessage, retryCheckingForPipelinerun } from './commit'
1818
import { upgrade } from './upgrade'
1919

2020
const cmdName = getFilename(__filename)
@@ -85,8 +85,8 @@ const applyAll = async () => {
8585
let labelOpts = ['']
8686
if (intitalInstall) {
8787
// When Otomi is installed for the very first time and ArgoCD is not yet there.
88-
// The 'tag!=teams' does not include team-ns-admin release name.
89-
labelOpts = ['tag!=teams']
88+
// Only install the core apps
89+
labelOpts = ['app=core']
9090
await hf(
9191
{
9292
labelOpts,
@@ -120,6 +120,7 @@ const applyAll = async () => {
120120
{ streams: { stdout: d.stream.log, stderr: d.stream.error } },
121121
)
122122
await cloneOtomiChartsInGitea()
123+
await retryCheckingForPipelinerun()
123124
await printWelcomeMessage()
124125
}
125126
}

src/cmd/commit.ts

+48-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { Argv } from 'yargs'
1212
import { $, cd } from 'zx'
1313
import { Arguments as DroneArgs } from './gen-drone'
1414
import { validateValues } from './validate-values'
15+
import { CustomObjectsApi, KubeConfig } from '@kubernetes/client-node'
16+
import retry from 'async-retry'
1517

1618
const cmdName = getFilename(__filename)
1719

@@ -104,17 +106,57 @@ export const cloneOtomiChartsInGitea = async (): Promise<void> => {
104106
d.info('Cloned apl-charts in Gitea')
105107
}
106108

109+
export async function retryCheckingForPipelinerun() {
110+
const d = terminal(`cmd:${cmdName}:apply`)
111+
await retry(
112+
async () => {
113+
await checkIfPipelineRunExists()
114+
},
115+
{ retries: env.RETRIES, randomize: env.RANDOM, minTimeout: env.MIN_TIMEOUT, factor: env.FACTOR },
116+
).catch((e) => {
117+
d.error('Error retrieving PipelineRuns:', e)
118+
throw e
119+
})
120+
}
121+
122+
export async function checkIfPipelineRunExists(): Promise<void> {
123+
const d = terminal(`cmd:${cmdName}:pipelinerun`)
124+
const kc = new KubeConfig()
125+
kc.loadFromDefault()
126+
const customObjectsApi = kc.makeApiClient(CustomObjectsApi)
127+
128+
const response = await customObjectsApi.listNamespacedCustomObject(
129+
'tekton.dev',
130+
'v1beta1',
131+
'otomi-pipelines',
132+
'pipelineruns',
133+
)
134+
135+
const pipelineRuns = (response.body as { items: any[] }).items
136+
if (pipelineRuns.length === 0) {
137+
d.info(`No Tekton pipeline runs found, triggering a new one...`)
138+
await $`git commit --allow-empty -m "[apl-trigger]"`
139+
await $`git push`
140+
throw new Error('PipelineRun not found in otomi-pipelines namespace')
141+
}
142+
d.info(`There is a Tekton PipelineRuns continuing...`)
143+
}
144+
107145
export const printWelcomeMessage = async (): Promise<void> => {
108146
const d = terminal(`cmd:${cmdName}:commit`)
109147
const values = (await hfValues()) as Record<string, any>
110148
const credentials = values.apps.keycloak
111149
const message = `
112-
########################################################################################################################################
113-
#
114-
# To start using APL, go to https://console.${values.cluster.domainSuffix} and sign in to the web console
115-
# with username "${credentials.adminUsername}" and password "${credentials.adminPassword}".
116-
#
117-
########################################################################################################################################`
150+
########################################################################################################################################
151+
#
152+
# Core apps installation complete! ArgoCD will now deploy the remaining applications.
153+
# To monitor the progress, run: kubectl get applications -A
154+
# Once ArgoCD finishes, you can start using APL. Visit: https://console.${values.cluster.domainSuffix}
155+
# Sign in to the web console with the following credentials:
156+
# - Username: "${credentials.adminUsername}"
157+
# - Password: "${credentials.adminPassword}"
158+
#
159+
########################################################################################################################################`
118160
d.info(message)
119161
}
120162

src/common/envalid.ts

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export const cliEnvSpec = {
3737
TRACE: bool({ default: false }),
3838
VERBOSITY: num({ desc: 'The verbosity level', default: 1 }),
3939
VALUES_INPUT: str({ desc: 'The chart values.yaml file', default: undefined }),
40+
RETRIES: num({ desc: 'The maximum amount of times to retry the operation by the reconciler', default: 6 }),
41+
RANDOM: bool({ desc: 'Randomizes the timeouts by multiplying with a factor between 1 to 2', default: false }),
42+
MIN_TIMEOUT: num({ desc: 'The number of milliseconds before starting the first retry', default: 10000 }),
43+
FACTOR: num({ desc: 'The factor to multiply the timeout with', default: 1 }),
4044
}
4145

4246
export function cleanEnv<T>(

values/argocd/argocd.gotmpl

+4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ configs:
9999
oidc.clientSecret: {{ $k.idp.clientSecret }}
100100
params:
101101
server.insecure: true # nginx terminates tls
102+
# -- Number of application status processors
103+
controller.status.processors: 10
104+
# -- Number of application operation processors
105+
controller.operation.processors: 5
102106

103107
rbac:
104108
policy.csv: |

values/otomi-pipelines/otomi-pipelines.gotmpl

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@ kms: {{- $kms | toYaml | nindent 2 }}
88
giteaPassword: {{ $g.adminPassword }}
99
otomiVersion: {{ $v.otomi.version }}
1010

11-
{{- if $v._derived.untrustedCA }}
12-
cloneUnsecure: true
13-
{{- end }}
11+
cloneUnsecure: true

0 commit comments

Comments
 (0)