Skip to content

Commit 76b32ef

Browse files
authored
Merge branch 'main' into chore/remove_v1alpha1_of_observability_api
2 parents 81b7e7a + 96032ac commit 76b32ef

File tree

10 files changed

+209
-95
lines changed

10 files changed

+209
-95
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
driver-opts: network=host
6565

6666
- name: Setup QEMU
67-
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
67+
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
6868
with:
6969
platforms: arm64
7070

@@ -119,7 +119,7 @@ jobs:
119119

120120
- name: Docker meta
121121
id: meta
122-
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
122+
uses: docker/metadata-action@318604b99e75e41977312d83839a89be02ca4893 # v5.9.0
123123
with:
124124
context: ${{ inputs.tag != '' && 'git' || 'workflow' }}
125125
images: |

.github/workflows/conformance.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878

7979
- name: NGF Docker meta
8080
id: ngf-meta
81-
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
81+
uses: docker/metadata-action@318604b99e75e41977312d83839a89be02ca4893 # v5.9.0
8282
with:
8383
images: |
8484
name=ghcr.io/nginx/nginx-gateway-fabric
@@ -92,7 +92,7 @@ jobs:
9292
9393
- name: NGINX Docker meta
9494
id: nginx-meta
95-
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
95+
uses: docker/metadata-action@318604b99e75e41977312d83839a89be02ca4893 # v5.9.0
9696
with:
9797
images: |
9898
name=ghcr.io/nginx/nginx-gateway-fabric/${{ inputs.image == 'plus' && 'nginx-plus' || inputs.image }}

.github/workflows/functional.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060

6161
- name: NGF Docker meta
6262
id: ngf-meta
63-
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
63+
uses: docker/metadata-action@318604b99e75e41977312d83839a89be02ca4893 # v5.9.0
6464
with:
6565
images: |
6666
name=ghcr.io/nginx/nginx-gateway-fabric
@@ -73,7 +73,7 @@ jobs:
7373
7474
- name: NGINX Docker meta
7575
id: nginx-meta
76-
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
76+
uses: docker/metadata-action@318604b99e75e41977312d83839a89be02ca4893 # v5.9.0
7777
with:
7878
images: |
7979
name=ghcr.io/nginx/nginx-gateway-fabric/${{ inputs.image == 'plus' && 'nginx-plus' || inputs.image }}

.github/workflows/helm.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939

4040
- name: NGF Docker meta
4141
id: ngf-meta
42-
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
42+
uses: docker/metadata-action@318604b99e75e41977312d83839a89be02ca4893 # v5.9.0
4343
with:
4444
images: |
4545
name=ghcr.io/nginx/nginx-gateway-fabric
@@ -52,7 +52,7 @@ jobs:
5252
5353
- name: NGINX Docker meta
5454
id: nginx-meta
55-
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
55+
uses: docker/metadata-action@318604b99e75e41977312d83839a89be02ca4893 # v5.9.0
5656
with:
5757
images: |
5858
name=ghcr.io/nginx/nginx-gateway-fabric/${{ inputs.image == 'plus' && 'nginx-plus' || inputs.image }}
@@ -119,7 +119,7 @@ jobs:
119119
check-latest: true
120120

121121
- name: Set up chart-testing
122-
uses: helm/chart-testing-action@0d28d3144d3a25ea2cc349d6e59901c4ff469b3b # v2.7.0
122+
uses: helm/chart-testing-action@6ec842c01de15ebb84c8627d2744a0c2f2755c9f # v2.8.0
123123

124124
- name: Install Chart
125125
run: |
@@ -172,7 +172,7 @@ jobs:
172172
check-latest: true
173173

174174
- name: Set up chart-testing
175-
uses: helm/chart-testing-action@0d28d3144d3a25ea2cc349d6e59901c4ff469b3b # v2.7.0
175+
uses: helm/chart-testing-action@6ec842c01de15ebb84c8627d2744a0c2f2755c9f # v2.8.0
176176

177177
- name: Install Chart
178178
run: |

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
check-latest: true
123123

124124
- name: Set up chart-testing
125-
uses: helm/chart-testing-action@0d28d3144d3a25ea2cc349d6e59901c4ff469b3b # v2.7.0
125+
uses: helm/chart-testing-action@6ec842c01de15ebb84c8627d2744a0c2f2755c9f # v2.8.0
126126
with:
127127
version: 3.14.0 # renovate: datasource=github-tags depName=helm/chart-testing
128128
# v6.0.0 resolved the compatibility issue with Python > 3.13. may be removed after the action itself is updated

build/ubi/Dockerfile.nginx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ADD --link --chown=101:1001 https://nginx.org/keys/nginx_signing.key nginx_signi
66
ADD --link --chown=101:1001 build/ubi/repos/nginx.repo nginx.repo
77
ADD --link --chown=101:1001 build/ubi/repos/agent.repo agent.repo
88

