diff --git a/pkg/watcher/dynamicwatcher/watch.go b/pkg/watcher/dynamicwatcher/watch.go index 45e58336f..62f91eae8 100644 --- a/pkg/watcher/dynamicwatcher/watch.go +++ b/pkg/watcher/dynamicwatcher/watch.go @@ -134,12 +134,6 @@ func (wh *WatchHandler) Stop(_ context.Context) { func (wh *WatchHandler) chooseWatcher(res schema.GroupVersionResource, opts metav1.ListOptions) (watch.Interface, error) { switch res.Resource { - case "applicationprofiles": - opts.ResourceVersion = softwarecomposition.ResourceVersionFullSpec - return wh.storageClient.ApplicationProfiles("").Watch(context.Background(), opts) - case "networkneighborhoods": - opts.ResourceVersion = softwarecomposition.ResourceVersionFullSpec - return wh.storageClient.NetworkNeighborhoods("").Watch(context.Background(), opts) case "pods": return wh.k8sClient.GetKubernetesClient().CoreV1().Pods("").Watch(context.Background(), opts) case "runtimerulealertbindings": @@ -152,7 +146,7 @@ func (wh *WatchHandler) chooseWatcher(res schema.GroupVersionResource, opts meta default: // Make sure the resource version is not our storage, if so we panic. if res.Group == kubescapeCustomResourceGroup { - return nil, fmt.Errorf("resource must use the storage client %s: %w", res.Resource, errNotImplemented) + return nil, fmt.Errorf("watch is not implemented by the kubescape storage client %s: %w", res.Resource, errNotImplemented) } return wh.k8sClient.GetDynamicClient().Resource(res).Watch(context.Background(), opts) diff --git a/pkg/watcher/dynamicwatcher/watch_test.go b/pkg/watcher/dynamicwatcher/watch_test.go index c4b2829d0..23b17af95 100644 --- a/pkg/watcher/dynamicwatcher/watch_test.go +++ b/pkg/watcher/dynamicwatcher/watch_test.go @@ -25,9 +25,7 @@ import ( ) var ( - resourcePod = schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"} - resourceNetworkNeighborhood = schema.GroupVersionResource{Group: "spdx.softwarecomposition.kubescape.io", Version: "v1beta1", Resource: "networkneighborhoods"} - resourceApplicationProfile = schema.GroupVersionResource{Group: "spdx.softwarecomposition.kubescape.io", Version: "v1beta1", Resource: "applicationprofiles"} + resourcePod = schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"} ) func init() { @@ -207,113 +205,11 @@ func getKey(obj runtime.Object) string { func TestStart_1(t *testing.T) { tt := []testObj{ - { - name: "list ApplicationProfiles", - resources: []schema.GroupVersionResource{resourceApplicationProfile}, - preCreatedObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindAP, mocks.TestCollection)}, - }, - { - name: "list NetworkNeighborhoods", - resources: []schema.GroupVersionResource{resourceNetworkNeighborhood}, - preCreatedObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindNN, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindNN, mocks.TestCollection)}, - }, { name: "watch Pods", resources: []schema.GroupVersionResource{resourcePod}, createObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindPod, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindPod, mocks.TestCollection)}, }, - { - name: "watch ApplicationProfiles", - resources: []schema.GroupVersionResource{resourceApplicationProfile}, - createObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindAP, mocks.TestCollection)}, - }, - { - name: "watch NetworkNeighborhoods", - resources: []schema.GroupVersionResource{resourceNetworkNeighborhood}, - createObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindNN, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindNN, mocks.TestCollection)}, - }, - } - - for _, tc := range tt { - t.Run(tc.name, func(t *testing.T) { - startTest(t, tc) - }) - } -} - -func TestStart_2(t *testing.T) { - tt := []testObj{ - { - name: "list and modify", - resources: []schema.GroupVersionResource{resourceApplicationProfile}, - preCreatedObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)}, - modifiedObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)}, - }, - { - name: "watch and modify", - resources: []schema.GroupVersionResource{resourceApplicationProfile}, - createObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)}, - modifiedObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)}, - }, - } - - for _, tc := range tt { - t.Run(tc.name, func(t *testing.T) { - startTest(t, tc) - }) - } -} - -func TestStart_3(t *testing.T) { - tt := []testObj{ - - { - name: "list and watch", - resources: []schema.GroupVersionResource{resourceApplicationProfile}, - preCreatedObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestCollection)}, - createObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)}, - }, - { - name: "list and delete", - resources: []schema.GroupVersionResource{resourceApplicationProfile}, - preCreatedObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)}, - deleteObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)}, - }, - } - - for _, tc := range tt { - t.Run(tc.name, func(t *testing.T) { - startTest(t, tc) - }) - } -} -func TestStart_4(t *testing.T) { - tt := []testObj{ - { - name: "watch, modify, and delete", - resources: []schema.GroupVersionResource{resourceApplicationProfile}, - createObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)}, - modifiedObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)}, - deleteObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)}, - }, - } - - for _, tc := range tt { - t.Run(tc.name, func(t *testing.T) { - startTest(t, tc) - }) - } -} - -func TestStart_5(t *testing.T) { - tt := []testObj{ - { - name: "multi watch, modify, and delete", - resources: []schema.GroupVersionResource{resourceApplicationProfile, resourceNetworkNeighborhood, resourcePod}, - createObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindAP, mocks.TestCollection), mocks.GetRuntime(mocks.TestKindNN, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindNN, mocks.TestCollection), mocks.GetRuntime(mocks.TestKindPod, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindPod, mocks.TestCollection)}, - modifiedObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindAP, mocks.TestCollection), mocks.GetRuntime(mocks.TestKindNN, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindNN, mocks.TestCollection), mocks.GetRuntime(mocks.TestKindPod, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindPod, mocks.TestCollection)}, - deleteObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindAP, mocks.TestCollection), mocks.GetRuntime(mocks.TestKindNN, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindNN, mocks.TestCollection), mocks.GetRuntime(mocks.TestKindPod, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindPod, mocks.TestCollection)}, - }, } for _, tc := range tt {