Skip to content

Commit 1e79d8f

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. It's important to note that this default will only be applied at cluster creation time. If you have an existing cluster config, the name default name will not be changed if you added the config after starting the cluster the first time.
1 parent 15f0eed commit 1e79d8f

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ 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+
225+
startCmd.Flags().String(dnsDomain, constants.DefaultClusterDNSDomain, "The cluster dns domain name used in the Kubernetes cluster")
226+
225227
startCmd.Flags().Int(apiServerPort, constants.APIServerPort, "The apiserver listening port")
226228
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")
227229
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 +562,11 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime str
560562
out.WarningT("--network flag is only valid with the docker/podman, qemu, kvm, and vfkit drivers, it will be ignored")
561563
}
562564

565+
defaultClusterDNSDomain := viper.GetString(dnsDomain)
566+
if defaultClusterDNSDomain == constants.DefaultClusterDNSDomain {
567+
defaultClusterDNSDomain = viper.GetString(config.DefaultClusterDNSDomain)
568+
}
569+
563570
validateHANodeCount(cmd)
564571

565572
checkNumaCount(k8sVersion)
@@ -636,7 +643,7 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime str
636643
APIServerName: viper.GetString(apiServerName),
637644
APIServerNames: apiServerNames,
638645
APIServerIPs: apiServerIPs,
639-
DNSDomain: viper.GetString(dnsDomain),
646+
DNSDomain: defaultClusterDNSDomain,
640647
FeatureGates: viper.GetString(featureGates),
641648
ContainerRuntime: rtime,
642649
CRISocket: viper.GetString(criSocket),

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

0 commit comments

Comments
 (0)