Skip to content

Commit

Permalink
vendor k8s code from 1.29
Browse files Browse the repository at this point in the history
  • Loading branch information
dprotaso committed Aug 11, 2024
1 parent c69f256 commit 81e1aa7
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 92 deletions.
58 changes: 58 additions & 0 deletions codegen/cmd/injection-gen/generators/namer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright 2016 The Kubernetes Authors.

Check failure on line 2 in codegen/cmd/injection-gen/generators/namer.go

View workflow job for this annotation

GitHub Actions / style / Golang / Boilerplate Check (go)

[Go headers] reported by reviewdog 🐶 found mismatched boilerplate lines: Raw Output: codegen/cmd/injection-gen/generators/namer.go:2: found mismatched boilerplate lines: {[]string}[0]: -: "Copyright 2024 The Knative Authors" +: "Copyright 2024 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.
*/

package generators

import (
"k8s.io/gengo/namer"
"k8s.io/gengo/types"
)

// TagOverrideNamer is a namer which pulls names from a given tag, if specified,
// and otherwise falls back to a different namer.
type tagOverrideNamer struct {
tagName string
fallback namer.Namer
}

// Name returns the tag value if it exists. It no tag was found the fallback namer will be used
func (n *tagOverrideNamer) Name(t *types.Type) string {
if nameOverride := extractTag(n.tagName, append(t.SecondClosestCommentLines, t.CommentLines...)); nameOverride != "" {
return nameOverride
}

return n.fallback.Name(t)
}

// NewTagOverrideNamer creates a namer.Namer which uses the contents of the given tag as
// the name, or falls back to another Namer if the tag is not present.
func newTagOverrideNamer(tagName string, fallback namer.Namer) namer.Namer {
return &tagOverrideNamer{
tagName: tagName,
fallback: fallback,
}
}

// extractTag gets the comment-tags for the key. If the tag did not exist, it
// returns the empty string.
func extractTag(key string, lines []string) string {
val, present := types.ExtractCommentTags("+", lines)[key]
if !present || len(val) < 1 {
return ""
}

return val[0]
}
3 changes: 1 addition & 2 deletions codegen/cmd/injection-gen/generators/namesystems.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package generators
import (
"strings"

codegennamer "k8s.io/code-generator/pkg/namer"
"k8s.io/gengo/namer"
"k8s.io/gengo/types"
)
Expand Down Expand Up @@ -47,7 +46,7 @@ func NameSystems() namer.NameSystems {
"publicPlural": publicPluralNamer,
"allLowercasePlural": namer.NewAllLowercasePluralNamer(pluralExceptions),
"lowercaseSingular": &lowercaseSingularNamer{},
"apiGroup": codegennamer.NewTagOverrideNamer("publicPlural", publicPluralNamer),
"apiGroup": newTagOverrideNamer("publicPlural", publicPluralNamer),
"versionedClientset": &versionedClientsetNamer{public: publicNamer},
}
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
k8s.io/apimachinery v0.30.3
k8s.io/client-go v0.30.3
k8s.io/code-generator v0.30.3
k8s.io/gengo v0.0.0-20240129211411-f967bbeff4b4
k8s.io/gengo v0.0.0-20240404160639-a0386bf69313
k8s.io/klog/v2 v2.130.1
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
knative.dev/hack v0.0.0-20240801232131-441a19fc9ead
Expand Down Expand Up @@ -88,7 +88,7 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20240808171019-573a1156607a // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/gengo/v2 v2.0.0-20240404160639-a0386bf69313 // indirect
k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70 // indirect
k8s.io/kube-openapi v0.0.0-20240808142205-8e686545bdb8 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,10 @@ k8s.io/client-go v0.30.3 h1:bHrJu3xQZNXIi8/MoxYtZBBWQQXwy16zqJwloXXfD3k=
k8s.io/client-go v0.30.3/go.mod h1:8d4pf8vYu665/kUbsxWAQ/JDBNWqfFeZnvFiVdmx89U=
k8s.io/code-generator v0.30.3 h1:bmtnLJKagDS5f5uOEpLyJiDfIMKXGMKgOLBdde+w0Mc=
k8s.io/code-generator v0.30.3/go.mod h1:PFgBiv+miFV7TZYp+RXgROkhA+sWYZ+mtpbMLofMke8=
k8s.io/gengo v0.0.0-20240129211411-f967bbeff4b4 h1:izq7u3SJBdOAuA5YYe1/PIp9jczrih/jGlKRRt0G7bQ=
k8s.io/gengo v0.0.0-20240129211411-f967bbeff4b4/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/gengo/v2 v2.0.0-20240404160639-a0386bf69313 h1:bKcdZJOPICVmIIuaM9+MXmapE94dn5AYv5ODs1jA43o=
k8s.io/gengo/v2 v2.0.0-20240404160639-a0386bf69313/go.mod h1:VH3AT8AaQOqiGjMF9p0/IM1Dj+82ZwjfxUP1IxaHE+8=
k8s.io/gengo v0.0.0-20240404160639-a0386bf69313 h1:wBIDZID8ju9pwOiLlV22YYKjFGtiNSWgHf5CnKLRUuM=
k8s.io/gengo v0.0.0-20240404160639-a0386bf69313/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70 h1:NGrVE502P0s0/1hudf8zjgwki1X/TByhmAoILTarmzo=
k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70/go.mod h1:VH3AT8AaQOqiGjMF9p0/IM1Dj+82ZwjfxUP1IxaHE+8=
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
Expand Down
28 changes: 15 additions & 13 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ ${REPO_ROOT_DIR}/hack/generate-knative.sh "injection" \
# Based on: https://github.com/kubernetes/kubernetes/blob/8ddabd0da5cc54761f3216c08e99fa1a9f7ee2c5/hack/lib/init.sh#L116
# The '-path' is a hack to workaround the lack of portable `-depth 2`.
K8S_TYPES=$(find ./vendor/k8s.io/api -type d -path '*/*/*/*/*/*' | cut -d'/' -f 5-6 | sort | sed 's@/@:@g' |
grep -v "admission:" | grep -v "imagepolicy:" | grep -v "abac:" | grep -v "componentconfig:")
grep -v "abac:" | \
grep -v "admission:" | \
grep -v "admissionregistration:" \
grep -v "componentconfig:" | \
grep -v "imagepolicy:" | \
grep -v "resource:" | \
grep -v "storagemigration:" \
)

