Skip to content

Commit 6e15313

Browse files
committed
# This is a combination of 3 commits.
# This is the 1st commit message: update 2 # This is the commit message kubernetes-retired#2: update add dnsoption flag # This is the commit message kubernetes-retired#3: add init
1 parent fa7b9e8 commit 6e15313

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

virtualcluster/cmd/syncer/app/options/options.go

+22
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package options
1919
import (
2020
"fmt"
2121
"io/ioutil"
22+
"k8s.io/utils/pointer"
2223
"os"
2324
"time"
2425

@@ -67,6 +68,7 @@ type ResourceSyncerOptions struct {
6768
Port string
6869
CertFile string
6970
KeyFile string
71+
DnsOptions map[string]string
7072
}
7173

7274
// NewResourceSyncerOptions creates a new resource syncer with a default config.
@@ -101,6 +103,9 @@ func NewResourceSyncerOptions() (*ResourceSyncerOptions, error) {
101103
Port: "80",
102104
CertFile: "",
103105
KeyFile: "",
106+
DnsOptions: map[string]string{
107+
"ndots": "5",
108+
},
104109
}, nil
105110
}
106111

@@ -237,6 +242,7 @@ func (o *ResourceSyncerOptions) Config() (*syncerappconfig.Config, error) {
237242
return nil, err
238243
}
239244
c.ComponentConfig.RestConfig = superRestConfig
245+
c.ComponentConfig.DnsOptions = DnsOptionsConvert(o.DnsOptions)
240246
c.VirtualClusterClient = virtualClusterClient
241247
c.VirtualClusterInformer = vcinformers.NewSharedInformerFactory(virtualClusterClient, 0).Tenancy().V1alpha1().VirtualClusters()
242248
c.MetaClusterClient = metaClusterClient
@@ -363,3 +369,19 @@ func getClientConfig(config componentbaseconfig.ClientConnectionConfiguration, m
363369

364370
return restConfig, nil
365371
}
372+
373+
func DnsOptionsConvert(dnsoptions map[string]string) []corev1.PodDNSConfigOption {
374+
var podDnsOptions []corev1.PodDNSConfigOption
375+
podDnsOptions = make([]corev1.PodDNSConfigOption, len(dnsoptions))
376+
i := 0
377+
for k, v := range dnsoptions {
378+
podDnsOptions[i].Name = k
379+
if v == "" {
380+
podDnsOptions[i].Value = nil
381+
} else {
382+
podDnsOptions[i].Value = pointer.StringPtr(v)
383+
}
384+
i++
385+
}
386+
return podDnsOptions
387+
}

virtualcluster/pkg/syncer/apis/config/types.go

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package config
1919
import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
"k8s.io/client-go/rest"
22+
v1 "k8s.io/api/core/v1"
2223
componentbaseconfig "k8s.io/component-base/config"
2324
)
2425

@@ -73,6 +74,9 @@ type SyncerConfiguration struct {
7374

7475
// The maximum length of time to wait before giving up on a server request. A value of "" means use default.
7576
Timeout string
77+
78+
// The DnsOptions are the DNS options in resolv.conf that is attached to pod
79+
DnsOptions []v1.PodDNSConfigOption
7680
}
7781

7882
// SyncerLeaderElectionConfiguration expands LeaderElectionConfiguration

virtualcluster/pkg/syncer/conversion/mutate.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func mutateWeightedPodAffinityTerms(weightedTerms []v1.WeightedPodAffinityTerm,
112112
}
113113
}
114114

