-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add e2e for resource interpreter customization
Signed-off-by: changzhen <changzhen5@huawei.com>
- Loading branch information
1 parent
594ad9f
commit 4309b9d
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package framework | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
configv1alpha1 "github.com/karmada-io/karmada/pkg/apis/config/v1alpha1" | ||
karmada "github.com/karmada-io/karmada/pkg/generated/clientset/versioned" | ||
) | ||
|
||
// CreateResourceInterpreterCustomization create ResourceInterpreterCustomization with karmada client. | ||
func CreateResourceInterpreterCustomization(client karmada.Interface, customization *configv1alpha1.ResourceInterpreterCustomization) { | ||
ginkgo.By(fmt.Sprintf("Creating ResourceInterpreterCustomization(%s)", customization.Name), func() { | ||
_, err := client.ConfigV1alpha1().ResourceInterpreterCustomizations().Create(context.TODO(), customization, metav1.CreateOptions{}) | ||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) | ||
}) | ||
} | ||
|
||
// DeleteResourceInterpreterCustomization delete ResourceInterpreterCustomization with karmada client. | ||
func DeleteResourceInterpreterCustomization(client karmada.Interface, name string) { | ||
ginkgo.By(fmt.Sprintf("Deleting ResourceInterpreterCustomization(%s)", name), func() { | ||
err := client.ConfigV1alpha1().ResourceInterpreterCustomizations().Delete(context.TODO(), name, metav1.DeleteOptions{}) | ||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package helper | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
configv1alpha1 "github.com/karmada-io/karmada/pkg/apis/config/v1alpha1" | ||
) | ||
|
||
// NewResourceInterpreterCustomization will build a ResourceInterpreterCustomization object. | ||
func NewResourceInterpreterCustomization(name string) *configv1alpha1.ResourceInterpreterCustomization { | ||
return &configv1alpha1.ResourceInterpreterCustomization{ | ||
ObjectMeta: metav1.ObjectMeta{Name: name}, | ||
Spec: configv1alpha1.ResourceInterpreterCustomizationSpec{ | ||
Target: configv1alpha1.CustomizationTarget{ | ||
APIVersion: "apps/v1", | ||
Kind: "Deployment", | ||
}, | ||
Customizations: configv1alpha1.CustomizationRules{ | ||
ReplicaResource: &configv1alpha1.ReplicaResourceRequirement{ | ||
LuaScript: ` | ||
function GetReplicas(desiredObj) | ||
nodeClaim = {} | ||
resourceRequest = {} | ||
result = {} | ||
replica = desiredObj.spec.replicas + 1 | ||
result.resourceRequest = desiredObj.spec.template.spec.containers[1].resources.limits | ||
nodeClaim.nodeSelector = desiredObj.spec.template.spec.nodeSelector | ||
nodeClaim.tolerations = desiredObj.spec.template.spec.tolerations | ||
result.nodeClaim = {} | ||
result.nodeClaim = nil | ||
return replica, {} | ||
end`, | ||
}, | ||
}, | ||
}, | ||
} | ||
} |