Repository: k3s-io/k3s
File: pkg/daemons/control/deps/deps.go (Go)

Code before:
	regen, err := createServerSigningCertKey(config)
	if err != nil {
		return err
	}

	altNames := &certutil.AltNames{
		DNSNames: []string{"kubernetes", "kubernetes.default", "kubernetes.default.svc", "kubernetes.default.svc." + config.ClusterDomain},
	}

	addSANs(altNames, config.SANs)

	if _, err := createClientCertKey(regen, "kube-apiserver", nil,
		altNames, []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
		runtime.ServerCA, runtime.ServerCAKey,
		runtime.ServingKubeAPICert, runtime.ServingKubeAPIKey); err != nil {
		return err
	}

	if _, _, err := certutil.LoadOrGenerateKeyFile(runtime.ServingKubeletKey, regen); err != nil {
		return err
	}

	altNames = &certutil.AltNames{
		DNSNames: []string{"localhost"},
	}
	addSANs(altNames, []string{"127.0.0.1", "::1"})

	if _, err := createClientCertKey(regen, "kube-scheduler", nil,
		altNames, []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
		runtime.ServerCA, runtime.ServerCAKey,
		runtime.ServingKubeSchedulerCert, runtime.ServingKubeSchedulerKey); err != nil {
		return err
	}

	if _, err := createClientCertKey(regen, "kube-controller-manager", nil,
		altNames, []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
		runtime.ServerCA, runtime.ServerCAKey,
		runtime.ServingKubeControllerCert, runtime.ServingKubeControllerKey); err != nil {
		return err
	}

	return nil
}

func genETCDCerts(config *config.Control) error {
	runtime := config.Runtime
	regen, err := createSigningCertKey("etcd-server", runtime.ETCDServerCA, runtime.ETCDServerCAKey)
	if err != nil {
		return err
	}


Review comment (suggestion):
This is super nitty but you could just set all the names in one go:
```suggestion
	altNames = &certutil.AltNames{}
	addSANs(altNames, []string{"localhost" ,"127.0.0.1", "::1"})
```

Code after:
	regen, err := createServerSigningCertKey(config)
	if err != nil {
		return err
	}

	altNames := &certutil.AltNames{
		DNSNames: []string{"kubernetes", "kubernetes.default", "kubernetes.default.svc", "kubernetes.default.svc." + config.ClusterDomain},
	}

	addSANs(altNames, config.SANs)

	if _, err := createClientCertKey(regen, "kube-apiserver", nil,
		altNames, []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
		runtime.ServerCA, runtime.ServerCAKey,
		runtime.ServingKubeAPICert, runtime.ServingKubeAPIKey); err != nil {
		return err
	}

	if _, _, err := certutil.LoadOrGenerateKeyFile(runtime.ServingKubeletKey, regen); err != nil {
		return err
	}

	altNames = &certutil.AltNames{}
	addSANs(altNames, []string{"localhost" ,"127.0.0.1", "::1"})

	if _, err := createClientCertKey(regen, "kube-scheduler", nil,
		altNames, []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
		runtime.ServerCA, runtime.ServerCAKey,
		runtime.ServingKubeSchedulerCert, runtime.ServingKubeSchedulerKey); err != nil {
		return err
	}

	if _, err := createClientCertKey(regen, "kube-controller-manager", nil,
		altNames, []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
		runtime.ServerCA, runtime.ServerCAKey,
		runtime.ServingKubeControllerCert, runtime.ServingKubeControllerKey); err != nil {
		return err
	}

	return nil
}

func genETCDCerts(config *config.Control) error {
	runtime := config.Runtime
	regen, err := createSigningCertKey("etcd-server", runtime.ETCDServerCA, runtime.ETCDServerCAKey)
	if err != nil {
		return err
	}

	altNames := &certutil.AltNames{
		DNSNames: []string{"kine.sock"},