// Creates a new line for the result table for a specific source type
Creates a new line for the result table for a specific source type
// Creates a new line for the result table for a specific source type
func createTableLineForSourceType(policy netv1.NetworkPolicy, peer netv1.NetworkPolicyPeer, ports []netv1.NetworkPolicyPort,
	policyType string, sourceType SourceType) TableLine {
	line := createTableLine(policy, ports, policyType)
	if sourceType == PodSelector {
		line.policyPods = sortAndJoinLabels(peer.PodSelector.MatchLabels)
		line.policyNamespace = line.namespace
		line.policyIpBlock = Wildcard
	}
	if sourceType == NamespaceSelector {
		line.policyNamespace = sortAndJoinLabels(peer.NamespaceSelector.MatchLabels)
		line.policyPods = Wildcard
		line.policyIpBlock = Wildcard
	}
	if sourceType == IpBlock {
		var exceptions string
		for _, exception := range peer.IPBlock.Except {
			exceptions = addCharIfNotEmpty(exceptions, "\n") + exception
		}
		line.policyIpBlock = fmt.Sprintf("CIDR: %s Except: [%s]", peer.IPBlock.CIDR, exceptions)
		line.policyPods = Wildcard
		line.policyNamespace = Wildcard
	}
	return line
}
func createTableLineForSourceType ( policy netv1 . NetworkPolicy , peer netv1 . NetworkPolicyPeer , ports [ ] netv1 . NetworkPolicyPort , policyType string , sourceType SourceType ) TableLine { line := createTableLine ( policy , ports , policyType ) if sourceType == PodSelector { line . policyPods = sortAndJoinLabels ( peer . PodSelector . MatchLabels ) line . policyNamespace = line . namespace line . policyIpBlock = Wildcard } if sourceType == NamespaceSelector { line . policyNamespace = sortAndJoinLabels ( peer . NamespaceSelector . MatchLabels ) line . policyPods = Wildcard line . policyIpBlock = Wildcard } if sourceType == IpBlock { var exceptions string for _ , exception := range peer . IPBlock . Except { exceptions = addCharIfNotEmpty ( exceptions , " \n " ) + exception } line . policyIpBlock = fmt . Sprintf ( " " , peer . IPBlock . CIDR , exceptions ) line . policyPods = Wildcard line . policyNamespace = Wildcard } return line }
Creates a new line for the result table for a specific source type
Creates a new line for the result table for a specific source type