Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix coredns #2369

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion pkg/setup/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,23 @@ func StartControllers(controllerContext *synccontext.ControllerContext, syncers

func ApplyCoreDNS(controllerContext *synccontext.ControllerContext) {
_ = wait.ExponentialBackoffWithContext(controllerContext.Context, wait.Backoff{Duration: time.Second, Factor: 1.5, Cap: time.Minute, Steps: math.MaxInt32}, func(ctx context.Context) (bool, error) {
err := coredns.ApplyManifest(ctx, controllerContext.Config.ControlPlane.Advanced.DefaultImageRegistry, controllerContext.VirtualManager.GetConfig(), controllerContext.VirtualClusterVersion)
dnsDeployment := &appsv1.Deployment{}
err := controllerContext.VirtualManager.GetClient().Get(controllerContext.Context, types.NamespacedName{Namespace: "kube-system", Name: "coredns"}, dnsDeployment)
if err != nil && !kerrors.IsNotFound(err) {
return false, err
}
if err == nil {
// dns pod labels were changed to avoid conflict with apps running in the host cluster that select for the "kube-dns" label, e.g. cilium.
// If the deployment already exists with a label selector that is not "vcluster-kube-dns" then it needs to be deleted because the selector field is immutable.
// Otherwise, dns will break because the dns service will target the updated label but not match any deployments.
if dnsDeployment.Spec.Selector.MatchLabels["k8s-app"] != "vcluster-kube-dns" {
err = controllerContext.VirtualManager.GetClient().Delete(controllerContext.Context, dnsDeployment)
if err != nil && !kerrors.IsNotFound(err) {
return false, err
}
}
}
err = coredns.ApplyManifest(ctx, controllerContext.Config.ControlPlane.Advanced.DefaultImageRegistry, controllerContext.VirtualManager.GetConfig(), controllerContext.VirtualClusterVersion)
if err != nil {
if errors.Is(err, coredns.ErrNoCoreDNSManifests) {
klog.Infof("No CoreDNS manifests found, skipping CoreDNS configuration")
Expand Down
Loading