From b881cf075ad9931cfe4d6aeddaddb383347da8c6 Mon Sep 17 00:00:00 2001 From: Alan Clucas Date: Mon, 12 Aug 2024 11:24:18 +0100 Subject: [PATCH] fix(docs): Provide versioned links to documentation (#13455) Signed-off-by: Alan Clucas --- cmd/argo/commands/server.go | 2 +- pkg/apiclient/argo-kube-client.go | 2 +- pkg/apis/workflow/v1alpha1/version_types.go | 18 ++++++++++ util/help/topics.go | 40 ++++++++++++++++----- workflow/controller/operator.go | 2 +- 5 files changed, 52 insertions(+), 12 deletions(-) diff --git a/cmd/argo/commands/server.go b/cmd/argo/commands/server.go index f38a3abae144..1a7bd7a13bc8 100644 --- a/cmd/argo/commands/server.go +++ b/cmd/argo/commands/server.go @@ -64,7 +64,7 @@ func NewServerCommand() *cobra.Command { Use: "server", Short: "start the Argo Server", Example: fmt.Sprintf(` -See %s`, help.ArgoServer), +See %s`, help.ArgoServer()), RunE: func(c *cobra.Command, args []string) error { cmd.SetLogFormatter(logFormat) stats.RegisterStackDumper() diff --git a/pkg/apiclient/argo-kube-client.go b/pkg/apiclient/argo-kube-client.go index 4bc0ddc4fa2c..d984fcd54211 100644 --- a/pkg/apiclient/argo-kube-client.go +++ b/pkg/apiclient/argo-kube-client.go @@ -34,7 +34,7 @@ import ( var ( argoKubeOffloadNodeStatusRepo = sqldb.ExplosiveOffloadNodeStatusRepo - NoArgoServerErr = fmt.Errorf("this is impossible if you are not using the Argo Server, see " + help.CLI) + NoArgoServerErr = fmt.Errorf("this is impossible if you are not using the Argo Server, see " + help.CLI()) ) type argoKubeClient struct { diff --git a/pkg/apis/workflow/v1alpha1/version_types.go b/pkg/apis/workflow/v1alpha1/version_types.go index 1595c91f99b1..6845daa1609d 100644 --- a/pkg/apis/workflow/v1alpha1/version_types.go +++ b/pkg/apis/workflow/v1alpha1/version_types.go @@ -1,5 +1,10 @@ package v1alpha1 +import ( + "errors" + "regexp" +) + type Version struct { Version string `json:"version" protobuf:"bytes,1,opt,name=version"` BuildDate string `json:"buildDate" protobuf:"bytes,2,opt,name=buildDate"` @@ -10,3 +15,16 @@ type Version struct { Compiler string `json:"compiler" protobuf:"bytes,7,opt,name=compiler"` Platform string `json:"platform" protobuf:"bytes,8,opt,name=platform"` } + +var verRe = regexp.MustCompile(`^v(\d+)\.(\d+)\.(\d+)`) + +// BrokenDown returns the major, minor and release components +// of the version number, or error if this is not a release +// The error path is considered "normal" in a non-release build. +func (v Version) Components() (string, string, string, error) { + matches := verRe.FindStringSubmatch(v.Version) + if matches == nil || matches[1] == "0" { + return ``, ``, ``, errors.New("Not a formal release") + } + return matches[1], matches[2], matches[3], nil +} diff --git a/util/help/topics.go b/util/help/topics.go index 1e34bd6f9db0..3d3e01d5b6fb 100644 --- a/util/help/topics.go +++ b/util/help/topics.go @@ -1,13 +1,35 @@ package help -const ( - root = "https://argo-workflows.readthedocs.io/en/release-3.5" - ArgoServer = root + "/argo-server/" - CLI = root + "/cli/argo" +import ( + "fmt" - WorkflowTemplates = root + "/workflow-templates/" - WorkflowTemplatesReferencingOtherTemplates = WorkflowTemplates + "#referencing-other-workflowtemplates" - - Scaling = root + "/scaling/" - ConfigureMaximumRecursionDepth = Scaling + "#maximum-recursion-depth" + "github.com/argoproj/argo-workflows/v3" ) + +func root() string { + version := `latest` + if major, minor, _, err := argo.GetVersion().Components(); err == nil { + version = fmt.Sprintf("release-%s.%s", major, minor) + } + return fmt.Sprintf("https://argo-workflows.readthedocs.io/en/%s", version) +} + +// ArgoServer returns a URL to the argo-server documentation +func ArgoServer() string { + return root() + "/argo-server/" +} + +// CLI returns a URL to the cli documentation +func CLI() string { + return root() + "/cli/argo" +} + +// scaling returns a URL to the scaling documentation +func scaling() string { + return root() + "/scaling/" +} + +// ConfigureMaximumRecursionDepth returns a URL to the maximum recursion depth documentation +func ConfigureMaximumRecursionDepth() string { + return scaling() + "#maximum-recursion-depth" +} diff --git a/workflow/controller/operator.go b/workflow/controller/operator.go index 2fbe3084baa4..e83e1672529b 100644 --- a/workflow/controller/operator.go +++ b/workflow/controller/operator.go @@ -126,7 +126,7 @@ var ( // ErrTimeout indicates a specific template timed out ErrTimeout = errors.New(errors.CodeTimeout, "timeout") // ErrMaxDepthExceeded indicates that the maximum recursion depth was exceeded - ErrMaxDepthExceeded = errors.New(errors.CodeTimeout, fmt.Sprintf("Maximum recursion depth exceeded. See %s", help.ConfigureMaximumRecursionDepth)) + ErrMaxDepthExceeded = errors.New(errors.CodeTimeout, fmt.Sprintf("Maximum recursion depth exceeded. See %s", help.ConfigureMaximumRecursionDepth())) ) // maxOperationTime is the maximum time a workflow operation is allowed to run