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

fix: hgctl latest version bug #816

Merged
merged 2 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 11 additions & 2 deletions pkg/cmd/hgctl/helm/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ func locateChart(cpOpts *action.ChartPathOptions, name string, settings *cli.Env
return fileAbsPath, nil
}

func ParseLatestVersion(repoUrl string, version string) (string, error) {
func ParseLatestVersion(repoUrl string, version string, devel bool) (string, error) {

cpOpts := &action.ChartPathOptions{
RepoURL: repoUrl,
Expand Down Expand Up @@ -632,7 +632,16 @@ func ParseLatestVersion(repoUrl string, version string) (string, error) {

// get higress helm chart latest version
if entries, ok := indexFile.Entries[RepoChartIndexYamlHigressIndex]; ok {
return entries[0].AppVersion, nil
if devel {
return entries[0].AppVersion, nil
}

if chatVersion, err := indexFile.Get(RepoChartIndexYamlHigressIndex, ""); err != nil {
return "", errors.New("can't find higress latest version")
} else {
return chatVersion.Version, nil
}

}

return "", errors.New("can't find higress latest version")
Expand Down
9 changes: 6 additions & 3 deletions pkg/cmd/hgctl/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type InstallArgs struct {
Set []string
// ManifestsPath is a path to a ManifestsPath and profiles directory in the local filesystem with a release tgz.
ManifestsPath string
// Devel if set true when version is latest, it will get latest version, otherwise it will get latest stable version
Devel bool
}

func (a *InstallArgs) String() string {
Expand All @@ -67,6 +69,7 @@ func addInstallFlags(cmd *cobra.Command, args *InstallArgs) {
cmd.PersistentFlags().StringSliceVarP(&args.InFilenames, "filename", "f", nil, filenameFlagHelpStr)
cmd.PersistentFlags().StringArrayVarP(&args.Set, "set", "s", nil, setFlagHelpStr)
cmd.PersistentFlags().StringVarP(&args.ManifestsPath, "manifests", "d", "", manifestsFlagHelpStr)
cmd.PersistentFlags().BoolVar(&args.Devel, "devel", false, "use development versions (alpha, beta, and release candidate releases), If version is set, this is ignored")
}

// --manifests is an alias for --set installPackagePath=
Expand Down Expand Up @@ -141,7 +144,7 @@ func install(writer io.Writer, iArgs *InstallArgs) error {
return err
}

err = installManifests(profile, writer)
err = installManifests(profile, writer, iArgs.Devel)
if err != nil {
return fmt.Errorf("failed to install manifests: %v", err)
}
Expand Down Expand Up @@ -192,8 +195,8 @@ func promptProfileName(writer io.Writer) string {

}

func installManifests(profile *helm.Profile, writer io.Writer) error {
installer, err := installer.NewInstaller(profile, writer, false)
func installManifests(profile *helm.Profile, writer io.Writer, devel bool) error {
installer, err := installer.NewInstaller(profile, writer, false, devel, installer.InstallInstallerMode)
if err != nil {
return err
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/cmd/hgctl/installer/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type ComponentOptions struct {
Quiet bool
// Capabilities
Capabilities *chartutil.Capabilities
// devel
Devel bool
}

type ComponentOption func(*ComponentOptions)
Expand Down Expand Up @@ -98,6 +100,12 @@ func WithQuiet() ComponentOption {
}
}

func WithDevel(devel bool) ComponentOption {
return func(opts *ComponentOptions) {
opts.Devel = devel
}
}

func renderComponentManifest(spec any, renderer helm.Renderer, addOn bool, name ComponentName, namespace string) (string, error) {
var valsBytes []byte
var valsYaml string
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/hgctl/installer/higress.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (h *HigressComponent) Run() error {
// Parse latest version
if h.opts.Version == helm.RepoLatestVersion {

latestVersion, err := helm.ParseLatestVersion(h.opts.RepoURL, h.opts.Version)
latestVersion, err := helm.ParseLatestVersion(h.opts.RepoURL, h.opts.Version, h.opts.Devel)
if err != nil {
return err
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/cmd/hgctl/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"k8s.io/client-go/util/homedir"
)

type InstallerMode int32

const (
HgctlHomeDirPath = ".hgctl"
StandaloneInstalledPath = "higress-standalone"
Expand All @@ -37,20 +39,26 @@ const (
DefaultIstioNamespace = "istio-system"
)

const (
InstallInstallerMode InstallerMode = iota
UpgradeInstallerMode
UninstallInstallerMode
)

type Installer interface {
Install() error
UnInstall() error
Upgrade() error
}

func NewInstaller(profile *helm.Profile, writer io.Writer, quiet bool) (Installer, error) {
func NewInstaller(profile *helm.Profile, writer io.Writer, quiet bool, devel bool, installerMode InstallerMode) (Installer, error) {
switch profile.Global.Install {
case helm.InstallK8s, helm.InstallLocalK8s:
cliClient, err := kubernetes.NewCLIClient(options.DefaultConfigFlags.ToRawKubeConfigLoader())
if err != nil {
return nil, fmt.Errorf("failed to build kubernetes client: %w", err)
}
installer, err := NewK8sInstaller(profile, cliClient, writer, quiet)
installer, err := NewK8sInstaller(profile, cliClient, writer, quiet, devel, installerMode)
return installer, err
case helm.InstallLocalDocker:
installer, err := NewDockerInstaller(profile, writer, quiet)
Expand Down
10 changes: 8 additions & 2 deletions pkg/cmd/hgctl/installer/installer_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (o *K8sInstaller) isNamespacedObject(obj *object.K8sObject) bool {
return false
}

func NewK8sInstaller(profile *helm.Profile, cli kubernetes.CLIClient, writer io.Writer, quiet bool) (*K8sInstaller, error) {
func NewK8sInstaller(profile *helm.Profile, cli kubernetes.CLIClient, writer io.Writer, quiet bool, devel bool, installerMode InstallerMode) (*K8sInstaller, error) {
if profile == nil {
return nil, errors.New("install profile is empty")
}
Expand All @@ -267,14 +267,20 @@ func NewK8sInstaller(profile *helm.Profile, cli kubernetes.CLIClient, writer io.
}
fmt.Fprintf(writer, "%s\n", capabilities.KubeVersion.Version)
// initialize components
higressVersion := profile.Charts.Higress.Version
if installerMode == UninstallInstallerMode {
// uninstall
higressVersion = profile.HigressVersion
}
components := make(map[ComponentName]Component)
opts := []ComponentOption{
WithComponentNamespace(profile.Global.Namespace),
WithComponentChartPath(profile.InstallPackagePath),
WithComponentVersion(profile.Charts.Higress.Version),
WithComponentVersion(higressVersion),
WithComponentRepoURL(profile.Charts.Higress.Url),
WithComponentChartName(profile.Charts.Higress.Name),
WithComponentCapabilities(capabilities),
WithDevel(devel),
}
if quiet {
opts = append(opts, WithQuiet())
Expand Down
9 changes: 6 additions & 3 deletions pkg/cmd/hgctl/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type ManifestArgs struct {
Set []string
// ManifestsPath is a path to a ManifestsPath and profiles directory in the local filesystem with a release tgz.
ManifestsPath string
// Devel if set true when version is latest, it will get latest version, otherwise it will get latest stable version
Devel bool
}

func (a *ManifestArgs) String() string {
Expand Down Expand Up @@ -70,6 +72,7 @@ func addManifestFlags(cmd *cobra.Command, args *ManifestArgs) {
cmd.PersistentFlags().StringSliceVarP(&args.InFilenames, "filename", "f", nil, filenameFlagHelpStr)
cmd.PersistentFlags().StringArrayVarP(&args.Set, "set", "s", nil, setFlagHelpStr)
cmd.PersistentFlags().StringVarP(&args.ManifestsPath, "manifests", "d", "", manifestsFlagHelpStr)
cmd.PersistentFlags().BoolVar(&args.Devel, "devel", false, "use development versions (alpha, beta, and release candidate releases), If version is set, this is ignored")
}

// newManifestGenerateCmd generates a higress install manifest and applies it to a cluster
Expand Down Expand Up @@ -113,20 +116,20 @@ func generate(writer io.Writer, iArgs *ManifestArgs) error {
return err
}

err = genManifests(profile, writer)
err = genManifests(profile, writer, iArgs.Devel)
if err != nil {
return fmt.Errorf("failed to install manifests: %v", err)
}
return nil
}

func genManifests(profile *helm.Profile, writer io.Writer) error {
func genManifests(profile *helm.Profile, writer io.Writer, devel bool) error {
cliClient, err := kubernetes.NewCLIClient(options.DefaultConfigFlags.ToRawKubeConfigLoader())
if err != nil {
return fmt.Errorf("failed to build kubernetes client: %w", err)
}

op, err := installer.NewK8sInstaller(profile, cliClient, writer, true)
op, err := installer.NewK8sInstaller(profile, cliClient, writer, true, devel, installer.InstallInstallerMode)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/hgctl/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func promptUninstall(writer io.Writer) bool {
}

func uninstallManifests(profile *helm.Profile, writer io.Writer, uiArgs *uninstallArgs) error {
installer, err := installer.NewInstaller(profile, writer, false)
installer, err := installer.NewInstaller(profile, writer, false, false, installer.UninstallInstallerMode)
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/cmd/hgctl/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func addUpgradeFlags(cmd *cobra.Command, args *upgradeArgs) {
cmd.PersistentFlags().StringSliceVarP(&args.InFilenames, "filename", "f", nil, filenameFlagHelpStr)
cmd.PersistentFlags().StringArrayVarP(&args.Set, "set", "s", nil, setFlagHelpStr)
cmd.PersistentFlags().StringVarP(&args.ManifestsPath, "manifests", "d", "", manifestsFlagHelpStr)
cmd.PersistentFlags().BoolVar(&args.Devel, "devel", false, "use development versions (alpha, beta, and release candidate releases), If version is set, this is ignored")
}

// newUpgradeCmd upgrades Istio control plane in-place with eligibility checks.
Expand Down Expand Up @@ -91,7 +92,7 @@ func upgrade(writer io.Writer, iArgs *InstallArgs) error {
return nil
}

err = upgradeManifests(profile, writer)
err = upgradeManifests(profile, writer, iArgs.Devel)
if err != nil {
return err
}
Expand Down Expand Up @@ -120,8 +121,8 @@ func promptUpgrade(writer io.Writer) bool {
}
}

func upgradeManifests(profile *helm.Profile, writer io.Writer) error {
installer, err := installer.NewInstaller(profile, writer, false)
func upgradeManifests(profile *helm.Profile, writer io.Writer, devel bool) error {
installer, err := installer.NewInstaller(profile, writer, false, devel, installer.UpgradeInstallerMode)
if err != nil {
return err
}
Expand Down
Loading