Skip to content

Commit

Permalink
cmd/config: Align flags names among commands
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Blanquicet <josebl@microsoft.com>
  • Loading branch information
blanquicet committed Jul 14, 2023
1 parent 5a62c7a commit 6af8a80
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
16 changes: 9 additions & 7 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ func importCmdCommand() *cobra.Command {
vms, err := utils.VirtualMachineScaleSetVMsViaKubeconfig()
if err != nil {
logrus.Warn("Could not get VMSS VMs via Kubernetes API")
logrus.Warn("Please provide '--subscription-id', '--resource-group' and '--cluster-name' flags to get VMSS VMs via Azure API")
logrus.Warnf("Please provide '--%s', '--%s' and '--%s' flags to get VMSS VMs via Azure API",
utils.SubscriptionIDKey, utils.ResourceGroupKey, utils.ClusterNameKey)
return nil, fmt.Errorf("getting VMSS VMs via Kuberntes API: %w", err)
}
return vms, nil
Expand All @@ -141,9 +142,10 @@ func importCmdCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "import",
Short: "Import Kubernetes nodes in the configuration",
Long: "Import Kubernetes nodes in the configuration" + "\n\n" +
"It uses kubeconfig by default, but it can also use Azure API to get VMSS VMs." + "\n" +
"In case of Azure API, you need to provide '--subscription-id', '--resource-group' and '--cluster-name' flags.",
Long: fmt.Sprintf("Import Kubernetes nodes in the configuration"+"\n\n"+
"It uses kubeconfig by default, but it can also use Azure API to get VMSS VMs."+"\n"+
"In case of Azure API, you need to provide '--%s', '--%s' and '--%s' flags.",
utils.SubscriptionIDKey, utils.ResourceGroupKey, utils.ClusterNameKey),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
utils.DefaultSpinner.Start()
Expand All @@ -162,9 +164,9 @@ func importCmdCommand() *cobra.Command {
},
}

cmd.Flags().StringVarP(&subscriptionID, "subscription-id", "s", "", "Subscription ID of the cluster (only needed with Azure API)")
cmd.Flags().StringVarP(&resourceGroup, "resource-group", "g", "", "Resource group of the cluster (only needed with Azure API)")
cmd.Flags().StringVarP(&clusterName, "cluster-name", "c", "", "Name of the cluster (only needed with Azure API)")
cmd.Flags().StringVarP(&subscriptionID, utils.SubscriptionIDKey, "", "", "Subscription ID of the cluster (only needed with Azure API)")
cmd.Flags().StringVarP(&resourceGroup, utils.ResourceGroupKey, "", "", "Resource group of the cluster (only needed with Azure API)")
cmd.Flags().StringVarP(&clusterName, utils.ClusterNameKey, "", "", "Name of the cluster (only needed with Azure API)")

return cmd
}
2 changes: 2 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
const (
NodeKey = "node"
SubscriptionIDKey = "subscription"
ResourceGroupKey = "resource-group"
ClusterNameKey = "cluster-name"
NodeResourceGroupKey = "node-resource-group"
VMSSKey = "vmss"
VMSSInstanceIDKey = "instance-id"
Expand Down
7 changes: 6 additions & 1 deletion test/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"testing"
"time"

"github.com/Azure/kubectl-aks/cmd/utils"
"github.com/Azure/kubectl-aks/cmd/utils/config"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -95,7 +96,11 @@ func TestConfigImport(t *testing.T) {
_, err = os.ReadFile(configPath)
require.NotNil(t, err, "reading config file: %v", err)

runCommand(t, os.Getenv("KUBECTL_AKS"), "config", "import", "-s", subscriptionID, "-g", resourceGroup, "-c", clusterName)
runCommand(t, os.Getenv("KUBECTL_AKS"), "config", "import",
"--"+utils.SubscriptionIDKey, subscriptionID,
"--"+utils.ResourceGroupKey, resourceGroup,
"--"+utils.ClusterNameKey, clusterName,
)
azureConfigFile, err := os.ReadFile(configPath)
require.Nil(t, err, "reading config file: %v", err)
require.NotEmpty(t, azureConfigFile, "config file is empty")
Expand Down

0 comments on commit 6af8a80

Please sign in to comment.