Skip to content

Commit f140e4a

Browse files
committed
fix: add label to skip coredns injection at cluster creation and start
add new LabelClusterCoreDNSDisabled label to track CoreDNS disabled state, such that CoreDNS injection is skipped at cluster creation and start fixes #1610
1 parent 8ca0ccc commit f140e4a

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

pkg/client/cluster.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,13 +1114,11 @@ func ClusterStart(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clust
11141114

11151115
// get the first server in the list and run action on it once it's ready for it
11161116
for _, n := range servers {
1117-
// do not try to run the action, if CoreDNS is disabled on K3s level
1118-
for _, flag := range n.Args {
1119-
if strings.HasPrefix(flag, "--disable") && strings.Contains(flag, "coredns") {
1120-
l.Log().Debugf("CoreDNS disabled in K3s via flag `%s`. Not trying to use it.", flag)
1121-
return nil
1122-
}
1117+
if coreDNSDisabledLabel, exists := n.RuntimeLabels[k3d.LabelClusterCoreDNSDisabled]; exists && coreDNSDisabledLabel == "true" {
1118+
l.Log().Debugf("CoreDNS disabled via cluster label. Not trying to use it.")
1119+
return nil
11231120
}
1121+
11241122
ts, err := time.Parse("2006-01-02T15:04:05.999999999Z", n.State.Started)
11251123
if err != nil {
11261124
return err

pkg/config/transform.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ func TransformSimpleToClusterConfig(ctx context.Context, runtime runtimes.Runtim
269269
}
270270

271271
// -> ARGS
272+
coreDNSDisabled := false
272273
for _, argWithNodeFilters := range simpleConfig.Options.K3sOptions.ExtraArgs {
273274
if len(argWithNodeFilters.NodeFilters) == 0 && nodeCount > 1 {
274275
return nil, fmt.Errorf("K3sExtraArg '%s' lacks a node filter, but there's more than one node", argWithNodeFilters.Arg)
@@ -282,6 +283,11 @@ func TransformSimpleToClusterConfig(ctx context.Context, runtime runtimes.Runtim
282283
for _, node := range nodes {
283284
node.Args = append(node.Args, argWithNodeFilters.Arg)
284285
}
286+
287+
if strings.HasPrefix(argWithNodeFilters.Arg, "--disable") && strings.Contains(argWithNodeFilters.Arg, "coredns") {
288+
coreDNSDisabled = true
289+
}
290+
285291
}
286292

287293
/**************************
@@ -306,6 +312,10 @@ func TransformSimpleToClusterConfig(ctx context.Context, runtime runtimes.Runtim
306312
clusterCreateOpts.GlobalLabels[k] = v
307313
}
308314

315+
if coreDNSDisabled {
316+
clusterCreateOpts.GlobalLabels[k3d.LabelClusterCoreDNSDisabled] = "true"
317+
}
318+
309319
/*
310320
* Registries
311321
*/

pkg/types/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const (
8686
LabelNetworkID string = "k3d.cluster.network.id"
8787
LabelNetworkIPRange string = "k3d.cluster.network.iprange"
8888
LabelClusterStartHostAliases string = "k3d.cluster.start.hostaliases"
89+
LabelClusterCoreDNSDisabled string = "k3d.cluster.coredns.disabled"
8990
LabelRole string = "k3d.role"
9091
LabelServerAPIPort string = "k3d.server.api.port"
9192
LabelServerAPIHost string = "k3d.server.api.host"

0 commit comments

Comments
 (0)