@@ -23,10 +23,12 @@ import (
23
23
"net/http"
24
24
"net/url"
25
25
"os"
26
+ "path"
26
27
"path/filepath"
27
28
"strings"
28
29
"time"
29
30
31
+ "github.com/blang/semver"
30
32
"github.com/google/go-github/v45/github"
31
33
"github.com/pkg/errors"
32
34
"golang.org/x/oauth2"
@@ -36,6 +38,7 @@ import (
36
38
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
37
39
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
38
40
logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
41
+ "sigs.k8s.io/cluster-api/internal/goproxy"
39
42
)
40
43
41
44
const (
@@ -70,7 +73,7 @@ type gitHubRepository struct {
70
73
rootPath string
71
74
componentsPath string
72
75
injectClient * github.Client
73
- injectGoproxyClient * goproxyClient
76
+ injectGoproxyClient * goproxy. Client
74
77
}
75
78
76
79
var _ Repository = & gitHubRepository {}
@@ -83,7 +86,7 @@ func injectGithubClient(c *github.Client) githubRepositoryOption {
83
86
}
84
87
}
85
88
86
- func injectGoproxyClient (c * goproxyClient ) githubRepositoryOption {
89
+ func injectGoproxyClient (c * goproxy. Client ) githubRepositoryOption {
87
90
return func (g * gitHubRepository ) {
88
91
g .injectGoproxyClient = c
89
92
}
@@ -110,11 +113,20 @@ func (g *gitHubRepository) GetVersions() ([]string, error) {
110
113
111
114
var versions []string
112
115
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
+
114
122
// Log the error before fallback to github repository client happens.
115
123
if err != nil {
116
124
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 )
117
125
}
126
+
127
+ for _ , v := range parsedVersions {
128
+ versions = append (versions , "v" + v .String ())
129
+ }
118
130
}
119
131
120
132
// Fallback to github repository client if goProxyClient is nil or an error occurred.
@@ -239,19 +251,19 @@ func (g *gitHubRepository) getClient() *github.Client {
239
251
// getGoproxyClient returns a go proxy client.
240
252
// It returns nil, nil if the environment variable is set to `direct` or `off`
241
253
// to skip goproxy requests.
242
- func (g * gitHubRepository ) getGoproxyClient () (* goproxyClient , error ) {
254
+ func (g * gitHubRepository ) getGoproxyClient () (* goproxy. Client , error ) {
243
255
if g .injectGoproxyClient != nil {
244
256
return g .injectGoproxyClient , nil
245
257
}
246
- scheme , host , err := getGoproxyHost (os .Getenv ("GOPROXY" ))
258
+ scheme , host , err := goproxy . GetSchemeAndHost (os .Getenv ("GOPROXY" ))
247
259
if err != nil {
248
260
return nil , err
249
261
}
250
262
// Don't return a client if scheme and host is set to empty string.
251
263
if scheme == "" && host == "" {
252
264
return nil , nil
253
265
}
254
- return newGoproxyClient (scheme , host ), nil
266
+ return goproxy . NewClient (scheme , host ), nil
255
267
}
256
268
257
269
// setClientToken sets authenticatingHTTPClient field of gitHubRepository struct.
0 commit comments