Skip to content

tests: Add E2E test for net-attach-def lifecycle#14

Open
ormergi wants to merge 8 commits intoAlonaKaplan:mainfrom
ormergi:e2e-nad-lifecycle
Open

tests: Add E2E test for net-attach-def lifecycle#14
ormergi wants to merge 8 commits intoAlonaKaplan:mainfrom
ormergi:e2e-nad-lifecycle

Conversation

@ormergi
Copy link
Copy Markdown
Contributor

@ormergi ormergi commented Mar 10, 2024

Rebased on (#13, first five commits)

This PR bootstrap Ginkgo e2e test suite and tests the OverlayNetwork corresponding NetworkAttachmentDefinition 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

ormergi added 5 commits March 10, 2024 04:09
Signed-off-by: Or Mergi <ormergi@redhat.com>
The imported version is v1.4.0 to complay with k8s api dependencies.

Signed-off-by: Or Mergi <ormergi@redhat.com>
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 <ormergi@redhat.com>
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 <ormergi@redhat.com>
Signed-off-by: Or Mergi <ormergi@redhat.com>
@ormergi ormergi changed the title E2e nad lifecycle tests: Add E2E test for net-attach-def lifecycle Mar 10, 2024
ormergi added 3 commits March 10, 2024 13:23
Signed-off-by: Or Mergi <ormergi@redhat.com>
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 <ormergi@redhat.com>
Test creation and deletion of the OverlayNetwork correspoinding
net-attach-def object according to OverlayNetwork state.

Signed-off-by: Or Mergi <ormergi@redhat.com>
@ormergi ormergi force-pushed the e2e-nad-lifecycle branch from e5c2583 to cbc99bf Compare March 10, 2024 11:24
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())
Copy link
Copy Markdown
Owner

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()})

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants