mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 20:42:26 +00:00
Merge pull request #22736 from resouer/fix-util-dev
Auto commit by PR queue bot
This commit is contained in:
commit
4af38b52b9
@ -32,7 +32,7 @@ import (
|
||||
kubeletclient "k8s.io/kubernetes/pkg/kubelet/client"
|
||||
"k8s.io/kubernetes/pkg/master/ports"
|
||||
etcdstorage "k8s.io/kubernetes/pkg/storage/etcd"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
"k8s.io/kubernetes/pkg/util/config"
|
||||
utilnet "k8s.io/kubernetes/pkg/util/net"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
@ -74,7 +74,7 @@ type APIServer struct {
|
||||
OIDCIssuerURL string
|
||||
OIDCUsernameClaim string
|
||||
OIDCGroupsClaim string
|
||||
RuntimeConfig util.ConfigurationMap
|
||||
RuntimeConfig config.ConfigurationMap
|
||||
SSHKeyfile string
|
||||
SSHUser string
|
||||
ServiceAccountKeyFile string
|
||||
@ -106,7 +106,7 @@ func NewAPIServer() *APIServer {
|
||||
EventTTL: 1 * time.Hour,
|
||||
MasterCount: 1,
|
||||
MasterServiceNamespace: api.NamespaceDefault,
|
||||
RuntimeConfig: make(util.ConfigurationMap),
|
||||
RuntimeConfig: make(config.ConfigurationMap),
|
||||
StorageVersions: registered.AllPreferredGroupVersions(),
|
||||
DefaultStorageVersions: registered.AllPreferredGroupVersions(),
|
||||
KubeletConfig: kubeletclient.KubeletClientConfig{
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"k8s.io/kubernetes/pkg/master/ports"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
"k8s.io/kubernetes/pkg/util/config"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
@ -52,8 +53,8 @@ type KubeletServer struct {
|
||||
ChaosChance float64
|
||||
// Crash immediately, rather than eating panics.
|
||||
ReallyCrashForTesting bool
|
||||
SystemReserved util.ConfigurationMap
|
||||
KubeReserved util.ConfigurationMap
|
||||
SystemReserved config.ConfigurationMap
|
||||
KubeReserved config.ConfigurationMap
|
||||
}
|
||||
|
||||
// NewKubeletServer will create a new KubeletServer with default values.
|
||||
@ -62,8 +63,8 @@ func NewKubeletServer() *KubeletServer {
|
||||
AuthPath: util.NewStringFlag("/var/lib/kubelet/kubernetes_auth"), // deprecated
|
||||
KubeConfig: util.NewStringFlag("/var/lib/kubelet/kubeconfig"),
|
||||
|
||||
SystemReserved: make(util.ConfigurationMap),
|
||||
KubeReserved: make(util.ConfigurationMap),
|
||||
SystemReserved: make(config.ConfigurationMap),
|
||||
KubeReserved: make(config.ConfigurationMap),
|
||||
KubeletConfiguration: componentconfig.KubeletConfiguration{
|
||||
Address: "0.0.0.0",
|
||||
CAdvisorPort: 4194,
|
||||
@ -181,7 +182,7 @@ func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&s.ClusterDNS, "cluster-dns", s.ClusterDNS, "IP address for a cluster DNS server. If set, kubelet will configure all containers to use this for DNS resolution in addition to the host's DNS servers")
|
||||
fs.DurationVar(&s.StreamingConnectionIdleTimeout.Duration, "streaming-connection-idle-timeout", s.StreamingConnectionIdleTimeout.Duration, "Maximum time a streaming connection can be idle before the connection is automatically closed. 0 indicates no timeout. Example: '5m'")
|
||||
fs.DurationVar(&s.NodeStatusUpdateFrequency.Duration, "node-status-update-frequency", s.NodeStatusUpdateFrequency.Duration, "Specifies how often kubelet posts node status to master. Note: be cautious when changing the constant, it must work with nodeMonitorGracePeriod in nodecontroller. Default: 10s")
|
||||
bindableNodeLabels := util.ConfigurationMap(s.NodeLabels)
|
||||
bindableNodeLabels := config.ConfigurationMap(s.NodeLabels)
|
||||
fs.Var(&bindableNodeLabels, "node-labels", "<Warning: Alpha feature> Labels to add when registering the node in the cluster. Labels must be key=value pairs separated by ','.")
|
||||
fs.DurationVar(&s.ImageMinimumGCAge.Duration, "minimum-image-ttl-duration", s.ImageMinimumGCAge.Duration, "Minimum age for a unused image before it is garbage collected. Examples: '300ms', '10s' or '2h45m'. Default: '2m'")
|
||||
fs.IntVar(&s.ImageGCHighThresholdPercent, "image-gc-high-threshold", s.ImageGCHighThresholdPercent, "The percent of disk usage after which image garbage collection is always run. Default: 90%")
|
||||
|
@ -59,6 +59,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubelet/server"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
utilconfig "k8s.io/kubernetes/pkg/util/config"
|
||||
"k8s.io/kubernetes/pkg/util/configz"
|
||||
"k8s.io/kubernetes/pkg/util/crypto"
|
||||
"k8s.io/kubernetes/pkg/util/flock"
|
||||
@ -876,7 +877,7 @@ func CreateAndInitKubelet(kc *KubeletConfig) (k KubeletBootstrap, pc *config.Pod
|
||||
return k, pc, nil
|
||||
}
|
||||
|
||||
func parseReservation(kubeReserved, systemReserved util.ConfigurationMap) (*kubetypes.Reservation, error) {
|
||||
func parseReservation(kubeReserved, systemReserved utilconfig.ConfigurationMap) (*kubetypes.Reservation, error) {
|
||||
reservation := new(kubetypes.Reservation)
|
||||
if rl, err := parseResourceList(kubeReserved); err != nil {
|
||||
return nil, err
|
||||
@ -891,7 +892,7 @@ func parseReservation(kubeReserved, systemReserved util.ConfigurationMap) (*kube
|
||||
return reservation, nil
|
||||
}
|
||||
|
||||
func parseResourceList(m util.ConfigurationMap) (api.ResourceList, error) {
|
||||
func parseResourceList(m utilconfig.ConfigurationMap) (api.ResourceList, error) {
|
||||
rl := make(api.ResourceList)
|
||||
for k, v := range m {
|
||||
switch api.ResourceName(k) {
|
||||
|
@ -2195,7 +2195,7 @@ _kubectl_config_view()
|
||||
flags_completion=()
|
||||
|
||||
flags+=("--flatten")
|
||||
flags+=("--merge")
|
||||
flags+=("--merge=")
|
||||
flags+=("--minify")
|
||||
flags+=("--no-headers")
|
||||
flags+=("--output=")
|
||||
@ -2249,8 +2249,8 @@ _kubectl_config_set-cluster()
|
||||
|
||||
flags+=("--api-version=")
|
||||
flags+=("--certificate-authority=")
|
||||
flags+=("--embed-certs")
|
||||
flags+=("--insecure-skip-tls-verify")
|
||||
flags+=("--embed-certs=")
|
||||
flags+=("--insecure-skip-tls-verify=")
|
||||
flags+=("--server=")
|
||||
flags+=("--alsologtostderr")
|
||||
flags+=("--client-certificate=")
|
||||
@ -2288,7 +2288,7 @@ _kubectl_config_set-credentials()
|
||||
|
||||
flags+=("--client-certificate=")
|
||||
flags+=("--client-key=")
|
||||
flags+=("--embed-certs")
|
||||
flags+=("--embed-certs=")
|
||||
flags+=("--password=")
|
||||
flags+=("--token=")
|
||||
flags+=("--username=")
|
||||
|
@ -29,6 +29,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
|
||||
clientcmdapi "k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
"k8s.io/kubernetes/pkg/util/flag"
|
||||
)
|
||||
|
||||
type createAuthInfoOptions struct {
|
||||
@ -40,7 +41,7 @@ type createAuthInfoOptions struct {
|
||||
token util.StringFlag
|
||||
username util.StringFlag
|
||||
password util.StringFlag
|
||||
embedCertData util.BoolFlag
|
||||
embedCertData flag.Tristate
|
||||
}
|
||||
|
||||
var create_authinfo_long = fmt.Sprintf(`Sets a user entry in kubeconfig
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
|
||||
clientcmdapi "k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
"k8s.io/kubernetes/pkg/util/flag"
|
||||
)
|
||||
|
||||
type createClusterOptions struct {
|
||||
@ -35,9 +36,9 @@ type createClusterOptions struct {
|
||||
name string
|
||||
server util.StringFlag
|
||||
apiVersion util.StringFlag
|
||||
insecureSkipTLSVerify util.BoolFlag
|
||||
insecureSkipTLSVerify flag.Tristate
|
||||
certificateAuthority util.StringFlag
|
||||
embedCAData util.BoolFlag
|
||||
embedCAData flag.Tristate
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -28,12 +28,12 @@ import (
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api/latest"
|
||||
"k8s.io/kubernetes/pkg/kubectl"
|
||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
"k8s.io/kubernetes/pkg/util/flag"
|
||||
)
|
||||
|
||||
type ViewOptions struct {
|
||||
ConfigAccess ConfigAccess
|
||||
Merge util.BoolFlag
|
||||
Merge flag.Tristate
|
||||
Flatten bool
|
||||
Minify bool
|
||||
RawByteData bool
|
||||
|
@ -34,6 +34,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/storage/etcd/metrics"
|
||||
etcdutil "k8s.io/kubernetes/pkg/storage/etcd/util"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
utilcache "k8s.io/kubernetes/pkg/util/cache"
|
||||
utilnet "k8s.io/kubernetes/pkg/util/net"
|
||||
"k8s.io/kubernetes/pkg/watch"
|
||||
|
||||
@ -128,7 +129,7 @@ func NewEtcdStorage(client etcd.Client, codec runtime.Codec, prefix string, quor
|
||||
copier: api.Scheme,
|
||||
pathPrefix: path.Join("/", prefix),
|
||||
quorum: quorum,
|
||||
cache: util.NewCache(maxEtcdCacheEntries),
|
||||
cache: utilcache.NewCache(maxEtcdCacheEntries),
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,7 +156,7 @@ type etcdHelper struct {
|
||||
// support multi-object transaction that will result in many objects with the same index.
|
||||
// Number of entries stored in the cache is controlled by maxEtcdCacheEntries constant.
|
||||
// TODO: Measure how much this cache helps after the conversion code is optimized.
|
||||
cache util.Cache
|
||||
cache utilcache.Cache
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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 util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// BoolFlag is a boolean flag compatible with flags and pflags that keeps track of whether it had a value supplied or not.
|
||||
// Getting this flag to act like a normal bool, where true/false are not required needs a little bit of extra code, example:
|
||||
// f := cmd.Flags().VarPF(&BoolFlagVar, "flagname", "", "help about the flag")
|
||||
// f.NoOptDefVal = "true"
|
||||
type BoolFlag struct {
|
||||
// If Set has been invoked this value is true
|
||||
provided bool
|
||||
// The exact value provided on the flag
|
||||
value bool
|
||||
}
|
||||
|
||||
func (f *BoolFlag) Default(value bool) {
|
||||
f.value = value
|
||||
}
|
||||
|
||||
func (f BoolFlag) String() string {
|
||||
return fmt.Sprintf("%t", f.value)
|
||||
}
|
||||
|
||||
func (f BoolFlag) Value() bool {
|
||||
return f.value
|
||||
}
|
||||
|
||||
func (f *BoolFlag) Set(value string) error {
|
||||
boolVal, err := strconv.ParseBool(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f.value = boolVal
|
||||
f.provided = true
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f BoolFlag) Provided() bool {
|
||||
return f.provided
|
||||
}
|
||||
|
||||
func (f *BoolFlag) Type() string {
|
||||
return "bool"
|
||||
}
|
2
pkg/util/cache.go → pkg/util/cache/cache.go
vendored
2
pkg/util/cache.go → pkg/util/cache/cache.go
vendored
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package util
|
||||
package cache
|
||||
|
||||
import (
|
||||
"sync"
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package util
|
||||
package cache
|
||||
|
||||
import (
|
||||
"testing"
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package util
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
83
pkg/util/flag/tristate.go
Normal file
83
pkg/util/flag/tristate.go
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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 flag
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Tristate is a flag compatible with flags and pflags that
|
||||
// keeps track of whether it had a value supplied or not.
|
||||
type Tristate int
|
||||
|
||||
const (
|
||||
Unset Tristate = iota // 0
|
||||
True
|
||||
False
|
||||
)
|
||||
|
||||
func (f *Tristate) Default(value bool) {
|
||||
*f = triFromBool(value)
|
||||
}
|
||||
|
||||
func (f Tristate) String() string {
|
||||
b := boolFromTri(f)
|
||||
return fmt.Sprintf("%t", b)
|
||||
}
|
||||
|
||||
func (f Tristate) Value() bool {
|
||||
b := boolFromTri(f)
|
||||
return b
|
||||
}
|
||||
|
||||
func (f *Tristate) Set(value string) error {
|
||||
boolVal, err := strconv.ParseBool(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*f = triFromBool(boolVal)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f Tristate) Provided() bool {
|
||||
if f != Unset {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (f *Tristate) Type() string {
|
||||
return "tristate"
|
||||
}
|
||||
|
||||
func boolFromTri(t Tristate) bool {
|
||||
if t == True {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func triFromBool(b bool) Tristate {
|
||||
if b {
|
||||
return True
|
||||
} else {
|
||||
return False
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user