@@ -13,94 +13,85 @@ package initialization
13
13
import (
14
14
"context"
15
15
"github.com/pkg/errors"
16
+ "github.com/spiffe/go-spiffe/v2/workloadapi"
16
17
"time"
17
18
18
19
"github.com/vmware-tanzu/secrets-manager/app/sentinel/internal/safe"
19
20
"github.com/vmware-tanzu/secrets-manager/core/backoff"
20
- "github.com/vmware-tanzu/secrets-manager/core/env"
21
21
log "github.com/vmware-tanzu/secrets-manager/core/log/std"
22
22
"github.com/vmware-tanzu/secrets-manager/core/spiffe"
23
23
)
24
24
25
25
func ensureApiConnectivity (ctx context.Context , cid * string ) {
26
- terminateAsap := env .TerminateSentinelOnInitCommandConnectivityFailure ()
27
-
28
26
log .TraceLn (cid , "Before checking api connectivity" )
29
27
30
- for {
31
- s := backoffStrategy ()
32
-
33
- err := backoff .Retry ("RunInitCommands:CheckConnectivity" , func () error {
34
- log .TraceLn (cid , "RunInitCommands:CheckConnectivity: checking connectivity to safe" )
28
+ s := backoffStrategy ()
29
+ err := backoff .Retry ("RunInitCommands:CheckConnectivity" , func () error {
30
+ log .TraceLn (cid , "RunInitCommands:CheckConnectivity: checking connectivity to safe" )
35
31
36
- src , acquired := spiffe .AcquireSourceForSentinel (ctx )
37
- if ! acquired {
38
- log .TraceLn (cid , "RunInitCommands:CheckConnectivity: failed to acquire source." )
39
- if terminateAsap {
40
- panic ("RunInitCommands:CheckConnectivity: failed to acquire source" )
41
- }
32
+ src , acquired := spiffe .AcquireSourceForSentinel (ctx )
33
+ if ! acquired {
34
+ log .TraceLn (cid , "RunInitCommands:CheckConnectivity: failed to acquire source." )
42
35
43
- return errors .New ("RunInitCommands:CheckConnectivity: failed to acquire source" )
44
- }
36
+ return errors .New ("RunInitCommands:CheckConnectivity: failed to acquire source" )
37
+ }
45
38
46
- log .TraceLn (cid , "RunInitCommands:CheckConnectivity: acquired source successfully" )
39
+ log .TraceLn (cid , "RunInitCommands:CheckConnectivity: acquired source successfully" )
47
40
48
- if err := safe .Check (ctx , src ); err != nil {
49
- log .TraceLn (cid , "RunInitCommands:CheckConnectivity: failed to verify connection to safe:" , err .Error ())
50
- if terminateAsap {
51
- panic ("RunInitCommands:CheckConnectivity: failed to verify connection to safe" )
52
- }
41
+ if err := safe .Check (ctx , src ); err != nil {
42
+ log .TraceLn (cid , "RunInitCommands:CheckConnectivity: failed to verify connection to safe:" , err .Error ())
53
43
54
- return errors .Wrap (err , "RunInitCommands:CheckConnectivity: cannot establish connection to safe 001" )
55
- }
44
+ return errors .Wrap (err , "RunInitCommands:CheckConnectivity: cannot establish connection to safe 001" )
45
+ }
56
46
57
- log .TraceLn (cid , "RunInitCommands:CheckConnectivity: success" )
58
- return nil
59
- }, s )
47
+ log .TraceLn (cid , "RunInitCommands:CheckConnectivity: success" )
48
+ return nil
49
+ }, s )
60
50
61
- if err == nil {
62
- log .TraceLn (cid , "exiting backoffs" )
63
- break
64
- }
51
+ if err == nil {
52
+ log .TraceLn (cid , "exiting backoffs" )
53
+ return
65
54
}
55
+
56
+ // I shouldn't be here.
57
+ panic ("RunInitCommands:CheckConnectivity: failed to verify connection to safe" )
66
58
}
67
59
68
- func ensureSourceAcquisition (ctx context.Context , cid * string ) {
60
+ func ensureSourceAcquisition (ctx context.Context , cid * string ) * workloadapi. X509Source {
69
61
// If `true`, instead of retrying with a backoff, kill the pod, and let the
70
62
// deployment controller restart it to initiate a new retry.
71
- terminateAsap := env .TerminateSentinelOnInitCommandConnectivityFailure ()
72
63
73
- waitInterval := env .InitCommandRunnerWaitIntervalForSentinel ()
74
- time .Sleep (waitInterval )
64
+ log .TraceLn (cid , "RunInitCommands: acquiring source 001" )
75
65
76
- for {
77
- log .TraceLn (cid , "RunInitCommands: acquiring source 001" )
66
+ s := backoff.Strategy {
67
+ MaxRetries : 20 ,
68
+ Delay : 1000 ,
69
+ Exponential : true ,
70
+ MaxDuration : 30 * time .Second ,
71
+ }
78
72
79
- s := backoff.Strategy {
80
- MaxRetries : 20 ,
81
- Delay : 1000 ,
82
- Exponential : true ,
83
- MaxDuration : 30 * time .Second ,
84
- }
73
+ var src * workloadapi.X509Source
85
74
86
- err := backoff .Retry ("RunInitCommands:AcquireSource" , func () error {
87
- log .TraceLn (cid , "RunInitCommands:AcquireSource: acquireSourceForSentinel: 000" )
88
- _ , acquired := spiffe .AcquireSourceForSentinel (ctx )
89
- if ! acquired {
90
- log .TraceLn (cid , "RunInitCommands:AcquireSource: failed to acquire source." )
91
- if terminateAsap {
92
- panic ("RunInitCommands:AcquireSource: failed to acquire source" )
93
- }
75
+ err := backoff .Retry ("RunInitCommands:AcquireSource" , func () error {
76
+ log .TraceLn (cid , "RunInitCommands:AcquireSource: acquireSourceForSentinel: 000" )
94
77
95
- return errors . New ( "RunInitCommands:AcquireSource: failed to acquire source 000" )
96
- }
78
+ acq , acquired := spiffe . AcquireSourceForSentinel ( ctx )
79
+ src = acq
97
80
98
- return nil
99
- }, s )
81
+ if ! acquired {
82
+ log . TraceLn ( cid , "RunInitCommands:AcquireSource: failed to acquire source." )
100
83
101
- if err == nil {
102
- log .TraceLn (cid , "RunInitCommands:AcquireSource: got source. breaking." )
103
- break
84
+ return errors .New ("RunInitCommands:AcquireSource: failed to acquire source 000" )
104
85
}
86
+
87
+ return nil
88
+ }, s )
89
+
90
+ if err == nil {
91
+ log .TraceLn (cid , "RunInitCommands:AcquireSource: got source. breaking." )
92
+ return src
105
93
}
94
+
95
+ // I shouldn't be here.
96
+ panic ("RunInitCommands:AcquireSource: failed to acquire source" )
106
97
}
0 commit comments