Skip to content

Commit 0f29e9f

Browse files
authored
from markphillips100 with my change on gitops_event_handler.py (#78)
1 parent 45a3ec2 commit 0f29e9f

30 files changed

Lines changed: 1178 additions & 339 deletions

gitopsconfig.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: example.com/v1
2+
kind: GitOpsConfig
3+
metadata:
4+
name: ezievent-identityservice-gitops-stage-dev
5+
spec:
6+
gitRepositoryType: "AZDO"
7+
ciCdOrchestratorType: "AZDO"
8+
gitOpsOperatorType: "ARGOCD"
9+
gitOpsAppURL: "https://dev.azure.com/ezievent/EziEvent/_git/ezievent-identityservice-gitops"
10+
azdoGitOpsRepoName: "ezievent-identityservice-gitops"
11+
azdoPrRepoName: "ezievent-identityservice-gitops"
12+
azdoOrgUrl: "https://dev.azure.com/ezievent/EziEvent"

manifests/helm/README.md

Lines changed: 173 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,173 @@
1-
GitOps connector Helm Chart template.
1+
# gitops-connector
2+
3+
GitOps Connector integrates a GitOps operator with CI/CD orchestrator
4+
5+
## Source Code
6+
7+
* <https://github.com/azure/gitops-connector>
8+
9+
## Installation
10+
11+
### Install GitOps Connector with Helm
12+
13+
Prepare **values.yaml** file and run the following command:
14+
15+
```console
16+
helm repo add gitops-connector https://azure.github.io/gitops-connector
17+
helm upgrade gitops-connector gitops-connector \
18+
--install \
19+
--namespace gitops-connector \
20+
--values values.yaml
21+
```
22+
23+
## Values
24+
25+
### Single Instance vs Multiple Instances
26+
27+
The gitops-connector supports operation in two different modes; Single Instance and Multiple Instances.
28+
29+
### Single Instance Configuration
30+
31+
This behaves in the same way as the original. Configuration is for one combination of gitops operator, respository and orchestrator, and config data is supplied via helm chart values as shown below.
32+
33+
| Key | Type | Default | Description |
34+
|-----|------|---------|-------------|
35+
| singleInstance.gitRepositoryType | string | `""` | Git Repository Type (`AZDO` or `GITHUB`) |
36+
| singleInstance.ciCdOrchestratorType | string | `""` | CI/CD Orchestrator Type (`AZDO` or `GITHUB`) |
37+
| singleInstance.gitOpsOperatorType | string | `""` | GitOps Operator Type (`FLUX` or `ARGOCD`) |
38+
| singleInstance.gitOpsAppURL | string | `""` | Call back URL from the Commit Status Window e.g. `https://github.com/kaizentm/gitops-manifests/commit; https://github.com/microsoft/spektate` |
39+
| singleInstance.azdoGitOpsRepoName | string | `""` | Azure DevOps Mainifests repository name. Required if `gitRepositoryType` is `AZDO` |
40+
| singleInstance.azdoOrgUrl | string | `""` | Azure DevOps Organization URL. Required if `gitRepositoryType` or `ciCdOrchestratorType` is `AZDO`. e.g. `https://dev.azure.com/organization/project` |
41+
| singleInstance.azdoPrRepoName | string | `""` | If `ciCdOrchestratorType` is `AZDO` and when PRs are not issued to the manifests repo, but to a separate HLD repo. Optional. |
42+
| singleInstance.gitHubGitOpsManifestsRepoName | string | `""` | GitHub Mainifests repository name. Required if `gitRepositoryType` is `GITHUB` |
43+
| singleInstance.gitHubOrgUrl | string | `""` | GitHub Organization URL. Required if `gitRepositoryType` or `ciCdOrchestratorType` is `GITHUB`. e.g. `https://api.github.com/owner/repo` |
44+
| singleInstance.gitHubGitOpsRepoName | string | `""` | GitHub Actions repository name. Required if `ciCdOrchestratorType` is `GITHUB` |
45+
| singleInstance.subscribers | object | `{}` | Optional list of subscriber endpoints to send raw JSON to |
46+
47+
### Multiple Instances Configuration
48+
49+
Setting `singleInstance: null` in the helm chart's values file deploys a CRD for `gitopsconfig` resources and informs the gitops-connector to watch for these to automatically configure named instances of each combination of supported operator, repository and orchestrator.
50+
51+
Each alert (Flux) or notification (ArgoCD) must send a `gitops_connector_config_name` property with a value that matches a named configuration defined by a gitsopsconfig manifest. See her for an example of a manifest:
52+
53+
```
54+
apiVersion: example.com/v1
55+
kind: GitOpsConfig
56+
metadata:
57+
name: my-gitops-repo-stage-dev
58+
spec:
59+
gitRepositoryType: "AZDO"
60+
ciCdOrchestratorType: "AZDO"
61+
gitOpsOperatorType: "ARGOCD"
62+
gitOpsAppURL: "https://dev.azure.com/myorg/MyProject/_git/my-gitops-repo"
63+
azdoGitOpsRepoName: "my-gitops-repo"
64+
azdoPrRepoName: "my-gitops-repo"
65+
azdoOrgUrl: "https://dev.azure.com/myorg/MyProject"
66+
```
67+
68+
For this configuration to be used for processing a message from a gitop operator, setup the required Alert or Notification as follows.
69+
70+
#### ArgoCD Notifications Setup
71+
```
72+
data:
73+
trigger.sync-operation-status: |
74+
- when: app.status.operationState.phase in ['Error', 'Failed']
75+
send: [sync-operation-status-change]
76+
- when: app.status.operationState.phase in ['Succeeded']
77+
send: [sync-operation-status-change]
78+
- when: app.status.operationState.phase in ['Running']
79+
send: [sync-operation-status-change]
80+
- when: app.status.health.status in ['Progressing']
81+
send: [sync-operation-status-change]
82+
- when: app.status.health.status in ['Healthy'] && app.status.operationState.phase in ['Succeeded']
83+
send: [sync-operation-status-change]
84+
- when: app.status.health.status in ['Unknown', 'Suspended', 'Degraded', 'Missing', 'Healthy']
85+
send: [sync-operation-status-change]
86+
service.webhook.gitops-connector: |
87+
url: http://gitops-connector.gitops:8080/gitopsphase
88+
headers:
89+
- name: Content-Type
90+
value: application/json
91+
template.sync-operation-status-change: |
92+
webhook:
93+
gitops-connector:
94+
method: POST
95+
body: |
96+
{
97+
"commitid": "{{.app.status.operationState.operation.sync.revision}}",
98+
"phase": "{{.app.status.operationState.phase}}",
99+
"sync_status": "{{.app.status.sync.status}}",
100+
"health": "{{.app.status.health.status}}",
101+
"message": "{{.app.status.operationState.message}}",
102+
"resources": {{toJson .app.status.resources}},
103+
"gitops_connector_config_name": "{{ index .app.metadata.annotations "gitops-connector-config-name" }}"
104+
}
105+
```
106+
107+
This config expects the monitored Application manifest to have an annotation of `gitops-connector-config-name` set with the value of the named configuration that should handle the notifications.
108+
109+
#### FluxV2 Alert Setup
110+
```
111+
apiVersion: notification.toolkit.fluxcd.io/v1beta2
112+
kind: Provider
113+
metadata:
114+
name: my-gitops-repo-connector
115+
namespace: flux-system
116+
spec:
117+
type: generic
118+
address: http://gitops-connector:8080/gitopsphase
119+
120+
apiVersion: notification.toolkit.fluxcd.io/v1beta2
121+
kind: Alert
122+
metadata:
123+
name: my-gitops-repo-connector
124+
namespace: flux-system
125+
spec:
126+
eventMetadata:
127+
gitops_connector_config_name: my-gitops-repo-stage-dev
128+
eventSeverity: info
129+
providerRef:
130+
name: my-gitops-repo-connector
131+
eventSources:
132+
- kind: GitRepository
133+
name: my-gitops-repo-source
134+
- kind: Kustomization
135+
name: my-gitops-repo-kustomization
136+
```
137+
138+
### Common
139+
140+
| Key | Type | Default | Description |
141+
|-----|------|---------|-------------|
142+
| orchestratorPAT | string | `""` | GitHub or Azure DevOps personal access token |
143+
| nameOverride | string | `""` | Partially override resource names (adds suffix) |
144+
| fullnameOverride | string | `""` | Fully override resource names |
145+
| extraObjects | tpl/list | `[]` | Array of extra objects to deploy with the release |
146+
147+
### Parameters
148+
149+
| Key | Type | Default | Description |
150+
|-----|------|---------|-------------|
151+
| image.repository | string | `"ghcr.io/azure/gitops-connector"` | Image repository |
152+
| image.pullPolicy | string | `"IfNotPresent"` | Image pull policy |
153+
| image.tag | string | `""` | Overrides the image tag whose default is the chart appVersion |
154+
| imagePullSecrets | list | `[]` | Image pull secrets |
155+
| env | tpl/list | `[]` | Additional environment variables |
156+
| envFrom | tpl/list | `[]` | Additional environment variables from a secret or configMap |
157+
| resources | object | `{}` | Container Resources requests and limits |
158+
| securityContext | object | `{}` | Container Security Context |
159+
| podAnnotations | tpl/object | `{}` | Additional annotations for pod |
160+
| podLabels | tpl/object | `{}` | Additional labels for pod |
161+
| podSecurityContext | object | `{}` | Pod Security Context |
162+
| affinity | object | `{}` | Pod Affinity configuration |
163+
| nodeSelector | object | `{}` | Pod Node Selector configuration |
164+
| tolerations | list | `[]` | Pod Tolerations configuration |
165+
| volumes | tpl/list | `[]` | Additional volumes to the pod |
166+
| volumeMounts | tpl/list | `[]` | Additional volumeMounts to the container |
167+
| service.type | string | `"ClusterIP"` | Service type |
168+
| service.port | int | `8080` | Port to expose |
169+
| serviceAccount.create | bool | `true` | Specifies whether a service account should be created |
170+
| serviceAccount.automount | bool | `true` | Specifies whether a service account token should be mounted |
171+
| serviceAccount.annotations | tpl/object | `{}` | Annotations to add to the service account |
172+
| serviceAccount.name | string | `""` | The name of the service account to use. If not set and create is true, a name is generated using the fullname template |
173+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "gitops-connector.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "gitops-connector.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "gitops-connector.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "gitops-connector.labels" -}}
37+
{{ include "gitops-connector.selectorLabels" . }}
38+
{{- if .Chart.AppVersion }}
39+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
40+
{{- end }}
41+
app.kubernetes.io/managed-by: {{ .Release.Service }}
42+
{{- end }}
43+
44+
{{/*
45+
Selector labels
46+
*/}}
47+
{{- define "gitops-connector.selectorLabels" -}}
48+
app: {{ .Chart.Name }}
49+
app.kubernetes.io/name: {{ include "gitops-connector.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "gitops-connector.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "gitops-connector.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ include "gitops-connector.fullname" . }}
5+
labels: {{- include "gitops-connector.labels" . | nindent 4 }}
6+
data:
7+
8+
{{- if .Values.singleInstance }}
9+
10+
GIT_REPOSITORY_TYPE: {{ required "Provide a value for gitRepositoryType" .Values.singleInstance.gitRepositoryType}}
11+
CICD_ORCHESTRATOR_TYPE: {{ required "Provide a value for ciCdOrchestratorType" .Values.singleInstance.ciCdOrchestratorType}}
12+
GITOPS_OPERATOR_TYPE: {{ required "Provide a value for gitOpsOperatorType" .Values.singleInstance.gitOpsOperatorType}}
13+
GITOPS_APP_URL: {{ required "Provide a value for gitOpsAppURL" .Values.singleInstance.gitOpsAppURL}}
14+
15+
{{- if eq .Values.singleInstance.gitRepositoryType "AZDO"}}
16+
AZDO_GITOPS_REPO_NAME: {{ required "Provide a value for azdoGitOpsRepoName" .Values.singleInstance.azdoGitOpsRepoName}}
17+
{{- end }}
18+
19+
{{- if and (eq .Values.singleInstance.ciCdOrchestratorType "AZDO") (.Values.singleInstance.azdoPrRepoName)}}
20+
AZDO_PR_REPO_NAME: {{ .Values.singleInstance.azdoPrRepoName}}
21+
{{- end }}
22+
23+
{{- if or (eq .Values.singleInstance.gitRepositoryType "AZDO") (eq .Values.singleInstance.ciCdOrchestratorType "AZDO")}}
24+
AZDO_ORG_URL: {{ required "Provide a value for azdoOrgUrl" .Values.singleInstance.azdoOrgUrl}}
25+
{{- end }}
26+
27+
{{- if eq .Values.singleInstance.ciCdOrchestratorType "GITHUB"}}
28+
GITHUB_GITOPS_REPO_NAME: {{ required "Provide a value for gitHubGitOpsRepoName" .Values.singleInstance.gitHubGitOpsRepoName}}
29+
{{- end }}
30+
31+
{{- if eq .Values.singleInstance.gitRepositoryType "GITHUB"}}
32+
GITHUB_GITOPS_MANIFEST_REPO_NAME: {{ required "Provide a value for gitHubGitOpsManifestsRepoName" .Values.singleInstance.gitHubGitOpsManifestsRepoName}}
33+
{{- end }}
34+
35+
{{- if or (eq .Values.singleInstance.gitRepositoryType "GITHUB") (eq .Values.singleInstance.ciCdOrchestratorType "GITHUB")}}
36+
GITHUB_ORG_URL: {{ required "Provide a value for gitHubOrgUrl" .Values.singleInstance.gitHubOrgUrl}}
37+
{{- end }}
38+
39+
{{- end }}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{{- if not .Values.singleInstance }}
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
name: gitopsconfigs.example.com # Replace 'example.com' with your domain
6+
spec:
7+
group: example.com # Replace 'example.com' with your domain
8+
names:
9+
kind: GitOpsConfig
10+
plural: gitopsconfigs
11+
singular: gitopsconfig
12+
scope: Namespaced
13+
versions:
14+
- name: v1
15+
served: true
16+
storage: true
17+
schema:
18+
openAPIV3Schema:
19+
type: object
20+
required: ['spec']
21+
properties:
22+
spec:
23+
type: object
24+
required: ['gitRepositoryType','ciCdOrchestratorType','gitOpsOperatorType','gitOpsAppURL']
25+
properties:
26+
gitRepositoryType:
27+
type: string
28+
description: "Type of the Git repository (e.g., GitHub, Azure DevOps)"
29+
ciCdOrchestratorType:
30+
type: string
31+
description: "Type of CI/CD orchestrator (e.g., Jenkins, Azure Pipelines)"
32+
gitOpsOperatorType:
33+
type: string
34+
description: "GitOps operator type (e.g., ArgoCD, Flux)"
35+
gitOpsAppURL:
36+
type: string
37+
description: "URL for the GitOps application"
38+
azdoGitOpsRepoName:
39+
type: string
40+
description: "Azure DevOps repository name for GitOps"
41+
azdoPrRepoName:
42+
type: string
43+
description: "Azure DevOps repository name for pull requests"
44+
azdoOrgUrl:
45+
type: string
46+
description: "Azure DevOps organization URL"
47+
gitHubGitOpsRepoName:
48+
type: string
49+
description: "GitHub repository name for GitOps"
50+
gitHubGitOpsManifestsRepoName:
51+
type: string
52+
description: "GitHub repository name for manifests"
53+
gitHubOrgUrl:
54+
type: string
55+
description: "GitHub organization URL"
56+
57+
{{- end }}

0 commit comments

Comments
 (0)