mirror of https://github.com/knative/caching.git
upgrade to latest dependencies (#476)
bumping knative.dev/pkg 980a337...47dfdcf: > 47dfdcf consolidate k8s flags to an environment package (# 2133) > 6484377 update boilerplate date (# 2134) > 35916ab Update actions (# 2132) Signed-off-by: Knative Automation <automation@knative.team>
This commit is contained in:
parent
81da77b579
commit
7a5afaeb6c
2
go.mod
2
go.mod
|
@ -20,5 +20,5 @@ require (
|
|||
k8s.io/code-generator v0.19.7
|
||||
k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6
|
||||
knative.dev/hack v0.0.0-20210428122153-93ad9129c268
|
||||
knative.dev/pkg v0.0.0-20210526081028-980a33719a10
|
||||
knative.dev/pkg v0.0.0-20210528203030-47dfdcfaedfd
|
||||
)
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1116,8 +1116,8 @@ k8s.io/utils v0.0.0-20200729134348-d5654de09c73 h1:uJmqzgNWG7XyClnU/mLPBWwfKKF1K
|
|||
k8s.io/utils v0.0.0-20200729134348-d5654de09c73/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
|
||||
knative.dev/hack v0.0.0-20210428122153-93ad9129c268 h1:lBIj9Epd9UQ55NEaHzAdY/UZbuaegCdGPKVC2+Z68Q0=
|
||||
knative.dev/hack v0.0.0-20210428122153-93ad9129c268/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
|
||||
knative.dev/pkg v0.0.0-20210526081028-980a33719a10 h1:4tC0TcIx4EU6PCcRwdIiCWuKI3vpOgpQUrF1nUeF1t8=
|
||||
knative.dev/pkg v0.0.0-20210526081028-980a33719a10/go.mod h1:nOD9XjvR+UuO1fHZSaOhfTWDCIz06crh1qQppgZDzR0=
|
||||
knative.dev/pkg v0.0.0-20210528203030-47dfdcfaedfd h1:UEVVrLzbuwD6DGR6pBy41onVZI8lC9QCZboBs5qxeLc=
|
||||
knative.dev/pkg v0.0.0-20210528203030-47dfdcfaedfd/go.mod h1:nOD9XjvR+UuO1fHZSaOhfTWDCIz06crh1qQppgZDzR0=
|
||||
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=
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright 2020 The Knative Authors
|
||||
Copyright 2021 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.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright 2020 The Knative Authors
|
||||
Copyright 2021 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.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2020 The Knative Authors
|
||||
Copyright 2021 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.
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
Copyright 2021 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.
|
||||
*/
|
||||
|
||||
package environment
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||
)
|
||||
|
||||
// ClientConfig holds the information about the environment and can be configured with flags
|
||||
type ClientConfig struct {
|
||||
Cluster string // K8s cluster (defaults to cluster in kubeconfig)
|
||||
ServerURL string // ServerURL - The address of the Kubernetes API server. Overrides any value in kubeconfig.
|
||||
Burst int // Burst - Maximum burst for throttle.
|
||||
QPS float64 // QPS - Maximum QPS to the server from the client.
|
||||
Kubeconfig string // Kubeconfig - Path to a kubeconfig. Current casing is present for backwards compatibility
|
||||
}
|
||||
|
||||
func (c *ClientConfig) InitFlags(fs *flag.FlagSet) {
|
||||
fs.StringVar(&c.Cluster, "cluster", "", "Defaults to the current cluster in kubeconfig.")
|
||||
|
||||
fs.StringVar(&c.ServerURL, "server", "",
|
||||
"The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
|
||||
|
||||
fs.StringVar(&c.Kubeconfig, "kubeconfig", os.Getenv("KUBECONFIG"),
|
||||
"Path to a kubeconfig. Only required if out-of-cluster.")
|
||||
|
||||
fs.IntVar(&c.Burst, "kube-api-burst", 0, "Maximum burst for throttle.")
|
||||
|
||||
fs.Float64Var(&c.QPS, "kube-api-qps", 0, "Maximum QPS to the server from the client.")
|
||||
}
|
||||
|
||||
func (c *ClientConfig) GetRESTConfig() (*rest.Config, error) {
|
||||
if c.Burst < 0 {
|
||||
return nil, fmt.Errorf("provided burst value %d must be > 0", c.Burst)
|
||||
}
|
||||
if c.QPS < 0 || c.QPS > math.MaxFloat32 {
|
||||
return nil, fmt.Errorf("provided QPS value %f must be >0 and <3.4+e38", c.QPS)
|
||||
}
|
||||
|
||||
// If we have an explicit indication of where the kubernetes config lives, read that.
|
||||
if c.Kubeconfig != "" {
|
||||
return c.configFromPath(c.Kubeconfig)
|
||||
}
|
||||
|
||||
// If not, try the in-cluster config.
|
||||
if rc, err := rest.InClusterConfig(); err == nil {
|
||||
return c.applyOverrides(rc), nil
|
||||
}
|
||||
|
||||
// If no in-cluster config, try the default location in the user's home directory.
|
||||
if c, err := c.configFromPath(clientcmd.RecommendedHomeFile); err == nil {
|
||||
return c, nil
|
||||
}
|
||||
|
||||
return nil, errors.New("could not create a valid kubeconfig")
|
||||
}
|
||||
|
||||
func (c *ClientConfig) configFromPath(path string) (*rest.Config, error) {
|
||||
overrides := &clientcmd.ConfigOverrides{}
|
||||
|
||||
if c.Cluster != "" {
|
||||
overrides.Context = clientcmdapi.Context{Cluster: c.Cluster}
|
||||
} else if c.ServerURL != "" {
|
||||
overrides.ClusterInfo = clientcmdapi.Cluster{Server: c.ServerURL}
|
||||
}
|
||||
|
||||
config, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
|
||||
&clientcmd.ClientConfigLoadingRules{ExplicitPath: path},
|
||||
overrides,
|
||||
).ClientConfig()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.applyOverrides(config), nil
|
||||
}
|
||||
|
||||
func (c *ClientConfig) applyOverrides(restCfg *rest.Config) *rest.Config {
|
||||
restCfg.QPS = float32(c.QPS)
|
||||
restCfg.Burst = c.Burst
|
||||
return restCfg
|
||||
}
|
|
@ -17,102 +17,34 @@ limitations under the License.
|
|||
package injection
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
"k8s.io/klog"
|
||||
"knative.dev/pkg/environment"
|
||||
)
|
||||
|
||||
// Environment holds the config for flag based config.
|
||||
type Environment struct {
|
||||
// ServerURL - The address of the Kubernetes API server. Overrides any value in kubeconfig.
|
||||
ServerURL string
|
||||
// Kubeconfig - Path to a kubeconfig.
|
||||
Kubeconfig string // Note: named Kubeconfig because of legacy reasons vs KubeConfig.
|
||||
// Burst - Maximum burst for throttle.
|
||||
Burst int
|
||||
// QPS - Maximum QPS to the server from the client.
|
||||
QPS float64
|
||||
}
|
||||
|
||||
var (
|
||||
env *Environment
|
||||
once sync.Once
|
||||
)
|
||||
|
||||
func Flags() *Environment {
|
||||
once.Do(func() {
|
||||
env = new(Environment)
|
||||
|
||||
flag.StringVar(&env.ServerURL, "server", "",
|
||||
"The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
|
||||
|
||||
flag.StringVar(&env.Kubeconfig, "kubeconfig", os.Getenv("KUBECONFIG"),
|
||||
"Path to a kubeconfig. Only required if out-of-cluster.")
|
||||
|
||||
flag.IntVar(&env.Burst, "kube-api-burst", 0, "Maximum burst for throttle.")
|
||||
|
||||
flag.Float64Var(&env.QPS, "kube-api-qps", 0, "Maximum QPS to the server from the client.")
|
||||
})
|
||||
return env
|
||||
}
|
||||
|
||||
// ParseAndGetRESTConfigOrDie parses the rest config flags and creates a client or
|
||||
// dies by calling log.Fatalf.
|
||||
func ParseAndGetRESTConfigOrDie() *rest.Config {
|
||||
env := Flags()
|
||||
|
||||
env := new(environment.ClientConfig)
|
||||
env.InitFlags(flag.CommandLine)
|
||||
klog.InitFlags(flag.CommandLine)
|
||||
flag.Parse()
|
||||
if env.Burst < 0 {
|
||||
log.Fatal("Invalid burst value", env.Burst)
|
||||
}
|
||||
if env.QPS < 0 || env.QPS > math.MaxFloat32 {
|
||||
log.Fatal("Invalid QPS value", env.QPS)
|
||||
}
|
||||
|
||||
cfg, err := GetRESTConfig(env.ServerURL, env.Kubeconfig)
|
||||
cfg, err := env.GetRESTConfig()
|
||||
if err != nil {
|
||||
log.Fatal("Error building kubeconfig: ", err)
|
||||
}
|
||||
|
||||
cfg.Burst = env.Burst
|
||||
cfg.QPS = float32(env.QPS)
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
// GetRESTConfig returns a rest.Config to be used for kubernetes client creation.
|
||||
// It does so in the following order:
|
||||
// 1. Use the passed kubeconfig/serverURL.
|
||||
// 2. Fallback to the KUBECONFIG environment variable.
|
||||
// 3. Fallback to in-cluster config.
|
||||
// 4. Fallback to the ~/.kube/config.
|
||||
// Deprecated: use environment.ClientConfig package
|
||||
func GetRESTConfig(serverURL, kubeconfig string) (*rest.Config, error) {
|
||||
// If we have an explicit indication of where the kubernetes config lives, read that.
|
||||
if kubeconfig != "" {
|
||||
c, err := clientcmd.BuildConfigFromFlags(serverURL, kubeconfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c, nil
|
||||
env := environment.ClientConfig{
|
||||
Kubeconfig: kubeconfig,
|
||||
ServerURL: serverURL,
|
||||
}
|
||||
|
||||
// If not, try the in-cluster config.
|
||||
if c, err := rest.InClusterConfig(); err == nil {
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// If no in-cluster config, try the default location in the user's home directory.
|
||||
if c, err := clientcmd.BuildConfigFromFlags("", clientcmd.RecommendedHomeFile); err == nil {
|
||||
return c, nil
|
||||
}
|
||||
|
||||
return nil, errors.New("could not create a valid kubeconfig")
|
||||
return env.GetRESTConfig()
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright 2020 The Knative Authors
|
||||
Copyright 2021 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.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright 2020 The Knative Authors
|
||||
Copyright 2021 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.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright 2020 The Knative Authors
|
||||
Copyright 2021 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.
|
||||
|
|
|
@ -667,7 +667,7 @@ k8s.io/utils/trace
|
|||
# knative.dev/hack v0.0.0-20210428122153-93ad9129c268
|
||||
## explicit
|
||||
knative.dev/hack
|
||||
# knative.dev/pkg v0.0.0-20210526081028-980a33719a10
|
||||
# knative.dev/pkg v0.0.0-20210528203030-47dfdcfaedfd
|
||||
## explicit
|
||||
knative.dev/pkg/apis
|
||||
knative.dev/pkg/apis/duck
|
||||
|
@ -681,6 +681,7 @@ knative.dev/pkg/codegen/cmd/injection-gen/args
|
|||
knative.dev/pkg/codegen/cmd/injection-gen/generators
|
||||
knative.dev/pkg/configmap
|
||||
knative.dev/pkg/controller
|
||||
knative.dev/pkg/environment
|
||||
knative.dev/pkg/hack
|
||||
knative.dev/pkg/hash
|
||||
knative.dev/pkg/injection
|
||||
|
|
Loading…
Reference in New Issue