Skip to content

Commit

Permalink
mounting kubectl from the host instead to copying it to protokube
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislovecnm committed Oct 8, 2017
1 parent 319ebab commit 8e721f9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
5 changes: 0 additions & 5 deletions images/protokube-builder/onbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,4 @@ cp /src/.build/local/protokube /src/.build/artifacts/
make channels
cp /src/.build/local/channels /src/.build/artifacts/

# channels uses protokube
cd /src/.build/artifacts/
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.6.6/bin/linux/amd64/kubectl
chmod +x kubectl

chown -R $HOST_UID:$HOST_GID /src/.build/artifacts
2 changes: 0 additions & 2 deletions images/protokube/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ RUN apt-get update && apt-get install --yes \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY /.build/artifacts/kubectl /usr/bin/kubectl

COPY /.build/artifacts/protokube /usr/bin/protokube
COPY /.build/artifacts/channels /usr/bin/channels

Expand Down
12 changes: 12 additions & 0 deletions nodeup/pkg/model/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,15 @@ func (c *NodeupModelContext) UseSecureKubelet() bool {

return false
}

// KubectlPath returns distro based path for kubectl
func (c *NodeupModelContext) KubectlPath() string {
kubeletCommand := "/usr/local/bin"
if c.Distribution == distros.DistributionCoreOS {
kubeletCommand = "/opt/bin"
}
if c.Distribution == distros.DistributionContainerOS {
kubeletCommand = "/home/kubernetes/bin"
}
return kubeletCommand
}
13 changes: 2 additions & 11 deletions nodeup/pkg/model/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (b *KubectlBuilder) Build(c *fi.ModelBuilderContext) error {
}

t := &nodetasks.File{
Path: b.kubectlPath(),
Path: b.KubectlPath() + "/" + assetName,
Contents: asset,
Type: nodetasks.FileType_File,
Mode: s("0755"),
Expand Down Expand Up @@ -101,13 +101,4 @@ func (b *KubectlBuilder) Build(c *fi.ModelBuilderContext) error {
return nil
}

func (b *KubectlBuilder) kubectlPath() string {
kubeletCommand := "/usr/local/bin/kubectl"
if b.Distribution == distros.DistributionCoreOS {
kubeletCommand = "/opt/bin/kubectl"
}
if b.Distribution == distros.DistributionContainerOS {
kubeletCommand = "/home/kubernetes/bin/kubectl"
}
return kubeletCommand
}

19 changes: 17 additions & 2 deletions nodeup/pkg/model/protokube.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,27 @@ func (t *ProtokubeBuilder) buildSystemdService() (*nodetasks.Service, error) {
"-v", "/:/rootfs/",
"-v", "/var/run/dbus:/var/run/dbus",
"-v", "/run/systemd:/run/systemd",
"--net=host", "--privileged",
}

// add kubectl only if a master
// path changes depending on distro, and always mount it on /opt/kops/bin
// kubectl is downloaded an installed by other tasks
if t.IsMaster {
dockerArgs = append(dockerArgs, []string{
"-v", t.KubectlPath() + ":/opt/kops/bin:ro",
"--env", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/kops/bin",
}...)
}

dockerArgs = append(dockerArgs, []string{
"--net=host",
"--privileged",
"--env", "KUBECONFIG=/rootfs/var/lib/kops/kubeconfig",
t.ProtokubeEnvironmentVariables(),
t.ProtokubeImageName(),
"/usr/bin/protokube",
}
}...)

protokubeCommand := strings.Join(dockerArgs, " ") + " " + protokubeFlagsArgs

manifest := &systemd.Manifest{}
Expand Down

0 comments on commit 8e721f9

Please sign in to comment.