mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
commit
58030faf4a
@ -61,7 +61,7 @@ func main() {
|
|||||||
|
|
||||||
controllerManager.Run(1 * time.Second)
|
controllerManager.Run(1 * time.Second)
|
||||||
|
|
||||||
// Kublet
|
// Kubelet
|
||||||
fakeDocker1 := &kubelet.FakeDockerClient{}
|
fakeDocker1 := &kubelet.FakeDockerClient{}
|
||||||
myKubelet := kubelet.Kubelet{
|
myKubelet := kubelet.Kubelet{
|
||||||
Hostname: machineList[0],
|
Hostname: machineList[0],
|
||||||
@ -73,7 +73,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
go myKubelet.RunKubelet("", manifestUrl, servers[0], "localhost", "", 0)
|
go myKubelet.RunKubelet("", manifestUrl, servers[0], "localhost", "", 0)
|
||||||
|
|
||||||
// Create a second kublet so that the guestbook example's two redis slaves both
|
// Create a second kubelet so that the guestbook example's two redis slaves both
|
||||||
// have a place they can schedule.
|
// have a place they can schedule.
|
||||||
fakeDocker2 := &kubelet.FakeDockerClient{}
|
fakeDocker2 := &kubelet.FakeDockerClient{}
|
||||||
otherKubelet := kubelet.Kubelet{
|
otherKubelet := kubelet.Kubelet{
|
||||||
|
@ -14,6 +14,6 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Package kubelet is the package that contains the libraries that drive the Kublet binary.
|
// Package kubelet is the package that contains the libraries that drive the Kubelet binary.
|
||||||
// The kublet is responsible for node level pod management. It runs on each worker in the cluster.
|
// The kubelet is responsible for node level pod management. It runs on each worker in the cluster.
|
||||||
package kubelet
|
package kubelet
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"github.com/fsouza/go-dockerclient"
|
"github.com/fsouza/go-dockerclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A simple fake docker client, so that kublet can be run for testing without requiring a real docker setup.
|
// A simple fake docker client, so that kubelet can be run for testing without requiring a real docker setup.
|
||||||
type FakeDockerClient struct {
|
type FakeDockerClient struct {
|
||||||
containerList []docker.APIContainers
|
containerList []docker.APIContainers
|
||||||
container *docker.Container
|
container *docker.Container
|
||||||
|
@ -116,7 +116,7 @@ func (kl *Kubelet) RunKubelet(config_path, manifest_url, etcd_servers, address,
|
|||||||
glog.Infof("Watching for HTTP configs at %s", manifest_url)
|
glog.Infof("Watching for HTTP configs at %s", manifest_url)
|
||||||
go util.Forever(func() {
|
go util.Forever(func() {
|
||||||
if err := kl.extractFromHTTP(manifest_url, updateChannel); err != nil {
|
if err := kl.extractFromHTTP(manifest_url, updateChannel); err != nil {
|
||||||
glog.Errorf("Error syncing http: %#v", err)
|
glog.Errorf("Error syncing http: %v", err)
|
||||||
}
|
}
|
||||||
}, kl.HTTPCheckFrequency)
|
}, kl.HTTPCheckFrequency)
|
||||||
}
|
}
|
||||||
@ -166,7 +166,7 @@ func (kl *Kubelet) LogEvent(event *api.Event) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error writing event: %s\n", err)
|
glog.Errorf("Error writing event: %s\n", err)
|
||||||
if response != nil {
|
if response != nil {
|
||||||
glog.Infof("Response was: %#v\n", *response)
|
glog.Infof("Response was: %v\n", *response)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@ -427,21 +427,21 @@ func (kl *Kubelet) WatchFiles(config_path string, updateChannel chan<- manifestU
|
|||||||
statInfo, err := os.Stat(config_path)
|
statInfo, err := os.Stat(config_path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
glog.Errorf("Error accessing path: %#v", err)
|
glog.Errorf("Error accessing path: %v", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if statInfo.Mode().IsDir() {
|
if statInfo.Mode().IsDir() {
|
||||||
manifests, err := kl.extractFromDir(config_path)
|
manifests, err := kl.extractFromDir(config_path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error polling dir: %#v", err)
|
glog.Errorf("Error polling dir: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
updateChannel <- manifestUpdate{fileSource, manifests}
|
updateChannel <- manifestUpdate{fileSource, manifests}
|
||||||
} else if statInfo.Mode().IsRegular() {
|
} else if statInfo.Mode().IsRegular() {
|
||||||
manifest, err := kl.extractFromFile(config_path)
|
manifest, err := kl.extractFromFile(config_path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error polling file: %#v", err)
|
glog.Errorf("Error polling file: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
updateChannel <- manifestUpdate{fileSource, []api.ContainerManifest{manifest}}
|
updateChannel <- manifestUpdate{fileSource, []api.ContainerManifest{manifest}}
|
||||||
@ -498,7 +498,7 @@ func (kl *Kubelet) extractFromHTTP(url string, updateChannel chan<- manifestUpda
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("%v: received '%v', but couldn't parse as a "+
|
return fmt.Errorf("%v: received '%v', but couldn't parse as a "+
|
||||||
"single manifest (%v: %#v) or as multiple manifests (%v: %#v).\n",
|
"single manifest (%v: %+v) or as multiple manifests (%v: %+v).\n",
|
||||||
url, string(data), singleErr, manifest, multiErr, manifests)
|
url, string(data), singleErr, manifest, multiErr, manifests)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -506,7 +506,7 @@ func (kl *Kubelet) extractFromHTTP(url string, updateChannel chan<- manifestUpda
|
|||||||
// Return a list of containers, or an error if one occurs.
|
// Return a list of containers, or an error if one occurs.
|
||||||
func (kl *Kubelet) ResponseToManifests(response *etcd.Response) ([]api.ContainerManifest, error) {
|
func (kl *Kubelet) ResponseToManifests(response *etcd.Response) ([]api.ContainerManifest, error) {
|
||||||
if response.Node == nil || len(response.Node.Value) == 0 {
|
if response.Node == nil || len(response.Node.Value) == 0 {
|
||||||
return nil, fmt.Errorf("no nodes field: %#v", response)
|
return nil, fmt.Errorf("no nodes field: %v", response)
|
||||||
}
|
}
|
||||||
var manifests []api.ContainerManifest
|
var manifests []api.ContainerManifest
|
||||||
err := kl.ExtractYAMLData([]byte(response.Node.Value), &manifests)
|
err := kl.ExtractYAMLData([]byte(response.Node.Value), &manifests)
|
||||||
@ -519,12 +519,12 @@ func (kl *Kubelet) getKubeletStateFromEtcd(key string, updateChannel chan<- mani
|
|||||||
if util.IsEtcdNotFound(err) {
|
if util.IsEtcdNotFound(err) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
glog.Errorf("Error on etcd get of %s: %#v", key, err)
|
glog.Errorf("Error on etcd get of %s: %v", key, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
manifests, err := kl.ResponseToManifests(response)
|
manifests, err := kl.ResponseToManifests(response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error parsing response (%#v): %s", response, err)
|
glog.Errorf("Error parsing response (%v): %s", response, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
glog.Infof("Got state from etcd: %+v", manifests)
|
glog.Infof("Got state from etcd: %+v", manifests)
|
||||||
@ -585,7 +585,7 @@ func (kl *Kubelet) ExtractYAMLData(buf []byte, output interface{}) error {
|
|||||||
func (kl *Kubelet) extractFromEtcd(response *etcd.Response) ([]api.ContainerManifest, error) {
|
func (kl *Kubelet) extractFromEtcd(response *etcd.Response) ([]api.ContainerManifest, error) {
|
||||||
var manifests []api.ContainerManifest
|
var manifests []api.ContainerManifest
|
||||||
if response.Node == nil || len(response.Node.Value) == 0 {
|
if response.Node == nil || len(response.Node.Value) == 0 {
|
||||||
return manifests, fmt.Errorf("no nodes field: %#v", response)
|
return manifests, fmt.Errorf("no nodes field: %v", response)
|
||||||
}
|
}
|
||||||
err := kl.ExtractYAMLData([]byte(response.Node.Value), &manifests)
|
err := kl.ExtractYAMLData([]byte(response.Node.Value), &manifests)
|
||||||
return manifests, err
|
return manifests, err
|
||||||
@ -601,13 +601,13 @@ func (kl *Kubelet) WatchEtcd(watchChannel <-chan *etcd.Response, updateChannel c
|
|||||||
if watchResponse == nil {
|
if watchResponse == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
glog.Infof("Got etcd change: %#v", watchResponse)
|
glog.Infof("Got etcd change: %v", watchResponse)
|
||||||
manifests, err := kl.extractFromEtcd(watchResponse)
|
manifests, err := kl.extractFromEtcd(watchResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error handling response from etcd: %#v", err)
|
glog.Errorf("Error handling response from etcd: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
glog.Infof("manifests: %#v", manifests)
|
glog.Infof("manifests: %+v", manifests)
|
||||||
// Ok, we have a valid configuration, send to channel for
|
// Ok, we have a valid configuration, send to channel for
|
||||||
// rejiggering.
|
// rejiggering.
|
||||||
updateChannel <- manifestUpdate{etcdSource, manifests}
|
updateChannel <- manifestUpdate{etcdSource, manifests}
|
||||||
@ -641,7 +641,7 @@ func (kl *Kubelet) createNetworkContainer(manifest *api.ContainerManifest) (Dock
|
|||||||
|
|
||||||
// Sync the configured list of containers (desired state) with the host current state
|
// Sync the configured list of containers (desired state) with the host current state
|
||||||
func (kl *Kubelet) SyncManifests(config []api.ContainerManifest) error {
|
func (kl *Kubelet) SyncManifests(config []api.ContainerManifest) error {
|
||||||
glog.Infof("Desired: %#v", config)
|
glog.Infof("Desired: %+v", config)
|
||||||
var err error
|
var err error
|
||||||
dockerIdsToKeep := map[DockerId]bool{}
|
dockerIdsToKeep := map[DockerId]bool{}
|
||||||
|
|
||||||
@ -650,14 +650,14 @@ func (kl *Kubelet) SyncManifests(config []api.ContainerManifest) error {
|
|||||||
// Make sure we have a network container
|
// Make sure we have a network container
|
||||||
netId, err := kl.getNetworkContainerId(&manifest)
|
netId, err := kl.getNetworkContainerId(&manifest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to introspect network container. (%#v) Skipping container %s", err, manifest.Id)
|
glog.Errorf("Failed to introspect network container. (%v) Skipping container %s", err, manifest.Id)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if netId == "" {
|
if netId == "" {
|
||||||
glog.Infof("Network container doesn't exist, creating")
|
glog.Infof("Network container doesn't exist, creating")
|
||||||
netId, err = kl.createNetworkContainer(&manifest)
|
netId, err = kl.createNetworkContainer(&manifest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to create network container: %#v Skipping container %s", err, manifest.Id)
|
glog.Errorf("Failed to create network container: %v Skipping container %s", err, manifest.Id)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -666,24 +666,24 @@ func (kl *Kubelet) SyncManifests(config []api.ContainerManifest) error {
|
|||||||
for _, container := range manifest.Containers {
|
for _, container := range manifest.Containers {
|
||||||
containerId, err := kl.getContainerId(&manifest, &container)
|
containerId, err := kl.getContainerId(&manifest, &container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error detecting container: %#v skipping.", err)
|
glog.Errorf("Error detecting container: %v skipping.", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if containerId == "" {
|
if containerId == "" {
|
||||||
glog.Infof("%#v doesn't exist, creating", container)
|
glog.Infof("%+v doesn't exist, creating", container)
|
||||||
kl.DockerPuller.Pull(container.Image)
|
kl.DockerPuller.Pull(container.Image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error pulling container: %#v", err)
|
glog.Errorf("Error pulling container: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
containerId, err = kl.runContainer(&manifest, &container, "container:"+string(netId))
|
containerId, err = kl.runContainer(&manifest, &container, "container:"+string(netId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO(bburns) : Perhaps blacklist a container after N failures?
|
// TODO(bburns) : Perhaps blacklist a container after N failures?
|
||||||
glog.Errorf("Error creating container: %#v", err)
|
glog.Errorf("Error creating container: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
glog.V(1).Infof("%#v exists as %v", container.Name, containerId)
|
glog.V(1).Infof("%s exists as %v", container.Name, containerId)
|
||||||
}
|
}
|
||||||
dockerIdsToKeep[containerId] = true
|
dockerIdsToKeep[containerId] = true
|
||||||
}
|
}
|
||||||
@ -692,7 +692,7 @@ func (kl *Kubelet) SyncManifests(config []api.ContainerManifest) error {
|
|||||||
// Kill any containers we don't need
|
// Kill any containers we don't need
|
||||||
existingContainers, err := kl.getDockerContainers()
|
existingContainers, err := kl.getDockerContainers()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error listing containers: %#v", err)
|
glog.Errorf("Error listing containers: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for id, container := range existingContainers {
|
for id, container := range existingContainers {
|
||||||
@ -700,7 +700,7 @@ func (kl *Kubelet) SyncManifests(config []api.ContainerManifest) error {
|
|||||||
glog.Infof("Killing: %s", id)
|
glog.Infof("Killing: %s", id)
|
||||||
err = kl.killContainer(container)
|
err = kl.killContainer(container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error killing container: %#v", err)
|
glog.Errorf("Error killing container: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -718,7 +718,7 @@ func (kl *Kubelet) RunSyncLoop(updateChannel <-chan manifestUpdate, handler Sync
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case u := <-updateChannel:
|
case u := <-updateChannel:
|
||||||
glog.Infof("Got configuration from %s: %#v", u.source, u.manifests)
|
glog.Infof("Got configuration from %s: %+v", u.source, u.manifests)
|
||||||
last[u.source] = u.manifests
|
last[u.source] = u.manifests
|
||||||
case <-time.After(kl.SyncFrequency):
|
case <-time.After(kl.SyncFrequency):
|
||||||
}
|
}
|
||||||
@ -730,7 +730,7 @@ func (kl *Kubelet) RunSyncLoop(updateChannel <-chan manifestUpdate, handler Sync
|
|||||||
|
|
||||||
err := handler.SyncManifests(manifests)
|
err := handler.SyncManifests(manifests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Couldn't sync containers : %#v", err)
|
glog.Errorf("Couldn't sync containers : %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ type kubeletInterface interface {
|
|||||||
|
|
||||||
func (s *KubeletServer) error(w http.ResponseWriter, err error) {
|
func (s *KubeletServer) error(w http.ResponseWriter, err error) {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
fmt.Fprintf(w, "Internal Error: %#v", err)
|
fmt.Fprintf(w, "Internal Error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *KubeletServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
func (s *KubeletServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
@ -87,7 +87,7 @@ func (s *KubeletServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
stats, err := s.Kubelet.GetContainerStats(container)
|
stats, err := s.Kubelet.GetContainerStats(container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
fmt.Fprintf(w, "Internal Error: %#v", err)
|
fmt.Fprintf(w, "Internal Error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if stats == nil {
|
if stats == nil {
|
||||||
@ -98,7 +98,7 @@ func (s *KubeletServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
data, err := json.Marshal(stats)
|
data, err := json.Marshal(stats)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
fmt.Fprintf(w, "Internal Error: %#v", err)
|
fmt.Fprintf(w, "Internal Error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
@ -116,7 +116,7 @@ func (s *KubeletServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
data, err := s.Kubelet.GetContainerInfo(container)
|
data, err := s.Kubelet.GetContainerInfo(container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
fmt.Fprintf(w, "Internal Error: %#v", err)
|
fmt.Fprintf(w, "Internal Error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
Loading…
Reference in New Issue
Block a user