Skip to content

Commit

Permalink
Merge pull request #108 from Jont828/version
Browse files Browse the repository at this point in the history
✨ Add git version info to controller
  • Loading branch information
k8s-ci-robot authored Aug 16, 2023
2 parents 7deaac2 + 305d893 commit a31234e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion hack/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ version::ldflags() {
local key=${1}
local val=${2}
ldflags+=(
"-X 'sigs.k8s.io/cluster-api/version.${key}=${val}'"
"-X 'sigs.k8s.io/cluster-api-addon-provider-helm/version.${key}=${val}'"
)
}

Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
addonsv1alpha1 "sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1"
hcpController "sigs.k8s.io/cluster-api-addon-provider-helm/controllers/helmchartproxy"
hrpController "sigs.k8s.io/cluster-api-addon-provider-helm/controllers/helmreleaseproxy"
"sigs.k8s.io/cluster-api-addon-provider-helm/version"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
kcpv1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
Expand Down Expand Up @@ -148,7 +149,7 @@ func main() {
os.Exit(1)
}

setupLog.Info("starting manager")
setupLog.Info("starting manager", "version", version.Get().String())
if err := mgr.Start(ctx); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
Expand Down
64 changes: 64 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Copyright 2023 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package version

import (
"fmt"
"runtime"
)

var (
gitMajor string // major version, always numeric
gitMinor string // minor version, numeric possibly followed by "+"
gitVersion string // semantic version, derived by build scripts
gitCommit string // sha1 from git, output of $(git rev-parse HEAD)
gitTreeState string // state of git tree, either "clean" or "dirty"
buildDate string // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
)

// Info contains all version-related information.
type Info struct {
Major string `json:"major,omitempty"`
Minor string `json:"minor,omitempty"`
GitVersion string `json:"gitVersion,omitempty"`
GitCommit string `json:"gitCommit,omitempty"`
GitTreeState string `json:"gitTreeState,omitempty"`
BuildDate string `json:"buildDate,omitempty"`
GoVersion string `json:"goVersion,omitempty"`
Compiler string `json:"compiler,omitempty"`
Platform string `json:"platform,omitempty"`
}

// Get returns version info initialized from defaults and the runtime environment.
func Get() Info {
return Info{
Major: gitMajor,
Minor: gitMinor,
GitVersion: gitVersion,
GitCommit: gitCommit,
GitTreeState: gitTreeState,
BuildDate: buildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}
}

// String returns version info in a human-friendly format.
func (info Info) String() string {
return info.GitVersion
}

0 comments on commit a31234e

Please sign in to comment.