Skip to content

Commit

Permalink
minor code improvements.
Browse files Browse the repository at this point in the history
Signed-off-by: muhammad adil ghaffar <muhammad.adil.ghaffar@est.tech>
  • Loading branch information
adilGhaffarDev committed Dec 12, 2023
1 parent bcae803 commit d339128
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 41 deletions.
27 changes: 1 addition & 26 deletions test/e2e/clusterctl_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"fmt"

. "github.com/onsi/ginkgo/v2"
"k8s.io/utils/ptr"
. "github.com/onsi/gomega"
"k8s.io/utils/ptr"
)

var (
Expand All @@ -46,13 +46,8 @@ var _ = Describe("When testing clusterctl upgrades (v1.0=>current)", func() {
BootstrapClusterProxy: bootstrapClusterProxy,
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
<<<<<<< HEAD
InfrastructureProvider: ptr.To("docker"),
InitWithBinary: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.0.5/clusterctl-{OS}-{ARCH}",
=======
InfrastructureProvider: pointer.String("docker"),
InitWithBinary: fmt.Sprintf(clusterctlDownloadURL, stableRelease),
>>>>>>> 579c6948e2 (Resolve release markers)
// We have to pin the providers because with `InitWithProvidersContract` the test would
// use the latest version for the contract (which is v1.3.X for v1beta1).
InitWithCoreProvider: fmt.Sprintf(providerCAPIPrefix, stableRelease),
Expand Down Expand Up @@ -84,13 +79,8 @@ var _ = Describe("When testing clusterctl upgrades (v1.4=>current)", func() {
BootstrapClusterProxy: bootstrapClusterProxy,
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
<<<<<<< HEAD
InfrastructureProvider: ptr.To("docker"),
InitWithBinary: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.4.5/clusterctl-{OS}-{ARCH}",
=======
InfrastructureProvider: pointer.String("docker"),
InitWithBinary: fmt.Sprintf(clusterctlDownloadURL, stableRelease),
>>>>>>> 579c6948e2 (Resolve release markers)
// We have to pin the providers because with `InitWithProvidersContract` the test would
// use the latest version for the contract (which is v1.5.X for v1beta1).
InitWithCoreProvider: fmt.Sprintf(providerCAPIPrefix, stableRelease),
Expand Down Expand Up @@ -119,13 +109,8 @@ var _ = Describe("When testing clusterctl upgrades using ClusterClass (v1.4=>cur
BootstrapClusterProxy: bootstrapClusterProxy,
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
<<<<<<< HEAD
InfrastructureProvider: ptr.To("docker"),
InitWithBinary: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.4.5/clusterctl-{OS}-{ARCH}",
=======
InfrastructureProvider: pointer.String("docker"),
InitWithBinary: fmt.Sprintf(clusterctlDownloadURL, stableRelease),
>>>>>>> 579c6948e2 (Resolve release markers)
// We have to pin the providers because with `InitWithProvidersContract` the test would
// use the latest version for the contract (which is v1.5.X for v1beta1).
InitWithCoreProvider: fmt.Sprintf(providerCAPIPrefix, stableRelease),
Expand Down Expand Up @@ -154,13 +139,8 @@ var _ = Describe("When testing clusterctl upgrades (v1.5=>current)", func() {
BootstrapClusterProxy: bootstrapClusterProxy,
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
<<<<<<< HEAD
InfrastructureProvider: ptr.To("docker"),
InitWithBinary: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.5.0/clusterctl-{OS}-{ARCH}",
=======
InfrastructureProvider: pointer.String("docker"),
InitWithBinary: fmt.Sprintf(clusterctlDownloadURL, stableRelease),
>>>>>>> 579c6948e2 (Resolve release markers)
InitWithProvidersContract: "v1beta1",
// NOTE: If this version is changed here the image and SHA must also be updated in all DockerMachineTemplates in `test/e2e/data/infrastructure-docker/v1.5/bases.
InitWithKubernetesVersion: "v1.28.0",
Expand All @@ -183,13 +163,8 @@ var _ = Describe("When testing clusterctl upgrades using ClusterClass (v1.5=>cur
BootstrapClusterProxy: bootstrapClusterProxy,
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
<<<<<<< HEAD
InfrastructureProvider: ptr.To("docker"),
InitWithBinary: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.5.0/clusterctl-{OS}-{ARCH}",
=======
InfrastructureProvider: pointer.String("docker"),
InitWithBinary: fmt.Sprintf(clusterctlDownloadURL, stableRelease),
>>>>>>> 579c6948e2 (Resolve release markers)
InitWithProvidersContract: "v1beta1",
// NOTE: If this version is changed here the image and SHA must also be updated in all DockerMachineTemplates in `test/e2e/data/infrastructure-docker/v1.5/bases.
InitWithKubernetesVersion: "v1.28.0",
Expand Down
22 changes: 7 additions & 15 deletions test/framework/clusterctl/e2e_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,6 @@ type Files struct {

// ResolveReleases converts release markers to release version.
func (c *E2EConfig) ResolveReleases() error {
scheme, host, err := goproxy.GetSchemeAndHost(os.Getenv("GOPROXY"))
if err != nil {
return err
}
if scheme == "" || host == "" {
return fmt.Errorf("releasemarker does not support disabling the go proxy: GOPROXY=%q", os.Getenv("GOPROXY"))
}
goproxyClient := goproxy.NewClient(scheme, host)
for i := range c.Providers {
provider := &c.Providers[i]
for j := range provider.Versions {
Expand All @@ -270,9 +262,9 @@ func (c *E2EConfig) ResolveReleases() error {
continue
}
releaseMarker := strings.TrimLeft(strings.TrimRight(version.Name, "}"), "{")
ver, err := resolveReleaseMarker(releaseMarker, goproxyClient)
ver, err := ResolveRelease(releaseMarker)
if err != nil {
return errors.Wrapf(err, "Failed resolving release url %q", version.Name)
return errors.Wrapf(err, "failed resolving release url %q", version.Name)
}
ver = "v" + ver
version.Value = strings.Replace(version.Value, version.Name, ver, 1)
Expand All @@ -288,7 +280,7 @@ func ResolveRelease(releaseMarker string) (string, error) {
return "", err
}
if scheme == "" || host == "" {
return "", fmt.Errorf("releasemarker does not support disabling the go proxy: GOPROXY=%q", os.Getenv("GOPROXY"))
return "", errors.Errorf("releasemarker does not support disabling the go proxy: GOPROXY=%q", os.Getenv("GOPROXY"))
}
goproxyClient := goproxy.NewClient(scheme, host)
return resolveReleaseMarker(releaseMarker, goproxyClient)
Expand All @@ -299,17 +291,17 @@ func ResolveRelease(releaseMarker string) (string, error) {
// - Resolves "go://sigs.k8s.io/cluster-api@latest-v1.0" to the latest patch release of v.1.0 including rc and pre releases.
func resolveReleaseMarker(releaseMarker string, goproxyClient *goproxy.Client) (string, error) {
if !strings.HasPrefix(releaseMarker, "go://") {
return "", errors.Errorf("Unknown release marker scheme")
return "", errors.Errorf("unknown release marker scheme")
}

releaseMarker = strings.TrimPrefix(releaseMarker, "go://")
if releaseMarker == "" {
return "", errors.New("Empty release url")
return "", errors.New("empty release url")
}

gomoduleParts := strings.Split(releaseMarker, "@")
if len(gomoduleParts) < 2 {
return "", errors.Errorf("Go module or version missing")
return "", errors.Errorf("go module or version missing")
}
gomodule := gomoduleParts[0]

Expand All @@ -321,7 +313,7 @@ func resolveReleaseMarker(releaseMarker string, goproxyClient *goproxy.Client) (
version = strings.TrimPrefix(version, "v")
minSemVersion, err := semver.Parse(version)
if err != nil {
return "", errors.Wrapf(err, "Parsing semver for %s", version)
return "", errors.Wrapf(err, "parsing semver for %s", version)
}
maxSemVersion := minSemVersion
maxSemVersion.Minor++
Expand Down
8 changes: 8 additions & 0 deletions test/framework/clusterctl/e2e_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func Test_resolveReleaseMarker(t *testing.T) {
goproxytest.HTTPTestMethod(t, r, "GET")
fmt.Fprint(w, "v1.2.0\n")
fmt.Fprint(w, "v1.2.1-rc.0\n")
fmt.Fprint(w, "v1.3.0-rc.0\n")
fmt.Fprint(w, "v1.3.0-rc.1\n")
})
tests := []struct {
name string
Expand All @@ -62,6 +64,12 @@ func Test_resolveReleaseMarker(t *testing.T) {
want: "1.2.1-rc.0",
wantErr: false,
},
{
name: "Get stable release when there is no stable release in given minor",
releaseMarker: "go://github.com/o/r1@v1.3",
want: "1.2.0",
wantErr: false,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit d339128

Please sign in to comment.