Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
7fbdcf88
Commit
7fbdcf88
authored
Oct 24, 2018
by
Jay Lim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kube-apiserver: fix missing global flags for --help
Signed-off-by:
Jay Lim
<
jay@imjching.com
>
parent
a19bf332
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
117 additions
and
9 deletions
+117
-9
BUILD
cmd/kube-apiserver/BUILD
+0
-2
apiserver.go
cmd/kube-apiserver/apiserver.go
+0
-6
BUILD
cmd/kube-apiserver/app/BUILD
+1
-0
BUILD
cmd/kube-apiserver/app/options/BUILD
+10
-1
globalflags.go
cmd/kube-apiserver/app/options/globalflags.go
+41
-0
globalflags_test.go
cmd/kube-apiserver/app/options/globalflags_test.go
+61
-0
server.go
cmd/kube-apiserver/app/server.go
+4
-0
No files found.
cmd/kube-apiserver/BUILD
View file @
7fbdcf88
...
...
@@ -23,9 +23,7 @@ go_library(
"//pkg/client/metrics/prometheus:go_default_library",
"//pkg/version/prometheus:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/server:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/flag:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/logs:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library",
],
)
...
...
cmd/kube-apiserver/apiserver.go
View file @
7fbdcf88
...
...
@@ -19,16 +19,12 @@ limitations under the License.
package
main
import
(
goflag
"flag"
"fmt"
"math/rand"
"os"
"time"
"github.com/spf13/pflag"
"k8s.io/apiserver/pkg/server"
utilflag
"k8s.io/apiserver/pkg/util/flag"
"k8s.io/apiserver/pkg/util/logs"
"k8s.io/kubernetes/cmd/kube-apiserver/app"
_
"k8s.io/kubernetes/pkg/client/metrics/prometheus"
// for client metric registration
...
...
@@ -43,8 +39,6 @@ func main() {
// TODO: once we switch everything over to Cobra commands, we can go back to calling
// utilflag.InitFlags() (by removing its pflag.Parse() call). For now, we have to set the
// normalize func and add the go flag set by hand.
pflag
.
CommandLine
.
SetNormalizeFunc
(
utilflag
.
WordSepNormalizeFunc
)
pflag
.
CommandLine
.
AddGoFlagSet
(
goflag
.
CommandLine
)
// utilflag.InitFlags()
logs
.
InitLogs
()
defer
logs
.
FlushLogs
()
...
...
cmd/kube-apiserver/app/BUILD
View file @
7fbdcf88
...
...
@@ -57,6 +57,7 @@ go_library(
"//staging/src/k8s.io/apiserver/pkg/storage/etcd3/preflight:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/flag:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/globalflag:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/webhook:go_default_library",
"//staging/src/k8s.io/client-go/informers:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
...
...
cmd/kube-apiserver/app/options/BUILD
View file @
7fbdcf88
...
...
@@ -9,6 +9,7 @@ load(
go_library(
name = "go_default_library",
srcs = [
"globalflags.go",
"options.go",
"validation.go",
],
...
...
@@ -16,6 +17,7 @@ go_library(
deps = [
"//pkg/api/legacyscheme:go_default_library",
"//pkg/apis/core:go_default_library",
"//pkg/cloudprovider/providers:go_default_library",
"//pkg/features:go_default_library",
"//pkg/kubeapiserver/options:go_default_library",
"//pkg/kubelet/client:go_default_library",
...
...
@@ -24,17 +26,23 @@ go_library(
"//pkg/serviceaccount:go_default_library",
"//staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/net:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/admission:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/server/options:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/storage/storagebackend:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/flag:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/globalflag:go_default_library",
"//staging/src/k8s.io/kube-aggregator/pkg/apiserver/scheme:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = ["options_test.go"],
srcs = [
"globalflags_test.go",
"options_test.go",
],
embed = [":go_default_library"],
deps = [
"//pkg/api/legacyscheme:go_default_library",
...
...
@@ -46,6 +54,7 @@ go_test(
"//staging/src/k8s.io/apiserver/pkg/server/options:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/storage/storagebackend:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/flag:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/globalflag:go_default_library",
"//staging/src/k8s.io/apiserver/plugin/pkg/audit/buffered:go_default_library",
"//staging/src/k8s.io/apiserver/plugin/pkg/audit/truncate:go_default_library",
"//staging/src/k8s.io/client-go/rest:go_default_library",
...
...
cmd/kube-apiserver/app/options/globalflags.go
0 → 100644
View file @
7fbdcf88
/*
Copyright 2018 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
options
import
(
"github.com/spf13/pflag"
"k8s.io/apiserver/pkg/util/globalflag"
// ensure libs have a chance to globally register their flags
_
"k8s.io/apiserver/pkg/admission"
_
"k8s.io/kubernetes/pkg/cloudprovider/providers"
)
// AddCustomGlobalFlags explicitly registers flags that internal packages register
// against the global flagsets from "flag". We do this in order to prevent
// unwanted flags from leaking into the kube-apiserver's flagset.
func
AddCustomGlobalFlags
(
fs
*
pflag
.
FlagSet
)
{
// Lookup flags in global flag set and re-register the values with our flagset.
// Adds flags from k8s.io/kubernetes/pkg/cloudprovider/providers.
globalflag
.
Register
(
fs
,
"cloud-provider-gce-lb-src-cidrs"
)
// Adds flags from k8s.io/apiserver/pkg/admission.
globalflag
.
Register
(
fs
,
"default-not-ready-toleration-seconds"
)
globalflag
.
Register
(
fs
,
"default-unreachable-toleration-seconds"
)
}
cmd/kube-apiserver/app/options/globalflags_test.go
0 → 100644
View file @
7fbdcf88
/*
Copyright 2018 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
options
import
(
"flag"
"reflect"
"sort"
"strings"
"testing"
"github.com/spf13/pflag"
apiserverflag
"k8s.io/apiserver/pkg/util/flag"
"k8s.io/apiserver/pkg/util/globalflag"
)
func
TestAddCustomGlobalFlags
(
t
*
testing
.
T
)
{
namedFlagSets
:=
&
apiserverflag
.
NamedFlagSets
{}
// Note that we will register all flags (including klog flags) into the same
// flag set. This allows us to test against all global flags from
// flags.CommandLine.
nfs
:=
namedFlagSets
.
FlagSet
(
"test"
)
globalflag
.
AddGlobalFlags
(
nfs
,
"test-cmd"
)
AddCustomGlobalFlags
(
nfs
)
actualFlag
:=
[]
string
{}
nfs
.
VisitAll
(
func
(
flag
*
pflag
.
Flag
)
{
actualFlag
=
append
(
actualFlag
,
flag
.
Name
)
})
// Get all flags from flags.CommandLine, except flag `test.*`.
wantedFlag
:=
[]
string
{
"help"
}
pflag
.
CommandLine
.
SetNormalizeFunc
(
apiserverflag
.
WordSepNormalizeFunc
)
pflag
.
CommandLine
.
AddGoFlagSet
(
flag
.
CommandLine
)
pflag
.
VisitAll
(
func
(
flag
*
pflag
.
Flag
)
{
if
!
strings
.
Contains
(
flag
.
Name
,
"test."
)
{
wantedFlag
=
append
(
wantedFlag
,
flag
.
Name
)
}
})
sort
.
Strings
(
wantedFlag
)
if
!
reflect
.
DeepEqual
(
wantedFlag
,
actualFlag
)
{
t
.
Errorf
(
"[Default]: expected %+v, got %+v"
,
wantedFlag
,
actualFlag
)
}
}
cmd/kube-apiserver/app/server.go
View file @
7fbdcf88
...
...
@@ -50,6 +50,7 @@ import (
serverstorage
"k8s.io/apiserver/pkg/server/storage"
"k8s.io/apiserver/pkg/storage/etcd3/preflight"
apiserverflag
"k8s.io/apiserver/pkg/util/flag"
"k8s.io/apiserver/pkg/util/globalflag"
"k8s.io/apiserver/pkg/util/webhook"
clientgoinformers
"k8s.io/client-go/informers"
clientgoclientset
"k8s.io/client-go/kubernetes"
...
...
@@ -117,6 +118,9 @@ cluster's shared state through which all other components interact.`,
fs
:=
cmd
.
Flags
()
namedFlagSets
:=
s
.
Flags
()
verflag
.
AddFlags
(
namedFlagSets
.
FlagSet
(
"global"
))
globalflag
.
AddGlobalFlags
(
namedFlagSets
.
FlagSet
(
"global"
),
cmd
.
Name
())
options
.
AddCustomGlobalFlags
(
namedFlagSets
.
FlagSet
(
"generic"
))
for
_
,
f
:=
range
namedFlagSets
.
FlagSets
{
fs
.
AddFlagSet
(
f
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment