Skip to content

Commit

Permalink
cmd/kube-rbac-proxy/app: finalize creation of options and proxy confi…
Browse files Browse the repository at this point in the history
…g within Complete()
  • Loading branch information
liouk committed May 31, 2023
1 parent 71da752 commit b410b96
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions cmd/kube-rbac-proxy/app/kube-rbac-proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ that can perform RBAC authorization against the Kubernetes API using SubjectAcce
k8sapiflag.PrintFlags(fs)

// set default options
completedOptions, err := Complete(o)
completedOptions, proxyCfg, err := Complete(o)
if err != nil {
return err
}
Expand All @@ -90,7 +90,7 @@ that can perform RBAC authorization against the Kubernetes API using SubjectAcce
return utilerrors.NewAggregate(errs)
}

return Run(completedOptions)
return Run(proxyCfg)
},
Args: cobra.NoArgs,
}
Expand Down Expand Up @@ -125,17 +125,18 @@ func (o *completedProxyRunOptions) Validate() []error {
return errs
}

// Complete sets defaults for the ProxyRunOptions.
// Complete sets defaults for the ProxyRunOptions and creates a server.KubeRBACProxyConfig
// based on the completed options.
// Should be called after the flags are parsed.
func Complete(o *options.ProxyRunOptions) (*completedProxyRunOptions, error) {
func Complete(o *options.ProxyRunOptions) (*completedProxyRunOptions, *server.KubeRBACProxyConfig, error) {

hostname, err := os.Hostname()
if err != nil {
return nil, fmt.Errorf("failed to retrieve hostname for self-signed cert: %w", err)
return nil, nil, fmt.Errorf("failed to retrieve hostname for self-signed cert: %w", err)
}

if err := o.SecureServing.MaybeDefaultWithSelfSignedCerts(hostname, nil, nil); err != nil {
return nil, fmt.Errorf("error creating self-signed certificates: %v", err)
return nil, nil, fmt.Errorf("error creating self-signed certificates: %v", err)
}

if o.ProxyOptions.ProxyEndpointsPort != 0 {
Expand All @@ -149,14 +150,15 @@ func Complete(o *options.ProxyRunOptions) (*completedProxyRunOptions, error) {
ProxyRunOptions: o,
}

return completed, nil
}

func Run(opts *completedProxyRunOptions) error {
cfg, err := createKubeRBACProxyConfig(opts)
proxyCfg, err := createKubeRBACProxyConfig(completed)
if err != nil {
return err
return nil, nil, err
}

return completed, proxyCfg, nil
}

func Run(cfg *server.KubeRBACProxyConfig) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down

0 comments on commit b410b96

Please sign in to comment.