Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
f718957a
Commit
f718957a
authored
Jan 05, 2015
by
Dawn Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move GetHostName and GetDockerEndpoint methods to pkg/util
parent
83f1aa55
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
62 deletions
+66
-62
kubelet.go
cmd/kubelet/kubelet.go
+1
-1
kubernetes.go
cmd/kubernetes/kubernetes.go
+1
-2
util.go
pkg/kubelet/util.go
+0
-42
standalone.go
pkg/standalone/standalone.go
+1
-17
node.go
pkg/util/node.go
+63
-0
No files found.
cmd/kubelet/kubelet.go
View file @
f718957a
...
...
@@ -124,7 +124,7 @@ func main() {
CAdvisorPort
:
*
cAdvisorPort
,
EnableServer
:
*
enableServer
,
EnableDebuggingHandlers
:
*
enableDebuggingHandlers
,
DockerClient
:
kubelet
.
ConnectToDockerOrDie
(
*
dockerEndpoint
),
DockerClient
:
util
.
ConnectToDockerOrDie
(
*
dockerEndpoint
),
EtcdClient
:
kubelet
.
EtcdClientOrDie
(
etcdServerList
,
*
etcdConfigFile
),
}
...
...
cmd/kubernetes/kubernetes.go
View file @
f718957a
...
...
@@ -27,7 +27,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
"github.com/GoogleCloudPlatform/kubernetes/pkg/standalone"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
...
...
@@ -52,7 +51,7 @@ func startComponents(etcdClient tools.EtcdClient, cl *client.Client, addr string
standalone
.
RunScheduler
(
cl
)
standalone
.
RunControllerManager
(
machineList
,
cl
,
*
nodeMilliCPU
,
*
nodeMemory
)
dockerClient
:=
kubelet
.
ConnectToDockerOrDie
(
*
dockerEndpoint
)
dockerClient
:=
util
.
ConnectToDockerOrDie
(
*
dockerEndpoint
)
standalone
.
SimpleRunKubelet
(
etcdClient
,
dockerClient
,
machineList
[
0
],
"/tmp/kubernetes"
,
""
,
"127.0.0.1"
,
10250
)
}
...
...
pkg/kubelet/util.go
View file @
f718957a
...
...
@@ -20,10 +20,8 @@ import (
"fmt"
"net/http"
"os"
"os/exec"
"path"
"strconv"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
...
...
@@ -32,50 +30,10 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/health"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/coreos/go-etcd/etcd"
"github.com/fsouza/go-dockerclient"
"github.com/golang/glog"
cadvisor
"github.com/google/cadvisor/client"
)
// TODO: move this into a pkg/util
func
GetHostname
(
hostnameOverride
string
)
string
{
hostname
:=
[]
byte
(
hostnameOverride
)
if
string
(
hostname
)
==
""
{
// Note: We use exec here instead of os.Hostname() because we
// want the FQDN, and this is the easiest way to get it.
fqdn
,
err
:=
exec
.
Command
(
"hostname"
,
"-f"
)
.
Output
()
if
err
!=
nil
{
glog
.
Fatalf
(
"Couldn't determine hostname: %v"
,
err
)
}
hostname
=
fqdn
}
return
strings
.
TrimSpace
(
string
(
hostname
))
}
// TODO: move this into a pkg/util
func
GetDockerEndpoint
(
dockerEndpoint
string
)
string
{
var
endpoint
string
if
len
(
dockerEndpoint
)
>
0
{
endpoint
=
dockerEndpoint
}
else
if
len
(
os
.
Getenv
(
"DOCKER_HOST"
))
>
0
{
endpoint
=
os
.
Getenv
(
"DOCKER_HOST"
)
}
else
{
endpoint
=
"unix:///var/run/docker.sock"
}
glog
.
Infof
(
"Connecting to docker on %s"
,
endpoint
)
return
endpoint
}
// TODO: move this into pkg/util
func
ConnectToDockerOrDie
(
dockerEndpoint
string
)
*
docker
.
Client
{
client
,
err
:=
docker
.
NewClient
(
GetDockerEndpoint
(
dockerEndpoint
))
if
err
!=
nil
{
glog
.
Fatal
(
"Couldn't connect to docker."
)
}
return
client
}
// TODO: move this into the kubelet itself
func
MonitorCAdvisor
(
k
*
Kubelet
,
cp
uint
)
{
defer
util
.
HandleCrash
()
...
...
pkg/standalone/standalone.go
View file @
f718957a
...
...
@@ -21,7 +21,6 @@ import (
"math"
"net"
"net/http"
"os"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
...
...
@@ -56,21 +55,6 @@ func (h *delegateHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
w
.
WriteHeader
(
http
.
StatusNotFound
)
}
// Get a docker endpoint, either from the string passed in, or $DOCKER_HOST environment variables
func
GetDockerEndpoint
(
dockerEndpoint
string
)
string
{
var
endpoint
string
if
len
(
dockerEndpoint
)
>
0
{
endpoint
=
dockerEndpoint
}
else
if
len
(
os
.
Getenv
(
"DOCKER_HOST"
))
>
0
{
endpoint
=
os
.
Getenv
(
"DOCKER_HOST"
)
}
else
{
endpoint
=
"unix:///var/run/docker.sock"
}
glog
.
Infof
(
"Connecting to docker on %s"
,
endpoint
)
return
endpoint
}
// RunApiServer starts an API server in a go routine.
func
RunApiServer
(
cl
*
client
.
Client
,
etcdClient
tools
.
EtcdClient
,
addr
string
,
port
int
)
{
handler
:=
delegateHandler
{}
...
...
@@ -172,7 +156,7 @@ func RunKubelet(kcfg *KubeletConfig) {
kubelet
.
SetupLogging
()
kubelet
.
SetupCapabilities
(
kcfg
.
AllowPrivileged
)
kcfg
.
Hostname
=
kubelet
.
GetHostname
(
kcfg
.
HostnameOverride
)
kcfg
.
Hostname
=
util
.
GetHostname
(
kcfg
.
HostnameOverride
)
if
len
(
kcfg
.
RootDirectory
)
>
0
{
kubelet
.
SetupRootDirectoryOrDie
(
kcfg
.
RootDirectory
)
}
...
...
pkg/util/node.go
0 → 100644
View file @
f718957a
/*
Copyright 2015 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
util
import
(
"os"
"os/exec"
"strings"
"github.com/fsouza/go-dockerclient"
"github.com/golang/glog"
)
func
GetHostname
(
hostnameOverride
string
)
string
{
hostname
:=
[]
byte
(
hostnameOverride
)
if
string
(
hostname
)
==
""
{
// Note: We use exec here instead of os.Hostname() because we
// want the FQDN, and this is the easiest way to get it.
fqdn
,
err
:=
exec
.
Command
(
"hostname"
,
"-f"
)
.
Output
()
if
err
!=
nil
{
glog
.
Fatalf
(
"Couldn't determine hostname: %v"
,
err
)
}
hostname
=
fqdn
}
return
strings
.
TrimSpace
(
string
(
hostname
))
}
// Get a docker endpoint, either from the string passed in, or $DOCKER_HOST environment variables
func
GetDockerEndpoint
(
dockerEndpoint
string
)
string
{
var
endpoint
string
if
len
(
dockerEndpoint
)
>
0
{
endpoint
=
dockerEndpoint
}
else
if
len
(
os
.
Getenv
(
"DOCKER_HOST"
))
>
0
{
endpoint
=
os
.
Getenv
(
"DOCKER_HOST"
)
}
else
{
endpoint
=
"unix:///var/run/docker.sock"
}
glog
.
Infof
(
"Connecting to docker on %s"
,
endpoint
)
return
endpoint
}
func
ConnectToDockerOrDie
(
dockerEndpoint
string
)
*
docker
.
Client
{
client
,
err
:=
docker
.
NewClient
(
GetDockerEndpoint
(
dockerEndpoint
))
if
err
!=
nil
{
glog
.
Fatal
(
"Couldn't connect to docker."
)
}
return
client
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment