Skip to content

Commit

Permalink
CoreDNS pod definition and Corefile template for control plane
Browse files Browse the repository at this point in the history
For cloud platforms where customers are allowed to bring their own
DNS post cluster install, an in-cluster DNS solution is required
for the installation to be successful.
Adding the manifest containing CoreDNS pod definition and Corefile
template to be used by the MCO instance running on the control plane.
  • Loading branch information
sadasu committed Nov 16, 2023
1 parent 43923bf commit e5a1767
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/controller/template/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ func renderTemplate(config RenderConfig, path string, b []byte) ([]byte, error)
funcs["urlHost"] = urlHost
funcs["urlPort"] = urlPort
funcs["isOpenShiftManagedDefaultLB"] = isOpenShiftManagedDefaultLB
funcs["cloudPlatformShortName"] = cloudPlatformShortName
tmpl, err := template.New(path).Funcs(funcs).Parse(string(b))
if err != nil {
return nil, fmt.Errorf("failed to parse template %s: %w", path, err)
Expand Down Expand Up @@ -687,3 +688,15 @@ func isOpenShiftManagedDefaultLB(cfg RenderConfig) bool {
}
return false
}

func cloudPlatformShortName(cfg RenderConfig) interface{} {
if cfg.Infra.Status.PlatformStatus != nil {
switch cfg.Infra.Status.PlatformStatus.Type {
case configv1.GCPPlatformType:
return "gcp"
default:
return ""
}
}
return ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
mode: 0644
path: "/etc/kubernetes/static-pod-resources/coredns/Corefile.tmpl"
contents:
inline: |
. {
errors
bufsize 512
health :18080
forward . {{`{{- range $upstream := .DNSUpstreams}} {{$upstream}}{{- end}}`}} {
policy sequential
}
cache 30
reload
template IN {{`{{ .Cluster.CloudLBRecordType }}`}} {{ .DNS.Spec.BaseDomain }} {
match ^api.{{ .DNS.Spec.BaseDomain }}
answer "{{`{{"{{ .Name }}"}}`}} 60 in {{`{{"{{ .Type }}"}}`}} {{ if gt (len (.Cluster.APILBIPs )) 0 }}{{ index (.Cluster.APILBIPs) 0 }}{{ end }}"
fallthrough
}
template IN {{`{{ .Cluster.CloudLBEmptyType }}`}} {{ .DNS.Spec.BaseDomain }} {
match ^api.{{ .DNS.Spec.BaseDomain }}
{{ if gt (len (.Cluster.APILBIPs )) 1 }}answer "{{`{{"{{ .Name }}"}}`}} 60 in {{`{{"{{ .Type }}"}}`}} {{ index (.Cluster.APILBIPs) 1 }}"{{ end }}
fallthrough
}
template IN {{`{{ .Cluster.CloudLBRecordType }}`}} {{ .DNS.Spec.BaseDomain }} {
match ^api-int.{{ .DNS.Spec.BaseDomain }}
answer "{{`{{"{{ .Name }}"}}`}} 60 in {{`{{"{{ .Type }}"}}`}} {{ if gt (len (.Cluster.APIIntLBIPs)) 0 }}{{ index (.Cluster.APIIntLBIPs) 0 }}{{ end }}"
fallthrough
}
template IN {{`{{ .Cluster.CloudLBEmptyType }}`}} {{ .DNS.Spec.BaseDomain }} {
match ^api-int.{{ .DNS.Spec.BaseDomain }}
{{ if gt (len (.Cluster.APIIntLBIPs)) 1 }}answer "{{`{{"{{ .Name }}"}}`}} 60 in {{`{{"{{ .Type }}"}}`}} {{ index (.Cluster.APIIntLBIPs) 1 }}"{{ end }}
fallthrough
}
hosts {
{{`{{- range .Cluster.NodeAddresses }}
{{ .Address }} {{ .Name }} {{ .Name }}.{{ $.Cluster.Name }}.{{ $.Cluster.Domain }}
{{- end }}`}}
fallthrough
}
}
109 changes: 109 additions & 0 deletions templates/common/cloud-platform-alt-dns/files/coredns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
mode: 0644
path: {{ if gt (len (.CloudIntLBIPs)) 0 -}} "/etc/kubernetes/manifests/coredns.yaml" {{ else }} "/etc/kubernetes/disabled-manifests/coredns.yaml" {{ end }}
contents:
inline: |
kind: Pod
apiVersion: v1
metadata:
name: coredns
namespace: openshift-{{ cloudPlatformShortName . }}-infra
creationTimestamp:
deletionGracePeriodSeconds: 65
labels:
app: {{ cloudPlatformShortName . }}-infra-coredns
spec:
volumes:
- name: resource-dir
hostPath:
path: "/etc/kubernetes/static-pod-resources/coredns"
- name: kubeconfig
hostPath:
path: "/var/lib/kubelet"
- name: conf-dir
hostPath:
path: "/etc/coredns"
initContainers:
- name: render-config-coredns
image: {{ .Images.baremetalRuntimeCfgImage }}
command:
- runtimecfg
- render
- "/var/lib/kubelet/kubeconfig"
- "--cloud-ext-lb-ips"
- "{{- range $index, $ip := .CloudExtLBIPs }}{{ if gt $index 0 }},{{end}}{{$ip}}{{end}}"
- "--cloud-int-lb-ips"
- "{{- range $index, $ip := .CloudIntLBIPs }}{{ if gt $index 0 }},{{end}}{{$ip}}{{end}}"
- "/config"
- "--out-dir"
- "/etc/coredns"
resources: {}
volumeMounts:
- name: kubeconfig
mountPath: "/var/lib/kubelet"
mountPropagation: HostToContainer
- name: resource-dir
mountPath: "/config"
mountPropagation: HostToContainer
- name: conf-dir
mountPath: "/etc/coredns"
mountPropagation: HostToContainer
imagePullPolicy: IfNotPresent
containers:
- name: coredns
securityContext:
privileged: true
image: {{.Images.corednsImage}}
args:
- "--conf"
- "/etc/coredns/Corefile"
resources:
requests:
cpu: 100m
memory: 200Mi
volumeMounts:
- name: conf-dir
mountPath: "/etc/coredns"
livenessProbe:
httpGet:
path: /health
port: 18080
scheme: HTTP
initialDelaySeconds: 60
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 5
terminationMessagePolicy: FallbackToLogsOnError
imagePullPolicy: IfNotPresent
- name: coredns-monitor
securityContext:
privileged: true
image: {{ .Images.baremetalRuntimeCfgImage }}
command:
- corednsmonitor
- "/var/lib/kubelet/kubeconfig"
- "/config/Corefile.tmpl"
- "/etc/coredns/Corefile"
- "--cloud-ext-lb-ips"
- "{{- range $index, $ip := .CloudExtLBIPs }}{{ if gt $index 0 }},{{end}}{{$ip}}{{end}}"
- "--cloud-int-lb-ips"
- "{{- range $index, $ip := .CloudIntLBIPs }}{{ if gt $index 0 }},{{end}}{{$ip}}{{end}}"
resources:
requests:
cpu: 100m
memory: 200Mi
volumeMounts:
- name: kubeconfig
mountPath: "/var/lib/kubelet"
mountPropagation: HostToContainer
- name: resource-dir
mountPath: "/config"
mountPropagation: HostToContainer
- name: conf-dir
mountPath: "/etc/coredns"
mountPropagation: HostToContainer
imagePullPolicy: IfNotPresent
hostNetwork: true
tolerations:
- operator: Exists
priorityClassName: system-node-critical
status: {}

0 comments on commit e5a1767

Please sign in to comment.