automatiko-io / automatiko-approval-task

Tekton Pipeline Custom task implementation to add approval capabilities into the pipelines
Apache License 2.0
44 stars 14 forks source link

Can not get approval tasks from automatiko-approval-task UI #1

Closed hillbun closed 2 years ago

hillbun commented 2 years ago

I create pipelinerun with tekton trigger, and it is PipelineRun resourcetemplates.

I can get approval tasks list in tekton dashboard of Approval Tasks

it shows message:

status:  
  approvalUrl: 'http://automatiko-approval-task.default//management/tasks/link/c2luZ2xlfDRkODI0NDk4LTBhMDMtM2VlNy04ZGE1LTU2M2ZkNGVhZTM3MzpiMDk0OTEyNy04MGQ4LTQxZDktODY1Ny0wY2IzYjI5YTM5NDd8MmE4ZGVjNjgtMzg1OS00NGMzLWIyNGYtZjRmNmJkODNhOTYyfA=='
  message: Approval task has been created and assigned
  status: pending

But I can not get task from automatiko-approval-task UI

also, curl "http://automatiko-approval-task.default//management/tasks/link/c2luZ2xlfDRkODI0NDk4LTBhMDMtM2VlNy04ZGE1LTU2M2ZkNGVhZTM3MzpiMDk0OTEyNy04MGQ4LTQxZDktODY1Ny0wY2IzYjI5YTM5NDd8MmE4ZGVjNjgtMzg1OS00NGMzLWIyNGYtZjRmNmJkODNhOTYyfA=="

it returns:

{"message":null}

mswiderski commented 2 years ago

could it be the // just after the host? Try removing one of them and see if that helps.

Another way to try if you can get access to the approval task is to go to http://automatiko-approval-task.default and fill the form to look tasks up.

In addition, could you look into logs of the approval task pod?

hillbun commented 2 years ago

I create pipelinerun resourcetemplates for gitlab push EventListener:

          resourcetemplates:
            - apiVersion: tekton.dev/v1beta1
              kind: PipelineRun
              metadata:
                generateName: gitlab-pipelinerun-
              spec:
                pipelineSpec:
                  tasks:
                    - name: git-clone-task
                      taskRef:
                        name: git-clone
                      workspaces:
                        - name: ws
                          workspace: ws
                    - name: hello-task
                      taskRef:
                        name: hello
                      runAfter:
                        - git-clone-task
                      workspaces:
                        - name: ws
                          workspace: ws
                    - name: world-task
                      taskRef:
                        name: world
                      runAfter:
                        - git-clone-task
                      workspaces:
                        - name: ws
                          workspace: ws
                    - name: npm-task
                      taskRef:
                        name: npm
                      runAfter:
                        - git-clone-task
                      workspaces:
                        - name: ws
                          workspace: ws
                    - name: deploy-dev-approval-task
                      taskRef:
                        apiVersion: tekton.automatiko.io/v1alpha1
                        kind: ApprovalTask
                        name: approvaltask
                      params:
                        - name: pipeline
                          value: "$(context.pipelineRun.name)"
                        - name: description
                          value: "Approval from pipeline $(context.pipeline.name)"
                      runAfter:
                        - npm-task
                      workspaces:
                        - name: ws
                          workspace: ws

After pipelinerun created, and task git-clone-task, hello-task, world-task, npm-task finished, I can get a approval tasks in tekton dashboard of Approval Tasks.

it shows message:

apiVersion: tekton.automatiko.io/v1alpha1
kind: ApprovalTask
metadata:  creationTimestamp: '2022-08-10T02:27:25Z'
  finalizers:    - approvaltasks.tekton.automatiko.io/finalizer
  generation: 1  labels:    decision: pending
    responses: 0_of_1
  managedFields:    - apiVersion: tekton.automatiko.io/v1alpha1
      fieldsType: FieldsV1
      fieldsV1:        'f:metadata':          'f:finalizers':            .: {}            'v:"approvaltasks.tekton.automatiko.io/finalizer"': {}          'f:labels':            .: {}            'f:decision': {}            'f:responses': {}        'f:spec':          .: {}          'f:approvers': {}          'f:description': {}          'f:groups': {}          'f:pipeline': {}          'f:strategy': {}        'f:status':          .: {}          'f:approvalUrl': {}          'f:message': {}          'f:status': {}      manager: okhttp
      operation: Update
      time: '2022-08-10T02:27:25Z'
  name: gitlab-pipelinerun-p55nx-deploy-dev-approval-task
  namespace: default
  resourceVersion: '190397067'
  uid: 4e1c0438-ba02-4d1a-b9e8-017152d9e2ef