OUTPUT_PKG="knative.dev/pkg/client/injection/kube" \
VERSIONED_CLIENTSET_PKG="k8s.io/client-go/kubernetes" \
Expand All @@ -65,24 +72,19 @@ VERSIONED_CLIENTSET_PKG="k8s.io/apiextensions-apiserver/pkg/client/clientset/cli
group "Knative Codegen"

# Only deepcopy the Duck types, as they are not real resources.
${CODEGEN_PKG}/generate-groups.sh "deepcopy" \
knative.dev/pkg/client knative.dev/pkg/apis \
"duck:v1alpha1,v1beta1,v1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt

# Depends on generate-groups.sh to install bin/deepcopy-gen
go run k8s.io/code-generator/cmd/deepcopy-gen --input-dirs \
$(echo \
go run k8s.io/code-generator/cmd/deepcopy-gen \
--output-file zz_generated.deepcopy.go \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt \
knative.dev/pkg/apis \
knative.dev/pkg/apis/duck/v1alpha1 \
knative.dev/pkg/apis/duck/v1beta1 \
knative.dev/pkg/apis/duck/v1 \
knative.dev/pkg/tracker \
knative.dev/pkg/logging \
knative.dev/pkg/metrics \
knative.dev/pkg/testing \
knative.dev/pkg/testing/duck \
knative.dev/pkg/webhook/resourcesemantics/conversion/internal \
| sed "s/ /,/g") \
-O zz_generated.deepcopy \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt
knative.dev/pkg/webhook/resourcesemantics/conversion/internal

group "Update deps post-codegen"

Expand Down
16 changes: 8 additions & 8 deletions vendor/k8s.io/gengo/v2/namer/namer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 5 additions & 46 deletions vendor/k8s.io/gengo/v2/parser/parse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 5 additions & 15 deletions vendor/k8s.io/gengo/v2/types/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -892,14 +892,14 @@ k8s.io/code-generator/cmd/register-gen/generators
k8s.io/code-generator/pkg/namer
k8s.io/code-generator/pkg/util
k8s.io/code-generator/third_party/forked/golang/reflect
# k8s.io/gengo v0.0.0-20240129211411-f967bbeff4b4
# k8s.io/gengo v0.0.0-20240404160639-a0386bf69313
## explicit; go 1.13
k8s.io/gengo/args
k8s.io/gengo/generator
k8s.io/gengo/namer
k8s.io/gengo/parser
k8s.io/gengo/types
# k8s.io/gengo/v2 v2.0.0-20240404160639-a0386bf69313
# k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70
## explicit; go 1.20
k8s.io/gengo/v2
k8s.io/gengo/v2/generator
Expand Down

0 comments on commit 81e1aa7

Please sign in to comment.