Skip to content

Commit 951733f

Browse files
authored
Merge branch 'main' into fix/linode-machine-firewall-ref
2 parents eb3fd3f + 50188d8 commit 951733f

File tree

2 files changed

+67
-5
lines changed

2 files changed

+67
-5
lines changed

api/v1alpha2/linodemachine_types.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package v1alpha2
1818

1919
import (
20+
"slices"
21+
2022
"github.com/linode/linodego"
2123
corev1 "k8s.io/api/core/v1"
2224
"k8s.io/apimachinery/pkg/api/resource"
@@ -631,11 +633,9 @@ func (lm *LinodeMachine) GetCondition(condType string) *metav1.Condition {
631633
}
632634

633635
func (lm *LinodeMachine) DeleteCondition(condType string) {
634-
for i := range lm.Status.Conditions {
635-
if lm.Status.Conditions[i].Type == condType {
636-
lm.Status.Conditions = append(lm.Status.Conditions[:i], lm.Status.Conditions[i+1:]...)
637-
}
638-
}
636+
lm.Status.Conditions = slices.DeleteFunc(lm.Status.Conditions, func(c metav1.Condition) bool {
637+
return c.Type == condType
638+
})
639639
}
640640

641641
func (lm *LinodeMachine) IsPaused() bool {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Copyright 2023 Akamai Technologies, Inc.
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+
17+
package v1alpha2
18+
19+
import (
20+
"fmt"
21+
"testing"
22+
23+
"github.com/stretchr/testify/assert"
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
)
26+
27+
func TestDeleteCondition(t *testing.T) {
28+
t.Parallel()
29+
30+
tests := []struct {
31+
name string
32+
length int
33+
delta int
34+
del string
35+
}{
36+
{name: "empty", length: 0, del: "type0"},
37+
{name: "delete-only", length: 1, del: "type0", delta: -1},
38+
{name: "delete-first", length: 3, del: "type0", delta: -1},
39+
{name: "delete-last", length: 3, del: "type2", delta: -1},
40+
{name: "delete-missing", length: 3, del: "type3"},
41+
}
42+
43+
for _, tc := range tests {
44+
t.Run(tc.name, func(t *testing.T) {
45+
t.Parallel()
46+
47+
conds := make([]metav1.Condition, tc.length)
48+
for i := 0; i < tc.length; i++ {
49+
conds[i] = metav1.Condition{Type: fmt.Sprintf("type%d", i)}
50+
}
51+
lm := &LinodeMachine{
52+
Status: LinodeMachineStatus{
53+
Conditions: conds,
54+
},
55+
}
56+
57+
lm.DeleteCondition(tc.del)
58+
assert.NotContains(t, lm.Status.Conditions, tc.del)
59+
assert.Len(t, lm.Status.Conditions, tc.length+tc.delta)
60+
})
61+
}
62+
}

0 commit comments

Comments
 (0)