spec:  approvers: []  description: Approval from pipeline gitlab-pipelinerun-p55nx
  groups: []  pipeline: gitlab-pipelinerun-p55nx
  strategy: SINGLE
status:
  approvalUrl: 'http://automatiko-approval-task.default//management/tasks/link/c2luZ2xlfDYzZjQ2NTY3LWIyMzItMzM2Ny04M2IxLWQ1MGQ0YTliMDRhMTpjOWRhNDlkMy02MmFlLTRlM2ItYmE1NC1mMWQ1ZjgwNzlmNmV8YzA5NWMwMzEtNzY1Mi00YTFmLWI3NWQtYjIyM2Q4N2ZiOGUxfA=='
  message: Approval task has been created and assigned
  status: pending

I run:

curl "http://automatiko-approval-task.default/management/tasks/link/c2luZ2xlfDYzZjQ2NTY3LWIyMzItMzM2Ny04M2IxLWQ1MGQ0YTliMDRhMTpjOWRhNDlkMy02MmFlLTRlM2ItYmE1NC1mMWQ1ZjgwNzlmNmV8YzA5NWMwMzEtNzY1Mi00YTFmLWI3NWQtYjIyM2Q4N2ZiOGUxfA=="

It returns:

<!DOCTYPE html>
<html lang="en">
<head>
        <title>Not found</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

<!--===============================================================================================-->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
        <link rel="stylesheet" type="text/css" href="css/main.css">
<!--===============================================================================================-->
</head>
<body>

        <div class="container-contact100">
                <div class="wrap-contact100">
                        <div  style="text-align: center;">
                        <span class="fa fa-search" style="font-size:60px;"></span>
                        <br/><br/><br/><br/>
                        <h3 style="text-align: center;">Task you're looking for has not been found</h3>
                        </div>
                </div>
        </div>

</body>
</html>

I can not get any task from http://automatiko-approval-task.default/tasks.html, or search pipelinerun name of gitlab-pipelinerun-p55nx from http://automatiko-approval-task.default/

I run kubectl logs automatiko-approval-task-7cb9c7764c-r64kt

It shows error:

io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException: Process instance with id gitlab-pipelinerun-p55nx-approval not found
        at io.automatiko.tekton.tasks.approval.ApprovalsResource.lambda$get_approvals$5(ApprovalsResource.java:94)
        at java.util.Optional.orElseThrow(Optional.java:408)
        at io.automatiko.tekton.tasks.approval.ApprovalsResource.lambda$getTasks_approvals$20(ApprovalsResource.java:194)
        at io.automatiko.engine.services.uow.UnitOfWorkExecutor.executeInUnitOfWork(UnitOfWorkExecutor.java:27)
        at io.automatiko.tekton.tasks.approval.ApprovalsResource.getTasks_approvals(ApprovalsResource.java:193)
        at io.automatiko.tekton.tasks.approval.ApprovalsResource$quarkusrestinvoker$getTasks_approvals_ba1833a3b5830bd30bdc7b109c14d5a49813a2ed.invoke(Unknown Source)
        at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
        at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:108)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:141)
        at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:554)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
        at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
        at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Thread.java:829)
        at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:704)
        at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202)
mswiderski commented 2 years ago

I think it is caused by missing approvers or groups in the definition of the task. Can you try to assign a any approver like this

- name: deploy-dev-approval-task
  taskRef:
    apiVersion: tekton.automatiko.io/v1alpha1
    kind: ApprovalTask
    name: approvaltask
  params:
    - name: pipeline
      value: "$(context.pipelineRun.name)"
    - name: description
      value: "Approval from pipeline $(context.pipeline.name)"
    - name: approvers
      value:
        - "John"
  runAfter:
    - npm-task
  workspaces:
    - name: ws
      workspace: ws

