Skip to content

Commit 8205124

Browse files
committed
cli/command/node: nodeContext: remove uses of reflect
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 40f052c commit 8205124

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

cli/command/node/formatter.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package node
22

33
import (
4+
"bytes"
45
"encoding/base64"
56
"fmt"
6-
"reflect"
77
"strings"
88

99
"github.com/docker/cli/cli/command/formatter"
@@ -170,15 +170,23 @@ func (c *nodeContext) ManagerStatus() string {
170170
}
171171

172172
func (c *nodeContext) TLSStatus() string {
173-
if c.info.Cluster == nil || reflect.DeepEqual(c.info.Cluster.TLSInfo, swarm.TLSInfo{}) || reflect.DeepEqual(c.n.Description.TLSInfo, swarm.TLSInfo{}) {
173+
if c.info.Cluster == nil || isEmptyTLSInfo(c.info.Cluster.TLSInfo) || isEmptyTLSInfo(c.n.Description.TLSInfo) {
174174
return "Unknown"
175175
}
176-
if reflect.DeepEqual(c.n.Description.TLSInfo, c.info.Cluster.TLSInfo) {
176+
if equalTLSInfo(c.n.Description.TLSInfo, c.info.Cluster.TLSInfo) {
177177
return "Ready"
178178
}
179179
return "Needs Rotation"
180180
}
181181

182+
func isEmptyTLSInfo(t swarm.TLSInfo) bool {
183+
return t.TrustRoot == "" && len(t.CertIssuerSubject) == 0 && len(t.CertIssuerPublicKey) == 0
184+
}
185+
186+
func equalTLSInfo(t, o swarm.TLSInfo) bool {
187+
return t.TrustRoot == o.TrustRoot && bytes.Equal(t.CertIssuerSubject, o.CertIssuerSubject) && bytes.Equal(t.CertIssuerPublicKey, o.CertIssuerPublicKey)
188+
}
189+
182190
func (c *nodeContext) EngineVersion() string {
183191
return c.n.Description.Engine.EngineVersion
184192
}
@@ -320,8 +328,7 @@ func (ctx *nodeInspectContext) EngineVersion() string {
320328
}
321329

322330
func (ctx *nodeInspectContext) HasTLSInfo() bool {
323-
tlsInfo := ctx.Node.Description.TLSInfo
324-
return !reflect.DeepEqual(tlsInfo, swarm.TLSInfo{})
331+
return !isEmptyTLSInfo(ctx.Node.Description.TLSInfo)
325332
}
326333

327334
func (ctx *nodeInspectContext) TLSInfoTrustRoot() string {

0 commit comments

Comments
 (0)