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

Get binary for specific version of EKS-A release in E2E tests #650

Merged
merged 3 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion internal/pkg/files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"os"
"path/filepath"
"strings"

"github.com/aws/eks-anywhere/pkg/logger"
)
Expand Down Expand Up @@ -46,7 +47,7 @@ func GzipFileDownloadExtract(uri, fileToExtract, destination string) error {
switch header.Typeflag {
case tar.TypeReg:
name := header.FileInfo().Name()
if name == fileToExtract {
if strings.TrimPrefix(name, "./") == fileToExtract {
out, err := os.OpenFile(targetFile, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode))
if err != nil {
return fmt.Errorf("error opening %s file: %v", fileToExtract, err)
Expand Down
28 changes: 14 additions & 14 deletions pkg/semver/semver.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@ func (v *Version) LessThan(v2 *Version) bool {
}

func (v *Version) Compare(v2 *Version) int {
if v.Major != v2.Major {
if v.Major > v2.Major {
return 1
}
return -1
if c := compare(v.Major, v2.Major); c != 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice this is very clear now

return c
}
if v.Minor != v2.Minor {
if v.Minor > v2.Minor {
return 1
}
return -1
if c := compare(v.Minor, v2.Minor); c != 0 {
return c
}
if v.Patch != v2.Patch {
if v.Patch > v2.Patch {
return 1
}
if c := compare(v.Patch, v2.Patch); c != 0 {
return c
}
return 0
}

func compare(i, i2 uint64) int {
if i > i2 {
return 1
} else if i < i2 {
return -1
}
return 0
Expand Down
48 changes: 43 additions & 5 deletions test/framework/releaseVersions.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package framework

import (
"fmt"
"os"
"path/filepath"

"github.com/aws/eks-anywhere/internal/pkg/files"
"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/semver"
"github.com/aws/eks-anywhere/pkg/validations"
releasev1alpha1 "github.com/aws/eks-anywhere/release/api/v1alpha1"
)

const prodReleasesManifest = "https://anywhere-assets.eks.amazonaws.com/releases/eks-a/manifest.yaml"
const (
prodReleasesManifest = "https://anywhere-assets.eks.amazonaws.com/releases/eks-a/manifest.yaml"
releaseBinaryName = "eksctl-anywhere"
)

func (e *ClusterE2ETest) GetLatestMinorReleaseFromMain() *releasev1alpha1.EksARelease {
func (e *ClusterE2ETest) GetLatestMinorReleaseFromMain() string {
reader := cluster.NewManifestReader()
e.T.Logf("Reading prod release manifest %s", prodReleasesManifest)
releases, err := reader.GetReleases(prodReleasesManifest)
Expand All @@ -28,10 +37,15 @@ func (e *ClusterE2ETest) GetLatestMinorReleaseFromMain() *releasev1alpha1.EksARe
e.T.Fatalf("Releases manifest doesn't contain latest release %s", releases.Spec.LatestVersion)
}

return latestRelease
binaryPath, err := e.getBinary(latestRelease)
if err != nil {
e.T.Fatalf("Failed getting binary for latest release: %s", err)
}

return binaryPath
}

func (e *ClusterE2ETest) GetLatestMinorReleaseFromReleaseBranch(releaseBranchVersion *semver.Version) *releasev1alpha1.EksARelease {
func (e *ClusterE2ETest) GetLatestMinorReleaseFromReleaseBranch(releaseBranchVersion *semver.Version) string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps this method should be "GetLatestMinorReleaseBinaryFromReleaseBranch" or "DownloadLatestMinorReleaseFromReleaseBranch" or something (I realize that's really long) that indicates that it not only gets the release object but actually downloads the binary itself

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I can change it to GetLatestMinorReleaseBinaryFromReleaseBranch because it'll only download the binary if it doesn't exist, but it'll always "get" the binary to use in the E2E test.

reader := cluster.NewManifestReader()
e.T.Logf("Reading prod release manifest %s", prodReleasesManifest)
releases, err := reader.GetReleases(prodReleasesManifest)
Expand Down Expand Up @@ -60,5 +74,29 @@ func (e *ClusterE2ETest) GetLatestMinorReleaseFromReleaseBranch(releaseBranchVer
e.T.Fatalf("Releases manifest doesn't contain a version of the previous minor release")
}

return latestPrevMinorRelease
binaryPath, err := e.getBinary(latestPrevMinorRelease)
if err != nil {
e.T.Fatalf("Failed getting binary for latest previous minor release: %s", err)
}

return binaryPath
}

func (e *ClusterE2ETest) getBinary(release *releasev1alpha1.EksARelease) (string, error) {
latestReleaseBinaryFolder := filepath.Join("bin", release.Version)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the directory will be in the format ./bin/v0.6.0/?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes!

latestReleaseBinaryPath := filepath.Join(latestReleaseBinaryFolder, releaseBinaryName)

if !validations.FileExists(latestReleaseBinaryPath) {
e.T.Logf("Downloading binary for EKS-A release [%s]", release.Version)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider logging the path as well (here and in the errors)

err := os.MkdirAll(latestReleaseBinaryFolder, os.ModePerm)
if err != nil {
return "", fmt.Errorf("failed creating directory for release [%s]: %s", release.Version, err)
}

err = files.GzipFileDownloadExtract(release.EksABinary.LinuxBinary.URI, releaseBinaryName, latestReleaseBinaryFolder)
if err != nil {
return "", fmt.Errorf("failed extracting binary for release [%s]: %s", release.Version, err)
}
}
return latestReleaseBinaryPath, nil
}