Skip to content

Commit 605efe8

Browse files
committed
new rule at first
1 parent d4d7d13 commit 605efe8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

calico.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,21 @@ func (s *Server) AddCalicoRule(profileName string, action string, protocol strin
2020
proto := numorstring.ProtocolFromString(protocol)
2121
rule.Protocol = &proto
2222
rule.Destination.Ports = []numorstring.Port{numorstring.SinglePort(uint16(p))}
23-
profile.Spec.IngressRules = append(profile.Spec.IngressRules, rule)
23+
if action == "allow" {
24+
rules := []api.Rule{rule}
25+
for _, ingressRule := range profile.Spec.IngressRules {
26+
rules = append(rules, ingressRule)
27+
}
28+
profile.Spec.IngressRules = rules
29+
} else if action == "deny" {
30+
rules := []api.Rule{rule}
31+
for _, egressRule := range profile.Spec.EgressRules {
32+
rules = append(rules, egressRule)
33+
}
34+
profile.Spec.EgressRules = rules
35+
} else {
36+
log.Fatal("action " + action + " is not allow or deny")
37+
}
2438
_, err = s.calico.Profiles().Apply(profile)
2539
if err != nil {
2640
log.Fatal(err)

0 commit comments

Comments
 (0)