MCPcopy Index your code
hub / github.com/docker/cli / RootRotationProgress

Function RootRotationProgress

cli/command/swarm/progress/root_rotation.go:28–73  ·  view source on GitHub ↗

RootRotationProgress outputs progress information for convergence of a root rotation.

(ctx context.Context, apiClient client.APIClient, progressWriter io.WriteCloser)

Source from the content-addressed store, hash-verified

26
27// RootRotationProgress outputs progress information for convergence of a root rotation.
28func RootRotationProgress(ctx context.Context, apiClient client.APIClient, progressWriter io.WriteCloser) error {
29 defer func() {
30 _ = progressWriter.Close()
31 }()
32
33 progressOut := streamformatter.NewJSONProgressOutput(progressWriter, false)
34
35 sigint := make(chan os.Signal, 1)
36 signal.Notify(sigint, os.Interrupt)
37 defer signal.Stop(sigint)
38
39 // draw 2 progress bars, 1 for nodes with the correct cert, 1 for nodes with the correct trust root
40 progress.Update(progressOut, "desired root digest", "")
41 progress.Update(progressOut, certsRotatedStr, certsAction)
42 progress.Update(progressOut, rootsRotatedStr, rootsAction)
43
44 var done bool
45
46 for {
47 info, err := apiClient.SwarmInspect(ctx, client.SwarmInspectOptions{})
48 if err != nil {
49 return err
50 }
51
52 if done {
53 return nil
54 }
55
56 res, err := apiClient.NodeList(ctx, client.NodeListOptions{})
57 if err != nil {
58 return err
59 }
60
61 done = updateProgress(progressOut, info.Swarm.ClusterInfo.TLSInfo, res.Items, info.Swarm.ClusterInfo.RootRotationInProgress)
62
63 select {
64 case <-time.After(200 * time.Millisecond):
65 case <-sigint:
66 if !done {
67 progress.Message(progressOut, "", "Operation continuing in background.")
68 progress.Message(progressOut, "", "Use `swarmctl cluster inspect default` to check progress.")
69 }
70 return nil
71 }
72 }
73}
74
75func updateProgress(progressOut progress.Output, desiredTLSInfo swarm.TLSInfo, nodes []swarm.Node, rootRotationInProgress bool) bool {
76 // write the current desired root cert's digest, because the desired root certs might be too long

Callers

nothing calls this directly

Calls 4

updateProgressFunction · 0.85
SwarmInspectMethod · 0.80
CloseMethod · 0.45
NodeListMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…