sigs.k8s.io/kubebuilder/v3@v3.14.0/cmd/version.go (about)

     1  /*
     2  Copyright 2017 The Kubernetes 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 main
    18  
    19  import (
    20  	"fmt"
    21  )
    22  
    23  // var needs to be used instead of const as ldflags is used to fill this
    24  // information in the release process
    25  var (
    26  	kubeBuilderVersion      = "unknown"
    27  	kubernetesVendorVersion = "unknown"
    28  	goos                    = "unknown"
    29  	goarch                  = "unknown"
    30  	gitCommit               = "$Format:%H$" // sha1 from git, output of $(git rev-parse HEAD)
    31  
    32  	buildDate = "1970-01-01T00:00:00Z" // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
    33  )
    34  
    35  // version contains all the information related to the CLI version
    36  type version struct {
    37  	KubeBuilderVersion string `json:"kubeBuilderVersion"`
    38  	KubernetesVendor   string `json:"kubernetesVendor"`
    39  	GitCommit          string `json:"gitCommit"`
    40  	BuildDate          string `json:"buildDate"`
    41  	GoOs               string `json:"goOs"`
    42  	GoArch             string `json:"goArch"`
    43  }
    44  
    45  // versionString returns the CLI version
    46  func versionString() string {
    47  	return fmt.Sprintf("Version: %#v", version{
    48  		kubeBuilderVersion,
    49  		kubernetesVendorVersion,
    50  		gitCommit,
    51  		buildDate,
    52  		goos,
    53  		goarch,
    54  	})
    55  }