Skip to content

Commit 1e1f36c

Browse files
committed
LOG-8109 & LOG-8091 & NetworkPolicy refactor
1 parent 790b900 commit 1e1f36c

File tree

4 files changed

+391
-437
lines changed

4 files changed

+391
-437
lines changed

internal/constants/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ const (
7676
HTTPFormat = "kubeAPIAudit"
7777
SyslogReceiverPort = 10514
7878

79+
DefaultHTTPPort = int32(80)
80+
DefaultHTTPSPort = int32(443)
81+
7982
VolumeNameTrustedCA = "trusted-ca"
8083

8184
STDOUT = "stdout"

internal/network/network_policy.go

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,8 @@ import (
1818
// ReconcileClusterLogForwarderNetworkPolicy reconciles the NetworkPolicy for the clusterlogforwarder
1919
// It handles both AllowAllIngressEgress and RestrictIngressEgress rule sets, parsing ports from outputs and inputs when needed.
2020
func ReconcileClusterLogForwarderNetworkPolicy(k8Client client.Client, namespace, policyName, instanceName, component string, policyRuleSet obsv1.NetworkPolicyRuleSetType, outputs []obsv1.OutputSpec, inputs []obsv1.InputSpec, ownerRef metav1.OwnerReference, visitor func(o runtime.Object)) error {
21-
var egressPorts []factory.PortProtocol
22-
var ingressPorts []int32
23-
24-
// For RestrictIngressEgress, determine the ports to use based on URLs in outputs and defaults
25-
if policyRuleSet == obsv1.NetworkPolicyRuleSetTypeRestrictIngressEgress {
26-
// Parse ports from inputs (receiver inputs use TCP)
27-
if len(inputs) > 0 {
28-
ingressPorts = GetInputPorts(inputs)
29-
}
30-
31-
// Parse ports for egress from outputs and proxy configuration if any
32-
egressPortMap := map[factory.PortProtocol]bool{}
33-
// Parse ports with protocols from outputs
34-
if len(outputs) > 0 {
35-
GetOutputPortsWithProtocols(outputs, egressPortMap)
36-
37-
}
38-
// Add proxy ports if any for cluster-wide proxy configuration
39-
GetProxyPorts(egressPortMap)
40-
41-
// Convert map to slice
42-
egressPorts = make([]factory.PortProtocol, 0, len(egressPortMap))
43-
for pp := range egressPortMap {
44-
egressPorts = append(egressPorts, pp)
45-
}
46-
}
21+
egressPorts := DetermineEgressPortProtocols(outputs, policyRuleSet)
22+
ingressPorts := DetermineIngressPortProtocols(inputs, policyRuleSet)
4723

4824
desired := factory.NewNetworkPolicyWithProtocolPorts(namespace, policyName, instanceName, component, string(policyRuleSet), egressPorts, ingressPorts, visitor)
4925
utils.AddOwnerRefToObject(desired, ownerRef)

0 commit comments

Comments
 (0)