Skip to content

Commit 9f6c5f2

Browse files
committed
Merge pull request #2339 from mboersma/fix-golint-warnings
style(*): add doc strings, remove unused code
2 parents 72f4419 + 3c49fda commit 9f6c5f2

7 files changed

Lines changed: 91 additions & 151 deletions

File tree

deisctl/client/client.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/deis/deis/deisctl/cmd"
99
)
1010

11+
// DeisCtlClient manages Deis components, configuration, and related tasks.
1112
type DeisCtlClient interface {
1213
Config() error
1314
Install(targets []string) error
@@ -23,10 +24,13 @@ type DeisCtlClient interface {
2324
Update() error
2425
}
2526

27+
// Client uses a backend to implement the DeisCtlClient interface.
2628
type Client struct {
2729
Backend backend.Backend
2830
}
2931

32+
// NewClient returns a Client using the requested backend.
33+
// The only backend currently supported is "fleet".
3034
func NewClient(requestedBackend string) (*Client, error) {
3135
var backend backend.Backend
3236

@@ -47,50 +51,66 @@ func NewClient(requestedBackend string) (*Client, error) {
4751
return &Client{Backend: backend}, nil
4852
}
4953

54+
// Config gets or sets a configuration value from the cluster.
55+
//
56+
// A configuration value is stored and retrieved from a key/value store (in this case, etcd)
57+
// at /deis/<component>/<config>. Configuration values are typically used for component-level
58+
// configuration, such as enabling TLS for the routers.
5059
func (c *Client) Config() error {
5160
return cmd.Config()
5261
}
5362

63+
// Install loads components' definitions from local unit files.
5464
func (c *Client) Install(targets []string) error {
5565
return cmd.Install(c.Backend, targets)
5666
}
5767

68+
// Journal prints log output for the specified components.
5869
func (c *Client) Journal(targets []string) error {
5970
return cmd.Journal(c.Backend, targets)
6071
}
6172

73+
// List prints a summary of installed components.
6274
func (c *Client) List() error {
6375
return cmd.ListUnits(c.Backend)
6476
}
6577

78+
// RefreshUnits overwrites local unit files with those requested.
6679
func (c *Client) RefreshUnits() error {
6780
return cmd.RefreshUnits()
6881
}
6982

83+
// Restart stops and then starts components.
7084
func (c *Client) Restart(targets []string) error {
7185
return cmd.Restart(c.Backend, targets)
7286
}
7387

88+
// Scale grows or shrinks the number of running components.
7489
func (c *Client) Scale(targets []string) error {
7590
return cmd.Scale(c.Backend, targets)
7691
}
7792

93+
// Start activates the specified components.
7894
func (c *Client) Start(targets []string) error {
7995
return cmd.Start(c.Backend, targets)
8096
}
8197

98+
// Status prints the current state of components.
8299
func (c *Client) Status(targets []string) error {
83100
return cmd.Status(c.Backend, targets)
84101
}
85102

103+
// Stop deactivates the specified components.
86104
func (c *Client) Stop(targets []string) error {
87105
return cmd.Stop(c.Backend, targets)
88106
}
89107

108+
// Uninstall unloads components' definitions.
90109
func (c *Client) Uninstall(targets []string) error {
91110
return cmd.Uninstall(c.Backend, targets)
92111
}
93112

113+
// Update changes the platform version on a cluster host.
94114
func (c *Client) Update() error {
95115
return cmd.Update()
96116
}

deisctl/cmd/cmd.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,23 @@ import (
2424
)
2525

2626
const (
27+
// PlatformInstallCommand is shorthand for "all the Deis components."
2728
PlatformInstallCommand string = "platform"
2829
)
2930

31+
// ListUnits prints a list of installed units.
3032
func ListUnits(b backend.Backend) error {
31-
err := b.ListUnits()
32-
return err
33+
return b.ListUnits()
3334
}
3435

36+
// ListUnitFiles prints the contents of all defined unit files.
3537
func ListUnitFiles(b backend.Backend) error {
3638
err := b.ListUnitFiles()
3739
return err
3840
}
3941

42+
// Scale grows or shrinks the number of running components.
43+
// Currently "router" is the only type that can be scaled.
4044
func Scale(b backend.Backend, targets []string) error {
4145
outchan := make(chan string)
4246
errchan := make(chan error)
@@ -60,6 +64,7 @@ func Scale(b backend.Backend, targets []string) error {
6064
return nil
6165
}
6266

67+
// Start activates the specified components.
6368
func Start(b backend.Backend, targets []string) error {
6469

6570
if len(targets) == 1 && targets[0] == PlatformInstallCommand {
@@ -94,6 +99,7 @@ deisctl config platform set sshPrivateKey=<path-to-key>
9499
return nil
95100
}
96101

102+
// StartPlatform activates all components.
97103
func StartPlatform(b backend.Backend) error {
98104

99105
outchan := make(chan string)
@@ -165,6 +171,7 @@ func startDefaultServices(b backend.Backend, wg *sync.WaitGroup, outchan chan st
165171
wg.Wait()
166172
}
167173

174+
// Stop deactivates the specified components.
168175
func Stop(b backend.Backend, targets []string) error {
169176

170177
if len(targets) == 1 && targets[0] == PlatformInstallCommand {
@@ -184,6 +191,7 @@ func Stop(b backend.Backend, targets []string) error {
184191
return nil
185192
}
186193

194+
// StopPlatform deactivates all components.
187195
func StopPlatform(b backend.Backend) error {
188196

189197
outchan := make(chan string)
@@ -234,13 +242,15 @@ func stopDefaultServices(b backend.Backend, wg *sync.WaitGroup, outchan chan str
234242
wg.Wait()
235243
}
236244

245+
// Restart stops and then starts components.
237246
func Restart(b backend.Backend, targets []string) error {
238247
if err := Stop(b, targets); err != nil {
239248
return err
240249
}
241250
return Start(b, targets)
242251
}
243252

253+
// Status prints the current state of components.
244254
func Status(b backend.Backend, targets []string) error {
245255
for _, target := range targets {
246256
if err := b.Status(target); err != nil {
@@ -250,6 +260,7 @@ func Status(b backend.Backend, targets []string) error {
250260
return nil
251261
}
252262

263+
// Journal prints log output for the specified components.
253264
func Journal(b backend.Backend, targets []string) error {
254265
for _, target := range targets {
255266
if err := b.Journal(target); err != nil {
@@ -259,6 +270,8 @@ func Journal(b backend.Backend, targets []string) error {
259270
return nil
260271
}
261272

273+
// Install loads components' definitions from local unit files.
274+
// After Install, the components will be available to Start.
262275
func Install(b backend.Backend, targets []string) error {
263276

264277
// if target is platform, install all services
@@ -280,6 +293,8 @@ func Install(b backend.Backend, targets []string) error {
280293
return nil
281294
}
282295

296+
// InstallPlatform loads all components' definitions from local unit files.
297+
// After InstallPlatform, all components will be available for StartPlatform.
283298
func InstallPlatform(b backend.Backend) error {
284299

285300
if err := checkRequiredKeys(); err != nil {
@@ -328,6 +343,8 @@ func installDefaultServices(b backend.Backend, wg *sync.WaitGroup, outchan chan
328343
wg.Wait()
329344
}
330345

346+
// Uninstall unloads components' definitions.
347+
// After Uninstall, the component will be unavailable until Install is called.
331348
func Uninstall(b backend.Backend, targets []string) error {
332349

333350
// if target is platform, uninstall all services
@@ -349,6 +366,8 @@ func Uninstall(b backend.Backend, targets []string) error {
349366
return nil
350367
}
351368

369+
// UninstallPlatform unloads all components' definitions.
370+
// After UninstallPlatform, all components will be unavailable.
352371
func UninstallPlatform(b backend.Backend) error {
353372

354373
outchan := make(chan string)
@@ -432,13 +451,15 @@ func splitScaleTarget(target string) (c string, num int, err error) {
432451
return
433452
}
434453

454+
// Config gets or sets a configuration value in the cluster.
435455
func Config() error {
436456
if err := config.Config(); err != nil {
437457
return err
438458
}
439459
return nil
440460
}
441461

462+
// Update changes the platform version on a cluster host.
442463
func Update() error {
443464
if err := utils.Execute(constant.HooksDir + "pre-update"); err != nil {
444465
fmt.Println("pre-updatehook failed")
@@ -455,6 +476,9 @@ func Update() error {
455476
return nil
456477
}
457478

479+
// RefreshUnits overwrites local unit files with those requested.
480+
// Downloading from the Deis project GitHub URL by tag or SHA is the only mechanism
481+
// currently supported.
458482
func RefreshUnits() error {
459483
usage := `Refreshes local unit files from the master repository.
460484

deisctl/constant/constants.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,24 @@ package constant
33
import "time"
44

55
const (
6-
UnitsDir = "/var/lib/deis/units/"
7-
HooksDir = "/var/lib/deis/hooks/"
8-
Version = "/etc/deis-version"
9-
MachineID = "/etc/machine-id"
10-
UpdatekeyDir = "/deis/update/"
6+
// UnitsDir is the default directory for unit files.
7+
UnitsDir = "/var/lib/deis/units/"
8+
9+
// HooksDir is the default directory for hook scripts.
10+
HooksDir = "/var/lib/deis/hooks/"
11+
12+
// Version is the location of the deis-version text file.
13+
Version = "/etc/deis-version"
14+
15+
// MachineID is the location of the machine-id file.
16+
MachineID = "/etc/machine-id"
17+
18+
// UpdatekeyDir is the etcd directory for update data.
19+
UpdatekeyDir = "/deis/update/"
20+
21+
// InitialInterval specifies how long to wait at first between update loops.
1122
InitialInterval = time.Second * 10
12-
MaxInterval = time.Minute * 7
23+
24+
// MaxInterval is the longest time allowed to wait between loops.
25+
MaxInterval = time.Minute * 7
1326
)

deisctl/update/client.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/deis/deis/deisctl/utils"
2222
)
2323

24+
// Client handles locking, update server interactions, and node updates.
2425
type Client struct {
2526
ID string
2627
SessionID string
@@ -33,6 +34,7 @@ type Client struct {
3334
lock *lock.Lock
3435
}
3536

37+
// Logf prints a log message prefixed by Client.ID.
3638
func (c *Client) Logf(format string, args ...interface{}) {
3739
format = c.ID + ": " + format
3840
fmt.Printf(format, args...)
@@ -47,6 +49,7 @@ func (c *Client) getCodebaseURL(uc *omaha.UpdateCheck) string {
4749
return uc.Urls.Urls[0].CodeBase + uc.Manifest.Packages.Packages[0].Name
4850
}
4951

52+
// RequestLock asks for a new etcd Lock.
5053
func (c *Client) RequestLock() {
5154
elc, err := lock.NewEtcdLockClient(nil)
5255
if err != nil {
@@ -60,7 +63,10 @@ func (c *Client) RequestLock() {
6063
c.lock = lock.New(mID, elc)
6164
}
6265

63-
func (c *Client) OmahaRequest(otype, result string, updateCheck, isPing bool) *omaha.Request {
66+
// OmahaRequest returns an update server Request of the specified type.
67+
func (c *Client) OmahaRequest(
68+
otype, result string, updateCheck, isPing bool) *omaha.Request {
69+
6470
req := omaha.NewRequest("lsb", "CoreOS", "", "")
6571
app := req.AddApp(c.AppID, c.Version)
6672
app.MachineID = c.ID
@@ -92,6 +98,7 @@ func (c *Client) OmahaRequest(otype, result string, updateCheck, isPing bool) *o
9298
return req
9399
}
94100

101+
// MakeRequest queries the omaha update server and returns its Response.
95102
func (c *Client) MakeRequest(otype, result string, updateCheck, isPing bool) (*omaha.Response, error) {
96103
client := &http.Client{}
97104
req := c.OmahaRequest(otype, result, updateCheck, isPing)
@@ -122,7 +129,7 @@ func (c *Client) MakeRequest(otype, result string, updateCheck, isPing bool) (*o
122129
return oresp, nil
123130
}
124131

125-
// Loop between n and m seconds
132+
// Loop repeatedly makes a request, pausing a random amount between n and m seconds.
126133
func (c *Client) Loop(n, m int) {
127134
interval := constant.InitialInterval
128135
for {
@@ -178,6 +185,7 @@ func (c *Client) Loop(n, m int) {
178185
}
179186
}
180187

188+
// SetVersion specifies the particular platform version for update.
181189
func (c *Client) SetVersion(resp *omaha.Response) {
182190
// A field can potentially be nil.
183191
defer func() {
@@ -218,6 +226,7 @@ func (c *Client) SetVersion(resp *omaha.Response) {
218226
c.SessionID = uuid.New()
219227
}
220228

229+
// Update changes services on a node to match the requested version.
221230
func (c *Client) Update() (err error) {
222231
deis, _ := fleet.NewClient()
223232
localServices := deis.GetLocaljobs()

0 commit comments

Comments
 (0)