Skip to content

Commit

Permalink
fix debug panic
Browse files Browse the repository at this point in the history
  • Loading branch information
juanvallejo committed Aug 6, 2018
1 parent 5465639 commit 0f0f2bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
14 changes: 9 additions & 5 deletions pkg/oc/cli/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ type DebugOptions struct {
AppsClient appsv1client.AppsV1Interface
ImageClient imagev1client.ImageV1Interface

Printer printers.ResourcePrinter
LogsForObject polymorphichelpers.LogsForObjectFunc
Printer printers.ResourcePrinter
LogsForObject polymorphichelpers.LogsForObjectFunc
RESTClientGetter genericclioptions.RESTClientGetter

NoStdin bool
ForceTTY bool
Expand Down Expand Up @@ -211,6 +212,7 @@ func (o *DebugOptions) Complete(cmd *cobra.Command, f kcmdutil.Factory, args []s
return kcmdutil.UsageErrorf(cmd, "all resources must be specified before environment changes: %s", strings.Join(args, " "))
}
o.Resources = resources
o.RESTClientGetter = f

switch {
case o.ForceTTY && o.NoStdin:
Expand Down Expand Up @@ -444,12 +446,14 @@ func (o *DebugOptions) RunDebug() error {
case err == kubectl.ErrPodCompleted, err == kubectl.ErrContainerTerminated, !o.Attach.Stdin:
return kcmd.LogsOptions{
Object: pod,
Options: &kapi.PodLogOptions{
Options: &corev1.PodLogOptions{
Container: o.Attach.ContainerName,
Follow: true,
},
IOStreams: o.IOStreams,
LogsForObject: o.LogsForObject,
RESTClientGetter: o.RESTClientGetter,
ConsumeRequestFn: kcmd.DefaultConsumeRequestFn,
IOStreams: o.IOStreams,
LogsForObject: o.LogsForObject,
}.RunLogs()
case err != nil:
return err
Expand Down
19 changes: 13 additions & 6 deletions pkg/oc/cli/newapp/newapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,11 @@ type ObjectGeneratorOptions struct {
}

type AppOptions struct {
genericclioptions.IOStreams
*ObjectGeneratorOptions

RESTClientGetter genericclioptions.RESTClientGetter

genericclioptions.IOStreams
}

type versionedPrintObj struct {
Expand Down Expand Up @@ -367,6 +370,8 @@ func NewCmdNewApplication(name, baseName string, f kcmdutil.Factory, streams gen

// Complete sets any default behavior for the command
func (o *AppOptions) Complete(baseName, commandName string, f kcmdutil.Factory, c *cobra.Command, args []string) error {
o.RESTClientGetter = f

cmdutil.WarnAboutCommaSeparation(o.ErrOut, o.ObjectGeneratorOptions.Config.TemplateParameters, "--param")
err := o.ObjectGeneratorOptions.Complete(baseName, commandName, f, c, args)
if err != nil {
Expand Down Expand Up @@ -510,7 +515,7 @@ func (o *AppOptions) RunNewApp() error {

switch {
case len(installing) == 1:
return followInstallation(config, installing[0], o.LogsForObject)
return followInstallation(config, o.RESTClientGetter, installing[0], o.LogsForObject)
case len(installing) > 1:
for i := range installing {
fmt.Fprintf(out, "%sTrack installation of %s with '%s logs %s'.\n", indent, installing[i].Name, o.BaseName, installing[i].Name)
Expand Down Expand Up @@ -554,7 +559,7 @@ func getServices(items []runtime.Object) []*corev1.Service {
return svc
}

func followInstallation(config *newcmd.AppConfig, pod *corev1.Pod, logsForObjectFn polymorphichelpers.LogsForObjectFunc) error {
func followInstallation(config *newcmd.AppConfig, clientGetter genericclioptions.RESTClientGetter, pod *corev1.Pod, logsForObjectFn polymorphichelpers.LogsForObjectFunc) error {
fmt.Fprintf(config.Out, "--> Installing ...\n")

// we cannot retrieve logs until the pod is out of pending
Expand All @@ -567,12 +572,14 @@ func followInstallation(config *newcmd.AppConfig, pod *corev1.Pod, logsForObject
opts := &kcmd.LogsOptions{
Namespace: pod.Namespace,
ResourceArg: pod.Name,
Options: &kapi.PodLogOptions{
Options: &corev1.PodLogOptions{
Follow: true,
Container: pod.Spec.Containers[0].Name,
},
LogsForObject: logsForObjectFn,
IOStreams: genericclioptions.IOStreams{Out: config.Out},
RESTClientGetter: clientGetter,
ConsumeRequestFn: kcmd.DefaultConsumeRequestFn,
LogsForObject: logsForObjectFn,
IOStreams: genericclioptions.IOStreams{Out: config.Out},
}
logErr := opts.RunLogs()

Expand Down

0 comments on commit 0f0f2bf

Please sign in to comment.