Skip to content

Commit

Permalink
Adds hub version in output of tkn version command
Browse files Browse the repository at this point in the history
Signed-off-by: PuneetPunamiya <[email protected]>
  • Loading branch information
PuneetPunamiya authored and tekton-robot committed Jan 3, 2024
1 parent 8b556cf commit b5f7f16
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Client version: dev
Chains version: v0.8.0
Pipeline version: v0.10.0
Triggers version: v0.5.0
Dashboard version: v0.7.0
Operator version: v0.54.0
Hub version: v1.14.0
10 changes: 10 additions & 0 deletions pkg/cmd/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func Command(p cli.Params) *cobra.Command {
if operatorVersion != "" {
fmt.Fprintf(cmd.OutOrStdout(), "Operator version: %s\n", operatorVersion)
}
hubVersion, _ := version.GetHubVersion(cs, namespace)
if hubVersion != "" {
fmt.Fprintf(cmd.OutOrStdout(), "Hub version: %s\n", hubVersion)
}
case "client":
fmt.Fprintf(cmd.OutOrStdout(), "%s\n", clientVersion)
case "chains":
Expand Down Expand Up @@ -130,6 +134,12 @@ func Command(p cli.Params) *cobra.Command {
operatorVersion = "unknown"
}
fmt.Fprintf(cmd.OutOrStdout(), "%s\n", operatorVersion)
case "hub":
hubVersion, _ := version.GetHubVersion(cs, namespace)
if hubVersion == "" {
hubVersion = "unknown"
}
fmt.Fprintf(cmd.OutOrStdout(), "%s\n", hubVersion)
default:
fmt.Fprintf(cmd.OutOrStdout(), "Invalid component value\n")
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func TestGetVersions(t *testing.T) {
triggersConfigMap := getConfigMapData("triggers-info", "v0.5.0", map[string]string{"app.kubernetes.io/part-of": "tekton-pipelines"})
dashboardConfigMap := getConfigMapData("dashboard-info", "v0.7.0", map[string]string{"app.kubernetes.io/part-of": "tekton-pipelines"})
operatorConfigMap := getConfigMapData("tekton-operator-info", "v0.54.0", map[string]string{"app.kubernetes.io/part-of": "tekton-pipelines"})
hubConfigMap := getConfigMapData("hub-info", "v1.14.0", map[string]string{"app.kubernetes.io/part-of": "tekton-pipelines"})

testParams := []struct {
name string
Expand Down Expand Up @@ -305,11 +306,11 @@ func TestGetVersions(t *testing.T) {
configMap: []*corev1.ConfigMap{pipelineConfigMap, triggersConfigMap, dashboardConfigMap, operatorConfigMap},
goldenFile: true,
}, {
name: "deployment with pipeline, chains, triggers, dashboard and operator installed",
name: "deployment with pipeline, chains, triggers, dashboard, hub and operator installed",
namespace: "test",
userProvidedNamespace: "test",
deployment: []*v1.Deployment{},
configMap: []*corev1.ConfigMap{pipelineConfigMap, chainsConfigMap, triggersConfigMap, dashboardConfigMap, operatorConfigMap},
configMap: []*corev1.ConfigMap{pipelineConfigMap, chainsConfigMap, triggersConfigMap, dashboardConfigMap, operatorConfigMap, hubConfigMap},
goldenFile: true,
}}
for _, tp := range testParams {
Expand Down
10 changes: 10 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
triggersInfo string = "triggers-info"
dashboardInfo string = "dashboard-info"
operatorInfo string = "tekton-operator-info"
hubInfo string = "hub-info"
)

var defaultNamespaces = []string{"tekton-pipelines", "openshift-pipelines", "tekton-chains", "tekton-operator", "openshift-operators"}
Expand Down Expand Up @@ -293,3 +294,12 @@ func GetOperatorVersion(c *cli.Clients, ns string) (string, error) {
version := configMap.Data["version"]
return version, nil
}

func GetHubVersion(c *cli.Clients, ns string) (string, error) {
configMap, err := getConfigMap(c, hubInfo, ns)
if err != nil {
return "", err
}
version := configMap.Data["version"]
return version, nil
}

0 comments on commit b5f7f16

Please sign in to comment.