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

EVEREST-1729 | check CLI constraints from VS during install #1021

Merged
merged 9 commits into from
Jan 24, 2025
16 changes: 16 additions & 0 deletions pkg/cli/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,28 @@ func (o *Install) setVersionInfo(ctx context.Context) error {
if err != nil {
return err
}

supVer, err := common.NewSupportedVersion(latestMeta)
if err != nil {
return err
}
if err := o.checkRequirements(supVer); err != nil {
return err
}
mayankshah1607 marked this conversation as resolved.
Show resolved Hide resolved

o.l.Debugf("Everest latest version available: %s", latest)
o.l.Debugf("Everest version information %#v", latestMeta)
o.installVersion = latest.String()
return nil
}

func (o *Install) checkRequirements(supVer *common.SupportedVersion) error {
if err := cliutils.VerifyCLIVersion(supVer); err != nil {
return err
}
return nil
}

func (o *Install) setupHelmInstaller(ctx context.Context) error {
nsExists, err := o.namespaceExists(ctx, common.SystemNamespace)
if err != nil {
Expand Down
20 changes: 2 additions & 18 deletions pkg/cli/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,25 +377,9 @@ func (u *Upgrade) verifyRequirements(ctx context.Context, meta *version.Metadata
func (u *Upgrade) checkRequirements(ctx context.Context, supVer *common.SupportedVersion) error {
// TODO: olm, catalog to be implemented.

// cli version check.
if cliVersion.Version != "" {
u.l.Infof("Checking cli version requirements")
cli, err := goversion.NewVersion(cliVersion.Version)
if err != nil {
return errors.Join(err, fmt.Errorf("invalid cli version %s", cliVersion.Version))
}

if !supVer.Cli.Check(cli.Core()) {
return fmt.Errorf(
"cli version %q does not meet minimum requirements of %q",
cli, supVer.Cli.String(),
)
}
u.l.Debugf("cli version %q meets requirements %q", cli, supVer.Cli.String())
} else {
u.l.Debug("cli version is empty")
if err := cliutils.VerifyCLIVersion(supVer); err != nil {
return err
}

// Operator version check.
if err := u.checkOperatorRequirements(ctx, supVer); err != nil {
return err
Expand Down
20 changes: 20 additions & 0 deletions pkg/cli/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ package utils
import (
"context"
"errors"
"fmt"
"net/url"
"path"

goversion "github.com/hashicorp/go-version"
"go.uber.org/zap"
k8serrors "k8s.io/apimachinery/pkg/api/errors"

Expand Down Expand Up @@ -61,3 +63,21 @@ func NewKubeclient(l *zap.SugaredLogger, kubeconfigPath string) (*kubernetes.Kub
}
return k, nil
}

// VerifyCLIVersion checks if the CLI version satisfies the constraints.
func VerifyCLIVersion(supVer *common.SupportedVersion) error {
if version.Version == "" {
return nil
}
cli, err := goversion.NewVersion(version.Version)
if err != nil {
return fmt.Errorf("failed to parse CLI version: %w", err)
}
if !supVer.Cli.Check(cli.Core()) {
return fmt.Errorf(
"cli version %q does not satisfy the constraints %q",
cli, supVer.Cli.String(),
)
}
return nil
}
Loading