@@ -145,6 +145,12 @@ func NewPlaceholderHandler(k8sClient kubernetes.Interface, routingTable routing.
145145
146146// injectPlaceholderScript injects the placeholder refresh script into a template
147147func injectPlaceholderScript (templateContent string ) string {
148+ // Check if the placeholder script is already present
149+ if strings .Contains (templateContent , placeholderScript ) {
150+ // Return the original content if the script is already present
151+ return templateContent
152+ }
153+
148154 lowerContent := strings .ToLower (templateContent )
149155
150156 // Look for </body> tag (case-insensitive)
@@ -247,13 +253,13 @@ func (h *PlaceholderHandler) getTemplate(ctx context.Context, hso *v1alpha1.HTTP
247253 }
248254 h .cacheMutex .RUnlock ()
249255
256+ h .cacheMutex .Lock ()
250257 injectedContent := injectPlaceholderScript (config .Content )
251258 tmpl , err := template .New ("inline" ).Parse (injectedContent )
252259 if err != nil {
260+ h .cacheMutex .Unlock ()
253261 return nil , err
254262 }
255-
256- h .cacheMutex .Lock ()
257263 h .templateCache [cacheKey ] = & cacheEntry {
258264 template : tmpl ,
259265 hsoGeneration : hso .Generation ,
@@ -278,23 +284,24 @@ func (h *PlaceholderHandler) getTemplate(ctx context.Context, hso *v1alpha1.HTTP
278284 }
279285 h .cacheMutex .RUnlock ()
280286
287+ h .cacheMutex .Lock ()
281288 key := config .ContentConfigMapKey
282289 if key == "" {
283290 key = "template.html"
284291 }
285292
286293 content , ok := cm .Data [key ]
287294 if ! ok {
295+ h .cacheMutex .Unlock ()
288296 return nil , fmt .Errorf ("key %s not found in ConfigMap %s" , key , config .ContentConfigMap )
289297 }
290298
291299 injectedContent := injectPlaceholderScript (content )
292300 tmpl , err := template .New ("configmap" ).Parse (injectedContent )
293301 if err != nil {
302+ h .cacheMutex .Unlock ()
294303 return nil , err
295304 }
296-
297- h .cacheMutex .Lock ()
298305 h .templateCache [cacheKey ] = & cacheEntry {
299306 template : tmpl ,
300307 hsoGeneration : hso .Generation ,
0 commit comments