Skip to content

Commit

Permalink
Use vmpath constants where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
tstromberg committed Feb 7, 2020
1 parent 2504989 commit 97f926e
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pkg/drivers/none/none.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
var cleanupPaths = []string{
vmpath.GuestEphemeralDir,
vmpath.GuestManifestsDir,
"/var/lib/minikube",
vmpath.GuestPersistentDir,
}

// Driver is a driver designed to run kubeadm w/o VM management, and assumes systemctl.
Expand Down
3 changes: 2 additions & 1 deletion pkg/gvisor/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/vmpath"
)

const (
Expand Down Expand Up @@ -176,7 +177,7 @@ func copyAssetToDest(targetName, dest string) error {
}

// Now, copy the data from this asset to dest
src := filepath.Join(constants.GvisorFilesPath, asset.GetTargetName())
src := filepath.Join(vmpath.GuestGvisorDir, asset.GetTargetName())
log.Printf("%s asset path: %s", targetName, src)
contents, err := ioutil.ReadFile(src)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/assets/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ var Addons = map[string]*Addon{
false),
MustBinAsset(
"deploy/addons/gvisor/gvisor-config.toml",
constants.GvisorFilesPath,
vmpath.GuestGvisorDir,
constants.GvisorConfigTomlTargetName,
"0640",
true),
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/bootstrapper/bsutil/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func GenerateKubeadmYAML(mc config.MachineConfig, r cruntime.Manager) ([]byte, e
FeatureArgs map[string]bool
NoTaintMaster bool
}{
CertDir: vmpath.GuestCertsDir,
CertDir: vmpath.GuestKubernetesCertsDir,
ServiceCIDR: constants.DefaultServiceCIDR,
PodSubnet: k8s.ExtraOptions.Get("pod-network-cidr", Kubeadm),
AdvertiseAddress: cp.IP,
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/bootstrapper/bsutil/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var versionSpecificOpts = []config.VersionedExtraOption{

// Auth args
config.NewUnversionedOption(Kubelet, "authorization-mode", "Webhook"),
config.NewUnversionedOption(Kubelet, "client-ca-file", path.Join(vmpath.GuestCertsDir, "ca.crt")),
config.NewUnversionedOption(Kubelet, "client-ca-file", path.Join(vmpath.GuestKubernetesCertsDir, "ca.crt")),

// Cgroup args
config.NewUnversionedOption(Kubelet, "cgroup-driver", "cgroupfs"),
Expand Down
23 changes: 8 additions & 15 deletions pkg/minikube/bootstrapper/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ import (
"github.com/juju/mutex"
)

const (
// CACertificatesDir contains CA certificates
CACertificatesDir = "/usr/share/ca-certificates"
// SSLCertStoreDir contains SSL certificates
SSLCertStoreDir = "/etc/ssl/certs"
)

var (
certs = []string{
"ca.crt", "ca.key", "apiserver.crt", "apiserver.key", "proxy-client-ca.crt",
Expand Down Expand Up @@ -89,7 +82,7 @@ func SetupCerts(cmd command.Runner, k8s config.KubernetesConfig, n config.Node)
if strings.HasSuffix(cert, ".key") {
perms = "0600"
}
certFile, err := assets.NewFileAsset(p, vmpath.GuestCertsDir, cert, perms)
certFile, err := assets.NewFileAsset(p, vmpath.GuestKubernetesCertsDir, cert, perms)
if err != nil {
return err
}
Expand All @@ -112,9 +105,9 @@ func SetupCerts(cmd command.Runner, k8s config.KubernetesConfig, n config.Node)
kcs := &kubeconfig.Settings{
ClusterName: n.Name,
ClusterServerAddress: fmt.Sprintf("https://%s", net.JoinHostPort("localhost", fmt.Sprint(n.Port))),
ClientCertificate: path.Join(vmpath.GuestCertsDir, "apiserver.crt"),
ClientKey: path.Join(vmpath.GuestCertsDir, "apiserver.key"),
CertificateAuthority: path.Join(vmpath.GuestCertsDir, "ca.crt"),
ClientCertificate: path.Join(vmpath.GuestKubernetesCertsDir, "apiserver.crt"),
ClientKey: path.Join(vmpath.GuestKubernetesCertsDir, "apiserver.key"),
CertificateAuthority: path.Join(vmpath.GuestKubernetesCertsDir, "ca.crt"),
KeepContext: false,
}

Expand Down Expand Up @@ -289,7 +282,7 @@ func collectCACerts() (map[string]string, error) {
if validPem {
filename := filepath.Base(hostpath)
dst := fmt.Sprintf("%s.%s", strings.TrimSuffix(filename, ext), "pem")
certFiles[hostpath] = path.Join(CACertificatesDir, dst)
certFiles[hostpath] = path.Join(vmpath.GuestCertAuthDir, dst)
}
}
}
Expand All @@ -304,7 +297,7 @@ func collectCACerts() (map[string]string, error) {
}

// populates minikube CA
certFiles[filepath.Join(localPath, "ca.crt")] = path.Join(CACertificatesDir, "minikubeCA.pem")
certFiles[filepath.Join(localPath, "ca.crt")] = path.Join(vmpath.GuestCertAuthDir, "minikubeCA.pem")

filtered := map[string]string{}
for k, v := range certFiles {
Expand Down Expand Up @@ -340,7 +333,7 @@ func configureCACerts(cr command.Runner, caCerts map[string]string) error {

for _, caCertFile := range caCerts {
dstFilename := path.Base(caCertFile)
certStorePath := path.Join(SSLCertStoreDir, dstFilename)
certStorePath := path.Join(vmpath.GuestCertStoreDir, dstFilename)
cmd := fmt.Sprintf("test -f %s || ln -fs %s %s", caCertFile, certStorePath, caCertFile)
if _, err := cr.RunCmd(exec.Command("sudo", "/bin/bash", "-c", cmd)); err != nil {
return errors.Wrapf(err, "create symlink for %s", caCertFile)
Expand All @@ -350,7 +343,7 @@ func configureCACerts(cr command.Runner, caCerts map[string]string) error {
if err != nil {
return errors.Wrapf(err, "calculate hash for cacert %s", caCertFile)
}
subjectHashLink := path.Join(SSLCertStoreDir, fmt.Sprintf("%s.0", subjectHash))
subjectHashLink := path.Join(vmpath.GuestCertStoreDir, fmt.Sprintf("%s.0", subjectHash))

// NOTE: This symlink may exist, but point to a missing file
cmd := fmt.Sprintf("test -L %s || ln -fs %s %s", subjectHashLink, certStorePath, subjectHashLink)
Expand Down
7 changes: 4 additions & 3 deletions pkg/minikube/cluster/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ var (
vmpath.GuestManifestsDir,
vmpath.GuestEphemeralDir,
vmpath.GuestPersistentDir,
vmpath.GuestCertsDir,
vmpath.GuestKubernetesCertsDir,
path.Join(vmpath.GuestPersistentDir, "images"),
path.Join(vmpath.GuestPersistentDir, "binaries"),
"/tmp/gvisor",
"/usr/share/ca-certificates",
vmpath.GuestGvisorDir,
vmpath.GuestCertAuthDir,
vmpath.GuestCertStoreDir,
}
)

Expand Down
3 changes: 0 additions & 3 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ var KubernetesReleaseBinaries = []string{"kubelet", "kubeadm", "kubectl"}
var ImageCacheDir = localpath.MakeMiniPath("cache", "images")

const (
// GvisorFilesPath is the path to the gvisor files saved by go-bindata
GvisorFilesPath = "/tmp/gvisor"

// GvisorConfigTomlTargetName is the go-bindata target name for the gvisor config.toml
GvisorConfigTomlTargetName = "gvisor-config.toml"
)
10 changes: 8 additions & 2 deletions pkg/minikube/vmpath/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ const (
GuestEphemeralDir = "/var/tmp/minikube"
// GuestPersistentDir is the path where persistent data should be stored within the VM (not tmpfs)
GuestPersistentDir = "/var/lib/minikube"
// GuestCertsDir are where Kubernetes certificates are kept on the guest
GuestCertsDir = GuestPersistentDir + "/certs"
// GuestKubernetesCertsDir are where Kubernetes certificates are stored
GuestKubernetesCertsDir = GuestPersistentDir + "/certs"
// GuestCertAuthDir is where system CA certificates are installed to
GuestCertAuthDir = "/usr/share/ca-certificates"
// GuestCertStoreDir is where system SSL certificates are installed
GuestCertStoreDir = "/etc/ssl/certs"
// Where gvisor bootstraps from
GuestGvisorDir = "/tmp/gvisor"
)

0 comments on commit 97f926e

Please sign in to comment.