Example #1
0
// Run blocks implementing the scheduler module.
func Run(conn db.Conn, dk docker.Client) {
	bootWait(conn)

	subnet := getMinionSubnet(conn)
	err := dk.ConfigureNetwork(plugin.NetworkName, subnet)
	if err != nil {
		log.WithError(err).Fatal("Failed to configure network plugin")
	}

	loopLog := util.NewEventTimer("Scheduler")
	trig := conn.TriggerTick(60, db.MinionTable, db.ContainerTable,
		db.PlacementTable, db.EtcdTable).C
	for range trig {
		loopLog.LogStart()
		minion, err := conn.MinionSelf()
		if err != nil {
			log.WithError(err).Warn("Missing self in the minion table.")
			continue
		}

		if minion.Role == db.Worker {
			subnet = updateNetwork(conn, dk, subnet)
			runWorker(conn, dk, minion.PrivateIP, subnet)
		} else if minion.Role == db.Master {
			runMaster(conn)
		}
		loopLog.LogEnd()
	}
}
Example #2
0
func updateNetwork(conn db.Conn, dk docker.Client, subnet net.IPNet) net.IPNet {

	newSubnet := getMinionSubnet(conn)
	if subnet.String() == newSubnet.String() {
		return subnet
	}

	err := dk.ConfigureNetwork(plugin.NetworkName, newSubnet)
	if err != nil {
		log.WithError(err).Fatal("Failed to configure network plugin")
		return subnet
	}

	return newSubnet
}