Bump gengo/v2 to latest

Co-authored-by: Tim Hockin <thockin@google.com>
Co-authored-by: Aaron Prindle <aprindle@google.com>
Co-authored-by: Yongrui Lin <yongrlin@google.com>
# Conflicts:
#	vendor/modules.txt
This commit is contained in:
Joe Betz 2025-03-03 09:49:50 -05:00
parent b363f196c5
commit 7f5e1baeee
23 changed files with 400 additions and 32 deletions

2
go.mod
View File

@ -212,7 +212,7 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 // indirect
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2 // indirect
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
sigs.k8s.io/kustomize/api v0.19.0 // indirect

4
go.sum
View File

@ -654,8 +654,8 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 h1:si3PfKm8dDYxgfbeA6orqrtLkvvIeH8UqffFJDl0bz4=
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU=
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 h1:2OX19X59HxDprNCVrWi6jb7LW1PoqTlYqEq5H2oetog=
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 h1:hcha5B1kVACrLujCKLbr8XWMxCxzQx42DY8QKYJrDLg=

View File

@ -121,7 +121,7 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 // indirect
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 // indirect
k8s.io/kms v0.0.0 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2 // indirect
)

View File

@ -507,8 +507,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 h1:si3PfKm8dDYxgfbeA6orqrtLkvvIeH8UqffFJDl0bz4=
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU=
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 h1:2OX19X59HxDprNCVrWi6jb7LW1PoqTlYqEq5H2oetog=
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 h1:hcha5B1kVACrLujCKLbr8XWMxCxzQx42DY8QKYJrDLg=

View File

@ -14,9 +14,10 @@ require (
github.com/spf13/pflag v1.0.5
golang.org/x/text v0.22.0
k8s.io/apimachinery v0.0.0
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7
k8s.io/klog/v2 v2.130.1
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
sigs.k8s.io/yaml v1.4.0
)
@ -42,7 +43,6 @@ require (
google.golang.org/protobuf v1.35.2 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
)

View File

@ -136,8 +136,8 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 h1:si3PfKm8dDYxgfbeA6orqrtLkvvIeH8UqffFJDl0bz4=
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU=
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 h1:2OX19X59HxDprNCVrWi6jb7LW1PoqTlYqEq5H2oetog=
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 h1:hcha5B1kVACrLujCKLbr8XWMxCxzQx42DY8QKYJrDLg=

View File

@ -104,7 +104,7 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 // indirect
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 // indirect
k8s.io/kms v0.0.0 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2 // indirect
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect

View File

@ -302,8 +302,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 h1:si3PfKm8dDYxgfbeA6orqrtLkvvIeH8UqffFJDl0bz4=
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU=
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 h1:2OX19X59HxDprNCVrWi6jb7LW1PoqTlYqEq5H2oetog=
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 h1:hcha5B1kVACrLujCKLbr8XWMxCxzQx42DY8QKYJrDLg=

View File

@ -232,7 +232,7 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU=
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 h1:hcha5B1kVACrLujCKLbr8XWMxCxzQx42DY8QKYJrDLg=

View File

