From 9d082ff35e00335a6d7e60f078ba7136e1fdab74 Mon Sep 17 00:00:00 2001 From: knative-automation Date: Thu, 21 Jul 2022 09:29:19 -0400 Subject: [PATCH] upgrade to latest dependencies (#659) bumping knative.dev/hack 65c463a...a645040: > a645040 Update community files (# 201) > 81e30c2 remove references to git markdown checking (# 199) > e3be8da Update community files (# 197) bumping knative.dev/pkg e60d250...1a5e168: > 1a5e168 Update community files (# 2553) > c488837 Add reconcile for ValidatingWebhookConfiguration and MutatingWebhookConfiguration. (# 2550) > 1ad02a5 Drop error from changeset.Get signature (# 2549) > 473ba31 Bump min go version to 1.18 && read build info from embedded binary (# 2548) > f1f36a2 Fix subresource update logic. (# 2546) > 418e138 Update community files (# 2545) Signed-off-by: Knative Automation --- go.mod | 4 +- go.sum | 7 +- vendor/knative.dev/hack/README.md | 15 -- vendor/knative.dev/pkg/apis/contexts.go | 15 +- vendor/knative.dev/pkg/changeset/commit.go | 145 ++++++------------ vendor/knative.dev/pkg/changeset/doc.go | 8 +- vendor/knative.dev/pkg/hack/update-codegen.sh | 2 +- vendor/knative.dev/pkg/logging/config.go | 11 +- .../pkg/logging/logkey/constants.go | 6 +- vendor/modules.txt | 4 +- 10 files changed, 78 insertions(+), 139 deletions(-) diff --git a/go.mod b/go.mod index 9972cbb9..5b4c4d96 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,6 @@ require ( k8s.io/client-go v0.23.8 k8s.io/code-generator v0.23.8 k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 - knative.dev/hack v0.0.0-20220701014203-65c463ac8c98 - knative.dev/pkg v0.0.0-20220705130606-e60d250dc637 + knative.dev/hack v0.0.0-20220721014222-a6450400b5f1 + knative.dev/pkg v0.0.0-20220721014205-1a5e1682be3a ) diff --git a/go.sum b/go.sum index 52f0c47d..d75943c3 100644 --- a/go.sum +++ b/go.sum @@ -1144,10 +1144,11 @@ k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/ k8s.io/utils v0.0.0-20211116205334-6203023598ed/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 h1:HNSDgDCrr/6Ly3WEGKZftiE7IY19Vz2GdbOCyI4qqhc= k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= -knative.dev/hack v0.0.0-20220701014203-65c463ac8c98 h1:kAwcKZOwYU0QCGEwvZrgnLrynFCWnXetwR/+a4W9R70= knative.dev/hack v0.0.0-20220701014203-65c463ac8c98/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI= -knative.dev/pkg v0.0.0-20220705130606-e60d250dc637 h1:wvz8Y/b2Ubox0pbTLAbKags19UC72Ik+b/tIW2QP9/E= -knative.dev/pkg v0.0.0-20220705130606-e60d250dc637/go.mod h1:MxsV3ZGdrH87zv4O9HtxzbNwmiKcGwEP7UdriLINSn0= +knative.dev/hack v0.0.0-20220721014222-a6450400b5f1 h1:t6jYBtJwVhyx+48cidFj1ckYAlMesS0yCnAlW2BJyNo= +knative.dev/hack v0.0.0-20220721014222-a6450400b5f1/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI= +knative.dev/pkg v0.0.0-20220721014205-1a5e1682be3a h1:/eiY3kygS2SOenGTjCBw3c1K0s2JfR3z7+TDx8my6NA= +knative.dev/pkg v0.0.0-20220721014205-1a5e1682be3a/go.mod h1:eMXp/bEI/o1rKbNjTgifcQsI//e/3pfk0SMLu38Q3Sk= pgregory.net/rapid v0.3.3/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU= 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= diff --git a/vendor/knative.dev/hack/README.md b/vendor/knative.dev/hack/README.md index de565f7c..89cae268 100644 --- a/vendor/knative.dev/hack/README.md +++ b/vendor/knative.dev/hack/README.md @@ -12,29 +12,14 @@ This is a helper script to run the presubmit tests. To use it: 1. [optional] Define the function `build_tests()`. If you don't define this function, the default action for running the build tests is to: - - check markdown files - run `go build` on the entire repo - run `/hack/verify-codegen.sh` (if it exists) - check licenses in all go packages - The markdown link checker tool doesn't check `localhost` links by default. - Its configuration file, `markdown-link-check-config.json`, lives in the - `hack` directory. To override it, create a file with the same name, - containing the custom config in the `/test` directory. - - The markdown lint tool ignores long lines by default. Its configuration file, - `markdown-lint-config.rc`, lives in the `hack` repo. To override it, create a - file with the same name, containing the custom config in the `/test` - directory. - 1. [optional] Customize the default build test runner, if you're using it. Set the following environment variables if the default values don't fit your needs: - - `DISABLE_MD_LINTING`: Disable linting markdown files, defaults to 0 - (false). - - `DISABLE_MD_LINK_CHECK`: Disable checking links in markdown files, defaults - to 0 (false). - `PRESUBMIT_TEST_FAIL_FAST`: Fail the presubmit test immediately if a test fails, defaults to 0 (false). diff --git a/vendor/knative.dev/pkg/apis/contexts.go b/vendor/knative.dev/pkg/apis/contexts.go index b9835fc0..a3550dce 100644 --- a/vendor/knative.dev/pkg/apis/contexts.go +++ b/vendor/knative.dev/pkg/apis/contexts.go @@ -85,14 +85,21 @@ func IsInUpdate(ctx context.Context) bool { return ctx.Value(inUpdateKey{}) != nil } -// IsInStatusUpdate checks whether the context is an Update. -func IsInStatusUpdate(ctx context.Context) bool { +// GetUpdatedSubresource returns the subresource being updated or "" if there +// is no subresource that's being updated. Examples are "status" for Status +// updates, or "scale" for scaling Deployment. +func GetUpdatedSubresource(ctx context.Context) string { value := ctx.Value(inUpdateKey{}) if value == nil { - return false + return "" } up := value.(*updatePayload) - return up.subresource == "status" + return up.subresource +} + +// IsInStatusUpdate checks whether the context is an Update. +func IsInStatusUpdate(ctx context.Context) bool { + return GetUpdatedSubresource(ctx) == "status" } // GetBaseline returns the baseline of the update, or nil when we diff --git a/vendor/knative.dev/pkg/changeset/commit.go b/vendor/knative.dev/pkg/changeset/commit.go index 3668dfeb..93167c94 100644 --- a/vendor/knative.dev/pkg/changeset/commit.go +++ b/vendor/knative.dev/pkg/changeset/commit.go @@ -1,5 +1,5 @@ /* -Copyright 2018 The Knative Authors +Copyright 2022 The Knative Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -17,113 +17,64 @@ limitations under the License. package changeset import ( - "bufio" - "fmt" - "io/ioutil" - "os" - "path/filepath" "regexp" - "strings" + "runtime/debug" + "strconv" + "sync" ) -const ( - commitIDFile = "HEAD" - koDataPathEnvName = "KO_DATA_PATH" - // packedRefsFile is a file containing a list of refs, used to compact the - // list of refs instead of storing them on the filesystem directly. - // See https://git-scm.com/docs/git-pack-refs - packedRefsFile = "packed-refs" +const Unknown = "unknown" + +var ( + shaRegexp = regexp.MustCompile(`^[a-f0-9]{40,64}$`) + rev string + err error + once sync.Once + + readBuildInfo = debug.ReadBuildInfo ) -var commitIDRE = regexp.MustCompile(`^[a-f0-9]{40}$`) +// Get returns the 'vcs.revision' property from the embedded build information +// If there is no embedded information 'unknown' will be returned +// +// The result will have a '-dirty' suffix if the workspace was not clean +func Get() string { + once.Do(func() { + rev = get() + }) -// Get tries to fetch the first 7 digitals of GitHub commit ID from HEAD file in -// KO_DATA_PATH. If it fails, it returns the error it gets. -func Get() (string, error) { - data, err := readFileFromKoData(commitIDFile) - if err != nil { - return "", err - } - commitID := strings.TrimSpace(string(data)) - if rID := strings.TrimPrefix(commitID, "ref: "); rID != commitID { - // First try to read from the direct ref file - e.g. refs/heads/main - data, err := readFileFromKoData(rID) - if err != nil { - if !os.IsNotExist(err) { - return "", err - } - - // Ref file didn't exist - it might be contained in the packed-refs - // file. - var pferr error - data, pferr = findPackedRef(rID) - // Only return the sub-error if the packed-refs file exists, otherwise - // just let the original error return (e.g. treat it as if we didn't - // even attempt the operation). This is primarily to keep the error - // messages clean. - if pferr != nil { - if os.IsNotExist(pferr) { - return "", err - } - return "", pferr - } - } - commitID = strings.TrimSpace(string(data)) - } - if commitIDRE.MatchString(commitID) { - return commitID[:7], nil - } - return "", fmt.Errorf("%q is not a valid GitHub commit ID", commitID) + return rev } -// readFileFromKoData tries to read data as string from the file with given name -// under KO_DATA_PATH then returns the content as string. The file is expected -// to be wrapped into the container from /kodata by ko. If it fails, returns -// the error it gets. -func readFileFromKoData(filename string) ([]byte, error) { - f, err := koDataFile(filename) - if err != nil { - return nil, err +func get() string { + info, ok := readBuildInfo() + if !ok { + return Unknown } - defer f.Close() - return ioutil.ReadAll(f) -} -// readFileFromKoData tries to open the file with given name under KO_DATA_PATH. -// The file is expected to be wrapped into the container from /kodata by ko. -// If it fails, returns the error it gets. -func koDataFile(filename string) (*os.File, error) { - koDataPath := os.Getenv(koDataPathEnvName) - if koDataPath == "" { - return nil, fmt.Errorf("%q does not exist or is empty", koDataPathEnvName) - } - return os.Open(filepath.Join(koDataPath, filename)) -} + var revision string + var modified bool -// findPackedRef searches the packed-ref file for ref values. -// This can happen if the # of refs in a repo grows too much - git will try -// and condense them into a file. -// See https://git-scm.com/docs/git-pack-refs -func findPackedRef(ref string) ([]byte, error) { - f, err := koDataFile(packedRefsFile) - if err != nil { - return nil, err - } - defer f.Close() - - scanner := bufio.NewScanner(f) - for scanner.Scan() { - // We only care about lines with ` ` pairs. - // Why this might happen: - // 1. Lines starting with ^ refer to unpeeled tag SHAs - // (e.g. the commits pointed to by annotated tags) - s := strings.Split(scanner.Text(), " ") - if len(s) != 2 { - continue - } - if ref == s[1] { - return []byte(s[0]), nil + for _, s := range info.Settings { + switch s.Key { + case "vcs.revision": + revision = s.Value + case "vcs.modified": + modified, _ = strconv.ParseBool(s.Value) } } - return nil, fmt.Errorf("%q ref not found in packed-refs", ref) + + if revision == "" { + return Unknown + } + + if shaRegexp.MatchString(revision) { + revision = revision[:7] + } + + if modified { + revision += "-dirty" + } + + return revision } diff --git a/vendor/knative.dev/pkg/changeset/doc.go b/vendor/knative.dev/pkg/changeset/doc.go index c56f7ebf..9727f27d 100644 --- a/vendor/knative.dev/pkg/changeset/doc.go +++ b/vendor/knative.dev/pkg/changeset/doc.go @@ -14,10 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package changeset provides Knative utilities for fetching GitHub Commit ID -// from kodata directory. It requires GitHub HEAD file to be linked into -// Knative component source code via the following command: -// ln -s -r .git/HEAD ./cmd//kodata/ -// Then ko will build this file into $KO_DATA_PATH when building the container -// for a Knative component. +// Package changeset returns version control info that was embedded in the +// golang binary package changeset diff --git a/vendor/knative.dev/pkg/hack/update-codegen.sh b/vendor/knative.dev/pkg/hack/update-codegen.sh index 859602cc..d432f659 100644 --- a/vendor/knative.dev/pkg/hack/update-codegen.sh +++ b/vendor/knative.dev/pkg/hack/update-codegen.sh @@ -51,7 +51,7 @@ EXTERNAL_INFORMER_PKG="k8s.io/client-go/informers" \ k8s.io/api \ "${K8S_TYPES}" \ --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt \ - --force-genreconciler-kinds "Namespace,ConfigMap,Deployment,Secret,Pod,CronJob,NetworkPolicy,Node" + --force-genreconciler-kinds "Namespace,ConfigMap,Deployment,Secret,Pod,CronJob,NetworkPolicy,Node,ValidatingWebhookConfiguration,MutatingWebhookConfiguration" OUTPUT_PKG="knative.dev/pkg/client/injection/apiextensions" \ VERSIONED_CLIENTSET_PKG="k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" \ diff --git a/vendor/knative.dev/pkg/logging/config.go b/vendor/knative.dev/pkg/logging/config.go index de979368..a95dfe8f 100644 --- a/vendor/knative.dev/pkg/logging/config.go +++ b/vendor/knative.dev/pkg/logging/config.go @@ -75,15 +75,14 @@ func NewLogger(configJSON string, levelOverride string, opts ...zap.Option) (*za } func enrichLoggerWithCommitID(logger *zap.Logger) *zap.SugaredLogger { - commitID, err := changeset.Get() - if err != nil { - logger.Info("Fetch GitHub commit ID from kodata failed", zap.Error(err)) + revision := changeset.Get() + if revision == changeset.Unknown { + logger.Info("Unable to read vcs.revision from binary") return logger.Sugar() } - // Enrich logs with GitHub commit ID. - return logger.With(zap.String(logkey.GitHubCommitID, commitID)).Sugar() - + // Enrich logs with the components git revision. + return logger.With(zap.String(logkey.Commit, revision)).Sugar() } // NewLoggerFromConfig creates a logger using the provided Config diff --git a/vendor/knative.dev/pkg/logging/logkey/constants.go b/vendor/knative.dev/pkg/logging/logkey/constants.go index 9e1c4d81..1e9b6214 100644 --- a/vendor/knative.dev/pkg/logging/logkey/constants.go +++ b/vendor/knative.dev/pkg/logging/logkey/constants.go @@ -59,7 +59,7 @@ const ( // KubernetesService is the key used to represent a Kubernetes service name in logs KubernetesService = "knative.dev/k8sservice" - // GitHubCommitID is the key used to represent the GitHub Commit ID where the - // Knative component was built from in logs - GitHubCommitID = "commit" + // Commit is the logging key used to represent the VCS revision that the + // Knative component was built from + Commit = "commit" ) diff --git a/vendor/modules.txt b/vendor/modules.txt index 80718612..bd0ecb4c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -600,10 +600,10 @@ k8s.io/utils/integer k8s.io/utils/internal/third_party/forked/golang/net k8s.io/utils/net k8s.io/utils/trace -# knative.dev/hack v0.0.0-20220701014203-65c463ac8c98 +# knative.dev/hack v0.0.0-20220721014222-a6450400b5f1 ## explicit knative.dev/hack -# knative.dev/pkg v0.0.0-20220705130606-e60d250dc637 +# knative.dev/pkg v0.0.0-20220721014205-1a5e1682be3a ## explicit knative.dev/pkg/apis knative.dev/pkg/apis/duck