mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 04:06:03 +00:00
Merge pull request #215 from thockin/cleanups
Clarify config file code to be clear that it handles directories, too. ...
This commit is contained in:
commit
55be74ae36
@ -15,7 +15,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
// The kubelet binary is responsible for maintaining a set of containers on a particular host VM.
|
||||
// It sync's data from both configuration file as well as from a quorum of etcd servers.
|
||||
// It syncs data from both configuration file(s) as well as from a quorum of etcd servers.
|
||||
// It then queries Docker to see what is currently running. It synchronizes the configuration data,
|
||||
// with the running set of containers by starting or stopping Docker containers.
|
||||
package main
|
||||
@ -34,10 +34,10 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
file = flag.String("config", "", "Path to the config file/dir")
|
||||
config = flag.String("config", "", "Path to the config file or directory of files")
|
||||
etcdServers = flag.String("etcd_servers", "", "Url of etcd servers in the cluster")
|
||||
syncFrequency = flag.Duration("sync_frequency", 10*time.Second, "Max period between synchronizing running containers and config")
|
||||
fileCheckFrequency = flag.Duration("file_check_frequency", 20*time.Second, "Duration between checking file for new data")
|
||||
fileCheckFrequency = flag.Duration("file_check_frequency", 20*time.Second, "Duration between checking config files for new data")
|
||||
httpCheckFrequency = flag.Duration("http_check_frequency", 20*time.Second, "Duration between checking http for new data")
|
||||
manifestUrl = flag.String("manifest_url", "", "URL for accessing the container manifest")
|
||||
address = flag.String("address", "127.0.0.1", "The address for the info server to serve on")
|
||||
@ -62,6 +62,8 @@ func main() {
|
||||
|
||||
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.
|
||||
hostname, err = exec.Command("hostname", "-f").Output()
|
||||
if err != nil {
|
||||
log.Fatalf("Couldn't determine hostname: %v", err)
|
||||
@ -75,5 +77,5 @@ func main() {
|
||||
SyncFrequency: *syncFrequency,
|
||||
HTTPCheckFrequency: *httpCheckFrequency,
|
||||
}
|
||||
my_kubelet.RunKubelet(*file, *manifestUrl, *etcdServers, *address, *port)
|
||||
my_kubelet.RunKubelet(*config, *manifestUrl, *etcdServers, *address, *port)
|
||||
}
|
||||
|
@ -89,12 +89,12 @@ const (
|
||||
httpServerSource = "http_server"
|
||||
)
|
||||
|
||||
// Starts background goroutines. If file, manifest_url, or address are empty,
|
||||
// Starts background goroutines. If config_path, manifest_url, or address are empty,
|
||||
// they are not watched. Never returns.
|
||||
func (kl *Kubelet) RunKubelet(file, manifest_url, etcd_servers, address string, port uint) {
|
||||
func (kl *Kubelet) RunKubelet(config_path, manifest_url, etcd_servers, address string, port uint) {
|
||||
updateChannel := make(chan manifestUpdate)
|
||||
if file != "" {
|
||||
go util.Forever(func() { kl.WatchFile(file, updateChannel) }, kl.FileCheckFrequency)
|
||||
if config_path != "" {
|
||||
go util.Forever(func() { kl.WatchFiles(config_path, updateChannel) }, kl.FileCheckFrequency)
|
||||
}
|
||||
if manifest_url != "" {
|
||||
go util.Forever(func() {
|
||||
@ -451,32 +451,35 @@ func (kl *Kubelet) extractSingleFromReader(reader io.Reader) (api.ContainerManif
|
||||
return manifest, nil
|
||||
}
|
||||
|
||||
// Watch a file for changes to the set of pods that should run on this Kubelet
|
||||
// This function loops forever and is intended to be run as a goroutine
|
||||
func (kl *Kubelet) WatchFile(file string, updateChannel chan<- manifestUpdate) {
|
||||
// Watch a file or direcory of files for changes to the set of pods that
|
||||
// should run on this Kubelet.
|
||||
func (kl *Kubelet) WatchFiles(config_path string, updateChannel chan<- manifestUpdate) {
|
||||
var err error
|
||||
|
||||
fileInfo, err := os.Stat(file)
|
||||
statInfo, err := os.Stat(config_path)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
log.Printf("Error polling file: %#v", err)
|
||||
log.Printf("Error accessing path: %#v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if fileInfo.IsDir() {
|
||||
manifests, err := kl.extractFromDir(file)
|
||||
if statInfo.Mode().IsDir() {
|
||||
manifests, err := kl.extractFromDir(config_path)
|
||||
if err != nil {
|
||||
log.Printf("Error polling dir: %#v", err)
|
||||
return
|
||||
}
|
||||
updateChannel <- manifestUpdate{fileSource, manifests}
|
||||
} else {
|
||||
manifest, err := kl.extractFromFile(file)
|
||||
} else if statInfo.Mode().IsRegular() {
|
||||
manifest, err := kl.extractFromFile(config_path)
|
||||
if err != nil {
|
||||
log.Printf("Error polling file: %#v", err)
|
||||
return
|
||||
}
|
||||
updateChannel <- manifestUpdate{fileSource, []api.ContainerManifest{manifest}}
|
||||
} else {
|
||||
log.Printf("Error accessing config - not a directory or file")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user