Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#3011 from yuwenma/chore-name
Browse files Browse the repository at this point in the history
chore: change type-generators to give shorter api _types.go file name
  • Loading branch information
google-oss-prow[bot] authored Oct 29, 2024
2 parents 1b77c54 + 9b29e59 commit db632f4
Show file tree
Hide file tree
Showing 24 changed files with 12 additions and 12 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ func RunGenerateCRD(ctx context.Context, o *GenerateCRDOptions) error {
}

kind := o.ResourceKindName
if !scaffolder.TypeFileNotExist(kind) {
fmt.Printf("file %s already exists, skipping\n", scaffolder.PathToTypeFile(kind))
if !scaffolder.TypeFileNotExist(o.ResourceProtoName) {
fmt.Printf("file %s already exists, skipping\n", scaffolder.PathToTypeFile(o.ResourceProtoName))
} else {
err := scaffolder.AddTypeFile(kind, o.ResourceProtoName)
err := scaffolder.AddTypeFile(o.ResourceProtoName, kind)
if err != nil {
return fmt.Errorf("add type file %s: %w", scaffolder.PathToTypeFile(kind), err)
return fmt.Errorf("add type file %s: %w", scaffolder.PathToTypeFile(o.ResourceProtoName), err)
}
}
if scaffolder.RefsFileExist(kind, o.ResourceProtoName) {
Expand Down
16 changes: 8 additions & 8 deletions dev/tools/controllerbuilder/scaffold/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,29 @@ func scaffoldRefsFile(path string, cArgs *apis.APIArgs) error {
return nil
}

func (a *APIScaffolder) TypeFileNotExist(kind string) bool {
typeFilePath := a.PathToTypeFile(kind)
func (a *APIScaffolder) TypeFileNotExist(resourceProtoName string) bool {
typeFilePath := a.PathToTypeFile(resourceProtoName)
_, err := os.Stat(typeFilePath)
if err == nil {
return false
}
return errors.Is(err, os.ErrNotExist)
}

func (a *APIScaffolder) PathToTypeFile(kind string) string {
fileName := strings.ToLower(kind) + "_types.go"
func (a *APIScaffolder) PathToTypeFile(resourceProtoName string) string {
fileName := strings.ToLower(resourceProtoName) + "_reference.go"
return filepath.Join(a.BaseDir, a.GoPackage, fileName)
}

func (a *APIScaffolder) AddTypeFile(kind, proto string) error {
typeFilePath := a.PathToTypeFile(kind)
func (a *APIScaffolder) AddTypeFile(resourceProtoName, kind string) error {
typeFilePath := a.PathToTypeFile(resourceProtoName)
cArgs := &apis.APIArgs{
Group: a.Group,
Version: a.Version,
Kind: kind,
PackageProtoTag: a.PackageProtoTag,
KindProtoTag: a.PackageProtoTag + "." + proto,
ProtoResource: proto,
KindProtoTag: a.PackageProtoTag + "." + resourceProtoName,
ProtoResource: resourceProtoName,
}
return scaffoldTypeFile(typeFilePath, cArgs)
}
Expand Down

0 comments on commit db632f4

Please sign in to comment.