@@ -56,7 +56,8 @@ type Deployment struct {
56
56
fileOverviews []* pb.File
57
57
files []File
58
58
59
- Lock sync.RWMutex
59
+ FileLock sync.RWMutex
60
+ errLock sync.RWMutex
60
61
}
61
62
62
63
// newDeployment returns a new Deployment object.
@@ -72,56 +73,94 @@ func (d *Deployment) GetBroadcaster() broadcast.Broadcaster {
72
73
return d .broadcaster
73
74
}
74
75
75
- // GetFileOverviews returns the current list of fileOverviews and configVersion for the deployment.
76
- func (d * Deployment ) GetFileOverviews () ([] * pb. File , string ) {
77
- d .Lock . RLock ()
78
- defer d .Lock . RUnlock ()
76
+ // SetLatestConfigError sets the latest config apply error for the deployment.
77
+ func (d * Deployment ) SetLatestConfigError ( err error ) {
78
+ d .errLock . Lock ()
79
+ defer d .errLock . Unlock ()
79
80
80
- return d . fileOverviews , d . configVersion
81
+ d . latestConfigError = err
81
82
}
82
83
83
- // GetNGINXPlusActions returns the current NGINX Plus API Actions for the deployment.
84
- func (d * Deployment ) GetNGINXPlusActions () [] * pb. NGINXPlusAction {
85
- d .Lock . RLock ()
86
- defer d .Lock . RUnlock ()
84
+ // SetLatestUpstreamError sets the latest upstream update error for the deployment.
85
+ func (d * Deployment ) SetLatestUpstreamError ( err error ) {
86
+ d .errLock . Lock ()
87
+ defer d .errLock . Unlock ()
87
88
88
- return d . nginxPlusActions
89
+ d . latestUpstreamError = err
89
90
}
90
91
91
92
// GetLatestConfigError gets the latest config apply error for the deployment.
92
93
func (d * Deployment ) GetLatestConfigError () error {
93
- d .Lock .RLock ()
94
- defer d .Lock .RUnlock ()
94
+ d .errLock .RLock ()
95
+ defer d .errLock .RUnlock ()
95
96
96
97
return d .latestConfigError
97
98
}
98
99
99
100
// GetLatestUpstreamError gets the latest upstream update error for the deployment.
100
101
func (d * Deployment ) GetLatestUpstreamError () error {
101
- d .Lock .RLock ()
102
- defer d .Lock .RUnlock ()
102
+ d .errLock .RLock ()
103
+ defer d .errLock .RUnlock ()
103
104
104
105
return d .latestUpstreamError
105
106
}
106
107
108
+ // SetPodErrorStatus sets the error status of a Pod in this Deployment if applying the config failed.
109
+ func (d * Deployment ) SetPodErrorStatus (pod string , err error ) {
110
+ d .errLock .Lock ()
111
+ defer d .errLock .Unlock ()
112
+
113
+ d .podStatuses [pod ] = err
114
+ }
115
+
107
116
// RemovePodStatus deletes a pod from the pod status map.
108
117
func (d * Deployment ) RemovePodStatus (podName string ) {
109
- d .Lock .Lock ()
110
- defer d .Lock .Unlock ()
118
+ d .errLock .Lock ()
119
+ defer d .errLock .Unlock ()
111
120
112
121
delete (d .podStatuses , podName )
113
122
}
114
123
124
+ // GetConfigurationStatus returns the current config status for this Deployment. It combines
125
+ // the most recent errors (if they exist) for all Pods in the Deployment into a single error.
126
+ func (d * Deployment ) GetConfigurationStatus () error {
127
+ d .errLock .RLock ()
128
+ defer d .errLock .RUnlock ()
129
+
130
+ errs := make ([]error , 0 , len (d .podStatuses ))
131
+ for _ , err := range d .podStatuses {
132
+ errs = append (errs , err )
133
+ }
134
+
135
+ if len (errs ) == 1 {
136
+ return errs [0 ]
137
+ }
138
+
139
+ return errors .Join (errs ... )
140
+ }
141
+
115
142
/*
116
143
The following functions for the Deployment object are UNLOCKED, meaning that they are unsafe.
117
- Callers of these functions MUST ensure the lock is set before calling.
144
+ Callers of these functions MUST ensure the FileLock is set before calling.
118
145
119
146
These functions are called as part of the ConfigApply or APIRequest processes. These entire processes
120
147
are locked by the caller, hence why the functions themselves do not set the locks.
121
148
*/
122
149
150
+ // GetFileOverviews returns the current list of fileOverviews and configVersion for the deployment.
151
+ // The deployment FileLock MUST already be locked before calling this function.
152
+ func (d * Deployment ) GetFileOverviews () ([]* pb.File , string ) {
153
+ return d .fileOverviews , d .configVersion
154
+ }
155
+
156
+ // GetNGINXPlusActions returns the current NGINX Plus API Actions for the deployment.
157
+ // The deployment FileLock MUST already be locked before calling this function.
158
+ func (d * Deployment ) GetNGINXPlusActions () []* pb.NGINXPlusAction {
159
+ return d .nginxPlusActions
160
+ }
161
+
123
162
// GetFile gets the requested file for the deployment and returns its contents.
124
- // The deployment MUST already be locked before calling this function.
163
+ // The deployment FileLock MUST already be locked before calling this function.
125
164
func (d * Deployment ) GetFile (name , hash string ) []byte {
126
165
for _ , file := range d .files {
127
166
if name == file .Meta .GetName () && hash == file .Meta .GetHash () {
@@ -133,7 +172,7 @@ func (d *Deployment) GetFile(name, hash string) []byte {
133
172
}
134
173
135
174
// SetFiles updates the nginx files and fileOverviews for the deployment and returns the message to send.
136
- // The deployment MUST already be locked before calling this function.
175
+ // The deployment FileLock MUST already be locked before calling this function.
137
176
func (d * Deployment ) SetFiles (files []File ) broadcast.NginxAgentMessage {
138
177
d .files = files
139
178
@@ -167,45 +206,11 @@ func (d *Deployment) SetFiles(files []File) broadcast.NginxAgentMessage {
167
206
168
207
// SetNGINXPlusActions updates the deployment's latest NGINX Plus Actions to perform if using NGINX Plus.
169
208
// Used by a Subscriber when it first connects.
170
- // The deployment MUST already be locked before calling this function.
209
+ // The deployment FileLock MUST already be locked before calling this function.
171
210
func (d * Deployment ) SetNGINXPlusActions (actions []* pb.NGINXPlusAction ) {
172
211
d .nginxPlusActions = actions
173
212
}
174
213
175
- // SetPodErrorStatus sets the error status of a Pod in this Deployment if applying the config failed.
176
- // The deployment MUST already be locked before calling this function.
177
- func (d * Deployment ) SetPodErrorStatus (pod string , err error ) {
178
- d .podStatuses [pod ] = err
179
- }
180
-
181
- // SetLatestConfigError sets the latest config apply error for the deployment.
182
- // The deployment MUST already be locked before calling this function.
183
- func (d * Deployment ) SetLatestConfigError (err error ) {
184
- d .latestConfigError = err
185
- }
186
-
187
- // SetLatestUpstreamError sets the latest upstream update error for the deployment.
188
- // The deployment MUST already be locked before calling this function.
189
- func (d * Deployment ) SetLatestUpstreamError (err error ) {
190
- d .latestUpstreamError = err
191
- }
192
-
193
- // GetConfigurationStatus returns the current config status for this Deployment. It combines
194
- // the most recent errors (if they exist) for all Pods in the Deployment into a single error.
195
- // The deployment MUST already be locked before calling this function.
196
- func (d * Deployment ) GetConfigurationStatus () error {
197
- errs := make ([]error , 0 , len (d .podStatuses ))
198
- for _ , err := range d .podStatuses {
199
- errs = append (errs , err )
200
- }
201
-
202
- if len (errs ) == 1 {
203
- return errs [0 ]
204
- }
205
-
206
- return errors .Join (errs ... )
207
- }
208
-
209
214
//counterfeiter:generate . DeploymentStorer
210
215
211
216
// DeploymentStorer is an interface to store Deployments.
0 commit comments