And then use john as user to get the tasks for. In the curl command append ?user=john

curl "http://automatiko-approval-task.default/management/tasks/link/c2luZ2xlfDYzZjQ2NTY3LWIyMzItMzM2Ny04M2IxLWQ1MGQ0YTliMDRhMTpjOWRhNDlkMy02MmFlLTRlM2ItYmE1NC1mMWQ1ZjgwNzlmNmV8YzA5NWMwMzEtNzY1Mi00YTFmLWI3NWQtYjIyM2Q4N2ZiOGUxfA==?user=john"
mswiderski commented 2 years ago

I just ran into a similar problem after restarting the pod of the automatiko approval tasks when there were active pipelines waiting on the task. Could you please try with clean state? I mean to cancel any pipeline that waits on the approval task, then restart pod of automatiko approval task and then try with new pipeline?

I will investigate why it breaks on restart as it is certainly not expected.

mswiderski commented 2 years ago

just pushed out a new 0.3.1 release that addresses the problem with resuming after restart of the operator of the automatiko approval tasks. If you could give it a try that would be great.

hillbun commented 2 years ago

I delete all pilelinerun, and make a fresh run again

curl 'http://automatiko-approval-task.default//management/tasks/link/c2luZ2xlfDYxMmRmMGNmLTllOTMtMzdlNy1hMTlkLTQ0NDIyMzEzM2Q1Yjo5NjNhMWRmMi1lNWY2LTRiMWQtYWJmOS02MGE1MmI0ZGIzNmZ8YTlhZjJkMWEtMGIzYS00NjJjLWEyZGYtZGI5YzAxOGI4ZTM5fA==?user=john'

I get result

<!DOCTYPE html>
<html lang="en">
<head>
        <title>Approval Task</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

<!--===============================================================================================-->
        <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script src="/js/jquery.serializejson.js"></script>
        <link rel="stylesheet" type="text/css" href="/css/main.css">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
<!--===============================================================================================-->
</head>
<body>

        <div class="container-contact100">
                <div class="wrap-contact100">
                        <form id="content" class="contact100-form validate-form">
                                <span class="contact100-form-title">
                                        Approval task
                                </span>

                                <div class="wrap-input100 validate-input bg1">
                                        <h4>
                                                Approval from pipeline gitlab-pipelinerun-sr8vq
                                        </h4>
                                </div>

                                <div class="wrap-input100 validate-input bg0 rs1-alert-validate">
                                        <span class="label-input100">Comment</span>
                                        <textarea id="comment" class="input100" name="message" placeholder="Add your comment here..."></textarea>
                                </div>

                                <div class="container-contact100-form-btn">
                                        <button id="approveButton" class="contact100-form-btn approve">
                                                <span>
                                                        Approve
                                                </span>
                                        </button>

                                        <button id="rejectButton" class="contact100-form-btn reject">
                                                <span>
                                                        Reject
                                                </span>
                                        </button>
                                </div>
                        </form>
                </div>
        </div>

<script type="text/javascript">
        let taskActionUrl = "/approvals/612df0cf-9e93-37e7-a19d-444223133d5b/single/612df0cf-9e93-37e7-a19d-444223133d5b:963a1df2-e5f6-4b1d-abf9-60a52b4db36f/approval/a9af2d1a-0b3a-462c-a2df-db9c018b8e39?redirect=true&user=john";

        let completeTask = function(approved, comment) {

                $.ajax({
                        url : taskActionUrl,
                        type : 'POST',
                        dataType : 'json',
                        contentType: 'application/json',
                        data: JSON.stringify({'approval': approved, 'comment': comment}),
                        crossDomain : true,
                        success : function(data) {
                                if (approved) {
                                        $( "#content" ).parent()
                                    .append(
                                      $('<div  style="text-align: center;"> '+
                                                '       <span class="fa fa-check" style="font-size:60px;"></span> '+
                                                '       <br/><br/><br/><br/> '+
                                                '       <h3 style="text-align: center;">Pipeline "gitlab-pipelinerun-sr8vq" has been approved</h3> '+
                                                '       </div>')
                                    );
                                } else {
                                        $( "#content" ).parent()
                                    .append(
                                      $('<div  style="text-align: center;"> '+
                                                                '       <span class="fa fa-ban" style="font-size:60px;"></span> '+
                                                                '       <br/><br/><br/><br/> '+
                                                                '       <h3 style="text-align: center;">Pipeline "gitlab-pipelinerun-sr8vq" has been rejected</h3> '+
                                                                '       </div>')
                                    );
                                }
                                $( "#content" ).remove();

                        },
                        error : function(req, status, error) {
                                console.error("Task complete failed with " + status + ", error: " + error);
                        }
                });

        }

        $(document).ready(function() {
                $('#content').submit(false);

                $( "#approveButton" ).on( "click", function() {
                        completeTask(true, $( "#comment" ).val());

                });

                $( "#rejectButton" ).on( "click", function() {
                        completeTask(false, $( "#comment" ).val());

                });

        });
        </script>
