Skip to content

Commit

Permalink
rebase on main
Browse files Browse the repository at this point in the history
  • Loading branch information
gertschouten committed Dec 13, 2024
1 parent 183fe13 commit b9e2cb2
Show file tree
Hide file tree
Showing 14 changed files with 573 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.fabric8.kubernetes.api.model.Affinity;
import io.fabric8.kubernetes.api.model.HostAlias;
import io.fabric8.kubernetes.api.model.LocalObjectReference;
import io.fabric8.kubernetes.api.model.PodDNSConfig;
import io.fabric8.kubernetes.api.model.PodSecurityContext;
import io.fabric8.kubernetes.api.model.Toleration;
import io.fabric8.kubernetes.api.model.TopologySpreadConstraint;
Expand Down Expand Up @@ -37,7 +38,7 @@
)
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@JsonPropertyOrder({"metadata", "imagePullSecrets", "securityContext", "terminationGracePeriodSeconds", "affinity",
"tolerations", "topologySpreadConstraints", "priorityClassName", "schedulerName", "hostAliases",
"tolerations", "topologySpreadConstraints", "priorityClassName", "schedulerName", "hostAliases", "dnsPolicy", "dnsConfig",
"enableServiceLinks", "tmpDirSizeLimit", "volumes"})
@EqualsAndHashCode
@ToString
Expand All @@ -53,6 +54,8 @@ public class PodTemplate implements HasMetadataTemplate, UnknownPropertyPreservi
private String priorityClassName;
private String schedulerName;
private List<HostAlias> hostAliases;
private PodDNSConfig dnsConfig;
private String dnsPolicy;
private Boolean enableServiceLinks;
private String tmpDirSizeLimit;
private List<AdditionalVolume> volumes;
Expand Down Expand Up @@ -174,6 +177,30 @@ public void setHostAliases(List<HostAlias> hostAliases) {
this.hostAliases = hostAliases;
}

@Description("The pod's DNSPolicy. " +
"Defaults to `ClusterFirst`. " +
"Valid values are `ClusterFirstWithHostNet`, `ClusterFirst`, `Default` or `None`.")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public String getDnsPolicy() {
return dnsPolicy;
}

public void setDnsPolicy(String dnsPolicy) {
this.dnsPolicy = dnsPolicy;
}

@Description("The pod's DNSConfig. " +
"If specified, the parameters specified here will be merged to the generated DNS configuration based on the DNSPolicy.")
@KubeLink(group = "core", version = "v1", kind = "poddnsconfig")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public PodDNSConfig getDnsConfig() {
return dnsConfig;
}

public void setDnsConfig(PodDNSConfig dnsConfig) {
this.dnsConfig = dnsConfig;
}

@Description("Indicates whether information about services should be injected into Pod's environment variables.")
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public Boolean getEnableServiceLinks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ void testKafkaConnectWithInvalidExternalConfiguration() {
assertMissingRequiredPropertiesMessage(exception.getMessage(), "valueFrom");
}

@Test
public void testKafkaConnectWithDnsConfig() {
createDeleteCustomResource("KafkaConnect-with-dnsConfig.yaml");
}

