mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
fix: kustomize edit add component check (#24100)
Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com>
This commit is contained in:
@@ -365,15 +365,18 @@ func (k *kustomize) Build(opts *v1alpha1.ApplicationSourceKustomize, kustomizeOp
|
||||
foundComponents = append(foundComponents, c)
|
||||
}
|
||||
}
|
||||
args := []string{"edit", "add", "component"}
|
||||
args = append(args, foundComponents...)
|
||||
cmd := exec.Command(k.getBinaryPath(), args...)
|
||||
cmd.Dir = k.path
|
||||
cmd.Env = env
|
||||
commands = append(commands, executil.GetCommandArgsToLog(cmd))
|
||||
_, err := executil.Run(cmd)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
|
||||
if len(foundComponents) > 0 {
|
||||
args := []string{"edit", "add", "component"}
|
||||
args = append(args, foundComponents...)
|
||||
cmd := exec.Command(k.getBinaryPath(), args...)
|
||||
cmd.Dir = k.path
|
||||
cmd.Env = env
|
||||
commands = append(commands, executil.GetCommandArgsToLog(cmd))
|
||||
_, err := executil.Run(cmd)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -615,6 +615,26 @@ func TestFailKustomizeBuildPatches(t *testing.T) {
|
||||
require.EqualError(t, err, "kustomization file not found in the path")
|
||||
}
|
||||
|
||||
func TestKustomizeBuildComponentsNoFoundComponents(t *testing.T) {
|
||||
appPath, err := testDataDir(t, kustomization6)
|
||||
require.NoError(t, err)
|
||||
kustomize := NewKustomizeApp(appPath, appPath, git.NopCreds{}, "", "", "", "")
|
||||
|
||||
// Test with non-existent components and IgnoreMissingComponents = true
|
||||
// This should result in foundComponents being empty, so no "edit add component" command should be executed
|
||||
kustomizeSource := v1alpha1.ApplicationSourceKustomize{
|
||||
Components: []string{"./non-existent-component1", "./non-existent-component2"},
|
||||
IgnoreMissingComponents: true,
|
||||
}
|
||||
_, _, commands, err := kustomize.Build(&kustomizeSource, nil, nil, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Verify that no "edit add component" command was executed
|
||||
for _, cmd := range commands {
|
||||
assert.NotContains(t, cmd, "edit add component", "kustomize edit add component should not be invoked when foundComponents is empty")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_getImageParameters_sorted(t *testing.T) {
|
||||
apps := []*unstructured.Unstructured{
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user