Repository: open-telemetry/opentelemetry-operator

Issue:
The `StatusReplicas` field is not being set for the `DaemonSet`
### Component(s)

collector

### What happened?

## Description

[It has been documented](https://github.com/open-telemetry/opentelemetry-operator/blob/02e42e5db45616e982343a87cc6519df1c21578c/apis/v1beta1/opentelemetrycollector_types.go#L300) that the `StatusReplicas` field is set for `Deployment, DaemonSet and the StatefulSet`. However, setting this status is missing for the `DaemonSet` [here](https://github.com/open-telemetry/opentelemetry-operator/blob/02e42e5db45616e982343a87cc6519df1c21578c/internal/status/collector/collector.go#L78).

## Steps to Reproduce

1. Deploy the opentelemetry-operator.
2. Install the DaemonSet
3. You can see that the field `statusReplicas` is missing.

## Expected Result

The `statusReplicas` should be set.

## Actual Result

The `statusReplicas` is empty.


### Kubernetes Version

1.32.2

### Operator version

v0.124.0

### Collector version

v0.124.1

### Environment information

## Environment
OS: Ubuntu 24.0
Compiler(if manually compiled): go1.24.1


### Log output

```shell

```

### Additional context

_No response_

Discussion:

Solution patch:
diff --git a/.chloggen/nikola-jokic_fix-status-replicas.yaml b/.chloggen/nikola-jokic_fix-status-replicas.yaml
new file mode 100755
index 00000000..f079a2a6
--- /dev/null
+++ b/.chloggen/nikola-jokic_fix-status-replicas.yaml
@@ -0,0 +1,16 @@
+# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
+change_type: bug_fix
+
+# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
+component: collector
+
+# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
+note: "Set the `statusReplicas` field for the `DaemonSet`"
+
+# One or more tracking issues related to the change
+issues: [3930]
+
+# (Optional) One or more lines of additional information to render under the primary note.
+# These lines will be padded with 2 spaces and then inserted directly into the document.
+# Use pipe (|) for multiline entries.
+subtext:
diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml
index 7fcd7cc5..64a2c01c 100644
--- a/.github/workflows/continuous-integration.yaml
+++ b/.github/workflows/continuous-integration.yaml
@@ -82,15 +82,15 @@ jobs:
         go-version: "~1.24.2"
 
     - name: Initialize CodeQL
-      uses: github/codeql-action/init@45775bd8235c68ba998cffa5171334d58593da47 # v3.28.15
+      uses: github/codeql-action/init@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
       with:
         languages: go
 
     - name: Autobuild
-      uses: github/codeql-action/autobuild@45775bd8235c68ba998cffa5171334d58593da47 # v3.28.15
+      uses: github/codeql-action/autobuild@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
 
     - name: Perform CodeQL Analysis
-      uses: github/codeql-action/analyze@45775bd8235c68ba998cffa5171334d58593da47 # v3.28.15
+      uses: github/codeql-action/analyze@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
 
     - name: Govulncheck
       uses: golang/govulncheck-action@b625fbe08f3bccbe446d94fbf87fcc875a4f50ee # v1.0.4
diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml
index d90896dc..4d6e2785 100644
--- a/.github/workflows/e2e.yaml
+++ b/.github/workflows/e2e.yaml
@@ -112,7 +112,7 @@ jobs:
       run: make install-tools
 
     - name: Download test image archive
-      uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
+      uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
       with:
         name: Test image archive
 
diff --git a/.github/workflows/ossf-scorecard.yml b/.github/workflows/ossf-scorecard.yml
index 6a9f19aa..45677ee4 100644
--- a/.github/workflows/ossf-scorecard.yml
+++ b/.github/workflows/ossf-scorecard.yml
@@ -42,6 +42,6 @@ jobs:
       # Upload the results to GitHub's code scanning dashboard (optional).
       # Commenting out will disable upload of results to your repo's Code Scanning dashboard
       - name: "Upload to code-scanning"
-        uses: github/codeql-action/upload-sarif@45775bd8235c68ba998cffa5171334d58593da47 # v3.28.15
+        uses: github/codeql-action/upload-sarif@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
         with:
           sarif_file: results.sarif
diff --git a/.github/workflows/publish-autoinstrumentation-apache-httpd.yaml b/.github/workflows/publish-autoinstrumentation-apache-httpd.yaml
index e55ba115..bbdd48a3 100644
--- a/.github/workflows/publish-autoinstrumentation-apache-httpd.yaml
+++ b/.github/workflows/publish-autoinstrumentation-apache-httpd.yaml
@@ -63,7 +63,7 @@ jobs:
           password: ${{ secrets.GITHUB_TOKEN }}
 
       - name: Build and push
-        uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0
+        uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
         with:
           context: autoinstrumentation/apache-httpd
           platforms: linux/amd64
diff --git a/.github/workflows/publish-autoinstrumentation-dotnet.yaml b/.github/workflows/publish-autoinstrumentation-dotnet.yaml
index 375696d7..87974bd5 100644
--- a/.github/workflows/publish-autoinstrumentation-dotnet.yaml
+++ b/.github/workflows/publish-autoinstrumentation-dotnet.yaml
@@ -73,7 +73,7 @@ jobs:
           password: ${{ secrets.GITHUB_TOKEN }}
 
       - name: Build and push
-        uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0
+        uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
         with:
           context: autoinstrumentation/dotnet
           platforms: linux/amd64,linux/arm64
diff --git a/.github/workflows/publish-autoinstrumentation-java.yaml b/.github/workflows/publish-autoinstrumentation-java.yaml
index 6e2351e2..de8ea5fd 100644
--- a/.github/workflows/publish-autoinstrumentation-java.yaml
+++ b/.github/workflows/publish-autoinstrumentation-java.yaml
@@ -74,7 +74,7 @@ jobs:
           password: ${{ secrets.GITHUB_TOKEN }}
 
       - name: Build and push
-        uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0
+        uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
         with:
           context: autoinstrumentation/java
           platforms: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le
diff --git a/.github/workflows/publish-autoinstrumentation-nodejs.yaml b/.github/workflows/publish-autoinstrumentation-nodejs.yaml
index 43dc737a..f884df5a 100644
--- a/.github/workflows/publish-autoinstrumentation-nodejs.yaml
+++ b/.github/workflows/publish-autoinstrumentation-nodejs.yaml
@@ -73,7 +73,7 @@ jobs:
           password: ${{ secrets.GITHUB_TOKEN }}
 
       - name: Build and push
-        uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0
+        uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
         with:
           context: autoinstrumentation/nodejs
           platforms: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le
diff --git a/.github/workflows/publish-autoinstrumentation-php.yaml b/.github/workflows/publish-autoinstrumentation-php.yaml
index 9ce8e33c..404129cf 100644
--- a/.github/workflows/publish-autoinstrumentation-php.yaml
+++ b/.github/workflows/publish-autoinstrumentation-php.yaml
@@ -73,7 +73,7 @@ jobs:
         run: pushd ./autoinstrumentation/php ; ./prepare_files_for_docker_image.sh --ext-ver ${{ env.VERSION }} --dest-dir ${PWD}/files_for_docker_image ; popd
 
       - name: Build and push
-        uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0
+        uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
         with:
           context: autoinstrumentation/php
           push: ${{ github.event_name == 'push' }}
diff --git a/.github/workflows/publish-autoinstrumentation-python.yaml b/.github/workflows/publish-autoinstrumentation-python.yaml
index 91e2a298..072a9232 100644
--- a/.github/workflows/publish-autoinstrumentation-python.yaml
+++ b/.github/workflows/publish-autoinstrumentation-python.yaml
@@ -73,7 +73,7 @@ jobs:
           password: ${{ secrets.GITHUB_TOKEN }}
 
       - name: Build and push
-        uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0
+        uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
         with:
           context: autoinstrumentation/python
           platforms: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le
diff --git a/.github/workflows/publish-images.yaml b/.github/workflows/publish-images.yaml
index 9cfe647b..85a47dc0 100644
--- a/.github/workflows/publish-images.yaml
+++ b/.github/workflows/publish-images.yaml
@@ -99,7 +99,7 @@ jobs:
           password: ${{ secrets.GITHUB_TOKEN }}
 
       - name: Build and push Operator image
-        uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0
+        uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
         with:
           context: .
           file: ./Dockerfile
diff --git a/.github/workflows/publish-must-gather.yaml b/.github/workflows/publish-must-gather.yaml
index 7e77ba29..3c08dbd0 100644
--- a/.github/workflows/publish-must-gather.yaml
+++ b/.github/workflows/publish-must-gather.yaml
@@ -80,7 +80,7 @@ jobs:
           password: ${{ secrets.GITHUB_TOKEN }}
 
       - name: Build and push must-gather image
-        uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0
+        uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
         with:
           context: .
           file: ./cmd/gather/Dockerfile
diff --git a/.github/workflows/publish-operator-bundle.yaml b/.github/workflows/publish-operator-bundle.yaml
index c751e4ee..24a8ab1c 100644
--- a/.github/workflows/publish-operator-bundle.yaml
+++ b/.github/workflows/publish-operator-bundle.yaml
@@ -67,7 +67,7 @@ jobs:
           password: ${{ secrets.GITHUB_TOKEN }}
 
       - name: Build and push Operator image
-        uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0
+        uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
         with:
           context: ./bundle/community/
           file: ./bundle/community/bundle.Dockerfile
diff --git a/.github/workflows/publish-operator-opamp-bridge.yaml b/.github/workflows/publish-operator-opamp-bridge.yaml
index 9fc6c6de..c61f1a1f 100644
--- a/.github/workflows/publish-operator-opamp-bridge.yaml
+++ b/.github/workflows/publish-operator-opamp-bridge.yaml
@@ -88,7 +88,7 @@ jobs:
           password: ${{ secrets.GITHUB_TOKEN }}
 
       - name: Build and push
-        uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0
+        uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
         with:
           context: cmd/operator-opamp-bridge
           platforms: ${{ env.PLATFORMS }}
diff --git a/.github/workflows/publish-target-allocator.yaml b/.github/workflows/publish-target-allocator.yaml
index d134349f..2cc1aea5 100644
--- a/.github/workflows/publish-target-allocator.yaml
+++ b/.github/workflows/publish-target-allocator.yaml
@@ -88,7 +88,7 @@ jobs:
           password: ${{ secrets.GITHUB_TOKEN }}
 
       - name: Build and push
-        uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0
+        uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
         with:
           context: cmd/otel-allocator
           platforms: ${{ env.PLATFORMS }}
diff --git a/.github/workflows/reusable-publish-test-e2e-images.yaml b/.github/workflows/reusable-publish-test-e2e-images.yaml
index 1ba90e8c..799dce4c 100644
--- a/.github/workflows/reusable-publish-test-e2e-images.yaml
+++ b/.github/workflows/reusable-publish-test-e2e-images.yaml
@@ -51,7 +51,7 @@ jobs:
           password: ${{ secrets.GITHUB_TOKEN }}
 
       - name: Build and push
-        uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0
+        uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
         with:
           tags: ${{ steps.meta.outputs.tags }}
           context: tests/test-e2e-apps/${{ inputs.path }}
diff --git a/go.mod b/go.mod
index 4f3de64d..e0e36b3a 100644
--- a/go.mod
+++ b/go.mod
@@ -23,7 +23,7 @@ require (
 	github.com/oklog/run v1.1.0
 	github.com/open-telemetry/opamp-go v0.15.0
 	github.com/openshift/api v0.0.0-20240124164020-e2ce40831f2e
-	github.com/operator-framework/api v0.30.0
+	github.com/operator-framework/api v0.31.0
 	github.com/operator-framework/operator-lib v0.17.0
 	github.com/prometheus-operator/prometheus-operator v0.80.1
 	github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.80.1
diff --git a/go.sum b/go.sum
index 6e4e44e2..37002e8b 100644
--- a/go.sum
+++ b/go.sum
@@ -413,8 +413,8 @@ github.com/openshift/api v0.0.0-20240124164020-e2ce40831f2e h1:cxgCNo/R769CO23AK
 github.com/openshift/api v0.0.0-20240124164020-e2ce40831f2e/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
 github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
 github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
-github.com/operator-framework/api v0.30.0 h1:44hCmGnEnZk/Miol5o44dhSldNH0EToQUG7vZTl29kk=
-github.com/operator-framework/api v0.30.0/go.mod h1:FYxAPhjtlXSAty/fbn5YJnFagt6SpJZJgFNNbvDe5W0=
+github.com/operator-framework/api v0.31.0 h1:tRsFTuZ51xD8U5QgiPo3+mZgVipHZVgRXYrI6RRXOh8=
+github.com/operator-framework/api v0.31.0/go.mod h1:57oCiHNeWcxmzu1Se8qlnwEKr/GGXnuHvspIYFCcXmY=
 github.com/operator-framework/operator-lib v0.17.0 h1:cbz51wZ9+GpWR1ZYP4CSKSSBxDlWxmmnseaHVZZjZt4=
 github.com/operator-framework/operator-lib v0.17.0/go.mod h1:TGopBxIE8L6E/Cojzo26R3NFp1eNlqhQNmzqhOblaLw=
 github.com/ovh/go-ovh v1.6.0 h1:ixLOwxQdzYDx296sXcgS35TOPEahJkpjMGtzPadCjQI=
diff --git a/internal/config/main.go b/internal/config/config.go
similarity index 100%
rename from internal/config/main.go
rename to internal/config/config.go
diff --git a/internal/status/collector/collector.go b/internal/status/collector/collector.go
index 59ea2c94..d6616c4c 100644
--- a/internal/status/collector/collector.go
+++ b/internal/status/collector/collector.go
@@ -80,6 +80,9 @@ func updateCollectorStatus(ctx context.Context, cli client.Client, changed *v1be
 		if err := cli.Get(ctx, objKey, obj); err != nil {
 			return fmt.Errorf("failed to get daemonSet status.replicas: %w", err)
 		}
+		replicas = obj.Status.DesiredNumberScheduled
+		readyReplicas = obj.Status.NumberReady
+		statusReplicas = strconv.Itoa(int(readyReplicas)) + "/" + strconv.Itoa(int(replicas))
 		statusImage = obj.Spec.Template.Spec.Containers[0].Image
 	}
 



Test patch:
diff --git a/internal/config/main_test.go b/internal/config/config_test.go
similarity index 100%
rename from internal/config/main_test.go
rename to internal/config/config_test.go
diff --git a/internal/status/collector/collector_test.go b/internal/status/collector/collector_test.go
index 05bd861e..0a5d3c75 100644
--- a/internal/status/collector/collector_test.go
+++ b/internal/status/collector/collector_test.go
@@ -152,6 +152,10 @@ func createMockKubernetesClientDaemonset() client.Client {
 				},
 			},
 		},