@BeforeAll
void setupEnvironment() {
client = new KubernetesClientBuilder().withConfig(new ConfigBuilder().withNamespace(NAMESPACE).build()).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public void testKafkaMirrorMaker2WithInvalidExternalConfiguration() {
assertMissingRequiredPropertiesMessage(exception.getMessage(), "valueFrom");
}

@Test
void testKafkaMirrorMaker2WithDnsConfig() {
createDeleteCustomResource("KafkaMirrorMaker2-with-dnsConfig.yaml");
}

@BeforeAll
void setupEnvironment() {
client = new KubernetesClientBuilder().withConfig(new ConfigBuilder().withNamespace(NAMESPACE).build()).build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaConnect
metadata:
name: test-kafka-connect
spec:
image: foo
replicas: 6
bootstrapServers: kafka:9092
template:
deployment:
metadata:
labels:
key1: label1
key2: label2
annotations:
key1: label1
key2: label2
pod:
metadata:
labels:
key1: label1
key2: label2
annotations:
key1: label1
key2: label2
imagePullSecrets:
- name: some-secret
- name: some-other-secret
dnsPolicy: "None"
dnsConfig:
nameservers:
- 192.0.2.1
searches:
- ns1.svc.cluster-domain.example
- my.dns.search.suffix
options:
- name: ndots
value: "2"
- name: edns0
securityContext:
runAsUser: 1000001
runAsGroup: 1000001
fsGroup: 0
terminationGracePeriodSeconds: 30
volumes:
- name: example-secret
secret:
secretName: secret-name
- name: example-configmap
configMap:
name: config-map-name
connectContainer:
volumeMounts:
- name: example-secret
mountPath: /path/to/mount/secret-volume
subPath: subPath1
initContainer:
volumeMounts:
- name: example-configmap
mountPath: /path/to/mount/cm-volume
podDisruptionBudget:
metadata:
labels:
key1: label1
key2: label2
annotations:
key1: label1
key2: label2
maxUnavailable: 1
apiService:
metadata:
labels:
key1: label1
key2: label2
annotations:
key1: label1
key2: label2
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaMirrorMaker2
metadata:
name: test-kafka-mirror-maker-2
spec:
image: foo
replicas: 6
connectCluster: target
clusters:
- alias: source
bootstrapServers: my-source-kafka:9092
- alias: target
bootstrapServers: my-target-kafka:9092
mirrors:
- sourceCluster: source
targetCluster: target
sourceConnector: {}
topicsPattern: my-topic
template:
deployment:
metadata:
labels:
key1: label1
key2: label2
annotations:
key1: label1
key2: label2
pod:
metadata:
labels:
key1: label1
key2: label2
annotations:
key1: label1
key2: label2
imagePullSecrets:
- name: some-secret
- name: some-other-secret
dnsPolicy: "None"
dnsConfig:
nameservers:
- 192.0.2.1
searches:
- ns1.svc.cluster-domain.example
- my.dns.search.suffix
options:
- name: ndots
value: "2"
- name: edns0
securityContext:
runAsUser: 1000001
runAsGroup: 1000001
fsGroup: 0
terminationGracePeriodSeconds: 30
volumes:
- name: example-secret
secret:
secretName: secret-name
- name: example-configmap
configMap:
name: config-map-name
connectContainer:
volumeMounts:
- name: example-secret
mountPath: /path/to/mount/secret-volume
subPath: subPath1
initContainer:
volumeMounts:
- name: example-configmap
mountPath: /path/to/mount/cm-volume
podDisruptionBudget:
metadata:
labels:
key1: label1
key2: label2
annotations:
key1: label1
key2: label2
maxUnavailable: 1
apiService:
metadata:
labels:
key1: label1
key2: label2
annotations:
key1: label1
key2: label2
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ public static Pod createStatefulPod(
.withPriorityClassName(template != null ? template.getPriorityClassName() : null)
.withSchedulerName(template != null && template.getSchedulerName() != null ? template.getSchedulerName() : "default-scheduler")
.withHostAliases(template != null ? template.getHostAliases() : null)
.withDnsPolicy(template != null ? template.getDnsPolicy() : null)
.withDnsConfig(template != null ? template.getDnsConfig() : null)
.withTopologySpreadConstraints(template != null ? template.getTopologySpreadConstraints() : null)
.endSpec()
.build();
Expand Down Expand Up @@ -339,6 +341,8 @@ public static PodTemplateSpec createPodTemplateSpec(
.withPriorityClassName(template != null ? template.getPriorityClassName() : null)
.withSchedulerName(template != null && template.getSchedulerName() != null ? template.getSchedulerName() : "default-scheduler")
.withHostAliases(template != null ? template.getHostAliases() : null)
.withDnsPolicy(template != null ? template.getDnsPolicy() : null)
.withDnsConfig(template != null ? template.getDnsConfig() : null)
.withTopologySpreadConstraints(template != null ? template.getTopologySpreadConstraints() : null)
.endSpec()
.build();
Expand Down Expand Up @@ -402,6 +406,8 @@ public static Pod createPod(
.withPriorityClassName(template != null ? template.getPriorityClassName() : null)
.withSchedulerName(template != null && template.getSchedulerName() != null ? template.getSchedulerName() : "default-scheduler")
.withHostAliases(template != null ? template.getHostAliases() : null)
.withDnsPolicy(template != null ? template.getDnsPolicy() : null)
.withDnsConfig(template != null ? template.getDnsConfig() : null)
.withTopologySpreadConstraints(template != null ? template.getTopologySpreadConstraints() : null)
.endSpec()
.build();
Expand Down Expand Up @@ -458,4 +464,4 @@ private static DeploymentStrategy rollingUpdateStrategy() {
/* test */ static List<LocalObjectReference> imagePullSecrets(PodTemplate template, List<LocalObjectReference> defaultValue) {
return template != null && template.getImagePullSecrets() != null ? template.getImagePullSecrets() : defaultValue;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimVolumeSource;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimVolumeSourceBuilder;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.PodDNSConfig;
import io.fabric8.kubernetes.api.model.PodDNSConfigBuilder;
import io.fabric8.kubernetes.api.model.PodDNSConfigOptionBuilder;
import io.fabric8.kubernetes.api.model.PodSecurityContextBuilder;
import io.fabric8.kubernetes.api.model.Quantity;
import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder;
Expand Down Expand Up @@ -954,6 +957,21 @@ public void testTemplate() {
.withIp("192.168.1.87")
.build();

String dnsPolicy = "None";
PodDNSConfig dnsConfig = new PodDNSConfigBuilder()
.withNameservers("192.0.2.1")
.withSearches("ns1.svc.cluster-domain.example", "my.dns.search.suffix")
.withOptions(
new PodDNSConfigOptionBuilder()
.withName("ndots")
.withValue("2")
.build(),
new PodDNSConfigOptionBuilder()
.withName("edns0")
.build()
)
.build();

ConfigMapVolumeSource configMap = new ConfigMapVolumeSourceBuilder()
.withName("configMap1")
.build();
Expand Down Expand Up @@ -1002,6 +1020,8 @@ public void testTemplate() {
.withPriorityClassName("top-priority")
.withSchedulerName("my-scheduler")
.withHostAliases(hostAlias1, hostAlias2)
.withDnsPolicy(dnsPolicy)
.withDnsConfig(dnsConfig)
.withEnableServiceLinks(false)
.withTmpDirSizeLimit("10Mi")
.withVolumes(additionalVolumeConfigMap, additionalVolumePvc)
Expand Down Expand Up @@ -1054,6 +1074,8 @@ public void testTemplate() {
assertThat(pod.getMetadata().getAnnotations().entrySet().containsAll(podAnots.entrySet()), is(true));
assertThat(pod.getSpec().getSchedulerName(), is("my-scheduler"));
assertThat(pod.getSpec().getHostAliases(), containsInAnyOrder(hostAlias1, hostAlias2));
assertThat(pod.getSpec().getDnsPolicy(), is(dnsPolicy));
assertThat(pod.getSpec().getDnsConfig(), is(dnsConfig));
assertThat(pod.getSpec().getEnableServiceLinks(), is(false));
assertThat(getVolume(pod, "strimzi-tmp").getEmptyDir().getSizeLimit(), is(new Quantity("10Mi")));
assertThat(getVolume(pod, additionalVolumeConfigMap.getName()).getConfigMap(), is(configMap));
Expand Down
Loading

0 comments on commit b9e2cb2

Please sign in to comment.