Skip to content

Commit

Permalink
feat: deploy core apps via argocd (#1630)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Erll <merll@akamai.com>
Co-authored-by: jeho <17126497+j-zimnowoda@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 4, 2024
1 parent ba34f5d commit 98ee9af
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 30 deletions.
4 changes: 3 additions & 1 deletion charts/gitea/templates/gitea/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@ spec:
emptyDir: {}
{{- else if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }}
volumeClaimTemplates:
- metadata:
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data
{{- with .Values.persistence.annotations }}
annotations:
Expand Down
4 changes: 3 additions & 1 deletion charts/harbor/templates/redis/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ spec:
{{- end }}
{{- if and .Values.persistence.enabled (not $redis.existingClaim) }}
volumeClaimTemplates:
- metadata:
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data
labels:
{{ include "harbor.labels" . | indent 8 }}
Expand Down
4 changes: 3 additions & 1 deletion charts/harbor/templates/trivy/trivy-sts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ spec:
{{- end }}
{{- if and .Values.persistence.enabled (not $trivy.existingClaim) }}
volumeClaimTemplates:
- metadata:
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data
labels:
{{ include "harbor.labels" . | indent 8 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,9 @@ spec:
claimName: {{ printf "redis-data-%s-master" (include "common.names.fullname" .) }}
{{- else }}
volumeClaimTemplates:
- metadata:
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: redis-data
labels: {{- include "common.labels.matchLabels" . | nindent 10 }}
app.kubernetes.io/component: master
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,9 @@ spec:
claimName: {{ printf "%s" (tpl .Values.replica.persistence.existingClaim .) }}
{{- else }}
volumeClaimTemplates:
- metadata:
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: redis-data
labels: {{- include "common.labels.matchLabels" . | nindent 10 }}
app.kubernetes.io/component: replica
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,9 @@ spec:
claimName: {{ printf "%s" (tpl .Values.replica.persistence.existingClaim .) }}
{{- else }}
volumeClaimTemplates:
- metadata:
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: redis-data
labels: {{- include "common.labels.matchLabels" . | nindent 10 }}
app.kubernetes.io/component: node
Expand Down
4 changes: 3 additions & 1 deletion charts/otomi-pipelines/templates/eventlistener.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ spec:
triggers:
- name: otomi-tekton-listener
bindings:
- ref: otomi-tekton-binding
- kind: TriggerBinding
ref: otomi-tekton-binding
template:
ref: otomi-tekton-template
resources:
Expand All @@ -18,4 +19,5 @@ spec:
serviceAccountName: otomi-tekton-triggers-sa
containers:
- resources: {{- toYaml .Values.eventListener.resources | nindent 18 }}
name: ''

8 changes: 8 additions & 0 deletions charts/otomi-pipelines/templates/tekton-otomi-git-clone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ metadata:
spec:
params:
- name: repoUrl
type: string
- name: commitMessage
type: string
- name: giteaCredentialsSecretName
type: string
results:
- name: CI
description: Determine if pipeline should run based on the commit message
type: string
- name: OTOMI_VERSION
description: Otomi version as in values/env/settings.yaml
type: string
- name: TRIGGER_TEAMS_PIPELINE
description: Determine if the otomi-task-teams is about to run
type: string
- name: TRIGGER_PLATFORM_PIPELINE
description: Determine if the otomi-task is about to run
type: string
workspaces:
- name: source
mountPath: /home/app/stack/env/
Expand All @@ -28,6 +35,7 @@ spec:
image: otomi/core:{{ .Values.otomiVersion }}
steps:
- name: git-clone
computeResources: {}
script: |
#!/bin/bash
set -e
Expand Down
7 changes: 7 additions & 0 deletions charts/otomi-pipelines/templates/tekton-otomi-task-teams.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ metadata:
spec:
params:
- name: OTOMI_VERSION
type: string
- name: CI
type: string
- name: repoUrl
type: string
- name: giteaCredentialsSecretName
type: string
workspaces:
- name: source
mountPath: /home/app/stack/env
Expand All @@ -37,6 +41,7 @@ spec:
value: '2'
steps:
- name: git-clone
computeResources: {}
script: |
#!/bin/bash
set -e
Expand All @@ -57,12 +62,14 @@ spec:
git clone --depth 1 https://$GITEA_USERNAME:$GITEA_PASSWORD@$url $ENV_DIR
{{- end }}
- name: test
computeResources: {}
command:
- '/bin/bash'
args:
- '-c'
- 'binzx/otomi validate-values'
- name: apply
computeResources: {}
script: |
#!/bin/bash
set -e
Expand Down
8 changes: 8 additions & 0 deletions charts/otomi-pipelines/templates/tekton-otomi-task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ metadata:
spec:
params:
- name: OTOMI_VERSION
type: string
- name: CI
type: string
- name: repoUrl
type: string
- name: giteaCredentialsSecretName
type: string
workspaces:
- name: source
mountPath: /home/app/stack/env
Expand All @@ -37,6 +41,7 @@ spec:
value: '1'
steps:
- name: git-clone
computeResources: {}
script: |
#!/bin/bash
set -e
Expand All @@ -57,18 +62,21 @@ spec:
git clone --depth 1 https://$GITEA_USERNAME:$GITEA_PASSWORD@$url $ENV_DIR
{{- end }}
- name: bootstrap
computeResources: {}
command:
- '/bin/bash'
args:
- '-c'
- 'binzx/otomi bootstrap'
- name: test
computeResources: {}
command:
- '/bin/bash'
args:
- '-c'
- 'binzx/otomi validate-values'
- name: apply
computeResources: {}
script: |
#!/bin/bash
set -e
Expand Down
6 changes: 6 additions & 0 deletions charts/otomi-pipelines/templates/tekton-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ spec:
- name: gitea-credentials
params:
- name: repoUrl
type: string
- name: commitMessage
type: string
- name: giteaCredentialsSecretName
type: string
tasks:
- name: otomi-git-clone
params:
Expand All @@ -21,6 +24,7 @@ spec:
- name: giteaCredentialsSecretName
value: $(params.giteaCredentialsSecretName)
taskRef:
kind: Task
name: otomi-git-clone
workspaces:
- name: source
Expand All @@ -38,6 +42,7 @@ spec:
- name: giteaCredentialsSecretName
value: $(params.giteaCredentialsSecretName)
taskRef:
kind: Task
name: otomi-task
workspaces:
- name: source
Expand All @@ -64,6 +69,7 @@ spec:
- name: giteaCredentialsSecretName
value: $(params.giteaCredentialsSecretName)
taskRef:
kind: Task
name: otomi-task-teams
workspaces:
- name: source
Expand Down
3 changes: 2 additions & 1 deletion charts/tempo/templates/lib/service-monitor.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ spec:
scrapeTimeout: {{ . }}
{{- end }}
relabelings:
- sourceLabels: [job]
- action: replace
sourceLabels: [job]
replacement: "{{ $.ctx.Release.Namespace }}/{{ $.component }}"
targetLabel: job
{{- if kindIs "string" .clusterLabel }}
Expand Down
20 changes: 10 additions & 10 deletions src/cmd/apply-as-apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const setup = (): void => {
mkdirSync(valuesDir, { recursive: true })
}

interface HelmRelese {
interface HelmRelease {
name: string
namespace: string
enabled: boolean
Expand All @@ -38,11 +38,11 @@ interface HelmRelese {
chart: string
version: string
}
const getAppName = (release: HelmRelese): string => {
const getAppName = (release: HelmRelease): string => {
return `${release.namespace}-${release.name}`
}

const getArgocdAppManifest = (release: HelmRelese, values: Record<string, any>, otomiVersion) => {
const getArgocdAppManifest = (release: HelmRelease, values: Record<string, any>, otomiVersion) => {
return {
apiVersion: 'argoproj.io/v1alpha1',
kind: 'Application',
Expand Down Expand Up @@ -80,17 +80,17 @@ const getArgocdAppManifest = (release: HelmRelese, values: Record<string, any>,
}
}

const removeApplication = async (release: HelmRelese): Promise<void> => {
const removeApplication = async (release: HelmRelease): Promise<void> => {
const name = getAppName(release)
if (!(await isResourcePresent('application', name, 'argocd'))) return

// TODO: do we always want to remove finalisers?
// TODO: do we always want to remove finalizers?
await $`kubectl -n argocd patch application ${name} -p '{"metadata": {"finalizers": null}}' --type merge`
const resDelete = await $`kubectl -n argocd delete application ${name}`
d.info(resDelete.stdout.toString())
}

const writeApplicationManifest = async (release: HelmRelese, otomiVersion: string): Promise<void> => {
const writeApplicationManifest = async (release: HelmRelease, otomiVersion: string): Promise<void> => {
const appName = `${release.namespace}-${release.name}`
// d.info(`Generating Argocd Application at ${appName}`)
const applicationPath = `${appsDir}/${appName}.yaml`
Expand Down Expand Up @@ -125,9 +125,9 @@ export const applyAsApps = async (argv: HelmArguments): Promise<void> => {
})
const errors: Array<any> = []
// Generate JSON object with all helmfile releases defined in helmfile.d
const releses: [] = JSON.parse(res.stdout.toString())
const releases: [] = JSON.parse(res.stdout.toString())
await Promise.allSettled(
releses.map(async (release: HelmRelese) => {
releases.map(async (release: HelmRelease) => {
try {
if (release.installed) await writeApplicationManifest(release, otomiVersion)
else {
Expand All @@ -147,10 +147,10 @@ export const applyAsApps = async (argv: HelmArguments): Promise<void> => {
d.error(e)
errors.push(e)
}
if (errors.length === 0) d.info(`All applications has been deployed succesfully`)
if (errors.length === 0) d.info(`All applications has been deployed successfully`)
else {
errors.map((e) => d.error(e))
d.error(`Not all applications has been deployed succesfully`)
d.error(`Not all applications has been deployed successfully`)
}
}

Expand Down
20 changes: 9 additions & 11 deletions src/cmd/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,25 @@ const applyAll = async () => {
// When Otomi is installed for the very first time and ArgoCD is not yet there.
// The 'tag!=teams' does not include team-ns-admin release name.
labelOpts = ['tag!=teams']
await hf(
{
labelOpts,
logLevel: logLevelString(),
args: hfArgs,
},
{ streams: { stdout: d.stream.log, stderr: d.stream.error } },
)
} else {
// When Otomi is already installed and Tekton pipeline performs GitOps.
// We ensure that helmfile does not deploy any team related Helm release.
labelOpts = ['pipeline!=otomi-task-teams']

// We still need to deploy all teams because some settings depend on platform apps.
// Note that team-ns-admin contains ingress for platform apps.
const params = cloneDeep(argv)
params.label = ['pipeline=otomi-task-teams']
//TODO here happens the real installation of the apps
await applyAsApps(params)
}

await hf(
{
labelOpts,
logLevel: logLevelString(),
args: hfArgs,
},
{ streams: { stdout: d.stream.log, stderr: d.stream.error } },
)

await upgrade({ when: 'post' })
if (!(env.isDev && env.DISABLE_SYNC)) {
await commit()
Expand Down
14 changes: 14 additions & 0 deletions values/argocd/argocd.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ configs:
users.anonymous.enabled: "false"
# Note that the clientSecret is not actually used
# as for now oauth2-proxy handles the login
resource.compareoptions: |
# disables status field diffing in specified resource types
ignoreAggregatedRoles: true
resource.exclusions: |
- apiGroups:
- "*"
kinds:
- "PipelineRun"
- "TaskRun"
clusters:
- "*"
resource.customizations.knownTypeFields.cert-manager.io_Certificate: |
- field: spec.duration
type: meta/v1/Duration
oidc.config: |
name: Otomi
issuer: {{ $v._derived.oidcBaseUrl }}
Expand Down
2 changes: 1 addition & 1 deletion values/jaeger-operator/jaeger-operator.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jaeger:
securityContext:
runAsNonRoot: true
runAsUser: 1000
strategy: allInOne
strategy: allinone

rbac:
clusterRole: true
Expand Down

0 comments on commit 98ee9af

Please sign in to comment.