Repository: kubesphere/ks-devops
Pull request #805 (2022-08-29 09:17:35)

Doc: allow authenticated users checking Pipeline running log
<!-- Thanks for sending a pull request! Here are some tips for you:

1. If you want **faster** PR reviews, read how: https://github.com/kubesphere/community/blob/master/developer-guide/development/the-pr-author-guide-to-getting-through-code-review.md
2. In case you want to know how your PR got reviewed, read: https://github.com/kubesphere/community/blob/master/developer-guide/development/code-review-guide.md
3. Here are some coding conventions followed by the KubeSphere community: https://github.com/kubesphere/community/blob/master/developer-guide/development/coding-conventions.md
4. Additional open-source best practice: https://github.com/LinuxSuRen/open-source-best-practice
-->

### What type of PR is this?
<!-- 
Add one of the following kinds:
/kind bug
/kind cleanup
/kind feature
/kind design
/kind chore

Optionally add one or more of the following kinds if applicable:
/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
-->
/kind documentation

### What this PR does / why we need it:

### Which issue(s) this PR fixes:
<!--
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
Please leave it or change # to be None if there is no corresponding issue that exists
-->
Fixes #

### Special notes for reviewers:
<!--
You can use the following command to let the DevOps SIG members help you to review your PR.
/cc @kubesphere/sig-devops 
And please avoid cc any individual.
-->
Please check the following list before waiting reviewers:

- [ ] Already committed the CRD files to [the Helm Chart](https://github.com/kubesphere-sigs/ks-devops-helm-chart/) if you created some new CRDs
- [ ] Already [added the permission](https://github.com/kubesphere/ks-installer/blob/9e063b085a0e43fdb3d0d9e3e7f4149146f14b9c/roles/ks-core/prepare/files/ks-init/role-templates.yaml) for the new API
- [ ] Already added the RBAC markers for the new controllers

### Does this PR introduce a user-facing change??
<!--
If no, just write "None" in the release-note block below.
If yes, a release note is required:
Enter your extended-release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".

Please keep the note be same as your PR title if you believe it should be in the release notes.
-->
```release-note
None
```


ks-ci-bot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by:
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please ask for approval from **linuxsuren** after the PR has been reviewed.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubesphere%2Fks-devops).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/kubesphere/ks-devops/blob/master/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["linuxsuren"]} -->

Patch:
diff --git a/.golangci.yml b/.golangci.yml
index 6931365..19be75e 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -5,7 +5,7 @@ run:
   concurrency: 4
 
   # timeout for analysis, e.g. 30s, 5m, default is 1m
-  timeout: 5m
+  timeout: 8m
 
   skip-dirs:
     - .git
