diff --git a/cmd/flux/build_kustomization.go b/cmd/flux/build_kustomization.go index dd10ea11..0c968ddf 100644 --- a/cmd/flux/build_kustomization.go +++ b/cmd/flux/build_kustomization.go @@ -88,12 +88,22 @@ func buildKsCmdRun(cmd *cobra.Command, args []string) (err error) { } } - builder, err := build.NewBuilder(name, buildKsArgs.path, - build.WithClientConfig(kubeconfigArgs, kubeclientOptions), - build.WithTimeout(rootArgs.timeout), - build.WithKustomizationFile(buildKsArgs.kustomizationFile), - build.WithDryRun(buildKsArgs.dryRun), - ) + var builder *build.Builder + if buildKsArgs.dryRun { + builder, err = build.NewBuilder(name, buildKsArgs.path, + build.WithTimeout(rootArgs.timeout), + build.WithKustomizationFile(buildKsArgs.kustomizationFile), + build.WithDryRun(buildKsArgs.dryRun), + build.WithNamespace(*kubeconfigArgs.Namespace), + ) + } else { + builder, err = build.NewBuilder(name, buildKsArgs.path, + build.WithClientConfig(kubeconfigArgs, kubeclientOptions), + build.WithTimeout(rootArgs.timeout), + build.WithKustomizationFile(buildKsArgs.kustomizationFile), + ) + } + if err != nil { return err } diff --git a/cmd/flux/testdata/build-kustomization/delete-service/hpa.yaml b/cmd/flux/testdata/build-kustomization/delete-service/hpa.yaml index 6bd46a2c..263e9128 100644 --- a/cmd/flux/testdata/build-kustomization/delete-service/hpa.yaml +++ b/cmd/flux/testdata/build-kustomization/delete-service/hpa.yaml @@ -1,4 +1,4 @@ -apiVersion: autoscaling/v2beta2 +apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: podinfo diff --git a/cmd/flux/testdata/build-kustomization/podinfo-result.yaml b/cmd/flux/testdata/build-kustomization/podinfo-result.yaml index e4646dd3..009347d8 100644 --- a/cmd/flux/testdata/build-kustomization/podinfo-result.yaml +++ b/cmd/flux/testdata/build-kustomization/podinfo-result.yaml @@ -77,7 +77,7 @@ spec: cpu: 100m memory: 64Mi --- -apiVersion: autoscaling/v2beta2 +apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: labels: diff --git a/cmd/flux/testdata/build-kustomization/podinfo-without-service-result.yaml b/cmd/flux/testdata/build-kustomization/podinfo-without-service-result.yaml index 943381c8..e1e1885f 100644 --- a/cmd/flux/testdata/build-kustomization/podinfo-without-service-result.yaml +++ b/cmd/flux/testdata/build-kustomization/podinfo-without-service-result.yaml @@ -77,7 +77,7 @@ spec: cpu: 100m memory: 64Mi --- -apiVersion: autoscaling/v2beta2 +apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: labels: diff --git a/cmd/flux/testdata/build-kustomization/podinfo/hpa.yaml b/cmd/flux/testdata/build-kustomization/podinfo/hpa.yaml index 6bd46a2c..263e9128 100644 --- a/cmd/flux/testdata/build-kustomization/podinfo/hpa.yaml +++ b/cmd/flux/testdata/build-kustomization/podinfo/hpa.yaml @@ -1,4 +1,4 @@ -apiVersion: autoscaling/v2beta2 +apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: podinfo diff --git a/internal/build/build.go b/internal/build/build.go index f4c3fca9..04befbc0 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -139,6 +139,14 @@ func WithClientConfig(rcg *genericclioptions.ConfigFlags, clientOpts *runclient. } } +// WithNamespace sets the namespace +func WithNamespace(namespace string) BuilderOptionFunc { + return func(b *Builder) error { + b.namespace = namespace + return nil + } +} + // WithDryRun sets the dry-run flag func WithDryRun(dryRun bool) BuilderOptionFunc { return func(b *Builder) error {