Skip to content

Commit

Permalink
Remove references to old volume source, handle endpoints change
Browse files Browse the repository at this point in the history
  • Loading branch information
smarterclayton committed Mar 2, 2015
1 parent 2e9532d commit 4610229
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 92 deletions.
4 changes: 2 additions & 2 deletions pkg/build/controller/strategy/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func setupDockerSocket(podSpec *kapi.Pod) {
dockerSocketVolume := kapi.Volume{
Name: "docker-socket",
Source: kapi.VolumeSource{
HostPath: &kapi.HostPath{
HostPath: &kapi.HostPathVolumeSource{
Path: dockerSocketPath,
},
},
Expand All @@ -45,7 +45,7 @@ func setupDockerConfig(podSpec *kapi.Pod) {
dockerConfigVolume := kapi.Volume{
Name: "docker-cfg",
Source: kapi.VolumeSource{
HostPath: &kapi.HostPath{
HostPath: &kapi.HostPathVolumeSource{
Path: dockerConfig,
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func NewCommandCLI(name, fullName string) *cobra.Command {
func NewCmdKubectl(name string) *cobra.Command {
flags := pflag.NewFlagSet("", pflag.ContinueOnError)
f := clientcmd.New(flags)
cmd := f.Factory.NewKubectlCommand(os.Stdout)
cmd := f.Factory.NewKubectlCommand(os.Stdin, os.Stdout, os.Stderr)
cmd.Aliases = []string{"kubectl"}
cmd.Use = name
cmd.Short = "Kubernetes cluster management via kubectl"
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/experimental/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ func NewCmdRegistry(f *clientcmd.Factory, parentName, name string, out io.Writer
},
}
if mountHost {
podTemplate.Spec.Volumes[0].Source.HostPath = &kapi.HostPath{Path: cfg.HostMount}
podTemplate.Spec.Volumes[0].Source.HostPath = &kapi.HostPathVolumeSource{Path: cfg.HostMount}
} else {
podTemplate.Spec.Volumes[0].Source.EmptyDir = &kapi.EmptyDir{}
podTemplate.Spec.Volumes[0].Source.EmptyDir = &kapi.EmptyDirVolumeSource{}
}

objects := []runtime.Object{
Expand Down
16 changes: 11 additions & 5 deletions pkg/cmd/server/kubernetes/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
kconfig "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/config"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/proxy"
pconfig "github.com/GoogleCloudPlatform/kubernetes/pkg/proxy/config"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
kexec "github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/iptables"
"github.com/fsouza/go-dockerclient"
dockerclient "github.com/fsouza/go-dockerclient"
"github.com/golang/glog"
cadvisor "github.com/google/cadvisor/client"

Expand Down Expand Up @@ -85,19 +86,23 @@ type NodeConfig struct {
// A client to connect to the master.
Client *client.Client
// A client to connect to Docker
DockerClient *docker.Client
DockerClient dockertools.DockerInterface
}

// EnsureDocker attempts to connect to the Docker daemon defined by the helper,
// and if it is unable to it will print a warning.
func (c *NodeConfig) EnsureDocker(docker *dockerutil.Helper) {
dockerClient, dockerAddr := docker.GetClientOrExit()
if err := dockerClient.Ping(); err != nil {
if !c.AllowDisabledDocker {
glog.Fatalf("ERROR: Docker could not be reached at %s. Docker must be installed and running to start containers.\n%v", dockerAddr, err)
}
glog.Errorf("WARNING: Docker could not be reached at %s. Docker must be installed and running to start containers.\n%v", dockerAddr, err)
c.DockerClient = &dockertools.FakeDockerClient{VersionInfo: dockerclient.Env{"apiversion=1.15"}}
} else {
glog.Infof("Connecting to Docker at %s", dockerAddr)
c.DockerClient = dockerClient
}
c.DockerClient = dockerClient
}

// EnsureVolumeDir attempts to convert the provided volume directory argument to
Expand Down Expand Up @@ -156,13 +161,14 @@ func (c *NodeConfig) RunKubelet() {
"",
nil,
kapi.NamespaceDefault,
app.ProbeVolumePlugins())
app.ProbeVolumePlugins(),
5*time.Minute)
if err != nil {
glog.Fatalf("Couldn't run kubelet: %s", err)
}
go util.Forever(func() { k.Run(cfg.Updates()) }, 0)

handler := kubelet.NewServer(k, true, c.AllowDisabledDocker)
handler := kubelet.NewServer(k, true)

server := &http.Server{
Addr: net.JoinHostPort(c.BindHost, strconv.Itoa(NodePort)),
Expand Down
35 changes: 5 additions & 30 deletions plugins/router/template/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package templaterouter

import (
"fmt"
"strings"
"strconv"
"text/template"

kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
Expand Down Expand Up @@ -123,41 +123,16 @@ func endpointsKey(endpoints kapi.Endpoints) string {
return endpoints.Name
}

// endpointFromString parses the string into host/port and create an endpoint from it.
// if the string is empty then nil, false will be returned
func endpointFromString(s string) (ep *Endpoint, ok bool) {
if len(s) == 0 {
return nil, false
}

ep = &Endpoint{}
//not using net.url here because it doesn't split the port out when parsing
if strings.Contains(s, ":") {
eArr := strings.Split(s, ":")
ep.IP = eArr[0]
ep.Port = eArr[1]
} else {
ep.IP = s
ep.Port = "80"
}

ep.ID = fmt.Sprintf("%s:%s", ep.IP, ep.Port)

return ep, true
}

// createRouterEndpoints creates openshift router endpoints based on k8s endpoints
func createRouterEndpoints(endpoints *kapi.Endpoints) []Endpoint {
routerEndpoints := make([]Endpoint, len(endpoints.Endpoints))

for i, e := range endpoints.Endpoints {
ep, ok := endpointFromString(e)

if !ok {
glog.Warningf("Unable to convert %s to endpoint", e)
continue
routerEndpoints[i] = Endpoint{
ID: fmt.Sprintf("%s:%d", e.IP, e.Port),
IP: e.IP,
Port: strconv.Itoa(e.Port),
}
routerEndpoints[i] = *ep
}

return routerEndpoints
Expand Down
58 changes: 6 additions & 52 deletions plugins/router/template/plugin_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package templaterouter

import (
"reflect"
"testing"

kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
Expand Down Expand Up @@ -118,15 +117,15 @@ func TestHandleEndpoints(t *testing.T) {
ObjectMeta: kapi.ObjectMeta{
Name: "test", //kapi.endpoints inherits the name of the service
},
Endpoints: []string{"1.1.1.1"}, //not specifying a port to force the port 80 assumption
Endpoints: []kapi.Endpoint{{IP: "1.1.1.1", Port: 345}}, //not specifying a port to force the port 80 assumption
},
expectedServiceUnit: &ServiceUnit{
Name: "test", //service name from kapi.endpoints object
EndpointTable: map[string]Endpoint{
"1.1.1.1:80": { //port 80 will be added by default if not specified
ID: "1.1.1.1:80",
"1.1.1.1:345": {
ID: "1.1.1.1:345",
IP: "1.1.1.1",
Port: "80", //defaulted by code
Port: "345",
},
},
},
Expand All @@ -138,7 +137,7 @@ func TestHandleEndpoints(t *testing.T) {
ObjectMeta: kapi.ObjectMeta{
Name: "test",
},
Endpoints: []string{"2.2.2.2:8080"},
Endpoints: []kapi.Endpoint{{IP: "2.2.2.2", Port: 8080}},
},
expectedServiceUnit: &ServiceUnit{
Name: "test",
Expand All @@ -158,7 +157,7 @@ func TestHandleEndpoints(t *testing.T) {
ObjectMeta: kapi.ObjectMeta{
Name: "test",
},
Endpoints: []string{"3.3.3.3"},
Endpoints: []kapi.Endpoint{{IP: "3.3.3.3", Port: 0}},
},
expectedServiceUnit: &ServiceUnit{
Name: "test",
Expand Down Expand Up @@ -274,48 +273,3 @@ func TestHandleRoute(t *testing.T) {
}

}

// TestEndpointFromString test creation of endpoint from a string
func TestEndpointFromString(t *testing.T) {
endpointFromStringTestCases := map[string]struct {
InputEndpoint string
ExpectedEndpoint *Endpoint
ExpectedOk bool
}{
"Empty String": {
InputEndpoint: "",
ExpectedEndpoint: nil,
ExpectedOk: false,
},
"Default Port": {
InputEndpoint: "test",
ExpectedEndpoint: &Endpoint{
ID: "test:80",
IP: "test",
Port: "80",
},
ExpectedOk: true,
},
"Non-default Port": {
InputEndpoint: "test:9999",
ExpectedEndpoint: &Endpoint{
ID: "test:9999",
IP: "test",
Port: "9999",
},
ExpectedOk: true,
},
}

for k, tc := range endpointFromStringTestCases {
endpoint, ok := endpointFromString(tc.InputEndpoint)

if ok != tc.ExpectedOk {
t.Fatalf("%s failed, expected ok=%t but got %t", k, tc.ExpectedOk, ok)
}

if !reflect.DeepEqual(endpoint, tc.ExpectedEndpoint) {
t.Fatalf("%s failed, the returned endpoint didn't match the expected endpoint %v : %v", k, endpoint, tc.ExpectedEndpoint)
}
}
}

0 comments on commit 4610229

Please sign in to comment.