Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix util pkg contains code of boolflag cache configrationmap #22736

Merged
merged 4 commits into from
Mar 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/kube-apiserver/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down
11 changes: 6 additions & 5 deletions cmd/kubelet/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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%")
Expand Down
5 changes: 3 additions & 2 deletions cmd/kubelet/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/flock"
"k8s.io/kubernetes/pkg/util/io"
Expand Down Expand Up @@ -875,7 +876,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
Expand All @@ -890,7 +891,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) {
Expand Down
8 changes: 4 additions & 4 deletions contrib/completions/bash/kubectl
Original file line number Diff line number Diff line change
Expand Up @@ -2195,7 +2195,7 @@ _kubectl_config_view()
flags_completion=()

flags+=("--flatten")
flags+=("--merge")
flags+=("--merge=")
flags+=("--minify")
flags+=("--no-headers")
flags+=("--output=")
Expand Down Expand Up @@ -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=")
Expand Down Expand Up @@ -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=")
Expand Down
3 changes: 2 additions & 1 deletion pkg/kubectl/cmd/config/create_authinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pkg/kubectl/cmd/config/create_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ 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 {
configAccess ConfigAccess
name string
server util.StringFlag
apiVersion util.StringFlag
insecureSkipTLSVerify util.BoolFlag
insecureSkipTLSVerify flag.Tristate
certificateAuthority util.StringFlag
embedCAData util.BoolFlag
embedCAData flag.Tristate
}

const (
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubectl/cmd/config/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pkg/storage/etcd/etcd_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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),
}
}

Expand All @@ -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() {
Expand Down
65 changes: 0 additions & 65 deletions pkg/util/bool_flag.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/util/cache.go → pkg/util/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package util
package cache

import (
"sync"
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/cache_test.go → pkg/util/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package util
package cache

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package util
package config

import (
"fmt"
Expand Down
83 changes: 83 additions & 0 deletions pkg/util/flag/tristate.go
Original file line number Diff line number Diff line change
@@ -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
}
}