Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
13 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions .github/workflows/release-pullrequest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
name: Build and Push
strategy:
matrix:
runner: [buildjet-2vcpu-ubuntu-2204-arm, buildjet-2vcpu-ubuntu-2204]
runner: [ubuntu-22.04-arm, ubuntu-22.04]
include:
- runner: buildjet-2vcpu-ubuntu-2204-arm
- runner: ubuntu-22.04-arm
platform: linux/arm64
- runner: buildjet-2vcpu-ubuntu-2204
- runner: ubuntu-22.04
platform: linux/amd64
runs-on: ${{ matrix.runner }}

Expand All @@ -33,23 +33,23 @@ jobs:

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
uses: docker/metadata-action@v6
with:
images: ${{ env.GHCR_REPO }}

- name: Login to GHCR
uses: docker/login-action@v3
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
uses: docker/setup-buildx-action@v4

- name: Build and NOT push
id: build
uses: docker/build-push-action@v5
uses: docker/build-push-action@v7
with:
platforms: ${{ matrix.platform }}
push: false
Expand All @@ -58,15 +58,15 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: 'stable'
- name: Gather dependencies
run: go mod download
- name: Run coverage
run: go test -race -tags=unit,integration -p 1 -coverprofile=coverage.txt -timeout 30m -covermode=atomic ./...
run: go test -race -tags=unit,integration -p 1 -timeout 30m -coverprofile=coverage.txt -covermode=atomic ./... -coverpkg=./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v6
with:
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.CODECOV_TOKEN }}
36 changes: 17 additions & 19 deletions .github/workflows/release-tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: release-tag

on:
push:
tags: [ '[0-9]+.[0-9]+.[0-9]+' ]
tags: [ '[0-9]+.[0-9]+.[0-9]+', '[0-9]+.[0-9]+.[0-9]+-*' ]

env:
GHCR_REPO: ghcr.io/${{ github.repository }}
Expand All @@ -13,11 +13,11 @@ jobs:
strategy:
fail-fast: false
matrix:
runner: [buildjet-2vcpu-ubuntu-2204-arm, buildjet-2vcpu-ubuntu-2204]
runner: [ubuntu-22.04-arm, ubuntu-22.04]
include:
- runner: buildjet-2vcpu-ubuntu-2204-arm
- runner: ubuntu-22.04-arm
platform: linux/arm64
- runner: buildjet-2vcpu-ubuntu-2204
- runner: ubuntu-22.04
platform: linux/amd64
runs-on: ${{ matrix.runner }}

Expand All @@ -33,23 +33,23 @@ jobs:

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
uses: docker/metadata-action@v6
with:
images: ${{ env.GHCR_REPO }}

- name: Login to GHCR
uses: docker/login-action@v3
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
uses: docker/setup-buildx-action@v4

- name: Build and push by digest
id: build
uses: docker/build-push-action@v5
uses: docker/build-push-action@v7
with:
platforms: ${{ matrix.platform }}
push: true
Expand All @@ -63,7 +63,7 @@ jobs:
touch "/tmp/digests/${digest#sha256:}"

- name: Upload digest
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
Expand All @@ -79,25 +79,25 @@ jobs:
packages: write
steps:
- name: Download digests
uses: actions/download-artifact@v4
uses: actions/download-artifact@v8
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true

- name: Login to GHCR
uses: docker/login-action@v3
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
uses: docker/setup-buildx-action@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
uses: docker/metadata-action@v6
with:
images: ${{ env.GHCR_REPO }}

Expand All @@ -114,20 +114,18 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: 'stable'
- name: Gather dependencies
run: go mod download
- name: Run coverage
run: go test -race -tags=unit,integration -p 1 -coverprofile=coverage.txt -timeout 30m -covermode=atomic ./...
run: go test -race -tags=unit,integration -p 1 -timeout 30m -coverprofile=coverage.txt -covermode=atomic ./... -coverpkg=./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v6
with:
token: ${{ secrets.CODECOV_TOKEN }}


update-crd-doc:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Build environment
# -----------------
FROM golang:1.25.0-bookworm AS builder
FROM golang:1.25.6-bookworm AS builder
LABEL stage=builder

ARG DEBIAN_FRONTEND=noninteractive
Expand Down
101 changes: 17 additions & 84 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,114 +1,47 @@
# Git Provider

