mirror of https://github.com/kubernetes/kops.git
Wire up context from cobra in cmd/kops
Removes a lot of context.TODO() calls.
This commit is contained in:
parent
90cbf75584
commit
ba59d65bc9
|
|
@ -76,7 +76,7 @@ func NewCmdCreate(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
Example: createExample,
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunCreate(context.TODO(), f, out, options)
|
||||
return RunCreate(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ func NewCmdCreateCluster(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
}
|
||||
}
|
||||
|
||||
return RunCreateCluster(context.TODO(), f, out, options)
|
||||
return RunCreateCluster(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ func NewCmdCreateInstanceGroup(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunCreateInstanceGroup(context.TODO(), f, out, options)
|
||||
return RunCreateInstanceGroup(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -277,8 +277,9 @@ func RunCreateInstanceGroup(ctx context.Context, f *util.Factory, out io.Writer,
|
|||
|
||||
func completeClusterSubnet(f commandutils.Factory, excludeSubnets *[]string) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
ctx := cmd.Context()
|
||||
|
||||
commandutils.ConfigureKlogForCompletion()
|
||||
ctx := context.TODO()
|
||||
|
||||
cluster, _, completions, directive := GetClusterForCompletion(ctx, f, nil)
|
||||
if cluster == nil {
|
||||
|
|
|
|||
|
|
@ -128,10 +128,10 @@ func NewCmdCreateKeypair(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
return nil
|
||||
},
|
||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return completeCreateKeypair(f, options, args, toComplete)
|
||||
return completeCreateKeypair(cmd.Context(), f, options, args, toComplete)
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunCreateKeypair(context.TODO(), f, out, options)
|
||||
return RunCreateKeypair(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -304,16 +304,15 @@ func completeKeyset(ctx context.Context, cluster *kopsapi.Cluster, clientSet sim
|
|||
return keyset, keyStore, nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
||||
func completeCreateKeypair(f commandutils.Factory, options *CreateKeypairOptions, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
func completeCreateKeypair(ctx context.Context, f commandutils.Factory, options *CreateKeypairOptions, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
commandutils.ConfigureKlogForCompletion()
|
||||
ctx := context.TODO()
|
||||
|
||||
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, f, nil)
|
||||
if cluster == nil {
|
||||
return completions, directive
|
||||
}
|
||||
|
||||
keyset, _, completions, directive := completeKeyset(cluster, clientSet, args, rotatableKeysetFilter)
|
||||
keyset, _, completions, directive := completeKeyset(ctx, cluster, clientSet, args, rotatableKeysetFilter)
|
||||
if keyset == nil {
|
||||
return completions, directive
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ func NewCmdCreateSecretCiliumPassword(f *util.Factory, out io.Writer) *cobra.Com
|
|||
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunCreateSecretCiliumEncryptionConfig(context.TODO(), f, out, options)
|
||||
return RunCreateSecretCiliumEncryptionConfig(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ func NewCmdCreateSecretDockerConfig(f *util.Factory, out io.Writer) *cobra.Comma
|
|||
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunCreateSecretDockerConfig(context.TODO(), f, out, options)
|
||||
return RunCreateSecretDockerConfig(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ func NewCmdCreateSecretEncryptionConfig(f *util.Factory, out io.Writer) *cobra.C
|
|||
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunCreateSecretEncryptionConfig(context.TODO(), f, out, options)
|
||||
return RunCreateSecretEncryptionConfig(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ func NewCmdCreateSecretWeavePassword(f *util.Factory, out io.Writer) *cobra.Comm
|
|||
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunCreateSecretWeavePassword(context.TODO(), f, out, options)
|
||||
return RunCreateSecretWeavePassword(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ func NewCmdCreateSSHPublicKey(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunCreateSSHPublicKey(context.TODO(), f, out, options)
|
||||
return RunCreateSSHPublicKey(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ func NewCmdDelete(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
SuggestFor: []string{"rm"},
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunDelete(context.TODO(), f, out, options)
|
||||
return RunDelete(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ func NewCmdDeleteCluster(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
Args: rootCommand.clusterNameArgsNoKubeconfig(&options.ClusterName),
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunDeleteCluster(context.TODO(), f, out, options)
|
||||
return RunDeleteCluster(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ func NewCmdDeleteInstance(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
},
|
||||
ValidArgsFunction: completeInstanceOrNode(f, &options),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunDeleteInstance(context.TODO(), f, out, &options)
|
||||
return RunDeleteInstance(cmd.Context(), f, out, &options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -307,12 +307,13 @@ func findDeletionNode(groups map[string]*cloudinstances.CloudInstanceGroup, opti
|
|||
|
||||
func completeInstanceOrNode(f commandutils.Factory, options *DeleteInstanceOptions) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
ctx := cmd.Context()
|
||||
|
||||
if len(args) > 0 {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
||||
commandutils.ConfigureKlogForCompletion()
|
||||
ctx := context.TODO()
|
||||
|
||||
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, f, nil)
|
||||
if cluster == nil {
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ func NewCmdDeleteInstanceGroup(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
},
|
||||
ValidArgsFunction: completeInstanceGroup(f, nil, &[]string{kops.InstanceGroupRoleControlPlane.ToLowerString()}),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
ctx := context.TODO()
|
||||
ctx := cmd.Context()
|
||||
|
||||
if !options.Yes {
|
||||
message := fmt.Sprintf("Do you really want to delete instance group %q? This action cannot be undone.", options.GroupName)
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ func NewCmdDeleteSecret(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
},
|
||||
ValidArgsFunction: completeSecretNames(f),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunDeleteSecret(context.TODO(), f, out, options)
|
||||
return RunDeleteSecret(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -120,8 +120,9 @@ func RunDeleteSecret(ctx context.Context, f *util.Factory, out io.Writer, option
|
|||
|
||||
func completeSecretNames(f commandutils.Factory) func(cmd *cobra.Command, args []string, complete string) ([]string, cobra.ShellCompDirective) {
|
||||
return func(cmd *cobra.Command, args []string, complete string) ([]string, cobra.ShellCompDirective) {
|
||||
ctx := cmd.Context()
|
||||
|
||||
commandutils.ConfigureKlogForCompletion()
|
||||
ctx := context.TODO()
|
||||
|
||||
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, f, nil)
|
||||
if cluster == nil {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ func NewCmdDeleteSSHPublicKey(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
ctx := context.TODO()
|
||||
ctx := cmd.Context()
|
||||
|
||||
return RunDeleteSSHPublicKey(ctx, f, out, options)
|
||||
},
|
||||
|
|
|
|||
|
|
@ -98,10 +98,10 @@ func NewCmdDistrustKeypair(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
return nil
|
||||
},
|
||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return completeDistrustKeyset(f, options, args, toComplete)
|
||||
return completeDistrustKeyset(cmd.Context(), f, options, args, toComplete)
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunDistrustKeypair(context.TODO(), f, out, options)
|
||||
return RunDistrustKeypair(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -192,16 +192,15 @@ func distrustKeypair(ctx context.Context, out io.Writer, name string, keypairIDs
|
|||
return nil
|
||||
}
|
||||
|
||||
func completeDistrustKeyset(f commandutils.Factory, options *DistrustKeypairOptions, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
func completeDistrustKeyset(ctx context.Context, f commandutils.Factory, options *DistrustKeypairOptions, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
commandutils.ConfigureKlogForCompletion()
|
||||
ctx := context.TODO()
|
||||
|
||||
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, f, nil)
|
||||
if cluster == nil {
|
||||
return completions, directive
|
||||
}
|
||||
|
||||
keyset, _, completions, directive := completeKeyset(cluster, clientSet, args, rotatableKeysetFilter)
|
||||
keyset, _, completions, directive := completeKeyset(ctx, cluster, clientSet, args, rotatableKeysetFilter)
|
||||
if keyset == nil {
|
||||
return completions, directive
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ func NewCmdEditCluster(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunEditCluster(context.TODO(), f, out, options)
|
||||
return RunEditCluster(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ func NewCmdEditInstanceGroup(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
},
|
||||
ValidArgsFunction: completeInstanceGroup(f, nil, nil),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunEditInstanceGroup(context.TODO(), f, out, options)
|
||||
return RunEditInstanceGroup(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ func NewCmdExportKubeconfig(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
},
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunExportKubeconfig(context.TODO(), f, out, options, args)
|
||||
return RunExportKubeconfig(cmd.Context(), f, out, options, args)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ func NewCmdGet(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
Short: i18n.T(`Get one or many resources.`),
|
||||
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunGet(context.TODO(), f, out, options)
|
||||
return RunGet(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ func NewCmdGetAll(f *util.Factory, out io.Writer, getOptions *GetOptions) *cobra
|
|||
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunGetAll(context.TODO(), f, out, options)
|
||||
return RunGetAll(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ func NewCmdGetAssets(f *util.Factory, out io.Writer, getOptions *GetOptions) *co
|
|||
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunGetAssets(context.TODO(), f, out, &options)
|
||||
return RunGetAssets(cmd.Context(), f, out, &options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ func NewCmdGetCluster(f *util.Factory, out io.Writer, getOptions *GetOptions) *c
|
|||
},
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, false, true),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunGetClusters(context.TODO(), f, out, &options)
|
||||
return RunGetClusters(cmd.Context(), f, out, &options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ func NewCmdGetInstanceGroups(f *util.Factory, out io.Writer, getOptions *GetOpti
|
|||
return completeInstanceGroup(f, &args, nil)(cmd, nil, toComplete)
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunGetInstanceGroups(context.TODO(), f, out, &options)
|
||||
return RunGetInstanceGroups(cmd.Context(), f, out, &options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ func NewCmdGetInstances(f *util.Factory, out io.Writer, options *GetOptions) *co
|
|||
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunGetInstances(context.TODO(), f, out, options)
|
||||
return RunGetInstances(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,10 +72,10 @@ func NewCmdGetKeypairs(f *util.Factory, out io.Writer, getOptions *GetOptions) *
|
|||
return nil
|
||||
},
|
||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return completeGetKeypairs(f, options, args, toComplete)
|
||||
return completeGetKeypairs(cmd.Context(), f, options, args, toComplete)
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunGetKeypairs(context.TODO(), f, out, options)
|
||||
return RunGetKeypairs(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -259,9 +259,8 @@ func RunGetKeypairs(ctx context.Context, f commandutils.Factory, out io.Writer,
|
|||
return nil
|
||||
}
|
||||
|
||||
func completeGetKeypairs(f commandutils.Factory, options *GetKeypairsOptions, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
func completeGetKeypairs(ctx context.Context, f commandutils.Factory, options *GetKeypairsOptions, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
commandutils.ConfigureKlogForCompletion()
|
||||
ctx := context.TODO()
|
||||
|
||||
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, f, nil)
|
||||
if cluster == nil {
|
||||
|
|
@ -269,7 +268,7 @@ func completeGetKeypairs(f commandutils.Factory, options *GetKeypairsOptions, ar
|
|||
}
|
||||
|
||||
alreadySelected := sets.NewString(args...).Insert("all")
|
||||
_, _, completions, directive = completeKeyset(cluster, clientSet, nil, func(name string, keyset *fi.Keyset) bool {
|
||||
_, _, completions, directive = completeKeyset(ctx, cluster, clientSet, nil, func(name string, keyset *fi.Keyset) bool {
|
||||
return !alreadySelected.Has(name)
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ func NewCmdGetSecrets(f *util.Factory, out io.Writer, getOptions *GetOptions) *c
|
|||
},
|
||||
ValidArgsFunction: completeSecretNames(f),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunGetSecrets(context.TODO(), f, out, &options)
|
||||
return RunGetSecrets(cmd.Context(), f, out, &options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ func NewCmdGetSSHPublicKeys(f *util.Factory, out io.Writer, getOptions *GetOptio
|
|||
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunGetSSHPublicKeys(context.TODO(), f, out, &options)
|
||||
return RunGetSSHPublicKeys(cmd.Context(), f, out, &options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ limitations under the License.
|
|||
|
||||
package main // import "k8s.io/kops/cmd/kops"
|
||||
|
||||
import "context"
|
||||
|
||||
func main() {
|
||||
Execute()
|
||||
ctx := context.Background()
|
||||
Execute(ctx)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ func NewCmdPromoteKeypair(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
return nil
|
||||
},
|
||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return completePromoteKeyset(f, options, args, toComplete)
|
||||
return completePromoteKeyset(cmd.Context(), f, options, args, toComplete)
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunPromoteKeypair(cmd.Context(), f, out, options)
|
||||
|
|
@ -201,16 +201,15 @@ func promoteKeypair(ctx context.Context, out io.Writer, name string, keypairID s
|
|||
return nil
|
||||
}
|
||||
|
||||
func completePromoteKeyset(f commandutils.Factory, options *PromoteKeypairOptions, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
func completePromoteKeyset(ctx context.Context, f commandutils.Factory, options *PromoteKeypairOptions, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
commandutils.ConfigureKlogForCompletion()
|
||||
ctx := context.TODO()
|
||||
|
||||
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, f, nil)
|
||||
if cluster == nil {
|
||||
return completions, directive
|
||||
}
|
||||
|
||||
keyset, _, completions, directive := completeKeyset(cluster, clientSet, args, rotatableKeysetFilter)
|
||||
keyset, _, completions, directive := completeKeyset(ctx, cluster, clientSet, args, rotatableKeysetFilter)
|
||||
if keyset == nil {
|
||||
return completions, directive
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ func NewCmdReplace(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
Args: cobra.NoArgs,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunReplace(context.TODO(), f, out, options)
|
||||
return RunReplace(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
cmd.Flags().StringSliceVarP(&options.Filenames, "filename", "f", options.Filenames, "A list of one or more files separated by a comma.")
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ func NewCmdRollingUpdateCluster(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunRollingUpdateCluster(context.TODO(), f, out, &options)
|
||||
return RunRollingUpdateCluster(cmd.Context(), f, out, &options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -458,8 +458,9 @@ func RunRollingUpdateCluster(ctx context.Context, f *util.Factory, out io.Writer
|
|||
|
||||
func completeInstanceGroup(f commandutils.Factory, selectedInstanceGroups *[]string, selectedInstanceGroupRoles *[]string) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
ctx := cmd.Context()
|
||||
|
||||
commandutils.ConfigureKlogForCompletion()
|
||||
ctx := context.TODO()
|
||||
|
||||
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, f, args)
|
||||
if cluster == nil {
|
||||
|
|
|
|||
|
|
@ -89,10 +89,10 @@ var rootCommand = RootCmd{
|
|||
},
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
func Execute(ctx context.Context) {
|
||||
goflag.Set("logtostderr", "true")
|
||||
goflag.CommandLine.Parse([]string{})
|
||||
if err := rootCommand.cobraCommand.Execute(); err != nil {
|
||||
if err := rootCommand.cobraCommand.ExecuteContext(ctx); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ func NewCmdToolboxDump(f commandutils.Factory, out io.Writer) *cobra.Command {
|
|||
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunToolboxDump(context.TODO(), f, out, options)
|
||||
return RunToolboxDump(cmd.Context(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ func NewCmdToolboxInstanceSelector(f commandutils.Factory, out io.Writer) *cobra
|
|||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
commandline.Command.RunE = func(cmd *cobra.Command, args []string) error {
|
||||
return RunToolboxInstanceSelector(context.TODO(), f, out, &commandline, options)
|
||||
return RunToolboxInstanceSelector(cmd.Context(), f, out, &commandline, options)
|
||||
}
|
||||
|
||||
cpuArchs := []string{cpuArchitectureAMD64, cpuArchitectureARM64}
|
||||
|
|
|
|||
|
|
@ -80,10 +80,10 @@ func NewCmdTrustKeypair(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
return nil
|
||||
},
|
||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return completeTrustKeyset(f, options, args, toComplete)
|
||||
return completeTrustKeyset(cmd.Context(), f, options, args, toComplete)
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
ctx := context.TODO()
|
||||
ctx := cmd.Context()
|
||||
|
||||
return RunTrustKeypair(ctx, f, out, options)
|
||||
},
|
||||
|
|
@ -135,16 +135,15 @@ func RunTrustKeypair(ctx context.Context, f *util.Factory, out io.Writer, option
|
|||
return nil
|
||||
}
|
||||
|
||||
func completeTrustKeyset(f commandutils.Factory, options *TrustKeypairOptions, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
func completeTrustKeyset(ctx context.Context, f commandutils.Factory, options *TrustKeypairOptions, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
commandutils.ConfigureKlogForCompletion()
|
||||
ctx := context.TODO()
|
||||
|
||||
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, f, nil)
|
||||
if cluster == nil {
|
||||
return completions, directive
|
||||
}
|
||||
|
||||
keyset, _, completions, directive := completeKeyset(cluster, clientSet, args, func(name string, keyset *fi.Keyset) bool {
|
||||
keyset, _, completions, directive := completeKeyset(ctx, cluster, clientSet, args, func(name string, keyset *fi.Keyset) bool {
|
||||
if name == "all" {
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ func NewCmdUpdateCluster(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
_, err := RunUpdateCluster(context.TODO(), f, out, options)
|
||||
_, err := RunUpdateCluster(cmd.Context(), f, out, options)
|
||||
return err
|
||||
},
|
||||
}
|
||||
|
|
@ -456,8 +456,9 @@ func hasKubecfg(contextName string) (bool, error) {
|
|||
|
||||
func completeUpdateClusterTarget(f commandutils.Factory, options *UpdateClusterOptions) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
ctx := cmd.Context()
|
||||
|
||||
commandutils.ConfigureKlogForCompletion()
|
||||
ctx := context.TODO()
|
||||
|
||||
cluster, _, _, directive := GetClusterForCompletion(ctx, f, nil)
|
||||
if cluster == nil {
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ func NewCmdUpgradeCluster(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
ctx := context.TODO()
|
||||
ctx := cmd.Context()
|
||||
|
||||
return RunUpgradeCluster(ctx, f, out, options)
|
||||
},
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ func NewCmdValidateCluster(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(f, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
result, err := RunValidateCluster(context.TODO(), f, out, options)
|
||||
result, err := RunValidateCluster(cmd.Context(), f, out, options)
|
||||
if err != nil {
|
||||
return fmt.Errorf("validation failed: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||
package commandutils
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
|
|
@ -27,6 +25,8 @@ import (
|
|||
// CompleteClusterName returns a Cobra completion function for cluster names.
|
||||
func CompleteClusterName(f Factory, suppressIfArgs bool, suppressArgs bool) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
ctx := cmd.Context()
|
||||
|
||||
if suppressIfArgs && len(args) > 0 {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
|
@ -38,7 +38,7 @@ func CompleteClusterName(f Factory, suppressIfArgs bool, suppressArgs bool) func
|
|||
return CompletionError("getting clientset", err)
|
||||
}
|
||||
|
||||
list, err := client.ListClusters(context.TODO(), metav1.ListOptions{})
|
||||
list, err := client.ListClusters(ctx, metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return CompletionError("listing clusters", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue