Skip to content

Commit

Permalink
update(pkg/cmd): use kubectl factory for k8s
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Di Donato <[email protected]>
  • Loading branch information
leodido authored and fntlnz committed Oct 30, 2020
1 parent c838f69 commit e30c491
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
6 changes: 3 additions & 3 deletions pkg/cmd/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

"github.com/iovisor/kubectl-trace/pkg/attacher"
"github.com/iovisor/kubectl-trace/pkg/factory"
"github.com/iovisor/kubectl-trace/pkg/meta"
"github.com/iovisor/kubectl-trace/pkg/signals"
"github.com/iovisor/kubectl-trace/pkg/tracejob"
Expand All @@ -15,6 +14,7 @@ import (
batchv1client "k8s.io/client-go/kubernetes/typed/batch/v1"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/rest"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
)

var (
Expand Down Expand Up @@ -50,7 +50,7 @@ func NewAttachOptions(streams genericclioptions.IOStreams) *AttachOptions {
}

// NewAttachCommand provides the attach command wrapping AttachOptions.
func NewAttachCommand(factory factory.Factory, streams genericclioptions.IOStreams) *cobra.Command {
func NewAttachCommand(factory cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
o := NewAttachOptions(streams)

cmd := &cobra.Command{
Expand Down Expand Up @@ -95,7 +95,7 @@ func (o *AttachOptions) Validate(cmd *cobra.Command, args []string) error {
}

// Complete completes the setup of the command.
func (o *AttachOptions) Complete(factory factory.Factory, cmd *cobra.Command, args []string) error {
func (o *AttachOptions) Complete(factory cmdutil.Factory, cmd *cobra.Command, args []string) error {
// Prepare namespace
var err error
o.namespace, _, err = factory.ToRawKubeConfigLoader().Namespace()
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"fmt"

"github.com/iovisor/kubectl-trace/pkg/factory"
"github.com/iovisor/kubectl-trace/pkg/meta"
"github.com/iovisor/kubectl-trace/pkg/tracejob"
"github.com/spf13/cobra"
Expand All @@ -12,6 +11,7 @@ import (
batchv1client "k8s.io/client-go/kubernetes/typed/batch/v1"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/rest"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
)

var (
Expand Down Expand Up @@ -58,7 +58,7 @@ func NewDeleteOptions(streams genericclioptions.IOStreams) *DeleteOptions {
}

// NewDeleteCommand provides the delete command wrapping DeleteOptions.
func NewDeleteCommand(factory factory.Factory, streams genericclioptions.IOStreams) *cobra.Command {
func NewDeleteCommand(factory cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
o := NewDeleteOptions(streams)

cmd := &cobra.Command{
Expand Down Expand Up @@ -102,7 +102,7 @@ func (o *DeleteOptions) Validate(cmd *cobra.Command, args []string) error {
}

// Complete completes the setup of the command.
func (o *DeleteOptions) Complete(factory factory.Factory, cmd *cobra.Command, args []string) error {
func (o *DeleteOptions) Complete(factory cmdutil.Factory, cmd *cobra.Command, args []string) error {
// Prepare namespace
var err error
o.namespace, _, err = factory.ToRawKubeConfigLoader().Namespace()
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"text/tabwriter"
"time"

"github.com/iovisor/kubectl-trace/pkg/factory"
"github.com/iovisor/kubectl-trace/pkg/meta"
"github.com/iovisor/kubectl-trace/pkg/tracejob"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/duration"
cmdutil "k8s.io/kubectl/pkg/cmd/util"

"k8s.io/cli-runtime/pkg/genericclioptions"
batchv1client "k8s.io/client-go/kubernetes/typed/batch/v1"
Expand Down Expand Up @@ -69,7 +69,7 @@ func NewGetOptions(streams genericclioptions.IOStreams) *GetOptions {
}

// NewGetCommand provides the get command wrapping GetOptions.
func NewGetCommand(factory factory.Factory, streams genericclioptions.IOStreams) *cobra.Command {
func NewGetCommand(factory cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
o := NewGetOptions(streams)

cmd := &cobra.Command{
Expand Down Expand Up @@ -114,7 +114,7 @@ func (o *GetOptions) Validate(cmd *cobra.Command, args []string) error {
}

// Complete completes the setup of the command.
func (o *GetOptions) Complete(factory factory.Factory, cmd *cobra.Command, args []string) error {
func (o *GetOptions) Complete(factory cmdutil.Factory, cmd *cobra.Command, args []string) error {
// Prepare namespace
var err error
o.namespace, _, err = factory.ToRawKubeConfigLoader().Namespace()
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"fmt"

"github.com/iovisor/kubectl-trace/pkg/factory"
"github.com/iovisor/kubectl-trace/pkg/logs"
"github.com/iovisor/kubectl-trace/pkg/meta"
"github.com/iovisor/kubectl-trace/pkg/tracejob"
Expand All @@ -13,6 +12,7 @@ import (
batchv1client "k8s.io/client-go/kubernetes/typed/batch/v1"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/rest"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
)

var (
Expand Down Expand Up @@ -54,7 +54,7 @@ func NewLogOptions(streams genericclioptions.IOStreams) *LogOptions {
}

// NewLogCommand provides the log command wrapping LogOptions.
func NewLogCommand(factory factory.Factory, streams genericclioptions.IOStreams) *cobra.Command {
func NewLogCommand(factory cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
o := NewLogOptions(streams)

cmd := &cobra.Command{
Expand Down Expand Up @@ -98,7 +98,7 @@ func (o *LogOptions) Validate(cmd *cobra.Command, args []string) error {
}

// Complete completes the setup of the command.
func (o *LogOptions) Complete(factory factory.Factory, cmd *cobra.Command, args []string) error {
func (o *LogOptions) Complete(factory cmdutil.Factory, cmd *cobra.Command, args []string) error {
// Prepare namespace
var err error
o.namespace, _, err = factory.ToRawKubeConfigLoader().Namespace()
Expand Down
10 changes: 5 additions & 5 deletions pkg/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import (
"io/ioutil"

"github.com/iovisor/kubectl-trace/pkg/attacher"
"github.com/iovisor/kubectl-trace/pkg/factory"
"github.com/iovisor/kubectl-trace/pkg/meta"
"github.com/iovisor/kubectl-trace/pkg/signals"
"github.com/iovisor/kubectl-trace/pkg/tracejob"
"github.com/spf13/cobra"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/kubernetes/scheme"
batchv1client "k8s.io/client-go/kubernetes/typed/batch/v1"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/rest"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
)

var (
Expand Down Expand Up @@ -48,7 +48,7 @@ var (
%[1]s trace run pod/nginx -c nginx -e "tracepoint:syscalls:sys_enter_* { @[probe] = count(); }"
%[1]s trace run pod/nginx nginx -e "tracepoint:syscalls:sys_enter_* { @[probe] = count(); }"
# Run a bpftrace inline program on a pod container with a custom image for the init container responsible to fetch linux headers
# Run a bpftrace inline program on a pod container with a custom image for the init container responsible to fetch linux headers
%[1]s trace run pod/nginx nginx -e "tracepoint:syscalls:sys_enter_* { @[probe] = count(); } --init-imagename=quay.io/custom-init-image-name --fetch-headers"
# Run a bpftrace inline program on a pod container with a custom image for the bpftrace container that will run your program in the cluster
Expand Down Expand Up @@ -104,7 +104,7 @@ func NewRunOptions(streams genericclioptions.IOStreams) *RunOptions {
}

// NewRunCommand provides the run command wrapping RunOptions.
func NewRunCommand(factory factory.Factory, streams genericclioptions.IOStreams) *cobra.Command {
func NewRunCommand(factory cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
o := NewRunOptions(streams)

cmd := &cobra.Command{
Expand Down Expand Up @@ -175,7 +175,7 @@ func (o *RunOptions) Validate(cmd *cobra.Command, args []string) error {
}

// Complete completes the setup of the command.
func (o *RunOptions) Complete(factory factory.Factory, cmd *cobra.Command, args []string) error {
func (o *RunOptions) Complete(factory cmdutil.Factory, cmd *cobra.Command, args []string) error {
// Prepare program
if len(o.program) > 0 {
b, err := ioutil.ReadFile(o.program)
Expand Down
8 changes: 3 additions & 5 deletions pkg/cmd/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"fmt"

"github.com/iovisor/kubectl-trace/pkg/factory"
cmdutil "k8s.io/kubectl/pkg/cmd/util"

"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
Expand Down Expand Up @@ -64,12 +64,10 @@ func NewTraceCommand(streams genericclioptions.IOStreams) *cobra.Command {
flags := cmd.PersistentFlags()
o.configFlags.AddFlags(flags)

matchVersionFlags := factory.NewMatchVersionFlags(o.configFlags)
matchVersionFlags := cmdutil.NewMatchVersionFlags(o.configFlags)
matchVersionFlags.AddFlags(flags)

// flags.AddGoFlagSet(flag.CommandLine) // todo(leodido) > evaluate whether we need this or not

f := factory.NewFactory(matchVersionFlags)
f := cmdutil.NewFactory(matchVersionFlags)

cmd.AddCommand(NewRunCommand(f, streams))
cmd.AddCommand(NewGetCommand(f, streams))
Expand Down

0 comments on commit e30c491

Please sign in to comment.