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

Creating a template sharing the same name as a deleted template causes an error #363

Closed
kqdeng opened this issue Nov 11, 2020 · 2 comments · Fixed by #371
Closed

Creating a template sharing the same name as a deleted template causes an error #363

kqdeng opened this issue Nov 11, 2020 · 2 comments · Fixed by #371
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@kqdeng
Copy link
Contributor

kqdeng commented Nov 11, 2020

Expected Behaviour

Templates can be successfully created even when it shares the same name as a deleted template.

Current Behaviour

Due to the fact that templates are soft deleted and the recent change of name also being a unique field, creating a template sharing the same name as a deleted template returns this error:

rpc error: code = Unknown desc = INSERT: pq: duplicate key value violates unique constraint "template_name_key"

Possible Solution

Steps to Reproduce (for bugs)

  1. create a unique constraint on name (if db isn't using the latest tink migrations)
alter table template add constraint template_name_key unique (name);
  1. create a workflow with a name
  2. delete the workflow
  3. create another workflow with the same name as in step 1

Context

At first, I thought the soft delete was to be able to get workflow data even after the associated template has been (soft) deleted, but this is not the case. Therefore, what exactly is the purpose of soft deleting?

Granted, there is a workaround for this (e.g. use a UUID as part of the name), but it seems unintuitive that new templates have to take deleted templates into consideration. Also, the only way to see what names have already been used is going into the db.

Your Environment

  • Operating System and version (e.g. Linux, Windows, MacOS):
    Ubuntu 18.04

  • How are you running Tinkerbell? Using Vagrant & VirtualBox, Vagrant & Libvirt, on Packet using Terraform, or give details:

  • Packet using Terraform (sandbox)
  • running all the latest images as of 11/11
  • added a unique constraint on template name in the db to match what's currently in the tink migrations
alter table template add constraint template_name_key unique (name);
  • Link to your project or a code example to reproduce issue:

Reproducing the error

/ # tink template create -n hello -p hello-world.yml
Created Template:  3119c312-2465-11eb-84af-0242ac130004
/ # tink template delete 3119c312-2465-11eb-84af-0242ac130004
/ # tink template create -n hello -p hello-world.yml
2020/11/11 21:31:18 rpc error: code = Unknown desc = INSERT: pq: duplicate key value violates unique constraint "template_name_key"

Getting a workflow with a deleted associated template

/ # tink template list
+--------------------------------------+-----------------+-------------------------------+-------------------------------+
| TEMPLATE ID                          | TEMPLATE NAME   | CREATED AT                    | UPDATED AT                    |
+--------------------------------------+-----------------+-------------------------------+-------------------------------+
| f1e780de-2460-11eb-ad81-0242ac130004 | hello-new-world | 2020-11-11 21:00:35 +0000 UTC | 2020-11-11 21:00:35 +0000 UTC |
+--------------------------------------+-----------------+-------------------------------+-------------------------------+
/ # tink workflow list
+--------------------------------------+--------------------------------------+-----------------------------------+-------------------------------+-------------------------------+
| WORKFLOW ID                          | TEMPLATE ID                          | HARDWARE DEVICE                   | CREATED AT                    | UPDATED AT                    |
+--------------------------------------+--------------------------------------+-----------------------------------+-------------------------------+-------------------------------+
| d3de4f6a-246c-11eb-933f-0242ac130004 | f1e780de-2460-11eb-ad81-0242ac130004 | {"device_1": "b4:96:91:5f:a9:50"} | 2020-11-11 22:25:39 +0000 UTC | 2020-11-11 22:25:39 +0000 UTC |
+--------------------------------------+--------------------------------------+-----------------------------------+-------------------------------+-------------------------------+
/ # tink workflow get d3de4f6a-246c-11eb-933f-0242ac130004
version: 0.1
name: hello_world
global_timeout: 6000
tasks:
- name: "hello-world"
  worker: "b4:96:91:5f:a9:50"
  actions:
  - name: "hello-world"
    image: hello-world
    timeout: 90

/ # tink template delete f1e780de-2460-11eb-ad81-0242ac130004
/ # tink workflow get d3de4f6a-246c-11eb-933f-0242ac130004
2020/11/11 23:01:12 rpc error: code = Unknown desc = failed to get template with ID: f1e780de-2460-11eb-ad81-0242ac130004: sql: no rows in result set

Original reporter: Matt Burns

@gianarb gianarb added the kind/bug Categorizes issue or PR as related to a bug. label Nov 12, 2020
@parauliya parauliya self-assigned this Nov 20, 2020
@parauliya
Copy link
Contributor

parauliya commented Nov 20, 2020

@kdeng3849 @gianarb ,
The reason behind doing a soft delete for template was to keep the workflow and whenever user wants to do a workflow get <workflow_id> it should get the workflow. But this is not happening right now as we are getting error while getting the workflow after deletion of it's template. And this is what we need to fix first.

Also regarding issue where user is not able to create a new template with the same name even after deleting the existing one, this is also an issue and needed a fix.

As per the above comment, I would like to do following fixes for this issue:

  1. Let the user create the template with the same name if the existing one is deleted (soft).
  2. Workflow get should not give the error even if the template is deleted.

Please let me know if you feel any concern with the approach or fixes asap.

@mattcburns
Copy link

mattcburns commented Nov 20, 2020

So is there no way to permanently delete a workflow template? It seems weird to me as a user that if I delete something it still hangs around.

parauliya pushed a commit to parauliya/tink that referenced this issue Nov 23, 2020
Signed-off-by: parauliya <aman@infracloud.io>
parauliya pushed a commit to parauliya/tink that referenced this issue Dec 4, 2020
Signed-off-by: parauliya <aman@infracloud.io>
parauliya pushed a commit to parauliya/tink that referenced this issue Dec 7, 2020
Signed-off-by: parauliya <aman@infracloud.io>
@mergify mergify bot closed this as completed in #371 Dec 7, 2020
mergify bot added a commit that referenced this issue Dec 7, 2020
Signed-off-by: parauliya <aman@infracloud.io>

## Description

This PR will fix allow user to create a template with the same name after deleting it. Before this, it was not possible because of an issue also after deleting a template all the workflow which were created with that template before deleting it will be able to access the template since we template will be deleted softly. 


## Why is this needed

Fixes: #363 

## How Has This Been Tested?
Tested all the scenarios mentioned in the linked issue manually using vagrant setup.

## How are existing users impacted? What migration steps/scripts do we need?

Have written a migration script for db.


## Checklist:

I have:

- [ ] updated the documentation and/or roadmap (if required)
- [x] added unit or e2e tests
- [ ] provided instructions on how to upgrade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
4 participants