Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Do not delete constraint if it is attached #3801

Merged
merged 12 commits into from
Apr 12, 2024

Conversation

StanislavStefanov
Copy link
Contributor

@StanislavStefanov StanislavStefanov commented Apr 10, 2024

Description
Currently a Formation Constraint can be deleted even if it is attached to a Formation Template. Deleting attached constraint can cause isses with the existing formations or newly created formations from the attached Formation Type.
Changes proposed in this pull request:

  • Fail if the formation Constraint is attached to any Formation Template

Related issue(s)

  • ...

Pull Request status

  • Implementation
  • Unit tests
  • Integration tests
  • chart/compass/values.yaml is updated
  • Mocks are regenerated, using the automated script

@StanislavStefanov StanislavStefanov requested a review from a team as a code owner April 10, 2024 08:28
@kyma-bot kyma-bot added 🦖 team-raptor Team Raptor Label cla: yes Indicates the PR's author has signed the CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 10, 2024
@StanislavStefanov StanislavStefanov requested review from a team as code owners April 10, 2024 08:29
@StanislavStefanov StanislavStefanov added the 👋 request review Review required label Apr 10, 2024
Copy link
Member

@DimitarPetrov DimitarPetrov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comment - can we just remove the DB cascade and make sure that the DB is guarding us as a list mile?

return errors.Wrapf(err, "while listing Formation Template Constraint References for Constraint with ID %s", id)
}

formationTemplateIDs := make([]string, 0, len(formationTemplateConstraintReferences))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need this, can we just check the other slice's len?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formationTemplateConstraintReferences is used for the error check and the formationTemplateIDs is used in the error message.

The gathering of the template IDs can be moved inside if len(formationTemplateConstraintReferences) > 0 { but it wont make any performance difference

@@ -150,6 +151,20 @@ func (s *service) ListByFormationTemplateIDs(ctx context.Context, formationTempl

// Delete deletes formation constraint by id
func (s *service) Delete(ctx context.Context, id string) error {
formationTemplateConstraintReferences, err := s.formationTemplateConstraintReferenceRepo.ListByConstraintID(ctx, id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just use exists?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use Exist - but then we wouldnt know which are the Formation Templates from which the constraint has to be potentialy detached

@kyma-bot
Copy link

kyma-bot commented Apr 12, 2024

@StanislavStefanov: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pre-main-compass-gke-benchmark 7ece296 link false /test pre-main-compass-gke-benchmark

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

@kyma-bot kyma-bot added the lgtm Looks good to me! label Apr 12, 2024
@kyma-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: la4ezar

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:

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

@kyma-bot kyma-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 12, 2024
@kyma-bot kyma-bot merged commit a799c2d into main Apr 12, 2024
11 of 13 checks passed
@la4ezar la4ezar deleted the dont-delete-attached-constraints branch April 12, 2024 13:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. lgtm Looks good to me! size/L Denotes a PR that changes 100-499 lines, ignoring generated files. 🦖 team-raptor Team Raptor Label 👋 request review Review required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants