Skip to content

Commit 2acdac0

Browse files
authored
fix: skip non-security-group port groups in sg gc (#6961)
(cherry picked from commit 9250e9f) Signed-off-by: zhangzujian <zhangzujian.7@gmail.com>
1 parent b64752b commit 2acdac0

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

pkg/controller/gc.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,12 @@ func (c *Controller) gcSecurityGroup() error {
835835
if pg.Name == denyAllPg || pg.Name == defaultPg || pg.ExternalIDs[networkPolicyKey] != "" {
836836
continue
837837
}
838+
sg := pg.ExternalIDs[sgKey]
839+
if sg == "" {
840+
continue
841+
}
838842
// if port group not exist in security group, delete it
839-
if !sgSet.Has(pg.ExternalIDs["sg"]) {
843+
if !sgSet.Has(sg) {
840844
klog.Infof("ready to gc port group %s", pg.Name)
841845
needToDelPgs = append(needToDelPgs, pg.Name)
842846
}

pkg/controller/gc_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55

66
"github.com/scylladb/go-set/strset"
77
"github.com/stretchr/testify/require"
8+
"go.uber.org/mock/gomock"
89

10+
"github.com/kubeovn/kube-ovn/pkg/ovs"
911
"github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb"
1012
"github.com/kubeovn/kube-ovn/pkg/util"
1113
)
@@ -49,3 +51,21 @@ func Test_logicalRouterPortFilter(t *testing.T) {
4951
}
5052
}
5153
}
54+
55+
func TestGcSecurityGroupSkipsVpcEgressGatewayPortGroup(t *testing.T) {
56+
fakeController := newFakeController(t)
57+
ctrl := fakeController.fakeController
58+
mockOvnClient := fakeController.mockOvnClient
59+
60+
mockOvnClient.EXPECT().ListPortGroups(map[string]string{"vendor": util.CniTypeName}).Return([]ovnnb.PortGroup{{
61+
Name: "VEG.0b5177562709",
62+
ExternalIDs: map[string]string{
63+
"af": "4",
64+
ovs.ExternalIDVendor: util.CniTypeName,
65+
ovs.ExternalIDVpcEgressGateway: "default/egress-ha-a",
66+
},
67+
}}, nil)
68+
mockOvnClient.EXPECT().DeletePortGroup(gomock.Any()).Times(0)
69+
70+
require.NoError(t, ctrl.gcSecurityGroup())
71+
}

0 commit comments

Comments
 (0)