utils

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NodeKey              = "node"
	SubscriptionIDKey    = "subscription"
	ResourceGroupKey     = "resource-group"
	ClusterNameKey       = "cluster-name"
	NodeResourceGroupKey = "node-resource-group"
	VMSSKey              = "vmss"
	VMSSInstanceIDKey    = "instance-id"
	ResourceIDKey        = "id"
)
View Source
const (
	OutputTruncateHead OutputTruncate = iota
	OutputTruncateTail

	BytesLimit                        = 4096
	DefaultRunCommandTimeoutInSeconds = 300
)

Variables

View Source
var DefaultSpinner = spinner.New(spinner.CharSets[9], 200*time.Millisecond)
View Source
var KubernetesConfigFlags = genericclioptions.NewConfigFlags(false)

Functions

func ARMClientOptions added in v0.2.5

func ARMClientOptions(cfg cloud.Configuration) *arm.ClientOptions

ARMClientOptions returns arm.ClientOptions configured for the given cloud.

func AddCommonFlags

func AddCommonFlags(command *cobra.Command, flags *CommonFlags)

func AddNodeFlags

func AddNodeFlags(command *cobra.Command)

AddNodeFlags adds node flags and binds them to config/environment variables Every command that allows user to specify the node name has three options: (1) Provide the kubernetes node name (2) Provide the VMMS instance information (--subscription, --node-resource-group, --vmss and --instance-id) (3) Provide Resource ID (/subscriptions/mySubID/resourceGroups/myRG/providers/myProvider/virtualMachineScaleSets/myVMSS/virtualMachines/myInsID)

func AddNodeFlagsOnly

func AddNodeFlagsOnly(command *cobra.Command)

AddNodeFlagsOnly adds node flags without binding config/environment variables

func DetectKubeconfigClusterName added in v0.3.0

func DetectKubeconfigClusterName() string

DetectKubeconfigClusterName returns the current kubeconfig context name, which is typically the cluster name. Returns "" if it can't be determined.

func GetCloudConfiguration added in v0.2.5

func GetCloudConfiguration() cloud.Configuration

GetCloudConfiguration returns the cloud.Configuration for the active Azure CLI cloud. It reads ~/.azure/config (cloud name) to determine the active cloud name and maps it to a known cloud.Configuration. If detection fails, it defaults to AzurePublic.

func GetClusterFlag added in v0.3.0

func GetClusterFlag() string

GetClusterFlag returns the --cluster flag value.

func GetCredentials

func GetCredentials() (*azidentity.ChainedTokenCredential, error)

GetCredentials returns a credential chain that will try to authenticate using the Azure CLI and then using the interactive browser. Further details about authentication: https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/azidentity

func GetNodeName added in v0.2.5

func GetNodeName() string

GetNodeName returns the current node name from flags/config.

func GetNodeResourceID

func GetNodeResourceID(ctx context.Context, nodeName string) (string, error)

GetNodeResourceID retrieve the Azure resource ID of a given node. In other words, the resource ID of the VM scale set instance. It returns format: /subscriptions/mySubID/resourceGroups/myRG/providers/myProvider/virtualMachineScaleSets/myVMSS/virtualMachines/myInsID

func ParseVMSSResourceID

func ParseVMSSResourceID(id string, vm *VirtualMachineScaleSetVM) error

ParseVMSSResourceID extracts elements from a given VMSS resource ID with format: /subscriptions/mySubID/resourceGroups/myRG/providers/myProvider/virtualMachineScaleSets/myVMSS/virtualMachines/myInsID

func VirtualMachineScaleSetVMsViaAzureAPI added in v0.2.2

func VirtualMachineScaleSetVMsViaAzureAPI(subID, rg, clusterName string) (map[string]*VirtualMachineScaleSetVM, error)

func VirtualMachineScaleSetVMsViaKubeconfig

func VirtualMachineScaleSetVMsViaKubeconfig() (map[string]*VirtualMachineScaleSetVM, error)

Types

type CommonFlags

type CommonFlags struct {
	Verbose bool
}

CommonFlags contains CLI flags common for all subcommands

type OutputTruncate added in v0.2.1

type OutputTruncate int

type RunCommandResult added in v0.2.2

type RunCommandResult struct {
	Stdout string
	Stderr string
}

func RunCommand

func RunCommand(
	ctx context.Context,
	cred azcore.TokenCredential,
	vm *VirtualMachineScaleSetVM,
	command *string,
	timeout *int,
	outputTruncate OutputTruncate,
) (
	*RunCommandResult,
	error,
)

type SelectionResult added in v0.3.0

type SelectionResult struct {
	Cluster  string
	Node     string   // empty when AllNodes is true
	AllNodes bool     // true if user chose to target entire cluster
	Nodes    []string // populated when AllNodes is true
}

SelectionResult holds the user's interactive selection.

func InteractiveSelectNode added in v0.3.0

func InteractiveSelectNode(cfg *config.Config) (*SelectionResult, error)

InteractiveSelectNode prompts the user to pick a cluster and node. If a current cluster is set, it uses that cluster directly and only prompts for the node. Otherwise it prompts for both. Returns an error if stdin is not a terminal.

type VirtualMachineScaleSetVM

type VirtualMachineScaleSetVM struct {
	SubscriptionID    string
	NodeResourceGroup string
	VMScaleSet        string
	InstanceID        string
}

func VirtualMachineScaleSetVMFromConfig

func VirtualMachineScaleSetVMFromConfig() (*VirtualMachineScaleSetVM, error)

VirtualMachineScaleSetVMFromConfig returns a VirtualMachineScaleSetVM object it assumes that the config is set and valid

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL