Skip to content

Commit d830514

Browse files
committed
Add a default cluster dns name config
It is very handy to be able to store the default cluster dns name so that I can fire up and teardown clusters easily without losing that setting. You can think of this as a default value for the `start --dns-domain <val>` flag, but only when starting a new cluster. In my particular case, I would like to set my default cluster dna domain to a subdomain under a domain that I control. E.g. `cluster.wt.user.dev.example.com`. I want to do this to make it easier to manage TLS certs for my dev cluster. For context, the `start --dns-domain <val>` flag works like this: If you fire up a new cluster with that flag, you will get a new cluster with the domain name base. If you start an existing cluster, the config will be updated to the new domain name base and then started. This config will work a little differently. The change implements a config that will only affect newly started cluster. Here are some examples to show that difference: Newly started cluster example: ``` $ minikube config set DefaultClusterDNSDomain cluster2.local $ minikube start ... ``` Stop and starting the cluster with `--dns-domain` flag: ``` $ minikube stop ... $ minikub start --dns-domain cluster3.local ... ``` Stopping and starting a new cluster with a non-default domain name and without the `--dns-domain` flag: ``` $ minikube stop ... $ minikub start ... ``` The reason for this behavior is that I am not configuring the name of a cluster. That is a cluster configuration option. I am setting the default for that. If I manually overrode the name of a cluster when started previously, I don't want a default option to override my cluster configuration.
1 parent 7d8d974 commit d830514

File tree

8 files changed

+566
-5
lines changed

8 files changed

+566
-5
lines changed

cmd/minikube/cmd/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ var settings = []Setting{
172172
name: config.MaxAuditEntries,
173173
set: SetInt,
174174
},
175+
{
176+
name: config.DefaultClusterDNSDomain,
177+
set: SetString,
178+
},
175179
}
176180

177181
// ConfigCmd represents the config command

cmd/minikube/cmd/start.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ func runStart(cmd *cobra.Command, _ []string) {
161161
}
162162
defer pkgtrace.Cleanup()
163163

164+
viper.SetDefault(config.DefaultClusterDNSDomain, constants.DefaultClusterDNSDomain)
165+
164166
displayVersion(version.GetVersion())
165167
go download.CleanUpOlderPreloads()
166168

cmd/minikube/cmd/start_flags.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func initKubernetesFlags() {
221221
Valid components are: kubelet, kubeadm, apiserver, controller-manager, etcd, proxy, scheduler
222222
Valid kubeadm parameters: `+fmt.Sprintf("%s, %s", strings.Join(bsutil.KubeadmExtraArgsAllowed[bsutil.KubeadmCmdParam], ", "), strings.Join(bsutil.KubeadmExtraArgsAllowed[bsutil.KubeadmConfigParam], ",")))
223223
startCmd.Flags().String(featureGates, "", "A set of key=value pairs that describe feature gates for alpha/experimental features.")
224-
startCmd.Flags().String(dnsDomain, constants.ClusterDNSDomain, "The cluster dns domain name used in the Kubernetes cluster")
224+
startCmd.Flags().String(dnsDomain, constants.DefaultClusterDNSDomain, "The cluster dns domain name used in the Kubernetes cluster")
225225
startCmd.Flags().Int(apiServerPort, constants.APIServerPort, "The apiserver listening port")
226226
startCmd.Flags().String(apiServerName, constants.APIServerName, "The authoritative apiserver hostname for apiserver certificates and connectivity. This can be used if you want to make the apiserver available from outside the machine")
227227
startCmd.Flags().StringSliceVar(&apiServerNames, "apiserver-names", nil, "A set of apiserver names which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine")
@@ -560,6 +560,11 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime str
560560
out.WarningT("--network flag is only valid with the docker/podman, qemu, kvm, and vfkit drivers, it will be ignored")
561561
}
562562

563+
defaultClusterDNSDomain := viper.GetString(dnsDomain)
564+
if defaultClusterDNSDomain == constants.DefaultClusterDNSDomain {
565+
defaultClusterDNSDomain = viper.GetString(config.DefaultClusterDNSDomain)
566+
}
567+
563568
validateHANodeCount(cmd)
564569

565570
checkNumaCount(k8sVersion)
@@ -636,7 +641,7 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime str
636641
APIServerName: viper.GetString(apiServerName),
637642
APIServerNames: apiServerNames,
638643
APIServerIPs: apiServerIPs,
639-
DNSDomain: viper.GetString(dnsDomain),
644+
DNSDomain: defaultClusterDNSDomain,
640645
FeatureGates: viper.GetString(featureGates),
641646
ContainerRuntime: rtime,
642647
CRISocket: viper.GetString(criSocket),

go.work.sum

Lines changed: 547 additions & 1 deletion
Large diffs are not rendered by default.

pkg/minikube/bootstrapper/certs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestSetupCerts(t *testing.T) {
3636
CertExpiration: constants.DefaultCertExpiration,
3737
KubernetesConfig: config.KubernetesConfig{
3838
APIServerName: constants.APIServerName,
39-
DNSDomain: constants.ClusterDNSDomain,
39+
DNSDomain: constants.DefaultClusterDNSDomain,
4040
ServiceCIDR: constants.DefaultServiceCIDR,
4141
},
4242
}

pkg/minikube/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ const (
5858
EmbedCerts = "EmbedCerts"
5959
// MaxAuditEntries is the maximum number of audit entries to retain
6060
MaxAuditEntries = "MaxAuditEntries"
61+
// DefaultDnsDomain is the key for the default dns domain name when creating
62+
// a cluster
63+
DefaultClusterDNSDomain = "DefaultClusterDNSDomain"
6164
)
6265

6366
var (

pkg/minikube/constants/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const (
7575
// APIServerName is the default API server name
7676
APIServerName = "minikubeCA"
7777
// ClusterDNSDomain is the default DNS domain
78-
ClusterDNSDomain = "cluster.local"
78+
DefaultClusterDNSDomain = "cluster.local"
7979
// DefaultServiceCIDR is The CIDR to be used for service cluster IPs
8080
DefaultServiceCIDR = "10.96.0.0/12"
8181
// HostAlias is a DNS alias to the container/VM host IP

site/content/en/docs/commands/config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Configurable fields:
4141
* native-ssh
4242
* rootless
4343
* MaxAuditEntries
44+
* DefaultClusterDNSDomain
4445

4546
```shell
4647
minikube config SUBCOMMAND [flags]

0 commit comments

Comments
 (0)