</body>
</html>

But I can not get task from http://automatiko-approval-task.default/tasks.html, or search pipelinerun name and Approver from http://automatiko-approval-task.default/ UI dashboard.

I will rey release 0.3.1 next.

mswiderski commented 2 years ago

ok, the outcome of the curl shows it works as expected as it gives you the form. If you open it in the browser then it will allow you to approve or reject the task and continue the pipeline.

the tasks.html and the search requires to provide user as well. So both pipeline run name and the user to get the tasks.

hillbun commented 2 years ago

I try 0.3.1

curl return shows it works as expected.

But I still can not get task search with rom http://automatiko-approval-task.default/tasks.html, or search pipelinerun name and Approver from http://automatiko-approval-task.default/ UI dashboard.

but this demo is OK for UI search.

kubectl apply -f k8s/test/print.yaml kubectl apply -f k8s/test/pipeline-single.yaml

also there is another problem, I delete all pipelinerun, but still one exist in menu of tekton dashboard Approval Tasks list.

How this happen? and how to purge?

hillbun commented 2 years ago

is this problem caused by pipelinerun templates of my case?

mswiderski commented 2 years ago

But I still can not get task search with rom http://automatiko-approval-task.default/tasks.html, or search pipelinerun name and Approver from http://automatiko-approval-task.default/ UI dashboard.

you need to use both pipeline and user (who is added as approver) in the form.

also there is another problem, I delete all pipelinerun, but still one exist in menu of tekton dashboard Approval Tasks list. How this happen? and how to purge?

it must be the left over from the previous runs as it was failing and thus did not clean it up properly. with 0.3.1 this should no longer happen. To remove it you can delete it as any other Kubernetes resource kubectl delete approvaltask nameoftheresource

mswiderski commented 2 years ago

is this problem caused by pipelinerun templates of my case?

nope, it should be completely independent from the pipelines as it only relies on the approval task definition.

hillbun commented 2 years ago

it must be the left over from the previous runs as it was failing and thus did not clean it up properly. with 0.3.1 this should no longer happen. To remove it you can delete it as any other Kubernetes resource kubectl delete approvaltask nameoftheresource

kubectl delete approvaltask gitlab-pipelinerun-sr8vq-deploy-dev-approval-task --force --grace-period=0

It takes a long time and not finished.

hillbun commented 2 years ago

But I still can not get task search with rom http://automatiko-approval-task.default/tasks.html, or search pipelinerun name and Approver from http://automatiko-approval-task.default/ UI dashboard.

you need to use both pipeline and user (who is added as approver) in the form.

I get yaml from tekton dashboard:

apiVersion: tekton.automatiko.io/v1alpha1
kind: ApprovalTask
metadata:
  creationTimestamp: '2022-08-11T01:54:37Z'
  finalizers:
    - approvaltasks.tekton.automatiko.io/finalizer
  generation: 1
  labels:
    decision: pending
    responses: 0_of_1
  managedFields:
    - apiVersion: tekton.automatiko.io/v1alpha1
      fieldsType: FieldsV1
      fieldsV1:        'f:metadata':          'f:finalizers':            .: {}            'v:"approvaltasks.tekton.automatiko.io/finalizer"': {}          'f:labels':            .: {}            'f:decision': {}            'f:responses': {}        'f:spec':          .: {}          'f:approvers': {}          'f:description': {}          'f:groups': {}          'f:pipeline': {}          'f:strategy': {}        'f:status': {}      manager: okhttp
      operation: Update
      time: '2022-08-11T01:54:37Z'
  name: gitlab-pipelinerun-g7n26-deploy-dev-approval-task
  namespace: default
  resourceVersion: '191421498'
  uid: acc473e3-9665-4c54-b87c-3b959f14e8ef
