From 91e31c167345b97e8a444e52dab56e59aab78e58 Mon Sep 17 00:00:00 2001 From: zhaohuiweixiao Date: Sat, 6 May 2023 17:47:19 +0800 Subject: [PATCH] Fix: restrict the rules that automatically add topology strategy to addons to be valid only for the yaml type (#5957) Signed-off-by: zhaohuihui --- pkg/addon/render.go | 4 ++++ pkg/addon/render_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/pkg/addon/render.go b/pkg/addon/render.go index d1f575292..a8ef22bbf 100644 --- a/pkg/addon/render.go +++ b/pkg/addon/render.go @@ -421,6 +421,10 @@ func renderResources(addon *InstallPackage, args map[string]interface{}) ([]comm // checkNeedAttachTopologyPolicy will check this addon want to deploy to runtime-cluster, but application template doesn't specify the // topology policy, then will attach the policy to application automatically. func checkNeedAttachTopologyPolicy(app *v1beta1.Application, addon *InstallPackage) bool { + // the cue template will not be attached topology policy for the white-box principle + if len(addon.AppCueTemplate.Data) != 0 { + return false + } if !isDeployToRuntime(addon) { return false } diff --git a/pkg/addon/render_test.go b/pkg/addon/render_test.go index 5b737922d..3509e8bdd 100644 --- a/pkg/addon/render_test.go +++ b/pkg/addon/render_test.go @@ -304,6 +304,29 @@ func TestAppComponentRender(t *testing.T) { } func TestCheckNeedAttachTopologyPolicy(t *testing.T) { + addon := &InstallPackage{ + AppCueTemplate: ElementFile{ + Data: "not empty", + Name: "template.cue", + }, + } + assert.Equal(t, checkNeedAttachTopologyPolicy(&v1beta1.Application{Spec: v1beta1.ApplicationSpec{Policies: []v1beta1.AppPolicy{{ + Type: v1alpha1.SharedResourcePolicyType, + }}}}, addon), false) + + addon0 := &InstallPackage{ + AppCueTemplate: ElementFile{ + Data: "", + Name: "template.cue", + }, + Meta: Meta{ + DeployTo: &DeployTo{RuntimeCluster: true}, + }, + } + assert.Equal(t, checkNeedAttachTopologyPolicy(&v1beta1.Application{Spec: v1beta1.ApplicationSpec{Policies: []v1beta1.AppPolicy{{ + Type: v1alpha1.SharedResourcePolicyType, + }}}}, addon0), true) + addon1 := &InstallPackage{ Meta: Meta{ DeployTo: nil, @@ -335,6 +358,7 @@ func TestCheckNeedAttachTopologyPolicy(t *testing.T) { assert.Equal(t, checkNeedAttachTopologyPolicy(&v1beta1.Application{Spec: v1beta1.ApplicationSpec{Policies: []v1beta1.AppPolicy{{ Type: v1alpha1.SharedResourcePolicyType, }}}}, addon4), true) + } func TestGenerateAppFrameworkWithCue(t *testing.T) {