Skip to content

Commit 86734c1

Browse files
committed
Remove unnecessary function, use file lock
1 parent ac38be6 commit 86734c1

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

internal/controller/nginx/agent/command.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -521,25 +521,20 @@ func (cs *commandService) getPodOwner(podName string) (types.NamespacedName, *v1
521521
return types.NamespacedName{Namespace: pod.Namespace, Name: replicaOwnerRefs[0].Name}, pod, nil
522522
}
523523

524-
// findContainerImage returns the image of the first container with the given name.
525-
// Returns empty string if container is not found.
526-
func findContainerImage(containers []v1.Container, containerName string) string {
527-
for _, container := range containers {
528-
if container.Name == containerName {
529-
return container.Image
530-
}
531-
}
532-
return ""
533-
}
534-
535524
// validatePodImageVersion checks if the pod's nginx container image version matches the expected version
536525
// from its deployment. Returns an error if versions don't match.
537526
func (cs *commandService) validatePodImageVersion(
538527
pod *v1.Pod,
539528
expectedImage string,
540529
) error {
541-
// Find the nginx container in the pod
542-
podNginxImage := findContainerImage(pod.Spec.Containers, "nginx")
530+
var podNginxImage string
531+
532+
for _, container := range pod.Spec.Containers {
533+
if container.Name == "nginx" {
534+
podNginxImage = container.Image
535+
break
536+
}
537+
}
543538
if podNginxImage == "" {
544539
return fmt.Errorf("nginx container not found in pod %q", pod.Name)
545540
}

internal/controller/nginx/agent/deployment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ func (d *Deployment) GetBroadcaster() broadcast.Broadcaster {
7777

7878
// SetImageVersion sets the deployment's image version.
7979
func (d *Deployment) SetImageVersion(imageVersion string) {
80-
d.errLock.Lock()
81-
defer d.errLock.Unlock()
80+
d.FileLock.Lock()
81+
defer d.FileLock.Unlock()
8282

8383
d.imageVersion = imageVersion
8484
}

0 commit comments

Comments
 (0)