Break down function
@@ -570,24 +570,8 @@ func walk(dir string, force, enableJibInit bool) ([]string, []InitBuilder, error
}
filePath := filepath.Join(path, file.Name())
- if IsSkaffoldConfig(filePath) {
- if !force {
- return fmt.Errorf("pre-existing %s found", filePath)
- }
- logrus.Debugf("%s is a valid skaffold configuration: continuing since --force=true", filePath)
- continue
- }
-
- if IsSupportedKubernetesFileExtension(filePath) {
- potentialConfigs = append(potentialConfigs, filePath)
- continue
- }
-
- // try and parse build file
- if findBuilders {
- var builderConfigs []InitBuilder
- builderConfigs, findBuildersInDirectories = detectBuilders(enableJibInit, filePath)
- foundBuilders = append(foundBuilders, builderConfigs...)
+ if findBuildersInDirectories, err = checkFile(filePath, force, findBuilders, enableJibInit, &potentialConfigs, &foundBuilders); err != nil {
+ return err
}
}
@@ -608,3 +592,30 @@ func walk(dir string, force, enableJibInit bool) ([]string, []InitBuilder, error
}
return potentialConfigs, foundBuilders, nil
}
+
+// checkFile checks if filePath is a skaffold config, k8s config, or builder config. Detected k8s configs are added to potentialConfigs,
+// and builder configs are added to foundBuilders. Returns true if subdirectories should continue to be searched, or false if the search
+// should stop at this directory level (e.g. if a Jib config being found).
+func checkFile(filePath string, force, findBuilders, enableJibInit bool, potentialConfigs *[]string, foundBuilders *[]InitBuilder) (bool, error) {
+ if IsSkaffoldConfig(filePath) {
+ if !force {
+ return false, fmt.Errorf("pre-existing %s found", filePath)
+ }
+ logrus.Debugf("%s is a valid skaffold configuration: continuing since --force=true", filePath)
+ return findBuilders, nil
+ }
+
+ if IsSupportedKubernetesFileExtension(filePath) {
+ *potentialConfigs = append(*potentialConfigs, filePath)
+ return findBuilders, nil
+ }
+
+ // try and parse build file
+ if findBuilders {
+ builderConfigs, findBuildersInDirectories := detectBuilders(enableJibInit, filePath)
+ *foundBuilders = append(*foundBuilders, builderConfigs...)
+ return findBuildersInDirectories, nil
+ }
+
+ return findBuilders, nil
+}