spec:
  approvers:
    - john
  description: Approval from pipeline gitlab-pipelinerun-g7n26
  groups: []
  pipeline: gitlab-pipelinerun-g7n26
  strategy: SINGLE

I fill Pipeline run name: gitlab-pipelinerun-g7n26 and Approver: john in the form of http://automatiko-approval-task.default/, but get no tasks result.

mswiderski commented 2 years ago

it must be the left over from the previous runs as it was failing and thus did not clean it up properly. with 0.3.1 this should no longer happen. To remove it you can delete it as any other Kubernetes resource kubectl delete approvaltask nameoftheresource

kubectl delete approvaltask gitlab-pipelinerun-sr8vq-deploy-dev-approval-task --force --grace-period=0

It takes a long time and not finished.

most likely due to broken finalisers. If it did not remove it you can try to remove the operator of automatiko approval tasks and then drop it.

mswiderski commented 2 years ago

I fill Pipeline run name: gitlab-pipelinerun-g7n26 and Approver: john in the form of http://automatiko-approval-task.default/, but get no tasks result.

can you look into browser network logs? If you could provide that information with few screenshots of what you enter in the form and what is logged in the network tab in the browser to see what it actually does.

Since the task can be worked on via link from the CR then it has all the data in so there must be something misconfigured I believe.

hillbun commented 2 years ago

most likely due to broken finalisers. If it did not remove it you can try to remove the operator of automatiko approval tasks and then drop it.

Would you let me know steps? thanks.

mswiderski commented 2 years ago

it should be just to do kubectl delete -f name_of_the_yaml_file_used_to_install_it then check if the resource is still there.

hillbun commented 2 years ago

it should be just to do kubectl delete -f name_of_the_yaml_file_used_to_install_it then check if the resource is still there.

I delete pods automatiko-approval-task and when delete approvaltask properly.

mswiderski commented 2 years ago

so you managed to remove it?

hillbun commented 2 years ago

I fill Pipeline run name: gitlab-pipelinerun-g7n26 and Approver: john in the form of http://automatiko-approval-task.default/, but get no tasks result.

can you look into browser network logs? If you could provide that information with few screenshots of what you enter in the form and what is logged in the network tab in the browser to see what it actually does.

Since the task can be worked on via link from the CR then it has all the data in so there must be something misconfigured I believe.

I reproduce now.

I get approval task details:

spec:
  approvers:
    - john
  description: Approval from pipeline gitlab-pipelinerun-4wwb2
  groups: []  pipeline: gitlab-pipelinerun-4wwb2
  strategy: SINGLE
status:  approvalUrl: 'http://automatiko-approval-task.default//management/tasks/link/c2luZ2xlfDU1YWM4MjAyLTg2YWMtM2Y0ZS1hNjlkLTcxNmUyM2ZlYWY4YTo5NDEzNDBhZi0xMTdkLTQ1ZjAtOTUyZi1kZjhlMTI1ZDhkM2V8NTE4ODhjZjItZDkyMC00M2Y2LWExZTgtM2VhYWJlYmNhY2NjfA=='
  message: Approval task has been created and assigned
  status: pending

curl "http://automatiko-approval-task.default//management/tasks/link/c2luZ2xlfDU1YWM4MjAyLTg2YWMtM2Y0ZS1hNjlkLTcxNmUyM2ZlYWY4YTo5NDEzNDBhZi0xMTdkLTQ1ZjAtOTUyZi1kZjhlMTI1ZDhkM2V8NTE4ODhjZjItZDkyMC00M2Y2LWExZTgtM2VhYWJlYmNhY2NjfA==?user=john"

I get result:

