Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions pkg/examples/conversion/example_conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
"github.com/crossplane/upjet/v2/pkg/config/conversion"
)

// ConvertSingletonListToEmbeddedObject generates the example manifests for
// the APIs with converted singleton lists in their new API versions with the
// embedded objects. All manifests under `startPath` are scanned and the
// ApplyAPIConverters applies the registered converters to generated
// example manifests under the given root directory.
// All (generated) manifests under the `startPath` are scanned and the
// header at the specified path `licenseHeaderPath` is used for the converted
// example manifests.
func ConvertSingletonListToEmbeddedObject(pc *config.Provider, startPath, licenseHeaderPath string) error {
func ApplyAPIConverters(pc *config.Provider, startPath, licenseHeaderPath string) error {
resourceRegistry := prepareResourceRegistry(pc)

var license string
Expand Down Expand Up @@ -64,15 +64,15 @@ func ConvertSingletonListToEmbeddedObject(pc *config.Provider, startPath, licens
return nil
}

newPath := strings.ReplaceAll(path, examples[0].GroupVersionKind().Version, rootResource.Version)
if path == newPath {
return nil
}
annotationValue := strings.ToLower(fmt.Sprintf("%s/%s/%s", rootResource.ShortGroup, rootResource.Version, rootResource.Kind))
for _, e := range examples {
if resource, ok := resourceRegistry[fmt.Sprintf("%s/%s", e.GroupVersionKind().Kind, e.GroupVersionKind().Group)]; ok {
conversionPaths := resource.CRDListConversionPaths()
if conversionPaths != nil && e.GroupVersionKind().Version != resource.Version {
// if the latest version has conversions, run the conversions on the
// example manifest.
// Please note that only the version being generated (latest version)
// is processed.
if conversionPaths != nil && e.GroupVersionKind().Version == resource.Version {
for i, cp := range conversionPaths {
// Here, for the manifests to be converted, only `forProvider
// is converted, assuming the `initProvider` field is empty in the
Expand Down Expand Up @@ -100,7 +100,7 @@ func ConvertSingletonListToEmbeddedObject(pc *config.Provider, startPath, licens
}
}
convertedFileContent = license + "\n\n"
if err := writeExampleContent(path, convertedFileContent, examples, newPath); err != nil {
if err := writeExampleContent(path, convertedFileContent, examples, path); err != nil {
return errors.Wrap(err, "failed to write example content")
}
}
Expand Down
Loading