-
Notifications
You must be signed in to change notification settings - Fork 81
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
Make custom console respect custom params #1250
Merged
savitaashture
merged 2 commits into
openshift-pipelines:main
from
chmouel:custom-params-on-console
May 2, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,55 +186,95 @@ A few settings are available to configure this feature: | |
|
||
`<filename>`, `<line>`, `<error>` | ||
|
||
### Reporting logs URL to Tekton Dashboard or a custom Dashboard or Console | ||
### Reporting logs | ||
|
||
Pipelines as Code have the ability to automatically detect the OpenShift Console and link the logs of the tasks to the | ||
public URL of the OpenShift Console. If you are using the Tekton Dashboard, you can configure this feature using the | ||
`tekton-dashboard-url` setting. Simply set this to your dashboard URL, and the pipelinerun status and tasklog will be | ||
displayed there. | ||
Pipeline as Code can report the logs of the tasks to the [OpenShift | ||
Console](https://docs.openshift.com/container-platform/latest/web_console/web-console.html), | ||
the [Tekton Dashboard](https://tekton.dev/docs/dashboard/) or if you have your | ||
own give you flexibility to link to your custom Dashboard. | ||
|
||
Alternatively, you can also configure a custom console with the following settings: | ||
#### OpenShift Console | ||
|
||
Pipelines as Code will automatically detect the OpenShift Console and link the logs of the tasks to the | ||
public URL of the OpenShift Console. | ||
|
||
#### [Tekton Dashboard](https://tekton.dev/docs/dashboard/) | ||
|
||
If you are using the Tekton Dashboard, you can configure this feature using the | ||
`tekton-dashboard-url` setting. Simply set this to your dashboard URL, and the pipelinerun status and tasklog will be | ||
displayed there. | ||
|
||
#### Custom Console (or dashboard) | ||
|
||
Alternatively, you have the ability to configure the links to go to your custom | ||
dashboard using the following settings: | ||
|
||
* `custom-console-name` | ||
|
||
Set this to the name of your custom console. example: `MyCorp Console` | ||
Set this to the name of your custom console. example: `MyCorp Console` | ||
|
||
* `custom-console-url` | ||
|
||
Set this to the root URL of your custom console. example: `https://mycorp.com` | ||
Set this to the root URL of your custom console. example: `https://mycorp.com` | ||
|
||
* `custom-console-url-pr-details` | ||
|
||
Set this to the URL where to view the details of the `PipelineRun`. This is | ||
shown when the PipelineRun is started so the user can follow execution on your | ||
console or when to see more details about the pipelinerun ion result. | ||
Set this to the URL where to view the details of the `PipelineRun`. This is | ||
shown when the PipelineRun is started so the user can follow execution on your | ||
console or when to see more details about the pipelinerun on result. | ||
|
||
The URL suports templating for these value: | ||
The URL suports all the standard variables as exposed on the Pipelinerun (refer to | ||
the documentation on [Authoring PipelineRuns](../authoringprs)) with the added | ||
variable: | ||
|
||
* `{{ namespace }}`: The target namespace where the pipelinerun is executed | ||
* `{{ pr }}`: The PipelineRun name. | ||
* `{{ namespace }}`: The target namespace where the pipelinerun is executed | ||
* `{{ pr }}`: The PipelineRun name. | ||
|
||
example: `https://mycorp.com/ns/{{ namespace }}/pipelinerun/{{ pr }}` | ||
|
||
example: `https://mycorp.com/ns/{{ namespace }}/pipelienrun/{{ pr }}` | ||
Moreover it can access the [custom parameters](../guide/repositorycrd/#custom-parameter-expansion) from a | ||
Repository CR. For example if the user has a parameter in their Repo CR like this : | ||
|
||
* `custom-console-url-pr-tasklog` | ||
```yaml | ||
[...] | ||
spec: | ||
params: | ||
- name: custom | ||
value: value | ||
``` | ||
|
||
Set this to the URL where to view the log of the taskrun of the `PipelineRun`. This is | ||
shown when we post a result of the task breakdown to link to the logs of the taskrun. | ||
and the global configuration setting for `custom-console-url-pr-details` is: | ||
|
||
`https://mycorp.com/ns/{{ namespace }}/{{ custom }}` | ||
|
||
the `{{ custom }}` tag in the URL is expanded as `value`. | ||
|
||
This let operator to add specific informations like a `UUID` about a user as | ||
parameter in their repo CR and let it link to the console. | ||
|
||
* `custom-console-url-pr-tasklog` | ||
|
||
Set this to the URL where to view the log of the taskrun of the `PipelineRun`. This is | ||
shown when we post a result of the task breakdown to link to the logs of the taskrun. | ||
|
||
The URL suports templating for these value: | ||
The URL suports custom parameter on Repo CR and the standard parameters as | ||
described in the `custom-console-url-pr-details` setting and as well those added | ||
values: | ||
|
||
* `{{ namespace }}`: The target namespace where the pipelinerun is executed | ||
* `{{ pr }}`: The PipelineRun name. | ||
* `{{ task }}`: The Task name in the PR | ||
* `{{ pod }}`: The Pod name of the TaskRun | ||
* `{{ firstFailedStep }}`: The name of the first failed step in the TaskRun | ||
* `{{ namespace }}`: The target namespace where the pipelinerun is executed | ||
* `{{ pr }}`: The PipelineRun name. | ||
* `{{ task }}`: The Task name in the PR | ||
* `{{ pod }}`: The Pod name of the TaskRun | ||
* `{{ firstFailedStep }}`: The name of the first failed step in the TaskRun | ||
|
||
example: `https://mycorp.com/ns/{{ namespace }}/pipelinerun/{{ pr }}/logs/{{ task }}#{{ pod }}-{{ firstFailedStep }}` | ||
example: `https://mycorp.com/ns/{{ namespace }}/pipelinerun/{{ pr }}/logs/{{ task }}#{{ pod }}-{{ firstFailedStep }}` | ||
|
||
## Pipelines-As-Code Info | ||
|
||
There are a settings exposed through a config map for which any authenticated | ||
user can access to know about the Pipeline as Code status. | ||
user can access to know about the Pipeline as Code status. This Configmap | ||
will be automatically created with the [OpenShift Pipelines Operator](https://docs.openshift.com/container-platform/latest/cicd/pipelines/understanding-openshift-pipelines.html) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be nice to mention the name of the ConfigMap, seeing as the user might want to access it? |
||
or when installing with [tkn pac boostrap](../../guide/cli/#bootstrap) command. | ||
|
||
* `version` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package customparams | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add test for cel as well ? |
||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/google/cel-go/cel" | ||
"github.com/google/cel-go/checker/decls" | ||
"github.com/google/cel-go/common/types" | ||
"github.com/google/cel-go/common/types/ref" | ||
) | ||
|
||
func celEvaluate(expr string, env *cel.Env, data map[string]interface{}) (ref.Val, error) { | ||
parsed, issues := env.Parse(expr) | ||
if issues != nil && issues.Err() != nil { | ||
return nil, fmt.Errorf("failed to parse expression %#v: %w", expr, issues.Err()) | ||
} | ||
|
||
checked, issues := env.Check(parsed) | ||
if issues != nil && issues.Err() != nil { | ||
return nil, fmt.Errorf("expression %#v check failed: %w", expr, issues.Err()) | ||
} | ||
|
||
prg, err := env.Program(checked, cel.EvalOptions(cel.OptOptimize)) | ||
if err != nil { | ||
return nil, fmt.Errorf("expression %#v failed to create a Program: %w", expr, err) | ||
} | ||
|
||
out, _, err := prg.Eval(data) | ||
if err != nil { | ||
return nil, fmt.Errorf("expression %#v failed to evaluate: %w", expr, err) | ||
} | ||
|
||
return out, nil | ||
} | ||
|
||
// celFilter filters a query with cel, it sets two variables for the user to use | ||
// in the cel filter. body and pac. | ||
// body is the payload of the event, since it's already casted we un-marshall/and | ||
// marshall it as a map[string]interface{} | ||
func celFilter(query string, body any, pacParams map[string]string) (bool, error) { | ||
nbody, err := json.Marshal(body) | ||
if err != nil { | ||
return false, err | ||
} | ||
var jsonMap map[string]interface{} | ||
err = json.Unmarshal(nbody, &jsonMap) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
mapStrDyn := decls.NewMapType(decls.String, decls.Dyn) | ||
celDec, _ := cel.NewEnv( | ||
cel.Declarations( | ||
decls.NewVar("body", mapStrDyn), | ||
decls.NewVar("pac", mapStrDyn), | ||
)) | ||
val, err := celEvaluate(query, celDec, map[string]any{ | ||
"body": jsonMap, | ||
"pac": pacParams, | ||
}) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
//nolint: gocritic | ||
switch val.(type) { | ||
case types.Bool: | ||
if val.Value() == true { | ||
return true, nil | ||
} | ||
} | ||
return false, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove "a"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also remove "for"