diff --git a/go.mod b/go.mod index c068915a7..bc860e1a8 100644 --- a/go.mod +++ b/go.mod @@ -27,9 +27,9 @@ require ( k8s.io/client-go v0.23.9 k8s.io/code-generator v0.23.9 k8s.io/kube-openapi v0.0.0-20220124234850-424119656bbf - knative.dev/eventing v0.34.1 - knative.dev/hack v0.0.0-20220823140917-8d1e4ccf9dc3 - knative.dev/pkg v0.0.0-20220818004048-4a03844c0b15 + knative.dev/eventing v0.34.1-0.20220906111743-7f1f49f5b4e0 + knative.dev/hack v0.0.0-20220906140443-f9dc7220d362 + knative.dev/pkg v0.0.0-20220826162920-93b66e6a8700 ) require ( @@ -41,7 +41,7 @@ require ( golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 gotest.tools/v3 v3.1.0 k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 - knative.dev/client v0.34.0 + knative.dev/client v0.34.1-0.20220906114442-59948bb3723d ) require ( @@ -148,8 +148,8 @@ require ( k8s.io/cli-runtime v0.23.4 // indirect k8s.io/gengo v0.0.0-20220613173612-397b4ae3bce7 // indirect k8s.io/klog/v2 v2.70.2-0.20220707122935-0990e81f1a8f // indirect - knative.dev/networking v0.0.0-20220818010248-e51df7cdf571 // indirect - knative.dev/serving v0.34.0 // indirect + knative.dev/networking v0.0.0-20220831065816-215bac90b28b // indirect + knative.dev/serving v0.34.1-0.20220905171742-62685b3b4a5a // indirect sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect sigs.k8s.io/kustomize/api v0.10.1 // indirect sigs.k8s.io/kustomize/kyaml v0.13.0 // indirect diff --git a/go.sum b/go.sum index 34599266c..c55a82dc3 100644 --- a/go.sum +++ b/go.sum @@ -1378,18 +1378,18 @@ 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/client v0.34.0 h1:CY62Bd/sodq8aeL6dYGYnDCvpe39qiPGXJHtR4Rktbk= -knative.dev/client v0.34.0/go.mod h1:mquhJiwkZytOKzLjRu3K+5HWRM6YAplWfvGUbCFZI4M= -knative.dev/eventing v0.34.1 h1:r6QuQmDCmmSANdTRLdbKb6YcYaJoeNpEuFfS8Bq0ZgQ= -knative.dev/eventing v0.34.1/go.mod h1:6UnNnPrEUNAM9PfCpf7L8N7G/1vq+HQlpOjzndY6ryw= -knative.dev/hack v0.0.0-20220823140917-8d1e4ccf9dc3 h1:umaeMRecA0g5g48L9tnEAkTBIitr9eKWMyJYo9YttAA= -knative.dev/hack v0.0.0-20220823140917-8d1e4ccf9dc3/go.mod h1:t/azP8I/Cygaw+87O7rkAPrNRjCelmtfSzWzu/9TM7I= -knative.dev/networking v0.0.0-20220818010248-e51df7cdf571 h1:Lu/TsJjxg1p+2CMr2LNHEdEFBNHYjDoZv2f1QZoM8jg= -knative.dev/networking v0.0.0-20220818010248-e51df7cdf571/go.mod h1:m3ataWRwmbHjOY9sCFvcDWRNLVITxVl0fH0RxdCa4jE= -knative.dev/pkg v0.0.0-20220818004048-4a03844c0b15 h1:GNmzHVaUo3zoi/wtIN71LPQaWy6DdoYzmb+GIq2s4fw= -knative.dev/pkg v0.0.0-20220818004048-4a03844c0b15/go.mod h1:YLjXbkQLlGHok+u0FLfMbBHFzY9WGu3GHhnrptoAy8I= -knative.dev/serving v0.34.0 h1:x3fS4e0AcNBBlQv5Dd5y30W2gtrxndUEwIEPknZfeVg= -knative.dev/serving v0.34.0/go.mod h1:IyfedOBq3KzcD5dZONjbix2BfS0jOwDq5td8UE9CjCk= +knative.dev/client v0.34.1-0.20220906114442-59948bb3723d h1:2VReV5z4UELaRYJDo/+QU7gYd4LVcOKMeZDC9hfi4sI= +knative.dev/client v0.34.1-0.20220906114442-59948bb3723d/go.mod h1:2Z3qxDjIiniQCGrpvTRbbn9nxB8D5pzVH36E3xql+ko= +knative.dev/eventing v0.34.1-0.20220906111743-7f1f49f5b4e0 h1:IVLZkOQlBL8MMwSYw28WVMru36UdXTZW+FkKuZACMhs= +knative.dev/eventing v0.34.1-0.20220906111743-7f1f49f5b4e0/go.mod h1:6UnNnPrEUNAM9PfCpf7L8N7G/1vq+HQlpOjzndY6ryw= +knative.dev/hack v0.0.0-20220906140443-f9dc7220d362 h1:z3MkroifHD8RBAJv3zD6PDYhE/XRRJdrMpuIYHd3cFI= +knative.dev/hack v0.0.0-20220906140443-f9dc7220d362/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q= +knative.dev/networking v0.0.0-20220831065816-215bac90b28b h1:NhaGPmanHDyWMsl/LudsCmTMcdEEjZFk3qkSIUOW9Jw= +knative.dev/networking v0.0.0-20220831065816-215bac90b28b/go.mod h1:vMMT540KNAh6TWmpGEFnExTxJ/j9cee5qNV7Bs0kzUk= +knative.dev/pkg v0.0.0-20220826162920-93b66e6a8700 h1:6xjS69vf5Pbwu+dWckqPALmm5pc3p0/XScPpRBhugRc= +knative.dev/pkg v0.0.0-20220826162920-93b66e6a8700/go.mod h1:WIQZyPTLzT+z0V3/gB91aWugIi3E1mkU9rjCrLfjOwY= +knative.dev/serving v0.34.1-0.20220905171742-62685b3b4a5a h1:GT7gPwH4JkKScyZBKwNpE2w4hPDbbVFG66iZWbTxI4M= +knative.dev/serving v0.34.1-0.20220905171742-62685b3b4a5a/go.mod h1:F1+qPPtn78vmrDdOoOsapHEOCzVqRcmDcFFJolWVuE0= 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= diff --git a/vendor/knative.dev/client/pkg/serving/config_changes.go b/vendor/knative.dev/client/pkg/serving/config_changes.go index 56847797d..6e7b9a7b5 100644 --- a/vendor/knative.dev/client/pkg/serving/config_changes.go +++ b/vendor/knative.dev/client/pkg/serving/config_changes.go @@ -77,6 +77,11 @@ func UpdateScaleTarget(template *servingv1.RevisionTemplateSpec, target int) err return UpdateRevisionTemplateAnnotation(template, autoscaling.TargetAnnotationKey, strconv.Itoa(target)) } +//UpdateScaleActivation updates the scale activation annotation +func UpdateScaleActivation(template *servingv1.RevisionTemplateSpec, activation int) error { + return UpdateRevisionTemplateAnnotation(template, autoscaling.ActivationScaleKey, strconv.Itoa(activation)) +} + // UpdateScaleUtilization updates container target utilization percentage annotation func UpdateScaleUtilization(template *servingv1.RevisionTemplateSpec, target int) error { return UpdateRevisionTemplateAnnotation(template, autoscaling.TargetUtilizationPercentageKey, strconv.Itoa(target)) diff --git a/vendor/knative.dev/hack/go.work b/vendor/knative.dev/hack/go.work new file mode 100644 index 000000000..b20aabbbc --- /dev/null +++ b/vendor/knative.dev/hack/go.work @@ -0,0 +1,7 @@ +go 1.18 + +use ( + . + schema + test/e2e +) diff --git a/vendor/knative.dev/hack/library.sh b/vendor/knative.dev/hack/library.sh index 26cd00cb8..ade3303ba 100644 --- a/vendor/knative.dev/hack/library.sh +++ b/vendor/knative.dev/hack/library.sh @@ -97,7 +97,7 @@ function patch_version() { # Print error message and exit 1 # Parameters: $1..$n - error message to be displayed function abort() { - echo "error: $*" + echo "error: $*" >&2 exit 1 } @@ -126,7 +126,7 @@ function subheader() { # Simple warning banner for logging purposes. function warning() { - make_banner "!" "$1" + make_banner '!' "$*" >&2 } # Checks whether the given function exists. @@ -567,7 +567,6 @@ function go_run() { export GORUN_PATH GOPATH="${GORUN_PATH}" \ GOFLAGS='' \ - GO111MODULE='' \ go run "$package" "$@" } @@ -577,6 +576,7 @@ function go_run() { # $3..$n - parameters passed to the tool. # Deprecated: use go_run instead function run_go_tool() { + warning 'The "run_go_tool" function is deprecated. Use "go_run" instead.' local package=$1 # If no `@version` is provided, default to adding `@latest` if [[ "$package" != *@* ]]; then @@ -601,6 +601,26 @@ function add_trap { done } +# Run a command, described by $1, for every go module in the project. +# Parameters: $1 - Description of the command being run, +# $2 - $n - Arguments to pass to the command. +function foreach_go_module() { + local failed=0 + local -r cmd="$1" + shift + local gomod_filepath gomod_dir + while read -r gomod_filepath; do + gomod_dir="$(dirname "$gomod_filepath")" + pushd "$gomod_dir" > /dev/null + "$cmd" "$@" || failed=$? + popd > /dev/null + if (( failed )); then + echo "Command '${cmd}' failed in module $gomod_dir: $failed" >&2 + return $failed + fi + done < <(find . -name go.mod -type f ! -path "*/vendor/*" ! -path "*/third_party/*") +} + # Update go deps. # Parameters (parsed as flags): # "--upgrade", bool, do upgrade. @@ -613,14 +633,18 @@ function add_trap { # global env var: FLOATING_DEPS # --upgrade will set GOPROXY to direct unless it is already set. function go_update_deps() { - cd "${REPO_ROOT_DIR}" || return 1 + foreach_go_module __go_update_deps_for_module "$@" +} + +function __go_update_deps_for_module() { + ( # do not modify the environment + set -Eeuo pipefail - export GO111MODULE=on export GOFLAGS="" export GONOSUMDB="${GONOSUMDB:-},knative.dev/*" export GONOPROXY="${GONOPROXY:-},knative.dev/*" - echo "=== Update Deps for Golang" + echo "=== Update Deps for Golang module: $(go_mod_module_name)" local UPGRADE=0 local RELEASE="v9000.1" # release v9000 is so far in the future, it will always pick the default branch. @@ -646,7 +670,7 @@ function go_update_deps() { else group "Upgrading to release ${RELEASE}" fi - FLOATING_DEPS+=( $(go_run knative.dev/test-infra/buoy@latest float ${REPO_ROOT_DIR}/go.mod "${buoyArgs[@]}") ) + FLOATING_DEPS+=( $(go_run knative.dev/test-infra/buoy@latest float ./go.mod "${buoyArgs[@]}") ) if [[ ${#FLOATING_DEPS[@]} > 0 ]]; then echo "Floating deps to ${FLOATING_DEPS[@]}" go get -d ${FLOATING_DEPS[@]} @@ -664,6 +688,9 @@ function go_update_deps() { go mod vendor 2>&1 | grep -v "ignoring symlink" || true eval "$orig_pipefail_opt" + if ! [ -d vendor ]; then + return 0 + fi group "Removing unwanted vendor files" # Remove unwanted vendor files @@ -680,13 +707,15 @@ function go_update_deps() { group "Removing broken symlinks" remove_broken_symlinks ./vendor + ) } + # Return the go module name of the current module. # Intended to be used like: # export MODULE_NAME=$(go_mod_module_name) function go_mod_module_name() { - go mod graph | cut -d' ' -f 1 | grep -v '@' | head -1 + grep -E '^module ' go.mod | cut -d' ' -f2 } # Return a GOPATH to a temp directory. Works around the out-of-GOPATH issues @@ -717,11 +746,10 @@ function run_kntest() { # Parameters: $1 - output file, relative to repo root dir. # $2 - directory to inspect. function update_licenses() { - cd "${REPO_ROOT_DIR}" || return 1 local dst=$1 local dir=$2 shift - go_run github.com/google/go-licenses@v1.2.0 \ + go_run github.com/google/go-licenses@v1.2.1 \ save "${dir}" --save_path="${dst}" --force || \ { echo "--- FAIL: go-licenses failed to update licenses"; return 1; } } @@ -729,7 +757,7 @@ function update_licenses() { # Run go-licenses to check for forbidden licenses. function check_licenses() { # Check that we don't have any forbidden licenses. - go_run github.com/google/go-licenses@v1.2.0 \ + go_run github.com/google/go-licenses@v1.2.1 \ check "${REPO_ROOT_DIR}/..." || \ { echo "--- FAIL: go-licenses failed the license check"; return 1; } } @@ -762,7 +790,7 @@ function is_protected_project() { # Remove symlinks in a path that are broken or lead outside the repo. # Parameters: $1 - path name, e.g. vendor function remove_broken_symlinks() { - for link in $(find $1 -type l); do + for link in $(find "$1" -type l); do # Remove broken symlinks if [[ ! -e ${link} ]]; then unlink ${link} diff --git a/vendor/knative.dev/hack/presubmit-tests.sh b/vendor/knative.dev/hack/presubmit-tests.sh index d9549f51b..539facf73 100644 --- a/vendor/knative.dev/hack/presubmit-tests.sh +++ b/vendor/knative.dev/hack/presubmit-tests.sh @@ -122,7 +122,12 @@ function report_build_test() { # * `go build` on the entire repo # * check licenses in all go packages function default_build_test_runner() { + foreach_go_module __build_test_runner_for_module +} + +function __build_test_runner_for_module() { local failed=0 + subheader "Build tests for $(go_mod_module_name)" # Run verify-codegen check if [[ -f ./hack/verify-codegen.sh ]]; then subheader "Checking autogenerated code is up-to-date" @@ -132,18 +137,26 @@ function default_build_test_runner() { # verify-codegen (as md files can be auto-generated in some repos). (( IS_DOCUMENTATION_PR )) && return ${failed} # Don't merge these two lines, or return code will always be 0. + # Get all build tags in go code (ignore /vendor, /hack and /third_party) + local tags + tags="$(grep -I -r '// +build' . | \ + grep -v '/vendor/' | \ + grep -v '/hack/' | \ + grep -v '/third_party' | \ + cut -f3 -d' ' | \ + tr ',' '\n' | \ + sort | uniq | \ + grep -v '^!' | \ + tr '\n' ' ')" local go_pkg_dirs - go_pkg_dirs="$(go list ./...)" || return 1 - # Skip build test if there is no go code - [[ -z "${go_pkg_dirs}" ]] && return ${failed} + go_pkg_dirs="$(go list -tags "${tags}" ./...)" || return $? + if [[ -z "${go_pkg_dirs}" ]]; then + subheader "No golang code found, skipping build tests" + return 0 + fi # Ensure all the code builds subheader "Checking that go code builds" - # Get all build tags in go code (ignore /vendor, /hack and /third_party) - local tags - tags="$(find . \ - -path './vendor' -prune -o -path './hack' -prune -o -path './third_party' -prune \ - -o -type f -name '*.go' -exec grep '// +build' {} + \ - | cut -f3 -d' ' | tr ',' '\n' | uniq | sort | tr '\n' ' ')" + report_build_test Build_Go \ go test -vet=off -tags "${tags}" -exec echo ./... || failed=2 @@ -185,6 +198,11 @@ function run_unit_tests() { # Default unit test runner that runs all go tests in the repo. function default_unit_test_runner() { + foreach_go_module __unit_test_runner_for_module +} + +function __unit_test_runner_for_module() { + subheader "Unit tests for $(go_mod_module_name)" report_go_test -short -race -count 1 ./... } diff --git a/vendor/knative.dev/pkg/test/kube_checks.go b/vendor/knative.dev/pkg/test/kube_checks.go index 30698e694..3e295a55f 100644 --- a/vendor/knative.dev/pkg/test/kube_checks.go +++ b/vendor/knative.dev/pkg/test/kube_checks.go @@ -34,6 +34,7 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/kubernetes" k8styped "k8s.io/client-go/kubernetes/typed/core/v1" + "knative.dev/pkg/test/logging" ) @@ -141,6 +142,9 @@ func WaitForServiceEndpoints(ctx context.Context, client kubernetes.Interface, s waitErr := wait.PollImmediate(interval, podTimeout, func() (bool, error) { var err error endpoints, err = endpointsService.Get(ctx, svcName, metav1.GetOptions{}) + if apierrs.IsNotFound(err) { + return false, nil + } if err != nil { return false, err } diff --git a/vendor/knative.dev/pkg/webhook/admission.go b/vendor/knative.dev/pkg/webhook/admission.go index ea5518260..db131b902 100644 --- a/vendor/knative.dev/pkg/webhook/admission.go +++ b/vendor/knative.dev/pkg/webhook/admission.go @@ -17,10 +17,13 @@ limitations under the License. package webhook import ( + "bytes" "context" "encoding/json" "fmt" + "io" "net/http" + "strings" "time" "go.uber.org/zap" @@ -90,10 +93,12 @@ func admissionHandler(rootLogger *zap.SugaredLogger, stats StatsReporter, c Admi logger.Infof("Webhook ServeHTTP request=%#v", r) var review admissionv1.AdmissionReview - if err := json.NewDecoder(r.Body).Decode(&review); err != nil { + bodyBuffer := bytes.Buffer{} + if err := json.NewDecoder(io.TeeReader(r.Body, &bodyBuffer)).Decode(&review); err != nil { http.Error(w, fmt.Sprint("could not decode body:", err), http.StatusBadRequest) return } + r.Body = io.NopCloser(&bodyBuffer) logger = logger.With( logkey.Kind, review.Request.Kind.String(), @@ -124,6 +129,18 @@ func admissionHandler(rootLogger *zap.SugaredLogger, stats StatsReporter, c Admi if !reviewResponse.Allowed || reviewResponse.PatchType != nil || response.Response == nil { response.Response = reviewResponse } + + // If warnings contain newlines, which they will do by default if + // using Knative apis.FieldError, split them based on newlines + // and create a new warning. This is because any control characters + // in the warnings will cause the warning to be dropped silently. + if reviewResponse.Warnings != nil { + cleanedWarnings := make([]string, 0, len(reviewResponse.Warnings)) + for _, w := range reviewResponse.Warnings { + cleanedWarnings = append(cleanedWarnings, strings.Split(w, "\n")...) + } + reviewResponse.Warnings = cleanedWarnings + } response.Response.UID = review.Request.UID logger = logger.With( @@ -141,7 +158,7 @@ func admissionHandler(rootLogger *zap.SugaredLogger, stats StatsReporter, c Admi if stats != nil { // Only report valid requests - stats.ReportRequest(review.Request, response.Response, time.Since(ttStart)) + stats.ReportAdmissionRequest(review.Request, response.Response, time.Since(ttStart)) } } } diff --git a/vendor/knative.dev/pkg/webhook/conversion.go b/vendor/knative.dev/pkg/webhook/conversion.go index 201ff41f4..2e876c14f 100644 --- a/vendor/knative.dev/pkg/webhook/conversion.go +++ b/vendor/knative.dev/pkg/webhook/conversion.go @@ -21,6 +21,7 @@ import ( "encoding/json" "fmt" "net/http" + "time" "go.uber.org/zap" apixv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" @@ -37,8 +38,9 @@ type ConversionController interface { Convert(context.Context, *apixv1.ConversionRequest) *apixv1.ConversionResponse } -func conversionHandler(rootLogger *zap.SugaredLogger, _ StatsReporter, c ConversionController) http.HandlerFunc { +func conversionHandler(rootLogger *zap.SugaredLogger, stats StatsReporter, c ConversionController) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + var ttStart = time.Now() logger := rootLogger logger.Infof("Webhook ServeHTTP request=%#v", r) @@ -69,10 +71,9 @@ func conversionHandler(rootLogger *zap.SugaredLogger, _ StatsReporter, c Convers return } - // TODO(dprotaso) - figure out what metrics we want reported - // if stats != nil { - // // Only report valid requests - // stats.ReportRequest(review.Request, response.Response, time.Since(ttStart)) - // } + if stats != nil { + // Only report valid requests + stats.ReportConversionRequest(review.Request, response.Response, time.Since(ttStart)) + } } } diff --git a/vendor/knative.dev/pkg/webhook/resourcesemantics/interface.go b/vendor/knative.dev/pkg/webhook/resourcesemantics/interface.go index 7f216b101..aa989894d 100644 --- a/vendor/knative.dev/pkg/webhook/resourcesemantics/interface.go +++ b/vendor/knative.dev/pkg/webhook/resourcesemantics/interface.go @@ -17,6 +17,7 @@ limitations under the License. package resourcesemantics import ( + admissionregistrationv1 "k8s.io/api/admissionregistration/v1" "k8s.io/apimachinery/pkg/runtime" "knative.dev/pkg/apis" ) @@ -28,3 +29,22 @@ type GenericCRD interface { apis.Validatable runtime.Object } + +// VerbLimited defines which Verbs you want to have the webhook invoked on. +type VerbLimited interface { + // SupportedVerbs define which operations (verbs) webhook is called on. + SupportedVerbs() []admissionregistrationv1.OperationType +} + +// SubResourceLimited defines which subresources you want to have the webhook +// invoked on. For example "status", "scale", etc. +type SubResourceLimited interface { + // SupportedSubResources are the subresources that will be registered + // for the resource validation. + // If you wanted to add for example scale validation for Deployments, you'd + // do: + // []string{"", "/status", "/scale"} + // And to get just the main resource, you would do: + // []string{""} + SupportedSubResources() []string +} diff --git a/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/controller.go b/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/controller.go index 02e47032b..8e8e008e6 100644 --- a/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/controller.go +++ b/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/controller.go @@ -35,34 +35,21 @@ import ( "knative.dev/pkg/webhook/resourcesemantics" ) -// NewAdmissionController constructs a reconciler -func NewAdmissionController( +// NewAdmissionControllerWithConfig constructs a reconciler and registers the +// provided handlers with specified verbs and SubResources +func NewAdmissionControllerWithConfig( ctx context.Context, name, path string, handlers map[schema.GroupVersionKind]resourcesemantics.GenericCRD, wc func(context.Context) context.Context, disallowUnknownFields bool, - callbacks ...map[schema.GroupVersionKind]Callback, + callbacks map[schema.GroupVersionKind]Callback, ) *controller.Impl { - client := kubeclient.Get(ctx) vwhInformer := vwhinformer.Get(ctx) secretInformer := secretinformer.Get(ctx) options := webhook.GetOptions(ctx) - // This not ideal, we are using a variadic argument to effectively make callbacks optional - // This allows this addition to be non-breaking to consumers of /pkg - // TODO: once all sub-repos have adopted this, we might move this back to a traditional param. - var unwrappedCallbacks map[schema.GroupVersionKind]Callback - switch len(callbacks) { - case 0: - unwrappedCallbacks = map[schema.GroupVersionKind]Callback{} - case 1: - unwrappedCallbacks = callbacks[0] - default: - panic("NewAdmissionController may not be called with multiple callback maps") - } - wh := &reconciler{ LeaderAwareFuncs: pkgreconciler.LeaderAwareFuncs{ // Have this reconciler enqueue our singleton whenever it becomes leader. @@ -77,7 +64,7 @@ func NewAdmissionController( }, path: path, handlers: handlers, - callbacks: unwrappedCallbacks, + callbacks: callbacks, withContext: wc, disallowUnknownFields: disallowUnknownFields, @@ -109,4 +96,29 @@ func NewAdmissionController( }) return c + +} + +// NewAdmissionController constructs a reconciler +func NewAdmissionController( + ctx context.Context, + name, path string, + handlers map[schema.GroupVersionKind]resourcesemantics.GenericCRD, + wc func(context.Context) context.Context, + disallowUnknownFields bool, + callbacks ...map[schema.GroupVersionKind]Callback, +) *controller.Impl { + // This not ideal, we are using a variadic argument to effectively make callbacks optional + // This allows this addition to be non-breaking to consumers of /pkg + // TODO: once all sub-repos have adopted this, we might move this back to a traditional param. + var unwrappedCallbacks map[schema.GroupVersionKind]Callback + switch len(callbacks) { + case 0: + unwrappedCallbacks = map[schema.GroupVersionKind]Callback{} + case 1: + unwrappedCallbacks = callbacks[0] + default: + panic("NewAdmissionController may not be called with multiple callback maps") + } + return NewAdmissionControllerWithConfig(ctx, name, path, handlers, wc, disallowUnknownFields, unwrappedCallbacks) } diff --git a/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/reconcile_config.go b/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/reconcile_config.go index 0078b61ce..a838351c8 100644 --- a/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/reconcile_config.go +++ b/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/reconcile_config.go @@ -100,23 +100,54 @@ func (ac *reconciler) reconcileValidatingWebhook(ctx context.Context, caCert []b logger := logging.FromContext(ctx) rules := make([]admissionregistrationv1.RuleWithOperations, 0, len(ac.handlers)) - for gvk := range ac.handlers { + for gvk, config := range ac.handlers { plural := strings.ToLower(flect.Pluralize(gvk.Kind)) + // If SupportedVerbs has not been given, provide the legacy defaults + // of Create, Update, and Delete + supportedVerbs := []admissionregistrationv1.OperationType{ + admissionregistrationv1.Create, + admissionregistrationv1.Update, + admissionregistrationv1.Delete, + } + + if vl, ok := config.(resourcesemantics.VerbLimited); ok { + logging.FromContext(ctx).Debugf("Using custom Verbs") + supportedVerbs = vl.SupportedVerbs() + } + logging.FromContext(ctx).Debugf("Registering verbs: %s", supportedVerbs) + + resources := []string{} + // If SupportedSubResources has not been given, provide the legacy + // defaults of main resource, and status + if srl, ok := config.(resourcesemantics.SubResourceLimited); ok { + logging.FromContext(ctx).Debugf("Using custom SubResources") + for _, subResource := range srl.SupportedSubResources() { + if subResource == "" { + // Special case the actual plural if given + resources = append(resources, plural) + } else { + resources = append(resources, plural+subResource) + } + } + } else { + resources = append(resources, plural, plural+"/status") + } + logging.FromContext(ctx).Debugf("Registering SubResources: %s", resources) rules = append(rules, admissionregistrationv1.RuleWithOperations{ - Operations: []admissionregistrationv1.OperationType{ - admissionregistrationv1.Create, - admissionregistrationv1.Update, - admissionregistrationv1.Delete, - }, + Operations: supportedVerbs, Rule: admissionregistrationv1.Rule{ APIGroups: []string{gvk.Group}, APIVersions: []string{gvk.Version}, - Resources: []string{plural, plural + "/status"}, + Resources: resources, }, }) } + for _, r := range rules { + logging.FromContext(ctx).Debugf("Rule: %+v", r) + } + // Sort the rules by Group, Version, Kind so that things are deterministically ordered. sort.Slice(rules, func(i, j int) bool { lhs, rhs := rules[i], rules[j] diff --git a/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/validation_admit.go b/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/validation_admit.go index 8ac55e805..2b05a7cd0 100644 --- a/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/validation_admit.go +++ b/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/validation_admit.go @@ -41,7 +41,6 @@ type Callback struct { function func(ctx context.Context, unstructured *unstructured.Unstructured) error // supportedVerbs are the verbs supported for the callback. - // The function will only be called on these actions. supportedVerbs map[webhook.Operation]struct{} } diff --git a/vendor/knative.dev/pkg/webhook/stats_reporter.go b/vendor/knative.dev/pkg/webhook/stats_reporter.go index 9d64634fe..1fe30e8af 100644 --- a/vendor/knative.dev/pkg/webhook/stats_reporter.go +++ b/vendor/knative.dev/pkg/webhook/stats_reporter.go @@ -25,6 +25,7 @@ import ( "go.opencensus.io/stats/view" "go.opencensus.io/tag" admissionv1 "k8s.io/api/admission/v1" + apixv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "knative.dev/pkg/metrics" ) @@ -57,11 +58,17 @@ var ( resourceResourceKey = tag.MustNewKey("resource_resource") resourceNamespaceKey = tag.MustNewKey("resource_namespace") admissionAllowedKey = tag.MustNewKey("admission_allowed") + + desiredAPIVersionKey = tag.MustNewKey("desired_api_version") + resultStatusKey = tag.MustNewKey("result_status") + resultReasonKey = tag.MustNewKey("result_reason") + resultCodeKey = tag.MustNewKey("result_code") ) // StatsReporter reports webhook metrics type StatsReporter interface { - ReportRequest(request *admissionv1.AdmissionRequest, response *admissionv1.AdmissionResponse, d time.Duration) error + ReportAdmissionRequest(request *admissionv1.AdmissionRequest, response *admissionv1.AdmissionResponse, d time.Duration) error + ReportConversionRequest(request *apixv1.ConversionRequest, response *apixv1.ConversionResponse, d time.Duration) error } // reporter implements StatsReporter interface @@ -82,7 +89,7 @@ func NewStatsReporter() (StatsReporter, error) { } // Captures req count metric, recording the count and the duration -func (r *reporter) ReportRequest(req *admissionv1.AdmissionRequest, resp *admissionv1.AdmissionResponse, d time.Duration) error { +func (r *reporter) ReportAdmissionRequest(req *admissionv1.AdmissionRequest, resp *admissionv1.AdmissionResponse, d time.Duration) error { ctx, err := tag.New( r.ctx, tag.Insert(requestOperationKey, string(req.Operation)), @@ -105,6 +112,25 @@ func (r *reporter) ReportRequest(req *admissionv1.AdmissionRequest, resp *admiss return nil } +// Captures req count metric, recording the count and the duration +func (r *reporter) ReportConversionRequest(req *apixv1.ConversionRequest, resp *apixv1.ConversionResponse, d time.Duration) error { + ctx, err := tag.New( + r.ctx, + tag.Insert(desiredAPIVersionKey, req.DesiredAPIVersion), + tag.Insert(resultStatusKey, resp.Result.Status), + tag.Insert(resultReasonKey, string(resp.Result.Reason)), + tag.Insert(resultCodeKey, strconv.Itoa(int(resp.Result.Code))), + ) + if err != nil { + return err + } + + metrics.RecordBatch(ctx, requestCountM.M(1), + // Convert time.Duration in nanoseconds to milliseconds + responseTimeInMsecM.M(float64(d.Milliseconds()))) + return nil +} + func RegisterMetrics() { tagKeys := []tag.Key{ requestOperationKey, @@ -115,7 +141,11 @@ func RegisterMetrics() { resourceVersionKey, resourceResourceKey, resourceNamespaceKey, - admissionAllowedKey} + admissionAllowedKey, + desiredAPIVersionKey, + resultStatusKey, + resultReasonKey, + resultCodeKey} if err := view.Register( &view.View{ diff --git a/vendor/knative.dev/serving/pkg/apis/config/defaults.go b/vendor/knative.dev/serving/pkg/apis/config/defaults.go index 3168d210c..3b9c18c9e 100644 --- a/vendor/knative.dev/serving/pkg/apis/config/defaults.go +++ b/vendor/knative.dev/serving/pkg/apis/config/defaults.go @@ -121,7 +121,6 @@ func NewDefaultsConfigFromMap(data map[string]string) (*Defaults, error) { cm.AsInt64("revision-timeout-seconds", &nc.RevisionTimeoutSeconds), cm.AsInt64("max-revision-timeout-seconds", &nc.MaxRevisionTimeoutSeconds), - cm.AsInt64("revision-response-start-timeout-seconds", &nc.RevisionRequestStartTimeoutSeconds), cm.AsInt64("revision-idle-timeout-seconds", &nc.RevisionIdleTimeoutSeconds), cm.AsInt64("container-concurrency", &nc.ContainerConcurrency), @@ -137,6 +136,15 @@ func NewDefaultsConfigFromMap(data map[string]string) (*Defaults, error) { return nil, err } + // We default this to what the user has specified + nc.RevisionRequestStartTimeoutSeconds = nc.RevisionTimeoutSeconds + + if err := cm.Parse(data, + cm.AsInt64("revision-response-start-timeout-seconds", &nc.RevisionRequestStartTimeoutSeconds), + ); err != nil { + return nil, err + } + if nc.RevisionTimeoutSeconds > nc.MaxRevisionTimeoutSeconds { return nil, fmt.Errorf("revision-timeout-seconds (%d) cannot be greater than max-revision-timeout-seconds (%d)", nc.RevisionTimeoutSeconds, nc.MaxRevisionTimeoutSeconds) } diff --git a/vendor/modules.txt b/vendor/modules.txt index db75c7a0e..f42e97cce 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1255,7 +1255,7 @@ k8s.io/utils/lru k8s.io/utils/net k8s.io/utils/pointer k8s.io/utils/trace -# knative.dev/client v0.34.0 +# knative.dev/client v0.34.1-0.20220906114442-59948bb3723d ## explicit; go 1.18 knative.dev/client/pkg/config knative.dev/client/pkg/dynamic @@ -1277,7 +1277,7 @@ knative.dev/client/pkg/sources/v1beta2 knative.dev/client/pkg/util knative.dev/client/pkg/util/mock knative.dev/client/pkg/wait -# knative.dev/eventing v0.34.1 +# knative.dev/eventing v0.34.1-0.20220906111743-7f1f49f5b4e0 ## explicit; go 1.18 knative.dev/eventing/pkg/adapter/v2 knative.dev/eventing/pkg/adapter/v2/util/crstatusevent @@ -1312,15 +1312,15 @@ knative.dev/eventing/pkg/metrics knative.dev/eventing/pkg/metrics/source knative.dev/eventing/pkg/observability knative.dev/eventing/pkg/observability/client -# knative.dev/hack v0.0.0-20220823140917-8d1e4ccf9dc3 -## explicit; go 1.17 +# knative.dev/hack v0.0.0-20220906140443-f9dc7220d362 +## explicit; go 1.18 knative.dev/hack -# knative.dev/networking v0.0.0-20220818010248-e51df7cdf571 +# knative.dev/networking v0.0.0-20220831065816-215bac90b28b ## explicit; go 1.18 knative.dev/networking/pkg/apis/networking knative.dev/networking/pkg/apis/networking/v1alpha1 knative.dev/networking/pkg/config -# knative.dev/pkg v0.0.0-20220818004048-4a03844c0b15 +# knative.dev/pkg v0.0.0-20220826162920-93b66e6a8700 ## explicit; go 1.18 knative.dev/pkg/apis knative.dev/pkg/apis/duck @@ -1396,7 +1396,7 @@ knative.dev/pkg/webhook/psbinding knative.dev/pkg/webhook/resourcesemantics knative.dev/pkg/webhook/resourcesemantics/defaulting knative.dev/pkg/webhook/resourcesemantics/validation -# knative.dev/serving v0.34.0 +# knative.dev/serving v0.34.1-0.20220905171742-62685b3b4a5a ## explicit; go 1.18 knative.dev/serving/pkg/apis/autoscaling knative.dev/serving/pkg/apis/autoscaling/v1alpha1