Skip to content

Commit 457abed

Browse files
committed
fix: validate --source flag in create kustomization command
Signed-off-by: Ghassan Malke <gmalke@shiftbase.com>
1 parent 5fc8afc commit 457abed

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

cmd/flux/create_kustomization.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
136136
if !strings.HasPrefix(kustomizationArgs.path.String(), "./") {
137137
return fmt.Errorf("path must begin with ./")
138138
}
139+
if kustomizationArgs.source.Name == "" {
140+
return fmt.Errorf("source is required")
141+
}
139142

140143
if !createArgs.export {
141144
logger.Generatef("generating Kustomization")
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//go:build unit
2+
// +build unit
3+
4+
/*
5+
Copyright 2026 The Flux authors
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
*/
19+
20+
package main
21+
22+
import "testing"
23+
24+
func TestCreateKustomization(t *testing.T) {
25+
tests := []struct {
26+
name string
27+
args string
28+
assert assertFunc
29+
}{
30+
{
31+
// A user creating a kustomization without --source gets a confusing
32+
// API-level error about spec.sourceRef.kind instead of a clear message.
33+
name: "missing source",
34+
args: "create kustomization my-app --path=./deploy --export",
35+
assert: assertError("source is required"),
36+
},
37+
}
38+
39+
for _, tt := range tests {
40+
t.Run(tt.name, func(t *testing.T) {
41+
cmd := cmdTestCase{
42+
args: tt.args,
43+
assert: tt.assert,
44+
}
45+
cmd.runTestCmd(t)
46+
})
47+
}
48+
}

0 commit comments

Comments
 (0)