use of io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyPeer in project strimzi-kafka-operator by strimzi.
the class CruiseControlTest method testRestApiPortNetworkPolicyWithNamespaceLabels.
@ParallelTest
public void testRestApiPortNetworkPolicyWithNamespaceLabels() {
NetworkPolicyPeer clusterOperatorPeer = new NetworkPolicyPeerBuilder().withNewPodSelector().withMatchLabels(Collections.singletonMap(Labels.STRIMZI_KIND_LABEL, "cluster-operator")).endPodSelector().withNewNamespaceSelector().withMatchLabels(Collections.singletonMap("nsLabelKey", "nsLabelValue")).endNamespaceSelector().build();
NetworkPolicy np = cc.generateNetworkPolicy(null, Labels.fromMap(Collections.singletonMap("nsLabelKey", "nsLabelValue")));
assertThat(np.getSpec().getIngress().stream().filter(ing -> ing.getPorts().get(0).getPort().equals(new IntOrString(CruiseControl.REST_API_PORT))).findFirst().orElse(null), is(notNullValue()));
List<NetworkPolicyPeer> rules = np.getSpec().getIngress().stream().filter(ing -> ing.getPorts().get(0).getPort().equals(new IntOrString(CruiseControl.REST_API_PORT))).map(NetworkPolicyIngressRule::getFrom).findFirst().orElseThrow();
assertThat(rules.size(), is(1));
assertThat(rules.contains(clusterOperatorPeer), is(true));
}
use of io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyPeer in project strimzi-kafka-operator by strimzi.
the class ModelUtilsTest method testCONetworkPolicyPeerNamespaceSelectorDifferentNSNoLabels.
@ParallelTest
public void testCONetworkPolicyPeerNamespaceSelectorDifferentNSNoLabels() {
NetworkPolicyPeer peer = new NetworkPolicyPeer();
ModelUtils.setClusterOperatorNetworkPolicyNamespaceSelector(peer, "my-ns", "my-operator-ns", null);
assertThat(peer.getNamespaceSelector().getMatchLabels(), is(nullValue()));
ModelUtils.setClusterOperatorNetworkPolicyNamespaceSelector(peer, "my-ns", "my-operator-ns", Labels.fromMap(emptyMap()));
assertThat(peer.getNamespaceSelector().getMatchLabels(), is(nullValue()));
}
use of io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyPeer in project strimzi-kafka-operator by strimzi.
the class ModelUtilsTest method testCONetworkPolicyPeerNamespaceSelectorSameNS.
@ParallelTest
public void testCONetworkPolicyPeerNamespaceSelectorSameNS() {
NetworkPolicyPeer peer = new NetworkPolicyPeer();
ModelUtils.setClusterOperatorNetworkPolicyNamespaceSelector(peer, "my-ns", "my-ns", null);
assertThat(peer.getNamespaceSelector(), is(nullValue()));
}
Aggregations