Skip to content

Commit 2c1085d

Browse files
committed
Fix dry-run still loading kubeconfig issue
If this is implemented, it will not assume that access to a kubeconfig is guaranteed even if just for retrieving configured namespace. Signed-off-by: Soule BA <[email protected]>
1 parent 49eb1c5 commit 2c1085d

File tree

6 files changed

+28
-10
lines changed

6 files changed

+28
-10
lines changed

cmd/flux/build_kustomization.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,22 @@ func buildKsCmdRun(cmd *cobra.Command, args []string) (err error) {
8888
}
8989
}
9090

91-
builder, err := build.NewBuilder(name, buildKsArgs.path,
92-
build.WithClientConfig(kubeconfigArgs, kubeclientOptions),
93-
build.WithTimeout(rootArgs.timeout),
94-
build.WithKustomizationFile(buildKsArgs.kustomizationFile),
95-
build.WithDryRun(buildKsArgs.dryRun),
96-
)
91+
var builder *build.Builder
92+
if buildKsArgs.dryRun {
93+
builder, err = build.NewBuilder(name, buildKsArgs.path,
94+
build.WithTimeout(rootArgs.timeout),
95+
build.WithKustomizationFile(buildKsArgs.kustomizationFile),
96+
build.WithDryRun(buildKsArgs.dryRun),
97+
build.WithNamespace(*kubeconfigArgs.Namespace),
98+
)
99+
} else {
100+
builder, err = build.NewBuilder(name, buildKsArgs.path,
101+
build.WithClientConfig(kubeconfigArgs, kubeclientOptions),
102+
build.WithTimeout(rootArgs.timeout),
103+
build.WithKustomizationFile(buildKsArgs.kustomizationFile),
104+
)
105+
}
106+
97107
if err != nil {
98108
return err
99109
}

cmd/flux/testdata/build-kustomization/delete-service/hpa.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: autoscaling/v2beta2
1+
apiVersion: autoscaling/v2
22
kind: HorizontalPodAutoscaler
33
metadata:
44
name: podinfo

cmd/flux/testdata/build-kustomization/podinfo-result.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ spec:
7777
cpu: 100m
7878
memory: 64Mi
7979
---
80-
apiVersion: autoscaling/v2beta2
80+
apiVersion: autoscaling/v2
8181
kind: HorizontalPodAutoscaler
8282
metadata:
8383
labels:

cmd/flux/testdata/build-kustomization/podinfo-without-service-result.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ spec:
7777
cpu: 100m
7878
memory: 64Mi
7979
---
80-
apiVersion: autoscaling/v2beta2
80+
apiVersion: autoscaling/v2
8181
kind: HorizontalPodAutoscaler
8282
metadata:
8383
labels:

cmd/flux/testdata/build-kustomization/podinfo/hpa.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: autoscaling/v2beta2
1+
apiVersion: autoscaling/v2
22
kind: HorizontalPodAutoscaler
33
metadata:
44
name: podinfo

internal/build/build.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ func WithClientConfig(rcg *genericclioptions.ConfigFlags, clientOpts *runclient.
139139
}
140140
}
141141

142+
// WithNamespace sets the namespace
143+
func WithNamespace(namespace string) BuilderOptionFunc {
144+
return func(b *Builder) error {
145+
b.namespace = namespace
146+
return nil
147+
}
148+
}
149+
142150
// WithDryRun sets the dry-run flag
143151
func WithDryRun(dryRun bool) BuilderOptionFunc {
144152
return func(b *Builder) error {

0 commit comments

Comments
 (0)