Skip to content

Commit

Permalink
add flag to show version information from servers
Browse files Browse the repository at this point in the history
instead of showing the client version show the live information on
cluster if we pass the --live flag to opc version

Signed-off-by: Chmouel Boudjnah <[email protected]>
  • Loading branch information
chmouel committed Jun 25, 2024
1 parent dd85448 commit bf24997
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
55 changes: 53 additions & 2 deletions pkg/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import (
_ "embed"

paccli "github.com/openshift-pipelines/pipelines-as-code/pkg/cli"
tkncli "github.com/tektoncd/cli/pkg/cli"
tknversion "github.com/tektoncd/cli/pkg/version"

// paccli "github.com/openshift-pipelines/opc/pkg"
"github.com/spf13/cobra"
)

var serverFlag = "server"

//go:embed version.json
var versionFile string

Expand All @@ -27,13 +30,59 @@ type versions struct {
ManualApprovalGate string `json:"manualapprovalgate"`
}

func getLiveInformations(iostreams *paccli.IOStreams) error {
tp := &tkncli.TektonParams{}
cs, err := tp.Clients()
if err != nil {
return err
}
namespace := "openshift-pipelines"
operatorNamespace := "openshift-operators"

chainsVersion, _ := tknversion.GetChainsVersion(cs, namespace)
if chainsVersion != "" {
fmt.Fprintf(iostreams.Out, "Chains version: %s\n", chainsVersion)
}
pipelineVersion, _ := tknversion.GetPipelineVersion(cs, namespace)
if pipelineVersion == "" {
pipelineVersion = "unknown, " +
"pipeline controller may be installed in another namespace."
}
fmt.Fprintf(iostreams.Out, "Pipeline version: %s\n", pipelineVersion)
triggersVersion, _ := tknversion.GetTriggerVersion(cs, namespace)
if triggersVersion != "" {
fmt.Fprintf(iostreams.Out, "Triggers version: %s\n", triggersVersion)
}
dashboardVersion, _ := tknversion.GetDashboardVersion(cs, namespace)
if dashboardVersion != "" {
fmt.Fprintf(iostreams.Out, "Dashboard version: %s\n", dashboardVersion)
}
operatorVersion, _ := tknversion.GetOperatorVersion(cs, operatorNamespace)
if operatorVersion != "" {
fmt.Fprintf(iostreams.Out, "Operator version: %s\n", operatorVersion)
}
hubVersion, _ := tknversion.GetHubVersion(cs, namespace)
if hubVersion != "" {
fmt.Fprintf(iostreams.Out, "Hub version: %s\n", hubVersion)
}
return nil
}

func VersionCommand(ioStreams *paccli.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "Print opc version",
Long: "Print OpenShift Pipeline Client version",
RunE: func(_ *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error {
var v versions
server, err := cmd.Flags().GetBool(serverFlag)
if err != nil {
return err
}
if server {
// TODO(chmouel): pac version when it's refactored in pac code
return getLiveInformations(ioStreams)
}
if err := json.Unmarshal([]byte(versionFile), &v); err != nil {
return fmt.Errorf("cannot unmarshall versions: %w", err)
}
Expand Down Expand Up @@ -65,5 +114,7 @@ func VersionCommand(ioStreams *paccli.IOStreams) *cobra.Command {
"commandType": "main",
},
}

cmd.Flags().BoolP(serverFlag, "s", false, "Get the services version information from cluster instead of the client version.")
return cmd
}
2 changes: 1 addition & 1 deletion pkg/version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"pac": "0.27.0", "tkn": "0.37.0", "results": "0.10.0", "manualapprovalgate": "0.2.0", "opc": "devel"}
{"pac": "0.27.1", "tkn": "0.37.0", "results": "0.10.0", "manualapprovalgate": "0.2.2", "opc": "devel"}

0 comments on commit bf24997

Please sign in to comment.