diff --git a/cmd/kube-apiserver/app/options/options.go b/cmd/kube-apiserver/app/options/options.go index a08e45f615e..c5eb38e2a1e 100644 --- a/cmd/kube-apiserver/app/options/options.go +++ b/cmd/kube-apiserver/app/options/options.go @@ -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{ diff --git a/cmd/kubelet/app/options/options.go b/cmd/kubelet/app/options/options.go index e58706f7349..81bc772bc83 100644 --- a/cmd/kubelet/app/options/options.go +++ b/cmd/kubelet/app/options/options.go @@ -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", " 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%") diff --git a/cmd/kubelet/app/server.go b/cmd/kubelet/app/server.go index 80ae438fa85..3cde955ac1d 100644 --- a/cmd/kubelet/app/server.go +++ b/cmd/kubelet/app/server.go @@ -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) { diff --git a/contrib/completions/bash/kubectl b/contrib/completions/bash/kubectl index b7d5a20429c..772ac4f8367 100644 --- a/contrib/completions/bash/kubectl +++ b/contrib/completions/bash/kubectl @@ -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=") diff --git a/pkg/kubectl/cmd/config/create_authinfo.go b/pkg/kubectl/cmd/config/create_authinfo.go index 0f8aa3b6fff..aeabd106d32 100644 --- a/pkg/kubectl/cmd/config/create_authinfo.go +++ b/pkg/kubectl/cmd/config/create_authinfo.go @@ -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 diff --git a/pkg/kubectl/cmd/config/create_cluster.go b/pkg/kubectl/cmd/config/create_cluster.go index 79edfd0cf37..b3e08414e30 100644 --- a/pkg/kubectl/cmd/config/create_cluster.go +++ b/pkg/kubectl/cmd/config/create_cluster.go @@ -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 ( diff --git a/pkg/kubectl/cmd/config/view.go b/pkg/kubectl/cmd/config/view.go index 5d253a118fa..bcdf91788f4 100644 --- a/pkg/kubectl/cmd/config/view.go +++ b/pkg/kubectl/cmd/config/view.go @@ -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 diff --git a/pkg/storage/etcd/etcd_helper.go b/pkg/storage/etcd/etcd_helper.go index 896baf63f74..469b2ed88f1 100644 --- a/pkg/storage/etcd/etcd_helper.go +++ b/pkg/storage/etcd/etcd_helper.go @@ -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() { diff --git a/pkg/util/bool_flag.go b/pkg/util/bool_flag.go deleted file mode 100644 index 768fc30350b..00000000000 --- a/pkg/util/bool_flag.go +++ /dev/null @@ -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" -} diff --git a/pkg/util/cache.go b/pkg/util/cache/cache.go similarity index 99% rename from pkg/util/cache.go rename to pkg/util/cache/cache.go index 47e30ca31d0..1d4cb923cec 100644 --- a/pkg/util/cache.go +++ b/pkg/util/cache/cache.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package util +package cache import ( "sync" diff --git a/pkg/util/cache_test.go b/pkg/util/cache/cache_test.go similarity index 99% rename from pkg/util/cache_test.go rename to pkg/util/cache/cache_test.go index a54f9e60981..8a86a72a503 100644 --- a/pkg/util/cache_test.go +++ b/pkg/util/cache/cache_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package util +package cache import ( "testing" diff --git a/pkg/util/configuration_map.go b/pkg/util/config/configuration_map.go similarity index 98% rename from pkg/util/configuration_map.go rename to pkg/util/config/configuration_map.go index cf2b326a908..e7ad4fadb3d 100644 --- a/pkg/util/configuration_map.go +++ b/pkg/util/config/configuration_map.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package util +package config import ( "fmt" diff --git a/pkg/util/flag/tristate.go b/pkg/util/flag/tristate.go new file mode 100644 index 00000000000..a9359695f5a --- /dev/null +++ b/pkg/util/flag/tristate.go @@ -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 + } +}