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 <automation@knative.team>
This commit is contained in:
knative-automation 2022-07-21 09:29:19 -04:00 committed by GitHub
parent 2731096a14
commit 9d082ff35e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 78 additions and 139 deletions

4
go.mod
View File

@ -10,6 +10,6 @@ require (
k8s.io/client-go v0.23.8 k8s.io/client-go v0.23.8
k8s.io/code-generator v0.23.8 k8s.io/code-generator v0.23.8
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65
knative.dev/hack v0.0.0-20220701014203-65c463ac8c98 knative.dev/hack v0.0.0-20220721014222-a6450400b5f1
knative.dev/pkg v0.0.0-20220705130606-e60d250dc637 knative.dev/pkg v0.0.0-20220721014205-1a5e1682be3a
) )

7
go.sum
View File

@ -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-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 h1:HNSDgDCrr/6Ly3WEGKZftiE7IY19Vz2GdbOCyI4qqhc=
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= 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/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/hack v0.0.0-20220721014222-a6450400b5f1 h1:t6jYBtJwVhyx+48cidFj1ckYAlMesS0yCnAlW2BJyNo=
knative.dev/pkg v0.0.0-20220705130606-e60d250dc637/go.mod h1:MxsV3ZGdrH87zv4O9HtxzbNwmiKcGwEP7UdriLINSn0= 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= 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/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/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=

View File

@ -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 1. [optional] Define the function `build_tests()`. If you don't define this
function, the default action for running the build tests is to: function, the default action for running the build tests is to:
- check markdown files
- run `go build` on the entire repo - run `go build` on the entire repo
- run `/hack/verify-codegen.sh` (if it exists) - run `/hack/verify-codegen.sh` (if it exists)
- check licenses in all go packages - 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 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 the following environment variables if the default values don't fit your
needs: 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 - `PRESUBMIT_TEST_FAIL_FAST`: Fail the presubmit test immediately if a test
fails, defaults to 0 (false). fails, defaults to 0 (false).

View File

@ -85,14 +85,21 @@ func IsInUpdate(ctx context.Context) bool {
return ctx.Value(inUpdateKey{}) != nil return ctx.Value(inUpdateKey{}) != nil
} }
// IsInStatusUpdate checks whether the context is an Update. // GetUpdatedSubresource returns the subresource being updated or "" if there
func IsInStatusUpdate(ctx context.Context) bool { // 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{}) value := ctx.Value(inUpdateKey{})
if value == nil { if value == nil {
return false return ""
} }
up := value.(*updatePayload) 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 // GetBaseline returns the baseline of the update, or nil when we

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2018 The Knative Authors Copyright 2022 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -17,113 +17,64 @@ limitations under the License.
package changeset package changeset
import ( import (
"bufio"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp" "regexp"
"strings" "runtime/debug"
"strconv"
"sync"
) )
const ( const Unknown = "unknown"
commitIDFile = "HEAD"
koDataPathEnvName = "KO_DATA_PATH" var (
// packedRefsFile is a file containing a list of refs, used to compact the shaRegexp = regexp.MustCompile(`^[a-f0-9]{40,64}$`)
// list of refs instead of storing them on the filesystem directly. rev string
// See https://git-scm.com/docs/git-pack-refs err error
packedRefsFile = "packed-refs" 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 return rev
// 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)
} }
// readFileFromKoData tries to read data as string from the file with given name func get() string {
// under KO_DATA_PATH then returns the content as string. The file is expected info, ok := readBuildInfo()
// to be wrapped into the container from /kodata by ko. If it fails, returns if !ok {
// the error it gets. return Unknown
func readFileFromKoData(filename string) ([]byte, error) {
f, err := koDataFile(filename)
if err != nil {
return nil, err
} }
defer f.Close()
return ioutil.ReadAll(f)
}
// readFileFromKoData tries to open the file with given name under KO_DATA_PATH. var revision string
// The file is expected to be wrapped into the container from /kodata by ko. var modified bool
// 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))
}
// findPackedRef searches the packed-ref file for ref values. for _, s := range info.Settings {
// This can happen if the # of refs in a repo grows too much - git will try switch s.Key {
// and condense them into a file. case "vcs.revision":
// See https://git-scm.com/docs/git-pack-refs revision = s.Value
func findPackedRef(ref string) ([]byte, error) { case "vcs.modified":
f, err := koDataFile(packedRefsFile) modified, _ = strconv.ParseBool(s.Value)
if err != nil {
return nil, err
}
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
// We only care about lines with `<commit> <ref>` 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
} }
} }
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
} }

