github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/version/version.go (about)

     1  package version
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/Masterminds/semver"
     7  )
     8  
     9  func IsKymaVersionAtLeast_1_20(runTimeVersion string) (bool, error) {
    10  	return isKymaVersionAtLeast("<1.20.x", runTimeVersion)
    11  }
    12  
    13  func IsKymaVersionAtLeast_1_21(runTimeVersion string) (bool, error) {
    14  	return isKymaVersionAtLeast("<1.21.x", runTimeVersion)
    15  }
    16  
    17  func isKymaVersionAtLeast(constraint, runTimeVersion string) (bool, error) {
    18  	c, err := semver.NewConstraint(constraint)
    19  	if err != nil {
    20  		return false, fmt.Errorf("unable to parse constraint  %s for kyma version %s", constraint, runTimeVersion)
    21  	}
    22  
    23  	version, err := semver.NewVersion(runTimeVersion)
    24  	if err != nil {
    25  		// Return here if get some non semver image version.
    26  		return true, nil
    27  	}
    28  
    29  	return !c.Check(version), nil
    30  }