...

Source file src/github.com/linkerd/linkerd2/pkg/version/version.go

Documentation: github.com/linkerd/linkerd2/pkg/version

     1  package version
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"os"
     7  )
     8  
     9  // Version is updated automatically as part of the build process, and is the
    10  // ground source of truth for the current process's build version.
    11  //
    12  // DO NOT EDIT
    13  var Version = undefinedVersion
    14  
    15  // ProxyInitVersion is the pinned version of the proxy-init, from
    16  // https://github.com/linkerd/linkerd2-proxy-init This has to be kept in sync
    17  // with the default version in the control plane's values.yaml.
    18  var ProxyInitVersion = "v2.4.0"
    19  var LinkerdCNIVersion = "v1.5.0"
    20  
    21  const (
    22  	// undefinedVersion should take the form `channel-version` to conform to
    23  	// channelVersion functions.
    24  	undefinedVersion = "dev-undefined"
    25  )
    26  
    27  func init() {
    28  	// Use `$LINKERD_CONTAINER_VERSION_OVERRIDE` as the version only if the
    29  	// version wasn't set at link time to minimize the chance of using it
    30  	// unintentionally. This mechanism allows the version to be bound at
    31  	// container build time instead of at executable link time to improve
    32  	// incremental rebuild efficiency.
    33  	if Version == undefinedVersion {
    34  		override := os.Getenv("LINKERD_CONTAINER_VERSION_OVERRIDE")
    35  		if override != "" {
    36  			Version = override
    37  		}
    38  	}
    39  }
    40  
    41  // match compares two versions and returns success if they match, or an error
    42  // with a contextual message if they do not.
    43  func match(expectedVersion, actualVersion string) error {
    44  	if expectedVersion == "" {
    45  		return errors.New("expected version is empty")
    46  	} else if actualVersion == "" {
    47  		return errors.New("actual version is empty")
    48  	}
    49  
    50  	actual, err := parseChannelVersion(actualVersion)
    51  	if err != nil {
    52  		return fmt.Errorf("failed to parse actual version: %w", err)
    53  	}
    54  	expected, err := parseChannelVersion(expectedVersion)
    55  	if err != nil {
    56  		return fmt.Errorf("failed to parse expected version: %w", err)
    57  	}
    58  
    59  	if actual.channel != expected.channel {
    60  		return fmt.Errorf("mismatched channels: running %s but retrieved %s",
    61  			actual, expected)
    62  	}
    63  
    64  	if actual.version != expected.version || !actual.hotpatchEqual(expected) {
    65  		return fmt.Errorf("is running version %s but the latest %s version is %s",
    66  			actual.versionWithHotpatch(), actual.channel, expected.versionWithHotpatch())
    67  	}
    68  
    69  	return nil
    70  }
    71  

View as plain text