<!DOCTYPE html>
<html lang="en">
<head>
        <title>Approval Task</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

<!--===============================================================================================-->
        <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script src="/js/jquery.serializejson.js"></script>
        <link rel="stylesheet" type="text/css" href="/css/main.css">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
<!--===============================================================================================-->
</head>
<body>

        <div class="container-contact100">
                <div class="wrap-contact100">
                        <form id="content" class="contact100-form validate-form">
                                <span class="contact100-form-title">
                                        Approval task
                                </span>

                                <div class="wrap-input100 validate-input bg1">
                                        <h4>
                                                Approval from pipeline gitlab-pipelinerun-4wwb2
                                        </h4>
                                </div>

                                <div class="wrap-input100 validate-input bg0 rs1-alert-validate">
                                        <span class="label-input100">Comment</span>
                                        <textarea id="comment" class="input100" name="message" placeholder="Add your comment here..."></textarea>
                                </div>

                                <div class="container-contact100-form-btn">
                                        <button id="approveButton" class="contact100-form-btn approve">
                                                <span>
                                                        Approve
                                                </span>
                                        </button>

                                        <button id="rejectButton" class="contact100-form-btn reject">
                                                <span>
                                                        Reject
                                                </span>
                                        </button>
                                </div>
                        </form>
                </div>
        </div>

<script type="text/javascript">
        let taskActionUrl = "/approvals/55ac8202-86ac-3f4e-a69d-716e23feaf8a/single/55ac8202-86ac-3f4e-a69d-716e23feaf8a:941340af-117d-45f0-952f-df8e125d8d3e/approval/51888cf2-d920-43f6-a1e8-3eaabebcaccc?redirect=true&user=john";

        let completeTask = function(approved, comment) {

                $.ajax({
                        url : taskActionUrl,
                        type : 'POST',
                        dataType : 'json',
                        contentType: 'application/json',
                        data: JSON.stringify({'approval': approved, 'comment': comment}),
                        crossDomain : true,
                        success : function(data) {
                                if (approved) {
                                        $( "#content" ).parent()
                                    .append(
                                      $('<div  style="text-align: center;"> '+
                                                '       <span class="fa fa-check" style="font-size:60px;"></span> '+
                                                '       <br/><br/><br/><br/> '+
                                                '       <h3 style="text-align: center;">Pipeline "gitlab-pipelinerun-4wwb2" has been approved</h3> '+
                                                '       </div>')
                                    );
                                } else {
                                        $( "#content" ).parent()
                                    .append(
                                      $('<div  style="text-align: center;"> '+
                                                                '       <span class="fa fa-ban" style="font-size:60px;"></span> '+
                                                                '       <br/><br/><br/><br/> '+
                                                                '       <h3 style="text-align: center;">Pipeline "gitlab-pipelinerun-4wwb2" has been rejected</h3> '+
                                                                '       </div>')
                                    );
                                }
                                $( "#content" ).remove();

                        },
                        error : function(req, status, error) {
                                console.error("Task complete failed with " + status + ", error: " + error);
                        }
                });

        }

        $(document).ready(function() {
                $('#content').submit(false);

                $( "#approveButton" ).on( "click", function() {
                        completeTask(true, $( "#comment" ).val());

                });

                $( "#rejectButton" ).on( "click", function() {
                        completeTask(false, $( "#comment" ).val());

                });

        });
        </script>
</body>
</html>

Next search from http://automatiko-approval-task.default/, fill Pipeline run name: gitlab-pipelinerun-4wwb2 and Approver: john in form.

I get HTTP 404 code, and response.

{"processInstanceId":"gitlab-pipelinerun-4wwb2-approval","message":"Process instance with id gitlab-pipelinerun-4wwb2-approval not found"}

hillbun commented 2 years ago

I get automatiko-approval-task logs

