@@ -14,7 +14,6 @@ import (
1414 apiserveroptions "k8s.io/apiserver/pkg/server/options"
1515 "k8s.io/apiserver/pkg/util/term"
1616 "k8s.io/apiserver/plugin/pkg/authenticator/token/oidc"
17- "k8s.io/cli-runtime/pkg/genericclioptions"
1817 "k8s.io/client-go/rest"
1918 cliflag "k8s.io/component-base/cli/flag"
2019 "k8s.io/component-base/cli/globalflag"
@@ -47,7 +46,7 @@ func NewRunCommand(stopCh <-chan struct{}) *cobra.Command {
4746
4847 kopOptions := new (options.KubeOIDCProxyOptions )
4948
50- clientConfigFlags := genericclioptions . NewConfigFlags ( true )
49+ clientConfigOptions := options . NewClientExtraFlags ( )
5150
5251 healthCheck := probe .New (strconv .Itoa (readinessProbePort ))
5352
@@ -56,6 +55,8 @@ func NewRunCommand(stopCh <-chan struct{}) *cobra.Command {
5655 Use : "kube-oidc-proxy" ,
5756 Long : "kube-oidc-proxy is a reverse proxy to authenticate users to Kubernetes API servers with Open ID Connect Authentication." ,
5857 RunE : func (cmd * cobra.Command , args []string ) error {
58+ var err error
59+
5960 if cmd .Flag ("version" ).Value .String () == "true" {
6061 version .PrintVersionAndExit ()
6162 }
@@ -64,16 +65,26 @@ func NewRunCommand(stopCh <-chan struct{}) *cobra.Command {
6465 return err
6566 }
6667
68+ if err := clientConfigOptions .Validate (cmd ); err != nil {
69+ return err
70+ }
71+
6772 if ssoptionsWithLB .SecureServingOptions .BindPort == readinessProbePort {
6873 return errors .New ("unable to securely serve on port 8080, used by readiness prob" )
6974 }
7075
71- // client rest config
72- restConfig , err := rest .InClusterConfig ()
73- if err != nil {
76+ var restConfig * rest.Config
77+ if clientConfigOptions .InClusterConfig {
78+ // In cluster config
79+ restConfig , err = rest .InClusterConfig ()
80+ if err != nil {
81+ return err
82+ }
83+
84+ } else {
7485
75- // fall back to cli flags if in cluster fails
76- restConfig , err = clientConfigFlags .ToRESTConfig ()
86+ // CLI flags if in cluster fails
87+ restConfig , err = clientConfigOptions .ToRESTConfig ()
7788 if err != nil {
7889 return err
7990 }
@@ -147,10 +158,10 @@ func NewRunCommand(stopCh <-chan struct{}) *cobra.Command {
147158
148159 ssoptionsWithLB .AddFlags (namedFlagSets .FlagSet ("secure serving" ))
149160
150- clientConfigFlags .CacheDir = nil
151- clientConfigFlags .Impersonate = nil
152- clientConfigFlags .ImpersonateGroup = nil
153- clientConfigFlags .AddFlags (namedFlagSets .FlagSet ("client" ))
161+ clientConfigOptions .CacheDir = nil
162+ clientConfigOptions .Impersonate = nil
163+ clientConfigOptions .ImpersonateGroup = nil
164+ clientConfigOptions .AddFlags (namedFlagSets .FlagSet ("client" ))
154165
155166 globalflag .AddGlobalFlags (namedFlagSets .FlagSet ("misc" ), cmd .Name ())
156167 namedFlagSets .FlagSet ("misc" ).Bool ("version" ,
0 commit comments