Skip to content

Commit 151d217

Browse files
(helm/v1-alpha): Skip empty directories in chart generation
Previously, the scaffolding process would create empty directories in the Helm chart even when the corresponding source directory was missing or contained no YAML files. This commit updates the logic to check for the existence of the source directory and its contents before attempting to copy files. Changes: - Skip processing if the source directory does not exist. - Skip creating destination directories if no YAML files are found. - Ensure only relevant directories and files are included in the chart.
1 parent 8c817f5 commit 151d217

File tree

1 file changed

+14
-3
lines changed
  • pkg/plugins/optional/helm/v1alpha/scaffolds

1 file changed

+14
-3
lines changed

pkg/plugins/optional/helm/v1alpha/scaffolds/init.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,27 @@ func (s *initScaffolder) copyConfigFiles() error {
231231
}
232232

233233
for _, dir := range configDirs {
234-
// Ensure destination directory exists
235-
if err := os.MkdirAll(dir.DestDir, os.ModePerm); err != nil {
236-
return fmt.Errorf("failed to create directory %s: %v", dir.DestDir, err)
234+
// Check if the source directory exists
235+
if _, err := os.Stat(dir.SrcDir); os.IsNotExist(err) {
236+
// Skip if the source directory does not exist
237+
continue
237238
}
238239

239240
files, err := filepath.Glob(filepath.Join(dir.SrcDir, "*.yaml"))
240241
if err != nil {
241242
return err
242243
}
243244

245+
// Skip processing if the directory is empty (no matching files)
246+
if len(files) == 0 {
247+
continue
248+
}
249+
250+
// Ensure destination directory exists
251+
if err := os.MkdirAll(dir.DestDir, os.ModePerm); err != nil {
252+
return fmt.Errorf("failed to create directory %s: %v", dir.DestDir, err)
253+
}
254+
244255
for _, srcFile := range files {
245256
destFile := filepath.Join(dir.DestDir, filepath.Base(srcFile))
246257
err := copyFileWithHelmLogic(srcFile, destFile, dir.SubDir, s.config.GetProjectName())

0 commit comments

Comments
 (0)