Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 4 additions & 6 deletions pkg/client/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1114,13 +1114,11 @@ func ClusterStart(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clust

// get the first server in the list and run action on it once it's ready for it
for _, n := range servers {
// do not try to run the action, if CoreDNS is disabled on K3s level
for _, flag := range n.Args {
if strings.HasPrefix(flag, "--disable") && strings.Contains(flag, "coredns") {
l.Log().Debugf("CoreDNS disabled in K3s via flag `%s`. Not trying to use it.", flag)
return nil
}
if coreDNSDisabledLabel, exists := n.RuntimeLabels[k3d.LabelClusterCoreDNSDisabled]; exists && coreDNSDisabledLabel == "true" {
l.Log().Debugf("CoreDNS disabled via cluster label. Not trying to use it.")
return nil
}

ts, err := time.Parse("2006-01-02T15:04:05.999999999Z", n.State.Started)
if err != nil {
return err
Expand Down
11 changes: 11 additions & 0 deletions pkg/config/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"io"
"net/netip"
"os"
"regexp"
"strings"

wharfie "github.com/rancher/wharfie/pkg/registries"
Expand Down Expand Up @@ -269,6 +270,7 @@ func TransformSimpleToClusterConfig(ctx context.Context, runtime runtimes.Runtim
}

// -> ARGS
coreDNSDisabled := false
for _, argWithNodeFilters := range simpleConfig.Options.K3sOptions.ExtraArgs {
if len(argWithNodeFilters.NodeFilters) == 0 && nodeCount > 1 {
return nil, fmt.Errorf("K3sExtraArg '%s' lacks a node filter, but there's more than one node", argWithNodeFilters.Arg)
Expand All @@ -282,6 +284,11 @@ func TransformSimpleToClusterConfig(ctx context.Context, runtime runtimes.Runtim
for _, node := range nodes {
node.Args = append(node.Args, argWithNodeFilters.Arg)
}

if regexp.MustCompile(`^--disable\s*(=|\s)\s*coredns$`).MatchString(argWithNodeFilters.Arg) {
coreDNSDisabled = true
}

}

/**************************
Expand All @@ -306,6 +313,10 @@ func TransformSimpleToClusterConfig(ctx context.Context, runtime runtimes.Runtim
clusterCreateOpts.GlobalLabels[k] = v
}

if coreDNSDisabled {
clusterCreateOpts.GlobalLabels[k3d.LabelClusterCoreDNSDisabled] = "true"
}

/*
* Registries
*/
Expand Down
1 change: 1 addition & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const (
LabelNetworkID string = "k3d.cluster.network.id"
LabelNetworkIPRange string = "k3d.cluster.network.iprange"
LabelClusterStartHostAliases string = "k3d.cluster.start.hostaliases"
LabelClusterCoreDNSDisabled string = "k3d.cluster.coredns.disabled"
LabelRole string = "k3d.role"
LabelServerAPIPort string = "k3d.server.api.port"
LabelServerAPIHost string = "k3d.server.api.host"
Expand Down
Loading