Skip to content

Commit

Permalink
chore: improve integrated coredns
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianKramm committed Oct 2, 2023
1 parent 402cd8c commit e0b076c
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 194 deletions.
43 changes: 0 additions & 43 deletions charts/eks/templates/integrated-coredns.yaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,6 @@
{{- if .Values.pro }}
{{- if .Values.coredns.integrated }}
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}-dns
namespace: {{ .Release.Namespace }}
annotations:
prometheus.io/port: "9153"
prometheus.io/scrape: "true"
{{- if .Values.coredns.service.annotations }}
{{ toYaml .Values.coredns.service.annotations | indent 8 }}
{{- end }}
{{- if .Values.globalAnnotations }}
{{ toYaml .Values.globalAnnotations | indent 4 }}
{{- end }}
spec:
selector:
app: vcluster
release: {{ .Release.Name }}
type: {{ .Values.coredns.service.type }}
{{- if (eq (.Values.coredns.service.type) "LoadBalancer") }}
{{- if .Values.coredns.service.externalTrafficPolicy }}
externalTrafficPolicy: {{ .Values.coredns.service.externalTrafficPolicy }}
{{- end }}
{{- if .Values.coredns.service.externalIPs }}
externalIPs:
{{- range $f := .Values.coredns.service.externalIPs }}
- {{ $f }}
{{- end }}
{{- end }}
{{- end }}
ports:
- name: dns
port: 53
targetPort: 1053
protocol: UDP
- name: dns-tcp
port: 53
targetPort: 1053
protocol: TCP
- name: metrics
port: 9153
protocol: TCP
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-dns
Expand Down
43 changes: 0 additions & 43 deletions charts/k0s/templates/integrated-coredns.yaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,6 @@
{{- if .Values.pro }}
{{- if .Values.coredns.integrated }}
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}-dns
namespace: {{ .Release.Namespace }}
annotations:
prometheus.io/port: "9153"
prometheus.io/scrape: "true"
{{- if .Values.coredns.service.annotations }}
{{ toYaml .Values.coredns.service.annotations | indent 8 }}
{{- end }}
{{- if .Values.globalAnnotations }}
{{ toYaml .Values.globalAnnotations | indent 4 }}
{{- end }}
spec:
selector:
app: vcluster
release: {{ .Release.Name }}
type: {{ .Values.coredns.service.type }}
{{- if (eq (.Values.coredns.service.type) "LoadBalancer") }}
{{- if .Values.coredns.service.externalTrafficPolicy }}
externalTrafficPolicy: {{ .Values.coredns.service.externalTrafficPolicy }}
{{- end }}
{{- if .Values.coredns.service.externalIPs }}
externalIPs:
{{- range $f := .Values.coredns.service.externalIPs }}
- {{ $f }}
{{- end }}
{{- end }}
{{- end }}
ports:
- name: dns
port: 53
targetPort: 1053
protocol: UDP
- name: dns-tcp
port: 53
targetPort: 1053
protocol: TCP
- name: metrics
port: 9153
protocol: TCP
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-dns
Expand Down
43 changes: 0 additions & 43 deletions charts/k3s/templates/integrated-coredns.yaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,6 @@
{{- if .Values.pro }}
{{- if .Values.coredns.integrated }}
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}-dns
namespace: {{ .Release.Namespace }}
annotations:
prometheus.io/port: "9153"
prometheus.io/scrape: "true"
{{- if .Values.coredns.service.annotations }}
{{ toYaml .Values.coredns.service.annotations | indent 8 }}
{{- end }}
{{- if .Values.globalAnnotations }}
{{ toYaml .Values.globalAnnotations | indent 4 }}
{{- end }}
spec:
selector:
app: vcluster
release: {{ .Release.Name }}
type: {{ .Values.coredns.service.type }}
{{- if (eq (.Values.coredns.service.type) "LoadBalancer") }}
{{- if .Values.coredns.service.externalTrafficPolicy }}
externalTrafficPolicy: {{ .Values.coredns.service.externalTrafficPolicy }}
{{- end }}
{{- if .Values.coredns.service.externalIPs }}
externalIPs:
{{- range $f := .Values.coredns.service.externalIPs }}
- {{ $f }}
{{- end }}
{{- end }}
{{- end }}
ports:
- name: dns
port: 53
targetPort: 1053
protocol: UDP
- name: dns-tcp
port: 53
targetPort: 1053
protocol: TCP
- name: metrics
port: 9153
protocol: TCP
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-dns
Expand Down
43 changes: 0 additions & 43 deletions charts/k8s/templates/integrated-coredns.yaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,6 @@
{{- if .Values.pro }}
{{- if .Values.coredns.integrated }}
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}-dns
namespace: {{ .Release.Namespace }}
annotations:
prometheus.io/port: "9153"
prometheus.io/scrape: "true"
{{- if .Values.coredns.service.annotations }}
{{ toYaml .Values.coredns.service.annotations | indent 8 }}
{{- end }}
{{- if .Values.globalAnnotations }}
{{ toYaml .Values.globalAnnotations | indent 4 }}
{{- end }}
spec:
selector:
app: vcluster
release: {{ .Release.Name }}
type: {{ .Values.coredns.service.type }}
{{- if (eq (.Values.coredns.service.type) "LoadBalancer") }}
{{- if .Values.coredns.service.externalTrafficPolicy }}
externalTrafficPolicy: {{ .Values.coredns.service.externalTrafficPolicy }}
{{- end }}
{{- if .Values.coredns.service.externalIPs }}
externalIPs:
{{- range $f := .Values.coredns.service.externalIPs }}
- {{ $f }}
{{- end }}
{{- end }}
{{- end }}
ports:
- name: dns
port: 53
targetPort: 1053
protocol: UDP
- name: dns-tcp
port: 53
targetPort: 1053
protocol: TCP
- name: metrics
port: 9153
protocol: TCP
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-dns
Expand Down
5 changes: 4 additions & 1 deletion pkg/controllers/resources/endpoints/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/loft-sh/vcluster/pkg/controllers/syncer"
synccontext "github.com/loft-sh/vcluster/pkg/controllers/syncer/context"
"github.com/loft-sh/vcluster/pkg/controllers/syncer/translator"
"github.com/loft-sh/vcluster/pkg/specialservices"
"github.com/loft-sh/vcluster/pkg/util/translate"
corev1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -41,6 +42,8 @@ var _ syncer.Starter = &endpointsSyncer{}
func (s *endpointsSyncer) ReconcileStart(ctx *synccontext.SyncContext, req ctrl.Request) (bool, error) {
if req.Namespace == "default" && req.Name == "kubernetes" {
return true, nil
} else if _, ok := specialservices.Default.SpecialServicesToSync()[req.NamespacedName]; ok {
return true, nil
}

svc := &corev1.Service{}
Expand Down Expand Up @@ -71,7 +74,7 @@ func (s *endpointsSyncer) ReconcileStart(ctx *synccontext.SyncContext, req ctrl.
// Deleting the endpoints is necessary here as some clusters would not correctly maintain
// the endpoints if they were managed by us previously and now should be managed by Kubernetes.
// In the worst case we would end up in a state where we have multiple endpoint slices pointing
// to the same endpoints resulting in wrong DNS and cluster networking. Hence deleting the previously
// to the same endpoints resulting in wrong DNS and cluster networking. Hence, deleting the previously
// managed endpoints signals the Kubernetes controller to recreate the endpoints from the selector.
klog.Infof("Refresh endpoints in physical cluster because they shouldn't be managed by vcluster anymore")
err = ctx.PhysicalClient.Delete(ctx.Context, endpoints)
Expand Down
20 changes: 6 additions & 14 deletions pkg/controllers/resources/pods/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,12 @@ func (s *podSyncer) findKubernetesIP(ctx *synccontext.SyncContext) (string, erro
}

func (s *podSyncer) findKubernetesDNSIP(ctx *synccontext.SyncContext) (string, error) {
serviceName := specialservices.DefaultKubeDNSServiceName
serviceNamespace := specialservices.DefaultKubeDNSServiceNamespace

var ip string
if dnsSvcSuffix := specialservices.Default.GetDNSServiceSuffix(); dnsSvcSuffix != nil {
// a dns service different from default is set, use it
serviceName = fmt.Sprintf("%s-%s", s.serviceName, *dnsSvcSuffix)
serviceNamespace = ctx.CurrentNamespace
} else {
serviceName = translate.Default.PhysicalName(serviceName, serviceNamespace)
serviceNamespace = translate.Default.PhysicalNamespace(serviceNamespace)
}

ip = s.translateAndFindService(ctx, serviceNamespace, serviceName)
// first try to find the actual synced service, then fallback to a different if we have a suffix (only in the case of integrated coredns)
ip := s.translateAndFindService(
ctx,
translate.Default.PhysicalNamespace(specialservices.DefaultKubeDNSServiceNamespace),
translate.Default.PhysicalName(specialservices.DefaultKubeDNSServiceName, specialservices.DefaultKubeDNSServiceNamespace),
)
if ip == "" {
return "", fmt.Errorf("waiting for DNS service IP")
}
Expand Down
8 changes: 1 addition & 7 deletions pkg/specialservices/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,11 @@ type SpecialServiceSyncer func(ctx context.Context,
servicePortTranslator ServicePortTranslator) error

type Interface interface {
GetDNSServiceSuffix() *string
SpecialServicesToSync() map[types.NamespacedName]SpecialServiceSyncer
}

type NameserverFinder struct {
DNSServiceSuffix *string
SpecialServices map[types.NamespacedName]SpecialServiceSyncer
}

func (f *NameserverFinder) GetDNSServiceSuffix() *string {
return f.DNSServiceSuffix
SpecialServices map[types.NamespacedName]SpecialServiceSyncer
}

func (f *NameserverFinder) SpecialServicesToSync() map[types.NamespacedName]SpecialServiceSyncer {
Expand Down

0 comments on commit e0b076c

Please sign in to comment.