@@ -202,6 +202,51 @@ func ensureContainerPort(modified *bool, existing *corev1.ContainerPort, require
202
202
}
203
203
}
204
204
205
+ func EnsureServicePorts (modified * bool , existing * []corev1.ServicePort , required []corev1.ServicePort ) {
206
+ for i , existingServicePort := range * existing {
207
+ var existingCurr * corev1.ServicePort
208
+ for _ , requiredServicePort := range required {
209
+ if existingServicePort .Name == requiredServicePort .Name {
210
+ existingCurr = & (* existing )[i ]
211
+ ensureServicePort (modified , existingCurr , requiredServicePort )
212
+ break
213
+ }
214
+ }
215
+ if existingCurr == nil {
216
+ * modified = true
217
+ * existing = append ((* existing )[:i ], (* existing )[i + 1 :]... )
218
+ }
219
+ }
220
+
221
+ for _ , requiredServicePort := range required {
222
+ match := false
223
+ for _ , existingServicePort := range * existing {
224
+ if existingServicePort .Name == requiredServicePort .Name {
225
+ match = true
226
+ break
227
+ }
228
+ }
229
+ if ! match {
230
+ * modified = true
231
+ * existing = append (* existing , requiredServicePort )
232
+ }
233
+ }
234
+ }
235
+
236
+ func ensureServicePort (modified * bool , existing * corev1.ServicePort , required corev1.ServicePort ) {
237
+ ensureServicePortDefaults (& required )
238
+ if ! equality .Semantic .DeepEqual (required , * existing ) {
239
+ * modified = true
240
+ * existing = required
241
+ }
242
+ }
243
+
244
+ func ensureServicePortDefaults (servicePort * corev1.ServicePort ) {
245
+ if servicePort .Protocol == "" {
246
+ servicePort .Protocol = corev1 .ProtocolTCP
247
+ }
248
+ }
249
+
205
250
func ensureVolumeMount (modified * bool , existing * corev1.VolumeMount , required corev1.VolumeMount ) {
206
251
if ! equality .Semantic .DeepEqual (required , * existing ) {
207
252
* modified = true
0 commit comments