Skip to content

Commit 22c9f84

Browse files
author
Zbigniew Mandziejewicz
committed
initial code commit
1 parent aa216c7 commit 22c9f84

35 files changed

+5579
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
verify:
8+
name: Verify
9+
runs-on: ubuntu-latest
10+
env:
11+
CODECOV_FILE: build/coverage.xml
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
- name: Setup Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version: '1.24'
19+
- name: Generate
20+
run: make generate format
21+
- name: No changed files
22+
run: git diff --name-status --exit-code
23+
- name: Lint
24+
run: make lint
25+
- name: Integration test
26+
run: make integration-test coverage
27+
- name: Upload coverage reports to Codecov
28+
uses: codecov/codecov-action@v5
29+
with:
30+
token: ${{ secrets.CODECOV_TOKEN }}
31+
files: ${{ env.CODECOV_FILE }}
32+
33+
image-build:
34+
name: Image Build
35+
if: github.actor!= 'dependabot-preview[bot]'
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v4
40+
- name: Set up QEMU
41+
uses: docker/setup-qemu-action@v3
42+
- name: Set up Docker Buildx
43+
uses: docker/setup-buildx-action@v3
44+
with:
45+
platforms: linux/amd64,linux/arm64
46+
- name: Login to GitHub Container Registry
47+
uses: docker/login-action@v3
48+
with:
49+
registry: ghcr.io
50+
username: ${{ github.actor }}
51+
password: ${{ secrets.GITHUB_TOKEN }}
52+
- name: Setup Skaffold
53+
uses: heypigeonhq/setup-skaffold@v1.0.0
54+
with:
55+
version: 2.14.1
56+
- name: Build images
57+
run: |
58+
mkdir build
59+
skaffold build --file-output=build/images.json
60+
- name: Archive image tags
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: images
64+
path: build/images.json

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/
2+
.vscode/

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
GOLANGCILINT_VERSION := v2.5.0
2+
GOTESTSUM_VERSION := v1.13.0
3+
4+
GOCOVERPKG := github.com/agoda-com/argocd-capi-operator/...
5+
6+
CONTROLLER_GEN_VERSION = v0.17.1
7+
CONTROLLER_GEN_ARGS := \
8+
paths={./...} \
9+
rbac:roleName=argocd-capi-operator \
10+
output:rbac:dir=config/rbac
11+
12+
include makefiles/go.mk
13+
include makefiles/controller.mk

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# argocd-capi-operator
2+
3+
Register [Cluster](https://doc.crds.dev/github.com/kubernetes-sigs/cluster-api/cluster.x-k8s.io/Cluster/v1beta1@v1.8.3) resources using [ArgoCD Cluster API](https://pkg.go.dev/github.com/argoproj/argo-cd/v2@v2.12.3/pkg/apiclient/cluster#ClusterServiceClient).
4+
5+
## How it works
6+
7+
Operator registers an Cluster in ArgoCD using token generated for service account `argocd-manager`.
8+
9+
Using cluster kubeconfig it creates/patches:
10+
11+
- Namespace `argocd`
12+
- ServiceAccount `argocd-manager` in namespace `argocd`
13+
- ClusterRole/ClusterRoleBinding `argocd-manager` letting argocd manage crds, webhooks and rbac resources
14+
15+
## Deployment
16+
17+
### Local
18+
19+
```bash
20+
skaffold run
21+
```
22+
23+
### Management Cluster
24+
25+
```bash
26+
skaffold build --kube-context <management-cluster> --quiet | \
27+
skaffold deploy ---kube-context <management-cluster> --build-artifacts -
28+
```
29+
30+
## Operations
31+
32+
### Usage
33+
34+
| Name | Default | Usage |
35+
| --- | --- | --- |
36+
| context | | Kubernetes context |
37+
| health-probe-bind-address | :8081 | The address the probe endpoint binds to |
38+
| instance | | Instance to populate argocd.fleet.agoda.com/instance annotation |
39+
| leader-election | true | Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager |
40+
| metrics-bind-address | :8080 | The address the metric endpoint binds to |
41+
| token-ttl | 1h0m0s | Service account bearer token TTL |
42+
| watch-namespaces | [] | Namespaces to watch for Cluster resources |
43+
| watch-selector | | Selector to watch for Cluster resources |
44+
| zap-devel | false | Development Mode defaults(encoder=consoleEncoder,logLevel=Debug,stackTraceLevel=Warn). Production Mode defaults(encoder=jsonEncoder,logLevel=Info,stackTraceLevel=Error) |
45+
| zap-encoder | | Zap log encoding (one of 'json' or 'console') |
46+
| zap-log-level | | Zap Level to configure the verbosity of logging. Can be one of 'debug', 'info', 'error', or any integer value > 0 which corresponds to custom debug levels of increasing verbosity |
47+
| zap-stacktrace-level | | Zap Level at and above which stacktraces are captured (one of 'info', 'error', 'panic'). |
48+
| zap-time-encoding | | Zap time encoding (one of 'epoch', 'millis', 'nano', 'iso8601', 'rfc3339' or 'rfc3339nano'). Defaults to 'epoch'. |
49+
50+
### Cluster discovery
51+
52+
[Cluster](https://doc.crds.dev/github.com/kubernetes-sigs/cluster-api/cluster.x-k8s.io/Cluster/v1beta1@v1.8.3) resources are only watched in namespaces specified by `--watch-namespaces`.
53+
54+
They can be further scoped down by `--watch-filter` which should contain value for `cluster.x-k8s.io/watch-filter` label.
55+
56+
Example:
57+
58+
```yaml
59+
apiVersion: apps/v1
60+
kind: Deployment
61+
metadata:
62+
name: argocd-capi-operator
63+
spec:
64+
template:
65+
spec:
66+
containers:
67+
- name: operator
68+
args:
69+
- --watch-namespaces=kubernetes,tools,nosql
70+
- --watch-filter=argocd
71+
```

cluster/config.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package cluster
2+
3+
import (
4+
"time"
5+
)
6+
7+
type Config struct {
8+
Instance string
9+
Namespace string
10+
ServiceAccountName string
11+
TokenTTL time.Duration
12+
}

0 commit comments

Comments
 (0)