mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 18:53:35 +00:00
Fresh dep ensure
This commit is contained in:
11
vendor/k8s.io/kubernetes/pkg/util/flag/BUILD
generated
vendored
11
vendor/k8s.io/kubernetes/pkg/util/flag/BUILD
generated
vendored
@ -3,6 +3,7 @@ package(default_visibility = ["//visibility:public"])
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_library(
|
||||
@ -10,8 +11,9 @@ go_library(
|
||||
srcs = ["flags.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/util/flag",
|
||||
deps = [
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/net:go_default_library",
|
||||
"//vendor/github.com/spf13/pflag:go_default_library",
|
||||
"//vendor/k8s.io/klog:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@ -27,3 +29,10 @@ filegroup(
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["flags_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = ["//vendor/github.com/spf13/pflag:go_default_library"],
|
||||
)
|
||||
|
136
vendor/k8s.io/kubernetes/pkg/util/flag/flags.go
generated
vendored
136
vendor/k8s.io/kubernetes/pkg/util/flag/flags.go
generated
vendored
@ -17,13 +17,145 @@ limitations under the License.
|
||||
package flag
|
||||
|
||||
import (
|
||||
"github.com/golang/glog"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/klog"
|
||||
|
||||
utilnet "k8s.io/apimachinery/pkg/util/net"
|
||||
)
|
||||
|
||||
// PrintFlags logs the flags in the flagset
|
||||
func PrintFlags(flags *pflag.FlagSet) {
|
||||
flags.VisitAll(func(flag *pflag.Flag) {
|
||||
glog.V(1).Infof("FLAG: --%s=%q", flag.Name, flag.Value)
|
||||
klog.V(1).Infof("FLAG: --%s=%q", flag.Name, flag.Value)
|
||||
})
|
||||
}
|
||||
|
||||
// TODO(mikedanese): remove these flag wrapper types when we remove command line flags
|
||||
|
||||
var (
|
||||
_ pflag.Value = &IPVar{}
|
||||
_ pflag.Value = &IPPortVar{}
|
||||
_ pflag.Value = &PortRangeVar{}
|
||||
)
|
||||
|
||||
// IPVar is used for validating a command line option that represents an IP. It implements the pflag.Value interface
|
||||
type IPVar struct {
|
||||
Val *string
|
||||
}
|
||||
|
||||
// Set sets the flag value
|
||||
func (v IPVar) Set(s string) error {
|
||||
if len(s) == 0 {
|
||||
v.Val = nil
|
||||
return nil
|
||||
}
|
||||
if net.ParseIP(s) == nil {
|
||||
return fmt.Errorf("%q is not a valid IP address", s)
|
||||
}
|
||||
if v.Val == nil {
|
||||
// it's okay to panic here since this is programmer error
|
||||
panic("the string pointer passed into IPVar should not be nil")
|
||||
}
|
||||
*v.Val = s
|
||||
return nil
|
||||
}
|
||||
|
||||
// String returns the flag value
|
||||
func (v IPVar) String() string {
|
||||
if v.Val == nil {
|
||||
return ""
|
||||
}
|
||||
return *v.Val
|
||||
}
|
||||
|
||||
// Type gets the flag type
|
||||
func (v IPVar) Type() string {
|
||||
return "ip"
|
||||
}
|
||||
|
||||
// IPPortVar is used for validating a command line option that represents an IP and a port. It implements the pflag.Value interface
|
||||
type IPPortVar struct {
|
||||
Val *string
|
||||
}
|
||||
|
||||
// Set sets the flag value
|
||||
func (v IPPortVar) Set(s string) error {
|
||||
if len(s) == 0 {
|
||||
v.Val = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
if v.Val == nil {
|
||||
// it's okay to panic here since this is programmer error
|
||||
panic("the string pointer passed into IPPortVar should not be nil")
|
||||
}
|
||||
|
||||
// Both IP and IP:port are valid.
|
||||
// Attempt to parse into IP first.
|
||||
if net.ParseIP(s) != nil {
|
||||
*v.Val = s
|
||||
return nil
|
||||
}
|
||||
|
||||
// Can not parse into IP, now assume IP:port.
|
||||
host, port, err := net.SplitHostPort(s)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%q is not in a valid format (ip or ip:port): %v", s, err)
|
||||
}
|
||||
if net.ParseIP(host) == nil {
|
||||
return fmt.Errorf("%q is not a valid IP address", host)
|
||||
}
|
||||
if _, err := strconv.Atoi(port); err != nil {
|
||||
return fmt.Errorf("%q is not a valid number", port)
|
||||
}
|
||||
*v.Val = s
|
||||
return nil
|
||||
}
|
||||
|
||||
// String returns the flag value
|
||||
func (v IPPortVar) String() string {
|
||||
if v.Val == nil {
|
||||
return ""
|
||||
}
|
||||
return *v.Val
|
||||
}
|
||||
|
||||
// Type gets the flag type
|
||||
func (v IPPortVar) Type() string {
|
||||
return "ipport"
|
||||
}
|
||||
|
||||
// PortRangeVar is used for validating a command line option that represents a port range. It implements the pflag.Value interface
|
||||
type PortRangeVar struct {
|
||||
Val *string
|
||||
}
|
||||
|
||||
// Set sets the flag value
|
||||
func (v PortRangeVar) Set(s string) error {
|
||||
if _, err := utilnet.ParsePortRange(s); err != nil {
|
||||
return fmt.Errorf("%q is not a valid port range: %v", s, err)
|
||||
}
|
||||
if v.Val == nil {
|
||||
// it's okay to panic here since this is programmer error
|
||||
panic("the string pointer passed into PortRangeVar should not be nil")
|
||||
}
|
||||
*v.Val = s
|
||||
return nil
|
||||
}
|
||||
|
||||
// String returns the flag value
|
||||
func (v PortRangeVar) String() string {
|
||||
if v.Val == nil {
|
||||
return ""
|
||||
}
|
||||
return *v.Val
|
||||
}
|
||||
|
||||
// Type gets the flag type
|
||||
func (v PortRangeVar) Type() string {
|
||||
return "port-range"
|
||||
}
|
||||
|
165
vendor/k8s.io/kubernetes/pkg/util/flag/flags_test.go
generated
vendored
Normal file
165
vendor/k8s.io/kubernetes/pkg/util/flag/flags_test.go
generated
vendored
Normal file
@ -0,0 +1,165 @@
|
||||
/*
|
||||
Copyright 2016 The Kubernetes 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 flag
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
func TestIPVar(t *testing.T) {
|
||||
defaultIP := "0.0.0.0"
|
||||
testCases := []struct {
|
||||
argc string
|
||||
expectErr bool
|
||||
expectVal string
|
||||
}{
|
||||
|
||||
{
|
||||
argc: "blah --ip=1.2.3.4",
|
||||
expectVal: "1.2.3.4",
|
||||
},
|
||||
{
|
||||
argc: "blah --ip=1.2.3.4a",
|
||||
expectErr: true,
|
||||
expectVal: defaultIP,
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
fs := pflag.NewFlagSet("blah", pflag.PanicOnError)
|
||||
ip := defaultIP
|
||||
fs.Var(IPVar{&ip}, "ip", "the ip")
|
||||
|
||||
var err error
|
||||
func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = r.(error)
|
||||
}
|
||||
}()
|
||||
fs.Parse(strings.Split(tc.argc, " "))
|
||||
}()
|
||||
|
||||
if tc.expectErr && err == nil {
|
||||
t.Errorf("did not observe an expected error")
|
||||
continue
|
||||
}
|
||||
if !tc.expectErr && err != nil {
|
||||
t.Errorf("observed an unexpected error: %v", err)
|
||||
continue
|
||||
}
|
||||
if tc.expectVal != ip {
|
||||
t.Errorf("unexpected ip: expected %q, saw %q", tc.expectVal, ip)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPPortVar(t *testing.T) {
|
||||
defaultIPPort := "0.0.0.0:8080"
|
||||
testCases := []struct {
|
||||
desc string
|
||||
argc string
|
||||
expectErr bool
|
||||
expectVal string
|
||||
}{
|
||||
|
||||
{
|
||||
desc: "valid ipv4 1",
|
||||
argc: "blah --ipport=0.0.0.0",
|
||||
expectVal: "0.0.0.0",
|
||||
},
|
||||
{
|
||||
desc: "valid ipv4 2",
|
||||
argc: "blah --ipport=127.0.0.1",
|
||||
expectVal: "127.0.0.1",
|
||||
},
|
||||
|
||||
{
|
||||
desc: "invalid IP",
|
||||
argc: "blah --ipport=invalidip",
|
||||
expectErr: true,
|
||||
expectVal: defaultIPPort,
|
||||
},
|
||||
{
|
||||
desc: "valid ipv4 with port",
|
||||
argc: "blah --ipport=0.0.0.0:8080",
|
||||
expectVal: "0.0.0.0:8080",
|
||||
},
|
||||
{
|
||||
desc: "invalid ipv4 with invalid port",
|
||||
argc: "blah --ipport=0.0.0.0:invalidport",
|
||||
expectErr: true,
|
||||
expectVal: defaultIPPort,
|
||||
},
|
||||
{
|
||||
desc: "invalid IP with port",
|
||||
argc: "blah --ipport=invalidip:8080",
|
||||
expectErr: true,
|
||||
expectVal: defaultIPPort,
|
||||
},
|
||||
{
|
||||
desc: "valid ipv6 1",
|
||||
argc: "blah --ipport=::1",
|
||||
expectVal: "::1",
|
||||
},
|
||||
{
|
||||
desc: "valid ipv6 2",
|
||||
argc: "blah --ipport=::",
|
||||
expectVal: "::",
|
||||
},
|
||||
{
|
||||
desc: "valid ipv6 with port",
|
||||
argc: "blah --ipport=[::1]:8080",
|
||||
expectVal: "[::1]:8080",
|
||||
},
|
||||
{
|
||||
desc: "invalid ipv6 with port without bracket",
|
||||
argc: "blah --ipport=fd00:f00d:600d:f00d:8080",
|
||||
expectErr: true,
|
||||
expectVal: defaultIPPort,
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
fs := pflag.NewFlagSet("blah", pflag.PanicOnError)
|
||||
ipport := defaultIPPort
|
||||
fs.Var(IPPortVar{&ipport}, "ipport", "the ip:port")
|
||||
|
||||
var err error
|
||||
func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = r.(error)
|
||||
}
|
||||
}()
|
||||
fs.Parse(strings.Split(tc.argc, " "))
|
||||
}()
|
||||
|
||||
if tc.expectErr && err == nil {
|
||||
t.Errorf("%q: Did not observe an expected error", tc.desc)
|
||||
continue
|
||||
}
|
||||
if !tc.expectErr && err != nil {
|
||||
t.Errorf("%q: Observed an unexpected error: %v", tc.desc, err)
|
||||
continue
|
||||
}
|
||||
if tc.expectVal != ipport {
|
||||
t.Errorf("%q: Unexpected ipport: expected %q, saw %q", tc.desc, tc.expectVal, ipport)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user