Skip to content

Commit 6236497

Browse files
fix
Signed-off-by: Yaroslav Borbat <[email protected]>
1 parent c584d1b commit 6236497

File tree

6 files changed

+73
-39
lines changed

6 files changed

+73
-39
lines changed

images/virtualization-artifact/pkg/controller/gc/cron_source_test.go

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package gc
218

319
import (
@@ -19,7 +35,7 @@ import (
1935
"github.com/deckhouse/virtualization-controller/pkg/common/testutil"
2036
)
2137

22-
var _ = FDescribe("CronSource", func() {
38+
var _ = Describe("CronSource", func() {
2339
const (
2440
// Every day at 00:00
2541
scheduleSpec = "0 * * * *"
@@ -31,7 +47,6 @@ var _ = FDescribe("CronSource", func() {
3147
fakeClient client.Client
3248
mgr *fakeGCManager
3349
fakeClock *clock.FakeClock
34-
//queue workqueue.RateLimitingInterface
3550
)
3651

3752
BeforeEach(func() {
@@ -50,7 +65,6 @@ var _ = FDescribe("CronSource", func() {
5065

5166
mgr = newFakeGCManager(fakeClient, time.Hour, 10)
5267
fakeClock = clock.NewFakeClock(time.Now())
53-
//queue = workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter())
5468
})
5569

5670
newSource := func(scheduleSpec string) *CronSource {
@@ -91,30 +105,6 @@ var _ = FDescribe("CronSource", func() {
91105
Expect(obj.Phase).NotTo(Equal(fakeObjectPhaseCompleted))
92106
}
93107
})
94-
95-
//It("should return the oldest object", func() {
96-
// // Every day at 00:00
97-
// scheduleSpec := "0 * * * *"
98-
// source := newSource(scheduleSpec)
99-
//
100-
// for i := range 2 {
101-
// namespace := fmt.Sprintf("test-namespace-%d", i)
102-
// for j := range 5 {
103-
// obj := NewFakeObject(fmt.Sprintf("fake-%d", j), namespace)
104-
// obj.Phase = fakeObjectPhaseCompleted
105-
//
106-
// Expect(obj.Phase).To(Equal(fakeObjectPhaseCompleted))
107-
// Expect(fakeClient.Create(context.Background(), obj)).To(Succeed())
108-
// }
109-
// }
110-
//
111-
// Expect(source.Start(context.Background(), nil, queue)).To(Succeed())
112-
// Expect(queue.Len()).To(Equal(0))
113-
//
114-
// fakeClock.Step(time.Hour * 25)
115-
//
116-
// Eventually(queue.Len()).WithTimeout(10 * time.Second).Should(Equal(20))
117-
//})
118108
})
119109

120110
func spawnFakeObjects(countNamespaces, countPerNamespace int, phase string, client client.Client) {

images/virtualization-artifact/pkg/controller/gc/fake.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package gc
218

319
import (

images/virtualization-artifact/pkg/controller/gc/filter.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package gc
218

319
import (

images/virtualization-artifact/pkg/controller/gc/suite_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package gc
218

319
import (

images/virtualization-artifact/pkg/controller/vm/gc.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,12 @@ func (m *vmimGCManager) ListForDelete(ctx context.Context) ([]client.Object, err
9393

9494
objs := make([]client.Object, 0, len(vmimList.Items))
9595
for _, vmim := range vmimList.Items {
96-
if m.ShouldBeDeleted(&vmim) {
97-
objs = append(objs, &vmim)
98-
}
96+
objs = append(objs, &vmim)
9997
}
100-
objs = gc.ExpiredFilter(objs, m.ttl)
101-
objs = gc.MaxByIndexFilter(objs, m.getIndex, m.max)
10298

103-
return objs, nil
99+
result := gc.DefaultFilter(objs, m.ShouldBeDeleted, m.ttl, m.getIndex, m.max)
100+
101+
return result, nil
104102
}
105103

106104
func (m *vmimGCManager) getIndex(obj client.Object) string {

images/virtualization-artifact/pkg/controller/vmop/gc.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,12 @@ func (m *vmopGCManager) ListForDelete(ctx context.Context) ([]client.Object, err
9494

9595
objs := make([]client.Object, 0, len(vmopList.Items))
9696
for _, vmop := range vmopList.Items {
97-
if m.ShouldBeDeleted(&vmop) {
98-
objs = append(objs, &vmop)
99-
}
97+
objs = append(objs, &vmop)
10098
}
101-
objs = gc.ExpiredFilter(objs, m.ttl)
102-
objs = gc.MaxByIndexFilter(objs, m.getIndex, m.max)
10399

104-
return objs, nil
100+
result := gc.DefaultFilter(objs, m.ShouldBeDeleted, m.ttl, m.getIndex, m.max)
101+
102+
return result, nil
105103
}
106104

107105
func (m *vmopGCManager) getIndex(obj client.Object) string {

0 commit comments

Comments
 (0)