upgrade to latest dependencies (#704)

bumping k8s.io/gengo 397b4ae...fad74ee:
  > fad74ee Merge pull request # 234 from aojea/use_github_actions
  > e83a76d Merge pull request # 233 from rainest/fix/filter-abort
  > f99002e remove travis
  > 3913671 Merge pull request # 199 from rainest/log/lower-severity-uncopyable
  > 535f8cc Restore uncopyable type case in Filter
  > 3bcdbc7 Merge pull request # 232 from alexzielenski/defaulter-const-symbol-reference
  > 914c10e Update examples/deepcopy-gen/generators/deepcopy.go
  > c0856e2 Merge pull request # 231 from weilaaa/add_method_symmetric_difference_in_set
  > 945b13c fix typo
  > ad375a7 Fail if any requested type cannot be copied
  > 66c86ac add method symmetric difference in set
  > 49f7e1e fix typo
  > 20f90a4 Update examples/defaulter-gen/generators/defaulter.go
  > e1d2c67 remove incorrect quotes from ref regex comment
  > 91632a7 address comments
  > bab4b7f allow +default to refer to symbols in code
bumping k8s.io/api 4b838ea...88912e3:
  > 88912e3 Update dependencies to v0.25.4 tag
  > e7b469b Merge pull request # 112808 from cheftako/automated-cherry-pick-of-# 112689-upstream-release-1.25
  > 1102e6f Updated vendor to the new preferred versions.
bumping k8s.io/code-generator 7e9837e...6523e22:
  > 6523e22 Merge pull request # 112808 from cheftako/automated-cherry-pick-of-# 112689-upstream-release-1.25
  > 59f8301 Updated vendor to the new preferred versions.
bumping knative.dev/hack b035462...de2ff40:
  > de2ff40 Allow tests to skip dumping resources on failure (# 255)
  > 646aac0 e2e script tweaks (# 252)
  > d470f52 Format go code (# 253)
bumping k8s.io/utils ee6ede2...8e77b1f:
  > 8e77b1f Merge pull request # 265 from danwinship/fix-dumb-api-mistake
  > 1a15be2 Merge pull request # 270 from dashpole/trace_panic
  > ba5a213 Fix an API accident with net.IPFamily
  > 61b03e2 Merge pull request # 268 from petr-muller/deprecation-convention
  > 71bfc7b make traces safe for concurrent use
  > cfd413d Merge pull request # 263 from saltbo/fix-invalid-gha-goverion
  > d90ac11 pointer: make deprecation comments follow convention
  > 460b63a demonstrate trace panic
  > 4270251 Merge pull request # 259 from LJTian/master
  > 4a5ee0b fix: update the go-versions format for the gha
  > 665eaae Merge pull request # 261 from liggitt/clean-deps
  > 1be0ed5 Update Go standard libs address to reduce jump time
  > 7796b5f Merge pull request # 260 from dims/bump-dependencies-and-go-language-version
  > 25648b1 Drop testify dependency
  > e9cbc92 Merge pull request # 242 from MushuEE/patch-3
  > c9660c8 Bump dependencies and go language version
  > 49b64f9 Drop afero dependency
  > ad59060 Merge pull request # 253 from kschoche/add_uint_to_pointer_pkg
  > d7bf925 Ineffective break statements triggering SA4011
  > 2e139fc Merge pull request # 254 from dims/bump-version-of-golang-to-1.19
  > d45ae35 add uint64 and uint to pointer pkg
  > e3a7968 Bump version of golang to 1.19
bumping k8s.io/klog/v2 0990e81...9ae4992:
  > 9ae4992 Merge pull request # 355 from pohly/call-overhead-benchmarks
  > cb9292a Merge pull request # 349 from pohly/init-flags-concurrency
  > f08fd26 klog: benchmark the overhead when logging is off
  > 02fe323 Merge pull request # 345 from dims/bump-version-of-golang-to-1.19-and-drop-older-versions
  > 28f7906 make InitFlags read-only
  > d64acbd Merge pull request # 344 from harshanarayana/bug/GIT-343/logr-handle-marshalling-non-string-values
  > 8c0f205 reformat to golang 1.19 standards
  > a952486 add test for the command line usage
  > dcddc5f kvlistformat: fix the issue with display marshalled value for non string type
  > 6f5eeb9 Bump version of golang to 1.19 and prune older versions
bumping knative.dev/pkg 0243d64...dca788a:
  > dca788a Min K8s version is now 1.24 (# 2639)
  > 6255ebd upgrade to latest dependencies (# 2638)
bumping k8s.io/apimachinery 478dd6e...4fbe8e4:
  > 4fbe8e4 Merge pull request # 112218 from haoruan/automated-cherry-pick-of-# 111936-upstream-release-1.25
  > cf171ba Merge pull request # 112808 from cheftako/automated-cherry-pick-of-# 112689-upstream-release-1.25
  > b4db414 Marshal MicroTime to json and proto at the same precision
  > cb0507f Updated vendor to the new preferred versions.
bumping k8s.io/client-go 593f096...7226b15:
  > 7226b15 Update dependencies to v0.25.4 tag
  > 166ab05 Merge pull request # 112808 from cheftako/automated-cherry-pick-of-# 112689-upstream-release-1.25
  > 4b5a638 Updated vendor to the new preferred versions.

Signed-off-by: Knative Automation <automation@knative.team>

Signed-off-by: Knative Automation <automation@knative.team>
This commit is contained in:
knative-automation 2022-11-16 13:35:39 +00:00 committed by GitHub
parent 9712d6eadf
commit 006045e4a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 359 additions and 198 deletions

18
go.mod
View File

@ -6,13 +6,13 @@ require (
github.com/google/go-cmp v0.5.8
github.com/hashicorp/golang-lru v0.5.4
go.uber.org/zap v1.19.1
k8s.io/api v0.25.2
k8s.io/apimachinery v0.25.2
k8s.io/client-go v0.25.2
k8s.io/code-generator v0.25.2
k8s.io/api v0.25.4
k8s.io/apimachinery v0.25.4
k8s.io/client-go v0.25.4
k8s.io/code-generator v0.25.4
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1
knative.dev/hack v0.0.0-20221114224536-b0354624aa29
knative.dev/pkg v0.0.0-20221107171117-0243d641354d
knative.dev/hack v0.0.0-20221115211737-de2ff401a852
knative.dev/pkg v0.0.0-20221115192737-dca788a951f3
)
require (
@ -78,9 +78,9 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/gengo v0.0.0-20220613173612-397b4ae3bce7 // indirect
k8s.io/klog/v2 v2.70.2-0.20220707122935-0990e81f1a8f // indirect
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
k8s.io/gengo v0.0.0-20221011193443-fad74ee6edd9 // indirect
k8s.io/klog/v2 v2.80.2-0.20221028030830-9ae4992afb54 // indirect
k8s.io/utils v0.0.0-20221108210102-8e77b1f39fe2 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect

43
go.sum
View File

@ -120,7 +120,6 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih4=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
@ -317,7 +316,6 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
@ -328,8 +326,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
@ -348,8 +346,8 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723 h1:sHOAIxRGBp443oHZIPB+HsUGaksVCXVQENPxwTfQdH4=
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
@ -783,28 +781,27 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.25.2 h1:v6G8RyFcwf0HR5jQGIAYlvtRNrxMJQG1xJzaSeVnIS8=
k8s.io/api v0.25.2/go.mod h1:qP1Rn4sCVFwx/xIhe+we2cwBLTXNcheRyYXwajonhy0=
k8s.io/apimachinery v0.25.2 h1:WbxfAjCx+AeN8Ilp9joWnyJ6xu9OMeS/fsfjK/5zaQs=
k8s.io/apimachinery v0.25.2/go.mod h1:hqqA1X0bsgsxI6dXsJ4HnNTBOmJNxyPp8dw3u2fSHwA=
k8s.io/client-go v0.25.2 h1:SUPp9p5CwM0yXGQrwYurw9LWz+YtMwhWd0GqOsSiefo=
k8s.io/client-go v0.25.2/go.mod h1:i7cNU7N+yGQmJkewcRD2+Vuj4iz7b30kI8OcL3horQ4=
k8s.io/code-generator v0.25.2 h1:qEHux0+E1c+j1MhsWn9+4Z6av8zrZBixOTPW064rSiY=
k8s.io/code-generator v0.25.2/go.mod h1:f61OcU2VqVQcjt/6TrU0sta1TA5hHkOO6ZZPwkL9Eys=
k8s.io/gengo v0.0.0-20220613173612-397b4ae3bce7 h1:RGb68G3yotdQggcyenx9y0+lnVJCXXcLa6geXOMlf5o=
k8s.io/gengo v0.0.0-20220613173612-397b4ae3bce7/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
k8s.io/api v0.25.4 h1:3YO8J4RtmG7elEgaWMb4HgmpS2CfY1QlaOz9nwB+ZSs=
k8s.io/api v0.25.4/go.mod h1:IG2+RzyPQLllQxnhzD8KQNEu4c4YvyDTpSMztf4A0OQ=
k8s.io/apimachinery v0.25.4 h1:CtXsuaitMESSu339tfhVXhQrPET+EiWnIY1rcurKnAc=
k8s.io/apimachinery v0.25.4/go.mod h1:jaF9C/iPNM1FuLl7Zuy5b9v+n35HGSh6AQ4HYRkCqwo=
k8s.io/client-go v0.25.4 h1:3RNRDffAkNU56M/a7gUfXaEzdhZlYhoW8dgViGy5fn8=
k8s.io/client-go v0.25.4/go.mod h1:8trHCAC83XKY0wsBIpbirZU4NTUpbuhc2JnI7OruGZw=
k8s.io/code-generator v0.25.4 h1:tjQ7/+9eN7UOiU2DP+0v4ntTI4JZLi2c1N0WllpFhTc=
k8s.io/code-generator v0.25.4/go.mod h1:9F5fuVZOMWRme7MYj2YT3L9ropPWPokd9VRhVyD3+0w=
k8s.io/gengo v0.0.0-20221011193443-fad74ee6edd9 h1:iu3o/SxaHVI7tKPtkGzD3M9IzrE21j+CUKH98NQJ8Ms=
k8s.io/gengo v0.0.0-20221011193443-fad74ee6edd9/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
k8s.io/klog/v2 v2.70.2-0.20220707122935-0990e81f1a8f h1:dltw7bAn8bCrQ2CmzzhgoieUZEbWqrvIGVdHGioP5nY=
k8s.io/klog/v2 v2.70.2-0.20220707122935-0990e81f1a8f/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/klog/v2 v2.80.2-0.20221028030830-9ae4992afb54 h1:hWRbsoRWt44OEBnYUd4ceLy4ofBoh+p9vauWp/I5Gdg=
k8s.io/klog/v2 v2.80.2-0.20221028030830-9ae4992afb54/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 h1:MQ8BAZPZlWk3S9K4a9NCkIFQtZShWqoha7snGixVgEA=
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1/go.mod h1:C/N6wCaBHeBHkHUesQOQy2/MZqGgMAFPqGsGQLdbZBU=
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed h1:jAne/RjBTyawwAy0utX5eqigAwz/lQhTmy+Hr/Cpue4=
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
knative.dev/hack v0.0.0-20221114224536-b0354624aa29 h1:FUHfJXlY5e9wFuSf5JlMONy/fQbofS7hEBfOMXLHXso=
knative.dev/hack v0.0.0-20221114224536-b0354624aa29/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
knative.dev/pkg v0.0.0-20221107171117-0243d641354d h1:ACj/4O74QvoB8zE/mlg1ji680gFW7RaUIjAL1x5IN58=
knative.dev/pkg v0.0.0-20221107171117-0243d641354d/go.mod h1:JwNkOLWAeuMYlH9WQA83k+afGCanWcvWvdXZsI3xKo4=
k8s.io/utils v0.0.0-20221108210102-8e77b1f39fe2 h1:GfD9OzL11kvZN5iArC6oTS7RTj7oJOIfnislxYlqTj8=
k8s.io/utils v0.0.0-20221108210102-8e77b1f39fe2/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
knative.dev/hack v0.0.0-20221115211737-de2ff401a852 h1:/uB4umKUahDlWbIC96rSETG2BYA0zwQ02SGuM9ZYdOo=
knative.dev/hack v0.0.0-20221115211737-de2ff401a852/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
knative.dev/pkg v0.0.0-20221115192737-dca788a951f3 h1:6saLhpYxTxGqXZTVSdw8JySNapiqt6QQnWNnyRfDjmw=
knative.dev/pkg v0.0.0-20221115192737-dca788a951f3/go.mod h1:QVePbTmHjPK+FRzlqqCzTU17EYsHHr15vPIUedJ+JWw=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

View File

@ -27,9 +27,12 @@ func (m *MicroTime) ProtoMicroTime() *Timestamp {
if m == nil {
return &Timestamp{}
}
// truncate precision to microseconds to match JSON marshaling/unmarshaling
truncatedNanoseconds := time.Duration(m.Time.Nanosecond()).Truncate(time.Microsecond)
return &Timestamp{
Seconds: m.Time.Unix(),
Nanos: int32(m.Time.Nanosecond()),
Nanos: int32(truncatedNanoseconds),
}
}
@ -51,7 +54,10 @@ func (m *MicroTime) Unmarshal(data []byte) error {
if err := p.Unmarshal(data); err != nil {
return err
}
m.Time = time.Unix(p.Seconds, int64(p.Nanos)).Local()
// truncate precision to microseconds to match JSON marshaling/unmarshaling
truncatedNanoseconds := time.Duration(p.Nanos).Truncate(time.Microsecond)
m.Time = time.Unix(p.Seconds, int64(truncatedNanoseconds)).Local()
return nil
}

View File

@ -173,19 +173,25 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
pkgNeedsGeneration := (ptagValue == tagValuePackage)
if !pkgNeedsGeneration {
// If the pkg-scoped tag did not exist, scan all types for one that
// explicitly wants generation.
// explicitly wants generation. Ensure all types that want generation
// can be copied.
var uncopyable []string
for _, t := range pkg.Types {
klog.V(5).Infof(" considering type %q", t.Name.String())
ttag := extractEnabledTypeTag(t)
if ttag != nil && ttag.value == "true" {
klog.V(5).Infof(" tag=true")
if !copyableType(t) {
klog.Fatalf("Type %v requests deepcopy generation but is not copyable", t)
uncopyable = append(uncopyable, fmt.Sprintf("%v", t))
} else {
pkgNeedsGeneration = true
}
pkgNeedsGeneration = true
break
}
}
if len(uncopyable) > 0 {
klog.Fatalf("Types requested deepcopy generation but are not copyable: %s",
strings.Join(uncopyable, ", "))
}
}
if pkgNeedsGeneration {

View File

@ -23,6 +23,7 @@ import (
"io"
"path/filepath"
"reflect"
"regexp"
"strconv"
"strings"
@ -497,6 +498,23 @@ func mustEnforceDefault(t *types.Type, depth int, omitEmpty bool) (interface{},
}
}
var refRE = regexp.MustCompile(`^ref\((?P<reference>[^"]+)\)$`)
var refREIdentIndex = refRE.SubexpIndex("reference")
// parseAsRef looks for strings that match one of the following:
// - ref(Ident)
// - ref(pkgpath.Ident)
// If the input string matches either of these, it will return the (optional)
// pkgpath, the Ident, and true. Otherwise it will return empty strings and
// false.
func parseAsRef(s string) (string, bool) {
matches := refRE.FindStringSubmatch(s)
if len(matches) < refREIdentIndex || matches[refREIdentIndex] == "" {
return "", false
}
return matches[refREIdentIndex], true
}
func populateDefaultValue(node *callNode, t *types.Type, tags string, commentLines []string) *callNode {
defaultMap := extractDefaultTag(commentLines)
var defaultString string
@ -513,8 +531,12 @@ func populateDefaultValue(node *callNode, t *types.Type, tags string, commentLin
} else if len(defaultMap) == 0 {
return node
}
var symbolReference string
var defaultValue interface{}
if err := json.Unmarshal([]byte(defaultString), &defaultValue); err != nil {
if id, ok := parseAsRef(defaultString); ok {
symbolReference = id
defaultString = ""
} else if err := json.Unmarshal([]byte(defaultString), &defaultValue); err != nil {
klog.Fatalf("Failed to unmarshal default: %v", err)
}
@ -542,7 +564,8 @@ func populateDefaultValue(node *callNode, t *types.Type, tags string, commentLin
node.defaultIsPrimitive = t.IsPrimitive()
node.defaultType = t.String()
node.defaultValue = defaultString
node.defaultValue.InlineConstant = defaultString
node.defaultValue.SymbolReference = symbolReference
node.defaultDepth = depth
return node
}
@ -668,6 +691,11 @@ const (
conversionPackagePath = "k8s.io/apimachinery/pkg/conversion"
)
type symbolTracker interface {
namer.ImportTracker
AddSymbol(types.Name)
}
// genDefaulter produces a file with a autogenerated conversions.
type genDefaulter struct {
generator.DefaultGen
@ -676,7 +704,7 @@ type genDefaulter struct {
peerPackages []string
newDefaulters defaulterFuncMap
existingDefaulters defaulterFuncMap
imports namer.ImportTracker
imports symbolTracker
typesForInit []*types.Type
}
@ -766,6 +794,24 @@ func (g *genDefaulter) GenerateType(c *generator.Context, t *types.Type, w io.Wr
}
i := 0
callTree.VisitInOrder(func(ancestors []*callNode, current *callNode) {
if len(current.defaultValue.SymbolReference) > 0 {
// If the defaultValue was a reference to a symbol instead of a constant,
// make sure to add it to imports and resolve the name of the symbol
// before generating the defaults.
parsedName := types.ParseFullyQualifiedName(current.defaultValue.SymbolReference)
g.imports.AddSymbol(parsedName)
// Rewrite the fully qualified name using the local package name
// from the imports
localPackage := g.imports.LocalNameOf(parsedName.Package)
if len(localPackage) > 0 {
current.defaultValue.SymbolReference = localPackage + "." + parsedName.Name
} else {
current.defaultValue.SymbolReference = parsedName.Name
}
}
if len(current.call) == 0 {
return
}
@ -795,26 +841,26 @@ func (g *genDefaulter) generateDefaulter(inType *types.Type, callTree *callNode,
// how in Go code an access would be performed. For example, if a defaulting function exists on a container
// lifecycle hook, to invoke that defaulter correctly would require this Go code:
//
// for i := range pod.Spec.Containers {
// o := &pod.Spec.Containers[i]
// if o.LifecycleHook != nil {
// SetDefaults_LifecycleHook(o.LifecycleHook)
// }
// }
// for i := range pod.Spec.Containers {
// o := &pod.Spec.Containers[i]
// if o.LifecycleHook != nil {
// SetDefaults_LifecycleHook(o.LifecycleHook)
// }
// }
//
// That would be represented by a call tree like:
//
// callNode
// field: "Spec"
// children:
// - field: "Containers"
// children:
// - index: true
// children:
// - field: "LifecycleHook"
// elem: true
// call:
// - SetDefaults_LifecycleHook
// callNode
// field: "Spec"
// children:
// - field: "Containers"
// children:
// - index: true
// children:
// - field: "LifecycleHook"
// elem: true
// call:
// - SetDefaults_LifecycleHook
//
// which we can traverse to build that Go struct (you must call the field Spec, then Containers, then range over
// that field, then check whether the LifecycleHook field is nil, before calling SetDefaults_LifecycleHook on
@ -836,7 +882,7 @@ type callNode struct {
// defaultValue is the defaultValue of a callNode struct
// Only primitive types and pointer types are eligible to have a default value
defaultValue string
defaultValue defaultValue
// defaultIsPrimitive is used to determine how to assign the default value.
// Primitive types will be directly assigned while complex types will use JSON unmarshalling
@ -862,6 +908,28 @@ type callNode struct {
defaultType string
}
type defaultValue struct {
// The value was written directly in the marker comment and
// has been parsed as JSON
InlineConstant string
// The name of the symbol relative to the parsed package path
// i.e. k8s.io/pkg.apis.v1.Foo if from another package or simply `Foo`
// if within the same package.
SymbolReference string
}
func (d defaultValue) IsEmpty() bool {
resolved := d.Resolved()
return resolved == ""
}
func (d defaultValue) Resolved() string {
if len(d.InlineConstant) > 0 {
return d.InlineConstant
}
return d.SymbolReference
}
// CallNodeVisitorFunc is a function for visiting a call tree. ancestors is the list of all parents
// of this node to the root of the tree - will be empty at the root.
type CallNodeVisitorFunc func(ancestors []*callNode, node *callNode)
@ -929,11 +997,11 @@ func getTypeZeroValue(t string) (interface{}, error) {
}
func (n *callNode) writeDefaulter(varName string, index string, isVarPointer bool, sw *generator.SnippetWriter) {
if n.defaultValue == "" {
if n.defaultValue.IsEmpty() {
return
}
args := generator.Args{
"defaultValue": n.defaultValue,
"defaultValue": n.defaultValue.Resolved(),
"varName": varName,
"index": index,
"varDepth": n.defaultDepth,
@ -1046,7 +1114,7 @@ func (n *callNode) WriteMethod(varName string, depth int, ancestors []*callNode,
}
sw.Do("}\n", nil)
case n.key:
if n.defaultValue != "" {
if !n.defaultValue.IsEmpty() {
// Map keys are typed and cannot share the same index variable as arrays and other maps
index = index + "_" + ancestors[len(ancestors)-1].field
vars["index"] = index

View File

@ -255,15 +255,15 @@ func (s $.type|public$) Clone() $.type|public$ {
return result
}
// Difference returns a set of objects that are not in s2
// Difference returns a set of objects that are not in s2.
// For example:
// s1 = {a1, a2, a3}
// s2 = {a1, a2, a4, a5}
// s1.Difference(s2) = {a3}
// s2.Difference(s1) = {a4, a5}
func (s $.type|public$) Difference(s2 $.type|public$) $.type|public$ {
func (s1 $.type|public$) Difference(s2 $.type|public$) $.type|public$ {
result := New$.type|public$()
for key := range s {
for key := range s1 {
if !s2.Has(key) {
result.Insert(key)
}
@ -271,6 +271,16 @@ func (s $.type|public$) Difference(s2 $.type|public$) $.type|public$ {
return result
}
// SymmetricDifference returns a set of elements which are in either of the sets, but not in their intersection.
// For example:
// s1 = {a1, a2, a3}
// s2 = {a1, a2, a4, a5}
// s1.SymmetricDifference(s2) = {a3, a4, a5}
// s2.SymmetricDifference(s1) = {a3, a4, a5}
func (s1 $.type|public$) SymmetricDifference(s2 $.type|public$) $.type|public$ {
return s1.Difference(s2).Union(s2.Difference(s1))
}
// Union returns a new set which includes items in either s1 or s2.
// For example:
// s1 = {a1, a2}

View File

@ -96,15 +96,15 @@ func (s Byte) Clone() Byte {
return result
}
// Difference returns a set of objects that are not in s2
// Difference returns a set of objects that are not in s2.
// For example:
// s1 = {a1, a2, a3}
// s2 = {a1, a2, a4, a5}
// s1.Difference(s2) = {a3}
// s2.Difference(s1) = {a4, a5}
func (s Byte) Difference(s2 Byte) Byte {
func (s1 Byte) Difference(s2 Byte) Byte {
result := NewByte()
for key := range s {
for key := range s1 {
if !s2.Has(key) {
result.Insert(key)
}
@ -112,6 +112,16 @@ func (s Byte) Difference(s2 Byte) Byte {
return result
}
// SymmetricDifference returns a set of elements which are in either of the sets, but not in their intersection.
// For example:
// s1 = {a1, a2, a3}
// s2 = {a1, a2, a4, a5}
// s1.SymmetricDifference(s2) = {a3, a4, a5}
// s2.SymmetricDifference(s1) = {a3, a4, a5}
func (s1 Byte) SymmetricDifference(s2 Byte) Byte {
return s1.Difference(s2).Union(s2.Difference(s1))
}
// Union returns a new set which includes items in either s1 or s2.
// For example:
// s1 = {a1, a2}

View File

@ -96,15 +96,15 @@ func (s Int) Clone() Int {
return result
}
// Difference returns a set of objects that are not in s2
// Difference returns a set of objects that are not in s2.
// For example:
// s1 = {a1, a2, a3}
// s2 = {a1, a2, a4, a5}
// s1.Difference(s2) = {a3}
// s2.Difference(s1) = {a4, a5}
func (s Int) Difference(s2 Int) Int {
func (s1 Int) Difference(s2 Int) Int {
result := NewInt()
for key := range s {
for key := range s1 {
if !s2.Has(key) {
result.Insert(key)
}
@ -112,6 +112,16 @@ func (s Int) Difference(s2 Int) Int {
return result
}
// SymmetricDifference returns a set of elements which are in either of the sets, but not in their intersection.
// For example:
// s1 = {a1, a2, a3}
// s2 = {a1, a2, a4, a5}
// s1.SymmetricDifference(s2) = {a3, a4, a5}
// s2.SymmetricDifference(s1) = {a3, a4, a5}
func (s1 Int) SymmetricDifference(s2 Int) Int {
return s1.Difference(s2).Union(s2.Difference(s1))
}
// Union returns a new set which includes items in either s1 or s2.
// For example:
// s1 = {a1, a2}

View File

@ -96,15 +96,15 @@ func (s Int64) Clone() Int64 {
return result
}
// Difference returns a set of objects that are not in s2
// Difference returns a set of objects that are not in s2.
// For example:
// s1 = {a1, a2, a3}
// s2 = {a1, a2, a4, a5}
// s1.Difference(s2) = {a3}
// s2.Difference(s1) = {a4, a5}
func (s Int64) Difference(s2 Int64) Int64 {
func (s1 Int64) Difference(s2 Int64) Int64 {
result := NewInt64()
for key := range s {
for key := range s1 {
if !s2.Has(key) {
result.Insert(key)
}
@ -112,6 +112,16 @@ func (s Int64) Difference(s2 Int64) Int64 {
return result
}
// SymmetricDifference returns a set of elements which are in either of the sets, but not in their intersection.
// For example:
// s1 = {a1, a2, a3}
// s2 = {a1, a2, a4, a5}
// s1.SymmetricDifference(s2) = {a3, a4, a5}
// s2.SymmetricDifference(s1) = {a3, a4, a5}
func (s1 Int64) SymmetricDifference(s2 Int64) Int64 {
return s1.Difference(s2).Union(s2.Difference(s1))
}
// Union returns a new set which includes items in either s1 or s2.
// For example:
// s1 = {a1, a2}

View File

@ -96,15 +96,15 @@ func (s String) Clone() String {
return result
}
// Difference returns a set of objects that are not in s2
// Difference returns a set of objects that are not in s2.
// For example:
// s1 = {a1, a2, a3}
// s2 = {a1, a2, a4, a5}
// s1.Difference(s2) = {a3}
// s2.Difference(s1) = {a4, a5}
func (s String) Difference(s2 String) String {
func (s1 String) Difference(s2 String) String {
result := NewString()
for key := range s {
for key := range s1 {
if !s2.Has(key) {
result.Insert(key)
}
@ -112,6 +112,16 @@ func (s String) Difference(s2 String) String {
return result
}
// SymmetricDifference returns a set of elements which are in either of the sets, but not in their intersection.
// For example:
// s1 = {a1, a2, a3}
// s2 = {a1, a2, a4, a5}
// s1.SymmetricDifference(s2) = {a3, a4, a5}
// s2.SymmetricDifference(s1) = {a3, a4, a5}
func (s1 String) SymmetricDifference(s2 String) String {
return s1.Difference(s2).Union(s2.Difference(s1))
}
// Union returns a new set which includes items in either s1 or s2.
// For example:
// s1 = {a1, a2}

View File

@ -26,7 +26,7 @@ import (
"k8s.io/gengo/types"
)
func NewImportTracker(typesToAdd ...*types.Type) namer.ImportTracker {
func NewImportTracker(typesToAdd ...*types.Type) *namer.DefaultImportTracker {
tracker := namer.NewDefaultImportTracker(types.Name{})
tracker.IsInvalidType = func(*types.Type) bool { return false }
tracker.LocalName = func(name types.Name) string { return golangTrackerLocalName(&tracker, name) }

View File

@ -55,6 +55,27 @@ func (tracker *DefaultImportTracker) AddTypes(types ...*types.Type) {
tracker.AddType(t)
}
}
func (tracker *DefaultImportTracker) AddSymbol(symbol types.Name) {
if tracker.local.Package == symbol.Package {
return
}
if len(symbol.Package) == 0 {
return
}
path := symbol.Path
if len(path) == 0 {
path = symbol.Package
}
if _, ok := tracker.pathToName[path]; ok {
return
}
name := tracker.LocalName(symbol)
tracker.nameToPath[name] = path
tracker.pathToName[path] = name
}
func (tracker *DefaultImportTracker) AddType(t *types.Type) {
if tracker.local.Package == t.Name.Package {
return
@ -70,19 +91,7 @@ func (tracker *DefaultImportTracker) AddType(t *types.Type) {
return
}
if len(t.Name.Package) == 0 {
return
}
path := t.Name.Path
if len(path) == 0 {
path = t.Name.Package
}
if _, ok := tracker.pathToName[path]; ok {
return
}
name := tracker.LocalName(t.Name)
tracker.nameToPath[name] = path
tracker.pathToName[path] = name
tracker.AddSymbol(t.Name)
}
func (tracker *DefaultImportTracker) ImportLines() []string {

View File

@ -47,8 +47,9 @@ var (
// If set, all log lines will be suppressed from the regular output, and
// redirected to the logr implementation.
// Use as:
// ...
// klog.SetLogger(zapr.NewLogger(zapLog))
//
// ...
// klog.SetLogger(zapr.NewLogger(zapLog))
//
// To remove a backing logr implemention, use ClearLogger. Setting an
// empty logger with SetLogger(logr.Logger{}) does not work.

View File

@ -145,7 +145,7 @@ func KVListFormat(b *bytes.Buffer, keysAndValues ...interface{}) {
case string:
writeStringValue(b, true, value)
default:
writeStringValue(b, false, fmt.Sprintf("%+v", v))
writeStringValue(b, false, fmt.Sprintf("%+v", value))
}
case []byte:
// In https://github.com/kubernetes/klog/pull/237 it was decided

137
vendor/k8s.io/klog/v2/klog.go generated vendored
View File

@ -39,39 +39,38 @@
// This package provides several flags that modify this behavior.
// As a result, flag.Parse must be called before any logging is done.
//
// -logtostderr=true
// Logs are written to standard error instead of to files.
// This shortcuts most of the usual output routing:
// -alsologtostderr, -stderrthreshold and -log_dir have no
// effect and output redirection at runtime with SetOutput is
// ignored.
// -alsologtostderr=false
// Logs are written to standard error as well as to files.
// -stderrthreshold=ERROR
// Log events at or above this severity are logged to standard
// error as well as to files.
// -log_dir=""
// Log files will be written to this directory instead of the
// default temporary directory.
// -logtostderr=true
// Logs are written to standard error instead of to files.
// This shortcuts most of the usual output routing:
// -alsologtostderr, -stderrthreshold and -log_dir have no
// effect and output redirection at runtime with SetOutput is
// ignored.
// -alsologtostderr=false
// Logs are written to standard error as well as to files.
// -stderrthreshold=ERROR
// Log events at or above this severity are logged to standard
// error as well as to files.
// -log_dir=""
// Log files will be written to this directory instead of the
// default temporary directory.
//
// Other flags provide aids to debugging.
//
// -log_backtrace_at=""
// When set to a file and line number holding a logging statement,
// such as
// -log_backtrace_at=gopherflakes.go:234
// a stack trace will be written to the Info log whenever execution
// hits that statement. (Unlike with -vmodule, the ".go" must be
// present.)
// -v=0
// Enable V-leveled logging at the specified level.
// -vmodule=""
// The syntax of the argument is a comma-separated list of pattern=N,
// where pattern is a literal file name (minus the ".go" suffix) or
// "glob" pattern and N is a V level. For instance,
// -vmodule=gopher*=3
// sets the V level to 3 in all Go files whose names begin "gopher".
// Other flags provide aids to debugging.
//
// -log_backtrace_at=""
// When set to a file and line number holding a logging statement,
// such as
// -log_backtrace_at=gopherflakes.go:234
// a stack trace will be written to the Info log whenever execution
// hits that statement. (Unlike with -vmodule, the ".go" must be
// present.)
// -v=0
// Enable V-leveled logging at the specified level.
// -vmodule=""
// The syntax of the argument is a comma-separated list of pattern=N,
// where pattern is a literal file name (minus the ".go" suffix) or
// "glob" pattern and N is a V level. For instance,
// -vmodule=gopher*=3
// sets the V level to 3 in all Go files whose names begin "gopher".
package klog
import (
@ -397,45 +396,48 @@ type flushSyncWriter interface {
io.Writer
}
// init sets up the defaults.
var logging loggingT
var commandLine flag.FlagSet
// init sets up the defaults and creates command line flags.
func init() {
commandLine.StringVar(&logging.logDir, "log_dir", "", "If non-empty, write log files in this directory (no effect when -logtostderr=true)")
commandLine.StringVar(&logging.logFile, "log_file", "", "If non-empty, use this log file (no effect when -logtostderr=true)")
commandLine.Uint64Var(&logging.logFileMaxSizeMB, "log_file_max_size", 1800,
"Defines the maximum size a log file can grow to (no effect when -logtostderr=true). Unit is megabytes. "+
"If the value is 0, the maximum file size is unlimited.")
commandLine.BoolVar(&logging.toStderr, "logtostderr", true, "log to standard error instead of files")
commandLine.BoolVar(&logging.alsoToStderr, "alsologtostderr", false, "log to standard error as well as files (no effect when -logtostderr=true)")
logging.setVState(0, nil, false)
commandLine.Var(&logging.verbosity, "v", "number for the log level verbosity")
commandLine.BoolVar(&logging.addDirHeader, "add_dir_header", false, "If true, adds the file directory to the header of the log messages")
commandLine.BoolVar(&logging.skipHeaders, "skip_headers", false, "If true, avoid header prefixes in the log messages")
commandLine.BoolVar(&logging.oneOutput, "one_output", false, "If true, only write logs to their native severity level (vs also writing to each lower severity level; no effect when -logtostderr=true)")
commandLine.BoolVar(&logging.skipLogHeaders, "skip_log_headers", false, "If true, avoid headers when opening log files (no effect when -logtostderr=true)")
logging.stderrThreshold = severityValue{
Severity: severity.ErrorLog, // Default stderrThreshold is ERROR.
}
logging.setVState(0, nil, false)
logging.logDir = ""
logging.logFile = ""
logging.logFileMaxSizeMB = 1800
logging.toStderr = true
logging.alsoToStderr = false
logging.skipHeaders = false
logging.addDirHeader = false
logging.skipLogHeaders = false
logging.oneOutput = false
commandLine.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=false)")
commandLine.Var(&logging.vmodule, "vmodule", "comma-separated list of pattern=N settings for file-filtered logging")
commandLine.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")
logging.settings.contextualLoggingEnabled = true
logging.flushD = newFlushDaemon(logging.lockAndFlushAll, nil)
}
// InitFlags is for explicitly initializing the flags.
// It may get called repeatedly for different flagsets, but not
// twice for the same one. May get called concurrently
// to other goroutines using klog. However, only some flags
// may get set concurrently (see implementation).
func InitFlags(flagset *flag.FlagSet) {
if flagset == nil {
flagset = flag.CommandLine
}
flagset.StringVar(&logging.logDir, "log_dir", logging.logDir, "If non-empty, write log files in this directory (no effect when -logtostderr=true)")
flagset.StringVar(&logging.logFile, "log_file", logging.logFile, "If non-empty, use this log file (no effect when -logtostderr=true)")
flagset.Uint64Var(&logging.logFileMaxSizeMB, "log_file_max_size", logging.logFileMaxSizeMB,
"Defines the maximum size a log file can grow to (no effect when -logtostderr=true). Unit is megabytes. "+
"If the value is 0, the maximum file size is unlimited.")
flagset.BoolVar(&logging.toStderr, "logtostderr", logging.toStderr, "log to standard error instead of files")
flagset.BoolVar(&logging.alsoToStderr, "alsologtostderr", logging.alsoToStderr, "log to standard error as well as files (no effect when -logtostderr=true)")
flagset.Var(&logging.verbosity, "v", "number for the log level verbosity")
flagset.BoolVar(&logging.addDirHeader, "add_dir_header", logging.addDirHeader, "If true, adds the file directory to the header of the log messages")
flagset.BoolVar(&logging.skipHeaders, "skip_headers", logging.skipHeaders, "If true, avoid header prefixes in the log messages")
flagset.BoolVar(&logging.oneOutput, "one_output", logging.oneOutput, "If true, only write logs to their native severity level (vs also writing to each lower severity level; no effect when -logtostderr=true)")
flagset.BoolVar(&logging.skipLogHeaders, "skip_log_headers", logging.skipLogHeaders, "If true, avoid headers when opening log files (no effect when -logtostderr=true)")
flagset.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=false)")
flagset.Var(&logging.vmodule, "vmodule", "comma-separated list of pattern=N settings for file-filtered logging")
flagset.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")
commandLine.VisitAll(func(f *flag.Flag) {
flagset.Var(f.Value, f.Name, f.Usage)
})
}
// Flush flushes all pending log I/O.
@ -550,12 +552,6 @@ type loggingT struct {
vmap map[uintptr]Level
}
var logging = loggingT{
settings: settings{
contextualLoggingEnabled: true,
},
}
// setVState sets a consistent state for V logging.
// l.mu is held.
func (l *loggingT) setVState(verbosity Level, filter []modulePat, setFilter bool) {
@ -633,8 +629,11 @@ It returns a buffer containing the formatted header and the user's file and line
The depth specifies how many stack frames above lives the source line to be identified in the log message.
Log lines have this form:
Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg...
where the fields are defined as follows:
L A single character, representing the log level (eg 'I' for INFO)
mm The month (zero padded; ie May is '05')
dd The day (zero padded)
@ -1298,9 +1297,13 @@ func newVerbose(level Level, b bool) Verbose {
// The returned value is a struct of type Verbose, which implements Info, Infoln
// and Infof. These methods will write to the Info log if called.
// Thus, one may write either
//
// if klog.V(2).Enabled() { klog.Info("log this") }
//
// or
//
// klog.V(2).Info("log this")
//
// The second form is shorter but the first is cheaper if logging is off because it does
// not evaluate its arguments.
//
@ -1582,10 +1585,10 @@ func ErrorSDepth(depth int, err error, msg string, keysAndValues ...interface{})
//
// Callers who want more control over handling of fatal events may instead use a
// combination of different functions:
// - some info or error logging function, optionally with a stack trace
// value generated by github.com/go-logr/lib/dbg.Backtrace
// - Flush to flush pending log data
// - panic, os.Exit or returning to the caller with an error
// - some info or error logging function, optionally with a stack trace
// value generated by github.com/go-logr/lib/dbg.Backtrace
// - Flush to flush pending log data
// - panic, os.Exit or returning to the caller with an error
//
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
func Fatal(args ...interface{}) {

2
vendor/k8s.io/utils/net/port.go generated vendored
View File

@ -29,7 +29,7 @@ type IPFamily string
// Constants for valid IPFamilys:
const (
IPv4 IPFamily = "4"
IPv6 = "6"
IPv6 IPFamily = "6"
)
// Protocol is a network protocol support by LocalPort.

30
vendor/k8s.io/utils/trace/trace.go generated vendored
View File

@ -21,6 +21,7 @@ import (
"context"
"fmt"
"math/rand"
"sync"
"time"
"k8s.io/klog/v2"
@ -93,13 +94,16 @@ func (s traceStep) writeItem(b *bytes.Buffer, formatter string, startTime time.T
// Trace keeps track of a set of "steps" and allows us to log a specific
// step if it took longer than its share of the total allowed time
type Trace struct {
// constant fields
name string
fields []Field
threshold *time.Duration
startTime time.Time
endTime *time.Time
traceItems []traceItem
parentTrace *Trace
// fields guarded by a lock
lock sync.RWMutex
threshold *time.Duration
endTime *time.Time
traceItems []traceItem
}
func (t *Trace) time() time.Time {
@ -138,6 +142,8 @@ func New(name string, fields ...Field) *Trace {
// how long it took. The Fields add key value pairs to provide additional details about the trace
// step.
func (t *Trace) Step(msg string, fields ...Field) {
t.lock.Lock()
defer t.lock.Unlock()
if t.traceItems == nil {
// traces almost always have less than 6 steps, do this to avoid more than a single allocation
t.traceItems = make([]traceItem, 0, 6)
@ -153,7 +159,9 @@ func (t *Trace) Nest(msg string, fields ...Field) *Trace {
newTrace := New(msg, fields...)
if t != nil {
newTrace.parentTrace = t
t.lock.Lock()
t.traceItems = append(t.traceItems, newTrace)
t.lock.Unlock()
}
return newTrace
}
@ -163,7 +171,9 @@ func (t *Trace) Nest(msg string, fields ...Field) *Trace {
// is logged.
func (t *Trace) Log() {
endTime := time.Now()
t.lock.Lock()
t.endTime = &endTime
t.lock.Unlock()
// an explicit logging request should dump all the steps out at the higher level
if t.parentTrace == nil { // We don't start logging until Log or LogIfLong is called on the root trace
t.logTrace()
@ -178,13 +188,17 @@ func (t *Trace) Log() {
// If the Trace is nested it is not immediately logged. Instead, it is logged when the trace it
// is nested within is logged.
func (t *Trace) LogIfLong(threshold time.Duration) {
t.lock.Lock()
t.threshold = &threshold
t.lock.Unlock()
t.Log()
}
// logTopLevelTraces finds all traces in a hierarchy of nested traces that should be logged but do not have any
// parents that will be logged, due to threshold limits, and logs them as top level traces.
func (t *Trace) logTrace() {
t.lock.RLock()
defer t.lock.RUnlock()
if t.durationIsWithinThreshold() {
var buffer bytes.Buffer
traceNum := rand.Int31()
@ -244,9 +258,13 @@ func (t *Trace) calculateStepThreshold() *time.Duration {
traceThreshold := *t.threshold
for _, s := range t.traceItems {
nestedTrace, ok := s.(*Trace)
if ok && nestedTrace.threshold != nil {
traceThreshold = traceThreshold - *nestedTrace.threshold
lenTrace--
if ok {
nestedTrace.lock.RLock()
if nestedTrace.threshold != nil {
traceThreshold = traceThreshold - *nestedTrace.threshold
lenTrace--
}
nestedTrace.lock.RUnlock()
}
}

View File

@ -123,6 +123,10 @@ This is a helper script for Knative E2E test scripts. To use it:
when a test fails, and can dump extra information about the current state of
the cluster (typically using `kubectl`).
1. [optional] Write the `on_success` function. It will be called when a test succeeds
1. [optional] Write the `on_failure` function. It will be called when a test fails
1. [optional] Write the `parse_flags()` function. It will be called whenever an
unrecognized flag is passed to the script, allowing you to define your own
flags. The function must return 0 if the flag is unrecognized, or the number

View File

@ -21,13 +21,8 @@ source "$(dirname "${BASH_SOURCE[0]:-$0}")/infra-library.sh"
readonly TEST_RESULT_FILE=/tmp/${REPO_NAME}-e2e-result
# Flag whether test is using a boskos GCP project
IS_BOSKOS=0
# Tear down the test resources.
function teardown_test_resources() {
# On boskos, save time and don't teardown as the cluster will be destroyed anyway.
(( IS_BOSKOS )) && return
header "Tearing down test environment"
if function_exists test_teardown; then
test_teardown
@ -89,10 +84,9 @@ function setup_test_cluster() {
kubectl config set-context "${k8s_cluster}" --namespace=default
echo "- Cluster is ${k8s_cluster}"
echo "- Docker is ${KO_DOCKER_REPO}"
echo "- KO_DOCKER_REPO is ${KO_DOCKER_REPO}"
# Do not run teardowns if we explicitly want to skip them.
(( ! SKIP_TEARDOWNS )) && add_trap teardown_test_resources EXIT
(( TEARDOWN )) && add_trap teardown_test_resources EXIT
# Handle failures ourselves, so we can dump useful info.
set +o errexit
@ -111,7 +105,7 @@ function success() {
echo "**************************************"
echo "*** E2E TESTS PASSED ***"
echo "**************************************"
dump_metrics
function_exists on_success && on_success
exit 0
}
@ -122,13 +116,18 @@ function fail_test() {
if [[ "X${message:-}X" == "XX" ]]; then
message='test failed'
fi
add_trap "dump_cluster_state;dump_metrics" EXIT
function_exists on_failure && on_failure
(( ! SKIP_DUMP_ON_FAILURE )) && dump_cluster_state
abort "${message}"
}
SKIP_TEARDOWNS=0
# Since create_test_cluster invokes the test script
# recursively we don't want to override these on the second
# invocation
TEARDOWN=${TEARDOWN:-0}
CLOUD_PROVIDER=${CLOUD_PROVIDER:-"gke"}
SKIP_DUMP_ON_FAILURE=${SKIP_DUMP_ON_FAILURE:-0}
E2E_SCRIPT=""
CLOUD_PROVIDER="gke"
# Parse flags and initialize the test cluster.
function initialize() {
@ -153,7 +152,7 @@ function initialize() {
# Skip parsed flag (and possibly argument) and continue
# Also save it to it's passed through to the test script
for ((i=1;i<=skip;i++)); do
# Avoid double-parsing
# Avoid double-parsing
if (( parse_script_flags )); then
e2e_script_command+=("$1")
fi
@ -165,9 +164,10 @@ function initialize() {
# Try parsing flag as a standard one.
case ${parameter} in
--run-tests) run_tests=1 ;;
--skip-teardowns) SKIP_TEARDOWNS=1 ;;
--skip-istio-addon) echo "--skip-istio-addon is no longer supported"
;; # This flag is a noop
--teardown) TEARDOWN=1 ;;
--skip-teardowns) echo "--skip-teardowns is no longer supported - opt in with --teardown" ;;
--skip-dump-on-failure) SKIP_DUMP_ON_FAILURE=1 ;;
--skip-istio-addon) echo "--skip-istio-addon is no longer supported" ;;
*)
case ${parameter} in
--cloud-provider) shift; CLOUD_PROVIDER="$1" ;;
@ -177,14 +177,13 @@ function initialize() {
shift
done
(( IS_PROW )) && [[ -z "${GCP_PROJECT_ID:-}" ]] && IS_BOSKOS=1
if [[ "${CLOUD_PROVIDER}" == "gke" ]]; then
custom_flags+=("--addons=NodeLocalDNS")
fi
readonly IS_BOSKOS
readonly SKIP_TEARDOWNS
readonly SKIP_DUMP_ON_FAILURE
readonly TEARDOWN
readonly CLOUD_PROVIDER
if (( ! run_tests )); then
create_test_cluster "${CLOUD_PROVIDER}" custom_flags e2e_script_command

20
vendor/modules.txt vendored
View File

@ -381,7 +381,7 @@ gopkg.in/yaml.v2
# gopkg.in/yaml.v3 v3.0.1
## explicit
gopkg.in/yaml.v3
# k8s.io/api v0.25.2
# k8s.io/api v0.25.4
## explicit; go 1.19
k8s.io/api/admissionregistration/v1
k8s.io/api/admissionregistration/v1beta1
@ -429,7 +429,7 @@ k8s.io/api/scheduling/v1beta1
k8s.io/api/storage/v1
k8s.io/api/storage/v1alpha1
k8s.io/api/storage/v1beta1
# k8s.io/apimachinery v0.25.2
# k8s.io/apimachinery v0.25.4
## explicit; go 1.19
k8s.io/apimachinery/pkg/api/equality
k8s.io/apimachinery/pkg/api/errors
@ -477,7 +477,7 @@ k8s.io/apimachinery/pkg/version
k8s.io/apimachinery/pkg/watch
k8s.io/apimachinery/third_party/forked/golang/json
k8s.io/apimachinery/third_party/forked/golang/reflect
# k8s.io/client-go v0.25.2
# k8s.io/client-go v0.25.4
## explicit; go 1.19
k8s.io/client-go/applyconfigurations/admissionregistration/v1
k8s.io/client-go/applyconfigurations/admissionregistration/v1beta1
@ -605,7 +605,7 @@ k8s.io/client-go/util/homedir
k8s.io/client-go/util/keyutil
k8s.io/client-go/util/retry
k8s.io/client-go/util/workqueue
# k8s.io/code-generator v0.25.2
# k8s.io/code-generator v0.25.4
## explicit; go 1.19
k8s.io/code-generator
k8s.io/code-generator/cmd/client-gen
@ -640,7 +640,7 @@ k8s.io/code-generator/cmd/set-gen
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-20220613173612-397b4ae3bce7
# k8s.io/gengo v0.0.0-20221011193443-fad74ee6edd9
## explicit; go 1.13
k8s.io/gengo/args
k8s.io/gengo/examples/deepcopy-gen/generators
@ -652,7 +652,7 @@ k8s.io/gengo/generator
k8s.io/gengo/namer
k8s.io/gengo/parser
k8s.io/gengo/types
# k8s.io/klog/v2 v2.70.2-0.20220707122935-0990e81f1a8f
# k8s.io/klog/v2 v2.80.2-0.20221028030830-9ae4992afb54
## explicit; go 1.13
k8s.io/klog/v2
k8s.io/klog/v2/internal/buffer
@ -677,8 +677,8 @@ k8s.io/kube-openapi/pkg/spec3
k8s.io/kube-openapi/pkg/util/proto
k8s.io/kube-openapi/pkg/util/sets
k8s.io/kube-openapi/pkg/validation/spec
# k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed
## explicit; go 1.12
# k8s.io/utils v0.0.0-20221108210102-8e77b1f39fe2
## explicit; go 1.18
k8s.io/utils/buffer
k8s.io/utils/clock
k8s.io/utils/clock/testing
@ -687,10 +687,10 @@ k8s.io/utils/internal/third_party/forked/golang/net
k8s.io/utils/net
k8s.io/utils/strings/slices
k8s.io/utils/trace
# knative.dev/hack v0.0.0-20221114224536-b0354624aa29
# knative.dev/hack v0.0.0-20221115211737-de2ff401a852
## explicit; go 1.18
knative.dev/hack
# knative.dev/pkg v0.0.0-20221107171117-0243d641354d
# knative.dev/pkg v0.0.0-20221115192737-dca788a951f3
## explicit; go 1.18
knative.dev/pkg/apis
knative.dev/pkg/apis/duck