avoid conflict with the update package flags

pull/21394/head
Predrag Rogic 2025-08-21 22:59:57 +01:00 committed by Medya Ghazizadeh
parent 2c53bac3d7
commit 2433c7978c
1 changed files with 12 additions and 2 deletions

View File

@ -18,18 +18,18 @@ package main
import (
"context"
"os"
"strings"
"github.com/google/go-github/v74/github"
"k8s.io/klog/v2"
"k8s.io/minikube/hack/update"
)
// recentK8sVersions returns the most recent k8s version, usually around 100.
func recentK8sVersions() ([]string, error) {
const k8s = "kubernetes"
ghc := update.GHClient()
ghc := ghClient()
list, _, err := ghc.Repositories.ListReleases(context.Background(), k8s, k8s, &github.ListOptions{PerPage: 100})
if err != nil {
return nil, err
@ -45,3 +45,13 @@ func recentK8sVersions() ([]string, error) {
klog.InfoS("Got releases", "releases", releases)
return releases, nil
}
// ghClient returns a GitHub client regardless of whether the GITHUB_TOKEN is set or not.
// NOTE: do NOT use "k8s.io/minikube/hack/update" instead, as its flags will conflict with the ones from this package
func ghClient() *github.Client {
if os.Getenv("GITHUB_TOKEN") == "" {
return github.NewClient(nil)
}
return github.NewClient(nil).WithAuthToken(os.Getenv("GITHUB_TOKEN"))
}