The Wayback Machine - https://web.archive.org/web/20201222170910/https://github.com/tektoncd/cli/pull/1092
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

Modify tkn version to accept namespace as ldflag and flag #1092

Merged
merged 1 commit into from Sep 24, 2020

Conversation

@savitaashture
Copy link
Contributor

@savitaashture savitaashture commented Jul 31, 2020

Changes

Issue: Authenticated user(non-admin) cannot get the tkn version info because of permission issue as tkn version generally looks pipeline and triggers controller deployment across the cluster(all-namespaces) and non-admin user generally doesn't have permission to view on all namespaces.

So to satisfy admin and non-admin requirements to get the tkn-version come up with the below solution from WG meeting

  1. Provide namespace as ldflag during tkn compilation
  2. User can specify namespace as flag tkn version -n {namespace}
  3. default namespace will be tekton-pipelines if no ldflag and -n flag specified

Output:

  1. Specified namespace in ldflag is tekton-pipelines1 and controllers are running in tekton-pipelines
$ GOOS=linux GOARCH=amd64 go build -mod=vendor -ldflags "-X github.com/tektoncd/cli/pkg/cmd/version.namespace=tekton-pipelines1"
$ tkn version
Client version: dev
Pipeline version: unknown, pipeline controller may be installed in another namespace please use tkn version -n {namespace}
Triggers version: unknown, triggers controller may be installed in another namespace please use tkn version -n {namespace}
Dashboard version: unknown, dashboard controller may be installed in another namespace please use tkn version -n {namespace}

  1. Specified correct namespace where controllers are running using flag
$ tkn version -n tekton-pipelines
Client version: dev
Pipeline version: v0.14.2
Triggers version: devel
Dashboard version: v0.9.0

  1. Built tkn binary from master code
    By default tkn version looks Deployment in tekton-pipeline or openshift-pipelines namespace
$ go build
$ tkn version
Client version: dev
Pipeline version: v0.14.2
Triggers version: devel
Dashboard version: v0.9.0
$ tkn version --help
Prints version information

Usage:
tkn version [flags]

Flags:
  -c, --check              check if a newer version is available
  -h, --help               help for version
  -n, --namespace string   namespace to check installed controller version

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes tests (if functionality changed/added)
  • Run the code checkers with make check
  • Regenerate the manpages, docs and go formatting with make generated
  • Commit messages follow commit message best practices

See the contribution guide
for more details.

Release Notes

@tekton-robot
Copy link
Contributor

@tekton-robot tekton-robot commented Jul 31, 2020

The following is the coverage report on the affected files.
Say /test pull-tekton-cli-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/cmd/version/version.go 78.1% 78.5% 0.3
pkg/version/version.go 91.1% 91.7% 0.6
@savitaashture savitaashture force-pushed the savitaashture:tknversion branch from 42ec180 to c563c76 Jul 31, 2020
@tekton-robot
Copy link
Contributor

@tekton-robot tekton-robot commented Jul 31, 2020

The following is the coverage report on the affected files.
Say /test pull-tekton-cli-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/cmd/version/version.go 78.1% 78.5% 0.3
pkg/version/version.go 91.1% 91.7% 0.6
Copy link
Member

@vdemeester vdemeester left a comment

👍

@savitaashture
Copy link
Contributor Author

@savitaashture savitaashture commented Jul 31, 2020

/test pull-tekton-cli-integration-tests

@@ -23,6 +23,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// NOTE: use go build -ldflags "-X github.com/tektoncd/cli/pkg/version.defaultNamespace=tekton-pipelines"
var defaultNamespace = "tekton-pipelines"

This comment has been minimized.

@piyush-garg

piyush-garg Jul 31, 2020
Contributor

Is not better to put defaultNamespace value in flag itself

This comment has been minimized.

@vdemeester

vdemeester Jul 31, 2020
Member

@piyush-garg wdym ? we need to have that variable "defined" so that we can overwrite it with the ldflags. Being here seems to make more sense to me than in the cmd part (with the flags).

@chmouel
Copy link
Member

@chmouel chmouel commented Aug 1, 2020

Not sure if that was discussed but can't we have a list of most common namespaces in defaultNamespace by default?

defaultNamespaces := []string{
   "tekton-pipeline",
   "openshift-pipeline",
   "otherinthefutureofpopularnamespacefortekton",
}

so an upstream tkn binary can work on openshift-pipelines by default (and vice versa) ?

we try the list in order to find the version in there?

@savitaashture
Copy link
Contributor Author

@savitaashture savitaashture commented Aug 3, 2020

pipeline

Hi @chmouel I don't remember exactly like we discussed to keep list of namespace but we can do that instead of one namespace tekton-pipeline we can keep 2 right now

defaultNamespaces := []string{
   "tekton-pipeline",
   "openshift-pipeline",
}

