Skip to content

Commit

Permalink
Add support for configuring unbound forwarders
Browse files Browse the repository at this point in the history
This patch adds support for unbound forwarders configuration.
The end user / operator should create a configmap similar to
the one on demo/examples and the forwarder files will be mounted
in the unbound pod.
  • Loading branch information
omersch381 committed Jan 14, 2025
1 parent c44a879 commit c371267
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 25 deletions.
15 changes: 15 additions & 0 deletions demo/examples/unbound_forwarder_example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: designate-unbound-forwarders-config
data:
forwarders.conf: |
forward-zone:
name: "."
forward-addr: 8.8.8.8
forward-addr: 8.8.4.4
other.conf: |
forward-zone:
name: "."
forward-addr: 8.8.8.8
forward-addr: 8.8.4.4
31 changes: 6 additions & 25 deletions pkg/designateunbound/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ limitations under the License.
package designateunbound

import (
"fmt"

designatev1beta1 "github.com/openstack-k8s-operators/designate-operator/api/v1beta1"
designate "github.com/openstack-k8s-operators/designate-operator/pkg/designate"
common "github.com/openstack-k8s-operators/lib-common/modules/common"
Expand All @@ -28,36 +30,15 @@ import (
"k8s.io/utils/ptr"
)

const (
configVolume = "designateunbound-config"
)

// StatefulSet func
func StatefulSet(instance *designatev1beta1.DesignateUnbound,
configHash string,
labels map[string]string,
annotations map[string]string,
) *appsv1.StatefulSet {
var configMode int32 = 0640

volumes := []corev1.Volume{
{
Name: configVolume,
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
DefaultMode: &configMode,
SecretName: "designate-unbound-config-data",
},
},
},
}
mounts := []corev1.VolumeMount{
{
Name: configVolume,
MountPath: "/etc/unbound/conf.d",
ReadOnly: true,
},
}
serviceName := fmt.Sprintf("%s-unbound", designate.ServiceName)
volumes := GetVolumes(serviceName)
volumeMounts := GetVolumeMounts()

livenessProbe := &corev1.Probe{
// TODO might need tuning
Expand Down Expand Up @@ -126,7 +107,7 @@ func StatefulSet(instance *designatev1beta1.DesignateUnbound,
RunAsUser: ptr.To[int64](0),
},
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
VolumeMounts: mounts,
VolumeMounts: volumeMounts,
Resources: instance.Spec.Resources,
ReadinessProbe: readinessProbe,
LivenessProbe: livenessProbe,
Expand Down
67 changes: 67 additions & 0 deletions pkg/designateunbound/volumes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Copyright 2025.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package designateunbound

import (
corev1 "k8s.io/api/core/v1"
)

const (
configVolume = "designateunbound-config"
forwardersConfigVolume = "designateunbound-forwarders-config"
)

func GetVolumes(baseConfigMapName string) []corev1.Volume {
var configMode int32 = 0640
forwardersConfigOptional := true

return []corev1.Volume{
{
Name: configVolume,
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: baseConfigMapName + "-config-data",
DefaultMode: &configMode,
},
},
},
{
Name: forwardersConfigVolume,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: baseConfigMapName + "-forwarders-config",
},
Optional: &forwardersConfigOptional,
DefaultMode: &configMode,
},
},
},
}
}

func GetVolumeMounts() []corev1.VolumeMount {
return []corev1.VolumeMount{
{
Name: configVolume,
MountPath: "/etc/unbound/conf.d",
ReadOnly: true,
},
{
Name: forwardersConfigVolume,
MountPath: "/etc/unbound/conf.d/forwarders",
ReadOnly: true,
},
}
}

0 comments on commit c371267

Please sign in to comment.