Merge pull request #19905 from ixdy/export-go-version
Auto commit by PR queue bot
This commit is contained in:
		@@ -126,7 +126,7 @@ kube::version::ldflag() {
 | 
				
			|||||||
kube::version::ldflags() {
 | 
					kube::version::ldflags() {
 | 
				
			||||||
  kube::version::get_version_vars
 | 
					  kube::version::get_version_vars
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  local -a ldflags=()
 | 
					  local -a ldflags=($(kube::version::ldflag "buildDate" "$(date -u +'%Y-%m-%dT%H:%M:%SZ')"))
 | 
				
			||||||
  if [[ -n ${KUBE_GIT_COMMIT-} ]]; then
 | 
					  if [[ -n ${KUBE_GIT_COMMIT-} ]]; then
 | 
				
			||||||
    ldflags+=($(kube::version::ldflag "gitCommit" "${KUBE_GIT_COMMIT}"))
 | 
					    ldflags+=($(kube::version::ldflag "gitCommit" "${KUBE_GIT_COMMIT}"))
 | 
				
			||||||
    ldflags+=($(kube::version::ldflag "gitTreeState" "${KUBE_GIT_TREE_STATE}"))
 | 
					    ldflags+=($(kube::version::ldflag "gitTreeState" "${KUBE_GIT_TREE_STATE}"))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,6 @@ package unversioned
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"reflect"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/api"
 | 
						"k8s.io/kubernetes/pkg/api"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/api/unversioned"
 | 
						"k8s.io/kubernetes/pkg/api/unversioned"
 | 
				
			||||||
@@ -98,13 +97,14 @@ func MatchesServerVersion(client *Client, c *restclient.Config) error {
 | 
				
			|||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	clientVersion := version.Get()
 | 
						cVer := version.Get()
 | 
				
			||||||
	serverVersion, err := client.Discovery().ServerVersion()
 | 
						sVer, err := client.Discovery().ServerVersion()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return fmt.Errorf("couldn't read version from server: %v\n", err)
 | 
							return fmt.Errorf("couldn't read version from server: %v\n", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if s := *serverVersion; !reflect.DeepEqual(clientVersion, s) {
 | 
						// GitVersion includes GitCommit and GitTreeState, but best to be safe?
 | 
				
			||||||
		return fmt.Errorf("server version (%#v) differs from client version (%#v)!\n", s, clientVersion)
 | 
						if cVer.GitVersion != sVer.GitVersion || cVer.GitCommit != sVer.GitCommit || cVer.GitTreeState != cVer.GitTreeState {
 | 
				
			||||||
 | 
							return fmt.Errorf("server version (%#v) differs from client version (%#v)!\n", sVer, cVer)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,7 +46,7 @@ var CommonMetrics = map[string][]string{
 | 
				
			|||||||
	"http_response_size_bytes":                 {"handler", "quantile"},
 | 
						"http_response_size_bytes":                 {"handler", "quantile"},
 | 
				
			||||||
	"http_response_size_bytes_count":           {"handler"},
 | 
						"http_response_size_bytes_count":           {"handler"},
 | 
				
			||||||
	"http_response_size_bytes_sum":             {"handler"},
 | 
						"http_response_size_bytes_sum":             {"handler"},
 | 
				
			||||||
	"kubernetes_build_info":                    {"major", "minor", "gitCommit", "gitTreeState", "gitVersion"},
 | 
						"kubernetes_build_info":                    {"major", "minor", "gitCommit", "gitTreeState", "gitVersion", "buildDate", "goVersion", "compiler", "platform"},
 | 
				
			||||||
	"process_cpu_seconds_total":                {},
 | 
						"process_cpu_seconds_total":                {},
 | 
				
			||||||
	"process_max_fds":                          {},
 | 
						"process_max_fds":                          {},
 | 
				
			||||||
	"process_open_fds":                         {},
 | 
						"process_open_fds":                         {},
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -54,4 +54,6 @@ var (
 | 
				
			|||||||
	gitVersion   string = "v0.0.0-master+$Format:%h$"
 | 
						gitVersion   string = "v0.0.0-master+$Format:%h$"
 | 
				
			||||||
	gitCommit    string = "$Format:%H$"    // sha1 from git, output of $(git rev-parse HEAD)
 | 
						gitCommit    string = "$Format:%H$"    // sha1 from git, output of $(git rev-parse HEAD)
 | 
				
			||||||
	gitTreeState string = "not a git tree" // state of git tree, either "clean" or "dirty"
 | 
						gitTreeState string = "not a git tree" // state of git tree, either "clean" or "dirty"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						buildDate string = "1970-01-01T00:00:00Z" // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,7 +16,12 @@ limitations under the License.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package version
 | 
					package version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import "github.com/prometheus/client_golang/prometheus"
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"runtime"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/prometheus/client_golang/prometheus"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Info contains versioning information.
 | 
					// Info contains versioning information.
 | 
				
			||||||
// TODO: Add []string of api versions supported? It's still unclear
 | 
					// TODO: Add []string of api versions supported? It's still unclear
 | 
				
			||||||
@@ -27,6 +32,10 @@ type Info struct {
 | 
				
			|||||||
	GitVersion   string `json:"gitVersion"`
 | 
						GitVersion   string `json:"gitVersion"`
 | 
				
			||||||
	GitCommit    string `json:"gitCommit"`
 | 
						GitCommit    string `json:"gitCommit"`
 | 
				
			||||||
	GitTreeState string `json:"gitTreeState"`
 | 
						GitTreeState string `json:"gitTreeState"`
 | 
				
			||||||
 | 
						BuildDate    string `json:"buildDate"`
 | 
				
			||||||
 | 
						GoVersion    string `json:"goVersion"`
 | 
				
			||||||
 | 
						Compiler     string `json:"compiler"`
 | 
				
			||||||
 | 
						Platform     string `json:"platform"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Get returns the overall codebase version. It's for detecting
 | 
					// Get returns the overall codebase version. It's for detecting
 | 
				
			||||||
@@ -40,6 +49,10 @@ func Get() Info {
 | 
				
			|||||||
		GitVersion:   gitVersion,
 | 
							GitVersion:   gitVersion,
 | 
				
			||||||
		GitCommit:    gitCommit,
 | 
							GitCommit:    gitCommit,
 | 
				
			||||||
		GitTreeState: gitTreeState,
 | 
							GitTreeState: gitTreeState,
 | 
				
			||||||
 | 
							BuildDate:    buildDate,
 | 
				
			||||||
 | 
							GoVersion:    runtime.Version(),
 | 
				
			||||||
 | 
							Compiler:     runtime.Compiler,
 | 
				
			||||||
 | 
							Platform:     fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -52,12 +65,12 @@ func init() {
 | 
				
			|||||||
	buildInfo := prometheus.NewGaugeVec(
 | 
						buildInfo := prometheus.NewGaugeVec(
 | 
				
			||||||
		prometheus.GaugeOpts{
 | 
							prometheus.GaugeOpts{
 | 
				
			||||||
			Name: "kubernetes_build_info",
 | 
								Name: "kubernetes_build_info",
 | 
				
			||||||
			Help: "A metric with a constant '1' value labeled by major, minor, git version, git commit and git tree state from which Kubernetes was built.",
 | 
								Help: "A metric with a constant '1' value labeled by major, minor, git version, git commit, git tree state, build date, Go version, and compiler from which Kubernetes was built, and platform on which it is running.",
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		[]string{"major", "minor", "gitVersion", "gitCommit", "gitTreeState"},
 | 
							[]string{"major", "minor", "gitVersion", "gitCommit", "gitTreeState", "buildDate", "goVersion", "compiler", "platform"},
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	info := Get()
 | 
						info := Get()
 | 
				
			||||||
	buildInfo.WithLabelValues(info.Major, info.Minor, info.GitVersion, info.GitCommit, info.GitTreeState).Set(1)
 | 
						buildInfo.WithLabelValues(info.Major, info.Minor, info.GitVersion, info.GitCommit, info.GitTreeState, info.BuildDate, info.GoVersion, info.Compiler, info.Platform).Set(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	prometheus.MustRegister(buildInfo)
 | 
						prometheus.MustRegister(buildInfo)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user