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

Fix ASA tenancy #3818

Merged
merged 25 commits into from
May 16, 2024
Merged

Fix ASA tenancy #3818

merged 25 commits into from
May 16, 2024

Conversation

la4ezar
Copy link
Contributor

@la4ezar la4ezar commented Apr 17, 2024

Description
When we delete a runtime that has ASA for it we should delete the associated scenarios labels and ASA for it. The problem is that the scenarios label is in the parent tenant and we are using the child tenant which comes from the context. But there are no such records in the database(for the child) and we don't process the scenarios labels, ASAs, and don't unassign the runtime from the formation.

Changes proposed in this pull request:

  • Fix ASA tenancy

Related issue(s)

  • ...

Pull Request status

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

@la4ezar la4ezar requested review from a team as code owners April 17, 2024 08:31
@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 17, 2024
@kyma-bot kyma-bot added 🦅 team-falcon Team Falcon Label size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 24, 2024
@@ -1499,7 +1503,7 @@ func (s *service) DeleteAutomaticScenarioAssignment(ctx context.Context, in *mod
return errors.Wrap(err, "while deleting the Assignment")
}

if err = s.asaEngine.RemoveAssignedScenario(ctx, in, s.UnassignFormation); err != nil {
if err = s.asaEngine.RemoveAssignedScenario(ctx, in, s.UnassignFormationIgnoreASA); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Using UnassignFormationIgnoreASA instead of UnassignFormation is not needed as in RemoveAssignedScenario the ASA is being deleted before using the processing function for unassign.

@@ -267,6 +267,7 @@ func TestServiceUnassignFormation(t *testing.T) {
ObjectType graphql.FormationObjectType
ObjectID string
InputFormation model.Formation
ShouldSkipASA bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test where the value is true and the scenario is comming from ASA to validate that it will be deleted.

@@ -862,35 +863,46 @@ func (r *Resolver) EventingConfiguration(ctx context.Context, obj *graphql.Runti
// deleteAssociatedScenarioAssignments ensures that scenario assignments which are responsible for creation of certain runtime labels are deleted,
Copy link
Contributor

Choose a reason for hiding this comment

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

Update the comment as the ASAs are not actualy deleted now

for _, parentTenantID := range tntMapping.Parents {
ctxWithParentTenant := tenant.SaveToContext(ctx, parentTenantID, "")

scenariosLbl, err := r.runtimeService.GetLabel(ctxWithParentTenant, runtimeID, model.ScenariosKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

The scenarioLabel will soon be removed. Instead of relying on it we should list the ASAs where the Tenant property of the ASA is amoung the tntMapping.Parents. Then we can remove the assigned scenarios using the ASAs. This will reduce the complexity and will remove unneeded calls to the DB.

@@ -1509,7 +1513,7 @@ func (s *service) DeleteAutomaticScenarioAssignment(ctx context.Context, in *mod
// RemoveAssignedScenarios removes all the scenarios that are coming from any of the provided ASAs
func (s *service) RemoveAssignedScenarios(ctx context.Context, in []*model.AutomaticScenarioAssignment) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename the method to something like UnassignFormationsCommingFromASA. The current name is a bit missleading.

Copy link
Contributor

Choose a reason for hiding this comment

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

Same applies to the asaEngine method as well


conditions := repo.Or(repo.ConditionTreesFromConditions(scenarioConditions)...)

if err := r.conditionLister.ListConditionTree(ctx, resource.AutomaticScenarioAssigment, tenantID, &collection, conditions); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use the standard lister with repo.NewInConditionForStringValues(scenarioColumn, scenarioNames) instead of this one

@@ -862,35 +863,46 @@ func (r *Resolver) EventingConfiguration(ctx context.Context, obj *graphql.Runti
// deleteAssociatedScenarioAssignments ensures that scenario assignments which are responsible for creation of certain runtime labels are deleted,
// if runtime doesn't have the scenarios label or is part of a scenario for which no scenario assignment exists => noop
func (r *Resolver) deleteAssociatedScenarioAssignments(ctx context.Context, runtimeID string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename the method as we no longer delete the ASAs

@ognyvrac
Copy link
Contributor

/hold

@kyma-bot kyma-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 13, 2024
}

scenarios, err := labelPkg.ValueToStringsSlice(scenariosLbl.Value)
scenarios, err := r.asaEngine.GetScenariosFromMatchingASAs(ctx, runtimeID, graphql.FormationObjectTypeRuntime)
Copy link
Contributor

Choose a reason for hiding this comment

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

use ctxWithParentTenant

@@ -37,6 +38,7 @@ type repository struct {
creator repo.CreatorGlobal
singleGetter repo.SingleGetter
lister repo.Lister
conditionLister repo.ConditionTreeLister
Copy link
Contributor

Choose a reason for hiding this comment

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

this lister is unused

Lachezar Bogomilov added 2 commits May 15, 2024 16:06
# Conflicts:
#	chart/compass/values.yaml
#	components/director/internal/domain/root_resolver.go
@kyma-bot
Copy link

kyma-bot commented May 15, 2024

@la4ezar: 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 fdf5ed3 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 May 16, 2024
@kyma-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: emmakarova, ognyvrac, StanislavStefanov

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 May 16, 2024
@la4ezar la4ezar removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 16, 2024
@kyma-bot kyma-bot merged commit ea62a40 into main May 16, 2024
7 checks passed
@la4ezar la4ezar deleted the fix-asa-tenancy branch May 16, 2024 12:58
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. 🦅 team-falcon Team Falcon Label lgtm Looks good to me! size/XXL Denotes a PR that changes 1000+ 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.

6 participants