Skip to content

Commit 7291749

Browse files
committed
remove watch for the storage client
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
1 parent 39d5448 commit 7291749

File tree

2 files changed

+2
-112
lines changed

2 files changed

+2
-112
lines changed

pkg/watcher/dynamicwatcher/watch.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,6 @@ func (wh *WatchHandler) Stop(_ context.Context) {
134134

135135
func (wh *WatchHandler) chooseWatcher(res schema.GroupVersionResource, opts metav1.ListOptions) (watch.Interface, error) {
136136
switch res.Resource {
137-
case "applicationprofiles":
138-
opts.ResourceVersion = softwarecomposition.ResourceVersionFullSpec
139-
return wh.storageClient.ApplicationProfiles("").Watch(context.Background(), opts)
140-
case "networkneighborhoods":
141-
opts.ResourceVersion = softwarecomposition.ResourceVersionFullSpec
142-
return wh.storageClient.NetworkNeighborhoods("").Watch(context.Background(), opts)
143137
case "pods":
144138
return wh.k8sClient.GetKubernetesClient().CoreV1().Pods("").Watch(context.Background(), opts)
145139
case "runtimerulealertbindings":
@@ -152,7 +146,7 @@ func (wh *WatchHandler) chooseWatcher(res schema.GroupVersionResource, opts meta
152146
default:
153147
// Make sure the resource version is not our storage, if so we panic.
154148
if res.Group == kubescapeCustomResourceGroup {
155-
return nil, fmt.Errorf("resource must use the storage client %s: %w", res.Resource, errNotImplemented)
149+
return nil, fmt.Errorf("watch is not implemented by the kubescape storage client %s: %w", res.Resource, errNotImplemented)
156150
}
157151

158152
return wh.k8sClient.GetDynamicClient().Resource(res).Watch(context.Background(), opts)

pkg/watcher/dynamicwatcher/watch_test.go

Lines changed: 1 addition & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ import (
2525
)
2626

2727
var (
28-
resourcePod = schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}
29-
resourceNetworkNeighborhood = schema.GroupVersionResource{Group: "spdx.softwarecomposition.kubescape.io", Version: "v1beta1", Resource: "networkneighborhoods"}
30-
resourceApplicationProfile = schema.GroupVersionResource{Group: "spdx.softwarecomposition.kubescape.io", Version: "v1beta1", Resource: "applicationprofiles"}
28+
resourcePod = schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}
3129
)
3230

3331
func init() {
@@ -207,113 +205,11 @@ func getKey(obj runtime.Object) string {
207205

208206
func TestStart_1(t *testing.T) {
209207
tt := []testObj{
210-
{
211-
name: "list ApplicationProfiles",
212-
resources: []schema.GroupVersionResource{resourceApplicationProfile},
213-
preCreatedObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindAP, mocks.TestCollection)},
214-
},
215-
{
216-
name: "list NetworkNeighborhoods",
217-
resources: []schema.GroupVersionResource{resourceNetworkNeighborhood},
218-
preCreatedObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindNN, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindNN, mocks.TestCollection)},
219-
},
220208
{
221209
name: "watch Pods",
222210
resources: []schema.GroupVersionResource{resourcePod},
223211
createObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindPod, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindPod, mocks.TestCollection)},
224212
},
225-
{
226-
name: "watch ApplicationProfiles",
227-
resources: []schema.GroupVersionResource{resourceApplicationProfile},
228-
createObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindAP, mocks.TestCollection)},
229-
},
230-
{
231-
name: "watch NetworkNeighborhoods",
232-
resources: []schema.GroupVersionResource{resourceNetworkNeighborhood},
233-
createObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindNN, mocks.TestNginx), mocks.GetRuntime(mocks.TestKindNN, mocks.TestCollection)},
234-
},
235-
}
236-
237-
for _, tc := range tt {
238-
t.Run(tc.name, func(t *testing.T) {
239-
startTest(t, tc)
240-
})
241-
}
242-
}
243-
244-
func TestStart_2(t *testing.T) {
245-
tt := []testObj{
246-
{
247-
name: "list and modify",
248-
resources: []schema.GroupVersionResource{resourceApplicationProfile},
249-
preCreatedObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)},
250-
modifiedObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)},
251-
},
252-
{
253-
name: "watch and modify",
254-
resources: []schema.GroupVersionResource{resourceApplicationProfile},
255-
createObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)},
256-
modifiedObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)},
257-
},
258-
}
259-
260-
for _, tc := range tt {
261-
t.Run(tc.name, func(t *testing.T) {
262-
startTest(t, tc)
263-
})
264-
}
265-
}
266-
267-
func TestStart_3(t *testing.T) {
268-
tt := []testObj{
269-
270-
{
271-
name: "list and watch",
272-
resources: []schema.GroupVersionResource{resourceApplicationProfile},
273-
preCreatedObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestCollection)},
274-
createObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)},
275-
},
276-
{
277-
name: "list and delete",
278-
resources: []schema.GroupVersionResource{resourceApplicationProfile},
279-
preCreatedObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)},
280-
deleteObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)},
281-
},
282-
}
283-
284-
for _, tc := range tt {
285-
t.Run(tc.name, func(t *testing.T) {
286-
startTest(t, tc)
287-
})
288-
}
289-
}
290-
func TestStart_4(t *testing.T) {
291-
tt := []testObj{
292-
{
293-
name: "watch, modify, and delete",
294-
resources: []schema.GroupVersionResource{resourceApplicationProfile},
295-
createObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)},
296-
modifiedObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)},
297-
deleteObjects: []runtime.Object{mocks.GetRuntime(mocks.TestKindAP, mocks.TestNginx)},
298-
},
299-
}
300-
301-
for _, tc := range tt {
302-
t.Run(tc.name, func(t *testing.T) {
303-
startTest(t, tc)
304-
})
305-
}
306-
}
307-
308-
func TestStart_5(t *testing.T) {
309-
tt := []testObj{
310-
{
311-
name: "multi watch, modify, and delete",
312-
resources: []schema.GroupVersionResource{resourceApplicationProfile, resourceNetworkNeighborhood, resourcePod},
313-
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)},
314-
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)},
315-
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)},
316-
},
317213
}
318214

319215
for _, tc := range tt {

0 commit comments

Comments
 (0)