Skip to content

Commit

Permalink
refactor the approach to set dnsConfig in podBuilder
Browse files Browse the repository at this point in the history
Signed-off-by: Hemant <hkbiet@gmail.com>
  • Loading branch information
hkiiita committed Nov 13, 2024
1 parent def56c6 commit ab67af1
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions test/e2e/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,7 @@ type PodBuilder struct {
ResourceRequests corev1.ResourceList
ResourceLimits corev1.ResourceList
ReadinessProbe *corev1.Probe
DnsConfig *corev1.PodDNSConfig
}

func NewPodBuilder(name, ns, image string) *PodBuilder {
Expand Down Expand Up @@ -1492,14 +1493,8 @@ func (b *PodBuilder) WithReadinessProbe(probe *corev1.Probe) *PodBuilder {

// WithCustomDNSConfig adds a custom DNS Configuration to the Pod spec.
// It ensures that the DNSPolicy is set to 'None' and assigns the provided DNSConfig.
func (b *PodBuilder) WithCustomDNSConfig(dnsServerConfig *corev1.PodDNSConfig) *PodBuilder {
b.MutateFunc = func(pod *corev1.Pod) {
// Set DNSPolicy to None to allow custom DNSConfig
pod.Spec.DNSPolicy = corev1.DNSNone

// Assign the provided DNSConfig to the Pod's DNSConfig field
pod.Spec.DNSConfig = dnsServerConfig
}
func (b *PodBuilder) WithCustomDNSConfig(dnsConfig *corev1.PodDNSConfig) *PodBuilder {
b.DnsConfig = dnsConfig
return b
}

Expand Down Expand Up @@ -1545,6 +1540,13 @@ func (b *PodBuilder) Create(data *TestData) error {
// tolerate NoSchedule taint if we want Pod to run on control-plane Node
podSpec.Tolerations = controlPlaneNoScheduleTolerations()
}
if b.DnsConfig != nil {
// Set DNSPolicy to None to allow custom DNSConfig
podSpec.DNSPolicy = corev1.DNSNone

// Assign the provided DNSConfig to the Pod's DNSConfig field
podSpec.DNSConfig = b.DnsConfig
}
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: b.Name,
Expand Down

0 comments on commit ab67af1

Please sign in to comment.