Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.3] 🐛 clusterctl: fix goproxy to also return versions for major > 1 #7728

Merged
Show file tree
Hide file tree
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
163 changes: 0 additions & 163 deletions cmd/clusterctl/client/repository/goproxy.go

This file was deleted.

100 changes: 0 additions & 100 deletions cmd/clusterctl/client/repository/goproxy_test.go

This file was deleted.

24 changes: 18 additions & 6 deletions cmd/clusterctl/client/repository/repository_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import (
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"strings"
"time"

"github.com/blang/semver"
"github.com/google/go-github/v45/github"
"github.com/pkg/errors"
"golang.org/x/oauth2"
Expand All @@ -36,6 +38,7 @@ import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
"sigs.k8s.io/cluster-api/internal/goproxy"
)

const (
Expand Down Expand Up @@ -70,7 +73,7 @@ type gitHubRepository struct {
rootPath string
componentsPath string
injectClient *github.Client
injectGoproxyClient *goproxyClient
injectGoproxyClient *goproxy.Client
}

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

func injectGoproxyClient(c *goproxyClient) githubRepositoryOption {
func injectGoproxyClient(c *goproxy.Client) githubRepositoryOption {
return func(g *gitHubRepository) {
g.injectGoproxyClient = c
}
Expand All @@ -110,11 +113,20 @@ func (g *gitHubRepository) GetVersions() ([]string, error) {

var versions []string
if goProxyClient != nil {
versions, err = goProxyClient.getVersions(context.TODO(), githubDomain, g.owner, g.repository)
// A goproxy is also able to handle the github repository path instead of the actual go module name.
gomodulePath := path.Join(githubDomain, g.owner, g.repository)

var parsedVersions semver.Versions
parsedVersions, err = goProxyClient.GetVersions(context.TODO(), gomodulePath)

// Log the error before fallback to github repository client happens.
if err != nil {
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)
}

for _, v := range parsedVersions {
versions = append(versions, "v"+v.String())
}
}

// Fallback to github repository client if goProxyClient is nil or an error occurred.
Expand Down Expand Up @@ -239,19 +251,19 @@ func (g *gitHubRepository) getClient() *github.Client {
// getGoproxyClient returns a go proxy client.
// It returns nil, nil if the environment variable is set to `direct` or `off`
// to skip goproxy requests.
func (g *gitHubRepository) getGoproxyClient() (*goproxyClient, error) {
func (g *gitHubRepository) getGoproxyClient() (*goproxy.Client, error) {
if g.injectGoproxyClient != nil {
return g.injectGoproxyClient, nil
}
scheme, host, err := getGoproxyHost(os.Getenv("GOPROXY"))
scheme, host, err := goproxy.GetSchemeAndHost(os.Getenv("GOPROXY"))
if err != nil {
return nil, err
}
// Don't return a client if scheme and host is set to empty string.
if scheme == "" && host == "" {
return nil, nil
}
return newGoproxyClient(scheme, host), nil
return goproxy.NewClient(scheme, host), nil
}

// setClientToken sets authenticatingHTTPClient field of gitHubRepository struct.
Expand Down
Loading