Skip to content

chore: Add the version of the Argo CD dependency to version output #423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 52 additions & 11 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,63 +17,103 @@ package version
import (
"encoding/json"
"runtime"
"runtime/debug"
"time"

"gopkg.in/yaml.v3"
)

var version = "99.9.9-unreleased"
var gitRevision = "unknown"
var gitStatus = "unknown"
var buildDate = time.Now().Format(time.RFC3339)

// versionInformation represents the version information of the argocd-agent.
type versionInformation struct {
Name string `json:"name"`
Component string `json:"component"`
Version string `json:"version"`
// Name is the name of the argocd-agent.
Name string `json:"name"`
// Component is the component of the argocd-agent.
Component string `json:"component"`
// Version is the version of the argocd-agent.
Version string `json:"version"`
// GitRevision is the git revision of the argocd-agent.
GitRevision string `json:"gitRevision" yaml:"gitRevision"`
GitStatus string `json:"gitStatus" yaml:"gitStatus"`
GoVersion string `json:"goVersion" yaml:"goVersion"`
// GitStatus is the git status of the argocd-agent.
GitStatus string `json:"gitStatus" yaml:"gitStatus"`
// GoVersion is the go version of the argocd-agent.
GoVersion string `json:"goVersion" yaml:"goVersion"`
// BuildDate is the build date of the argocd-agent.
BuildDate string `json:"buildDate" yaml:"buildDate"`
// ArgoCDVersion is the version of the argocd-agent's dependency on argocd.
ArgoCDVersion string `json:"argocdVersion" yaml:"argocdVersion"`
}

// Version represents the version of the argocd-agent.
type Version struct {
v versionInformation
}

// New returns a new Version object.
func New(name, component string) *Version {
v := versionInformation{
Name: name,
Component: component,
Version: version,
GitRevision: gitRevision,
GitStatus: gitStatus,
GoVersion: runtime.Version(),
Name: name,
Component: component,
Version: version,
GitRevision: gitRevision,
GitStatus: gitStatus,
GoVersion: runtime.Version(),
BuildDate: buildDate,
ArgoCDVersion: getArgoCDVersion(),
}
return &Version{v: v}
}

// QualifiedVersion returns the qualified version of the argocd-agent.
func (v *Version) QualifiedVersion() string {
return v.v.Name + "-" + v.v.Version
}

// Version returns the version of the argocd-agent.
func (v *Version) Version() string {
return version
}

// Name returns the name of the argocd-agent.
func (v *Version) Name() string {
return v.v.Name
}

// Component returns the component of the argocd-agent
func (v *Version) Component() string {
return v.v.Component
}

// GitRevision returns the git revision of the argocd-agent.
func (v *Version) GitRevision() string {
return v.v.GitRevision
}

// GitStatus returns the git status of the argocd-agent.

func (v *Version) GitStatus() string {
return v.v.GitStatus
}

// getArgoCDVersion returns the version of the argocd-agent's dependency on argocd.
func getArgoCDVersion() string {
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return "unknown"
}
for _, dep := range buildInfo.Deps {
if dep.Path == "github.com/argoproj/argo-cd/v2" {
return dep.Version
}
}
return "unknown"
}

// YAML returns the version information of the argocd-agent in YAML format.
func (v *Version) YAML() string {
b, err := yaml.Marshal(v.v)
if err != nil {
Expand All @@ -82,6 +122,7 @@ func (v *Version) YAML() string {
return string(b)
}

// JSON returns the version information of the argocd-agent in JSON format.
func (v *Version) JSON(indent bool) string {
var b []byte
var err error
Expand Down
Loading