mirror of https://github.com/kubernetes/kops.git
Implement completion for "kops get instancegroups"
This commit is contained in:
parent
a8aa6a9a68
commit
337377c163
|
@ -20,7 +20,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -109,7 +108,7 @@ func NewCmdGetCluster(f *util.Factory, out io.Writer, getOptions *GetOptions) *c
|
||||||
},
|
},
|
||||||
ValidArgsFunction: commandutils.CompleteClusterName(&rootCommand, false, true),
|
ValidArgsFunction: commandutils.CompleteClusterName(&rootCommand, false, true),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return RunGetClusters(context.TODO(), &rootCommand, os.Stdout, &options)
|
return RunGetClusters(context.TODO(), &rootCommand, out, &options)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -28,6 +27,7 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/kops/cmd/kops/util"
|
"k8s.io/kops/cmd/kops/util"
|
||||||
api "k8s.io/kops/pkg/apis/kops"
|
api "k8s.io/kops/pkg/apis/kops"
|
||||||
|
"k8s.io/kops/pkg/commands/commandutils"
|
||||||
"k8s.io/kops/pkg/formatter"
|
"k8s.io/kops/pkg/formatter"
|
||||||
"k8s.io/kops/util/pkg/tables"
|
"k8s.io/kops/util/pkg/tables"
|
||||||
"k8s.io/kubectl/pkg/util/i18n"
|
"k8s.io/kubectl/pkg/util/i18n"
|
||||||
|
@ -36,24 +36,25 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
getInstancegroupsLong = templates.LongDesc(i18n.T(`
|
getInstancegroupsLong = templates.LongDesc(i18n.T(`
|
||||||
Display one or many instancegroup resources.`))
|
Display one or many instance group resources.`))
|
||||||
|
|
||||||
getInstancegroupsExample = templates.Examples(i18n.T(`
|
getInstancegroupsExample = templates.Examples(i18n.T(`
|
||||||
# Get all instancegroups in a state store
|
# Get all instance groups in a state store
|
||||||
kops get ig
|
kops get instancegroups
|
||||||
|
|
||||||
# Get a cluster's instancegroup
|
# Get a cluster's instancegroup
|
||||||
kops get ig --name k8s-cluster.example.com nodes
|
kops get instancegroups --name k8s-cluster.example.com nodes
|
||||||
|
|
||||||
# Save a cluster's instancegroups desired configuration to YAML file
|
# Save a cluster's instancegroups desired configuration to YAML file
|
||||||
kops get ig --name k8s-cluster.example.com -o yaml > instancegroups-desired-config.yaml
|
kops get instancegroups --name k8s-cluster.example.com -o yaml > instancegroups-desired-config.yaml
|
||||||
`))
|
`))
|
||||||
|
|
||||||
getInstancegroupsShort = i18n.T(`Get one or many instancegroups`)
|
getInstancegroupsShort = i18n.T(`Get one or many instance groups.`)
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetInstanceGroupsOptions struct {
|
type GetInstanceGroupsOptions struct {
|
||||||
*GetOptions
|
*GetOptions
|
||||||
|
InstanceGroupNames []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCmdGetInstanceGroups(f *util.Factory, out io.Writer, getOptions *GetOptions) *cobra.Command {
|
func NewCmdGetInstanceGroups(f *util.Factory, out io.Writer, getOptions *GetOptions) *cobra.Command {
|
||||||
|
@ -62,43 +63,44 @@ func NewCmdGetInstanceGroups(f *util.Factory, out io.Writer, getOptions *GetOpti
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "instancegroups",
|
Use: "instancegroups [INSTANCE_GROUP]...",
|
||||||
Aliases: []string{"instancegroup", "ig"},
|
Aliases: []string{"instancegroup", "ig"},
|
||||||
Short: getInstancegroupsShort,
|
Short: getInstancegroupsShort,
|
||||||
Long: getInstancegroupsLong,
|
Long: getInstancegroupsLong,
|
||||||
Example: getInstancegroupsExample,
|
Example: getInstancegroupsExample,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := context.TODO()
|
options.ClusterName = rootCommand.ClusterName(true)
|
||||||
err := RunGetInstanceGroups(ctx, &options, args)
|
if options.ClusterName == "" {
|
||||||
if err != nil {
|
return fmt.Errorf("--name is required")
|
||||||
exitWithError(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options.InstanceGroupNames = args
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
return completeInstanceGroup(&args, nil)(cmd, nil, toComplete)
|
||||||
|
},
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
return RunGetInstanceGroups(context.TODO(), &rootCommand, out, &options)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunGetInstanceGroups(ctx context.Context, options *GetInstanceGroupsOptions, args []string) error {
|
func RunGetInstanceGroups(ctx context.Context, f commandutils.Factory, out io.Writer, options *GetInstanceGroupsOptions) error {
|
||||||
out := os.Stdout
|
clientset, err := f.Clientset()
|
||||||
|
|
||||||
clusterName := rootCommand.ClusterName(true)
|
|
||||||
if clusterName == "" {
|
|
||||||
return fmt.Errorf("--name is required")
|
|
||||||
}
|
|
||||||
|
|
||||||
clientset, err := rootCommand.Clientset()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cluster, err := clientset.GetCluster(ctx, clusterName)
|
cluster, err := clientset.GetCluster(ctx, options.ClusterName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error fetching cluster %q: %v", clusterName, err)
|
return fmt.Errorf("error fetching cluster %q: %v", options.ClusterName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cluster == nil {
|
if cluster == nil {
|
||||||
return fmt.Errorf("cluster %q was not found", clusterName)
|
return fmt.Errorf("cluster %q was not found", options.ClusterName)
|
||||||
}
|
}
|
||||||
|
|
||||||
list, err := clientset.InstanceGroupsFor(cluster).List(ctx, metav1.ListOptions{})
|
list, err := clientset.InstanceGroupsFor(cluster).List(ctx, metav1.ListOptions{})
|
||||||
|
@ -106,13 +108,13 @@ func RunGetInstanceGroups(ctx context.Context, options *GetInstanceGroupsOptions
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
instancegroups, err := filterInstanceGroupsByName(args, list.Items)
|
instancegroups, err := filterInstanceGroupsByName(options.InstanceGroupNames, list.Items)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(instancegroups) == 0 {
|
if len(instancegroups) == 0 {
|
||||||
return fmt.Errorf("No InstanceGroup objects found")
|
return fmt.Errorf("no InstanceGroup objects found")
|
||||||
}
|
}
|
||||||
|
|
||||||
var obj []runtime.Object
|
var obj []runtime.Object
|
||||||
|
@ -130,7 +132,7 @@ func RunGetInstanceGroups(ctx context.Context, options *GetInstanceGroupsOptions
|
||||||
case OutputJSON:
|
case OutputJSON:
|
||||||
return fullOutputJSON(out, obj...)
|
return fullOutputJSON(out, obj...)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unknown output format: %q", options.Output)
|
return fmt.Errorf("unknown output format: %q", options.Output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +183,7 @@ func igOutputTable(cluster *api.Cluster, instancegroups []*api.InstanceGroup, ou
|
||||||
return int32PointerToString(c.Spec.MaxSize)
|
return int32PointerToString(c.Spec.MaxSize)
|
||||||
})
|
})
|
||||||
// SUBNETS is not selected by default - not as useful as ZONES
|
// SUBNETS is not selected by default - not as useful as ZONES
|
||||||
return t.Render(instancegroups, os.Stdout, "NAME", "ROLE", "MACHINETYPE", "MIN", "MAX", "ZONES")
|
return t.Render(instancegroups, out, "NAME", "ROLE", "MACHINETYPE", "MIN", "MAX", "ZONES")
|
||||||
}
|
}
|
||||||
|
|
||||||
func int32PointerToString(v *int32) string {
|
func int32PointerToString(v *int32) string {
|
||||||
|
|
|
@ -63,7 +63,7 @@ kops get [flags]
|
||||||
* [kops](kops.md) - kOps is Kubernetes Operations.
|
* [kops](kops.md) - kOps is Kubernetes Operations.
|
||||||
* [kops get assets](kops_get_assets.md) - Display assets for cluster.
|
* [kops get assets](kops_get_assets.md) - Display assets for cluster.
|
||||||
* [kops get clusters](kops_get_clusters.md) - Get one or many clusters.
|
* [kops get clusters](kops_get_clusters.md) - Get one or many clusters.
|
||||||
* [kops get instancegroups](kops_get_instancegroups.md) - Get one or many instancegroups
|
* [kops get instancegroups](kops_get_instancegroups.md) - Get one or many instance groups.
|
||||||
* [kops get instances](kops_get_instances.md) - Display cluster instances.
|
* [kops get instances](kops_get_instances.md) - Display cluster instances.
|
||||||
* [kops get keypairs](kops_get_keypairs.md) - Get one or many keypairs.
|
* [kops get keypairs](kops_get_keypairs.md) - Get one or many keypairs.
|
||||||
* [kops get secrets](kops_get_secrets.md) - Get one or many secrets.
|
* [kops get secrets](kops_get_secrets.md) - Get one or many secrets.
|
||||||
|
|
|
@ -3,27 +3,27 @@
|
||||||
|
|
||||||
## kops get instancegroups
|
## kops get instancegroups
|
||||||
|
|
||||||
Get one or many instancegroups
|
Get one or many instance groups.
|
||||||
|
|
||||||
### Synopsis
|
### Synopsis
|
||||||
|
|
||||||
Display one or many instancegroup resources.
|
Display one or many instance group resources.
|
||||||
|
|
||||||
```
|
```
|
||||||
kops get instancegroups [flags]
|
kops get instancegroups [INSTANCE_GROUP]... [flags]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
```
|
```
|
||||||
# Get all instancegroups in a state store
|
# Get all instance groups in a state store
|
||||||
kops get ig
|
kops get instancegroups
|
||||||
|
|
||||||
# Get a cluster's instancegroup
|
# Get a cluster's instancegroup
|
||||||
kops get ig --name k8s-cluster.example.com nodes
|
kops get instancegroups --name k8s-cluster.example.com nodes
|
||||||
|
|
||||||
# Save a cluster's instancegroups desired configuration to YAML file
|
# Save a cluster's instancegroups desired configuration to YAML file
|
||||||
kops get ig --name k8s-cluster.example.com -o yaml > instancegroups-desired-config.yaml
|
kops get instancegroups --name k8s-cluster.example.com -o yaml > instancegroups-desired-config.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
Loading…
Reference in New Issue