But i am not sure if we have someother namespace used by anyother vendor.

So shall i go ahead with those 2 namespace right now ?

Makefile Outdated
ifneq ($(SKIPLDFLAG),)
FLAGS := $(VERSIONLDFLAG) $(SKIPLDFLAG)
FLAGS := $(VERSIONLDFLAG) $(SKIPLDFLAG)$(NAMESPACEFLAG)

This comment has been minimized.

@piyush-garg

piyush-garg Aug 3, 2020
Contributor

I think we need an if case for this also, there may be scenarios of only namespace flag provided

This comment has been minimized.

@savitaashture

savitaashture Aug 4, 2020
Author Contributor

I am not sure i understand completely like in which scenario we need if condition

and in the current code also i see with and without if condition flags are same i mean without any condition flags are here and with condition flags are here and both are same correct me if i mistaken something

Makefile Outdated Show resolved Hide resolved
clientVersion = devVersion
// flag to skip check flag in version cmd
skipCheckFlag = "false"
namespace string

This comment has been minimized.

@piyush-garg

piyush-garg Aug 3, 2020
Contributor

@vdemeester I mean we can put the default value here, and this can be overridden with LDFLAG and also namespace flag in cmd. And we can further use this in all functions. This way we can remove the defaultNamespace flag from pkg cc @savitaashture

This comment has been minimized.

@piyush-garg

piyush-garg Aug 3, 2020
Contributor

This can be single source for namespace then rather than two different for cmd and LDFLAG

This comment has been minimized.

@savitaashture

savitaashture Aug 4, 2020
Author Contributor

@piyush-garg updated code to have same var for both cmd and LDFLAG but not for default because now default is an []string{} and as per my understanding LDFLAG doesn't take the [] .

@piyush-garg
Copy link
Contributor

@piyush-garg piyush-garg commented Aug 3, 2020

pipeline

Hi @chmouel I don't remember exactly like we discussed to keep list of namespace but we can do that instead of one namespace tekton-pipeline we can keep 2 right now

defaultNamespaces := []string{
   "tekton-pipeline",
   "openshift-pipeline",
}

But i am not sure if we have someother namespace used by anyother vendor.

So shall i go ahead with those 2 namespace right now ?

Nit: AFAIR, namespaces are

defaultNamespaces := []string{
   "tekton-pipelines",
   "openshift-pipelines",
}
@chmouel
Copy link
Member

@chmouel chmouel commented Aug 3, 2020

@savitaashture Sounds good to me ! (the list of @piyush-garg openshift-pipeline with s :))

@vdemeester
Copy link
Member

@vdemeester vdemeester commented Aug 3, 2020

defaultNamespaces := []string{
   "tekton-pipelines",
   "openshift-pipelines",
}

If we use that, how does ldflags work with an array of string ? 🤔

@chmouel
Copy link
Member

@chmouel chmouel commented Aug 3, 2020

@vdemeester If there is a ldflag that was specified it will :

  1. Try the one from ldlfags
  2. Try the defaultNamespaces
@savitaashture savitaashture force-pushed the savitaashture:tknversion branch from c563c76 to 8a4ac51 Aug 4, 2020
@tekton-robot
Copy link
Contributor

@tekton-robot tekton-robot commented Aug 4, 2020

The following is the coverage report on the affected files.
Say /test pull-tekton-cli-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/cmd/version/version.go 78.1% 78.5% 0.3
pkg/version/version.go 91.1% 91.1% -0.0
@savitaashture savitaashture force-pushed the savitaashture:tknversion branch from 8a4ac51 to 84d3a68 Sep 14, 2020
@tekton-robot
Copy link
Contributor

@tekton-robot tekton-robot commented Sep 14, 2020

The following is the coverage report on the affected files.
Say /test pull-tekton-cli-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/cmd/version/version.go 79.4% 79.7% 0.3
pkg/version/version.go 91.5% 91.4% -0.1
@savitaashture
Copy link
Contributor Author

@savitaashture savitaashture commented Sep 14, 2020

@chmouel @vdemeester @piyush-garg

Addressed all the comments and rebased please do have a look

Thank you

@chmouel
Copy link
Member

@chmouel chmouel commented Sep 14, 2020

@savitaashture i think the unit test needs to be fixed for 0_10?

@savitaashture
Copy link
Contributor Author

@savitaashture savitaashture commented Sep 15, 2020

/test pull-tekton-cli-integration-tests-0_10

@savitaashture
Copy link
Contributor Author

@savitaashture savitaashture commented Sep 15, 2020

@savitaashture i think the unit test needs to be fixed for 0_10?

@chmouel Done

Copy link
Member

@vdemeester vdemeester left a comment

/meow

@tekton-robot
Copy link
Contributor

@tekton-robot tekton-robot commented Sep 17, 2020

