Merge pull request #2856 from jameszhangyukun/e2e-depency

[E2E] add test case for resource interpreter customization
This commit is contained in:
karmada-bot 2022-11-28 09:32:10 +08:00 committed by GitHub
commit 3f0a19c192
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 59 additions and 0 deletions

View File

@ -594,4 +594,63 @@ end `,
})
})
})
ginkgo.Context("InterpreterOperation DependencyInterpretation testing", func() {
var saName string
var sa *corev1.ServiceAccount
ginkgo.BeforeEach(func() {
saName = saNamePrefix + rand.String(RandomStrLength)
sa = testhelper.NewServiceaccount(testNamespace, saName)
deployment = testhelper.NewDeploymentWithServiceAccount(testNamespace, deployment.Name, saName)
policy.Spec.PropagateDeps = true
customization = testhelper.NewResourceInterpreterCustomization(
"interpreter-customization"+rand.String(RandomStrLength),
configv1alpha1.CustomizationTarget{
APIVersion: "apps/v1",
Kind: "Deployment",
},
configv1alpha1.CustomizationRules{
DependencyInterpretation: &configv1alpha1.DependencyInterpretation{
LuaScript: `
function GetDependencies(desiredObj)
dependentSas = {}
refs = {}
if desiredObj.spec.template.spec.serviceAccountName ~= '' and desiredObj.spec.template.spec.serviceAccountName ~= 'default' then
dependentSas[desiredObj.spec.template.spec.serviceAccountName] = true
end
local idx = 1
for key, value in pairs(dependentSas) do
dependObj = {}
dependObj.apiVersion = 'v1'
dependObj.kind = 'ServiceAccount'
dependObj.name = key
dependObj.namespace = desiredObj.metadata.namespace
refs[idx] = dependObj
idx = idx + 1
end
return refs
end `,
},
})
})
ginkgo.It("DependencyInterpretation testing", func() {
ginkgo.By("check if the serviceAccount is propagated automatically", func() {
framework.CreateServiceAccount(kubeClient, sa)
ginkgo.DeferCleanup(func() {
framework.RemoveServiceAccount(kubeClient, sa.GetNamespace(), sa.GetName())
})
framework.WaitDeploymentPresentOnClusterFitWith(targetCluster, deployment.Namespace, deployment.Name,
func(deployment *appsv1.Deployment) bool {
return true
})
framework.WaitServiceAccountPresentOnClusterFitWith(targetCluster, deployment.Namespace, sa.GetName(),
func(sa *corev1.ServiceAccount) bool {
return true
})
})
})
})
})