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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions pkg/cli/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,21 @@ func (o *Install) setVersionInfo(ctx context.Context) error {
o.l.Debugf("Everest latest version available: %s", latest)
o.l.Debugf("Everest version information %#v", latestMeta)
o.installVersion = latest.String()

supVer, err := common.NewSupportedVersion(latestMeta)
if err != nil {
return err
}
if err := o.checkRequirements(supVer); err != nil {
return err
}
return nil
}

func (o *Install) checkRequirements(supVer *common.SupportedVersion) error {
if err := cliutils.VerifyCLIVersion(supVer); err != nil {
return err
}
return 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 @@ -382,25 +382,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