feat(kubernetes-reflector): Add kubernetes-reflector (#13756)

**Description**
<!--
Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context. List any dependencies that
are required for this change.
-->

Although Kubernetes-reflector can be used to mirror both generic
Configmaps and Secrets across k8s namespaces, with this PR I
specifically intend to lay the groundwork for supporting wildcard
certificates in Truecharts.

To keep things small this PR only adds the app needed to support secrets
mirroring across namespaces. The rest of the functionality will be added
through separate PRs.

A high-level overview of how I picture this to work:
- A user will gain the ability to create "cluster-wide" certificates in
the `clusterIssuer` app config. This will generate the certificates and
store them in the app's namespace
- The created/updated certificates will be mirrored automatically to all
namespaces matching the regex `ix-.+` (or configurable for helm users)
with the help of the `kubernetes-reflector` app
- The user will gain the ability to use a "cluster-wide" certificate
when setting up an ingress for an app. Similar to how they can currently
use a custom secret for an ingress cert.

To achieve this in next PRs  I will be:
- Submitting small patches to the common lib. So far I think the only
change needed is to allow setting annotations to `Certificate` CRDs,
which is needed to allow `kubernetes-reflector` to replicate them (see
[cert-manager
docs](https://cert-manager.io/docs/devops-tips/syncing-secrets-across-namespaces/#using-reflector))
- Submitting small patches to the clusterIssuer app and the
`Ingress{*}.yaml` files

Relevant issue: #8634

I have not yet added the image to the TC repo. Will do that after the
review process, before merging.
  
⚒️ Fixes  # <!--(issue)-->

**⚙️ Type of change**

- [X] ⚙️ Feature/App addition
- [ ] 🪛 Bugfix
- [ ] ⚠️ Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] 🔃 Refactor of current code

**🧪 How Has This Been Tested?**
<!--
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration
-->
I have tested this by deploying the `kubernetes-reflector` app and then
applying the following yaml:
```yaml

apiVersion: v1
kind: Namespace
metadata:
  name: origin
---
apiVersion: v1
kind: Namespace
metadata:
  name: destination1
---
apiVersion: v1
kind: Namespace
metadata:
  name: destination2
---
apiVersion: v1
kind: Namespace
metadata:
  name: another-destination1
---
apiVersion: v1
kind: Namespace
metadata:
  name: another-destination2
---
apiVersion: v1
kind: Secret
metadata:
  annotations:
    # Allow reflection from source namespaces
    reflector.v1.k8s.emberstack.com/reflection-allowed: "true"
    # Namespaces from/to which reflection is allowed
    reflector.v1.k8s.emberstack.com/reflection-allowed-namespaces: "origin,(another-)?destination\\d+"
    # Auto reflect secrets/configmaps to destination namespaces
    reflector.v1.k8s.emberstack.com/reflection-auto-enabled: "true"
    # Destination namespaces
    reflector.v1.k8s.emberstack.com/reflection-auto-namespaces: "(another-)?destination\\d+"
  name: my-secret
  namespace: origin
type: Opaque
data:
  mydata: c2VjcmV0Cg==
  # mydata: c3VwZXJzdXBlcnNlY3JldAo=
```
Exact commands and output:
```bash
$ kubectl create ns ix-kubernetes-reflector
$ helm install -n ix-kubernetes-reflector kubernetes-reflector .
$ kubectl get secrets --all-namespaces
NAMESPACE                 NAME                                         TYPE                 DATA   AGE
kube-system               pop-os.node-password.k3s                     Opaque               1      144d
kube-system               k3s-serving                                  kubernetes.io/tls    2      144d
ix-kubernetes-reflector   sh.helm.release.v1.kubernetes-reflector.v1   helm.sh/release.v1   1      8s
$ kubectl apply -f test-reflect.yaml 
namespace/origin created
namespace/destination1 created
namespace/destination2 created
namespace/another-destination1 created
namespace/another-destination2 created
secret/my-secret created
$ kubectl get secrets --all-namespaces
NAMESPACE                 NAME                                         TYPE                 DATA   AGE
kube-system               pop-os.node-password.k3s                     Opaque               1      144d
kube-system               k3s-serving                                  kubernetes.io/tls    2      144d
ix-kubernetes-reflector   sh.helm.release.v1.kubernetes-reflector.v1   helm.sh/release.v1   1      29s
origin                    my-secret                                    Opaque               1      5s
destination1              my-secret                                    Opaque               1      5s
destination2              my-secret                                    Opaque               1      5s
another-destination1      my-secret                                    Opaque               1      5s
another-destination2      my-secret                                    Opaque               1      5s
$ kubectl describe secret -n destination1 my-secret | tail -1
mydata:  7 bytes
$ # Change the secret value (uncomment the other key and comment the first one)
$ kubectl apply -f test-reflect.yaml 
$ kubectl describe secret -n destination1 my-secret | tail -1
mydata:  17 bytes
$ kubectl delete secret -n origin my-secret
secret "my-secret" deleted
$ kubectl get secrets --all-namespaces
NAMESPACE                 NAME                                         TYPE                 DATA   AGE
kube-system               pop-os.node-password.k3s                     Opaque               1      144d
kube-system               k3s-serving                                  kubernetes.io/tls    2      144d
ix-kubernetes-reflector   sh.helm.release.v1.kubernetes-reflector.v1   helm.sh/release.v1   1      3m24s
```

**📃 Notes:**
<!-- Please enter any other relevant information here -->

**✔️ Checklist:**

- [X] ⚖️ My code follows the style guidelines of this project
- [X] 👀 I have performed a self-review of my own code
- [X] #️⃣ I have commented my code, particularly in hard-to-understand
areas
- [ ] 📄 I have made corresponding changes to the documentation
- [X] ⚠️ My changes generate no new warnings
- [X] 🧪 I have added tests to this description that prove my fix is
effective or that my feature works
- [X] ⬆️ I increased versions for any altered app according to semantic
versioning

**➕ App addition**

If this PR is an app addition please make sure you have done the
following.

- [ ] 🪞 I have opened a PR on
[truecharts/containers](https://github.com/truecharts/containers) adding
the container to TrueCharts mirror repo.
- [X] 🖼️ I have added an icon in the Chart's root directory called
`icon.png`

---

_Please don't blindly check all the boxes. Read them and only check
those that apply.
Those checkboxes are there for the reviewer to see what is this all
about and
the status of this PR with a quick glance._

---------

Signed-off-by: sdimovv <36302090+sdimovv@users.noreply.github.com>
Signed-off-by: Kjeld Schouten <kjeld@schouten-lebbing.nl>
Co-authored-by: Stavros Kois <47820033+stavros-k@users.noreply.github.com>
Co-authored-by: Kjeld Schouten <kjeld@schouten-lebbing.nl>
This commit is contained in:
sdimovv
2023-10-28 12:28:41 +02:00
committed by GitHub
co-authored by Stavros Kois Kjeld Schouten
parent 6f184b87fd
commit 9173c46335
7 changed files with 183 additions and 0 deletions
@@ -0,0 +1,30 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
# OWNERS file for Kubernetes
OWNERS
# helm-docs templates
*.gotmpl
# docs folder
/docs
# icon
icon.png
@@ -0,0 +1,32 @@
apiVersion: v2
appVersion: "7.1.210"
deprecated: false
description: Kubernetes-Reflector is a Kubernetes addon designed to monitor and reflect changes to secrets and configmaps across namespaces
home: https://truecharts.org/charts/operators/kubernetes-reflector
icon: https://truecharts.org/img/hotlink-ok/chart-icons/kubernetes-reflector.png
keywords:
- reflector
- secrets
- configmaps
- cert-manager
- certificates
dependencies:
- name: common
repository: https://library-charts.truecharts.org
version: 14.0.14
kubeVersion: ">=1.16.0-0"
maintainers:
- email: info@truecharts.org
name: TrueCharts
url: https://truecharts.org
name: kubernetes-reflector
sources:
- https://github.com/truecharts/charts/tree/master/charts/operators/kubernetes-reflector
- https://github.com/emberstack/kubernetes-reflector
type: application
version: 0.1.0
annotations:
truecharts.org/catagories: |
- operators
truecharts.org/SCALE-support: "true"
truecharts.org/grade: U
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

@@ -0,0 +1,42 @@
# Include{groups}
questions:
# Include{global}
# Include{workload}
# Include{workloadDeployment}
# Include{replicas1}
# Include{podSpec}
# Include{containerMain}
# Include{containerBasic}
# Include{containerAdvanced}
- variable: kubernetesReflector
group: "App Configuration"
label: "Kubernetes-Reflector Configuration"
schema:
additional_attrs: true
type: dict
attrs:
- variable: logLevel
label: "Log Level"
schema:
type: string
default: "Information"
enum:
- value: "Verbose"
description: "Trace"
- value: "Debug"
description: "Debug"
- value: "Information"
description: "Info"
- value: "Warning"
description: "Warnings"
- value: "Error"
description: "Errors"
- value: "Fatal"
description: "Fatal Errors"
# Include{resources}
# Include{advanced}
# Include{addons}
# Include{codeserver}
# Include{netshoot}
# Include{vpn}
# Include{documentation}
@@ -0,0 +1 @@
{{- include "tc.v1.common.loader.all" . }}
@@ -0,0 +1,78 @@
image:
repository: tccr.io/truecharts/kubernetes-reflector
pullPolicy: IfNotPresent
tag: v7.1.217@sha256:4ca9ce8c04441786ba0d343b3e5bfe9c638ac8efcc25aba0aaff3c6fb2363b5f
operator:
register: true
portal:
open:
enabled: false
rbac:
main:
enabled: true
primary: true
clusterWide: true
rules:
- apiGroups:
- ""
resources:
- "configmaps"
- "secrets"
verbs:
- "get"
- "list"
- "watch"
- "create"
- "update"
- "patch"
- "delete"
- apiGroups:
- ""
resources:
- "namespaces"
verbs:
- "watch"
- "list"
serviceAccount:
main:
enabled: true
primary: true
kubernetesReflector:
logLevel: Information
workload:
main:
podSpec:
automountServiceAccountToken: true
containers:
main:
securityContext:
readOnlyRootFilesystem: true
runAsNonRoot: true
env:
ES_Serilog__MinimumLevel__Default: '{{ .Values.kubernetesReflector.logLevel }}'
ES_Reflector__Watcher__Timeout: ""
ES_Reflector__Kubernetes__SkipTlsVerify: "false"
probes:
liveness:
type: http
path: /healthz
port: 25080
readiness:
type: http
path: /healthz
port: 25080
startup:
type: http
path: /healthz
port: 25080
service:
main:
enabled: false