Esempio n. 1
0
func updateNodes(dockerCli *client.DockerCli, nodes []string, mergeNode func(node *swarm.Node) error, success func(nodeID string)) error {
	client := dockerCli.Client()
	ctx := context.Background()

	for _, nodeID := range nodes {
		node, _, err := client.NodeInspectWithRaw(ctx, nodeID)
		if err != nil {
			return err
		}

		err = mergeNode(&node)
		if err != nil {
			if err == errNoRoleChange {
				continue
			}
			return err
		}
		err = client.NodeUpdate(ctx, node.ID, node.Version, node.Spec)
		if err != nil {
			return err
		}
		success(nodeID)
	}
	return nil
}
Esempio n. 2
0
func runUpdate(dockerCli *client.DockerCli, nodeID string, mergeNode func(node *swarm.Node)) error {
	client := dockerCli.Client()
	ctx := context.Background()

	node, err := client.NodeInspect(ctx, nodeID)
	if err != nil {
		return err
	}

	mergeNode(&node)
	err = client.NodeUpdate(ctx, node.ID, node.Version, node.Spec)
	if err != nil {
		return err
	}

	return nil
}