func deduplicateFileNames(templateData *SourceCodeTemplateData) {
	fileNames := make([]string, len(*templateData.SourceFiles)+1)
	fileNames[len(fileNames)-1] = "resources.go"
	sourceFiles := *templateData.SourceFiles
	for i, sourceFile := range sourceFiles {
		var count int
		for _, fileName := range fileNames {
			if fileName == "" {
				continue
			}
			if sourceFile.Filename == fileName {
				count++
				fields := strings.Split(sourceFile.Filename, ".go")
				sourceFiles[i].Filename = fmt.Sprintf("%s_%v.go", fields[0], count)
			}
		}
		fileNames[i] = sourceFile.Filename
	}
}
deduplicateFileNames dedeplicates the names of the files.  This is because
we cannot guarantee that files exist in different directories and may have
naming collisions.
package v1
import (
	"bytes"
	"errors"
	"fmt"
	"io/ioutil"
	"path/filepath"
	"regexp"
	"strings"
	"github.com/vmware-tanzu-labs/object-code-generator-for-k8s/pkg/generate"
	"gopkg.in/yaml.v3"
	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/apimachinery/pkg/runtime/serializer"
	"k8s.io/client-go/kubernetes/scheme"
	"github.com/vmware-tanzu-labs/operator-builder/internal/markers/inspect"
	"github.com/vmware-tanzu-labs/operator-builder/internal/markers/marker"
	"github.com/vmware-tanzu-labs/operator-builder/internal/utils"
)
var (
	ErrUnsupportedDataType    = errors.New("unsupported data type in workload marker")
	ErrUnableToParseFieldType = errors.New("unable to parse field")
)
func SupportedMarkerDataTypes() []string {
	return []string{"bool", "string", "int", "int32", "int64", "float32", "float64"}
}
func formatProcessError(manifestFile string, err error) error {
	return fmt.Errorf("error processing file %s; %w", manifestFile, err)
}
func processMarkers(
	workloadPath string,
	resources []string,
	collection bool,
	collectionResources bool,
) (*SourceCodeTemplateData, error) {
	const dataTypeString = "string"
	results := &SourceCodeTemplateData{
		SourceFiles:    new([]SourceFile),
		RBACRules:      new([]RBACRule),
		OwnershipRules: new([]OwnershipRule),
	}
	specFields := make(map[string]*APISpecField)
	for _, manifestFile := range resources {
		manifestContent, err := ioutil.ReadFile(filepath.Join(filepath.Dir(workloadPath), manifestFile))
		if err != nil {
			return nil, formatProcessError(manifestFile, err)
		}
		insp, err := InitializeMarkerInspector()
		if err != nil {
			return nil, formatProcessError(manifestFile, err)
		}
		nodes, markerResults, err := insp.InspectYAML(manifestContent, TransformYAML)
		if err != nil {
			return nil, formatProcessError(manifestFile, err)
		}
		buf := bytes.Buffer{}
		for _, node := range nodes {
			m, err := yaml.Marshal(node)
			if err != nil {
				return nil, formatProcessError(manifestFile, err)
			}
			buf.WriteString("---\n")
			buf.Write(m)
		}
		manifestContent = buf.Bytes()
		for _, markerResult := range markerResults {
			switch r := markerResult.Object.(type) {
			case FieldMarker:
				if collection && !collectionResources {
					continue
				}
				specField := &APISpecField{
					FieldName:         strings.ToTitle(r.Name),
					ManifestFieldName: r.Name,
					DataType:          r.Type.String(),
					APISpecContent: fmt.Sprintf(
						"%s %s `json:\"%s\"`",
						strings.Title(r.Name),
						r.Type,
						r.Name,
					),
				}
				if r.Description != nil {
					specField.DocumentationLines = strings.Split(*r.Description, "\n")
				}
				zv, err := zeroValue(r.Type.String())
				if err != nil {
					return nil, formatProcessError(manifestFile, err)
				}
				specField.ZeroVal = zv
				if r.Default != nil {
					if specField.DataType == dataTypeString {
						specField.DefaultVal = fmt.Sprintf("%q", r.Default)
						specField.SampleField = fmt.Sprintf("%s: %q", r.Name, r.Default)
					} else {
						specField.DefaultVal = fmt.Sprintf("%v", r.Default)
						specField.SampleField = fmt.Sprintf("%s: %v", r.Name, r.Default)
					}
				} else {
					if specField.DataType == dataTypeString {
						specField.SampleField = fmt.Sprintf("%s: %q", r.Name, r.originalValue)
					} else {
						specField.SampleField = fmt.Sprintf("%s: %v", r.Name, r.originalValue)
					}
				}
				specFields[r.Name] = specField
			case CollectionFieldMarker:
				if !collection {
					continue
				}
				specField := &APISpecField{
					FieldName:         strings.ToTitle(r.Name),
					ManifestFieldName: r.Name,
					DataType:          r.Type.String(),
					APISpecContent: fmt.Sprintf(
						"%s %s `json:\"%s\"`",
						strings.Title(r.Name),
						r.Type,
						r.Name,
					),
				}
				if r.Description != nil {
					specField.DocumentationLines = strings.Split(*r.Description, "\n")
				}
				zv, err := zeroValue(r.Type.String())
				if err != nil {
					return nil, formatProcessError(manifestFile, err)
				}
				specField.ZeroVal = zv
				if r.Default != nil {
					if specField.DataType == dataTypeString {
						specField.DefaultVal = fmt.Sprintf("%q", r.Default)
						specField.SampleField = fmt.Sprintf("%s: %q", r.Name, r.Default)
					} else {
						specField.DefaultVal = fmt.Sprintf("%v", r.Default)
						specField.SampleField = fmt.Sprintf("%s: %v", r.Name, r.Default)
					}
				} else {
					if specField.DataType == dataTypeString {
						specField.SampleField = fmt.Sprintf("%s: %q", r.Name, r.originalValue)
					} else {
						specField.SampleField = fmt.Sprintf("%s: %v", r.Name, r.originalValue)
					}
				}
				specFields[r.Name] = specField
			default:
				continue
			}
		}
		if collection && !collectionResources {
			continue
		}
		var sourceFile SourceFile
		sourceFile.Filename = filepath.Base(manifestFile)                 
		sourceFile.Filename = strings.Split(sourceFile.Filename, ".")[0]  
		sourceFile.Filename += ".go"                                      
		sourceFile.Filename = utils.ToFileName(sourceFile.Filename)       
		var childResources []ChildResource
		manifests := extractManifests(manifestContent)
		for _, manifest := range manifests {
			if collection && collectionResources {
				manifest = strings.Replace(
					manifest,
					"!!var collection",
					"!!var parent",
					-1,
				)
			}
			var manifestObject unstructured.Unstructured
			decoder := serializer.NewCodecFactory(scheme.Scheme).UniversalDecoder()
			err := runtime.DecodeInto(decoder, []byte(manifest), &manifestObject)
			if err != nil {
				return nil, formatProcessError(manifestFile, err)
			}
			resourceUniqueName := strings.Replace(strings.Title(manifestObject.GetName()), "-", "", -1)
			resourceUniqueName = strings.Replace(resourceUniqueName, ".", "", -1)
			resourceUniqueName = strings.Replace(resourceUniqueName, ":", "", -1)
			resourceUniqueName = fmt.Sprintf("%s%s", manifestObject.GetKind(), resourceUniqueName)
			resourceVersion, resourceGroup := versionGroupFromAPIVersion(manifestObject.GetAPIVersion())
			rbacRulesForManifest(manifestObject.GetKind(), resourceGroup, manifestObject.Object, results.RBACRules)
			newOwnershipRule := OwnershipRule{
				Version: manifestObject.GetAPIVersion(),
				Kind:    manifestObject.GetKind(),
				CoreAPI: isCoreAPI(resourceGroup),
			}
			ownershipExists := versionKindRecorded(results.OwnershipRules, &newOwnershipRule)
			if !ownershipExists {
				*results.OwnershipRules = append(*results.OwnershipRules, newOwnershipRule)
			}
			resource := ChildResource{
				Name:       manifestObject.GetName(),
				UniqueName: resourceUniqueName,
				Group:      resourceGroup,
				Version:    resourceVersion,
				Kind:       manifestObject.GetKind(),
			}
			resourceDefinition, err := generate.Generate([]byte(manifest), "resourceObj")
			if err != nil {
				return nil, formatProcessError(manifestFile, err)
			}
			resource.SourceCode = resourceDefinition
			resource.StaticContent = manifest
			childResources = append(childResources, resource)
		}
		sourceFile.Children = childResources
		*results.SourceFiles = append(*results.SourceFiles, sourceFile)
	}
	for _, v := range specFields {
		results.SpecFields = append(results.SpecFields, v)
	}
	deduplicateFileNames(results)
	return results, nil
}