Add source-watcher to the `install` and `bootstrap` commands

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
pull/5519/head
Stefan Prodan 16 hours ago
parent 0a87ed5a42
commit 3542d61afd
No known key found for this signature in database
GPG Key ID: 3299AEB0E4085BAF

@ -97,7 +97,7 @@ func init() {
bootstrapCmd.PersistentFlags().StringSliceVar(&bootstrapArgs.defaultComponents, "components", rootArgs.defaults.Components, bootstrapCmd.PersistentFlags().StringSliceVar(&bootstrapArgs.defaultComponents, "components", rootArgs.defaults.Components,
"list of components, accepts comma-separated values") "list of components, accepts comma-separated values")
bootstrapCmd.PersistentFlags().StringSliceVar(&bootstrapArgs.extraComponents, "components-extra", nil, 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", bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.registry, "registry", "ghcr.io/fluxcd",
"container registry where the Flux controller images are published") "container registry where the Flux controller images are published")

@ -83,7 +83,7 @@ type installFlags struct {
force bool force bool
} }
var installArgs = NewInstallFlags() var installArgs = newInstallFlags()
func init() { func init() {
installCmd.Flags().BoolVar(&installArgs.export, "export", false, installCmd.Flags().BoolVar(&installArgs.export, "export", false,
@ -93,7 +93,7 @@ func init() {
installCmd.Flags().StringSliceVar(&installArgs.defaultComponents, "components", rootArgs.defaults.Components, installCmd.Flags().StringSliceVar(&installArgs.defaultComponents, "components", rootArgs.defaults.Components,
"list of components, accepts comma-separated values") "list of components, accepts comma-separated values")
installCmd.Flags().StringSliceVar(&installArgs.extraComponents, "components-extra", nil, 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.manifestsPath, "manifests", "", "path to the manifest directory")
installCmd.Flags().StringVar(&installArgs.registry, "registry", rootArgs.defaults.Registry, installCmd.Flags().StringVar(&installArgs.registry, "registry", rootArgs.defaults.Registry,
"container registry where the toolkit images are published") "container registry where the toolkit images are published")
@ -115,9 +115,14 @@ func init() {
rootCmd.AddCommand(installCmd) rootCmd.AddCommand(installCmd)
} }
func NewInstallFlags() installFlags { func newInstallFlags() installFlags {
return 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 { if installArgs.export {
fmt.Print(manifest.Content) _, err = rootCmd.OutOrStdout().Write([]byte(manifest.Content))
return nil return err
} else if rootArgs.verbose { } 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") 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"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -16,7 +16,17 @@ limitations under the License.
package main 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) { func TestInstall(t *testing.T) {
// The pointer to kubeconfigArgs.Namespace is shared across // 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{} imagePolicyArgs = imagePolicyFlags{}
imageRepoArgs = imageRepoFlags{} imageRepoArgs = imageRepoFlags{}
imageUpdateArgs = imageUpdateFlags{} imageUpdateArgs = imageUpdateFlags{}
installArgs = newInstallFlags()
kustomizationArgs = NewKustomizationFlags() kustomizationArgs = NewKustomizationFlags()
receiverArgs = receiverFlags{} receiverArgs = receiverFlags{}
resumeArgs = ResumeFlags{} resumeArgs = ResumeFlags{}

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

@ -44,7 +44,7 @@ func MakeDefaultOptions() Options {
Version: "latest", Version: "latest",
Namespace: "flux-system", Namespace: "flux-system",
Components: []string{"source-controller", "kustomize-controller", "helm-controller", "notification-controller"}, 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: "", EventsAddr: "",
Registry: "ghcr.io/fluxcd", Registry: "ghcr.io/fluxcd",
RegistryCredential: "", RegistryCredential: "",

@ -65,7 +65,7 @@ patches:
- op: replace - op: replace
path: /spec/template/spec/containers/0/args/1 path: /spec/template/spec/containers/0/args/1
value: --log-level={{$logLevel}} value: --log-level={{$logLevel}}
{{- else if eq $component "source-controller" }} {{- else if or (eq $component "source-controller") (eq $component "source-watcher") }}
- target: - target:
group: apps group: apps
version: v1 version: v1
@ -102,7 +102,17 @@ patches:
value: --log-level={{$logLevel}} value: --log-level={{$logLevel}}
{{- end }} {{- end }}
{{- 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 }} {{- if $registry }}
images: images:
{{- range $i, $component := .Components }} {{- range $i, $component := .Components }}

Loading…
Cancel
Save