-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bundle manifest URL to EKS-A version command (#5760)
- Loading branch information
1 parent
a319d43
commit 773fcc9
Showing
4 changed files
with
83 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
GitVersion string | ||
GitVersion string `json:"version"` | ||
BundleManifestURL string `json:"bundleManifestURL,omitempty"` | ||
} | ||
|
||
func Get() Info { | ||
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 | ||
} |