Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ func main() {
klog.ErrorS(err, "failed to validate and apply logging configuration")
}

// If only the --version flag was requested, print version and exit before
// performing any initialization that may require contacting external
// services (IMDS/Kubernetes API). This allows `--version` to work in
// environments without metadata available (e.g., local/lab machines).
if *version {
versionInfo, versionErr := driver.GetVersionJSON()
if versionErr != nil {
klog.ErrorS(err, "failed to get version")
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
}
//nolint:forbidigo // Print version info without klog/timestamp
fmt.Println(versionInfo)
os.Exit(0)
}

var cloud cloudPkg.Cloud
var k8sClient kubernetes.Interface
var md metadata.MetadataService
Expand Down Expand Up @@ -160,17 +175,6 @@ func main() {
klog.FlushAndExit(klog.ExitFlushTimeout, 0)
}

if *version {
versionInfo, versionErr := driver.GetVersionJSON()
if versionErr != nil {
klog.ErrorS(err, "failed to get version")
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
}
//nolint:forbidigo // Print version info without klog/timestamp
fmt.Println(versionInfo)
os.Exit(0)
}

if *toStderr {
klog.SetOutput(os.Stderr)
}
Expand Down