chore(validation-gen): rename flag --extra-pkg -> --readonly-pkg in validation-gen

This commit is contained in:
Aaron Prindle 2025-03-08 20:04:27 +00:00
parent 67e1a1ebbb
commit cfcf7e93a3
5 changed files with 18 additions and 18 deletions

View File

@ -434,7 +434,7 @@ function codegen::validation() {
# main API types. Validations defined on types in these packages will be
# used, but not regenerated, unless they are also listed as a "regular"
# input on the command-line.
local extra_pkgs=(
local readonly_pkgs=(
k8s.io/apimachinery/pkg/apis/meta/v1
k8s.io/apimachinery/pkg/api/resource
k8s.io/apimachinery/pkg/runtime
@ -457,7 +457,7 @@ function codegen::validation() {
-v "${KUBE_VERBOSE}" \
--go-header-file "${BOILERPLATE_FILENAME}" \
--output-file "${output_file}" \
$(printf -- " --extra-pkg %s" "${extra_pkgs[@]}") \
$(printf -- " --readonly-pkg %s" "${readonly_pkgs[@]}") \
"${tag_pkgs[@]}" \
"$@"

View File

@ -75,7 +75,7 @@ func main() {
type Args struct {
OutputFile string
ExtraPkgs []string // Always consider these as last-ditch possibilities for validations.
ReadOnlyPkgs []string // Always consider these as last-ditch possibilities for validations.
GoHeaderFile string
PrintDocs bool
Lint bool
@ -85,7 +85,7 @@ type Args struct {
func (args *Args) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&args.OutputFile, "output-file", "generated.validations.go",
"the name of the file to be generated")
fs.StringSliceVar(&args.ExtraPkgs, "extra-pkg", args.ExtraPkgs,
fs.StringSliceVar(&args.ReadOnlyPkgs, "readonly-pkg", args.ReadOnlyPkgs,
"the import path of a package whose validation can be used by generated code, but is not being generated for")
fs.StringVar(&args.GoHeaderFile, "go-header-file", "",
"the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year")

View File

@ -205,21 +205,21 @@ func GetTargets(context *generator.Context, args *Args) []generator.Target {
}
// Make sure explicit extra-packages are added.
var extraPkgs []string
for _, pkg := range args.ExtraPkgs {
var readOnlyPkgs []string
for _, pkg := range args.ReadOnlyPkgs {
// In case someone specifies an extra as a path into vendor, convert
// it to its "real" package path.
if i := strings.Index(pkg, "/vendor/"); i != -1 {
pkg = pkg[i+len("/vendor/"):]
}
extraPkgs = append(extraPkgs, pkg)
readOnlyPkgs = append(readOnlyPkgs, pkg)
}
if expanded, err := context.FindPackages(extraPkgs...); err != nil {
if expanded, err := context.FindPackages(readOnlyPkgs...); err != nil {
klog.Fatalf("cannot find extra packages: %v", err)
} else {
extraPkgs = expanded // now in fully canonical form
readOnlyPkgs = expanded // now in fully canonical form
}
for _, extra := range extraPkgs {
for _, extra := range readOnlyPkgs {
inputPkgs = append(inputPkgs, extra)
pkgToInput[extra] = extra
}

View File

@ -494,7 +494,7 @@ func (td *typeDiscoverer) discover(t *types.Type, fldPath *field.Path) (*typeNod
if elemNode := underlying.node.elem.node; elemNode == nil {
if !thisNode.typeValidations.OpaqueValType {
return nil, fmt.Errorf("%v: value type %v is in a non-included package; "+
"either add this package to validation-gen's --extra-pkg flag, "+
"either add this package to validation-gen's --readonly-pkg flag, "+
"or add +k8s:eachVal=+k8s:opaqueType to the field to skip validation",
fldPath, underlying.node.elem.childType)
}
@ -525,7 +525,7 @@ func (td *typeDiscoverer) discover(t *types.Type, fldPath *field.Path) (*typeNod
if keyNode := underlying.node.key.node; keyNode == nil {
if !thisNode.typeValidations.OpaqueKeyType {
return nil, fmt.Errorf("%v: key type %v is in a non-included package; "+
"either add this package to validation-gen's --extra-pkg flag, "+
"either add this package to validation-gen's --readonly-pkg flag, "+
"or add +k8s:eachKey=+k8s:opaqueType to the field to skip validation",
fldPath, underlying.node.elem.childType)
}
@ -555,7 +555,7 @@ func (td *typeDiscoverer) discover(t *types.Type, fldPath *field.Path) (*typeNod
if elemNode := underlying.node.elem.node; elemNode == nil {
if !thisNode.typeValidations.OpaqueValType {
return nil, fmt.Errorf("%v: value type %v is in a non-included package; "+
"either add this package to validation-gen's --extra-pkg flag, "+
"either add this package to validation-gen's --readonly-pkg flag, "+
"or add +k8s:eachVal=+k8s:opaqueType to the field to skip validation",
fldPath, underlying.node.elem.childType)
}
@ -654,7 +654,7 @@ func (td *typeDiscoverer) discoverStruct(thisNode *typeNode, fldPath *field.Path
if child.node == nil { // a non-included type
if !child.fieldValidations.OpaqueType {
return fmt.Errorf("%v: type %v is in a non-included package; "+
"either add this package to validation-gen's --extra-pkg flag, "+
"either add this package to validation-gen's --readonly-pkg flag, "+
"or add +k8s:opaqueType to the field to skip validation",
childPath, childType.String())
}
@ -678,7 +678,7 @@ func (td *typeDiscoverer) discoverStruct(thisNode *typeNode, fldPath *field.Path
if elemNode := child.node.elem.node; elemNode == nil {
if !child.fieldValidations.OpaqueValType {
return fmt.Errorf("%v: value type %v is in a non-included package; "+
"either add this package to validation-gen's --extra-pkg flag, "+
"either add this package to validation-gen's --readonly-pkg flag, "+
"or add +k8s:eachVal=+k8s:opaqueType to the field to skip validation",
childPath, childType.Elem.String())
}
@ -709,7 +709,7 @@ func (td *typeDiscoverer) discoverStruct(thisNode *typeNode, fldPath *field.Path
if keyNode := child.node.key.node; keyNode == nil {
if !child.fieldValidations.OpaqueKeyType {
return fmt.Errorf("%v: key type %v is in a non-included package; "+
"either add this package to validation-gen's --extra-pkg flag, "+
"either add this package to validation-gen's --readonly-pkg flag, "+
"or add +k8s:eachKey=+k8s:opaqueType to the field to skip validation",
childPath, childType.Key.String())
}
@ -739,7 +739,7 @@ func (td *typeDiscoverer) discoverStruct(thisNode *typeNode, fldPath *field.Path
if elemNode := child.node.elem.node; elemNode == nil {
if !child.fieldValidations.OpaqueValType {
return fmt.Errorf("%v: value type %v is in a non-included package; "+
"either add this package to validation-gen's --extra-pkg flag, "+
"either add this package to validation-gen's --readonly-pkg flag, "+
"or add +k8s:eachVal=+k8s:opaqueType to the field to skip validation",
childPath, childType.Elem.String())
}

View File

@ -50,7 +50,7 @@ func (opaqueTypeTagValidator) Docs() TagDoc {
"If a referenced type's package is not included in the generator's current " +
"flags, this tag must be set, or code generation will fail (preventing silent " +
"mistakes). If the validations should not be ignored, add the type's package " +
"to the generator using the --extra-pkg flag.",
"to the generator using the --readonly-pkg flag.",
}
return doc
}