func GetManifestFiles()

in pkg/safeguards/helpers.go [27:63]


func GetManifestFiles(manifestsPath string, opt chartutil.ReleaseOptions) ([]types.ManifestFile, error) {
	isDir, err := IsDirectory(manifestsPath)
	if err != nil {
		return nil, fmt.Errorf("not a valid file or directory: %w", err)
	}

	var manifestFiles []types.ManifestFile
	if isDir {
		// check if Helm or Kustomize dir
		if isHelm(true, manifestsPath) {
			return preprocessing.RenderHelmChart(false, manifestsPath, opt)
		} else if isKustomize(true, manifestsPath) {
			return preprocessing.RenderKustomizeManifest(manifestsPath)
		} else {
			manifestFiles, err = GetManifestFilesFromDir(manifestsPath)
			return manifestFiles, err
		}
	} else if IsYAML(manifestsPath) { // path points to a file
		if isHelm(false, manifestsPath) {
			return preprocessing.RenderHelmChart(true, manifestsPath, opt)
		} else if isKustomize(false, manifestsPath) {
			return preprocessing.RenderKustomizeManifest(manifestsPath)
		} else {
			byteContent, err := os.ReadFile(manifestsPath)
			if err != nil {
				return nil, fmt.Errorf("could not read file %s: %s", manifestsPath, err)
			}
			manifestFiles = append(manifestFiles, types.ManifestFile{
				Name:            path.Base(manifestsPath),
				ManifestContent: byteContent,
			})
		}
		return manifestFiles, nil
	} else {
		return nil, fmt.Errorf("expected at least one .yaml or .yml file within given path")
	}
}