tests: Add E2E test for net-attach-def lifecycle#14
Open
ormergi wants to merge 8 commits intoAlonaKaplan:mainfrom
Open
tests: Add E2E test for net-attach-def lifecycle#14ormergi wants to merge 8 commits intoAlonaKaplan:mainfrom
ormergi wants to merge 8 commits intoAlonaKaplan:mainfrom
Conversation
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>
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>
e5c2583 to
cbc99bf
Compare
AlonaKaplan
reviewed
Mar 11, 2024
| 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()) |
Owner
There was a problem hiding this comment.
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()})
}
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebased on (#13, first five commits)
This PR bootstrap Ginkgo e2e test suite and tests the
OverlayNetworkcorrespondingNetworkAttachmentDefinitionlifecycle; 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