Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Nov 15, 2022
1 parent ea2e4e2 commit f54300e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 1 addition & 3 deletions cmd/clusterctl/client/cluster/cert_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package cluster
import (
"context"
_ "embed"
"strings"
"time"

"github.com/blang/semver"
Expand Down Expand Up @@ -403,8 +402,7 @@ func (cm *certManagerClient) getManifestObjs(certManagerConfig config.CertManage
// we are using the same machinery to retrieve the file by using a fake provider object using
// the cert manager repository url.
// In order to avoid unnecessary calls to GitHub API, "latest" is replace with the version currently installed by clusterctl.
url := strings.Replace(certManagerConfig.URL(), "latest", certManagerConfig.Version(), 1)
certManagerFakeProvider := config.NewProvider("cert-manager", url, "")
certManagerFakeProvider := config.NewProvider("cert-manager", certManagerConfig.URL(), "")
certManagerRepository, err := cm.repositoryClientFactory(certManagerFakeProvider, cm.configClient)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/client/config/cert_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package config
// CertManager defines cert-manager configuration.
type CertManager interface {
// URL returns the name of the cert-manager repository.
// If empty, "https://github.com/cert-manager/cert-manager/releases/latest/cert-manager.yaml" will be used.
// If empty, "https://github.com/cert-manager/cert-manager/releases/{DefaultVersion}/cert-manager.yaml" will be used.
URL() string

// Version returns the cert-manager version to install.
Expand Down
4 changes: 2 additions & 2 deletions cmd/clusterctl/client/config/cert_manager_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const (
CertManagerDefaultVersion = "v1.9.1"

// CertManagerDefaultURL defines the default cert-manager repository url to be used by clusterctl.
// NOTE: At runtime /latest will be replaced with the CertManagerDefaultVersion or with the
// NOTE: At runtime CertManagerDefaultVersion may be replaced with the
// version defined by the user in the clusterctl configuration file.
CertManagerDefaultURL = "https://github.com/cert-manager/cert-manager/releases/latest/cert-manager.yaml"
CertManagerDefaultURL = "https://github.com/cert-manager/cert-manager/releases/" + CertManagerDefaultVersion + "/cert-manager.yaml"

// CertManagerDefaultTimeout defines the default cert-manager timeout to be used by clusterctl.
CertManagerDefaultTimeout = 10 * time.Minute
Expand Down
10 changes: 6 additions & 4 deletions cmd/clusterctl/client/repository/goproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,28 @@ func (g *goproxyClient) getVersions(ctx context.Context, base, owner, repository
var rawResponse []byte
var retryError error
_ = wait.PollImmediateWithContext(ctx, retryableOperationInterval, retryableOperationTimeout, func(ctx context.Context) (bool, error) {
retryError = nil
req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL.String(), http.NoBody)
if err != nil {
return false, errors.Wrapf(err, "failed to create request")
return false, errors.Wrapf(err, "failed to get versions: failed to create request")
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
retryError = errors.Wrapf(err, "failed to get versions")
retryError = errors.Wrapf(err, "failed to get versions: failed to do request")
return false, nil
}
defer resp.Body.Close()

if resp.StatusCode != 200 {
retryError = errors.Errorf("Request status code %d: %s", resp.StatusCode, resp.Status)
retryError = errors.Errorf("failed to get versions: request status code %d", resp.StatusCode)
return false, nil
}

rawResponse, err = io.ReadAll(resp.Body)
if err != nil {
return false, errors.Wrap(err, "error reading goproxy response body")
retryError = errors.Wrap(err, "failed to get versions: error reading goproxy response body")
return false, nil
}
return true, nil
})
Expand Down

0 comments on commit f54300e

Please sign in to comment.