Compare commits
58 Commits
v0.13.3
...
encrypt-in
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c0987a9a6 | ||
|
|
fd364828a1 | ||
|
|
afa58d8c08 | ||
|
|
179062876e | ||
|
|
a796f3609f | ||
|
|
b7c6db74d2 | ||
|
|
4f7b040405 | ||
|
|
34ca29830e | ||
|
|
78f1b634fa | ||
|
|
044bc64ad9 | ||
|
|
091f439498 | ||
|
|
a17b0a1ce0 | ||
|
|
354cd5e177 | ||
|
|
4e8f1221f7 | ||
|
|
6b179aa7d9 | ||
|
|
f748114dfa | ||
|
|
5de83f015a | ||
|
|
a6620e478a | ||
|
|
c7fcffdd8e | ||
|
|
160f59a984 | ||
|
|
d38d487c2a | ||
|
|
db28907543 | ||
|
|
c4261399b5 | ||
|
|
b4edb46269 | ||
|
|
a20ed0e630 | ||
|
|
cea869e285 | ||
|
|
e12db14d1e | ||
|
|
296bf3cc6c | ||
|
|
1789aa180d | ||
|
|
bd255800db | ||
|
|
1355962b3c | ||
|
|
bb0114e379 | ||
|
|
f9622a5b9e | ||
|
|
3a74fcd75c | ||
|
|
7265276cc2 | ||
|
|
b98027b528 | ||
|
|
b6ae7d2cdd | ||
|
|
aa887c61c3 | ||
|
|
700cef0989 | ||
|
|
3ed3e553e7 | ||
|
|
d68158ddc9 | ||
|
|
9f83a69242 | ||
|
|
bf69dbd43d | ||
|
|
465ea5ccfd | ||
|
|
92ef39e2ad | ||
|
|
0404790df9 | ||
|
|
f880e93df4 | ||
|
|
4697b1101d | ||
|
|
50ff2accd2 | ||
|
|
c7d876eb8f | ||
|
|
eda392dfcd | ||
|
|
3b91e14f6d | ||
|
|
17e3c57d7e | ||
|
|
1c744a0f97 | ||
|
|
99bdb20aeb | ||
|
|
fbe7050cb8 | ||
|
|
12ea028aa9 | ||
|
|
ea62cb5fc9 |
109
.github/workflows/e2e-arm64.yaml
vendored
Normal file
109
.github/workflows/e2e-arm64.yaml
vendored
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
name: e2e-arm64
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches: [ main, update-components ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
ampere:
|
||||||
|
# Runner info
|
||||||
|
# Owner: Stefan Prodan
|
||||||
|
# VM: Oracle Cloud VM.Standard.A1.Flex 4CPU 24GB RAM
|
||||||
|
# OS: Linux 5.4.0-1045-oracle #49-Ubuntu SMP aarch64
|
||||||
|
# Packages: docker, kind, kubectl, kustomize
|
||||||
|
runs-on: [self-hosted, Linux, ARM64]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.16.x
|
||||||
|
- name: Prepare
|
||||||
|
id: prep
|
||||||
|
run: |
|
||||||
|
echo ::set-output name=CLUSTER::arm64-${GITHUB_SHA:0:7}-$(date +%s)
|
||||||
|
echo ::set-output name=CONTEXT::kind-arm64-${GITHUB_SHA:0:7}-$(date +%s)
|
||||||
|
- name: Run unit tests
|
||||||
|
run: make test
|
||||||
|
- name: Check if working tree is dirty
|
||||||
|
run: |
|
||||||
|
if [[ $(git diff --stat) != '' ]]; then
|
||||||
|
git diff
|
||||||
|
echo 'run make test and commit changes'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
go build -o /tmp/flux ./cmd/flux
|
||||||
|
- name: Setup Kubernetes Kind
|
||||||
|
run: |
|
||||||
|
kind create cluster --name ${{ steps.prep.outputs.CLUSTER }}
|
||||||
|
- name: flux check --pre
|
||||||
|
run: |
|
||||||
|
/tmp/flux check --pre \
|
||||||
|
--context ${{ steps.prep.outputs.CONTEXT }}
|
||||||
|
- name: flux install
|
||||||
|
run: |
|
||||||
|
/tmp/flux install \
|
||||||
|
--components-extra=image-reflector-controller,image-automation-controller \
|
||||||
|
--context ${{ steps.prep.outputs.CONTEXT }}
|
||||||
|
- name: flux create source git
|
||||||
|
run: |
|
||||||
|
/tmp/flux create source git podinfo-gogit \
|
||||||
|
--git-implementation=go-git \
|
||||||
|
--url https://github.com/stefanprodan/podinfo \
|
||||||
|
--tag-semver=">1.0.0" \
|
||||||
|
--context ${{ steps.prep.outputs.CONTEXT }}
|
||||||
|
/tmp/flux create source git podinfo-libgit2 \
|
||||||
|
--git-implementation=libgit2 \
|
||||||
|
--url https://github.com/stefanprodan/podinfo \
|
||||||
|
--branch="master" \
|
||||||
|
--context ${{ steps.prep.outputs.CONTEXT }}
|
||||||
|
- name: flux create kustomization
|
||||||
|
run: |
|
||||||
|
/tmp/flux create kustomization podinfo \
|
||||||
|
--source=podinfo-gogit \
|
||||||
|
--path="./deploy/overlays/dev" \
|
||||||
|
--prune=true \
|
||||||
|
--interval=5m \
|
||||||
|
--validation=client \
|
||||||
|
--health-check="Deployment/frontend.dev" \
|
||||||
|
--health-check="Deployment/backend.dev" \
|
||||||
|
--health-check-timeout=3m \
|
||||||
|
--context ${{ steps.prep.outputs.CONTEXT }}
|
||||||
|
- name: flux create tenant
|
||||||
|
run: |
|
||||||
|
/tmp/flux create tenant dev-team \
|
||||||
|
--with-namespace=apps \
|
||||||
|
--context ${{ steps.prep.outputs.CONTEXT }}
|
||||||
|
- name: flux create helmrelease
|
||||||
|
run: |
|
||||||
|
/tmp/flux -n apps create source helm podinfo \
|
||||||
|
--url https://stefanprodan.github.io/podinfo \
|
||||||
|
--context ${{ steps.prep.outputs.CONTEXT }}
|
||||||
|
|
||||||
|
/tmp/flux -n apps create hr podinfo-helm \
|
||||||
|
--source=HelmRepository/podinfo \
|
||||||
|
--chart=podinfo \
|
||||||
|
--chart-version="6.0.x" \
|
||||||
|
--service-account=dev-team \
|
||||||
|
--context ${{ steps.prep.outputs.CONTEXT }}
|
||||||
|
- name: flux get all
|
||||||
|
run: |
|
||||||
|
/tmp/flux get all --all-namespaces \
|
||||||
|
--context ${{ steps.prep.outputs.CONTEXT }}
|
||||||
|
- name: flux uninstall
|
||||||
|
run: |
|
||||||
|
/tmp/flux uninstall -s \
|
||||||
|
--context ${{ steps.prep.outputs.CONTEXT }}
|
||||||
|
- name: Debug failure
|
||||||
|
if: failure()
|
||||||
|
run: |
|
||||||
|
kubectl --context ${{ steps.prep.outputs.CONTEXT }} -n flux-system get all
|
||||||
|
/tmp/flux logs --all-namespaces
|
||||||
|
- name: Cleanup
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
kind delete cluster --name ${{ steps.prep.outputs.CLUSTER }}
|
||||||
16
README.md
16
README.md
@@ -22,13 +22,19 @@ Delivery on top of Kubernetes.
|
|||||||
|
|
||||||
## Flux installation
|
## Flux installation
|
||||||
|
|
||||||
With Homebrew:
|
With [Homebrew](https://brew.sh) for macOS and Linux:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
brew install fluxcd/tap/flux
|
brew install fluxcd/tap/flux
|
||||||
```
|
```
|
||||||
|
|
||||||
With Bash:
|
With [GoFish](https://gofi.sh) for Windows, macOS and Linux:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
gofish install flux
|
||||||
|
```
|
||||||
|
|
||||||
|
With Bash for macOS and Linux:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
curl -s https://fluxcd.io/install.sh | sudo bash
|
curl -s https://fluxcd.io/install.sh | sudo bash
|
||||||
@@ -46,10 +52,10 @@ Arch Linux (AUR) packages:
|
|||||||
- [flux-scm](https://aur.archlinux.org/packages/flux-scm): build the latest
|
- [flux-scm](https://aur.archlinux.org/packages/flux-scm): build the latest
|
||||||
(unstable) version from source code from our git `main` branch
|
(unstable) version from source code from our git `main` branch
|
||||||
|
|
||||||
Binaries for macOS, Windows and Linux AMD64/ARM are available to download on the
|
Binaries for macOS AMD64/ARM64, Linux AMD64/ARM/ARM64 and Windows are available to
|
||||||
[release page](https://github.com/fluxcd/flux2/releases).
|
download on the [release page](https://github.com/fluxcd/flux2/releases).
|
||||||
|
|
||||||
A container image with `kubectl` and `flux` is available on Docker Hub and GitHub:
|
A multi-arch container image with `kubectl` and `flux` is available on Docker Hub and GitHub:
|
||||||
|
|
||||||
* `docker.io/fluxcd/flux-cli:<version>`
|
* `docker.io/fluxcd/flux-cli:<version>`
|
||||||
* `ghcr.io/fluxcd/flux-cli:<version>`
|
* `ghcr.io/fluxcd/flux-cli:<version>`
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ type gitFlags struct {
|
|||||||
path flags.SafeRelativePath
|
path flags.SafeRelativePath
|
||||||
username string
|
username string
|
||||||
password string
|
password string
|
||||||
|
silent bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var gitArgs gitFlags
|
var gitArgs gitFlags
|
||||||
@@ -79,6 +80,7 @@ func init() {
|
|||||||
bootstrapGitCmd.Flags().Var(&gitArgs.path, "path", "path relative to the repository root, when specified the cluster sync will be scoped to this path")
|
bootstrapGitCmd.Flags().Var(&gitArgs.path, "path", "path relative to the repository root, when specified the cluster sync will be scoped to this path")
|
||||||
bootstrapGitCmd.Flags().StringVarP(&gitArgs.username, "username", "u", "git", "basic authentication username")
|
bootstrapGitCmd.Flags().StringVarP(&gitArgs.username, "username", "u", "git", "basic authentication username")
|
||||||
bootstrapGitCmd.Flags().StringVarP(&gitArgs.password, "password", "p", "", "basic authentication password")
|
bootstrapGitCmd.Flags().StringVarP(&gitArgs.password, "password", "p", "", "basic authentication password")
|
||||||
|
bootstrapGitCmd.Flags().BoolVarP(&gitArgs.silent, "silent", "s", false, "assumes the deploy key is already setup, skips confirmation")
|
||||||
|
|
||||||
bootstrapCmd.AddCommand(bootstrapGitCmd)
|
bootstrapCmd.AddCommand(bootstrapGitCmd)
|
||||||
}
|
}
|
||||||
@@ -173,7 +175,6 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
// Configure repository URL to match auth config for sync.
|
// Configure repository URL to match auth config for sync.
|
||||||
repositoryURL.User = url.User(gitArgs.username)
|
repositoryURL.User = url.User(gitArgs.username)
|
||||||
repositoryURL.Scheme = "ssh"
|
repositoryURL.Scheme = "ssh"
|
||||||
repositoryURL.Host = repositoryURL.Hostname()
|
|
||||||
if bootstrapArgs.sshHostname != "" {
|
if bootstrapArgs.sshHostname != "" {
|
||||||
repositoryURL.Host = bootstrapArgs.sshHostname
|
repositoryURL.Host = bootstrapArgs.sshHostname
|
||||||
}
|
}
|
||||||
@@ -248,6 +249,8 @@ func promptPublicKey(ctx context.Context, secret corev1.Secret, _ sourcesecret.O
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.Successf("public key: %s", strings.TrimSpace(ppk))
|
logger.Successf("public key: %s", strings.TrimSpace(ppk))
|
||||||
|
|
||||||
|
if !gitArgs.silent {
|
||||||
prompt := promptui.Prompt{
|
prompt := promptui.Prompt{
|
||||||
Label: "Please give the key access to your repository",
|
Label: "Please give the key access to your repository",
|
||||||
IsConfirm: true,
|
IsConfirm: true,
|
||||||
@@ -256,5 +259,6 @@ func promptPublicKey(ctx context.Context, secret corev1.Secret, _ sourcesecret.O
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("aborting")
|
return fmt.Errorf("aborting")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,8 @@ var createHelmReleaseCmd = &cobra.Command{
|
|||||||
|
|
||||||
# Create a HelmRelease targeting another namespace than the resource
|
# Create a HelmRelease targeting another namespace than the resource
|
||||||
flux create hr podinfo \
|
flux create hr podinfo \
|
||||||
--target-namespace=default \
|
--target-namespace=test \
|
||||||
|
--create-target-namespace=true \
|
||||||
--source=HelmRepository/podinfo \
|
--source=HelmRepository/podinfo \
|
||||||
--chart=podinfo
|
--chart=podinfo
|
||||||
|
|
||||||
@@ -113,6 +114,7 @@ type helmReleaseFlags struct {
|
|||||||
chart string
|
chart string
|
||||||
chartVersion string
|
chartVersion string
|
||||||
targetNamespace string
|
targetNamespace string
|
||||||
|
createNamespace bool
|
||||||
valuesFiles []string
|
valuesFiles []string
|
||||||
valuesFrom flags.HelmReleaseValuesFrom
|
valuesFrom flags.HelmReleaseValuesFrom
|
||||||
saName string
|
saName string
|
||||||
@@ -128,6 +130,7 @@ func init() {
|
|||||||
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.chartVersion, "chart-version", "", "Helm chart version, accepts a semver range (ignored for charts from GitRepository sources)")
|
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.chartVersion, "chart-version", "", "Helm chart version, accepts a semver range (ignored for charts from GitRepository sources)")
|
||||||
createHelmReleaseCmd.Flags().StringSliceVar(&helmReleaseArgs.dependsOn, "depends-on", nil, "HelmReleases that must be ready before this release can be installed, supported formats '<name>' and '<namespace>/<name>'")
|
createHelmReleaseCmd.Flags().StringSliceVar(&helmReleaseArgs.dependsOn, "depends-on", nil, "HelmReleases that must be ready before this release can be installed, supported formats '<name>' and '<namespace>/<name>'")
|
||||||
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.targetNamespace, "target-namespace", "", "namespace to install this release, defaults to the HelmRelease namespace")
|
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.targetNamespace, "target-namespace", "", "namespace to install this release, defaults to the HelmRelease namespace")
|
||||||
|
createHelmReleaseCmd.Flags().BoolVar(&helmReleaseArgs.createNamespace, "create-target-namespace", false, "create the target namespace if it does not exist")
|
||||||
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.saName, "service-account", "", "the name of the service account to impersonate when reconciling this HelmRelease")
|
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.saName, "service-account", "", "the name of the service account to impersonate when reconciling this HelmRelease")
|
||||||
createHelmReleaseCmd.Flags().StringSliceVar(&helmReleaseArgs.valuesFiles, "values", nil, "local path to values.yaml files, also accepts comma-separated values")
|
createHelmReleaseCmd.Flags().StringSliceVar(&helmReleaseArgs.valuesFiles, "values", nil, "local path to values.yaml files, also accepts comma-separated values")
|
||||||
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.valuesFrom, "values-from", helmReleaseArgs.valuesFrom.Description())
|
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.valuesFrom, "values-from", helmReleaseArgs.valuesFrom.Description())
|
||||||
@@ -167,6 +170,7 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
Duration: createArgs.interval,
|
Duration: createArgs.interval,
|
||||||
},
|
},
|
||||||
TargetNamespace: helmReleaseArgs.targetNamespace,
|
TargetNamespace: helmReleaseArgs.targetNamespace,
|
||||||
|
|
||||||
Chart: helmv2.HelmChartTemplate{
|
Chart: helmv2.HelmChartTemplate{
|
||||||
Spec: helmv2.HelmChartTemplateSpec{
|
Spec: helmv2.HelmChartTemplateSpec{
|
||||||
Chart: helmReleaseArgs.chart,
|
Chart: helmReleaseArgs.chart,
|
||||||
@@ -178,6 +182,9 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Install: &helmv2.Install{
|
||||||
|
CreateNamespace: helmReleaseArgs.createNamespace,
|
||||||
|
},
|
||||||
Suspend: false,
|
Suspend: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -187,7 +194,7 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if helmReleaseArgs.crds != "" {
|
if helmReleaseArgs.crds != "" {
|
||||||
helmRelease.Spec.Install = &helmv2.Install{CRDs: helmv2.Create}
|
helmRelease.Spec.Install.CRDs = helmv2.Create
|
||||||
helmRelease.Spec.Upgrade = &helmv2.Upgrade{CRDs: helmv2.CRDsPolicy(helmReleaseArgs.crds.String())}
|
helmRelease.Spec.Upgrade = &helmv2.Upgrade{CRDs: helmv2.CRDsPolicy(helmReleaseArgs.crds.String())}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,19 +63,15 @@ For Git over HTTP/S, the provided basic authentication credentials are stored in
|
|||||||
--username=username \
|
--username=username \
|
||||||
--password=password
|
--password=password
|
||||||
|
|
||||||
# Create a Git SSH secret on disk and print the deploy key
|
# Create a Git SSH secret on disk
|
||||||
flux create secret git podinfo-auth \
|
flux create secret git podinfo-auth \
|
||||||
--url=ssh://git@github.com/stefanprodan/podinfo \
|
--url=ssh://git@github.com/stefanprodan/podinfo \
|
||||||
--export > podinfo-auth.yaml
|
--export > podinfo-auth.yaml
|
||||||
|
|
||||||
yq read podinfo-auth.yaml 'data."identity.pub"' | base64 --decode
|
# Print the deploy key
|
||||||
|
yq eval '.stringData."identity.pub"' podinfo-auth.yaml
|
||||||
# Create a Git SSH secret on disk and encrypt it with Mozilla SOPS
|
|
||||||
flux create secret git podinfo-auth \
|
|
||||||
--namespace=apps \
|
|
||||||
--url=ssh://git@github.com/stefanprodan/podinfo \
|
|
||||||
--export > podinfo-auth.yaml
|
|
||||||
|
|
||||||
|
# Encrypt the secret on disk with Mozilla SOPS
|
||||||
sops --encrypt --encrypted-regex '^(data|stringData)$' \
|
sops --encrypt --encrypted-regex '^(data|stringData)$' \
|
||||||
--in-place podinfo-auth.yaml`,
|
--in-place podinfo-auth.yaml`,
|
||||||
RunE: createSecretGitCmdRun,
|
RunE: createSecretGitCmdRun,
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ type sourceHelmFlags struct {
|
|||||||
keyFile string
|
keyFile string
|
||||||
caFile string
|
caFile string
|
||||||
secretRef string
|
secretRef string
|
||||||
|
passCredentials bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var sourceHelmArgs sourceHelmFlags
|
var sourceHelmArgs sourceHelmFlags
|
||||||
@@ -85,6 +86,7 @@ func init() {
|
|||||||
createSourceHelmCmd.Flags().StringVar(&sourceHelmArgs.keyFile, "key-file", "", "TLS authentication key file path")
|
createSourceHelmCmd.Flags().StringVar(&sourceHelmArgs.keyFile, "key-file", "", "TLS authentication key file path")
|
||||||
createSourceHelmCmd.Flags().StringVar(&sourceHelmArgs.caFile, "ca-file", "", "TLS authentication CA file path")
|
createSourceHelmCmd.Flags().StringVar(&sourceHelmArgs.caFile, "ca-file", "", "TLS authentication CA file path")
|
||||||
createSourceHelmCmd.Flags().StringVarP(&sourceHelmArgs.secretRef, "secret-ref", "", "", "the name of an existing secret containing TLS or basic auth credentials")
|
createSourceHelmCmd.Flags().StringVarP(&sourceHelmArgs.secretRef, "secret-ref", "", "", "the name of an existing secret containing TLS or basic auth credentials")
|
||||||
|
createSourceHelmCmd.Flags().BoolVarP(&sourceHelmArgs.passCredentials, "pass-credentials", "", false, "pass credentials to all domains")
|
||||||
|
|
||||||
createSourceCmd.AddCommand(createSourceHelmCmd)
|
createSourceCmd.AddCommand(createSourceHelmCmd)
|
||||||
}
|
}
|
||||||
@@ -132,6 +134,7 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
helmRepository.Spec.SecretRef = &meta.LocalObjectReference{
|
helmRepository.Spec.SecretRef = &meta.LocalObjectReference{
|
||||||
Name: sourceHelmArgs.secretRef,
|
Name: sourceHelmArgs.secretRef,
|
||||||
}
|
}
|
||||||
|
helmRepository.Spec.PassCredentials = sourceHelmArgs.passCredentials
|
||||||
}
|
}
|
||||||
|
|
||||||
if createArgs.export {
|
if createArgs.export {
|
||||||
@@ -175,6 +178,7 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
helmRepository.Spec.SecretRef = &meta.LocalObjectReference{
|
helmRepository.Spec.SecretRef = &meta.LocalObjectReference{
|
||||||
Name: secretName,
|
Name: secretName,
|
||||||
}
|
}
|
||||||
|
helmRepository.Spec.PassCredentials = sourceHelmArgs.passCredentials
|
||||||
logger.Successf("authentication configured")
|
logger.Successf("authentication configured")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
39
cmd/flux/encrypt.go
Normal file
39
cmd/flux/encrypt.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2021 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var encryptCmd = &cobra.Command{
|
||||||
|
Use: "encrypt",
|
||||||
|
Short: "Encrypt secrets using SOPS",
|
||||||
|
Long: "The encrypt sub-commands initialise and manage Secret encryption using SOPS.",
|
||||||
|
}
|
||||||
|
|
||||||
|
type encryptFlags struct {
|
||||||
|
export bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var encryptArgs encryptFlags
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
encryptCmd.PersistentFlags().BoolVar(&encryptArgs.export, "export", false, "export in YAML format to stdout")
|
||||||
|
|
||||||
|
rootCmd.AddCommand(encryptCmd)
|
||||||
|
}
|
||||||
113
cmd/flux/encrypt_init.go
Normal file
113
cmd/flux/encrypt_init.go
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2021 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"filippo.io/age"
|
||||||
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/go-git/go-git/v5"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
var encryptInitCmd = &cobra.Command{
|
||||||
|
Use: "init",
|
||||||
|
Short: "Init SOPS encryption with age identity",
|
||||||
|
Long: "The encryption init command creates a new age identity and writes a .sops.yaml file to the current working directory.",
|
||||||
|
Example: ` # Init SOPS encryption with a new age identity
|
||||||
|
flux encryption init`,
|
||||||
|
RunE: encryptInitCmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
encryptCmd.AddCommand(encryptInitCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func encryptInitCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
// Confirm our current path is in a Git repository
|
||||||
|
path, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := git.PlainOpen(path); err != nil {
|
||||||
|
if err == git.ErrRepositoryNotExists {
|
||||||
|
err = fmt.Errorf("'%s' is not in a Git repository", path)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Abort early if .sops.yaml already exists
|
||||||
|
sopsCfgPath := filepath.Join(path, ".sops.yaml")
|
||||||
|
if _, err := os.Stat(sopsCfgPath); err == nil || os.IsExist(err) {
|
||||||
|
return fmt.Errorf("'%s' already contains a .sops.yaml config", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate a new identity
|
||||||
|
i, err := age.GenerateX25519Identity()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Successf("Generated identity %s", i.Recipient().String())
|
||||||
|
|
||||||
|
// Attempt to configure identity in .sops.yaml
|
||||||
|
const sopsCfg = `creation_rules:
|
||||||
|
- path_regex: .*.yaml
|
||||||
|
encrypted_regex: ^(data|stringData)$
|
||||||
|
age: %s
|
||||||
|
`
|
||||||
|
if err := ioutil.WriteFile(sopsCfgPath, []byte(fmt.Sprintf(sopsCfg, i.Recipient().String())), 0644); err != nil {
|
||||||
|
logger.Failuref("Failed to write recipient to .sops.yaml file")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Successf("Configured recipient in .sops.yaml file")
|
||||||
|
|
||||||
|
// Init client
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
|
defer cancel()
|
||||||
|
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a secret
|
||||||
|
secret := &corev1.Secret{
|
||||||
|
ObjectMeta: v1.ObjectMeta{
|
||||||
|
Name: "sops-age",
|
||||||
|
Namespace: rootArgs.namespace,
|
||||||
|
},
|
||||||
|
StringData: map[string]string{
|
||||||
|
"flux-auto.age": i.String(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if err := kubeClient.Create(ctx, secret); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Successf(`Secret '%s' with private key created`, secret.Name)
|
||||||
|
|
||||||
|
// TODO(hidde): lookup kustomize based on path ref? Do direct cluster mutation? (Preferably not!)
|
||||||
|
// Feels something is missing in general to provide a user experience improving bridge between "die hard"
|
||||||
|
// `--export` and "please do not do this" direct-apply-to-cluster.
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
38
go.mod
38
go.mod
@@ -3,34 +3,34 @@ module github.com/fluxcd/flux2
|
|||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
filippo.io/age v1.0.0-rc.3
|
||||||
github.com/Masterminds/semver/v3 v3.1.0
|
github.com/Masterminds/semver/v3 v3.1.0
|
||||||
github.com/cyphar/filepath-securejoin v0.2.2
|
github.com/cyphar/filepath-securejoin v0.2.2
|
||||||
github.com/fluxcd/go-git-providers v0.1.1
|
github.com/fluxcd/go-git-providers v0.1.1
|
||||||
github.com/fluxcd/helm-controller/api v0.10.0
|
github.com/fluxcd/helm-controller/api v0.11.1
|
||||||
github.com/fluxcd/image-automation-controller/api v0.9.1
|
github.com/fluxcd/image-automation-controller/api v0.12.0
|
||||||
github.com/fluxcd/image-reflector-controller/api v0.9.1
|
github.com/fluxcd/image-reflector-controller/api v0.10.0
|
||||||
github.com/fluxcd/kustomize-controller/api v0.12.0
|
github.com/fluxcd/kustomize-controller/api v0.13.0
|
||||||
github.com/fluxcd/notification-controller/api v0.13.0
|
github.com/fluxcd/notification-controller/api v0.15.0
|
||||||
github.com/fluxcd/pkg/apis/meta v0.9.0
|
github.com/fluxcd/pkg/apis/meta v0.10.0
|
||||||
github.com/fluxcd/pkg/runtime v0.11.0
|
github.com/fluxcd/pkg/runtime v0.12.0
|
||||||
github.com/fluxcd/pkg/ssh v0.0.5
|
github.com/fluxcd/pkg/ssh v0.0.5
|
||||||
github.com/fluxcd/pkg/untar v0.0.5
|
github.com/fluxcd/pkg/untar v0.0.5
|
||||||
github.com/fluxcd/pkg/version v0.0.1
|
github.com/fluxcd/pkg/version v0.0.1
|
||||||
github.com/fluxcd/source-controller/api v0.12.1
|
github.com/fluxcd/source-controller/api v0.15.1
|
||||||
github.com/go-git/go-git/v5 v5.1.0
|
github.com/go-git/go-git/v5 v5.4.2
|
||||||
github.com/google/go-containerregistry v0.2.0
|
github.com/google/go-containerregistry v0.2.0
|
||||||
github.com/manifoldco/promptui v0.7.0
|
github.com/manifoldco/promptui v0.7.0
|
||||||
github.com/olekukonko/tablewriter v0.0.4
|
github.com/olekukonko/tablewriter v0.0.4
|
||||||
github.com/spf13/cobra v1.1.1
|
github.com/spf13/cobra v1.1.3
|
||||||
github.com/spf13/pflag v1.0.5
|
github.com/spf13/pflag v1.0.5
|
||||||
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0
|
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b
|
||||||
k8s.io/api v0.20.4
|
k8s.io/api v0.21.1
|
||||||
k8s.io/apiextensions-apiserver v0.20.4
|
k8s.io/apiextensions-apiserver v0.21.1
|
||||||
k8s.io/apimachinery v0.20.4
|
k8s.io/apimachinery v0.21.1
|
||||||
k8s.io/cli-runtime v0.20.2 // indirect
|
k8s.io/client-go v0.21.1
|
||||||
k8s.io/client-go v0.20.4
|
sigs.k8s.io/cli-utils v0.25.1-0.20210608181808-f3974341173a
|
||||||
sigs.k8s.io/cli-utils v0.22.2
|
sigs.k8s.io/controller-runtime v0.9.0
|
||||||
sigs.k8s.io/controller-runtime v0.8.3
|
sigs.k8s.io/kustomize/api v0.8.10
|
||||||
sigs.k8s.io/kustomize/api v0.7.4
|
|
||||||
sigs.k8s.io/yaml v1.2.0
|
sigs.k8s.io/yaml v1.2.0
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -156,6 +156,10 @@ func KubeConfig(kubeConfigPath string, kubeContext string) (*rest.Config, error)
|
|||||||
return nil, fmt.Errorf("kubernetes configuration load failed: %w", err)
|
return nil, fmt.Errorf("kubernetes configuration load failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// avoid throttling request when some Flux CRDs are not registered
|
||||||
|
cfg.QPS = 50
|
||||||
|
cfg.Burst = 100
|
||||||
|
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
resources:
|
resources:
|
||||||
- https://github.com/fluxcd/helm-controller/releases/download/v0.10.0/helm-controller.crds.yaml
|
- https://github.com/fluxcd/helm-controller/releases/download/v0.11.1/helm-controller.crds.yaml
|
||||||
- https://github.com/fluxcd/helm-controller/releases/download/v0.10.0/helm-controller.deployment.yaml
|
- https://github.com/fluxcd/helm-controller/releases/download/v0.11.1/helm-controller.deployment.yaml
|
||||||
- account.yaml
|
- account.yaml
|
||||||
patchesJson6902:
|
patchesJson6902:
|
||||||
- target:
|
- target:
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
resources:
|
resources:
|
||||||
- https://github.com/fluxcd/image-automation-controller/releases/download/v0.9.1/image-automation-controller.crds.yaml
|
- https://github.com/fluxcd/image-automation-controller/releases/download/v0.12.0/image-automation-controller.crds.yaml
|
||||||
- https://github.com/fluxcd/image-automation-controller/releases/download/v0.9.1/image-automation-controller.deployment.yaml
|
- https://github.com/fluxcd/image-automation-controller/releases/download/v0.12.0/image-automation-controller.deployment.yaml
|
||||||
- account.yaml
|
- account.yaml
|
||||||
patchesJson6902:
|
patchesJson6902:
|
||||||
- target:
|
- target:
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
resources:
|
resources:
|
||||||
- https://github.com/fluxcd/image-reflector-controller/releases/download/v0.9.1/image-reflector-controller.crds.yaml
|
- https://github.com/fluxcd/image-reflector-controller/releases/download/v0.10.0/image-reflector-controller.crds.yaml
|
||||||
- https://github.com/fluxcd/image-reflector-controller/releases/download/v0.9.1/image-reflector-controller.deployment.yaml
|
- https://github.com/fluxcd/image-reflector-controller/releases/download/v0.10.0/image-reflector-controller.deployment.yaml
|
||||||
- account.yaml
|
- account.yaml
|
||||||
patchesJson6902:
|
patchesJson6902:
|
||||||
- target:
|
- target:
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
resources:
|
resources:
|
||||||
- https://github.com/fluxcd/kustomize-controller/releases/download/v0.12.0/kustomize-controller.crds.yaml
|
- https://github.com/fluxcd/kustomize-controller/releases/download/v0.13.0/kustomize-controller.crds.yaml
|
||||||
- https://github.com/fluxcd/kustomize-controller/releases/download/v0.12.0/kustomize-controller.deployment.yaml
|
- https://github.com/fluxcd/kustomize-controller/releases/download/v0.13.0/kustomize-controller.deployment.yaml
|
||||||
- account.yaml
|
- account.yaml
|
||||||
patchesJson6902:
|
patchesJson6902:
|
||||||
- target:
|
- target:
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
resources:
|
resources:
|
||||||
- https://github.com/fluxcd/notification-controller/releases/download/v0.13.0/notification-controller.crds.yaml
|
- https://github.com/fluxcd/notification-controller/releases/download/v0.15.0/notification-controller.crds.yaml
|
||||||
- https://github.com/fluxcd/notification-controller/releases/download/v0.13.0/notification-controller.deployment.yaml
|
- https://github.com/fluxcd/notification-controller/releases/download/v0.15.0/notification-controller.deployment.yaml
|
||||||
- account.yaml
|
- account.yaml
|
||||||
patchesJson6902:
|
patchesJson6902:
|
||||||
- target:
|
- target:
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
resources:
|
resources:
|
||||||
- https://github.com/fluxcd/source-controller/releases/download/v0.12.1/source-controller.crds.yaml
|
- https://github.com/fluxcd/source-controller/releases/download/v0.15.1/source-controller.crds.yaml
|
||||||
- https://github.com/fluxcd/source-controller/releases/download/v0.12.1/source-controller.deployment.yaml
|
- https://github.com/fluxcd/source-controller/releases/download/v0.15.1/source-controller.deployment.yaml
|
||||||
- account.yaml
|
- account.yaml
|
||||||
patchesJson6902:
|
patchesJson6902:
|
||||||
- target:
|
- target:
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
resources:
|
resources:
|
||||||
- https://github.com/fluxcd/source-controller/releases/download/v0.12.1/source-controller.crds.yaml
|
- https://github.com/fluxcd/source-controller/releases/download/v0.15.1/source-controller.crds.yaml
|
||||||
- https://github.com/fluxcd/kustomize-controller/releases/download/v0.12.0/kustomize-controller.crds.yaml
|
- https://github.com/fluxcd/kustomize-controller/releases/download/v0.13.0/kustomize-controller.crds.yaml
|
||||||
- https://github.com/fluxcd/helm-controller/releases/download/v0.10.0/helm-controller.crds.yaml
|
- https://github.com/fluxcd/helm-controller/releases/download/v0.11.1/helm-controller.crds.yaml
|
||||||
- https://github.com/fluxcd/notification-controller/releases/download/v0.13.0/notification-controller.crds.yaml
|
- https://github.com/fluxcd/notification-controller/releases/download/v0.15.0/notification-controller.crds.yaml
|
||||||
- https://github.com/fluxcd/image-reflector-controller/releases/download/v0.9.1/image-reflector-controller.crds.yaml
|
- https://github.com/fluxcd/image-reflector-controller/releases/download/v0.10.0/image-reflector-controller.crds.yaml
|
||||||
- https://github.com/fluxcd/image-automation-controller/releases/download/v0.9.1/image-automation-controller.crds.yaml
|
- https://github.com/fluxcd/image-automation-controller/releases/download/v0.12.0/image-automation-controller.crds.yaml
|
||||||
|
|||||||
14
manifests/integrations/Makefile
Normal file
14
manifests/integrations/Makefile
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
bases := $(shell dirname $(shell find | grep kustomization.yaml | sort))
|
||||||
|
|
||||||
|
all: $(bases)
|
||||||
|
|
||||||
|
permutations := $(bases) $(addsuffix /,$(bases))
|
||||||
|
.PHONY: $(permutations)
|
||||||
|
$(permutations):
|
||||||
|
@echo $@
|
||||||
|
@warnings=$$(kustomize build $@ -o /dev/null 2>&1); \
|
||||||
|
if [ "$$warnings" ]; then \
|
||||||
|
echo "$$warnings"; \
|
||||||
|
false; \
|
||||||
|
fi
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
initContainers:
|
||||||
|
- image: bitnami/kubectl
|
||||||
|
securityContext:
|
||||||
|
privileged: false
|
||||||
|
readOnlyRootFilesystem: true
|
||||||
|
allowPrivilegeEscalation: false
|
||||||
|
name: copy-kubectl
|
||||||
|
# it's okay to do this because kubectl is a statically linked binary
|
||||||
|
command:
|
||||||
|
- sh
|
||||||
|
- -ceu
|
||||||
|
- cp $(which kubectl) /kbin/
|
||||||
|
resources: {}
|
||||||
|
volumeMounts:
|
||||||
|
- name: kbin
|
||||||
|
mountPath: /kbin
|
||||||
|
containers:
|
||||||
|
- name: sync
|
||||||
|
volumeMounts:
|
||||||
|
- name: kbin
|
||||||
|
mountPath: /kbin
|
||||||
|
volumes:
|
||||||
|
- name: kbin
|
||||||
|
emptyDir: {}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
|
||||||
|
commonLabels:
|
||||||
|
app: credentials-sync-eventhub
|
||||||
|
|
||||||
|
resources:
|
||||||
|
- sync.yaml
|
||||||
|
|
||||||
|
patchesStrategicMerge:
|
||||||
|
- kubectl-patch.yaml
|
||||||
|
|
||||||
|
vars:
|
||||||
|
- name: KUBE_SECRET
|
||||||
|
objref:
|
||||||
|
kind: ConfigMap
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
apiVersion: v1
|
||||||
|
fieldref:
|
||||||
|
fieldpath: data.KUBE_SECRET
|
||||||
|
|
||||||
|
configurations:
|
||||||
|
- kustomizeconfig.yaml
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
varReference:
|
||||||
|
- path: rules/resourceNames
|
||||||
|
kind: Role
|
||||||
133
manifests/integrations/eventhub-credentials-sync/_base/sync.yaml
Normal file
133
manifests/integrations/eventhub-credentials-sync/_base/sync.yaml
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
data:
|
||||||
|
# Patch this ConfigMap with additional values needed for your cloud
|
||||||
|
KUBE_SECRET: webhook-url # does not yet exist -- will be created in the same Namespace
|
||||||
|
ADDRESS: "fluxv2" # the Azure Event Hub name
|
||||||
|
SYNC_PERIOD: "3600" # tokens expire; refresh faster than that
|
||||||
|
|
||||||
|
---
|
||||||
|
# This Deployment frequently fetches registry tokens and applies them as an imagePullSecret.
|
||||||
|
# It's done as a 1-replica Deployment rather than a CronJob, because CronJob scheduling can
|
||||||
|
# block cluster bootstraps and cold-reboots from obtaining registry tokens for a considerable time.
|
||||||
|
# This deployment will immediately fetch a token, which reduces latency for working image updates.
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
strategy:
|
||||||
|
type: Recreate
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
serviceAccountName: credentials-sync-eventhub
|
||||||
|
securityContext:
|
||||||
|
runAsNonRoot: true
|
||||||
|
runAsUser: 1001
|
||||||
|
containers:
|
||||||
|
- image: busybox # override this with a cloud-specific image
|
||||||
|
name: sync
|
||||||
|
envFrom:
|
||||||
|
- configMapRef:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
env:
|
||||||
|
- name: RECONCILE_SH # override this env var with a shell function in a kustomize patch
|
||||||
|
value: |-
|
||||||
|
reconcile() {
|
||||||
|
echo reconciling...
|
||||||
|
}
|
||||||
|
command:
|
||||||
|
- bash
|
||||||
|
- -ceu
|
||||||
|
- |-
|
||||||
|
# template reconcile() into the script
|
||||||
|
# env var is expanded by k8s before the pod starts
|
||||||
|
$(RECONCILE_SH)
|
||||||
|
|
||||||
|
apply-secret() {
|
||||||
|
/kbin/kubectl create secret generic "${1}" \
|
||||||
|
--from-literal=token="${2}" \
|
||||||
|
--from-literal=address="${3}" \
|
||||||
|
--dry-run=client -o=yaml \
|
||||||
|
| grep -v "creationTimestamp:" \
|
||||||
|
| /kbin/kubectl apply -f -
|
||||||
|
}
|
||||||
|
|
||||||
|
pause_loop() {
|
||||||
|
sleep "${SYNC_PERIOD:-3600}" || true
|
||||||
|
}
|
||||||
|
|
||||||
|
graceful_exit() {
|
||||||
|
echo "Trapped signal -- $(date)"
|
||||||
|
job_ids="$(
|
||||||
|
jobs \
|
||||||
|
| grep "pause_loop" \
|
||||||
|
| cut -d] -f1 \
|
||||||
|
| tr [ %
|
||||||
|
)"
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
if [ "${job_ids}" ]; then
|
||||||
|
kill ${job_ids}
|
||||||
|
fi
|
||||||
|
wait
|
||||||
|
echo "Graceful exit -- $(date)"
|
||||||
|
}
|
||||||
|
|
||||||
|
trap graceful_exit INT TERM
|
||||||
|
|
||||||
|
echo "Loop started (period: ${SYNC_PERIOD} s) -- $(date)"
|
||||||
|
while true; do
|
||||||
|
reconcile & wait $!
|
||||||
|
pause_loop & wait $!
|
||||||
|
done
|
||||||
|
resources: {}
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: /.azure
|
||||||
|
name: cache-volume
|
||||||
|
volumes:
|
||||||
|
- emptyDir: {}
|
||||||
|
name: cache-volume
|
||||||
|
|
||||||
|
# RBAC necessary for our Deployment to apply our secret that will store the JWT token
|
||||||
|
---
|
||||||
|
kind: Role
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
namespace: flux-system
|
||||||
|
rules:
|
||||||
|
- apiGroups: [""]
|
||||||
|
resources:
|
||||||
|
- secrets
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- create
|
||||||
|
- update
|
||||||
|
- patch
|
||||||
|
# Lock this down to the specific Secret name (Optional)
|
||||||
|
#resourceNames:
|
||||||
|
# - $(KUBE_SECRET) # templated from kustomize vars referencing ConfigMap, also see kustomizeconfig.yaml
|
||||||
|
---
|
||||||
|
kind: RoleBinding
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
namespace: flux-system
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
roleRef:
|
||||||
|
kind: Role
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
namespace: flux-system
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
apiVersion: batch/v1beta1
|
apiVersion: batch/v1beta1
|
||||||
kind: CronJob
|
kind: CronJob
|
||||||
metadata:
|
metadata:
|
||||||
name: credentials-sync
|
name: credentials-sync-eventhub
|
||||||
namespace: flux-system
|
namespace: flux-system
|
||||||
spec:
|
spec:
|
||||||
jobTemplate:
|
jobTemplate:
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
|
||||||
|
commonLabels:
|
||||||
|
app: credentials-sync-eventhub
|
||||||
|
|
||||||
|
resources:
|
||||||
|
- sync.yaml
|
||||||
|
|
||||||
|
patchesStrategicMerge:
|
||||||
|
- kubectl-patch.yaml
|
||||||
|
|
||||||
|
vars:
|
||||||
|
- name: KUBE_SECRET
|
||||||
|
objref:
|
||||||
|
kind: ConfigMap
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
apiVersion: v1
|
||||||
|
fieldref:
|
||||||
|
fieldpath: data.KUBE_SECRET
|
||||||
|
|
||||||
|
configurations:
|
||||||
|
- kustomizeconfig.yaml
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
varReference:
|
||||||
|
- path: rules/resourceNames
|
||||||
|
kind: Role
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
data:
|
||||||
|
# Patch this ConfigMap with additional values needed for your cloud
|
||||||
|
KUBE_SECRET: webhook-url # does not yet exist -- will be created in the same Namespace
|
||||||
|
ADDRESS: "fluxv2" # the Azure Event Hub name
|
||||||
|
|
||||||
|
---
|
||||||
|
# This CronJob frequently fetches registry tokens and applies them as an imagePullSecret.
|
||||||
|
# note: CronJob scheduling can block cluster bootstraps and cold-reboots from obtaining registry tokens for a considerable time.
|
||||||
|
# To run the job immediately, do `kubectl create job --from=cronjob/credentials-sync-eventhub -n flux-system credentials-sync-eventhub-init`
|
||||||
|
apiVersion: batch/v1beta1
|
||||||
|
kind: CronJob
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
suspend: false
|
||||||
|
schedule: 0 */6 * * *
|
||||||
|
failedJobsHistoryLimit: 1
|
||||||
|
successfulJobsHistoryLimit: 1
|
||||||
|
jobTemplate:
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
serviceAccountName: credentials-sync-eventhub
|
||||||
|
securityContext:
|
||||||
|
runAsNonRoot: true
|
||||||
|
runAsUser: 1001
|
||||||
|
restartPolicy: Never
|
||||||
|
containers:
|
||||||
|
- image: busybox # override this with a cloud-specific image
|
||||||
|
name: sync
|
||||||
|
envFrom:
|
||||||
|
- configMapRef:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
env:
|
||||||
|
- name: RECONCILE_SH # override this env var with a shell function in a kustomize patch
|
||||||
|
value: |-
|
||||||
|
reconcile() {
|
||||||
|
echo reconciling...
|
||||||
|
}
|
||||||
|
command:
|
||||||
|
- bash
|
||||||
|
- -ceu
|
||||||
|
- |-
|
||||||
|
# template reconcile() into the script
|
||||||
|
# env var is expanded by k8s before the pod starts
|
||||||
|
$(RECONCILE_SH)
|
||||||
|
|
||||||
|
apply-secret() {
|
||||||
|
/kbin/kubectl create secret generic "${1}" \
|
||||||
|
--from-literal=token="${2}" \
|
||||||
|
--from-literal=address="${3}" \
|
||||||
|
--dry-run=client -o=yaml \
|
||||||
|
| grep -v "creationTimestamp:" \
|
||||||
|
| /kbin/kubectl apply -f -
|
||||||
|
}
|
||||||
|
|
||||||
|
reconcile
|
||||||
|
resources: {}
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: /.azure
|
||||||
|
name: cache-volume
|
||||||
|
volumes:
|
||||||
|
- emptyDir: {}
|
||||||
|
name: cache-volume
|
||||||
|
|
||||||
|
# RBAC necessary for our Deployment to apply our secret that will store the JWT token
|
||||||
|
---
|
||||||
|
kind: Role
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
namespace: flux-system
|
||||||
|
rules:
|
||||||
|
- apiGroups: [""]
|
||||||
|
resources:
|
||||||
|
- secrets
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- create
|
||||||
|
- update
|
||||||
|
- patch
|
||||||
|
# Lock this down to the specific Secret name (Optional)
|
||||||
|
resourceNames:
|
||||||
|
- $(KUBE_SECRET) # templated from kustomize vars referencing ConfigMap, also see kustomizeconfig.yaml
|
||||||
|
---
|
||||||
|
kind: RoleBinding
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
namespace: flux-system
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
roleRef:
|
||||||
|
kind: Role
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
namespace: flux-system
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
# This is a stub resource patched by config-patches.yaml, so that all config is visible in one file
|
||||||
|
---
|
||||||
|
apiVersion: aadpodidentity.k8s.io/v1
|
||||||
|
kind: AzureIdentity
|
||||||
|
metadata:
|
||||||
|
name: lab # if this is changed, also change in config-patches.yaml
|
||||||
|
namespace: flux-system
|
||||||
|
---
|
||||||
|
apiVersion: aadpodidentity.k8s.io/v1
|
||||||
|
kind: AzureIdentityBinding
|
||||||
|
metadata:
|
||||||
|
name: lab
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
azureIdentity: $(AZ_IDENTITY_NAME) # match the AzureIdentity name
|
||||||
|
selector: $(AZ_IDENTITY_NAME) # match the AzureIdentity name
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
data:
|
||||||
|
KUBE_SECRET: webhook-url # does not yet exist -- will be created in the same Namespace
|
||||||
|
ADDRESS: "fluxv2" # the Azure Event Hub name
|
||||||
|
|
||||||
|
# Create an identity in Azure and assign it a role to write to Azure Event Hub (note: the identity's resourceGroup should match the Azure Event Hub):
|
||||||
|
# az identity create -n eventhub-write
|
||||||
|
# az role assignment create --role eventhub --assignee-object-id "$(az identity show -n eventhub-write -o tsv --query principalId)"
|
||||||
|
# Fetch the clientID and resourceID to configure the AzureIdentity spec below:
|
||||||
|
# az identity show -n eventhub-write -otsv --query clientId
|
||||||
|
# az identity show -n eventhub-write -otsv --query resourceId
|
||||||
|
---
|
||||||
|
apiVersion: aadpodidentity.k8s.io/v1
|
||||||
|
kind: AzureIdentity
|
||||||
|
metadata:
|
||||||
|
name: lab
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
clientID: 82d01fb0-7799-4d9d-92c7-21e7632c0000
|
||||||
|
resourceID: /subscriptions/82d01fb0-7799-4d9d-92c7-21e7632c0000/resourceGroups/stealthybox/providers/Microsoft.ManagedIdentity/userAssignedIdentities/eventhub-write
|
||||||
|
type: 0
|
||||||
|
|
||||||
|
# Set the reconcile period + specify the pod-identity via the aadpodidbinding label
|
||||||
|
---
|
||||||
|
apiVersion: batch/v1beta1
|
||||||
|
kind: CronJob
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
schedule: 0 * * * * # JWT tokens expire every 24 hours; refresh faster than that
|
||||||
|
jobTemplate:
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
aadpodidbinding: $(AZ_IDENTITY_NAME) # match the AzureIdentity name
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
|
||||||
|
namePrefix: jwt-
|
||||||
|
commonLabels:
|
||||||
|
app: jwt-eventhub-credentials-sync
|
||||||
|
|
||||||
|
namespace: flux-system
|
||||||
|
|
||||||
|
bases:
|
||||||
|
- ../_base
|
||||||
|
resources:
|
||||||
|
- az-identity.yaml
|
||||||
|
|
||||||
|
patchesStrategicMerge:
|
||||||
|
- config-patches.yaml
|
||||||
|
- reconcile-patch.yaml
|
||||||
|
|
||||||
|
vars:
|
||||||
|
- name: AZ_IDENTITY_NAME
|
||||||
|
objref:
|
||||||
|
kind: AzureIdentity
|
||||||
|
name: lab
|
||||||
|
apiVersion: aadpodidentity.k8s.io/v1
|
||||||
|
|
||||||
|
configurations:
|
||||||
|
- kustomizeconfig.yaml
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
varReference:
|
||||||
|
- path: spec/jobTemplate/spec/template/metadata/labels
|
||||||
|
kind: CronJob
|
||||||
|
- path: spec/azureIdentity
|
||||||
|
kind: AzureIdentityBinding
|
||||||
|
- path: spec/selector
|
||||||
|
kind: AzureIdentityBinding
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
apiVersion: batch/v1beta1
|
||||||
|
kind: CronJob
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
jobTemplate:
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: sync
|
||||||
|
image: mcr.microsoft.com/azure-cli
|
||||||
|
env:
|
||||||
|
- name: RECONCILE_SH
|
||||||
|
value: |-
|
||||||
|
reconcile() {
|
||||||
|
echo "Starting JWT token sync -- $(date)"
|
||||||
|
echo "Logging into Azure"
|
||||||
|
az login --identity
|
||||||
|
echo "Getting JWT token"
|
||||||
|
token=$(az account get-access-token --resource https://eventhubs.azure.net |jq -r .accessToken)
|
||||||
|
echo "Creating secret: ${KUBE_SECRET}"
|
||||||
|
apply-secret "${KUBE_SECRET}" ${token} "${ADDRESS}"
|
||||||
|
echo "Finished JWT token sync -- $(date)"
|
||||||
|
echo
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
data:
|
||||||
|
KUBE_SECRET: webhook-url # does not yet exist -- will be created in the same Namespace
|
||||||
|
ADDRESS: "fluxv2" # the Azure Event Hub name
|
||||||
|
|
||||||
|
# Create an identity in Azure and assign it a role to write to Azure Event Hub (note: the identity's resourceGroup should match the Azure Event Hub):
|
||||||
|
# az identity create -n eventhub-write
|
||||||
|
# az role assignment create --role eventhub --assignee-object-id "$(az identity show -n eventhub-write -o tsv --query principalId)"
|
||||||
|
# Fetch the clientID and resourceID to configure the AzureIdentity spec below:
|
||||||
|
# az identity show -n eventhub-write -otsv --query clientId
|
||||||
|
# az identity show -n eventhub-write -otsv --query resourceId
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
|
||||||
|
namePrefix: jwt-
|
||||||
|
commonLabels:
|
||||||
|
app: jwt-eventhub-credentials-sync
|
||||||
|
|
||||||
|
namespace: flux-system
|
||||||
|
|
||||||
|
bases:
|
||||||
|
- ../_base
|
||||||
|
resources:
|
||||||
|
- secret-azure-credentials.yaml
|
||||||
|
|
||||||
|
patchesStrategicMerge:
|
||||||
|
- config-patches.yaml
|
||||||
|
- reconcile-patch.yaml
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
apiVersion: batch/v1beta1
|
||||||
|
kind: CronJob
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
jobTemplate:
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: sync
|
||||||
|
image: mcr.microsoft.com/azure-cli
|
||||||
|
env:
|
||||||
|
- name: RECONCILE_SH
|
||||||
|
value: |-
|
||||||
|
reconcile() {
|
||||||
|
echo "Starting JWT token sync -- $(date)"
|
||||||
|
echo "Logging into Azure"
|
||||||
|
az login --service-principal -u ${AZURE_CLIENT_ID} -p ${AZURE_CLIENT_SECRET} --tenant ${AZURE_TENANT_ID}
|
||||||
|
echo "Getting JWT token"
|
||||||
|
token=$(az account get-access-token --resource https://eventhubs.azure.net |jq -r .accessToken)
|
||||||
|
echo "Creating secret: ${KUBE_SECRET}"
|
||||||
|
apply-secret "${KUBE_SECRET}" ${token} "${ADDRESS}"
|
||||||
|
echo "Finished JWT token sync -- $(date)"
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
- name: AZURE_CLIENT_ID
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: azure-credentials
|
||||||
|
key: AZURE_CLIENT_ID
|
||||||
|
- name: AZURE_CLIENT_SECRET
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: azure-credentials
|
||||||
|
key: AZURE_CLIENT_SECRET
|
||||||
|
- name: AZURE_TENANT_ID
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: azure-credentials
|
||||||
|
key: AZURE_TENANT_ID
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
AZURE_CLIENT_ID: MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMA==
|
||||||
|
AZURE_CLIENT_SECRET: c28tbXVjaC1zZWNyZXQ=
|
||||||
|
AZURE_TENANT_ID: MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMA==
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: azure-credentials
|
||||||
|
namespace: flux-system
|
||||||
|
type: Opaque
|
||||||
|
# This is just a example secret, you should never store secrets in git.
|
||||||
|
# One way forward can be to use sealed-secrets or SOPS
|
||||||
|
# https://fluxcd.io/docs/guides/sealed-secrets/
|
||||||
|
# https://fluxcd.io/docs/guides/mozilla-sops/
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
# This is a stub resource patched by config-patches.yaml, so that all config is visible in one file
|
||||||
|
---
|
||||||
|
apiVersion: aadpodidentity.k8s.io/v1
|
||||||
|
kind: AzureIdentity
|
||||||
|
metadata:
|
||||||
|
name: lab # if this is changed, also change in config-patches.yaml
|
||||||
|
namespace: flux-system
|
||||||
|
---
|
||||||
|
apiVersion: aadpodidentity.k8s.io/v1
|
||||||
|
kind: AzureIdentityBinding
|
||||||
|
metadata:
|
||||||
|
name: lab # this can have a different name, but it's nice to keep them the same
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
azureIdentity: $(AZ_IDENTITY_NAME) # match the AzureIdentity name
|
||||||
|
selector: $(AZ_IDENTITY_NAME) # match the AzureIdentity name
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
data:
|
||||||
|
KUBE_SECRET: webhook-url # does not yet exist -- will be created in the same Namespace
|
||||||
|
ADDRESS: "fluxv2" # the Azure Event Hub name
|
||||||
|
SYNC_PERIOD: "3600" # tokens expire; refresh faster than that
|
||||||
|
|
||||||
|
# Create an identity in Azure and assign it a role to write to Azure Event Hub (note: the identity's resourceGroup should match the Azure Event Hub):
|
||||||
|
# az identity create -n eventhub-write
|
||||||
|
# az role assignment create --role eventhub --assignee-object-id "$(az identity show -n eventhub-write -o tsv --query principalId)"
|
||||||
|
# Fetch the clientID and resourceID to configure the AzureIdentity spec below:
|
||||||
|
# az identity show -n eventhub-write -otsv --query clientId
|
||||||
|
# az identity show -n eventhub-write -otsv --query resourceId
|
||||||
|
---
|
||||||
|
apiVersion: aadpodidentity.k8s.io/v1
|
||||||
|
kind: AzureIdentity
|
||||||
|
metadata:
|
||||||
|
name: lab
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
clientID: 82d01fb0-7799-4d9d-92c7-21e7632c0000
|
||||||
|
resourceID: /subscriptions/82d01fb0-7799-4d9d-92c7-21e7632c0000/resourceGroups/stealthybox/providers/Microsoft.ManagedIdentity/userAssignedIdentities/eventhub-write
|
||||||
|
type: 0
|
||||||
|
|
||||||
|
# Specify the pod-identity via the aadpodidbinding label
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
aadpodidbinding: $(AZ_IDENTITY_NAME) # match the AzureIdentity name
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
|
||||||
|
namePrefix: jwt-
|
||||||
|
commonLabels:
|
||||||
|
app: jwt-eventhub-credentials-sync
|
||||||
|
|
||||||
|
namespace: flux-system
|
||||||
|
|
||||||
|
bases:
|
||||||
|
- ../_base
|
||||||
|
resources:
|
||||||
|
- az-identity.yaml
|
||||||
|
|
||||||
|
patchesStrategicMerge:
|
||||||
|
- config-patches.yaml
|
||||||
|
- reconcile-patch.yaml
|
||||||
|
|
||||||
|
vars:
|
||||||
|
- name: AZ_IDENTITY_NAME
|
||||||
|
objref:
|
||||||
|
kind: AzureIdentity
|
||||||
|
name: lab
|
||||||
|
apiVersion: aadpodidentity.k8s.io/v1
|
||||||
|
|
||||||
|
configurations:
|
||||||
|
- kustomizeconfig.yaml
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
varReference:
|
||||||
|
- path: spec/template/metadata/labels
|
||||||
|
kind: Deployment
|
||||||
|
- path: spec/azureIdentity
|
||||||
|
kind: AzureIdentityBinding
|
||||||
|
- path: spec/selector
|
||||||
|
kind: AzureIdentityBinding
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: sync
|
||||||
|
image: mcr.microsoft.com/azure-cli
|
||||||
|
env:
|
||||||
|
- name: RECONCILE_SH
|
||||||
|
value: |-
|
||||||
|
reconcile() {
|
||||||
|
echo "Starting JWT token sync -- $(date)"
|
||||||
|
echo "Logging into Azure"
|
||||||
|
az login --identity
|
||||||
|
echo "Getting JWT token"
|
||||||
|
token=$(az account get-access-token --resource https://eventhubs.azure.net |jq -r .accessToken)
|
||||||
|
echo "Creating secret: ${KUBE_SECRET}"
|
||||||
|
apply-secret "${KUBE_SECRET}" ${token} "${ADDRESS}"
|
||||||
|
echo "Finished JWT token sync -- $(date)"
|
||||||
|
echo
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
data:
|
||||||
|
KUBE_SECRET: webhook-url # does not yet exist -- will be created in the same Namespace
|
||||||
|
ADDRESS: "fluxv2" # the Azure Event Hub name
|
||||||
|
SYNC_PERIOD: "3600" # tokens expire; refresh faster than that
|
||||||
|
|
||||||
|
# Create an identity in Azure and assign it a role to write to Azure Event Hub (note: the identity's resourceGroup should match the Azure Event Hub):
|
||||||
|
# az identity create -n eventhub-write
|
||||||
|
# az role assignment create --role eventhub --assignee-object-id "$(az identity show -n eventhub-write -o tsv --query principalId)"
|
||||||
|
# Fetch the clientID and resourceID to configure the AzureIdentity spec below:
|
||||||
|
# az identity show -n eventhub-write -otsv --query clientId
|
||||||
|
# az identity show -n eventhub-write -otsv --query resourceId
|
||||||
|
# Specify the pod-identity via the aadpodidbinding label
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
|
||||||
|
namePrefix: jwt-
|
||||||
|
commonLabels:
|
||||||
|
app: jwt-eventhub-credentials-sync
|
||||||
|
|
||||||
|
namespace: flux-system
|
||||||
|
|
||||||
|
bases:
|
||||||
|
- ../_base
|
||||||
|
resources:
|
||||||
|
- secret-azure-credentials.yaml
|
||||||
|
|
||||||
|
patchesStrategicMerge:
|
||||||
|
- config-patches.yaml
|
||||||
|
- reconcile-patch.yaml
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync-eventhub
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: sync
|
||||||
|
image: mcr.microsoft.com/azure-cli
|
||||||
|
env:
|
||||||
|
- name: RECONCILE_SH
|
||||||
|
value: |-
|
||||||
|
reconcile() {
|
||||||
|
echo "Starting JWT token sync -- $(date)"
|
||||||
|
echo "Logging into Azure"
|
||||||
|
az login --service-principal -u ${AZURE_CLIENT_ID} -p ${AZURE_CLIENT_SECRET} --tenant ${AZURE_TENANT_ID}
|
||||||
|
echo "Getting JWT token"
|
||||||
|
token=$(az account get-access-token --resource https://eventhubs.azure.net |jq -r .accessToken)
|
||||||
|
echo "Creating secret: ${KUBE_SECRET}"
|
||||||
|
apply-secret "${KUBE_SECRET}" ${token} "${ADDRESS}"
|
||||||
|
echo "Finished JWT token sync -- $(date)"
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
- name: AZURE_CLIENT_ID
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: azure-credentials
|
||||||
|
key: AZURE_CLIENT_ID
|
||||||
|
- name: AZURE_CLIENT_SECRET
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: azure-credentials
|
||||||
|
key: AZURE_CLIENT_SECRET
|
||||||
|
- name: AZURE_TENANT_ID
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: azure-credentials
|
||||||
|
key: AZURE_TENANT_ID
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
AZURE_CLIENT_ID: MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMA==
|
||||||
|
AZURE_CLIENT_SECRET: c28tbXVjaC1zZWNyZXQ=
|
||||||
|
AZURE_TENANT_ID: MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMA==
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: azure-credentials
|
||||||
|
namespace: flux-system
|
||||||
|
type: Opaque
|
||||||
|
# This is just a example secret, you should never store secrets in git.
|
||||||
|
# One way forward can be to use sealed-secrets or SOPS
|
||||||
|
# https://fluxcd.io/docs/guides/sealed-secrets/
|
||||||
|
# https://fluxcd.io/docs/guides/mozilla-sops/
|
||||||
@@ -7,6 +7,9 @@ commonLabels:
|
|||||||
resources:
|
resources:
|
||||||
- sync.yaml
|
- sync.yaml
|
||||||
|
|
||||||
|
patchesStrategicMerge:
|
||||||
|
- kubectl-patch.yaml
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
- name: KUBE_SECRET
|
- name: KUBE_SECRET
|
||||||
objref:
|
objref:
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ spec:
|
|||||||
type: Recreate
|
type: Recreate
|
||||||
template:
|
template:
|
||||||
spec:
|
spec:
|
||||||
serviceAccount: credentials-sync
|
serviceAccountName: credentials-sync
|
||||||
containers:
|
containers:
|
||||||
- image: busybox # override this with a cloud-specific image
|
- image: busybox # override this with a cloud-specific image
|
||||||
name: sync
|
name: sync
|
||||||
@@ -102,8 +102,8 @@ rules:
|
|||||||
- update
|
- update
|
||||||
- patch
|
- patch
|
||||||
# # Lock this down to the specific Secret name (Optional)
|
# # Lock this down to the specific Secret name (Optional)
|
||||||
resourceNames:
|
#resourceNames:
|
||||||
- $(KUBE_SECRET) # templated from kustomize vars referencing ConfigMap, also see kustomizeconfig.yaml
|
#- $(KUBE_SECRET) # templated from kustomize vars referencing ConfigMap, also see kustomizeconfig.yaml
|
||||||
---
|
---
|
||||||
kind: RoleBinding
|
kind: RoleBinding
|
||||||
apiVersion: rbac.authorization.k8s.io/v1
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ commonLabels:
|
|||||||
resources:
|
resources:
|
||||||
- sync.yaml
|
- sync.yaml
|
||||||
|
|
||||||
|
patchesStrategicMerge:
|
||||||
|
- kubectl-patch.yaml
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
- name: KUBE_SECRET
|
- name: KUBE_SECRET
|
||||||
objref:
|
objref:
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ spec:
|
|||||||
|
|
||||||
apply-secret() {
|
apply-secret() {
|
||||||
/kbin/kubectl create secret docker-registry "${1}" \
|
/kbin/kubectl create secret docker-registry "${1}" \
|
||||||
--docker-passwrod="${2}" \
|
--docker-password="${2}" \
|
||||||
--docker-username="${3}" \
|
--docker-username="${3}" \
|
||||||
--docker-server="${4}" \
|
--docker-server="${4}" \
|
||||||
--dry-run=client -o=yaml \
|
--dry-run=client -o=yaml \
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ bases:
|
|||||||
|
|
||||||
patchesStrategicMerge:
|
patchesStrategicMerge:
|
||||||
- config-patches.yaml
|
- config-patches.yaml
|
||||||
- kubectl-patch.yaml
|
|
||||||
- reconcile-patch.yaml
|
- reconcile-patch.yaml
|
||||||
|
|
||||||
## uncomment if using encrypted-secret.yaml
|
## uncomment if using encrypted-secret.yaml
|
||||||
|
|||||||
@@ -5,3 +5,12 @@ kind: AzureIdentity
|
|||||||
metadata:
|
metadata:
|
||||||
name: credentials-sync # if this is changed, also change in config-patches.yaml
|
name: credentials-sync # if this is changed, also change in config-patches.yaml
|
||||||
namespace: flux-system
|
namespace: flux-system
|
||||||
|
---
|
||||||
|
apiVersion: aadpodidentity.k8s.io/v1
|
||||||
|
kind: AzureIdentityBinding
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync # this can have a different name, but it's nice to keep them the same
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
azureIdentity: $(AZ_IDENTITY_NAME) # match the AzureIdentity name
|
||||||
|
selector: $(AZ_IDENTITY_NAME) # match the AzureIdentity name
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ resources:
|
|||||||
|
|
||||||
patchesStrategicMerge:
|
patchesStrategicMerge:
|
||||||
- config-patches.yaml
|
- config-patches.yaml
|
||||||
- kubectl-patch.yaml
|
|
||||||
- reconcile-patch.yaml
|
- reconcile-patch.yaml
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
varReference:
|
varReference:
|
||||||
- path: spec/jobTemplate/spec/template/metadata/labels
|
- path: spec/jobTemplate/spec/template/metadata/labels
|
||||||
kind: Deployment
|
kind: CronJob
|
||||||
|
- path: spec/azureIdentity
|
||||||
|
kind: AzureIdentityBinding
|
||||||
|
- path: spec/selector
|
||||||
|
kind: AzureIdentityBinding
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: sync
|
- name: sync
|
||||||
image: aws/aws-cli
|
image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
|
||||||
env:
|
env:
|
||||||
- name: RECONCILE_SH
|
- name: RECONCILE_SH
|
||||||
value: |-
|
value: |-
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ bases:
|
|||||||
|
|
||||||
patchesStrategicMerge:
|
patchesStrategicMerge:
|
||||||
- config-patches.yaml
|
- config-patches.yaml
|
||||||
- kubectl-patch.yaml
|
|
||||||
- reconcile-patch.yaml
|
- reconcile-patch.yaml
|
||||||
|
|
||||||
## uncomment if using encrypted-secret.yaml
|
## uncomment if using encrypted-secret.yaml
|
||||||
|
|||||||
@@ -5,3 +5,12 @@ kind: AzureIdentity
|
|||||||
metadata:
|
metadata:
|
||||||
name: credentials-sync # if this is changed, also change in config-patches.yaml
|
name: credentials-sync # if this is changed, also change in config-patches.yaml
|
||||||
namespace: flux-system
|
namespace: flux-system
|
||||||
|
---
|
||||||
|
apiVersion: aadpodidentity.k8s.io/v1
|
||||||
|
kind: AzureIdentityBinding
|
||||||
|
metadata:
|
||||||
|
name: credentials-sync # this can have a different name, but it's nice to keep them the same
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
azureIdentity: $(AZ_IDENTITY_NAME) # match the AzureIdentity name
|
||||||
|
selector: $(AZ_IDENTITY_NAME) # match the AzureIdentity name
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
apiVersion: apps/v1
|
|
||||||
kind: Deployment
|
|
||||||
metadata:
|
|
||||||
name: credentials-sync
|
|
||||||
namespace: flux-system
|
|
||||||
spec:
|
|
||||||
template:
|
|
||||||
spec:
|
|
||||||
initContainers:
|
|
||||||
- image: bitnami/kubectl
|
|
||||||
name: copy-kubectl
|
|
||||||
# it's okay to do this because kubectl is a statically linked binary
|
|
||||||
command:
|
|
||||||
- sh
|
|
||||||
- -ceu
|
|
||||||
- cp $(which kubectl) /kbin/
|
|
||||||
resources: {}
|
|
||||||
volumeMounts:
|
|
||||||
- name: kbin
|
|
||||||
mountPath: /kbin
|
|
||||||
containers:
|
|
||||||
- name: sync
|
|
||||||
volumeMounts:
|
|
||||||
- name: kbin
|
|
||||||
mountPath: /kbin
|
|
||||||
volumes:
|
|
||||||
- name: kbin
|
|
||||||
emptyDir: {}
|
|
||||||
@@ -14,7 +14,6 @@ resources:
|
|||||||
|
|
||||||
patchesStrategicMerge:
|
patchesStrategicMerge:
|
||||||
- config-patches.yaml
|
- config-patches.yaml
|
||||||
- kubectl-patch.yaml
|
|
||||||
- reconcile-patch.yaml
|
- reconcile-patch.yaml
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
varReference:
|
varReference:
|
||||||
- path: spec/template/metadata/labels
|
- path: spec/template/metadata/labels
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
|
- path: spec/azureIdentity
|
||||||
|
kind: AzureIdentityBinding
|
||||||
|
- path: spec/selector
|
||||||
|
kind: AzureIdentityBinding
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: sync
|
- name: sync
|
||||||
image: aws/aws-cli
|
image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
|
||||||
env:
|
env:
|
||||||
- name: RECONCILE_SH
|
- name: RECONCILE_SH
|
||||||
value: |-
|
value: |-
|
||||||
|
|||||||
@@ -482,16 +482,20 @@
|
|||||||
"job": true,
|
"job": true,
|
||||||
"kubernetes_namespace": true,
|
"kubernetes_namespace": true,
|
||||||
"kubernetes_pod_name": true,
|
"kubernetes_pod_name": true,
|
||||||
"namespace": true,
|
|
||||||
"pod_template_hash": true,
|
"pod_template_hash": true,
|
||||||
"status": true,
|
"status": true,
|
||||||
"type": true
|
"type": true,
|
||||||
|
"pod": true,
|
||||||
|
"container": true,
|
||||||
|
"endpoint": true,
|
||||||
|
"exported_namespace": true
|
||||||
},
|
},
|
||||||
"indexByName": {},
|
"indexByName": {},
|
||||||
"renameByName": {
|
"renameByName": {
|
||||||
"Value": "Status",
|
"Value": "Status",
|
||||||
"kind": "Kind",
|
"kind": "Kind",
|
||||||
"name": "Name"
|
"name": "Name",
|
||||||
|
"namespace": "Namespace"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -594,15 +598,19 @@
|
|||||||
"job": true,
|
"job": true,
|
||||||
"kubernetes_namespace": true,
|
"kubernetes_namespace": true,
|
||||||
"kubernetes_pod_name": true,
|
"kubernetes_pod_name": true,
|
||||||
"namespace": true,
|
|
||||||
"pod_template_hash": true,
|
"pod_template_hash": true,
|
||||||
|
"pod": true,
|
||||||
"status": true,
|
"status": true,
|
||||||
"type": true
|
"type": true,
|
||||||
|
"container": true,
|
||||||
|
"endpoint": true,
|
||||||
|
"exported_namespace": true
|
||||||
},
|
},
|
||||||
"indexByName": {},
|
"indexByName": {},
|
||||||
"renameByName": {
|
"renameByName": {
|
||||||
"Value": "Status",
|
"Value": "Status",
|
||||||
"kind": "Kind",
|
"kind": "Kind",
|
||||||
|
"namespace": "Namespace",
|
||||||
"name": "Name"
|
"name": "Name"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -831,7 +839,7 @@
|
|||||||
"schemaVersion": 26,
|
"schemaVersion": 26,
|
||||||
"style": "light",
|
"style": "light",
|
||||||
"tags": [
|
"tags": [
|
||||||
"gitops-toolkit"
|
"flux"
|
||||||
],
|
],
|
||||||
"templating": {
|
"templating": {
|
||||||
"list": [
|
"list": [
|
||||||
|
|||||||
@@ -1356,7 +1356,7 @@
|
|||||||
"schemaVersion": 26,
|
"schemaVersion": 26,
|
||||||
"style": "light",
|
"style": "light",
|
||||||
"tags": [
|
"tags": [
|
||||||
"gitops-toolkit"
|
"flux"
|
||||||
],
|
],
|
||||||
"templating": {
|
"templating": {
|
||||||
"list": [
|
"list": [
|
||||||
@@ -1424,7 +1424,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"timezone": "",
|
"timezone": "",
|
||||||
"title": "GitOps Toolkit Control Plane",
|
"title": "Flux Control Plane",
|
||||||
"uid": "gitops-toolkit-control-plane",
|
"uid": "flux-control-plane",
|
||||||
"version": 1
|
"version": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
namespace: monitoring
|
||||||
|
resources:
|
||||||
|
- namespace.yaml
|
||||||
|
- repository.yaml
|
||||||
|
- release.yaml
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: monitoring
|
||||||
29
manifests/monitoring/kube-prometheus-stack/release.yaml
Normal file
29
manifests/monitoring/kube-prometheus-stack/release.yaml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
apiVersion: helm.toolkit.fluxcd.io/v2beta1
|
||||||
|
kind: HelmRelease
|
||||||
|
metadata:
|
||||||
|
name: kube-prometheus-stack
|
||||||
|
spec:
|
||||||
|
interval: 5m
|
||||||
|
chart:
|
||||||
|
spec:
|
||||||
|
chart: kube-prometheus-stack
|
||||||
|
sourceRef:
|
||||||
|
kind: HelmRepository
|
||||||
|
name: prometheus-community
|
||||||
|
interval: 1m
|
||||||
|
install:
|
||||||
|
crds: Create
|
||||||
|
upgrade:
|
||||||
|
crds: CreateReplace
|
||||||
|
values:
|
||||||
|
alertmanager:
|
||||||
|
enabled: false
|
||||||
|
grafana:
|
||||||
|
sidecar:
|
||||||
|
dashboards:
|
||||||
|
searchNamespace: ALL
|
||||||
|
prometheus:
|
||||||
|
prometheusSpec:
|
||||||
|
podMonitorSelector:
|
||||||
|
matchLabels:
|
||||||
|
app.kubernetes.io/part-of: flux
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
apiVersion: source.toolkit.fluxcd.io/v1beta1
|
||||||
|
kind: HelmRepository
|
||||||
|
metadata:
|
||||||
|
name: prometheus-community
|
||||||
|
spec:
|
||||||
|
interval: 1m
|
||||||
|
url: https://prometheus-community.github.io/helm-charts
|
||||||
13
manifests/monitoring/monitoring-config/kustomization.yaml
Normal file
13
manifests/monitoring/monitoring-config/kustomization.yaml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
namespace: flux-system
|
||||||
|
resources:
|
||||||
|
- podmonitor.yaml
|
||||||
|
configMapGenerator:
|
||||||
|
- name: flux-grafana-dashboards
|
||||||
|
files:
|
||||||
|
- ../grafana/dashboards/control-plane.json
|
||||||
|
- ../grafana/dashboards/cluster.json
|
||||||
|
options:
|
||||||
|
labels:
|
||||||
|
grafana_dashboard: flux-system
|
||||||
24
manifests/monitoring/monitoring-config/podmonitor.yaml
Normal file
24
manifests/monitoring/monitoring-config/podmonitor.yaml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
apiVersion: monitoring.coreos.com/v1
|
||||||
|
kind: PodMonitor
|
||||||
|
metadata:
|
||||||
|
name: flux-system
|
||||||
|
namespace: flux-system
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/part-of: flux
|
||||||
|
spec:
|
||||||
|
namespaceSelector:
|
||||||
|
matchNames:
|
||||||
|
- flux-system
|
||||||
|
selector:
|
||||||
|
matchExpressions:
|
||||||
|
- key: app
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- helm-controller
|
||||||
|
- source-controller
|
||||||
|
- kustomize-controller
|
||||||
|
- notification-controller
|
||||||
|
- image-automation-controller
|
||||||
|
- image-reflector-controller
|
||||||
|
podMetricsEndpoints:
|
||||||
|
- targetPort: http-prom
|
||||||
@@ -26,9 +26,11 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/filesys"
|
"sigs.k8s.io/kustomize/api/filesys"
|
||||||
"sigs.k8s.io/kustomize/api/krusty"
|
"sigs.k8s.io/kustomize/api/krusty"
|
||||||
|
kustypes "sigs.k8s.io/kustomize/api/types"
|
||||||
|
|
||||||
"github.com/fluxcd/pkg/untar"
|
"github.com/fluxcd/pkg/untar"
|
||||||
)
|
)
|
||||||
@@ -113,7 +115,14 @@ func generate(base string, options Options) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var kustomizeBuildMutex sync.Mutex
|
||||||
|
|
||||||
func build(base, output string) error {
|
func build(base, output string) error {
|
||||||
|
// TODO(stefan): temporary workaround for concurrent map read and map write bug
|
||||||
|
// https://github.com/kubernetes-sigs/kustomize/issues/3659
|
||||||
|
kustomizeBuildMutex.Lock()
|
||||||
|
defer kustomizeBuildMutex.Unlock()
|
||||||
|
|
||||||
kfile := filepath.Join(base, "kustomization.yaml")
|
kfile := filepath.Join(base, "kustomization.yaml")
|
||||||
|
|
||||||
fs := filesys.MakeFsOnDisk()
|
fs := filesys.MakeFsOnDisk()
|
||||||
@@ -137,10 +146,16 @@ func build(base, output string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
opt := krusty.MakeDefaultOptions()
|
buildOptions := &krusty.Options{
|
||||||
opt.DoLegacyResourceSort = true
|
DoLegacyResourceSort: true,
|
||||||
k := krusty.MakeKustomizer(fs, opt)
|
LoadRestrictions: kustypes.LoadRestrictionsNone,
|
||||||
m, err := k.Run(base)
|
AddManagedbyLabel: false,
|
||||||
|
DoPrune: false,
|
||||||
|
PluginConfig: kustypes.DisabledPluginConfig(),
|
||||||
|
}
|
||||||
|
|
||||||
|
k := krusty.MakeKustomizer(buildOptions)
|
||||||
|
m, err := k.Run(fs, base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/k8sdeps/kunstruct"
|
|
||||||
"sigs.k8s.io/kustomize/api/konfig"
|
"sigs.k8s.io/kustomize/api/konfig"
|
||||||
|
"sigs.k8s.io/kustomize/api/provider"
|
||||||
kustypes "sigs.k8s.io/kustomize/api/types"
|
kustypes "sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
@@ -35,7 +35,8 @@ func Generate(options Options) (*manifestgen.Manifest, error) {
|
|||||||
|
|
||||||
scan := func(base string) ([]string, error) {
|
scan := func(base string) ([]string, error) {
|
||||||
var paths []string
|
var paths []string
|
||||||
uf := kunstruct.NewKunstructuredFactoryImpl()
|
pvd := provider.NewDefaultDepProvider()
|
||||||
|
rf := pvd.GetResourceFactory()
|
||||||
err := options.FileSystem.Walk(base, func(path string, info os.FileInfo, err error) error {
|
err := options.FileSystem.Walk(base, func(path string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -58,7 +59,7 @@ func Generate(options Options) (*manifestgen.Manifest, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := uf.SliceFromBytes(fContents); err != nil {
|
if _, err := rf.SliceFromBytes(fContents); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
paths = append(paths, path)
|
paths = append(paths, path)
|
||||||
|
|||||||
Reference in New Issue
Block a user