@ -50,7 +50,7 @@ require (
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 // indirect
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 // indirect
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect

View File

@ -150,8 +150,8 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 h1:si3PfKm8dDYxgfbeA6orqrtLkvvIeH8UqffFJDl0bz4=
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU=
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 h1:2OX19X59HxDprNCVrWi6jb7LW1PoqTlYqEq5H2oetog=
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 h1:hcha5B1kVACrLujCKLbr8XWMxCxzQx42DY8QKYJrDLg=

View File

@ -100,7 +100,7 @@ require (
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.0.0 // indirect
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 // indirect
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kms v0.0.0 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2 // indirect

View File

@ -299,8 +299,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 h1:si3PfKm8dDYxgfbeA6orqrtLkvvIeH8UqffFJDl0bz4=
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU=
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 h1:2OX19X59HxDprNCVrWi6jb7LW1PoqTlYqEq5H2oetog=
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 h1:hcha5B1kVACrLujCKLbr8XWMxCxzQx42DY8QKYJrDLg=

View File

@ -49,7 +49,7 @@ require (
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 // indirect
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 // indirect
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 // indirect
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect

View File

@ -151,8 +151,8 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 h1:si3PfKm8dDYxgfbeA6orqrtLkvvIeH8UqffFJDl0bz4=
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU=
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 h1:2OX19X59HxDprNCVrWi6jb7LW1PoqTlYqEq5H2oetog=
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 h1:hcha5B1kVACrLujCKLbr8XWMxCxzQx42DY8QKYJrDLg=

2
vendor/k8s.io/gengo/v2/README.md generated vendored
View File

@ -50,4 +50,4 @@ The `tracer` example in this repo can be used to examine all of the hooks.
## Contributing
Please see [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on how to contribute.
Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for instructions on how to contribute.

217
vendor/k8s.io/gengo/v2/comments.go generated vendored
View File

@ -17,8 +17,10 @@ limitations under the License.
package gengo
import (
"bytes"
"fmt"
"strings"
"unicode"
)
// ExtractCommentTags parses comments for lines of the form:
@ -39,7 +41,9 @@ import (
//
// Then this function will return:
//
// map[string][]string{"foo":{"value1, "value2"}, "bar": {""}, "baz": {"qux"}}
// map[string][]string{"foo":{"value1, "value2"}, "bar": {""}, "baz": {`"qux"`}}
//
// Deprecated: Use ExtractFunctionStyleCommentTags.
func ExtractCommentTags(marker string, lines []string) map[string][]string {
out := map[string][]string{}
for _, line := range lines {
@ -50,7 +54,6 @@ func ExtractCommentTags(marker string, lines []string) map[string][]string {
if !strings.HasPrefix(line, marker) {
continue
}
// TODO: we could support multiple values per key if we split on spaces
kv := strings.SplitN(line[len(marker):], "=", 2)
if len(kv) == 2 {
out[kv[0]] = append(out[kv[0]], kv[1])
@ -69,15 +72,219 @@ func ExtractCommentTags(marker string, lines []string) map[string][]string {
// to be boolean ("true" or "false"), and any other value will cause an error
// to be returned. If the key has multiple values, the first one will be used.
func ExtractSingleBoolCommentTag(marker string, key string, defaultVal bool, lines []string) (bool, error) {
values := ExtractCommentTags(marker, lines)[key]
tags, err := ExtractFunctionStyleCommentTags(marker, []string{key}, lines)
if err != nil {
return false, err
}
values := tags[key]
if values == nil {
return defaultVal, nil
}
if values[0] == "true" {
if values[0].Value == "true" {
return true, nil
}
if values[0] == "false" {
if values[0].Value == "false" {
return false, nil
}
return false, fmt.Errorf("tag value for %q is not boolean: %q", key, values[0])
}
// ExtractFunctionStyleCommentTags parses comments for special metadata tags. The
// marker argument should be unique enough to identify the tags needed, and
// should not be a marker for tags you don't want, or else the caller takes
// responsibility for making that distinction.
//
// The tagNames argument is a list of specific tags being extracted. If this is
// nil or empty, all lines which match the marker are considered. If this is
// specified, only lines with begin with marker + one of the tags will be
// considered. This is useful when a common marker is used which may match
// lines which fail this syntax (e.g. which predate this definition).
//
// This function looks for input lines of the following forms:
// - 'marker' + "key=value"
// - 'marker' + "key()=value"
// - 'marker' + "key(arg)=value"
//
// The arg is optional. If not specified (either as "key=value" or as
// "key()=value"), the resulting Tag will have an empty Args list.
//
// The value is optional. If not specified, the resulting Tag will have "" as
// the value.
//
// Tag comment-lines may have a trailing end-of-line comment.
//
// The map returned here is keyed by the Tag's name without args.
//
// A tag can be specified more than one time and all values are returned. If
// the resulting map has an entry for a key, the value (a slice) is guaranteed
// to have at least 1 element.
//
// Example: if you pass "+" as the marker, and the following lines are in
// the comments:
//
// +foo=val1 // foo
// +bar
// +foo=val2 // also foo
// +baz="qux"
// +foo(arg) // still foo
//
// Then this function will return:
//
// map[string][]Tag{
// "foo": []Tag{{
// Name: "foo",
// Args: nil,
// Value: "val1",
// }, {
// Name: "foo",
// Args: nil,
// Value: "val2",
// }, {
// Name: "foo",
// Args: []string{"arg"},
// Value: "",
// }, {
// Name: "bar",
// Args: nil,
// Value: ""
// }, {
// Name: "baz",
// Args: nil,
// Value: "\"qux\""
// }}
//
// This function should be preferred instead of ExtractCommentTags.
func ExtractFunctionStyleCommentTags(marker string, tagNames []string, lines []string) (map[string][]Tag, error) {
stripTrailingComment := func(in string) string {
parts := strings.SplitN(in, "//", 2)
return strings.TrimSpace(parts[0])
}
out := map[string][]Tag{}
for _, line := range lines {
line = strings.TrimSpace(line)
if len(line) == 0 {
continue
}
if !strings.HasPrefix(line, marker) {
continue
}
line = stripTrailingComment(line)
kv := strings.SplitN(line[len(marker):], "=", 2)
key := kv[0]
val := ""
if len(kv) == 2 {
val = kv[1]
}
tag := Tag{}
if name, args, err := parseTagKey(key, tagNames); err != nil {
return nil, err
} else if name != "" {
tag.Name, tag.Args = name, args
tag.Value = val
out[tag.Name] = append(out[tag.Name], tag)
}
}
return out, nil
}
// Tag represents a single comment tag.
type Tag struct {
// Name is the name of the tag with no arguments.
Name string
// Args is a list of optional arguments to the tag.
Args []string
// Value is the value of the tag.
Value string
}
func (t Tag) String() string {
buf := bytes.Buffer{}
buf.WriteString(t.Name)
if len(t.Args) > 0 {
buf.WriteString("(")
for i, a := range t.Args {
if i > 0 {
buf.WriteString(", ")
}
buf.WriteString(a)
}
buf.WriteString(")")
}
return buf.String()
}
// parseTagKey parses the key part of an extended comment tag, including
// optional arguments. The input is assumed to be the entire text of the
// original input after the marker, up to the '=' or end-of-line.
//
// The tags argument is an optional list of tag names to match. If it is nil or
// empty, all tags match.
//
// At the moment, arguments are very strictly formatted (see parseTagArgs) and
// whitespace is not allowed.
//
// This function returns the key name and arguments, unless tagNames was
// specified and the input did not match, in which case it returns "".
func parseTagKey(input string, tagNames []string) (string, []string, error) {
parts := strings.SplitN(input, "(", 2)
key := parts[0]
if len(tagNames) > 0 {
found := false
for _, tn := range tagNames {
if key == tn {
found = true
break
}
}
if !found {
return "", nil, nil
}
}
var args []string
if len(parts) == 2 {
if ret, err := parseTagArgs(parts[1]); err != nil {
return key, nil, fmt.Errorf("failed to parse tag args: %v", err)
} else {
args = ret
}
}
return key, args, nil
}
// parseTagArgs parses the arguments part of an extended comment tag. The input
// is assumed to be the entire text of the original input after the opening
// '(', including the trailing ')'.
//
// At the moment this assumes that the entire string between the opening '('
// and the trailing ')' is a single Go-style identifier token, but in the
// future could be extended to have multiple arguments with actual syntax. The
// single token may consist only of letters and digits. Whitespace is not
// allowed.
func parseTagArgs(input string) ([]string, error) {
// This is really dumb, but should be extendable to a "real" parser if
// needed.
runes := []rune(input)
for i, r := range runes {
if unicode.IsLetter(r) || unicode.IsDigit(r) {
continue
}
if r == ',' {
return nil, fmt.Errorf("multiple arguments are not supported: %q", input)
}
if r == ')' {
if i != len(runes)-1 {
return nil, fmt.Errorf("unexpected characters after ')': %q", string(runes[i:]))
}
if i == 0 {
return nil, nil
}
return []string{string(runes[:i])}, nil
}
return nil, fmt.Errorf("unsupported character: %q", string(r))
}
return nil, fmt.Errorf("no closing ')' found: %q", input)
}

View File

@ -165,6 +165,24 @@ func (s *SnippetWriter) Dup(w io.Writer) *SnippetWriter {
// Append adds the contents of the io.Reader to this SnippetWriter's buffer.
func (s *SnippetWriter) Append(r io.Reader) error {
// The behavior of Do() is to ignore all future calls if there's an error,
// assuming the top-level caller will check Error(). This method is
// effectively a fancy Do(), so keep the same semantic.
if s.err != nil {
return nil
}
_, err := io.Copy(s.w, r)
return err
}
// Merge adds the contents of the io.Reader to this SnippetWriter's buffer and
// sets this SnippetWriter's error to the other's, if needed.
func (s *SnippetWriter) Merge(r io.Reader, other *SnippetWriter) error {
if s.err != nil {
return nil
}
if other.err != nil {
s.err = other.err
}
return s.Append(r)
}

View File

@ -370,7 +370,11 @@ func (r *rawNamer) Name(t *types.Type) string {
// TODO: include function signature
elems = append(elems, m.Name.Name)
}
name = "interface{" + strings.Join(elems, "; ") + "}"
if len(elems) == 0 {
name = "any"
} else {
name = "interface{" + strings.Join(elems, "; ") + "}"
}
case types.Func:
// TODO: add to name test
params := []string{}

View File

@ -652,6 +652,7 @@ func (p *Parser) walkType(u types.Universe, useName *types.Name, in gotypes.Type
switch t := in.(type) {
case *gotypes.Struct:
out := u.Type(name)
out.GoType = in
if out.Kind != types.Unknown {
return out
}
@ -670,6 +671,7 @@ func (p *Parser) walkType(u types.Universe, useName *types.Name, in gotypes.Type
return out
case *gotypes.Map:
out := u.Type(name)
out.GoType = in
if out.Kind != types.Unknown {
return out
}
@ -679,6 +681,7 @@ func (p *Parser) walkType(u types.Universe, useName *types.Name, in gotypes.Type
return out
case *gotypes.Pointer:
out := u.Type(name)
out.GoType = in
if out.Kind != types.Unknown {
return out
}
@ -687,6 +690,7 @@ func (p *Parser) walkType(u types.Universe, useName *types.Name, in gotypes.Type
return out
case *gotypes.Slice:
out := u.Type(name)
out.GoType = in
if out.Kind != types.Unknown {
return out
}
@ -695,6 +699,7 @@ func (p *Parser) walkType(u types.Universe, useName *types.Name, in gotypes.Type
return out
case *gotypes.Array:
out := u.Type(name)
out.GoType = in
if out.Kind != types.Unknown {
return out
}
@ -704,6 +709,7 @@ func (p *Parser) walkType(u types.Universe, useName *types.Name, in gotypes.Type
return out
case *gotypes.Chan:
out := u.Type(name)
out.GoType = in
if out.Kind != types.Unknown {
return out
}
@ -717,6 +723,7 @@ func (p *Parser) walkType(u types.Universe, useName *types.Name, in gotypes.Type
Package: "", // This is a magic package name in the Universe.
Name: t.Name(),
})
out.GoType = in
if out.Kind != types.Unknown {
return out
}
@ -724,6 +731,7 @@ func (p *Parser) walkType(u types.Universe, useName *types.Name, in gotypes.Type
return out
case *gotypes.Signature:
out := u.Type(name)
out.GoType = in
if out.Kind != types.Unknown {
return out
}
@ -732,6 +740,7 @@ func (p *Parser) walkType(u types.Universe, useName *types.Name, in gotypes.Type
return out
case *gotypes.Interface:
out := u.Type(name)
out.GoType = in
if out.Kind != types.Unknown {
return out
}
@ -754,6 +763,7 @@ func (p *Parser) walkType(u types.Universe, useName *types.Name, in gotypes.Type
case *gotypes.Named, *gotypes.Basic, *gotypes.Map, *gotypes.Slice:
name := goNameToName(t.String())
out = u.Type(name)
out.GoType = in
if out.Kind != types.Unknown {
return out
}
@ -776,6 +786,7 @@ func (p *Parser) walkType(u types.Universe, useName *types.Name, in gotypes.Type
}
if out := u.Type(name); out.Kind != types.Unknown {
out.GoType = in
return out // short circuit if we've already made this.
}
out = p.walkType(u, &name, t.Underlying())
@ -817,6 +828,7 @@ func (p *Parser) walkType(u types.Universe, useName *types.Name, in gotypes.Type
}
default:
out := u.Type(name)
out.GoType = in
if out.Kind != types.Unknown {
return out
}

100
vendor/k8s.io/gengo/v2/parser/tags/json.go generated vendored Normal file
View File

@ -0,0 +1,100 @@
/*
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// This is based on the highly efficient approach from https://golang.org/src/encoding/json/encode.go
package tags
import (
"reflect"
"strings"
"k8s.io/gengo/v2/types"
)
// JSON represents a go json field tag.
type JSON struct {
Name string
Omit bool
Inline bool
Omitempty bool
}
func (t JSON) String() string {
var tag string
if !t.Inline {
tag += t.Name
}
if t.Omitempty {
tag += ",omitempty"
}
if t.Inline {
tag += ",inline"
}
return tag
}
func LookupJSON(m types.Member) (JSON, bool) {
tag := reflect.StructTag(m.Tags).Get("json")
if tag == "-" {
return JSON{Omit: true}, true
}
name, opts := parse(tag)
inline := opts.Contains("inline")
omitempty := opts.Contains("omitempty")
if !inline && name == "" {
name = m.Name
}
return JSON{
Name: name,
Omit: false,
Inline: inline,
Omitempty: omitempty,
}, true
}
type options string
// parse splits a struct field's json tag into its Name and
// comma-separated options.
func parse(tag string) (string, options) {
if idx := strings.Index(tag, ","); idx != -1 {
return tag[:idx], options(tag[idx+1:])
}
return tag, ""
}
// Contains reports whether a comma-separated listAlias of options
// contains a particular substr flag. substr must be surrounded by a
// string boundary or commas.
func (o options) Contains(optionName string) bool {
if len(o) == 0 {
return false
}
s := string(o)
for s != "" {
var next string
i := strings.Index(s, ",")
if i >= 0 {
s, next = s[:i], s[i+1:]
}
if s == optionName {
return true
}
s = next
}
return false
}

View File

@ -16,7 +16,10 @@ limitations under the License.
package types
import "strings"
import (
gotypes "go/types"
"strings"
)
// Ref makes a reference to the given type. It can only be used for e.g.
// passing to namers.
@ -358,6 +361,9 @@ type Type struct {
// If Kind == Array
Len int64
// The underlying Go type.
GoType gotypes.Type
}
// String returns the name of the type.
@ -402,6 +408,11 @@ func (t *Type) IsAnonymousStruct() bool {
return (t.Kind == Struct && t.Name.Name == "struct{}") || (t.Kind == Alias && t.Underlying.IsAnonymousStruct())
}
// IsComparable returns whether the type is comparable.
func (t *Type) IsComparable() bool {
return gotypes.Comparable(t.GoType)
}
// A single struct member
type Member struct {
// The name of the member.
@ -452,6 +463,10 @@ type Signature struct {
// Built in types.
var (
Any = &Type{
Name: Name{Name: "any"},
Kind: Interface,
}
String = &Type{
Name: Name{Name: "string"},
Kind: Builtin,
@ -515,6 +530,7 @@ var (
builtins = &Package{
Types: map[string]*Type{
"any": Any,
"bool": Bool,
"string": String,
"int": Int,
@ -539,6 +555,16 @@ var (
}
)
func PointerTo(t *Type) *Type {
return &Type{
Name: Name{
Name: "*" + t.Name.String(),
},
Kind: Pointer,
Elem: t,
}
}
func IsInteger(t *Type) bool {
switch t {
case Int, Int64, Int32, Int16, Uint, Uint64, Uint32, Uint16, Byte:

3
vendor/modules.txt vendored
View File

@ -1054,12 +1054,13 @@ gopkg.in/yaml.v3
## explicit; go 1.24.0
# k8s.io/externaljwt v0.0.0 => ./staging/src/k8s.io/externaljwt
## explicit; go 1.24.0
# k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9
# k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7
## explicit; go 1.20
k8s.io/gengo/v2
k8s.io/gengo/v2/generator
k8s.io/gengo/v2/namer
k8s.io/gengo/v2/parser
k8s.io/gengo/v2/parser/tags
k8s.io/gengo/v2/types
# k8s.io/klog/v2 v2.130.1
## explicit; go 1.18