Skip to content

Commit 9901047

Browse files
Add DNS fields (#222)
* Test script * Accept DNSPolicy, DNSConfig (no test or API/docs updates yet). * Adding tests for DNSPolicy. * Add Kubebuilder generated files. * Remove local test script. * Set dnsPolicy: Default in e2e tests. * Set dnsPolicy: ClusterFirst (the default value) in e2e tests. * Add support for custom PodDNSConfig * Remove leading capital letter in cr * document dnsPolicy, dnsConfig. --------- Co-authored-by: Eyal Yurman <Eyal.Yurman.-ND@disney.com>
1 parent c5db34c commit 9901047

9 files changed

Lines changed: 422 additions & 0 deletions

File tree

apis/druid/v1alpha1/druid_types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,14 @@ type DruidSpec struct {
290290

291291
// +optional
292292
Auth druidapi.Auth `json:"auth,omitempty"`
293+
294+
// See v1.DNSPolicy for more details.
295+
// +optional
296+
DNSPolicy v1.DNSPolicy `json:"dnsPolicy,omitempty" protobuf:"bytes,6,opt,name=dnsPolicy,casttype=DNSPolicy"`
297+
298+
// See v1.PodDNSConfig for more details.
299+
// +optional
300+
DNSConfig *v1.PodDNSConfig `json:"dnsConfig,omitempty" protobuf:"bytes,26,opt,name=dnsConfig"`
293301
}
294302

295303
// DruidNodeSpec Specification of `Druid` Node type and its configurations.
@@ -494,6 +502,14 @@ type DruidNodeSpec struct {
494502
// Dynamic Configurations for Druid. Applied through the dynamic configuration API.
495503
// +optional
496504
DynamicConfig runtime.RawExtension `json:"dynamicConfig,omitempty"`
505+
506+
// See v1.DNSPolicy for more details.
507+
// +optional
508+
DNSPolicy v1.DNSPolicy `json:"dnsPolicy,omitempty" protobuf:"bytes,6,opt,name=dnsPolicy,casttype=DNSPolicy"`
509+
510+
// See v1.PodDNSConfig for more details.
511+
// +optional
512+
DNSConfig *v1.PodDNSConfig `json:"dnsConfig,omitempty" protobuf:"bytes,26,opt,name=dnsConfig"`
497513
}
498514

499515
// ZookeeperSpec IGNORED (Future API): In order to make Druid dependency setup extensible from within Druid operator.

apis/druid/v1alpha1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chart/crds/druid.apache.org_druids.yaml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,46 @@ spec:
15011501
description: DisablePVCDeletionFinalizer Whether PVCs shall be deleted
15021502
on the deletion of the Druid cluster.
15031503
type: boolean
1504+
dnsConfig:
1505+
description: See v1.PodDNSConfig for more details.
1506+
properties:
1507+
nameservers:
1508+
description: |-
1509+
A list of DNS name server IP addresses.
1510+
This will be appended to the base nameservers generated from DNSPolicy.
1511+
Duplicated nameservers will be removed.
1512+
items:
1513+
type: string
1514+
type: array
1515+
options:
1516+
description: |-
1517+
A list of DNS resolver options.
1518+
This will be merged with the base options generated from DNSPolicy.
1519+
Duplicated entries will be removed. Resolution options given in Options
1520+
will override those that appear in the base DNSPolicy.
1521+
items:
1522+
description: PodDNSConfigOption defines DNS resolver options
1523+
of a pod.
1524+
properties:
1525+
name:
1526+
description: Required.
1527+
type: string
1528+
value:
1529+
type: string
1530+
type: object
1531+
type: array
1532+
searches:
1533+
description: |-
1534+
A list of DNS search domains for host-name lookup.
1535+
This will be appended to the base search paths generated from DNSPolicy.
1536+
Duplicated search paths will be removed.
1537+
items:
1538+
type: string
1539+
type: array
1540+
type: object
1541+
dnsPolicy:
1542+
description: See v1.DNSPolicy for more details.
1543+
type: string
15041544
dynamicConfig:
15051545
description: Dynamic Configurations for Druid. Applied through the
15061546
dynamic configuration API.
@@ -3367,6 +3407,46 @@ spec:
33673407
type: string
33683408
type: object
33693409
type: object
3410+
dnsConfig:
3411+
description: See v1.PodDNSConfig for more details.
3412+
properties:
3413+
nameservers:
3414+
description: |-
3415+
A list of DNS name server IP addresses.
3416+
This will be appended to the base nameservers generated from DNSPolicy.
3417+
Duplicated nameservers will be removed.
3418+
items:
3419+
type: string
3420+
type: array
3421+
options:
3422+
description: |-
3423+
A list of DNS resolver options.
3424+
This will be merged with the base options generated from DNSPolicy.
3425+
Duplicated entries will be removed. Resolution options given in Options
3426+
will override those that appear in the base DNSPolicy.
3427+
items:
3428+
description: PodDNSConfigOption defines DNS resolver options
3429+
of a pod.
3430+
properties:
3431+
name:
3432+
description: Required.
3433+
type: string
3434+
value:
3435+
type: string
3436+
type: object
3437+
type: array
3438+
searches:
3439+
description: |-
3440+
A list of DNS search domains for host-name lookup.
3441+
This will be appended to the base search paths generated from DNSPolicy.
3442+
Duplicated search paths will be removed.
3443+
items:
3444+
type: string
3445+
type: array
3446+
type: object
3447+
dnsPolicy:
3448+
description: See v1.DNSPolicy for more details.
3449+
type: string
33703450
druid.port:
33713451
description: DruidPort Used by the `Druid` process.
33723452
format: int32

config/crd/bases/druid.apache.org_druids.yaml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,46 @@ spec:
15011501
description: DisablePVCDeletionFinalizer Whether PVCs shall be deleted
15021502
on the deletion of the Druid cluster.
15031503
type: boolean
1504+
dnsConfig:
1505+
description: See v1.PodDNSConfig for more details.
1506+
properties:
1507+
nameservers:
1508+
description: |-
1509+
A list of DNS name server IP addresses.
1510+
This will be appended to the base nameservers generated from DNSPolicy.
1511+
Duplicated nameservers will be removed.
1512+
items:
1513+
type: string
1514+
type: array
1515+
options:
1516+
description: |-
1517+
A list of DNS resolver options.
1518+
This will be merged with the base options generated from DNSPolicy.
1519+
Duplicated entries will be removed. Resolution options given in Options
1520+
will override those that appear in the base DNSPolicy.
1521+
items:
1522+
description: PodDNSConfigOption defines DNS resolver options
1523+
of a pod.
1524+
properties:
1525+
name:
1526+
description: Required.
1527+
type: string
1528+
value:
1529+
type: string
1530+
type: object
1531+
type: array
1532+
searches:
1533+
description: |-
1534+
A list of DNS search domains for host-name lookup.
1535+
This will be appended to the base search paths generated from DNSPolicy.
1536+
Duplicated search paths will be removed.
1537+
items:
1538+
type: string
1539+
type: array
1540+
type: object
1541+
dnsPolicy:
1542+
description: See v1.DNSPolicy for more details.
1543+
type: string
15041544
dynamicConfig:
15051545
description: Dynamic Configurations for Druid. Applied through the
15061546
dynamic configuration API.
@@ -3367,6 +3407,46 @@ spec:
33673407
type: string
33683408
type: object
33693409
type: object
3410+
dnsConfig:
3411+
description: See v1.PodDNSConfig for more details.
3412+
properties:
3413+
nameservers:
3414+
description: |-
3415+
A list of DNS name server IP addresses.
3416+
This will be appended to the base nameservers generated from DNSPolicy.
3417+
Duplicated nameservers will be removed.
3418+
items:
3419+
type: string
3420+
type: array
3421+
options:
3422+
description: |-
3423+
A list of DNS resolver options.
3424+
This will be merged with the base options generated from DNSPolicy.
3425+
Duplicated entries will be removed. Resolution options given in Options
3426+
will override those that appear in the base DNSPolicy.
3427+
items:
3428+
description: PodDNSConfigOption defines DNS resolver options
3429+
of a pod.
3430+
properties:
3431+
name:
3432+
description: Required.
3433+
type: string
3434+
value:
3435+
type: string
3436+
type: object
3437+
type: array
3438+
searches:
3439+
description: |-
3440+
A list of DNS search domains for host-name lookup.
3441+
This will be appended to the base search paths generated from DNSPolicy.
3442+
Duplicated search paths will be removed.
3443+
items:
3444+
type: string
3445+
type: array
3446+
type: object
3447+
dnsPolicy:
3448+
description: See v1.DNSPolicy for more details.
3449+
type: string
33703450
druid.port:
33713451
description: DruidPort Used by the `Druid` process.
33723452
format: int32

controllers/druid/handler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,8 @@ func makePodSpec(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid, nodeSpecUn
11221122
SecurityContext: firstNonNilValue(nodeSpec.PodSecurityContext, m.Spec.PodSecurityContext).(*v1.PodSecurityContext),
11231123
ServiceAccountName: firstNonEmptyStr(nodeSpec.ServiceAccountName, m.Spec.ServiceAccount),
11241124
PriorityClassName: firstNonEmptyStr(nodeSpec.PriorityClassName, m.Spec.PriorityClassName),
1125+
DNSPolicy: v1.DNSPolicy(firstNonEmptyStr(string(nodeSpec.DNSPolicy), string(m.Spec.DNSPolicy))),
1126+
DNSConfig: firstNonNilValue(nodeSpec.DNSConfig, m.Spec.DNSConfig).(*v1.PodDNSConfig),
11251127
}
11261128

11271129
addAdditionalContainers(m, nodeSpec, &spec)

controllers/druid/handler_test.go

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package druid
22

33
import (
44
"io/ioutil"
5+
"reflect"
6+
"testing"
57

68
"github.com/ghodss/yaml"
79
. "github.com/onsi/ginkgo/v2"
@@ -213,3 +215,139 @@ func readAndUnmarshallResource(file string, res interface{}) error {
213215
}
214216
return nil
215217
}
218+
219+
func TestPodSpecDNSConfig(t *testing.T) {
220+
tests := []struct {
221+
name string
222+
nodeDNSConfig *corev1.PodDNSConfig
223+
specDNSConfig *corev1.PodDNSConfig
224+
expected *corev1.PodDNSConfig
225+
}{
226+
{
227+
name: "Both nil",
228+
nodeDNSConfig: nil,
229+
specDNSConfig: nil,
230+
expected: nil,
231+
},
232+
{
233+
name: "Only spec provided",
234+
nodeDNSConfig: nil,
235+
specDNSConfig: &corev1.PodDNSConfig{
236+
Nameservers: []string{"8.8.8.8"},
237+
Searches: []string{"example.com"},
238+
},
239+
expected: &corev1.PodDNSConfig{
240+
Nameservers: []string{"8.8.8.8"},
241+
Searches: []string{"example.com"},
242+
},
243+
},
244+
{
245+
name: "Only node provided",
246+
nodeDNSConfig: &corev1.PodDNSConfig{
247+
Nameservers: []string{"1.1.1.1"},
248+
Searches: []string{"node.local"},
249+
},
250+
specDNSConfig: nil,
251+
expected: &corev1.PodDNSConfig{
252+
Nameservers: []string{"1.1.1.1"},
253+
Searches: []string{"node.local"},
254+
},
255+
},
256+
{
257+
name: "Both provided, node wins",
258+
nodeDNSConfig: &corev1.PodDNSConfig{
259+
Nameservers: []string{"1.1.1.1"},
260+
Searches: []string{"node.local"},
261+
},
262+
specDNSConfig: &corev1.PodDNSConfig{
263+
Nameservers: []string{"8.8.8.8"},
264+
Searches: []string{"example.com"},
265+
},
266+
expected: &corev1.PodDNSConfig{
267+
Nameservers: []string{"1.1.1.1"},
268+
Searches: []string{"node.local"},
269+
},
270+
},
271+
}
272+
273+
for _, tc := range tests {
274+
t.Run(tc.name, func(t *testing.T) {
275+
m := &druidv1alpha1.Druid{
276+
Spec: druidv1alpha1.DruidSpec{
277+
DNSConfig: tc.specDNSConfig,
278+
},
279+
}
280+
nodeSpec := &druidv1alpha1.DruidNodeSpec{
281+
DNSConfig: tc.nodeDNSConfig,
282+
}
283+
podSpec := makePodSpec(nodeSpec, m, "unique", "dummySHA")
284+
if !reflect.DeepEqual(podSpec.DNSConfig, tc.expected) {
285+
t.Errorf("expected DNSConfig %v, got %v", tc.expected, podSpec.DNSConfig)
286+
}
287+
})
288+
}
289+
}
290+
291+
func TestPodSpecDNSConfigYAML(t *testing.T) {
292+
m, err := readDruidClusterSpecFromFile("testdata/druid-test-cr.yaml")
293+
if err != nil {
294+
t.Fatalf("failed to read cluster spec: %v", err)
295+
}
296+
nodeSpec := m.Spec.Nodes["middlemanagers"]
297+
podSpec := makePodSpec(&nodeSpec, m, "unique", "dummySHA")
298+
expectedDNSConfig := &corev1.PodDNSConfig{
299+
Nameservers: []string{"10.0.0.53"},
300+
Searches: []string{"example.local"},
301+
}
302+
if !reflect.DeepEqual(podSpec.DNSConfig, expectedDNSConfig) {
303+
t.Errorf("expected DNSConfig %v, got %v", expectedDNSConfig, podSpec.DNSConfig)
304+
}
305+
}
306+
307+
// TestPodSpecDNSPolicy verifies DNSPolicy resolution in makePodSpec.
308+
func TestPodSpecDNSPolicy(t *testing.T) {
309+
tests := []struct {
310+
name string
311+
nodeDNS string
312+
specDNS string
313+
expected corev1.DNSPolicy
314+
}{
315+
{"Both empty", "", "", corev1.DNSPolicy("")},
316+
{"Only spec provided", "", "ClusterFirst", corev1.DNSPolicy("ClusterFirst")},
317+
{"Only node provided", "Default", "", corev1.DNSPolicy("Default")},
318+
{"Both provided, node wins", "Default", "ClusterFirst", corev1.DNSPolicy("Default")},
319+
}
320+
321+
for _, tc := range tests {
322+
tc := tc // capture current test case
323+
t.Run(tc.name, func(t *testing.T) {
324+
m := &druidv1alpha1.Druid{
325+
Spec: druidv1alpha1.DruidSpec{
326+
DNSPolicy: corev1.DNSPolicy(tc.specDNS),
327+
},
328+
}
329+
nodeSpec := &druidv1alpha1.DruidNodeSpec{
330+
DNSPolicy: corev1.DNSPolicy(tc.nodeDNS),
331+
}
332+
podSpec := makePodSpec(nodeSpec, m, "unique", "dummySHA")
333+
if podSpec.DNSPolicy != tc.expected {
334+
t.Errorf("expected DNSPolicy %q, got %q", tc.expected, podSpec.DNSPolicy)
335+
}
336+
})
337+
}
338+
}
339+
340+
// TestPodSpecDNSPolicyYAML validates that the generated PodSpec DNSPolicy matches the expected value,
341+
// using the druid-test-cr.yaml as the single input file.
342+
func TestPodSpecDNSPolicyYAML(t *testing.T) {
343+
m, err := readDruidClusterSpecFromFile("testdata/druid-test-cr.yaml")
344+
if err != nil {
345+
t.Fatalf("failed to read cluster spec: %v", err)
346+
}
347+
nodeSpec := m.Spec.Nodes["middlemanagers"]
348+
podSpec := makePodSpec(&nodeSpec, m, "unique", "dummySHA")
349+
expectedDNSPolicy := corev1.DNSPolicy("ClusterFirst")
350+
if podSpec.DNSPolicy != expectedDNSPolicy {
351+
t.Errorf("expected DNSPolicy %q, got %q", expectedDNSPolicy, podSpec.DNSPolicy)
352+
}
353+
}

0 commit comments

Comments
 (0)