Merge pull request #5519 from fluxcd/source-watcher

Add the source-watcher controller to the Flux distribution
main
Stefan Prodan 13 hours ago committed by GitHub
commit 46aa068fda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -97,7 +97,7 @@ func init() {
bootstrapCmd.PersistentFlags().StringSliceVar(&bootstrapArgs.defaultComponents, "components", rootArgs.defaults.Components,
"list of components, accepts comma-separated values")
bootstrapCmd.PersistentFlags().StringSliceVar(&bootstrapArgs.extraComponents, "components-extra", nil,
"list of components in addition to those supplied or defaulted, accepts values such as 'image-reflector-controller,image-automation-controller'")
"list of components in addition to those supplied or defaulted, accepts values such as 'image-reflector-controller,image-automation-controller,source-watcher'")
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.registry, "registry", "ghcr.io/fluxcd",
"container registry where the Flux controller images are published")

@ -83,7 +83,7 @@ type installFlags struct {
force bool
}
var installArgs = NewInstallFlags()
var installArgs = newInstallFlags()
func init() {
installCmd.Flags().BoolVar(&installArgs.export, "export", false,
@ -93,7 +93,7 @@ func init() {
installCmd.Flags().StringSliceVar(&installArgs.defaultComponents, "components", rootArgs.defaults.Components,
"list of components, accepts comma-separated values")
installCmd.Flags().StringSliceVar(&installArgs.extraComponents, "components-extra", nil,
"list of components in addition to those supplied or defaulted, accepts values such as 'image-reflector-controller,image-automation-controller'")
"list of components in addition to those supplied or defaulted, accepts values such as 'image-reflector-controller,image-automation-controller,source-watcher'")
installCmd.Flags().StringVar(&installArgs.manifestsPath, "manifests", "", "path to the manifest directory")
installCmd.Flags().StringVar(&installArgs.registry, "registry", rootArgs.defaults.Registry,
"container registry where the toolkit images are published")
@ -115,9 +115,14 @@ func init() {
rootCmd.AddCommand(installCmd)
}
func NewInstallFlags() installFlags {
func newInstallFlags() installFlags {
return installFlags{
logLevel: flags.LogLevel(rootArgs.defaults.LogLevel),
logLevel: flags.LogLevel(rootArgs.defaults.LogLevel),
defaultComponents: rootArgs.defaults.Components,
registry: rootArgs.defaults.Registry,
watchAllNamespaces: rootArgs.defaults.WatchAllNamespaces,
networkPolicy: rootArgs.defaults.NetworkPolicy,
clusterDomain: rootArgs.defaults.ClusterDomain,
}
}
@ -195,10 +200,13 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
}
if installArgs.export {
fmt.Print(manifest.Content)
return nil
_, err = rootCmd.OutOrStdout().Write([]byte(manifest.Content))
return err
} else if rootArgs.verbose {
fmt.Print(manifest.Content)
_, err = rootCmd.OutOrStdout().Write([]byte(manifest.Content))
if err != nil {
return err
}
}
logger.Successf("manifests build completed")

@ -1,5 +1,5 @@
/*
Copyright 2022 The Flux authors
Copyright 2025 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.
@ -16,7 +16,17 @@ limitations under the License.
package main
import "testing"
import (
"strings"
"testing"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
ssautil "github.com/fluxcd/pkg/ssa/utils"
"github.com/fluxcd/flux2/v2/pkg/manifestgen/install"
)
func TestInstall(t *testing.T) {
// The pointer to kubeconfigArgs.Namespace is shared across
@ -59,3 +69,43 @@ func TestInstall(t *testing.T) {
})
}
}
func TestInstall_ComponentsExtra(t *testing.T) {
g := NewWithT(t)
command := "install --export --components-extra=" +
strings.Join(install.MakeDefaultOptions().ComponentsExtra, ",")
output, err := executeCommand(command)
g.Expect(err).NotTo(HaveOccurred())
manifests, err := ssautil.ReadObjects(strings.NewReader(output))
g.Expect(err).NotTo(HaveOccurred())
foundImageAutomation := false
foundImageReflector := false
foundSourceWatcher := false
foundExternalArtifact := false
for _, obj := range manifests {
if obj.GetKind() == "Deployment" && obj.GetName() == "image-automation-controller" {
foundImageAutomation = true
}
if obj.GetKind() == "Deployment" && obj.GetName() == "image-reflector-controller" {
foundImageReflector = true
}
if obj.GetKind() == "Deployment" && obj.GetName() == "source-watcher" {
foundSourceWatcher = true
}
if obj.GetKind() == "Deployment" &&
(obj.GetName() == "kustomize-controller" || obj.GetName() == "helm-controller") {
containers, _, _ := unstructured.NestedSlice(obj.Object, "spec", "template", "spec", "containers")
g.Expect(containers).ToNot(BeEmpty())
args, _, _ := unstructured.NestedSlice(containers[0].(map[string]any), "args")
g.Expect(args).To(ContainElement("--feature-gates=ExternalArtifact=true"))
foundExternalArtifact = true
}
}
g.Expect(foundImageAutomation).To(BeTrue(), "image-automation-controller deployment not found")
g.Expect(foundImageReflector).To(BeTrue(), "image-reflector-controller deployment not found")
g.Expect(foundSourceWatcher).To(BeTrue(), "source-watcher deployment not found")
g.Expect(foundExternalArtifact).To(BeTrue(), "ExternalArtifact feature gate not found")
}

@ -447,6 +447,7 @@ func resetCmdArgs() {
imagePolicyArgs = imagePolicyFlags{}
imageRepoArgs = imageRepoFlags{}
imageUpdateArgs = imageUpdateFlags{}
installArgs = newInstallFlags()
kustomizationArgs = NewKustomizationFlags()
receiverArgs = receiverFlags{}
resumeArgs = ResumeFlags{}

@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: source-watcher

@ -0,0 +1,15 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- https://github.com/fluxcd/source-watcher/releases/download/v2.0.0/source-watcher.crds.yaml
- https://github.com/fluxcd/source-watcher/releases/download/v2.0.0/source-watcher.deployment.yaml
- account.yaml
transformers:
- labels.yaml
patches:
- target:
group: apps
version: v1
kind: Deployment
name: source-watcher
path: patch.yaml

@ -0,0 +1,13 @@
apiVersion: builtin
kind: LabelTransformer
metadata:
name: labels
labels:
app.kubernetes.io/component: source-watcher
app.kubernetes.io/part-of: flux
fieldSpecs:
- path: metadata/labels
create: true
- kind: Deployment
path: spec/template/metadata/labels
create: true

@ -0,0 +1,17 @@
- op: add
path: /spec/template/spec/containers/0/args/0
value: --events-addr=http://notification-controller.flux-system.svc.cluster.local./
- op: add
path: /spec/template/spec/serviceAccountName
value: source-watcher
- op: add
path: /spec/template/spec/priorityClassName
value: system-cluster-critical
- op: add
path: /spec/template/spec/containers/0/env/-
value:
name: GOMEMLIMIT
valueFrom:
resourceFieldRef:
containerName: manager
resource: limits.memory

@ -7,3 +7,4 @@ resources:
- https://github.com/fluxcd/notification-controller/releases/download/v1.6.0/notification-controller.crds.yaml
- https://github.com/fluxcd/image-reflector-controller/releases/download/v1.0.0/image-reflector-controller.crds.yaml
- https://github.com/fluxcd/image-automation-controller/releases/download/v0.41.2/image-automation-controller.crds.yaml
- https://github.com/fluxcd/source-watcher/releases/download/v2.0.0/source-watcher.crds.yaml

@ -18,6 +18,9 @@ rules:
- apiGroups: ['image.toolkit.fluxcd.io']
resources: ['*']
verbs: ['*']
- apiGroups: ['source.extensions.fluxcd.io']
resources: ['*']
verbs: ['*']
- apiGroups:
- ""
resources:
@ -109,3 +112,6 @@ subjects:
- kind: ServiceAccount
name: image-automation-controller
namespace: flux-system
- kind: ServiceAccount
name: source-watcher
namespace: flux-system

@ -46,5 +46,5 @@ func TestGenerate(t *testing.T) {
t.Errorf("Generation warning '%s' not found", warning)
}
fmt.Println(output)
t.Log(output)
}

@ -44,7 +44,7 @@ func MakeDefaultOptions() Options {
Version: "latest",
Namespace: "flux-system",
Components: []string{"source-controller", "kustomize-controller", "helm-controller", "notification-controller"},
ComponentsExtra: []string{"image-reflector-controller", "image-automation-controller"},
ComponentsExtra: []string{"image-reflector-controller", "image-automation-controller", "source-watcher"},
EventsAddr: "",
Registry: "ghcr.io/fluxcd",
RegistryCredential: "",

@ -65,7 +65,7 @@ patches:
- op: replace
path: /spec/template/spec/containers/0/args/1
value: --log-level={{$logLevel}}
{{- else if eq $component "source-controller" }}
{{- else if or (eq $component "source-controller") (eq $component "source-watcher") }}
- target:
group: apps
version: v1
@ -102,7 +102,17 @@ patches:
value: --log-level={{$logLevel}}
{{- end }}
{{- end }}
{{- range $i, $component := .Components }}
{{- if eq $component "source-watcher" }}
- target:
kind: Deployment
name: "(kustomize-controller|helm-controller)"
patch: |-
- op: add
path: /spec/template/spec/containers/0/args/-
value: --feature-gates=ExternalArtifact=true
{{- end }}
{{- end }}
{{- if $registry }}
images:
{{- range $i, $component := .Components }}

Loading…
Cancel
Save