9-
FROM ghcr.io/nginx/dependencies/nginx-ubi:ubi9@sha256:7ec723b1189ae6f1b9f25451800dbd6d5c046a0b7b020b4f2bcc90e83a640d4b AS ubi9-packages
9+
FROM ghcr.io/nginx/dependencies/nginx-ubi:ubi9@sha256:68964f6fa5ddd8e736139e9301cebb59e4c44fc1c4df71cb308599352bdc17da AS ubi9-packages
1010

1111
FROM redhat/ubi9-minimal:9.6 AS ubi-nginx
1212

build/ubi/Dockerfile.nginxplus

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ADD --link --chown=101:1001 https://cs.nginx.com/static/files/plus-9.repo nginx-
66
ADD --link --chown=101:1001 https://nginx.org/keys/nginx_signing.key nginx_signing.key
77
ADD --link --chown=101:1001 build/ubi/repos/agent.repo agent.repo
88

9-
FROM ghcr.io/nginx/dependencies/nginx-ubi:ubi9@sha256:7ec723b1189ae6f1b9f25451800dbd6d5c046a0b7b020b4f2bcc90e83a640d4b AS ubi9-packages
9+
FROM ghcr.io/nginx/dependencies/nginx-ubi:ubi9@sha256:68964f6fa5ddd8e736139e9301cebb59e4c44fc1c4df71cb308599352bdc17da AS ubi9-packages
1010

1111
FROM redhat/ubi9-minimal:9.6 AS ubi-nginx-plus
1212

internal/controller/provisioner/objects.go

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -686,33 +686,69 @@ func (p *NginxProvisioner) buildNginxDeployment(
686686
}
687687
}
688688

689-
var replicas *int32
690-
if deploymentCfg.Replicas != nil {
691-
replicas = deploymentCfg.Replicas
692-
}
693-
694-
if isAutoscalingEnabled(&deploymentCfg) {
695-
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
696-
defer cancel()
697-
698-
hpa := &autoscalingv2.HorizontalPodAutoscaler{}
699-
err := p.k8sClient.Get(ctx, types.NamespacedName{
700-
Namespace: objectMeta.Namespace,
701-
Name: objectMeta.Name,
702-
}, hpa)
703-
if err == nil && hpa.Status.DesiredReplicas > 0 {
704-
// overwrite with HPA's desiredReplicas
705-
replicas = helpers.GetPointer(hpa.Status.DesiredReplicas)
706-
}
707-
}
708-
689+
// Determine replica count based on HPA status
690+
replicas := p.determineReplicas(objectMeta, deploymentCfg)
709691
if replicas != nil {
710692
deployment.Spec.Replicas = replicas
711693
}
712694

713695
return deployment, nil
714696
}
715697

698+
// determineReplicas determines the appropriate replica count for a deployment based on HPA status.
699+
//
700+
// HPA Replicas Management Strategy:
701+
//
702+
// When an HPA is managing a deployment, we must read the current deployment's replicas
703+
// from the cluster and use that value, rather than trying to set our own value or read
704+
// from HPA.Status.DesiredReplicas (which is eventually consistent and stale).
705+
//
706+
// Why we can't use HPA.Status.DesiredReplicas:
707+
// - HPA.Status updates lag behind Deployment.Spec.Replicas changes
708+
// - When HPA scales down: HPA writes Deployment.Spec → then updates its own Status
709+
// - If we read Status during this window, we get the OLD value and overwrite HPA's new value
710+
// - This creates a race condition causing pod churn
711+
//
712+
// Our approach:
713+
// - When HPA exists: Read current deployment replicas from cluster and use that
714+
// - When HPA doesn't exist yet: Set replicas for initial deployment creation
715+
// - When HPA exists but Deployment doesn't exist yet: Set replicas for initial deployment creation
716+
// - When HPA is disabled: Set replicas normally.
717+
func (p *NginxProvisioner) determineReplicas(
718+
objectMeta metav1.ObjectMeta,
719+
deploymentCfg ngfAPIv1alpha2.DeploymentSpec,
720+
) *int32 {
721+
replicas := deploymentCfg.Replicas
722+
723+
if !isAutoscalingEnabled(&deploymentCfg) {
724+
return replicas
725+
}
726+
727+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
728+
defer cancel()
729+
730+
hpa := &autoscalingv2.HorizontalPodAutoscaler{}
731+
err := p.k8sClient.Get(ctx, types.NamespacedName{
732+
Namespace: objectMeta.Namespace,
733+
Name: objectMeta.Name,
734+
}, hpa)
735+
if err != nil {
736+
return replicas
737+
}
738+
739+
existingDeployment := &appsv1.Deployment{}
740+
err = p.k8sClient.Get(ctx, types.NamespacedName{
741+
Namespace: objectMeta.Namespace,
742+
Name: objectMeta.Name,
743+
}, existingDeployment)
744+
745+
if err == nil && existingDeployment.Spec.Replicas != nil {
746+
replicas = existingDeployment.Spec.Replicas
747+
}
748+
749+
return replicas
750+
}
751+
716752
// applyPatches applies the provided patches to the given object.
717753
func applyPatches(obj client.Object, patches []ngfAPIv1alpha2.Patch) error {
718754
if len(patches) == 0 {

0 commit comments

Comments
 (0)