Skip to content

Commit

Permalink
EVEREST-1729 | check CLI constraints from VS during install (#1021)
Browse files Browse the repository at this point in the history
Signed-off-by: Mayank Shah <[email protected]>
  • Loading branch information
mayankshah1607 authored Jan 24, 2025
1 parent cda344f commit d2e96df
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
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
}

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
}

0 comments on commit d2e96df

Please sign in to comment.