View File

@ -14,10 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
// Package changeset provides Knative utilities for fetching GitHub Commit ID // Package changeset returns version control info that was embedded in the
// from kodata directory. It requires GitHub HEAD file to be linked into // golang binary
// Knative component source code via the following command:
// ln -s -r .git/HEAD ./cmd/<knative-component-name>/kodata/
// Then ko will build this file into $KO_DATA_PATH when building the container
// for a Knative component.
package changeset package changeset

View File

@ -51,7 +51,7 @@ EXTERNAL_INFORMER_PKG="k8s.io/client-go/informers" \
k8s.io/api \ k8s.io/api \
"${K8S_TYPES}" \ "${K8S_TYPES}" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt \ --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" \ OUTPUT_PKG="knative.dev/pkg/client/injection/apiextensions" \
VERSIONED_CLIENTSET_PKG="k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" \ VERSIONED_CLIENTSET_PKG="k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" \

View File

@ -75,15 +75,14 @@ func NewLogger(configJSON string, levelOverride string, opts ...zap.Option) (*za
} }
func enrichLoggerWithCommitID(logger *zap.Logger) *zap.SugaredLogger { func enrichLoggerWithCommitID(logger *zap.Logger) *zap.SugaredLogger {
commitID, err := changeset.Get() revision := changeset.Get()
if err != nil { if revision == changeset.Unknown {
logger.Info("Fetch GitHub commit ID from kodata failed", zap.Error(err)) logger.Info("Unable to read vcs.revision from binary")
return logger.Sugar() return logger.Sugar()
} }
// Enrich logs with GitHub commit ID. // Enrich logs with the components git revision.
return logger.With(zap.String(logkey.GitHubCommitID, commitID)).Sugar() return logger.With(zap.String(logkey.Commit, revision)).Sugar()
} }
// NewLoggerFromConfig creates a logger using the provided Config // NewLoggerFromConfig creates a logger using the provided Config

View File

@ -59,7 +59,7 @@ const (
// KubernetesService is the key used to represent a Kubernetes service name in logs // KubernetesService is the key used to represent a Kubernetes service name in logs
KubernetesService = "knative.dev/k8sservice" KubernetesService = "knative.dev/k8sservice"
// GitHubCommitID is the key used to represent the GitHub Commit ID where the // Commit is the logging key used to represent the VCS revision that the
// Knative component was built from in logs // Knative component was built from
GitHubCommitID = "commit" Commit = "commit"
) )

4
vendor/modules.txt vendored
View File

@ -600,10 +600,10 @@ k8s.io/utils/integer
k8s.io/utils/internal/third_party/forked/golang/net k8s.io/utils/internal/third_party/forked/golang/net
k8s.io/utils/net k8s.io/utils/net
k8s.io/utils/trace k8s.io/utils/trace
# knative.dev/hack v0.0.0-20220701014203-65c463ac8c98 # knative.dev/hack v0.0.0-20220721014222-a6450400b5f1
## explicit ## explicit
knative.dev/hack knative.dev/hack
# knative.dev/pkg v0.0.0-20220705130606-e60d250dc637 # knative.dev/pkg v0.0.0-20220721014205-1a5e1682be3a
## explicit ## explicit
knative.dev/pkg/apis knative.dev/pkg/apis
knative.dev/pkg/apis/duck knative.dev/pkg/apis/duck