Skip to content

Commit 92de18b

Browse files
Merge pull request #18546 from deads2k/up-07-routerregistry
Automatic merge from submit-queue (batch tested with PRs 18437, 18546, 18550, 18579). make oadm router and registry resiliant to missing client `oc adm router --dry-run -o yaml` (and registry) shouldn't require an apiserver connection. This makes it tolerant for cluster up
2 parents a70f803 + a509e41 commit 92de18b

File tree

4 files changed

+68
-39
lines changed

4 files changed

+68
-39
lines changed

contrib/completions/bash/oc

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/completions/zsh/oc

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/oc/admin/registry/registry.go

+25-15
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ type RegistryConfig struct {
119119

120120
ClusterIP string
121121

122+
Local bool
122123
// TODO: accept environment values.
123124
}
124125

@@ -191,6 +192,7 @@ func NewCmdRegistry(f *clientcmd.Factory, parentName, name string, out, errout i
191192
cmd.Flags().StringVar(&cfg.FSGroup, "fs-group", "", "Specify fsGroup which is an ID that grants group access to registry block storage")
192193
cmd.Flags().BoolVar(&cfg.DaemonSet, "daemonset", cfg.DaemonSet, "If true, use a daemonset instead of a deployment config.")
193194
cmd.Flags().BoolVar(&cfg.EnforceQuota, "enforce-quota", cfg.EnforceQuota, "If true, the registry will refuse to write blobs if they exceed quota limits")
195+
cmd.Flags().BoolVar(&cfg.Local, "local", cfg.Local, "If true, do not contact the apiserver")
194196

195197
cfg.Action.BindForOutput(cmd.Flags())
196198
cmd.Flags().String("output-version", "", "The preferred API versions of the output objects")
@@ -259,11 +261,17 @@ func (opts *RegistryOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command,
259261
return fmt.Errorf("error getting namespace: %v", nsErr)
260262
}
261263

262-
kClient, kClientErr := f.ClientSet()
263-
if kClientErr != nil {
264-
return fmt.Errorf("error getting client: %v", kClientErr)
264+
if !opts.Config.Local {
265+
kClient, kClientErr := f.ClientSet()
266+
if kClientErr != nil {
267+
return fmt.Errorf("error getting client: %v", kClientErr)
268+
}
269+
opts.serviceClient = kClient.Core()
270+
}
271+
272+
if opts.Config.Local && !opts.Config.Action.DryRun {
273+
return fmt.Errorf("--local cannot be specified without --dry-run")
265274
}
266-
opts.serviceClient = kClient.Core()
267275

268276
opts.Config.Action.Bulk.Mapper = clientcmd.ResourceMapper(f)
269277
opts.Config.Action.Out, opts.Config.Action.ErrOut = out, errout
@@ -283,19 +291,21 @@ func (opts *RegistryOptions) RunCmdRegistry() error {
283291

284292
output := opts.Config.Action.ShouldPrint()
285293
generate := output
286-
service, err := opts.serviceClient.Services(opts.namespace).Get(name, metav1.GetOptions{})
287-
if err != nil {
288-
if !generate {
289-
if !errors.IsNotFound(err) {
290-
return fmt.Errorf("can't check for existing docker-registry %q: %v", name, err)
291-
}
292-
if opts.Config.Action.DryRun {
293-
return fmt.Errorf("Docker registry %q service does not exist", name)
294+
if !opts.Config.Local {
295+
service, err := opts.serviceClient.Services(opts.namespace).Get(name, metav1.GetOptions{})
296+
if err != nil {
297+
if !generate {
298+
if !errors.IsNotFound(err) {
299+
return fmt.Errorf("can't check for existing docker-registry %q: %v", name, err)
300+
}
301+
if opts.Config.Action.DryRun {
302+
return fmt.Errorf("Docker registry %q service does not exist", name)
303+
}
304+
generate = true
294305
}
295-
generate = true
306+
} else {
307+
clusterIP = service.Spec.ClusterIP
296308
}
297-
} else {
298-
clusterIP = service.Spec.ClusterIP
299309
}
300310

301311
if !generate {

pkg/oc/admin/router/router.go

+35-24
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ type RouterConfig struct {
233233

234234
// Strict SNI (do not use default cert)
235235
StrictSNI bool
236+
237+
Local bool
236238
}
237239

238240
const (
@@ -314,6 +316,7 @@ func NewCmdRouter(f *clientcmd.Factory, parentName, name string, out, errout io.
314316
cmd.Flags().StringVar(&cfg.MaxConnections, "max-connections", cfg.MaxConnections, "Specifies the maximum number of concurrent connections. Not supported for F5.")
315317
cmd.Flags().StringVar(&cfg.Ciphers, "ciphers", cfg.Ciphers, "Specifies the cipher suites to use. You can choose a predefined cipher set ('modern', 'intermediate', or 'old') or specify exact cipher suites by passing a : separated list. Not supported for F5.")
316318
cmd.Flags().BoolVar(&cfg.StrictSNI, "strict-sni", cfg.StrictSNI, "Use strict-sni bind processing (do not use default cert). Not supported for F5.")
319+
cmd.Flags().BoolVar(&cfg.Local, "local", cfg.Local, "If true, do not contact the apiserver")
317320

318321
cfg.Action.BindForOutput(cmd.Flags())
319322
cmd.Flags().String("output-version", "", "The preferred API versions of the output objects")
@@ -498,6 +501,10 @@ func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out, errout io.Write
498501
default:
499502
return kcmdutil.UsageErrorf(cmd, "You may pass zero or one arguments to provide a name for the router")
500503
}
504+
if cfg.Local && !cfg.Action.DryRun {
505+
return fmt.Errorf("--local cannot be specified without --dry-run")
506+
}
507+
501508
name := cfg.Name
502509

503510
var defaultOutputErr error
@@ -573,10 +580,6 @@ func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out, errout io.Write
573580
if err != nil {
574581
return fmt.Errorf("error getting client: %v", err)
575582
}
576-
kClient, err := f.ClientSet()
577-
if err != nil {
578-
return fmt.Errorf("error getting client: %v", err)
579-
}
580583

581584
cfg.Action.Bulk.Mapper = clientcmd.ResourceMapper(f)
582585
cfg.Action.Out, cfg.Action.ErrOut = out, errout
@@ -586,19 +589,25 @@ func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out, errout io.Write
586589

587590
output := cfg.Action.ShouldPrint()
588591
generate := output
589-
service, err := kClient.Core().Services(namespace).Get(name, metav1.GetOptions{})
590-
if err != nil {
591-
if !generate {
592-
if !errors.IsNotFound(err) {
593-
return fmt.Errorf("can't check for existing router %q: %v", name, err)
594-
}
595-
if !output && cfg.Action.DryRun {
596-
return fmt.Errorf("Router %q service does not exist", name)
592+
if !cfg.Local {
593+
kClient, err := f.ClientSet()
594+
if err != nil {
595+
return fmt.Errorf("error getting client: %v", err)
596+
}
597+
service, err := kClient.Core().Services(namespace).Get(name, metav1.GetOptions{})
598+
if err != nil {
599+
if !generate {
600+
if !errors.IsNotFound(err) {
601+
return fmt.Errorf("can't check for existing router %q: %v", name, err)
602+
}
603+
if !output && cfg.Action.DryRun {
604+
return fmt.Errorf("Router %q service does not exist", name)
605+
}
606+
generate = true
597607
}
598-
generate = true
608+
} else {
609+
clusterIP = service.Spec.ClusterIP
599610
}
600-
} else {
601-
clusterIP = service.Spec.ClusterIP
602611
}
603612

604613
if !generate {
@@ -610,17 +619,19 @@ func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out, errout io.Write
610619
return fmt.Errorf("you must specify a service account for the router with --service-account")
611620
}
612621

613-
securityClient, err := f.OpenshiftInternalSecurityClient()
614-
if err != nil {
615-
return err
616-
}
617-
if err := validateServiceAccount(securityClient, namespace, cfg.ServiceAccount, cfg.HostNetwork, cfg.HostPorts); err != nil {
618-
err = fmt.Errorf("router could not be created; %v", err)
619-
if !cfg.Action.ShouldPrint() {
622+
if !cfg.Local {
623+
securityClient, err := f.OpenshiftInternalSecurityClient()
624+
if err != nil {
620625
return err
621626
}
622-
fmt.Fprintf(errout, "error: %v\n", err)
623-
defaultOutputErr = kcmdutil.ErrExit
627+
if err := validateServiceAccount(securityClient, namespace, cfg.ServiceAccount, cfg.HostNetwork, cfg.HostPorts); err != nil {
628+
err = fmt.Errorf("router could not be created; %v", err)
629+
if !cfg.Action.ShouldPrint() {
630+
return err
631+
}
632+
fmt.Fprintf(errout, "error: %v\n", err)
633+
defaultOutputErr = kcmdutil.ErrExit
634+
}
624635
}
625636

626637
// create new router

0 commit comments

Comments
 (0)