Skip to content

Commit

Permalink
Add bundle manifest URL to EKS-A version command (#5760)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhay-krishna authored Dec 15, 2023
1 parent a319d43 commit 773fcc9
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ eks-a-binary:
CGO_ENABLED=0 GOOS=$(GO_OS) GOARCH=$(GO_ARCH) $(GO) build $(BUILD_TAGS_ARG) $(LINKER_FLAGS_ARG) $(BUILD_FLAGS) -o $(OUTPUT_FILE) github.com/aws/eks-anywhere/cmd/eksctl-anywhere

.PHONY: eks-a-embed-config
eks-a-embed-config: $(EMBED_CONFIG_FOLDER)
eks-a-embed-config: ## Build a dev release version of eks-a with embed cluster spec config
cp pkg/cluster/config/releases.yaml $(EMBED_CONFIG_FOLDER)/releases.yaml
$(MAKE) eks-a-binary GIT_VERSION=$(DEV_GIT_VERSION) RELEASE_MANIFEST_URL=embed:///config/releases.yaml BUILD_TAGS='$(BUILD_TAGS) files_embed_fs'

.PHONY: eks-a-cross-platform-embed-latest-config
Expand All @@ -177,6 +179,7 @@ eks-a-cross-platform-embed-latest-config: ## Build cross platform dev release ve

.PHONY: eks-a-custom-embed-config
eks-a-custom-embed-config:
cp pkg/cluster/config/releases.yaml $(EMBED_CONFIG_FOLDER)/releases.yaml
$(MAKE) eks-a-binary GIT_VERSION=$(CUSTOM_GIT_VERSION) RELEASE_MANIFEST_URL=embed:///config/releases.yaml LINKER_FLAGS='-s -w -X github.com/aws/eks-anywhere/pkg/eksctl.enabled=true' BUILD_TAGS='$(BUILD_TAGS) files_embed_fs'

.PHONY: eks-a-cross-platform-custom-embed-latest-config
Expand Down
44 changes: 41 additions & 3 deletions cmd/eksctl-anywhere/cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,65 @@
package cmd

import (
"encoding/json"
"fmt"

"github.com/ghodss/yaml"
"github.com/spf13/cobra"

"github.com/aws/eks-anywhere/pkg/version"
)

type versionOptions struct {
output string
}

var vo = &versionOptions{}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Get the eksctl anywhere version",
Long: "This command prints the version of eksctl anywhere",
RunE: func(cmd *cobra.Command, args []string) error {
return printVersion()
return vo.printVersion()
},
}

func init() {
rootCmd.AddCommand(versionCmd)
versionCmd.Flags().StringVarP(&vo.output, "output", "o", "", "specifies the output format (valid option: json)")
}

func printVersion() error {
fmt.Println(version.Get().GitVersion)
func (vo *versionOptions) printVersion() error {
versionInfo, bundlesErr := version.GetFullVersionInfo()
switch vo.output {
case "":
fmt.Printf("Version: %s\n", versionInfo.GitVersion)
if bundlesErr != nil {
return fmt.Errorf("error getting bundle manifest URL for version %s: %v", versionInfo, bundlesErr)
}
fmt.Printf("Bundle Manifest URL: %s\n", versionInfo.BundleManifestURL)
case "json":
versionInfoJSON, unmarshalErr := json.Marshal(versionInfo)
if unmarshalErr != nil {
return fmt.Errorf("error marshaling version info to JSON: %v", unmarshalErr)
}
fmt.Printf("%s\n", versionInfoJSON)
if bundlesErr != nil {
return fmt.Errorf("error getting bundle manifest URL for version %s: %v", versionInfo, bundlesErr)
}
case "yaml":
versionInfoYAML, unmarshalErr := yaml.Marshal(versionInfo)
if unmarshalErr != nil {
return fmt.Errorf("error marshaling version info to YAML: %v", unmarshalErr)
}
fmt.Printf("%s\n", versionInfoYAML)
if bundlesErr != nil {
return fmt.Errorf("error getting bundle manifest URL for version %s: %v", versionInfo, bundlesErr)
}
default:
return fmt.Errorf("invalid output format: %s", vo.output)
}

return nil
}
16 changes: 16 additions & 0 deletions pkg/manifests/releases/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ func ReadReleasesFromURL(reader Reader, url string) (*releasev1.Release, error)
return release, nil
}

// GetBundleManifestURL fetches the bundle manifest URL pertaining to this
// release version of EKS Anywhere.
func GetBundleManifestURL(reader Reader, version string) (string, error) {
eksAReleases, err := ReadReleases(reader)
if err != nil {
return "", fmt.Errorf("failed to read releases: %v", err)
}

eksAReleaseForVersion, err := ReleaseForVersion(eksAReleases, version)
if err != nil {
return "", fmt.Errorf("failed to get EKS-A release for version %s: %v", version, err)
}

return eksAReleaseForVersion.BundleManifestUrl, nil
}

func ReadBundlesForRelease(reader Reader, release *releasev1.EksARelease) (*releasev1.Bundles, error) {

Check warning on line 60 in pkg/manifests/releases/read.go

View workflow job for this annotation

GitHub Actions / lint

exported: exported function ReadBundlesForRelease should have comment or be unexported (revive)
return bundles.Read(reader, release.BundleManifestUrl)
}
Expand Down
24 changes: 23 additions & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
package version

import (
"github.com/aws/eks-anywhere/pkg/files"
"github.com/aws/eks-anywhere/pkg/manifests/releases"
)

var gitVersion string

type Info struct {

Check warning on line 10 in pkg/version/version.go

View workflow job for this annotation

GitHub Actions / lint

exported: exported type Info should have comment or be unexported (revive)
GitVersion string
GitVersion string `json:"version"`
BundleManifestURL string `json:"bundleManifestURL,omitempty"`
}

func Get() Info {

Check warning on line 15 in pkg/version/version.go

View workflow job for this annotation

GitHub Actions / lint

exported: exported function Get should have comment or be unexported (revive)
return Info{
GitVersion: gitVersion,
}
}

// GetFullVersionInfo returns the complete version information for the
// EKS Anywhere, including Git version and bundle manifest URL
// associated with this release.
func GetFullVersionInfo() (Info, error) {
reader := files.NewReader(files.WithEKSAUserAgent("cli", gitVersion))
bundleManifestURL, err := releases.GetBundleManifestURL(reader, gitVersion)
if err != nil {
return Info{GitVersion: gitVersion}, err
}

return Info{
GitVersion: gitVersion,
BundleManifestURL: bundleManifestURL,
}, nil
}

0 comments on commit 773fcc9

Please sign in to comment.