Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use client-go #61

Merged
merged 7 commits into from
Jun 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
322 changes: 212 additions & 110 deletions glide.lock

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ package: github.com/k8sdb/cli
import:
- package: github.com/appscode/go
- package: github.com/appscode/log
- package: k8s.io/kubernetes
version: ~1.5.0
- package: github.com/spf13/cobra
version: master
- package: github.com/spf13/pflag
version: master
- package: github.com/k8sdb/apimachinery
version: master
- package: k8s.io/kubernetes
version: ~1.6.0
- package: k8s.io/apimachinery
version: 75b8dd260ef0469d96d578705a87cffd0e09dab8
- package: k8s.io/client-go
version: v3.0.0-beta.0
- package: github.com/graymeta/stow
repo: https://github.com/appscode/stow.git
version: master
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"github.com/k8sdb/cli/pkg/cmd/util"
"github.com/k8sdb/cli/pkg/kube"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/runtime"
)

// ref: k8s.io/kubernetes/pkg/kubectl/cmd/create.go
Expand Down Expand Up @@ -65,7 +65,7 @@ func RunCreate(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *re
mapper,
typer,
resource.ClientMapperFunc(f.UnstructuredClientForMapping),
runtime.UnstructuredJSONScheme).
unstructured.UnstructuredJSONScheme).
Schema(util.Validator()).
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().
Expand All @@ -84,7 +84,7 @@ func RunCreate(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *re
return err
}

kind := info.GetObjectKind().GroupVersionKind().Kind
kind := info.Object.GetObjectKind().GroupVersionKind().Kind
if err := util.CheckSupportedResource(kind); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/decoder/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/ghodss/yaml"
tapi "github.com/k8sdb/apimachinery/api"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
)

func Decode(kind string, data []byte) (runtime.Object, error) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"github.com/k8sdb/cli/pkg/cmd/util"
"github.com/k8sdb/cli/pkg/kube"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/runtime"
)

// ref: k8s.io/kubernetes/pkg/kubectl/cmd/delete.go
Expand Down Expand Up @@ -75,7 +75,7 @@ func RunDelete(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, args []stri
args[0] = strings.Join(resources, ",")
}

r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.UnstructuredClientForMapping), runtime.UnstructuredJSONScheme).
r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.UnstructuredClientForMapping), unstructured.UnstructuredJSONScheme).
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(enforceNamespace, options).
Expand All @@ -98,7 +98,7 @@ func deleteResult(r *resource.Result, out io.Writer, shortOutput bool, mapper me
if err != nil {
return err
}
kind := info.GetObjectKind().GroupVersionKind().Kind
kind := info.Object.GetObjectKind().GroupVersionKind().Kind
if err := util.CheckSupportedResource(kind); err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"github.com/k8sdb/cli/pkg/cmd/util"
"github.com/k8sdb/cli/pkg/kube"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/runtime"
utilerrors "k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/printers"
)

var (
Expand All @@ -35,7 +35,7 @@ var (
)

func NewCmdDescribe(out, cmdErr io.Writer) *cobra.Command {
describerSettings := &kubectl.DescriberSettings{}
describerSettings := &printers.DescriberSettings{}

cmd := &cobra.Command{
Use: "describe (TYPE [NAME_PREFIX] | TYPE/NAME)",
Expand All @@ -53,7 +53,7 @@ func NewCmdDescribe(out, cmdErr io.Writer) *cobra.Command {
return cmd
}

func RunDescribe(f cmdutil.Factory, out, cmdErr io.Writer, cmd *cobra.Command, args []string, describerSettings *kubectl.DescriberSettings) error {
func RunDescribe(f cmdutil.Factory, out, cmdErr io.Writer, cmd *cobra.Command, args []string, describerSettings *printers.DescriberSettings) error {
selector := cmdutil.GetFlagString(cmd, "selector")
allNamespaces := cmdutil.GetFlagBool(cmd, "all-namespaces")
cmdNamespace, enforceNamespace := util.GetNamespace(cmd)
Expand Down Expand Up @@ -92,7 +92,7 @@ func RunDescribe(f cmdutil.Factory, out, cmdErr io.Writer, cmd *cobra.Command, a
}
args[0] = strings.Join(resources, ",")

r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.UnstructuredClientForMapping), runtime.UnstructuredJSONScheme).
r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.UnstructuredClientForMapping), unstructured.UnstructuredJSONScheme).
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().AllNamespaces(allNamespaces).
FilenameParam(enforceNamespace, &resource.FilenameOptions{}).
Expand Down
15 changes: 8 additions & 7 deletions pkg/cmd/describer/describer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
"github.com/golang/glog"
"github.com/k8sdb/apimachinery/client/clientset"
"github.com/k8sdb/cli/pkg/cmd/decoder"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/printers"
)

