From 21035f3180e666baa1fd12e1733a265bcae7ecb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Luk=C5=A1a?= Date: Fri, 9 Aug 2024 19:27:51 +0200 Subject: [PATCH] Rename `addTags` to `addComments` in API transformer (#259) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marko Lukša Signed-off-by: Daniel Grimm --- hack/api_transformer/main.go | 22 +++++++++++----------- hack/api_transformer/transform.yaml | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/hack/api_transformer/main.go b/hack/api_transformer/main.go index 234d77edb..d11a90272 100644 --- a/hack/api_transformer/main.go +++ b/hack/api_transformer/main.go @@ -70,7 +70,7 @@ type Transformations struct { ReplaceFunctionReturnTypes map[string]string `yaml:"replaceFunctionReturnTypes"` ReplaceFieldTypes map[string]string `yaml:"replaceFieldTypes"` ReplaceTypes map[string]string `yaml:"replaceTypes"` - AddTags map[string]string `yaml:"addTags"` + AddComments map[string]string `yaml:"addComments"` } var config *Config @@ -139,7 +139,7 @@ func merge(local, global *Transformations) *Transformations { ReplaceFunctionReturnTypes: mergeStringMaps(local.ReplaceFunctionReturnTypes, global.ReplaceFunctionReturnTypes), ReplaceFieldTypes: mergeStringMaps(local.ReplaceFieldTypes, global.ReplaceFieldTypes), ReplaceTypes: mergeStringMaps(local.ReplaceTypes, global.ReplaceTypes), - AddTags: mergeStringMaps(local.AddTags, global.AddTags), + AddComments: mergeStringMaps(local.AddComments, global.AddComments), } } @@ -240,17 +240,17 @@ func (t *FileTransformer) processFile() (*ast.File, error) { field.Type = newType } - if tag := t.getFieldTags(structName, fieldName); tag != "" { - addTag(field, tag) + if tag := t.getFieldComments(structName, fieldName); tag != "" { + addComment(field, tag) } if toString(field.Type) == "*intstr.IntOrString" { - addTag(field, "// +kubebuilder:validation:XIntOrString") + addComment(field, "// +kubebuilder:validation:XIntOrString") } if field.Doc != nil { for _, comment := range field.Doc.List { if strings.HasPrefix(comment.Text, "// REQUIRED.") { - addTag(field, "// +kubebuilder:validation:Required") + addComment(field, "// +kubebuilder:validation:Required") removeOmitemptyFromJSONTag(field) // TODO: remove pointer? } @@ -422,7 +422,7 @@ func convertTabsToHeadings(doc *ast.CommentGroup) { } } -func addTag(node ast.Node, text string) { +func addComment(node ast.Node, text string) { switch n := node.(type) { case *ast.Field: if n.Doc == nil { @@ -499,7 +499,7 @@ func processInterfaceFields(file *ast.File) { newFields = append(newFields, field) } if hasInterfaceField { - addTag(genDecl, buildOneOfValidation(interfaceFields)) + addComment(genDecl, buildOneOfValidation(interfaceFields)) } structType.Fields.List = newFields } @@ -654,7 +654,7 @@ func convertEnum(enumName string, file *ast.File) { if ident, ok := typeSpec.Type.(*ast.Ident); ok && ident.Name == "int32" { ident.Name = "string" } - addTag(genDecl, "// +kubebuilder:validation:Enum="+strings.Join(enumValues, ";")) + addComment(genDecl, "// +kubebuilder:validation:Enum="+strings.Join(enumValues, ";")) } case token.CONST: // change the constant values to strings @@ -745,8 +745,8 @@ func (t *FileTransformer) getFieldRename(structName string, fieldName string) st return getMapValue(structName, fieldName, t.Transformations.RenameFields) } -func (t *FileTransformer) getFieldTags(structName string, fieldName string) string { - return getMapValue(structName, fieldName, t.Transformations.AddTags) +func (t *FileTransformer) getFieldComments(structName string, fieldName string) string { + return getMapValue(structName, fieldName, t.Transformations.AddComments) } func getMapValue(parent string, child string, m map[string]string) string { diff --git a/hack/api_transformer/transform.yaml b/hack/api_transformer/transform.yaml index a4769c97b..4e04547a4 100644 --- a/hack/api_transformer/transform.yaml +++ b/hack/api_transformer/transform.yaml @@ -107,7 +107,7 @@ inputFiles: SidecarInjectorConfig.AlwaysInjectSelector: "[]metav1.LabelSelector" SidecarInjectorConfig.InjectedAnnotations: "map[string]string" SidecarInjectorConfig.Templates: "map[string]string" - addTags: + addComments: CNIConfig.PullPolicy: "// +kubebuilder:validation:Enum=Always;Never;IfNotPresent" GlobalConfig.ImagePullPolicy: "// +kubebuilder:validation:Enum=Always;Never;IfNotPresent" @@ -129,7 +129,7 @@ inputFiles: removeTypes: - LabelSelector - LabelSelectorRequirement - addTags: + addComments: MeshConfig.ExtensionProviders: "// +kubebuilder:validation:MaxItems=1000" # to prevent CEL cost overruns - module: istio.io/api