-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests: Add E2E test for net-attach-def lifecycle #14
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Or Mergi <[email protected]>
The imported version is v1.4.0 to complay with k8s api dependencies. Signed-off-by: Or Mergi <[email protected]>
This change enable the controller to create NetworkAttachmetDefinition objects [1]. [1] https://sdk.operatorframework.io/docs/building-operators/golang/advanced-topics/#adding-3rd-party-resources-to-your-operator Signed-off-by: Or Mergi <[email protected]>
On update/create of OverlayNetwork, create corresponding NetworkAttachmentDefinition. The NetworkAttachmentDefinition is created with OwnerReference [1] pointing to the reconciled object. Once the reconciled object is deleted the corresponding net-attach-def object is deleted as well by the cluster garbage collector. This change does not set the net-attach-def spec.config, it will be implemented in follow up commit. Do not fail when the reconciled OverlayNetwork object is it not found as it may got deleted just before getting into the reconcile loop. [1] https://sdk.operatorframework.io/docs/building-operators/ansible/reference/retroactively-owned-resources/ Signed-off-by: Or Mergi <[email protected]>
Signed-off-by: Or Mergi <[email protected]>
Signed-off-by: Or Mergi <[email protected]>
Setup cluster API client for tests. Runtime client is necessary to enable creating CRDs (e.g.: OverlayNetwork, NAD). The test suite create a Kubernetes Namespace "overlay-network-tests" for the tests and deleted when the test suite finish. Signed-off-by: Or Mergi <[email protected]>
Test creation and deletion of the OverlayNetwork correspoinding net-attach-def object according to OverlayNetwork state. Signed-off-by: Or Mergi <[email protected]>
e5c2583
to
cbc99bf
Compare
It("should create and delete net-attach-def according to OverlayNetwork state", func() { | ||
By("Create test OverlayNetwork instance") | ||
ovrlyNet := newTestOverlayNetwork(TestsNamespace, "test") | ||
Expect(RuntimeClient.Create(context.Background(), ovrlyNet)).To(Succeed()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please run the tests a project admin and not cluster-admin.
Chatgpt example of how it should be done-
Create a kubeconfig file for the project admin. Save it as kubeconfig-admin.yaml:
yaml
Copy code
apiVersion: v1
kind: Config
clusters:
- name: your-cluster-name
cluster:
server: https://your-cluster-server
certificate-authority-data:
users: - name: project-admin
user:
client-certificate-data:
client-key-data:
contexts: - name: project-admin-context
context:
cluster: your-cluster-name
user: project-admin
current-context: project-admin-context
Replace placeholders like your-cluster-name, https://your-cluster-server, , , and with the actual values.
Update your test code to use this custom kubeconfig file:
go
Copy code
import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
"path/filepath"
)
func getClientForProjectAdmin() (kubernetes.Interface, error) {
adminKubeconfigPath := "/path/to/kubeconfig-admin.yaml" // Update with the correct path
// Use the in-cluster config if running within a cluster, otherwise use the specified kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", adminKubeconfigPath)
if err != nil {
return nil, err
}
mgr, err := ctrl.NewManager(config, ctrlOptions)
if err != nil {
return nil, err
}
return client.New(mgr.GetConfig(), client.Options{Scheme: mgr.GetScheme(), Mapper: mgr.GetRESTMapper()})
}
Rebased on (#13, first five commits)
This PR bootstrap Ginkgo e2e test suite and tests the
OverlayNetwork
correspondingNetworkAttachmentDefinition
lifecycle; where the controller create/delete NAD when OverlayNetwork is created/delteted.The test suite create Namspace "overlay-network-tests" for tests and deletes it when the test suite finish.
How to run tests:
make functests