Go1.19 changes (#2631)

* run goimports

* ignore linter errors for now

* fix boilerplate
This commit is contained in:
Dave Protasowski 2022-11-03 18:34:05 -04:00 committed by GitHub
parent 6718478e1e
commit 44d1d7d978
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 208 additions and 330 deletions

View File

@ -1,96 +0,0 @@
# Copyright 2020 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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This file is automagically synced here from github.com/knative-sandbox/.github
# repo by knobots: https://github.com/knative-sandbox/knobots and will be overwritten.
name: Boilerplate
on:
pull_request:
branches: [ 'main', 'master', 'release-*' ]
jobs:
check:
name: Boilerplate Check
runs-on: ubuntu-latest
strategy:
fail-fast: false # Keep running if one leg fails.
matrix:
extension:
- go
- sh
# Map between extension and human-readable name.
include:
- extension: go
language: Go
- extension: sh
language: Bash
steps:
- name: Set up Go 1.18.x
uses: actions/setup-go@v2
with:
go-version: 1.18.x
id: go
- name: Check out code
uses: actions/checkout@v2
- name: Install Tools
run: |
TEMP_PATH="$(mktemp -d)"
cd $TEMP_PATH
echo '::group::🐶 Installing reviewdog ... https://github.com/reviewdog/reviewdog'
curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b "${TEMP_PATH}" 2>&1
echo '::endgroup::'
echo '::group:: Installing boilerplate-check ... https://github.com/mattmoor/boilerplate-check'
go install github.com/mattmoor/boilerplate-check/cmd/boilerplate-check@latest
echo '::endgroup::'
echo "${TEMP_PATH}" >> $GITHUB_PATH
- id: boilerplate_txt
uses: andstor/file-existence-action@v1
with:
files: ./hack/boilerplate/boilerplate.${{ matrix.extension }}.txt
- name: ${{ matrix.language }} license boilerplate
shell: bash
if: ${{ steps.boilerplate_txt.outputs.files_exists == 'true' }}
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ github.token }}
run: |
set -e
cd "${GITHUB_WORKSPACE}" || exit 1
echo '::group:: Running github.com/mattmoor/boilerplate-check for ${{ matrix.language }} with reviewdog 🐶 ...'
# Don't fail because of boilerplate-check
set +o pipefail
boilerplate-check check \
--boilerplate ./hack/boilerplate/boilerplate.${{ matrix.extension }}.txt \
--file-extension ${{ matrix.extension }} \
--exclude "(vendor|third_party)/" |
reviewdog -efm="%A%f:%l: %m" \
-efm="%C%.%#" \
-name="${{ matrix.language }} headers" \
-reporter="github-pr-check" \
-filter-mode="diff_context" \
-fail-on-error="true" \
-level="error"
echo '::endgroup::'

View File

@ -1,61 +0,0 @@
# Copyright 2020 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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This file is automagically synced here from github.com/knative-sandbox/.github
# repo by knobots: https://github.com/knative-sandbox/knobots and will be overwritten.
name: Do Not Submit
on:
pull_request:
branches: [ 'main', 'master', 'release-*' ]
jobs:
donotsubmit:
name: Do Not Submit
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Do Not Submit
shell: bash
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ github.token }}
run: |
set -e
cd "${GITHUB_WORKSPACE}" || exit 1
TEMP_PATH="$(mktemp -d)"
PATH="${TEMP_PATH}:$PATH"
echo '::group::🐶 Installing reviewdog ... https://github.com/reviewdog/reviewdog'
curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b "${TEMP_PATH}" 2>&1
echo '::endgroup::'
echo '::group:: Running DO NOT SUBMIT with reviewdog 🐶 ...'
# Don't fail because of grep
set +o pipefail
find . -type f -not -path './vendor/*' -not -path './third_party/*' -not -path './.git/*' -not -path './.github/workflows/*' |
xargs grep -n "DO NOT SUBMIT" |
reviewdog -efm="%f:%l:%m" \
-name="DO NOT SUBMIT" \
-reporter="github-pr-check" \
-filter-mode="added" \
-fail-on-error="true" \
-level="error"
echo '::endgroup::'

View File