+		Status: appsv1.DaemonSetStatus{
+			DesiredNumberScheduled: 1,
+			NumberReady:            1,
+		},
 	}
 	return fake.NewClientBuilder().WithObjects(daemonset).Build()
 }
@@ -176,6 +180,8 @@ func TestUpdateCollectorStatusDaemonsetMode(t *testing.T) {
 	err := updateCollectorStatus(ctx, cli, changed)
 	assert.NoError(t, err)
 
+	assert.Equal(t, int32(1), changed.Status.Scale.Replicas, "expected replicas to be 1")
+	assert.Equal(t, "1/1", changed.Status.Scale.StatusReplicas, "expected status replicas to be 1/1")
 	assert.Contains(t, changed.Status.Scale.Selector, "customLabel=customValue", "expected selector to contain customlabel=customValue")
 	assert.Equal(t, "app:latest", changed.Status.Image, "expected image to be app:latest")
 }
diff --git a/tests/e2e/smoke-daemonset/00-assert.yaml b/tests/e2e/smoke-daemonset/00-assert.yaml
index e4864fff..b509ca90 100644
--- a/tests/e2e/smoke-daemonset/00-assert.yaml
+++ b/tests/e2e/smoke-daemonset/00-assert.yaml
@@ -19,4 +19,6 @@ metadata:
 status:
   (starts_with(image, 'ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector')): true
   (version != ''): true
-  # TODO: Check replicas here after resolving https://github.com/open-telemetry/opentelemetry-operator/issues/3930
+  scale:
+    replicas: 1
+    statusReplicas: "1/1"