2022-08-11 07:17:42,307 INFO  [io.aut.tek.tas.app.int.ApprovalTaskResourceOperations] (EventHandler-runs) New approval task has been created RunStatus [startTime=2022-08-11T07:17:42Z, results=null, conditions=[{reason=Succeeded, message=Approval Task has been created, status=Unknown}]]
2022-08-11 07:17:42,309 INFO  [io.aut.eng.add.per.fil.job.FileSystemBasedJobService] (EventHandler-runs) Timer scheduled for date 2022-08-11T08:17:42.309295Z[GMT] will expire in 3599999
io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException: Process instance with id gitlab-pipelinerun-4wwb2-approval not found
        at io.automatiko.tekton.tasks.approval.ApprovalsResource.lambda$get_approvals$5(ApprovalsResource.java:94)
        at java.util.Optional.orElseThrow(Optional.java:408)
        at io.automatiko.tekton.tasks.approval.ApprovalsResource.lambda$getTasks_approvals$20(ApprovalsResource.java:194)
        at io.automatiko.engine.services.uow.UnitOfWorkExecutor.executeInUnitOfWork(UnitOfWorkExecutor.java:27)
        at io.automatiko.tekton.tasks.approval.ApprovalsResource.getTasks_approvals(ApprovalsResource.java:193)
        at io.automatiko.tekton.tasks.approval.ApprovalsResource$quarkusrestinvoker$getTasks_approvals_ba1833a3b5830bd30bdc7b109c14d5a49813a2ed.invoke(Unknown Source)
        at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
        at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:108)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:141)
        at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:554)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
        at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
        at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Thread.java:829)
        at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:704)
        at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202)
io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException: Process instance with id gitlab-pipelinerun-4wwb2-approval not found
        at io.automatiko.tekton.tasks.approval.ApprovalsResource.lambda$get_approvals$5(ApprovalsResource.java:94)
        at java.util.Optional.orElseThrow(Optional.java:408)
        at io.automatiko.tekton.tasks.approval.ApprovalsResource.lambda$getTasks_approvals$20(ApprovalsResource.java:194)
        at io.automatiko.engine.services.uow.UnitOfWorkExecutor.executeInUnitOfWork(UnitOfWorkExecutor.java:27)
        at io.automatiko.tekton.tasks.approval.ApprovalsResource.getTasks_approvals(ApprovalsResource.java:193)
        at io.automatiko.tekton.tasks.approval.ApprovalsResource$quarkusrestinvoker$getTasks_approvals_ba1833a3b5830bd30bdc7b109c14d5a49813a2ed.invoke(Unknown Source)
        at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
        at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:108)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:141)
        at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:554)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
        at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
        at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Thread.java:829)
        at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:704)
        at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202)
io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException: Process instance with id gitlab-pipelinerun-4wwb2-approval not found
        at io.automatiko.tekton.tasks.approval.ApprovalsResource.lambda$get_approvals$5(ApprovalsResource.java:94)
        at java.util.Optional.orElseThrow(Optional.java:408)
        at io.automatiko.tekton.tasks.approval.ApprovalsResource.lambda$getTasks_approvals$20(ApprovalsResource.java:194)
        at io.automatiko.engine.services.uow.UnitOfWorkExecutor.executeInUnitOfWork(UnitOfWorkExecutor.java:27)
        at io.automatiko.tekton.tasks.approval.ApprovalsResource.getTasks_approvals(ApprovalsResource.java:193)
        at io.automatiko.tekton.tasks.approval.ApprovalsResource$quarkusrestinvoker$getTasks_approvals_ba1833a3b5830bd30bdc7b109c14d5a49813a2ed.invoke(Unknown Source)
        at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
        at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:108)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:141)
        at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:554)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
        at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
        at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Thread.java:829)
        at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:704)
        at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202)
mswiderski commented 2 years ago

I found the issue, it is caused by the hardcoded name used by the search where it assumes the task name in the pipeline will be called approval and in you case it is deploy-dev-approval-task. I am going to fix it today.

I think that the fix will have to include both name of the pipeline and name of the task to search as there might be multiple approvals active for the same pipeline. In meantime please rename your approval task in pipeline to approval and that will solve the problem.

hillbun commented 2 years ago

So when you release new version today, I can define task name at liberty?

mswiderski commented 2 years ago

yes, that's exactly what will be there

mswiderski commented 2 years ago

new release with fixed search is now out, move your installation to 0.3.2 and hopefully this will address the issue with using any name of the task.

hillbun commented 2 years ago

I try and it is fixed.

