@@ -69,9 +69,9 @@ type Client struct {
69
69
cryptocontext * cryptutils.CryptoContext
70
70
insecure bool
71
71
72
- nodeID string
73
- systemID string
74
- currentNodeInfo * cloudprotocol. NodeInfo
72
+ nodeID string
73
+ systemID string
74
+ isMainNode bool
75
75
76
76
publicConnection * grpchelpers.GRPCConn
77
77
protectedConnection * grpc.ClientConn
@@ -165,28 +165,42 @@ func New(
165
165
return nil , aoserrors .Wrap (err )
166
166
}
167
167
168
- if ! insecure && localClient .isProtectedConnEnabled () {
169
- var ch <- chan * pb.CertInfo
168
+ nodeInfo , err := localClient .GetCurrentNodeInfo ()
169
+ if err != nil {
170
+ return nil , aoserrors .Wrap (err )
171
+ }
170
172
171
- if ch , err = localClient .SubscribeCertChanged (certStorage ); err != nil {
173
+ localClient .nodeID = nodeInfo .NodeID
174
+ localClient .isMainNode = nodeInfo .IsMainNode ()
175
+
176
+ if localClient .isMainNode {
177
+ if localClient .systemID , err = localClient .getSystemID (); err != nil {
172
178
return nil , aoserrors .Wrap (err )
173
179
}
174
-
175
- go localClient .processCertChange (ch )
176
180
}
177
181
178
- var nodeInfo cloudprotocol.NodeInfo
182
+ if localClient .isMainNode {
183
+ if err = localClient .subscribeNodeInfoChange (); err != nil {
184
+ log .Error ("Failed subscribe on NodeInfo change" )
179
185
180
- if nodeInfo , err = localClient .GetCurrentNodeInfo (); err != nil {
181
- return nil , aoserrors .Wrap (err )
186
+ return nil , aoserrors .Wrap (err )
187
+ }
188
+
189
+ if err = localClient .subscribeUnitSubjectsChange (); err != nil {
190
+ log .Error ("Failed subscribe on UnitSubject change" )
191
+
192
+ return nil , aoserrors .Wrap (err )
193
+ }
182
194
}
183
195
184
- localClient .nodeID = nodeInfo .NodeID
196
+ if ! insecure && localClient .isProtectedConnEnabled () {
197
+ var ch <- chan * pb.CertInfo
185
198
186
- if localClient .currentNodeInfo .IsMainNode () {
187
- if localClient .systemID , err = localClient .getSystemID (); err != nil {
199
+ if ch , err = localClient .SubscribeCertChanged (certStorage ); err != nil {
188
200
return nil , aoserrors .Wrap (err )
189
201
}
202
+
203
+ go localClient .processCertChange (ch )
190
204
}
191
205
192
206
return localClient , nil
@@ -323,11 +337,19 @@ func (client *Client) InstallCertificates(
323
337
// And IAM certificate for the main node should be send in the end. Otherwise IAM client/server
324
338
// restart will fail the following certificates to apply.
325
339
slices .SortStableFunc (certInfo , func (a , b cloudprotocol.IssuedCertData ) int {
326
- if a .NodeID == client .nodeID && a .Type == iamCertType {
340
+ if client . isMainNode && a .NodeID == client .nodeID && a .Type == iamCertType {
327
341
return 1
328
342
}
329
343
330
- if b .NodeID == client .nodeID && b .Type == iamCertType {
344
+ if client .isMainNode && b .NodeID == client .nodeID && b .Type == iamCertType {
345
+ return - 1
346
+ }
347
+
348
+ if client .isMainNode && a .NodeID == client .nodeID {
349
+ return 1
350
+ }
351
+
352
+ if client .isMainNode && b .NodeID == client .nodeID {
331
353
return - 1
332
354
}
333
355
@@ -497,7 +519,7 @@ func (client *Client) Deprovision(nodeID, password string) (err error) {
497
519
}
498
520
}()
499
521
500
- if nodeID == client .GetNodeID () {
522
+ if client . isMainNode && nodeID == client .nodeID {
501
523
err = aoserrors .New ("Can't deprovision main node" )
502
524
errorInfo = & cloudprotocol.ErrorInfo {
503
525
Message : err .Error (),
@@ -681,10 +703,6 @@ func (client *Client) GetCurrentNodeInfo() (cloudprotocol.NodeInfo, error) {
681
703
ctx , cancel := context .WithTimeout (context .Background (), iamRequestTimeout )
682
704
defer cancel ()
683
705
684
- if client .currentNodeInfo != nil {
685
- return * client .currentNodeInfo , nil
686
- }
687
-
688
706
response , err := client .publicService .GetNodeInfo (ctx , & empty.Empty {})
689
707
if err != nil {
690
708
return cloudprotocol.NodeInfo {}, aoserrors .Wrap (err )
@@ -693,12 +711,9 @@ func (client *Client) GetCurrentNodeInfo() (cloudprotocol.NodeInfo, error) {
693
711
log .WithFields (log.Fields {
694
712
"nodeID" : response .GetNodeId (),
695
713
"nodeType" : response .GetNodeType (),
696
- }).Debug ("Get node Info" )
697
-
698
- nodeInfo := pbconvert .NodeInfoFromPB (response )
699
- client .currentNodeInfo = & nodeInfo
714
+ }).Debug ("Get current node Info" )
700
715
701
- return * client . currentNodeInfo , nil
716
+ return pbconvert . NodeInfoFromPB ( response ) , nil
702
717
}
703
718
704
719
// GetUnitSubjects returns unit subjects.
@@ -840,26 +855,6 @@ func (client *Client) openGRPCConnection() (err error) {
840
855
client .publicNodesService = pb .NewIAMPublicNodesServiceClient (client .publicConnection )
841
856
client .publicPermissionsService = pb .NewIAMPublicPermissionsServiceClient (client .publicConnection )
842
857
843
- var nodeInfo cloudprotocol.NodeInfo
844
-
845
- if nodeInfo , err = client .GetCurrentNodeInfo (); err != nil {
846
- return aoserrors .Wrap (err )
847
- }
848
-
849
- if nodeInfo .IsMainNode () {
850
- if err = client .subscribeNodeInfoChange (); err != nil {
851
- log .Error ("Failed subscribe on NodeInfo change" )
852
-
853
- return aoserrors .Wrap (err )
854
- }
855
-
856
- if err = client .subscribeUnitSubjectsChange (); err != nil {
857
- log .Error ("Failed subscribe on UnitSubject change" )
858
-
859
- return aoserrors .Wrap (err )
860
- }
861
- }
862
-
863
858
if err = client .restoreCertInfoSubs (); err != nil {
864
859
log .Error ("Failed subscribe on CertInfo change" )
865
860
@@ -881,6 +876,8 @@ func (client *Client) openGRPCConnection() (err error) {
881
876
client .nodesService = pb .NewIAMNodesServiceClient (client .protectedConnection )
882
877
client .permissionsService = pb .NewIAMPermissionsServiceClient (client .protectedConnection )
883
878
879
+ log .Debug ("Connected to IAM" )
880
+
884
881
return nil
885
882
}
886
883
0 commit comments