@vdemeester: cat image

In response to this:

/meow

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Makefile Outdated
ifneq ($(SKIPLDFLAG),)
FLAGS := $(VERSIONLDFLAG) $(SKIPLDFLAG)
FLAGS := $(VERSIONLDFLAG) $(SKIPLDFLAG) $(NAMESPACELDFLAG)

This comment has been minimized.

@piyush-garg

piyush-garg Sep 17, 2020
Contributor

we need to handle the cases here carefully, I think it will cause an issue when you will not have skip flag but have namespace flag

or

we need to handle namespace flag case

This comment has been minimized.

@savitaashture

savitaashture Sep 21, 2020
Author Contributor

I have tested without specifying skip flag like below

GOOS=linux GOARCH=amd64 go build -mod=vendor -ldflags "-X github.com/tektoncd/cli/pkg/cmd/version.namespace=tekton-pipelines"

and it works without any issue

let me know if i miss understand the point which you have mentioned

This comment has been minimized.

@piyush-garg

piyush-garg Sep 22, 2020
Contributor

You are not using makefile here :D

This comment has been minimized.

@savitaashture

savitaashture Sep 22, 2020
Author Contributor

Updated makefile

tested with following scenario

  • NAMESPACE=tekton-pipelines SKIP_CHECK_FLAG=true RELEASE_VERSION=0.13 make amd64
  • NAMESPACE=tekton-pipelines make amd64
  • NAMESPACE=tekton-pipelines RELEASE_VERSION=0.13 make amd64
  • SKIP_CHECK_FLAG=true NAMESPACE=tekton-pipelines make amd64
if pipelineVersion == "" {
pipelineVersion = "unknown"
pipelineVersion = "unknown, " +
"pipeline controller may be installed in another namespace please use tkn version -n {namespace}"

This comment has been minimized.

@piyush-garg

piyush-garg Sep 17, 2020
Contributor

Do we need this, as we are planning to no show version in case of unknown

This comment has been minimized.

@savitaashture

savitaashture Sep 21, 2020
Author Contributor

I see still it exist in the current code so in order to keep in sync with master added this change but if there is a plan to not to show unknown then i think we can remove while doing the PR related to removing unknown changes

WDYT?

@savitaashture savitaashture force-pushed the savitaashture:tknversion branch from 84d3a68 to 60c5e65 Sep 22, 2020
@tekton-robot
Copy link
Contributor

@tekton-robot tekton-robot commented Sep 22, 2020

The following is the coverage report on the affected files.
Say /test pull-tekton-cli-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/cmd/version/version.go 79.4% 79.7% 0.3
pkg/version/version.go 91.5% 91.4% -0.1
@savitaashture
Copy link
Contributor Author

@savitaashture savitaashture commented Sep 22, 2020

/test pull-tekton-cli-integration-tests

@savitaashture savitaashture force-pushed the savitaashture:tknversion branch from 60c5e65 to 5325021 Sep 23, 2020
@tekton-robot
Copy link
Contributor

@tekton-robot tekton-robot commented Sep 23, 2020

The following is the coverage report on the affected files.
Say /test pull-tekton-cli-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/cmd/version/version.go 79.4% 79.7% 0.3
pkg/version/version.go 91.5% 91.4% -0.1
@savitaashture
Copy link
Contributor Author

@savitaashture savitaashture commented Sep 23, 2020

/test pull-tekton-cli-integration-tests

@savitaashture savitaashture force-pushed the savitaashture:tknversion branch from 5325021 to eb625c7 Sep 23, 2020
@tekton-robot
Copy link
Contributor

@tekton-robot tekton-robot commented Sep 23, 2020

The following is the coverage report on the affected files.
Say /test pull-tekton-cli-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/cmd/version/version.go 79.4% 79.7% 0.3
pkg/version/version.go 91.5% 91.4% -0.1
Copy link
Contributor

@piyush-garg piyush-garg left a comment

/lgtm

@tekton-robot
Copy link
Contributor

@tekton-robot tekton-robot commented Sep 24, 2020

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: piyush-garg, vdemeester

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [piyush-garg,vdemeester]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot merged commit 2587bd1 into tektoncd:master Sep 24, 2020
7 of 8 checks passed
7 of 8 checks passed
tide Not mergeable. Needs lgtm label.
Details
EasyCLA EasyCLA check passed. You are authorized to contribute.
Details
pull-tekton-cli-build-cross-tests Job succeeded.
Details
pull-tekton-cli-build-tests Job succeeded.
Details
pull-tekton-cli-go-coverage Job succeeded.
Details
pull-tekton-cli-integration-tests Job succeeded.
Details
pull-tekton-cli-integration-tests-0_10 Job succeeded.
Details
pull-tekton-cli-unit-tests Job succeeded.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.