github.com/oam-dev/kubevela@v1.9.11/version/version.go (about)

     1  /*
     2  Copyright 2021 The KubeVela Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package version
    18  
    19  import "github.com/hashicorp/go-version"
    20  
    21  // GitRevision is the commit of repo
    22  var GitRevision = "UNKNOWN"
    23  
    24  // VelaVersion is the version of cli.
    25  var VelaVersion = "UNKNOWN"
    26  
    27  // IsOfficialKubeVelaVersion checks whether the provided version string follows a KubeVela version pattern
    28  func IsOfficialKubeVelaVersion(versionStr string) bool {
    29  	_, err := version.NewSemver(versionStr)
    30  	return err == nil
    31  }
    32  
    33  // GetOfficialKubeVelaVersion extracts the KubeVela version from the provided string
    34  // More precisely, this method returns the segments and prerelease info w/o metadata
    35  func GetOfficialKubeVelaVersion(versionStr string) (string, error) {
    36  	s, err := version.NewSemver(versionStr)
    37  	if err != nil {
    38  		return "", err
    39  	}
    40  	v := s.String()
    41  	metadata := s.Metadata()
    42  	if metadata != "" {
    43  		metadata = "+" + metadata
    44  	}
    45  	return v[:len(v)-len(metadata)], nil
    46  }
    47  
    48  // ShouldUseLegacyHelmRepo checks whether the provided version should use the legacy helm repo
    49  func ShouldUseLegacyHelmRepo(ver *version.Version) bool {
    50  	if ver.LessThan(version.Must(version.NewVersion("1.8.2"))) {
    51  		return true
    52  	}
    53  
    54  	if ver.GreaterThanOrEqual(version.Must(version.NewVersion("1.9.0"))) {
    55  		return false
    56  	}
    57  
    58  	// After v1.9.0-beta.1.post1, we use the new helm repo
    59  	switch ver.Prerelease() {
    60  	case "beta.1.post1", "beta.2", "beta.3":
    61  		return false
    62  	default:
    63  		return true
    64  	}
    65  }