Fix: restrict the rules that automatically add topology strategy to addons to be valid only for the yaml type (#5957)

Signed-off-by: zhaohuihui <zhaohuihui_yewu@cmss.chinamobile.com>
This commit is contained in:
zhaohuiweixiao
2023-05-06 21:47:19 +12:00
committed by GitHub
parent e675cdafc4
commit 91e31c1673
2 changed files with 28 additions and 0 deletions
+4
View File
@@ -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
}
+24
View File
@@ -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) {