An open API service indexing awesome lists of open source software.

https://github.com/gianlucam76/ytt-controller

A Carvel YTT controller. Get ytt files from either Flux source or ConfigMap/Secret. Process them using ytt module. Make output available for Sveltos
https://github.com/gianlucam76/ytt-controller

carvel clusterapi controller flux gitops kubernetes ytt

Last synced: 2 months ago
JSON representation

A Carvel YTT controller. Get ytt files from either Flux source or ConfigMap/Secret. Process them using ytt module. Make output available for Sveltos

Awesome Lists containing this project

README

        

# ytt-controller
A YTT Carvel controller. It can fetch YTT files from:
1. Flux Sources (GitRepository/OCIRepository/Bucket)
2. ConfigMap/Secret

process those files programmatically invoking Carvel `ytt` and store the output in its Status section.
[Sveltos addon-manager](https://github.com/projectsveltos/addon-manager) can then be used to deploy the output of the ytt-controller in all selected managed clusters.

## Install

```bash
kubectl apply -f https://raw.githubusercontent.com/gianlucam76/ytt-controller/main/manifest/manifest.yaml
```

or if you want a specific version

```bash
kubectl apply -f https://raw.githubusercontent.com/gianlucam76/ytt-controller//manifest/manifest.yaml
```

## Using Flux GitRepository

For instance, this Github repository https://github.com/gianlucam76/ytt-examples contains ytt files.
You can use Flux to sync from it and then simply post this [YttSource](https://github.com/gianlucam76/ytt-controller/blob/main/api/v1alpha1/yttsource_types.go) CRD instance.
The ytt-controller will detect when Flux has synced the repo (and anytime there is a change), will programatically invoke ytt and store the outcome in its Status.Resources field.

```yaml
apiVersion: extension.projectsveltos.io/v1beta1
kind: YttSource
metadata:
name: yttsource-flux
spec:
namespace: flux-system
name: flux-system
kind: GitRepository
path: ./deployment/
```

```yaml
apiVersion: extension.projectsveltos.io/v1beta1
kind: YttSource
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"extension.projectsveltos.io/v1beta1","kind":"YttSource","metadata":{"annotations":{},"name":"yttsource-flux","namespace":"default"},"spec":{"kind":"GitRepository","name":"flux-system","namespace":"flux-system","path":"./deployment/"}}
creationTimestamp: "2023-05-22T06:20:01Z"
generation: 1
name: yttsource-flux
namespace: default
resourceVersion: "91726"
uid: c7ae3485-37a9-447a-9fa4-7d21a129ccf6
spec:
kind: GitRepository
name: flux-system
namespace: flux-system
path: ./deployment/
status:
resources: |
apiVersion: v1
kind: Service
metadata:
name: sample-app
labels:
environment: staging
spec:
selector:
app: sample-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: sample-app
labels:
environment: staging
spec:
replicas: 1
selector:
matchLabels:
environment: staging
template:
metadata:
labels:
environment: staging
spec:
containers:
- name: sample-app
image: nginx:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Secret
metadata:
name: application-settings
stringData:
app_mode: staging
certificates: /etc/ssl/staging
db_user: staging-user
db_password: staging-password
```

## Using ConfigMap/Secret

YttSource can also reference ConfigMap/Secret. For instance, we can create a ConfigMap whose BinaryData section contains ytt files.

```bash
tar -czf ytt.tar.gz -C ~mgianluc/go/src/github.com/gianlucam76/ytt-examples/deployment .
kubectl create configmap ytt --from-file=ytt.tar.gz=ytt.tar.gz
```

Then we can have YttSource reference this ConfigMap instance

```yaml
apiVersion: extension.projectsveltos.io/v1beta1
kind: YttSource
metadata:
name: yttsource-sample
spec:
namespace: default
name: ytt
kind: ConfigMap
path: ./
```

and the controller will programmatically execute ytt and store the outcome in Status.Results.

```yaml
apiVersion: extension.projectsveltos.io/v1beta1
kind: YttSource
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"extension.projectsveltos.io/v1beta1","kind":"YttSource","metadata":{"annotations":{},"name":"yttsource-sample","namespace":"default"},"spec":{"kind":"ConfigMap","name":"ytt","namespace":"default","path":"./"}}
creationTimestamp: "2023-05-22T06:27:31Z"
generation: 1
name: yttsource-sample
namespace: default
resourceVersion: "94517"
uid: 4b0b4efb-57b4-4ffd-ab32-dc56fee21a09
spec:
kind: ConfigMap
name: ytt
namespace: default
path: ./
status:
resources: |
apiVersion: v1
kind: Service
metadata:
name: sample-app
labels:
environment: staging
spec:
selector:
app: sample-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: sample-app
labels:
environment: staging
spec:
replicas: 1
selector:
matchLabels:
environment: staging
template:
metadata:
labels:
environment: staging
spec:
containers:
- name: sample-app
image: nginx:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Secret
metadata:
name: application-settings
stringData:
app_mode: staging
certificates: /etc/ssl/staging
db_user: staging-user
db_password: staging-password
```

At this point [Sveltos Kubernetes addon controller](https://github.com/projectsveltos/addon-controller) to use the output of the ytt-controller and deploy those resources in all selected managed clusters. To know more refer to [Sveltos documentation](https://projectsveltos.github.io/sveltos/ytt_extension/)

## Contributing

❤️ Your contributions are always welcome! If you want to contribute, have questions, noticed any bug or want to get the latest project news, you can connect with us in the following ways:

1. Open a bug/feature enhancement on github [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/projectsveltos/addon-manager/issues)
2. Chat with us on the Slack in the #projectsveltos channel [![Slack](https://img.shields.io/badge/join%20slack-%23projectsveltos-brighteen)](https://join.slack.com/t/projectsveltos/shared_invite/zt-1hraownbr-W8NTs6LTimxLPB8Erj8Q6Q)
3. [Contact Us](mailto:[email protected])