115-
func PodMutateDefault(vPod *v1.Pod, saSecretMap map[string]string, services []*v1.Service, nameServer string) PodMutator {
115+
func PodMutateDefault(vPod *v1.Pod, saSecretMap map[string]string, services []*v1.Service, nameServer string, dnsOption []v1.PodDNSConfigOption) PodMutator {
116116
return func(p *podMutateCtx) error {
117117
p.pPod.Status = v1.PodStatus{}
118118
p.pPod.Spec.NodeName = ""
@@ -173,7 +173,7 @@ func PodMutateDefault(vPod *v1.Pod, saSecretMap map[string]string, services []*v
173173
if err != nil {
174174
return err
175175
}
176-
mutateDNSConfig(p, vPod, vc.Spec.ClusterDomain, nameServer)
176+
mutateDNSConfig(p, vPod, vc.Spec.ClusterDomain, nameServer, dnsOption)
177177

178178
// FIXME(zhuangqh): how to support pod subdomain.
179179
if p.pPod.Spec.Subdomain != "" {
@@ -287,7 +287,7 @@ func getServiceEnvVarMap(ns, cluster string, enableServiceLinks *bool, services
287287
return apiServerService, m
288288
}
289289

290-
func mutateDNSConfig(p *podMutateCtx, vPod *v1.Pod, clusterDomain, nameServer string) {
290+
func mutateDNSConfig(p *podMutateCtx, vPod *v1.Pod, clusterDomain, nameServer string, dnsOption []v1.PodDNSConfigOption) {
291291
// If the TenantAllowDNSPolicy feature gate is added AND if the vPod labels include
292292
// tenancy.x-k8s.io/disable.dnsPolicyMutation: "true" then we should return without
293293
// mutating the config. This is to allow special pods like coredns to use the
@@ -304,11 +304,11 @@ func mutateDNSConfig(p *podMutateCtx, vPod *v1.Pod, clusterDomain, nameServer st
304304
case v1.DNSNone:
305305
return
306306
case v1.DNSClusterFirstWithHostNet:
307-
mutateClusterFirstDNS(p, vPod, clusterDomain, nameServer)
307+
mutateClusterFirstDNS(p, vPod, clusterDomain, nameServer, dnsOption)
308308
return
309309
case v1.DNSClusterFirst:
310310
if !p.pPod.Spec.HostNetwork {
311-
mutateClusterFirstDNS(p, vPod, clusterDomain, nameServer)
311+
mutateClusterFirstDNS(p, vPod, clusterDomain, nameServer, dnsOption)
312312
return
313313
}
314314
// Fallback to DNSDefault for pod on hostnetwork.
@@ -318,7 +318,7 @@ func mutateDNSConfig(p *podMutateCtx, vPod *v1.Pod, clusterDomain, nameServer st
318318
}
319319
}
320320

321-
func mutateClusterFirstDNS(p *podMutateCtx, vPod *v1.Pod, clusterDomain, nameServer string) {
321+
func mutateClusterFirstDNS(p *podMutateCtx, vPod *v1.Pod, clusterDomain, nameServer string, dnsOption []v1.PodDNSConfigOption) {
322322
if nameServer == "" {
323323
klog.Infof("vc %s does not have ClusterDNS IP configured and cannot create Pod using %q policy. Falling back to %q policy.",
324324
p.clusterName, v1.DNSClusterFirst, v1.DNSDefault)
@@ -333,12 +333,13 @@ func mutateClusterFirstDNS(p *podMutateCtx, vPod *v1.Pod, clusterDomain, nameSer
333333
// itself.
334334
dnsConfig := &v1.PodDNSConfig{
335335
Nameservers: []string{nameServer},
336-
Options: []v1.PodDNSConfigOption{
336+
Options: dnsOption,
337+
/* Options: []v1.PodDNSConfigOption{
337338
{
338339
Name: "ndots",
339340
Value: pointer.StringPtr("5"),
340341
},
341-
},
342+
},*/
342343
}
343344

344345
if clusterDomain != "" {
@@ -495,3 +496,4 @@ func (s *saSecretMutator) Mutate(vSecret *v1.Secret, clusterName string) {
495496
s.pSecret.Name = ""
496497
s.pSecret.GenerateName = vSecret.GetAnnotations()[v1.ServiceAccountNameKey] + "-token-"
497498
}
499+

virtualcluster/pkg/syncer/resources/pod/dws.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (c *controller) reconcilePodCreate(clusterName, targetNamespace, requestUID
198198

199199
var ms = []conversion.PodMutator{
200200
conversion.PodMutateServiceLink(c.Config.DisablePodServiceLinks),
201-
conversion.PodMutateDefault(vPod, pSecretMap, services, nameServer),
201+
conversion.PodMutateDefault(vPod, pSecretMap, services, nameServer, c.Config.DnsOptions),
202202
conversion.PodMutateAutoMountServiceAccountToken(c.Config.DisableServiceAccountToken),
203203
// TODO: make extension configurable
204204
//conversion.PodAddExtensionMeta(vPod),

0 commit comments

Comments
 (0)