@ -33,7 +33,7 @@ import (
// under Status rather than strings.
// This is to support existing resources until they migrate.
//
// Do not use this for anything new, use Addressable
// # Do not use this for anything new, use Addressable
//
// LegacyTargetable is the old schema for the addressable portion
// of the payload

View File

@ -31,10 +31,10 @@ type Populatable = ducktypes.Populatable
// the provided Implementable duck type. It is expected that under the resource
// definition implementing a particular "Fooable" that one would write:
//
// type ConcreteResource struct { ... }
// type ConcreteResource struct { ... }
//
// // Check that ConcreteResource properly implement Fooable.
// err := duck.VerifyType(&ConcreteResource{}, &something.Fooable{})
// // Check that ConcreteResource properly implement Fooable.
// err := duck.VerifyType(&ConcreteResource{}, &something.Fooable{})
//
// This will return an error if the duck typing is not satisfied.
func VerifyType(instance interface{}, iface Implementable) error {

View File

@ -54,16 +54,16 @@ var Funcs = fuzzer.MergeFuzzerFuncs(
// Consumers should initialize their conditions prior to fuzzing them.
// For example:
//
// func(s *SomeStatus, c fuzz.Continue) {
// c.FuzzNoCustom(s) // fuzz the status object
// func(s *SomeStatus, c fuzz.Continue) {
// c.FuzzNoCustom(s) // fuzz the status object
//
// // Clear the random fuzzed condition
// s.Status.SetConditions(nil)
// // Clear the random fuzzed condition
// s.Status.SetConditions(nil)
//
// // Fuzz the known conditions except their type value
// s.InitializeConditions()
// fuzz.Conditions(&s.Status, c)
// }
// // Fuzz the known conditions except their type value
// s.InitializeConditions()
// fuzz.Conditions(&s.Status, c)
// }
func FuzzConditions(accessor apis.ConditionsAccessor, c fuzz.Continue) {
conds := accessor.GetConditions()
for i, cond := range conds {

View File

@ -87,8 +87,7 @@ func init() {
// ExternalTypesViaJSON applies the round-trip test to all external round-trippable Kinds
// in the scheme. This is effectively testing the scenario:
//
// external -> json -> external
//
// external -> json -> external
func ExternalTypesViaJSON(t *testing.T, scheme *runtime.Scheme, fuzzerFuncs fuzzer.FuzzerFuncs) {
codecFactory := serializer.NewCodecFactory(scheme)
@ -114,8 +113,7 @@ func ExternalTypesViaJSON(t *testing.T, scheme *runtime.Scheme, fuzzerFuncs fuzz
// ExternalTypesViaHub applies the round-trip test to all external round-trippable Kinds
// in the scheme. This is effectively testing the scenario:
//
// external version -> hub version -> external version
//
// external version -> hub version -> external version
func ExternalTypesViaHub(t *testing.T, scheme, hubs *runtime.Scheme, fuzzerFuncs fuzzer.FuzzerFuncs) {
f := fuzzer.FuzzerFor(
fuzzer.MergeFuzzerFuncs(metafuzzer.Funcs, fuzzerFuncs),

View File

@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package apis
import (

View File

@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@ -27,10 +27,10 @@ type CommentTag map[string][]string
// ExtractCommentTags parses comments for lines of the form:
//
// "marker" + "prefix" + ':' + "key=value,key2=value2".
// "marker" + "prefix" + ':' + "key=value,key2=value2".
//
// In the following example the marker is '+' and the prefix is 'foo':
// +foo:key=value1,key2=value2,key=value3
// In the following example the marker is '+' and the prefix is 'foo':
// +foo:key=value1,key2=value2,key=value3
//
// Values are optional; empty map is the default. A tag can be specified more than
// one time and all values are returned. If the resulting map has an entry for
@ -38,17 +38,19 @@ type CommentTag map[string][]string
//
// Example: if you pass "+" for 'marker', and the following lines are in
// the comments:
// +foo:key=value1,key2=value2,key=value3
// +bar
//
// +foo:key=value1,key2=value2,key=value3
// +bar
//
// Then this function will return:
// map[string]map[string]string{
// "foo":{
// "key": []string{"value1", "value3"},
// "key2": []string{"value2"}
// },
// "bar": {},
// }
//
// map[string]map[string]string{
// "foo":{
// "key": []string{"value1", "value3"},
// "key2": []string{"value2"}
// },
// "bar": {},
// }
//
// Users are not expected to repeat values.
func ExtractCommentTags(marker string, lines []string) CommentTags {

View File

@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,

View File

@ -16,6 +16,6 @@ limitations under the License.
// Package configmap exists to facilitate consuming Kubernetes ConfigMap
// resources in various ways, including:
// - Watching them for changes over time, and
// - Loading them from a VolumeMount.
// - Watching them for changes over time, and
// - Loading them from a VolumeMount.
package configmap

View File

@ -38,7 +38,7 @@ func TestChecksum(t *testing.T) {
in: "1",
want: "83dcefb7",
}, {
in: " a somewhat longer test ",
in: " a somewhat longer test ",
want: "fefe6f72",
}, {
in: "a somewhat longer test",

View File

@ -35,7 +35,7 @@ type Logger interface {
// Constructors is a map for specifying configmap names to
// their function constructors
//
// The values of this map must be functions with the definition
// # The values of this map must be functions with the definition
//
// func(*k8s.io/api/core/v1.ConfigMap) (... , error)
//
@ -60,7 +60,7 @@ type UntypedStore struct {
// NewUntypedStore creates an UntypedStore with given name,
// Logger and Constructors
//
// The Logger must not be nil
// # The Logger must not be nil
//
// The values in the Constructors map must be functions with
// the definition

View File

@ -49,9 +49,11 @@ func (g graph) order() []string {
}
// path constructs an examplary path that looks something like:
// knative.dev/pkg/apis/duck
// knative.dev/pkg/apis # Also: [knative.dev/pkg/kmeta knative.dev/pkg/tracker]
// k8s.io/api/core/v1
//
// knative.dev/pkg/apis/duck
// knative.dev/pkg/apis # Also: [knative.dev/pkg/kmeta knative.dev/pkg/tracker]
// k8s.io/api/core/v1
//
// See the failing example in the test file.
func (g graph) path(name string) []string {
n := g[name]

View File

@ -16,12 +16,12 @@ limitations under the License.
// Package hash contains various Knative specific hashing utilities.
//
// - ChooseSubset is a consistent hashing/mapping function providing
// a consistent selection of N keys from M (N<=M) keys for a given
// target.
// - BucketSet is a bucketer library which uses ChooseSubset under the
// the hood in order to implement consistent mapping between keys and
// set of buckets, identified by unique names. Compared to basic bucket
// implementation which just does hash%num_buckets, when the number of
// buckets change only a small subset of keys are supposed to migrate.
// - ChooseSubset is a consistent hashing/mapping function providing
// a consistent selection of N keys from M (N<=M) keys for a given
// target.
// - BucketSet is a bucketer library which uses ChooseSubset under the
// the hood in order to implement consistent mapping between keys and
// set of buckets, identified by unique names. Compared to basic bucket
// implementation which just does hash%num_buckets, when the number of
// buckets change only a small subset of keys are supposed to migrate.
package hash

View File

@ -22,84 +22,84 @@ limitations under the License.
// interesting. The first is in the context of implementations of
// `controller.Reconciler` being wrapped in a `*controller.Impl`:
//
// import (
// // Simply linking this triggers the injection of the informer, which links
// // the factory triggering its injection, and which links the client,
// // triggering its injection. All you need to know is that it works :)
// deployinformer "knative.dev/pkg/injection/informers/kubeinformers/appsv1/deployment"
// "knative.dev/pkg/injection"
// )
// import (
// // Simply linking this triggers the injection of the informer, which links
// // the factory triggering its injection, and which links the client,
// // triggering its injection. All you need to know is that it works :)
// deployinformer "knative.dev/pkg/injection/informers/kubeinformers/appsv1/deployment"
// "knative.dev/pkg/injection"
// )
//
// func NewController(ctx context.Context) *controller.Impl {
// deploymentInformer := deployinformer.Get(ctx)
// // Pass deploymentInformer.Lister() to Reconciler
// ...
// // Set up events on deploymentInformer.Informer()
// ...
// }
// func NewController(ctx context.Context) *controller.Impl {
// deploymentInformer := deployinformer.Get(ctx)
// // Pass deploymentInformer.Lister() to Reconciler
// ...
// // Set up events on deploymentInformer.Informer()
// ...
// }
//
// Then in `package main` the entire controller process can be set up via:
//
// package main
// package main
//
// import (
// // The set of controllers this controller process runs.
// // Linking these will register their transitive dependencies, after
// // which the shared main can set up the rest.
// "github.com/knative/foo/pkg/reconciler/matt"
// "github.com/knative/foo/pkg/reconciler/scott"
// "github.com/knative/foo/pkg/reconciler/ville"
// "github.com/knative/foo/pkg/reconciler/dave"
// import (
// // The set of controllers this controller process runs.
// // Linking these will register their transitive dependencies, after
// // which the shared main can set up the rest.
// "github.com/knative/foo/pkg/reconciler/matt"
// "github.com/knative/foo/pkg/reconciler/scott"
// "github.com/knative/foo/pkg/reconciler/ville"
// "github.com/knative/foo/pkg/reconciler/dave"
//
// // This defines the shared main for injected controllers.
// "knative.dev/pkg/injection/sharedmain"
// )
// // This defines the shared main for injected controllers.
// "knative.dev/pkg/injection/sharedmain"
// )
//
// func main() {
// sharedmain.Main("mycomponent",
// // We pass in the list of controllers to construct, and that's it!
// // If we forget to add this, go will complain about the unused import.
// matt.NewController,
// scott.NewController,
// ville.NewController,
// dave.NewController,
// )
// }
// func main() {
// sharedmain.Main("mycomponent",
// // We pass in the list of controllers to construct, and that's it!
// // If we forget to add this, go will complain about the unused import.
// matt.NewController,
// scott.NewController,
// ville.NewController,
// dave.NewController,
// )
// }
//
// If you want to adapt the above to run the controller within a single
// namespace, you can instead do something like:
//
// package main
// package main
//
// import (
// // The set of controllers this controller process runs.
// // Linking these will register their transitive dependencies, after
// // which the shared main can set up the rest.
// "github.com/knative/foo/pkg/reconciler/matt"
// "github.com/knative/foo/pkg/reconciler/scott"
// "github.com/knative/foo/pkg/reconciler/ville"
// "github.com/knative/foo/pkg/reconciler/dave"
// import (
// // The set of controllers this controller process runs.
// // Linking these will register their transitive dependencies, after
// // which the shared main can set up the rest.
// "github.com/knative/foo/pkg/reconciler/matt"
// "github.com/knative/foo/pkg/reconciler/scott"
// "github.com/knative/foo/pkg/reconciler/ville"
// "github.com/knative/foo/pkg/reconciler/dave"
//
// // This defines the shared main for injected controllers.
// "knative.dev/pkg/injection/sharedmain"
// // This defines the shared main for injected controllers.
// "knative.dev/pkg/injection/sharedmain"
//
// // These are used to set up the context.
// "knative.dev/pkg/injection"
// "knative.dev/pkg/signals"
// )
// // These are used to set up the context.
// "knative.dev/pkg/injection"
// "knative.dev/pkg/signals"
// )
//
// func main() {
// // Scope the shared informer factories to the provided namespace.
// ctx := injection.WithNamespace(signals.NewContext(), "the-namespace")
// func main() {
// // Scope the shared informer factories to the provided namespace.
// ctx := injection.WithNamespace(signals.NewContext(), "the-namespace")
//
// // Use our initial context when setting up the controllers.
// sharedmain.MainWithContext(ctx, "mycomponent",
// // We pass in the list of controllers to construct, and that's it!
// // If we forget to add this, go will complain about the unused import.
// matt.NewController,
// scott.NewController,
// ville.NewController,
// dave.NewController,
// )
// }
// // Use our initial context when setting up the controllers.
// sharedmain.MainWithContext(ctx, "mycomponent",
// // We pass in the list of controllers to construct, and that's it!
// // If we forget to add this, go will complain about the unused import.
// matt.NewController,
// scott.NewController,
// ville.NewController,
// dave.NewController,
// )
// }
package injection

View File

@ -34,9 +34,11 @@ import (
//
// Typical integration:
// ```go
// ctx, startInformers := injection.EnableInjectionOrDie(signals.NewContext(), nil)
// ... start watches with informers, if required ...
// startInformers()
//
// ctx, startInformers := injection.EnableInjectionOrDie(signals.NewContext(), nil)
// ... start watches with informers, if required ...
// startInformers()
//
// ```
func EnableInjectionOrDie(ctx context.Context, cfg *rest.Config) (context.Context, func()) {
if ctx == nil {

View File

@ -29,9 +29,12 @@ import (
// StringSet returns a marshaler for the set of strings.
// To use this in sugared logger do:
//
// logger.Infow("Revision State", zap.Object("healthy", logging.StringSet(healthySet)),
// zap.Object("unhealthy", logging.StringSet(unhealthySet)))
//
// To use with non-sugared logger do:
//
// logger.Info("Revision State", zap.Object("healthy", logging.StringSet(healthySet)),
// zap.Object("unhealthy", logging.StringSet(unhealthySet)))
func StringSet(s sets.String) zapcore.ObjectMarshalerFunc {

View File

@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package metrics
import (

View File

@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package metricskey_test
import (

View File

@ -3,7 +3,9 @@ Copyright 2020 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

View File

@ -41,7 +41,7 @@ func (emptyPromExporter) ExportView(viewData *view.Data) {
// a signal to enrich the internal Meters with Resource information.
}
//nolint: unparam // False positive of flagging the second result of this function unused.
// nolint: unparam // False positive of flagging the second result of this function unused.
func newPrometheusExporter(config *metricsConfig, logger *zap.SugaredLogger) (view.Exporter, ResourceExporterFactory, error) {
e, err := prom.NewExporter(prom.Options{Namespace: config.component})
if err != nil {
@ -82,6 +82,7 @@ func startNewPromSrv(e *prom.Exporter, host string, port int) *http.Server {
if curPromSrv != nil {
curPromSrv.Close()
}
//nolint:gosec
curPromSrv = &http.Server{
Addr: host + ":" + strconv.Itoa(port),
Handler: sm,

View File

@ -3,7 +3,9 @@ Copyright 2019 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

View File

@ -28,6 +28,7 @@ import (
// NewServer returns a new HTTP Server with HTTP2 handler.
func NewServer(addr string, h http.Handler) *http.Server {
//nolint:gosec
h1s := &http.Server{
Addr: addr,
Handler: h2c.NewHandler(h, &http2.Server{}),

View File

@ -20,5 +20,6 @@ import "knative.dev/pkg/network"
// Error sets up a handler suitable for use with the ErrorHandler field on
// httputil's reverse proxy, which logs /proc/net/sockstat data.
//
//nolint:staticcheck // We actually want to mirror this.
var Error = network.ErrorHandler

View File

@ -110,6 +110,7 @@ func NewServer(handler http.Handler) *http.Server {
port = strconv.Itoa(ProfilingPort)
}
//nolint:gosec
return &http.Server{
Addr: ":" + port,
Handler: handler,

View File

@ -5,7 +5,7 @@ Licensed under the Apache License, Veroute.on 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,

View File

@ -44,7 +44,7 @@ CreateHookFunc is a function for handling a Create hook. Its runtime.Object
parameter will be the Kubernetes resource created. The resource can be cast
to its actual type like this:
pod := obj.(*v1.Pod)
pod := obj.(*v1.Pod)
A return value of true marks the hook as completed. Returning false allows
the hook to run again when the next resource of the requested type is
@ -57,7 +57,7 @@ UpdateHookFunc is a function for handling an update hook. its runtime.Object
parameter will be the Kubernetes resource updated. The resource can be cast
to its actual type like this:
pod := obj.(*v1.Pod)
pod := obj.(*v1.Pod)
A return value of true marks the hook as completed. Returning false allows
the hook to run again when the next resource of the requested type is

View File

@ -28,15 +28,18 @@ import (
// InduceFailure is used in conjunction with TableTest's WithReactors field.
// Tests that want to induce a failure in a row of a TableTest would add:
// WithReactors: []clientgotesting.ReactionFunc{
// // Makes calls to create revisions return an error.
// InduceFailure("create", "revisions"),
// },
//
// WithReactors: []clientgotesting.ReactionFunc{
// // Makes calls to create revisions return an error.
// InduceFailure("create", "revisions"),
// },
//
// Or to target a subresource, say a patch to InMemoryChannel.Status, you would add:
// WithReactors: []clientgotesting.ReactionFunc{
// // Makes calls to patch inmemorychannels status subresource return an error.
// InduceFailure("patch", "inmemorychannels/status"),
// },
//
// WithReactors: []clientgotesting.ReactionFunc{
// // Makes calls to patch inmemorychannels status subresource return an error.
// InduceFailure("patch", "inmemorychannels/status"),
// },
func InduceFailure(verb, resource string) clientgotesting.ReactionFunc {
return func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) {
if !action.Matches(verb, resource) {

View File

@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,

View File

@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,

View File

@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,

View File

@ -30,7 +30,7 @@ import (
"google.golang.org/api/option"
)
//nolint // there's also Client so they collide.
// nolint // there's also Client so they collide.
type GCSClient struct {
*storage.Client
}

View File

@ -44,9 +44,12 @@ var bannedImports = []vbTuple{
}
// TestBannedImports run with:
// go test ./vendor/knative.dev/pkg/test/imports/ -run TestBannedImports
//
// go test ./vendor/knative.dev/pkg/test/imports/ -run TestBannedImports
//
// Or with test-infra:
// report_go_test ${REPO_ROOT_DIR}/vendor/knative.dev/pkg/test/imports/...
//
// report_go_test ${REPO_ROOT_DIR}/vendor/knative.dev/pkg/test/imports/...
func TestBannedImports(t *testing.T) {
_, filename, _, _ := runtime.Caller(0)
dir := filepath.Dir(filename)

View File

@ -35,8 +35,10 @@ const (
// GetIngressEndpoint gets the ingress public IP or hostname.
// address - is the endpoint to which we should actually connect.
// portMap - translates the request's port to the port on address to which the caller
// should connect. This is used when the resolution to address goes through some
// sort of port-mapping, e.g. Kubernetes node ports.
//
// should connect. This is used when the resolution to address goes through some
// sort of port-mapping, e.g. Kubernetes node ports.
//
// err - an error when address/portMap cannot be established.
func GetIngressEndpoint(ctx context.Context, kubeClientset kubernetes.Interface, endpointOverride string) (address string, portMap func(string) string, err error) {
ingressName := istioIngressName

View File

@ -76,7 +76,9 @@ func (d *Docker) AddMount(typeStr, source, target string, optAdditionalArgs ...s
}
// AddRWOverlay mounts a directory into the image at the desired location, but with an overlay
// so internal changes do not modify the external directory.
//
// so internal changes do not modify the external directory.
//
// externalDirectory probably needs to be an absolute path
// Returns a function to clean up the mount (but does not delete the directory).
// Uses sudo and probably only works on Linux

View File

@ -26,13 +26,14 @@ import (
)
// steadyUpPacer is a Pacer that describes attack request rates that increases in the beginning then becomes steady.
// Max | ,----------------
// | /
// | /
// | /
// | /
// Min -+------------------------------> t
// |<-Up->|
//
// Max | ,----------------
// | /
// | /
// | /
// | /
// Min -+------------------------------> t
// |<-Up->|
type steadyUpPacer struct {
// upDuration is the duration that attack request rates increase from Min to Max.
// MUST be larger than 0.

View File

@ -33,9 +33,8 @@ This package exposes following methods:
A general flow for a Test Suite to use Zipkin Tracing support is as follows:
1. Call SetupZipkinTracing(kubernetes.Interface) in TestMain.
2. Use SpoofingClient to make HTTP requests.
3. Call CleanupZipkinTracingSetup on cleanup after tests are executed.
1. Call SetupZipkinTracing(kubernetes.Interface) in TestMain.
2. Use SpoofingClient to make HTTP requests.
3. Call CleanupZipkinTracingSetup on cleanup after tests are executed.
*/
package zipkin

View File

@ -110,9 +110,10 @@ func SetupZipkinTracingFromConfigTracingOrFail(ctx context.Context, t testing.TB
}
// SetupZipkinTracing sets up zipkin tracing which involves:
// 1. Setting up port-forwarding from localhost to zipkin pod on the cluster
// (pid of the process doing Port-Forward is stored in a global variable).
// 2. Enable AlwaysSample config for tracing for the SpoofingClient.
// 1. Setting up port-forwarding from localhost to zipkin pod on the cluster
// (pid of the process doing Port-Forward is stored in a global variable).
// 2. Enable AlwaysSample config for tracing for the SpoofingClient.
//
// The zipkin deployment must have the label app=zipkin
func SetupZipkinTracing(ctx context.Context, kubeClientset kubernetes.Interface, logf logging.FormatLogger, zipkinRemotePort int, zipkinNamespace string) (err error) {
setupOnce.Do(func() {
@ -152,13 +153,13 @@ func SetupZipkinTracingOrFail(ctx context.Context, t testing.TB, kubeClientset k
// CleanupZipkinTracingSetup cleans up the Zipkin tracing setup on the machine. This involves killing the process performing port-forward.
// This should be called exactly once in TestMain. Likely in the form:
//
// func TestMain(m *testing.M) {
// os.Exit(func() int {
// // Any setup required for the tests.
// defer zipkin.CleanupZipkinTracingSetup(logger)
// return m.Run()
// }())
// }
// func TestMain(m *testing.M) {
// os.Exit(func() int {
// // Any setup required for the tests.
// defer zipkin.CleanupZipkinTracingSetup(logger)
// return m.Run()
// }())
// }
func CleanupZipkinTracingSetup(logf logging.FormatLogger) {
teardownOnce.Do(func() {
// Because CleanupZipkinTracingSetup only runs once, make sure that now that it has been

View File

@ -147,8 +147,9 @@ func WithExporter(name string, logger *zap.SugaredLogger) ConfigOption {
// The host arg is used for a value of tag ip="{IP}" so you can use an actual IP. Otherwise,
// the host name must be able to be resolved.
// e.g)
// "name" is a service name like activator-service.
// "host" is a endpoint IP like activator-service's endpoint IP.
//
// "name" is a service name like activator-service.
// "host" is a endpoint IP like activator-service's endpoint IP.
func WithExporterFull(name, host string, logger *zap.SugaredLogger) ConfigOption {
return func(cfg *config.Config) error {
var (

View File

@ -27,13 +27,14 @@ import (
// FakeZipkinExporter is intended to capture the testing boilerplate of building
// up the ConfigOption to pass NewOpenCensusTracer and expose a mechanism for examining
// the traces it would have reported. To set it up, use something like:
// reporter, co := FakeZipkinExporter()
// defer reporter.Close()
// oct := NewOpenCensusTracer(co)
// defer oct.Close()
// // Do stuff.
// spans := reporter.Flush()
// // Check reported spans.
//
// reporter, co := FakeZipkinExporter()
// defer reporter.Close()
// oct := NewOpenCensusTracer(co)
// defer oct.Close()
// // Do stuff.
// spans := reporter.Flush()
// // Check reported spans.
func FakeZipkinExporter() (*recorder.ReporterRecorder, tracing.ConfigOption) {
// Create tracer with reporter recorder
reporter := recorder.NewReporter()

View File

@ -31,8 +31,8 @@ type ZipkinReporterFactory func(*config.Config) (zipkinreporter.Reporter, error)
// WithZipkinExporter returns a config with zipkin enabled.
//
// Deprecated: This function is the legacy entrypoint and should be replaced with one of:
// - WithExporter() in production code
// - testing/FakeZipkinExporter() in test code.
// - WithExporter() in production code
// - testing/FakeZipkinExporter() in test code.
func WithZipkinExporter(reporterFact ZipkinReporterFactory, endpoint *zipkinmodel.Endpoint) ConfigOption {
return func(cfg *config.Config) error {
var (

View File

@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package webhook
import (

View File

@ -17,11 +17,11 @@ limitations under the License.
// Package psbinding provides facilities to make authoring Bindings that
// work with "Pod Spec"-able subjects easier. There are two key components
// 1. The AdmissionController, which lives in psbinding.go (controller.go)
// sets it up.
// sets it up.
// 2. The BaseReconciler, which lives in reconciler.go and can either be
// used directly as a Reconciler, or it can be wrapped as a base
// implementation for a customized reconciler that wants to take advantage
// of its facilities (e.g. for updating status and manipulating finalizers).
// used directly as a Reconciler, or it can be wrapped as a base
// implementation for a customized reconciler that wants to take advantage
// of its facilities (e.g. for updating status and manipulating finalizers).
//
// The core concept to consuming psbinding is the Bindable interface. By
// implementing Bindable on your binding resource, you enable the BaseReconciler
@ -31,7 +31,9 @@ limitations under the License.
// "mutation" methods carry the business logic for the "Pod Spec"-able binding.
//
// The mutation methods have the signature:
// func(context.Context, *v1alpha1.WithPod)
//
// func(context.Context, *v1alpha1.WithPod)
//
// These methods are called to have the Binding perform its mutation on the
// supplied WithPod (our "Pod Spec"-able wrapper type). However, in some
// cases the binding may need additional context. Similar to apis.Validatable

View File

@ -208,6 +208,7 @@ func (wh *Webhook) Run(stop <-chan struct{}) error {
QuietPeriod: wh.Options.GracePeriod,
}
//nolint:gosec
server := &http.Server{
Handler: drainer,
Addr: fmt.Sprint(":", wh.Options.Port),