From 0e0f37b8a5ea3f3c7d4166f1d712cc00b7405532 Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Mon, 5 Feb 2024 14:13:33 +0530 Subject: [PATCH 1/4] fix deprettify results Signed-off-by: MUzairS15 --- server/meshmodel/kubernetes/policies/common.rego | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/meshmodel/kubernetes/policies/common.rego b/server/meshmodel/kubernetes/policies/common.rego index f0780a17ff7..64a45ace30f 100644 --- a/server/meshmodel/kubernetes/policies/common.rego +++ b/server/meshmodel/kubernetes/policies/common.rego @@ -26,7 +26,8 @@ get_array_index_to_patch(no_of_elements) := index { not no_of_elements == 0 # 0 based array indexing is followed - index = format_int(no_of_elements - 1, 10) + # patch the cofnig to the next position + index = format_int(no_of_elements, 10) } is_array(arr, mutated) = path { From 5f4b74f46882c1d7be72609b2462baa68fbfb7ba Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Mon, 5 Feb 2024 14:14:05 +0530 Subject: [PATCH 2/4] fix rel def Signed-off-by: MUzairS15 --- .../relationships/hierarchical_inventory.json | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/server/meshmodel/kubernetes/relationships/hierarchical_inventory.json b/server/meshmodel/kubernetes/relationships/hierarchical_inventory.json index e40d11e8573..fb92a88c70d 100644 --- a/server/meshmodel/kubernetes/relationships/hierarchical_inventory.json +++ b/server/meshmodel/kubernetes/relationships/hierarchical_inventory.json @@ -1,4 +1,4 @@ -{ + { "apiVersion": "core.meshery.io/v1alpha1", "kind": "Hierarchical", "metadata": { @@ -115,6 +115,7 @@ "containers", "_", "envFrom", + "0", "configMapRef", "name" ] @@ -136,6 +137,7 @@ "containers", "_", "envFrom", + "0", "configMapRef", "name" ] @@ -157,6 +159,7 @@ "containers", "_", "envFrom", + "0", "configMapRef", "name" ] @@ -178,6 +181,7 @@ "containers", "_", "envFrom", + "0", "configMapRef", "name" ] @@ -197,6 +201,7 @@ "containers", "_", "envFrom", + "0", "configMapRef", "name" ] @@ -218,6 +223,7 @@ "containers", "_", "envFrom", + "0", "configMapRef", "name" ] @@ -241,6 +247,7 @@ "containers", "_", "envFrom", + "0", "configMapRef", "name" ] @@ -256,4 +263,4 @@ } } ] -} \ No newline at end of file +} From 2a940e2ed9d35fd169e6d015ae78fa57d36f35ed Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Mon, 5 Feb 2024 16:45:39 +0530 Subject: [PATCH 3/4] support chaining Signed-off-by: MUzairS15 --- server/meshmodel/kubernetes/policies/common.rego | 2 +- .../kubernetes/policies/hierarchical_inventory.rego | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/server/meshmodel/kubernetes/policies/common.rego b/server/meshmodel/kubernetes/policies/common.rego index 64a45ace30f..a21e11e65c9 100644 --- a/server/meshmodel/kubernetes/policies/common.rego +++ b/server/meshmodel/kubernetes/policies/common.rego @@ -27,7 +27,7 @@ get_array_index_to_patch(no_of_elements) := index { # 0 based array indexing is followed # patch the cofnig to the next position - index = format_int(no_of_elements, 10) + index = format_int(no_of_elements - 1, 10) } is_array(arr, mutated) = path { diff --git a/server/meshmodel/kubernetes/policies/hierarchical_inventory.rego b/server/meshmodel/kubernetes/policies/hierarchical_inventory.rego index 577b5c22c33..1df6e7723ce 100644 --- a/server/meshmodel/kubernetes/policies/hierarchical_inventory.rego +++ b/server/meshmodel/kubernetes/policies/hierarchical_inventory.rego @@ -37,7 +37,10 @@ heirarchical_inventory_relationship[updated_comps] { allowed_component.traits.meshmap["meshmodel-metadata"].parentId == i updated_comp := apply_patch(allowed_component, service, from_selectors, to_selectors) - id := updated_comp.traits.meshmap.id + # The id is the combination of the _ + # eg: _ + # The client interceptor should rely on the id present in the traits only and hsould not bother to parse the above id, the above id is included to provided more context. + id := sprintf("%s_%s", [j, i]) } } From 86bd9b472a4f2177b76c09c2d4b940fea1d70a7b Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Mon, 5 Feb 2024 16:52:49 +0530 Subject: [PATCH 4/4] add comment Signed-off-by: MUzairS15 --- server/handlers/policy_relationship_handler.go | 3 +++ server/meshmodel/kubernetes/policies/common.rego | 1 - .../kubernetes/relationships/hierarchical_inventory.json | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/server/handlers/policy_relationship_handler.go b/server/handlers/policy_relationship_handler.go index de281bc35de..6e7d42b288c 100644 --- a/server/handlers/policy_relationship_handler.go +++ b/server/handlers/policy_relationship_handler.go @@ -108,6 +108,9 @@ func (h *Handler) EvaluateRelationshipPolicy( } evalresults[query] = result } + // Before starting the eval the design is de-prettified, so that we can use the relationships def correctly. + // The results contain the updated config. + // Prettify the results before sending it to client. evalResults = core.Format.Prettify(evalresults, false) // write the response diff --git a/server/meshmodel/kubernetes/policies/common.rego b/server/meshmodel/kubernetes/policies/common.rego index a21e11e65c9..f0780a17ff7 100644 --- a/server/meshmodel/kubernetes/policies/common.rego +++ b/server/meshmodel/kubernetes/policies/common.rego @@ -26,7 +26,6 @@ get_array_index_to_patch(no_of_elements) := index { not no_of_elements == 0 # 0 based array indexing is followed - # patch the cofnig to the next position index = format_int(no_of_elements - 1, 10) } diff --git a/server/meshmodel/kubernetes/relationships/hierarchical_inventory.json b/server/meshmodel/kubernetes/relationships/hierarchical_inventory.json index fb92a88c70d..611d6ef2288 100644 --- a/server/meshmodel/kubernetes/relationships/hierarchical_inventory.json +++ b/server/meshmodel/kubernetes/relationships/hierarchical_inventory.json @@ -1,4 +1,4 @@ - { +{ "apiVersion": "core.meshery.io/v1alpha1", "kind": "Hierarchical", "metadata": { @@ -263,4 +263,4 @@ } } ] -} +} \ No newline at end of file