Skip to content

Commit

Permalink
chore: fix typo in controllerbuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
jingyih committed Dec 13, 2024
1 parent 4345acc commit ac321f9
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions dev/tools/controllerbuilder/pkg/codegen/generatorbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,16 @@ func (f *generatedFile) Write(addCopyright bool) error {
return nil
}

func (v *generatorBase) WriteFiles(addCopyright bool) error {
for _, f := range v.generatedFiles {
func (g *generatorBase) WriteFiles(addCopyright bool) error {
for _, f := range g.generatedFiles {
if err := f.Write(addCopyright); err != nil {
return err
}
}
return nil
}

func (g *TypeGenerator) findTypeDeclaration(goTypeName string, srcDir string, skipGenerated bool) (*string, error) {
func (g *generatorBase) findTypeDeclaration(goTypeName string, srcDir string, skipGenerated bool) (*string, error) {
files, err := os.ReadDir(srcDir)
if err != nil {
if os.IsNotExist(err) { // type declaration does not exist
Expand Down Expand Up @@ -165,7 +165,7 @@ func (g *TypeGenerator) findTypeDeclaration(goTypeName string, srcDir string, sk
return nil, nil
}

func (g *TypeGenerator) findTypeDeclarationWithProtoTag(protoTag string, srcDir string, skipGenerated bool) (*string, error) {
func (g *generatorBase) findTypeDeclarationWithProtoTag(protoTag string, srcDir string, skipGenerated bool) (*string, error) {
files, err := os.ReadDir(srcDir)
if err != nil {
return nil, fmt.Errorf("reading directory %q: %w", srcDir, err)
Expand Down
8 changes: 4 additions & 4 deletions dev/tools/controllerbuilder/pkg/codegen/mappergenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ func (v *MapperGenerator) GenerateMappers() error {
}
out := v.getOutputFile(k)
out.packageName = lastGoComponent(goPackage)
{

{
pbPackage := pair.ProtoGoPackage
krmPackage := pair.KRMType.GoPackage

Expand Down Expand Up @@ -236,7 +236,7 @@ func (v *MapperGenerator) writeMapFunctionsForPair(out io.Writer, srcDir string,
continue
}

if !v.fieldExistInCounterpartStruct(goType, krmFieldName) && !v.fieldExistInCounterpartStruct(goType, krmFieldName+"Ref") { // special handling for Spec and observedState structs which map to the same proto message.
if !v.fieldExistInCounterpartStruct(goType, krmFieldName) && !v.fieldExistInCounterpartStruct(goType, krmFieldName+"Ref") { // special handling for Spec and ObservedState structs which map to the same proto message.
fmt.Fprintf(out, "\t// MISSING: %s\n", krmFieldName)
}
continue
Expand Down Expand Up @@ -404,7 +404,7 @@ func (v *MapperGenerator) writeMapFunctionsForPair(out io.Writer, srcDir string,
continue
}

if !v.fieldExistInCounterpartStruct(goType, krmFieldName) && !v.fieldExistInCounterpartStruct(goType, krmFieldName+"Ref") { // special handling for spec and state structs which map to the same proto message.
if !v.fieldExistInCounterpartStruct(goType, krmFieldName) && !v.fieldExistInCounterpartStruct(goType, krmFieldName+"Ref") { // special handling for spec and observedState structs which map to the same proto message.
fmt.Fprintf(out, "\t// MISSING: %s\n", krmFieldName)
}
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (o *GenerateBasicReconcilerOptions) BindFlags(cmd *cobra.Command) {
func (o *GenerateBasicReconcilerOptions) InitDefaults() error {
root, err := options.RepoRoot()
if err != nil {
return nil
return err
}
o.APIGoPackagePath = "github.com/GoogleCloudPlatform/k8s-config-connector/apis/"
o.APIDirectory = root + "/apis/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type GenerateMapperOptions struct {
func (o *GenerateMapperOptions) InitDefaults() error {
root, err := options.RepoRoot()
if err != nil {
return nil
return err
}
o.APIGoPackagePath = "github.com/GoogleCloudPlatform/k8s-config-connector/apis/"
o.APIDirectory = root + "/apis/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (r *ResourceList) Set(s string) error {
func (o *GenerateCRDOptions) InitDefaults() error {
root, err := options.RepoRoot()
if err != nil {
return nil
return err
}
o.OutputAPIDirectory = root + "/apis/"
return nil
Expand Down Expand Up @@ -168,7 +168,7 @@ func RunGenerateCRD(ctx context.Context, o *GenerateCRDOptions) error {

for _, resource := range o.Resources {
resourceProtoFullName := o.ServiceName + "." + resource.ProtoName
log.Info("visting proto", "name", resourceProtoFullName)
log.Info("visiting proto", "name", resourceProtoFullName)
if err := typeGenerator.VisitProto(resourceProtoFullName); err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type UpdateTypeOptions struct {
func (o *UpdateTypeOptions) InitDefaults() error {
root, err := options.RepoRoot()
if err != nil {
return nil
return err
}
o.apiDirectory = root + "/apis/"
o.goPackagePath = "github.com/GoogleCloudPlatform/k8s-config-connector/apis/"
Expand Down
2 changes: 1 addition & 1 deletion dev/tools/controllerbuilder/pkg/options/generateoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type GenerateOptions struct {
func (o *GenerateOptions) InitDefaults() error {
root, err := RepoRoot()
if err != nil {
return nil
return err
}
o.ProtoSourcePath = root + "/.build/googleapis.pb"
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func findGoTypesFile(directory string) (string, error) {
return "", err
}
if goTypesFile == "" {
return "", fmt.Errorf("did not found Go types file in directory %s", directory)
return "", fmt.Errorf("did not find Go types file in directory %s", directory)
}
return goTypesFile, nil
}
Expand Down
4 changes: 2 additions & 2 deletions dev/tools/controllerbuilder/scaffold/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ func FormatImports(path string, out []byte) error {
Comments: true,
AllErrors: true,
Fragment: true}
formatedOut, err := imports.Process(path, out, importOps)
formattedOut, err := imports.Process(path, out, importOps)
if err != nil {
return fmt.Errorf("format controller file %s: %w", path, err)
}
return WriteToFile(path, formatedOut)
return WriteToFile(path, formattedOut)
}

func WriteToFile(path string, out []byte) error {
Expand Down

0 comments on commit ac321f9

Please sign in to comment.