Skip to content

Commit 128e6fc

Browse files
committed
clusterctl: fix goproxy to also return versions for major > 1
Also: * moves goproxy functionality to an internal package * reuses the package also for releaselink * fixes releaselink references for aws
1 parent f73b00d commit 128e6fc

File tree

12 files changed

+481
-296
lines changed

12 files changed

+481
-296
lines changed

cmd/clusterctl/client/repository/goproxy.go

Lines changed: 0 additions & 163 deletions
This file was deleted.

cmd/clusterctl/client/repository/goproxy_test.go

Lines changed: 0 additions & 100 deletions
This file was deleted.

cmd/clusterctl/client/repository/repository_github.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ import (
2323
"net/http"
2424
"net/url"
2525
"os"
26+
"path"
2627
"path/filepath"
2728
"strings"
2829
"time"
2930

31+
"github.com/blang/semver"
3032
"github.com/google/go-github/v45/github"
3133
"github.com/pkg/errors"
3234
"golang.org/x/oauth2"
@@ -36,6 +38,7 @@ import (
3638
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3739
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
3840
logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
41+
"sigs.k8s.io/cluster-api/internal/goproxy"
3942
)
4043

4144
const (
@@ -70,7 +73,7 @@ type gitHubRepository struct {
7073
rootPath string
7174
componentsPath string
7275
injectClient *github.Client
73-
injectGoproxyClient *goproxyClient
76+
injectGoproxyClient *goproxy.Client
7477
}
7578

7679
var _ Repository = &gitHubRepository{}
@@ -83,7 +86,7 @@ func injectGithubClient(c *github.Client) githubRepositoryOption {
8386
}
8487
}
8588

86-
func injectGoproxyClient(c *goproxyClient) githubRepositoryOption {
89+
func injectGoproxyClient(c *goproxy.Client) githubRepositoryOption {
8790
return func(g *gitHubRepository) {
8891
g.injectGoproxyClient = c
8992
}
@@ -110,11 +113,20 @@ func (g *gitHubRepository) GetVersions() ([]string, error) {
110113

111114
var versions []string
112115
if goProxyClient != nil {
113-
versions, err = goProxyClient.getVersions(context.TODO(), githubDomain, g.owner, g.repository)
116+
// A goproxy is also able to handle the github repository path instead of the actual go module name.
117+
gomodulePath := path.Join(githubDomain, g.owner, g.repository)
118+
119+
var parsedVersions semver.Versions
120+
parsedVersions, err = goProxyClient.GetVersions(context.TODO(), gomodulePath)
121+
114122
// Log the error before fallback to github repository client happens.
115123
if err != nil {
116124
log.V(5).Info("error using Goproxy client to list versions for repository, falling back to github client", "owner", g.owner, "repository", g.repository, "error", err)
117125
}
126+
127+
for _, v := range parsedVersions {
128+
versions = append(versions, "v"+v.String())
129+
}
118130
}
119131

120132
// Fallback to github repository client if goProxyClient is nil or an error occurred.
@@ -239,19 +251,19 @@ func (g *gitHubRepository) getClient() *github.Client {
239251
// getGoproxyClient returns a go proxy client.
240252
// It returns nil, nil if the environment variable is set to `direct` or `off`
241253
// to skip goproxy requests.
242-
func (g *gitHubRepository) getGoproxyClient() (*goproxyClient, error) {
254+
func (g *gitHubRepository) getGoproxyClient() (*goproxy.Client, error) {
243255
if g.injectGoproxyClient != nil {
244256
return g.injectGoproxyClient, nil
245257
}
246-
scheme, host, err := getGoproxyHost(os.Getenv("GOPROXY"))
258+
scheme, host, err := goproxy.GetSchemeAndHost(os.Getenv("GOPROXY"))
247259
if err != nil {
248260
return nil, err
249261
}
250262
// Don't return a client if scheme and host is set to empty string.
251263
if scheme == "" && host == "" {
252264
return nil, nil
253265
}
254-
return newGoproxyClient(scheme, host), nil
266+
return goproxy.NewClient(scheme, host), nil
255267
}
256268

257269
// setClientToken sets authenticatingHTTPClient field of gitHubRepository struct.

0 commit comments

Comments
 (0)