Skip to content
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

Adds hub version in output of tkn version command #2205

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
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
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"
piyush-garg marked this conversation as resolved.
Show resolved Hide resolved
)

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
}
Loading