type Describer interface {
Describe(object runtime.Object, describerSettings *kubectl.DescriberSettings) (output string, err error)
Describe(object runtime.Object, describerSettings *printers.DescriberSettings) (output string, err error)
}

func NewDescriber(f cmdutil.Factory) Describer {
Expand Down Expand Up @@ -74,19 +75,19 @@ func (h *humanReadableDescriber) validateDescribeHandlerFunc(describeFunc reflec
"Must accept 2 parameters and return 2 value.")
}

if funcType.In(1) != reflect.TypeOf((*kubectl.DescriberSettings)(nil)) ||
if funcType.In(1) != reflect.TypeOf((*printers.DescriberSettings)(nil)) ||
funcType.Out(0) != reflect.TypeOf((string)("")) ||
funcType.Out(1) != reflect.TypeOf((*error)(nil)).Elem() {
return fmt.Errorf("invalid describe handler. The expected signature is: "+
"func handler(item %v, describerSettings *kubectl.DescriberSettings) (string, error)", funcType.In(0))
"func handler(item %v, describerSettings *printers.DescriberSettings) (string, error)", funcType.In(0))
}
return nil
}

func (h *humanReadableDescriber) Describe(obj runtime.Object, describerSettings *kubectl.DescriberSettings) (string, error) {
func (h *humanReadableDescriber) Describe(obj runtime.Object, describerSettings *printers.DescriberSettings) (string, error) {
kind := obj.GetObjectKind().GroupVersionKind().Kind
switch obj.(type) {
case *runtime.UnstructuredList, *runtime.Unstructured, *runtime.Unknown:
case *unstructured.UnstructuredList, *unstructured.Unstructured, *runtime.Unknown:
if objBytes, err := runtime.Encode(clientset.ExtendedCodec, obj); err == nil {

if decodedObj, err := decoder.Decode(kind, objBytes); err == nil {
Expand Down
49 changes: 26 additions & 23 deletions pkg/cmd/describer/k8sdb_describer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@ import (
"github.com/golang/glog"
tapi "github.com/k8sdb/apimachinery/api"
amc "github.com/k8sdb/apimachinery/pkg/controller"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/pkg/api"
apiv1 "k8s.io/client-go/pkg/api/v1"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/printers"
)

func (d *humanReadableDescriber) describeElastic(item *tapi.Elastic, describerSettings *kubectl.DescriberSettings) (string, error) {
func (d *humanReadableDescriber) describeElastic(item *tapi.Elastic, describerSettings *printers.DescriberSettings) (string, error) {
clientSet, err := d.ClientSet()
if err != nil {
return "", err
}

snapshots, err := d.extensionsClient.Snapshots(item.Namespace).List(
kapi.ListOptions{
metav1.ListOptions{
LabelSelector: labels.SelectorFromSet(
map[string]string{
amc.LabelDatabaseKind: tapi.ResourceKindElastic,
amc.LabelDatabaseName: item.Name,
},
),
).String(),
},
)
if err != nil {
Expand All @@ -34,11 +37,11 @@ func (d *humanReadableDescriber) describeElastic(item *tapi.Elastic, describerSe

var events *kapi.EventList
if describerSettings.ShowEvents {
if ref, err := kapi.GetReference(item); err != nil {
if ref, err := apiv1.GetReference(api.Scheme, item); err != nil {
glog.Errorf("Unable to construct reference to '%#v': %v", item, err)
} else {
ref.Kind = ""
events, err = clientSet.Core().Events(item.Namespace).Search(ref)
events, err = clientSet.Core().Events(item.Namespace).Search(api.Scheme, ref)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -82,20 +85,20 @@ func (d *humanReadableDescriber) describeElastic(item *tapi.Elastic, describerSe
})
}

func (d *humanReadableDescriber) describePostgres(item *tapi.Postgres, describerSettings *kubectl.DescriberSettings) (string, error) {
func (d *humanReadableDescriber) describePostgres(item *tapi.Postgres, describerSettings *printers.DescriberSettings) (string, error) {
clientSet, err := d.ClientSet()
if err != nil {
return "", err
}

snapshots, err := d.extensionsClient.Snapshots(item.Namespace).List(
kapi.ListOptions{
metav1.ListOptions{
LabelSelector: labels.SelectorFromSet(
map[string]string{
amc.LabelDatabaseKind: tapi.ResourceKindPostgres,
amc.LabelDatabaseName: item.Name,
},
),
).String(),
},
)
if err != nil {
Expand All @@ -104,11 +107,11 @@ func (d *humanReadableDescriber) describePostgres(item *tapi.Postgres, describer

var events *kapi.EventList
if describerSettings.ShowEvents {
if ref, err := kapi.GetReference(item); err != nil {
if ref, err := apiv1.GetReference(api.Scheme, item); err != nil {
glog.Errorf("Unable to construct reference to '%#v': %v", item, err)
} else {
ref.Kind = ""
events, err = clientSet.Core().Events(item.Namespace).Search(ref)
events, err = clientSet.Core().Events(item.Namespace).Search(api.Scheme, ref)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -154,19 +157,19 @@ func (d *humanReadableDescriber) describePostgres(item *tapi.Postgres, describer
})
}

func (d *humanReadableDescriber) describeSnapshot(item *tapi.Snapshot, describerSettings *kubectl.DescriberSettings) (string, error) {
func (d *humanReadableDescriber) describeSnapshot(item *tapi.Snapshot, describerSettings *printers.DescriberSettings) (string, error) {
clientSet, err := d.ClientSet()
if err != nil {
return "", err
}

var events *kapi.EventList
if describerSettings.ShowEvents {
if ref, err := kapi.GetReference(item); err != nil {
if ref, err := apiv1.GetReference(api.Scheme, item); err != nil {
glog.Errorf("Unable to construct reference to '%#v': %v", item, err)
} else {
ref.Kind = ""
events, err = clientSet.Core().Events(item.Namespace).Search(ref)
events, err = clientSet.Core().Events(item.Namespace).Search(api.Scheme, ref)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -201,20 +204,20 @@ func (d *humanReadableDescriber) describeSnapshot(item *tapi.Snapshot, describer
})
}

func (d *humanReadableDescriber) describeDormantDatabase(item *tapi.DormantDatabase, describerSettings *kubectl.DescriberSettings) (string, error) {
func (d *humanReadableDescriber) describeDormantDatabase(item *tapi.DormantDatabase, describerSettings *printers.DescriberSettings) (string, error) {
clientSet, err := d.ClientSet()
if err != nil {
return "", err
}

snapshots, err := d.extensionsClient.Snapshots(item.Namespace).List(
kapi.ListOptions{
metav1.ListOptions{
LabelSelector: labels.SelectorFromSet(
map[string]string{
amc.LabelDatabaseKind: item.Labels[amc.LabelDatabaseKind],
amc.LabelDatabaseName: item.Name,
},
),
).String(),
},
)
if err != nil {
Expand All @@ -223,11 +226,11 @@ func (d *humanReadableDescriber) describeDormantDatabase(item *tapi.DormantDatab

var events *kapi.EventList
if describerSettings.ShowEvents {
if ref, err := kapi.GetReference(item); err != nil {
if ref, err := apiv1.GetReference(api.Scheme, item); err != nil {
glog.Errorf("Unable to construct reference to '%#v': %v", item, err)
} else {
ref.Kind = ""
events, err = clientSet.Core().Events(item.Namespace).Search(ref)
events, err = clientSet.Core().Events(item.Namespace).Search(api.Scheme, ref)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -275,8 +278,8 @@ func describeStorage(storage *tapi.StorageSpec, out io.Writer) {
return
}

accessModes := kapi.GetAccessModesAsString(storage.AccessModes)
val, _ := storage.Resources.Requests[kapi.ResourceStorage]
accessModes := apiv1.GetAccessModesAsString(storage.AccessModes)
val, _ := storage.Resources.Requests[apiv1.ResourceStorage]
capacity := val.String()
fmt.Fprint(out, "Volume:\n")
fmt.Fprintf(out, " StorageClass:\t%s\n", storage.Class)
Expand Down Expand Up @@ -311,7 +314,7 @@ func listSnapshots(snapshotList *tapi.SnapshotList, out io.Writer) {
}

fmt.Fprint(out, "Snapshots:\n")
w := kubectl.GetNewTabWriter(out)
w := printers.GetNewTabWriter(out)

fmt.Fprint(w, " Name\tBucket\tStartTime\tCompletionTime\tPhase\n")
fmt.Fprint(w, " ----\t------\t---------\t--------------\t-----\n")
Expand Down
Loading