But Task name field is mandatory, I suggest it could be optional due to it is more convenient for me.

mswiderski commented 2 years ago

Unfortunately it must be mandatory as it has no context what you are searching for so both must be given as each approval task is independent and isolated. So they are not like in db grouped by pipeline run name.

Anyway, you can make use of the emails integration to pretty much remove the need for searching.

If you consider the problems to be fixed feel free to close the issue.

hillbun commented 2 years ago

Can can I get links like this?

http:///automatiko-approval-task.default/management/tasks/link/c2luZ2xlfDY2MzFkY2QxLWEzZDAtMzRjZi1hNDA1LWFhMTk5Yjg5NmQ3ZjoyNGQ3YzZkNy0xNmRhLTRjN2QtYjk0My1hMmU3YmFjNzM1ODl8N2VmNzA5ZWMtY2NmNS00YmZmLTg5NGEtNDIyN2UxMmQ0NjY2fA==?user=john&group=

Or a link to show task search result link for query?

Pipeline run name: gitlab-pipelinerun-tqkng Task name: deploy-dev-approval-task Approver: john

mswiderski commented 2 years ago

have a look at configuring emails https://github.com/automatiko-io/automatiko-approval-task#notifications

then approvers will receive links directly over email so no need to go to the search at all. Note that email links are personal meaning they include the user info. Though for production use cases security should be configured as well (https://github.com/automatiko-io/automatiko-approval-task#secure-access-to-approval-tasks)

hillbun commented 2 years ago
                  taskRef:
                    apiVersion: tekton.automatiko.io/v1alpha1
                    kind: ApprovalTask
                    name: approvaltask

name: approvaltask, can the value of name be anything else? or must be approvaltask?

mswiderski commented 2 years ago

I believe it can be anything, apiVersion and kind are the ones that must stay as is. Though needs to be tested to confirm it.

hillbun commented 2 years ago
                    - name: deploy-dev-approval-task
                      taskRef:
                        apiVersion: tekton.automatiko.io/v1alpha1
                        kind: ApprovalTask
                        name: approvaltask
                      params:
                        - name: pipeline
                          value: "$(context.pipelineRun.name)"
                        - name: description
                          value: "Approval from pipeline $(context.pipeline.name)"
                        - name: approvers
                          value:
                            - "xxx@xxx.com"
                      runAfter:
                        - npm-task
                      workspaces:
                        - name: ws
                          workspace: ws
                    - name: deploy-dev-approved-task
                      when:
                        - input: $(tasks.deploy-dev-approval-task.results.decision)
                          operator: in
                          values: [ "true" ]
                      taskRef:
                        name: print-decision
                      runAfter:
                        - deploy-dev-approval-task
                      params:
                        - name: decision
                          value: "APPROVED"
                        - name: comment
                          value: $(tasks.deploy-dev-approval-task.results.comment)
                    - name: deploy-dev-rejected-task
                      when:
                        - input: $(tasks.deploy-dev-approval-task.results.decision)
                          operator: in
                          values: [ "false" ]
                      taskRef:
                        name: print-decision
                      runAfter:
                        - deploy-dev-approval-task
                      params:
                        - name: decision
                          value: "REJECTED"
                        - name: comment
                          value: $(tasks.deploy-dev-approval-task.results.comment)

after I approve task of deploy-dev-approval-task, from tekton dashboard, task status is completed

spec:
  approvers:
    - xxx@xxx.com
  description: Approval from pipeline gitlab-pipelinerun-ztspf
  groups: []  pipeline: gitlab-pipelinerun-ztspf
  strategy: SINGLE
status: 
  approvalUrl: ''
  message: Approval task has been completed
  results: 
    comment: OKOLKLO
    decision: 'true'
  status: completed

But deploy-dev-approved-task or deploy-dev-rejected-task do not start, keep pending status.

hillbun commented 2 years ago

I can not get any error log from pod of automatiko-approval-task

mswiderski commented 2 years ago

sorry, there was one missing file to be included in 0.3.2 and I missed it. I just pushed new release 0.3.3 so please upgrade. Let me know if it addressed the issue.

hillbun commented 2 years ago

Yes, it worlks properly.

thanks.