Skip to content

Commit

Permalink
fix(kubernetes): permit null properties of NetworkPolicy PortRules (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
maggieneterval committed Jan 9, 2020
1 parent 140982b commit cd6ac7c
Showing 1 changed file with 9 additions and 4 deletions.
Expand Up @@ -31,6 +31,7 @@
import com.netflix.spinnaker.clouddriver.model.SecurityGroup;
import com.netflix.spinnaker.clouddriver.model.SecurityGroupSummary;
import com.netflix.spinnaker.clouddriver.model.securitygroups.Rule;
import io.kubernetes.client.custom.IntOrString;
import io.kubernetes.client.models.V1NetworkPolicy;
import io.kubernetes.client.models.V1NetworkPolicyEgressRule;
import io.kubernetes.client.models.V1NetworkPolicyIngressRule;
Expand All @@ -43,6 +44,7 @@
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -143,10 +145,13 @@ private static Set<Rule> outboundRules(V1NetworkPolicy policy) {
}

private static Rule fromPolicyPort(V1NetworkPolicyPort policyPort) {
String port = policyPort.getPort().toString();
IntOrString port = policyPort.getPort();
return new PortRule()
.setProtocol(policyPort.getProtocol())
.setPortRanges(new TreeSet<>(Collections.singletonList(new StringPortRange(port))));
.setPortRanges(
port == null
? null
: new TreeSet<>(Collections.singletonList(new StringPortRange(port.toString()))));
}

@Data
Expand All @@ -160,8 +165,8 @@ private static class KubernetesV2SecurityGroupSummary implements SecurityGroupSu

@Data
private static class PortRule implements Rule {
private SortedSet<PortRange> portRanges;
private String protocol;
@Nullable private SortedSet<PortRange> portRanges;
@Nullable private String protocol;
}

@EqualsAndHashCode(callSuper = true)
Expand Down

0 comments on commit cd6ac7c

Please sign in to comment.