This is a [Krateo](https://krateo.io) Provider that clones git repositories (eventually applying templates).

## Summary

- [Summary](#summary)
- [Overview](#overview)
- [Examples](#examples)
- [Configuration](#configuration)

This is a [Krateo](https://krateo.io) Provider that enables Git operations natively from your Kubernetes cluster.

## Overview

Git Provider clones git repositories and may apply [Mustache templates](https://mustache.github.io). It then pushes the cloned and modified repository to a different location. The templating values are retrieved in a configmap referenced in the custom resource.
It provides automatic reconciliation when changes are retrieved from the original repository.
The `git-provider` leverages Krateo [provider-runtime](https://docs.krateo.io/key-concepts/kco/#provider-runtime), a production-grade version of the controller-runtime, to provide automatic reconciliation and Git interactions.

Git Provider leverages Krateo [provider-runtime](https://docs.krateo.io/key-concepts/kco/#provider-runtime) a production-grade version of the controller-runtime.
It exposes two distinct Custom Resources (CRs) to handle different use cases:

## Examples
* **[Repo](docs/repo.md):** Designed for **Git-to-Git** workflows. It clones an existing Git repository, optionally applies templates ([Mustache](https://mustache.github.io) or [Go templates](https://pkg.go.dev/text/template)) to the files using values from a `ConfigMap`, and pushes the result to a destination repository.
* **[LocalResource](docs/local-resource.md):** Designed for **K8s-to-Git** workflows. It takes a local source (such as an embedded Kubernetes manifest, a reference to an existing cluster resource, or a raw string), optionally applies placeholder replacements, and commits the result directly to a destination Git repository.

### Provider Installation
## Installation

```bash
$ helm repo add krateo https://charts.krateo.io
$ helm repo update krateo
$ helm install git-provider krateo/git-provider
```

### Manifest Application

As a first step, you need to create a [`kind: Repo` Manifest](#repo-manifest) as shown below and a [ConfigMap](#configmap-manifest) which will contain the templating values.
## Documentation

### File Templating
`git-provider` uses the Mustache library ([see custom delimiter reference](https://github.com/janl/mustache.js/?tab=readme-ov-file#setting-in-templates)) to apply templating. Therefore, you need to specify the custom delimiter you want to use in the first line of the file you want to template. You can see an example [here](https://github.com/krateoplatformops/krateo-v2-template-fireworksapp/blob/5dee9fe1d2de3785eb7e6374ad50e3f8e7b12907/skeleton/chart/values.yaml#L1C1-L1C14).

### File Name Templating
If you need to template the filename of a file, you can only use the delimiters `{{ }}` (e.g., `{{ your-prop }}.yaml`).

#### Repo Manifest
```yaml
apiVersion: git.krateo.io/v1alpha1
kind: Repo
metadata:
name: test-repo
spec:
enableUpdate: false
configMapKeyRef:
key: values
name: filename-replace-values
namespace: default
fromRepo:
authMethod: generic
branch: main
path: skeleton
usernameRef:
key: username
name: git-username
namespace: default
secretRef:
key: token
name: git-secret
namespace: default
url: https://github.com/your-organization/fromRepo
toRepo:
authMethod: generic
branch: main
cloneFromBranch: main
path: /
secretRef:
key: token
name: git-secret
namespace: default
usernameRef:
key: username
name: git-username
namespace: default
url: https://github.com/your-organization/toRepo
unsupportedCapabilities: true
```

#### Configmap Manifest
```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: filename-replace-values
data:
values: |
{
"organizationName": "krateo",
"repositoryName": "testfilename",
"serviceType": "type",
"servicePort": "8080",
"testTemplate": "tplKrateo"
}
```
For detailed configuration, templating rules, and synchronization behavior, please refer to the specific documentation for each Custom Resource:

* 📖 [**Repo CR Documentation**](docs/repo.md)
* 📖 [**LocalResource CR Documentation**](docs/local-resource.md)

## Environment Variables

The provider controller can be configured using the following environment variables:

| Environment Variable | Type | Default Value | Description |
|---------------------|------|---------------|-------------|
| `GIT_PROVIDER_DEBUG` | bool | `false` | Run with debug logging |
| `GIT_PROVIDER_SYNC_PERIOD` | duration | `1h` | Controller manager sync period (e.g., 300ms, 1.5h, or 2h45m) |
| `GIT_PROVIDER_POLL_INTERVAL` | duration | `2m` | Poll interval controls how often an individual resource should be checked for drift |
| `GIT_PROVIDER_POLL_INTERVAL` | duration | `3m` | Poll interval controls how often an individual resource should be checked for drift |
| `GIT_PROVIDER_MAX_RECONCILE_RATE` | int | `5` | The number of concurrent reconciles for each controller. Maximum number of resources that can be reconciled at the same time |
| `GIT_PROVIDER_LEADER_ELECTION` | bool | `false` | Use leader election for the controller manager |
| `GIT_PROVIDER_MAX_ERROR_RETRY_INTERVAL` | duration | `1m` | The maximum interval between retries when an error occurs. Should be less than half of the poll interval |
| `GIT_PROVIDER_MIN_ERROR_RETRY_INTERVAL` | duration | `1s` | The minimum interval between retries when an error occurs. Should be less than max-error-retry-interval |
| `GIT_PROVIDER_TIMEOUT` | duration | `4m` | The timeout time for each action. |
| `GIT_PROVIDER_GIT_COMMIT_AUTHOR_NAME` | string | `krateo-git-provider` | The name to use for git commits. |
| `GIT_PROVIDER_GIT_COMMIT_AUTHOR_EMAIL` | string | `contact@krateo.io` | The email to use for git commits. |

## Configuration
To view the CR configuration visit [this link](https://doc.crds.dev/github.com/krateoplatformops/git-provider).
## CRD Reference
To view the generated CR configuration schema, visit [this link](https://doc.crds.dev/github.com/krateoplatformops/git-provider).
Loading