diff --git a/cmd/controller/app/controllers.go b/cmd/controller/app/controllers.go
index 908a12d..05a9abe 100644
--- a/cmd/controller/app/controllers.go
+++ b/cmd/controller/app/controllers.go
@@ -144,6 +144,7 @@ func getAllControllers(mgr manager.Manager, client k8s.Client, informerFactory i
 			err := (&gitrepository.PullRequestStatusReconciler{
 				Client:          mgr.GetClient(),
 				ExternalAddress: s.FeatureOptions.ExternalAddress,
+				ClusterName:     s.FeatureOptions.ClusterName,
 			}).SetupWithManager(mgr)
 			if err != nil {
 				return err
diff --git a/cmd/controller/app/options/feature.go b/cmd/controller/app/options/feature.go
index 06319e5..339b30b 100644
--- a/cmd/controller/app/options/feature.go
+++ b/cmd/controller/app/options/feature.go
@@ -29,6 +29,7 @@ type FeatureOptions struct {
 	Controllers     map[string]bool
 	SystemNamespace string
 	ExternalAddress string
+	ClusterName     string
 }
 
 // GetControllers returns the controllers map
@@ -79,6 +80,7 @@ func (o *FeatureOptions) AddFlags(fs *pflag.FlagSet, c *FeatureOptions) {
 	fs.StringVarP(&o.SystemNamespace, "system-namespace", "", "kubesphere-devops-system",
 		"The system namespace that contains ConfigMap, Secrets e.g.")
 	fs.StringVarP(&o.ExternalAddress, "external-address", "", "", "The external address for the UI")
+	fs.StringVarP(&o.ClusterName, "cluster-name", "", "default", "Current cluster name")
 }
 
 func (o *FeatureOptions) knownControllers() []string {
diff --git a/controllers/gitrepository/pull_request_status_controller.go b/controllers/gitrepository/pull_request_status_controller.go
index 8dca6df..5d8b96b 100644
--- a/controllers/gitrepository/pull_request_status_controller.go
+++ b/controllers/gitrepository/pull_request_status_controller.go
@@ -35,6 +35,7 @@ import (
 type PullRequestStatusReconciler struct {
 	client.Client
 	ExternalAddress string
+	ClusterName     string
 
 	log      logr.Logger
 	recorder record.EventRecorder
@@ -150,8 +151,9 @@ func getRepoInfo(repo *v1alpha3.MultiBranchPipeline) (info repoInfo) {
 func (r *PullRequestStatusReconciler) getExternalPipelineRunAddress(ctx context.Context, pipelineRun *v1alpha3.PipelineRun) (target string, err error) {
 	var ws string
 	if ws, err = r.getWorkspace(ctx, pipelineRun.GetNamespace()); err == nil {
-		target = fmt.Sprintf("%s/%s/clusters/default/devops/%s/pipelines/%s/run/%s/task-status",
-			net.ParseURL(r.ExternalAddress), ws, pipelineRun.Namespace, pipelineRun.Spec.PipelineRef.Name, pipelineRun.Name)
+		target = fmt.Sprintf("%s/%s/clusters/%s/devops/%s/pipelines/%s/branch/%s/run/%s/task-status",
+			net.ParseURL(r.ExternalAddress), ws, r.ClusterName,
+			pipelineRun.Namespace, pipelineRun.Spec.PipelineRef.Name, pipelineRun.Spec.SCM.RefName, pipelineRun.Name)
 	}
 	return
 }
diff --git a/docs/permission.md b/docs/permission.md
index fcc72d1..be263a2 100644
--- a/docs/permission.md
+++ b/docs/permission.md
@@ -18,3 +18,25 @@ Update [here](https://github.com/kubesphere/ks-installer/blob/e9e399d74a2fd8dbbb
 ## Resource specific
 You could create (or update) an CR (custom resource) that is `RoleBase` when you are trying to 
 create a new resource specific API. Such as, [role-template-manage-pipelines](https://github.com/kubesphere/ks-installer/blob/e9e399d74a2fd8dbbb6477a95afb91c40f423b72/roles/ks-core/prepare/files/ks-init/role-templates.yaml#L3323).
+
+## Examples
+
+### Allow authenticated users checking Pipeline running log
+
+Please feel free to add the following item into a `GlobalRole` of `authenticated`:
+
+You could find it by: `kubectl edit globalrole authenticated`
+
+```yaml
+rules:
+- apiGroups:
+  - devops.kubesphere.io
+  resources:
+  - devops
+  - pipelines
+  - pipelines/branches
+  - pipelineruns
+  - pipelineruns/nodedetails
+  verbs:
+  - get
+```


Test patch:
diff --git a/cmd/controller/app/options/feature_test.go b/cmd/controller/app/options/feature_test.go
index 042bc07..153a1ba 100644
--- a/cmd/controller/app/options/feature_test.go
+++ b/cmd/controller/app/options/feature_test.go
@@ -119,4 +119,5 @@ func TestFeatureOptions(t *testing.T) {
 	assert.NotNil(t, flagSet.Lookup("enabled-controllers"))
 	assert.NotNil(t, flagSet.Lookup("system-namespace"))
 	assert.NotNil(t, flagSet.Lookup("external-address"))
+	assert.NotNil(t, flagSet.Lookup("cluster-name"))
 }