Skip to content

Commit

Permalink
use crio client to get info
Browse files Browse the repository at this point in the history
  • Loading branch information
bparees committed Sep 23, 2017
1 parent 902e5ec commit 999ac00
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 15 deletions.
16 changes: 8 additions & 8 deletions pkg/build/builder/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,6 @@ func (d *DockerBuilder) dockerBuild(dir string, tag string, secrets []buildapi.S
return err
}

network, resolvConfHostPath, err := getContainerNetworkMode()
if err != nil {
return err
}

opts := docker.BuildImageOptions{
Name: tag,
RmTmpContainer: true,
Expand All @@ -310,10 +305,15 @@ func (d *DockerBuilder) dockerBuild(dir string, tag string, secrets []buildapi.S
NoCache: noCache,
Pull: forcePull,
BuildArgs: buildArgs,
NetworkMode: network,
BuildBinds: fmt.Sprintf("[\"%s:/etc/resolv.conf\"]", resolvConfHostPath),
}

network, resolvConfHostPath, err := getContainerNetworkMode()
if err != nil {
return err
}
opts.NetworkMode = network
if len(resolvConfHostPath) != 0 {
opts.BuildBinds = fmt.Sprintf("[\"%s:/etc/resolv.conf\"]", resolvConfHostPath)
}
// Though we are capped on memory and cpu at the cgroup parent level,
// some build containers care what their memory limit is so they can
// adapt, thus we need to set the memory limit at the container level
Expand Down
36 changes: 30 additions & 6 deletions pkg/build/builder/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package builder

import (
"bufio"
"errors"
"fmt"
"io"
"io/ioutil"
Expand All @@ -11,6 +12,8 @@ import (
"strconv"
"strings"

"github.com/google/cadvisor/container/crio"

docker "github.com/fsouza/go-dockerclient"

s2iapi "github.com/openshift/source-to-image/pkg/api"
Expand Down Expand Up @@ -122,21 +125,42 @@ func getContainerNetworkMode() (string, string, error) {
}
defer file.Close()

resolvConfHostPath, err := readResolvConfHostPath()
if err != nil {
return "", "", err
}
/*
resolvConfHostPath, err := readResolvConfHostPath()
if err != nil {
return "", "", err
}
*/

if id, containerType := readNetClsCGroup(file); id != "" {
glog.V(5).Infof("container type=%s", containerType)
if containerType != "crio-" {
return s2iapi.DockerNetworkModeContainerPrefix + id, resolvConfHostPath, nil
return s2iapi.DockerNetworkModeContainerPrefix + id, "", nil
}

pid, err := readPid()
crioClient, err := crio.Client()
if err != nil {
return "", "", err
}
info, err := crioClient.ContainerInfo(id)
if err != nil {
return "", "", err
}
glog.V(0).Infof("crio spec:\n%#v", info)
pid := string(info.Pid)
resolvConfHostPath := info.Annotations["io.kubernetes.cri-o.ResolvPath"]
if len(resolvConfHostPath) == 0 {
return "", "", errors.New("/etc/resolv.conf hostpath is empty")
}

/*
pid, err := readPid()
if err != nil {
return "", "", err
}
*/

glog.V(0).Infof("pid=%s, resolvpath=%s", pid, resolvConfHostPath)
return fmt.Sprintf("netns:/proc/%s/ns/net", pid), fmt.Sprintf("/var/run" + resolvConfHostPath), nil
}
return "", "", nil
Expand Down
1 change: 1 addition & 0 deletions pkg/build/controller/strategy/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func (bs *DockerBuildStrategy) CreateBuildPod(build *buildapi.Build) (*v1.Pod, e

setOwnerReference(pod, build)
setupDockerSocket(pod)
setupCrioSocket(pod)
setupDockerSecrets(pod, &pod.Spec.Containers[0], build.Spec.Output.PushSecret, strategy.PullSecret, build.Spec.Source.Images)
// For any secrets the user wants to reference from their Assemble script or Dockerfile, mount those
// secrets into the main container. The main container includes logic to copy them from the mounted
Expand Down
1 change: 1 addition & 0 deletions pkg/build/controller/strategy/sti.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func (bs *SourceBuildStrategy) CreateBuildPod(build *buildapi.Build) (*v1.Pod, e

setOwnerReference(pod, build)
setupDockerSocket(pod)
setupCrioSocket(pod)
setupDockerSecrets(pod, &pod.Spec.Containers[0], build.Spec.Output.PushSecret, strategy.PullSecret, build.Spec.Source.Images)
// For any secrets the user wants to reference from their Assemble script or Dockerfile, mount those
// secrets into the main container. The main container includes logic to copy them from the mounted
Expand Down
35 changes: 34 additions & 1 deletion pkg/build/controller/strategy/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import (
"strconv"
"strings"

"github.com/golang/glog"
"github.com/google/cadvisor/container/crio"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kvalidation "k8s.io/apimachinery/pkg/util/validation"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/v1"

"github.com/golang/glog"
"github.com/openshift/origin/pkg/api/apihelpers"
buildapi "github.com/openshift/origin/pkg/build/apis/build"
buildapiv1 "github.com/openshift/origin/pkg/build/apis/build/v1"
Expand Down Expand Up @@ -91,6 +93,37 @@ func setupDockerSocket(pod *v1.Pod) {
}
}

// setupCrioSocket configures the pod to support the host's Crio socket
func setupCrioSocket(pod *v1.Pod) {
crioSocketVolume := v1.Volume{
Name: "crio-socket",
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: crio.CrioSocket,
},
},
}

crioSocketVolumeMount := v1.VolumeMount{
Name: "crio-socket",
MountPath: crio.CrioSocket,
}

pod.Spec.Volumes = append(pod.Spec.Volumes,
crioSocketVolume)
pod.Spec.Containers[0].VolumeMounts =
append(pod.Spec.Containers[0].VolumeMounts,
crioSocketVolumeMount)
/*
for i, initContainer := range pod.Spec.InitContainers {
if initContainer.Name == ExtractImageContentContainer {
pod.Spec.InitContainers[i].VolumeMounts = append(pod.Spec.InitContainers[i].VolumeMounts, crioSocketVolumeMount)
break
}
}
*/
}

// mountSecretVolume is a helper method responsible for actual mounting secret
// volumes into a pod.
func mountSecretVolume(pod *v1.Pod, container *v1.Container, secretName, mountPath, volumeSuffix string) {
Expand Down

0 comments on commit 999ac00

Please sign in to comment.