Skip to content

Update use of global annotations to not include empty line in output#815

Open
seppelucas wants to merge 1 commit intokubescape:mainfrom
seppelucas:fix/cleanup-empty-lines-in-annotations
Open

Update use of global annotations to not include empty line in output#815
seppelucas wants to merge 1 commit intokubescape:mainfrom
seppelucas:fix/cleanup-empty-lines-in-annotations

Conversation

@seppelucas
Copy link
Copy Markdown

@seppelucas seppelucas commented Apr 8, 2026

No functional changes, only slightly cleaner helm output. Closes #814

Overview

Update usage of global annotations to not include empty lines in output.

Additional Information

No functional changes, only cleaning up the helm output.
Would be even better to not add annotations: is there are none. Maybe something to fix after #813, currently clashes.

How to Test

With a local helm build.

Before:

# Source: kubescape-operator/templates/operator/admission-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: "kubescape-admission-webhook"
  namespace: kubescape
  annotations:
    
  labels:
    helm.sh/chart: kubescape-operator-1.30.6
    app.kubernetes.io/name: kubescape-operator
    app.kubernetes.io/instance: my-release
    app.kubernetes.io/component: operator
    app.kubernetes.io/version: "1.30.6"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/part-of: kubescape
    app: operator
    tier: ks-control-plane
    kubescape.io/ignore: "true"
spec:
  ports:
    - port: 443
      targetPort: 8443
  selector:
      app.kubernetes.io/name: kubescape-operator
      app.kubernetes.io/instance: my-release
      app.kubernetes.io/component: operator
  type: ClusterIP  # Or use LoadBalancer or NodePort if needed
---

After:

# Source: kubescape-operator/templates/operator/admission-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: "kubescape-admission-webhook"
  namespace: kubescape
  annotations:
  labels:
    helm.sh/chart: kubescape-operator-1.30.6
    app.kubernetes.io/name: kubescape-operator
    app.kubernetes.io/instance: my-release
    app.kubernetes.io/component: operator
    app.kubernetes.io/version: "1.30.6"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/part-of: kubescape
    app: operator
    tier: ks-control-plane
    kubescape.io/ignore: "true"
spec:
  ports:
    - port: 443
      targetPort: 8443
  selector:
      app.kubernetes.io/name: kubescape-operator
      app.kubernetes.io/instance: my-release
      app.kubernetes.io/component: operator
  type: ClusterIP  # Or use LoadBalancer or NodePort if needed

Already tested, annotations is now empty where before it included an empty line with indent 4.

Related issues/PRs:

Summary by CodeRabbit

Release Notes

  • Refactor
    • Updated Helm template annotation rendering across all Kubernetes manifests to conditionally emit annotations only when configured, preventing unnecessary empty annotation blocks in generated resources.

No functional changes, only slightly cleaner helm output.
Closes kubescape#814

Signed-off-by: J.M. Lucas <slucas@osso.nl>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 8, 2026

📝 Walkthrough

Walkthrough

This pull request systematically updates 65+ Helm template files in the kubescape-operator chart to conditionally render metadata annotations. Each file replaces a direct template include that produces empty lines with a with block that emits content only when the included template returns a non-empty value.

Changes

Cohort / File(s) Summary
Asset Definitions
charts/kubescape-operator/assets/host-scanner-definition.yaml
Wrapped annotations include in with block to prevent empty lines when global annotations are not set.
Autoupdater Components
charts/kubescape-operator/templates/autoupdater/cronjob.yaml, charts/kubescape-operator/templates/autoupdater/serviceaccount.yaml
Updated metadata annotations rendering to use conditional with blocks instead of direct includes.
Cloud Configuration Resources
charts/kubescape-operator/templates/configs/cloud-secret.yaml, charts/kubescape-operator/templates/configs/cloudapi-configmap.yaml, charts/kubescape-operator/templates/configs/components-configmap.yaml, charts/kubescape-operator/templates/configs/custom-ca-certificates.yaml, charts/kubescape-operator/templates/configs/matchingRules-configmap.yaml, charts/kubescape-operator/templates/configs/priority-class.yaml, charts/kubescape-operator/templates/configs/private-registries-creds-secret.yaml
Consistently wrapped annotation includes in conditional with blocks across all config resources.
Grype Offline DB Components
charts/kubescape-operator/templates/grype-offline-db/cronjob.yaml, charts/kubescape-operator/templates/grype-offline-db/deployment.yaml
Updated CronJob and Deployment annotation rendering to conditionally emit content.
Kubescape Scheduler Components
charts/kubescape-operator/templates/kubescape-scheduler/configmap.yaml, charts/kubescape-operator/templates/kubescape-scheduler/cronjob.yaml
Applied conditional annotation rendering pattern to scheduler resources.
Kubescape Core RBAC & Network Resources
charts/kubescape-operator/templates/kubescape/clusterrole.yaml, charts/kubescape-operator/templates/kubescape/clusterrolebinding.yaml, charts/kubescape-operator/templates/kubescape/role.yaml, charts/kubescape-operator/templates/kubescape/rolebinding.yaml, charts/kubescape-operator/templates/kubescape/scc-rolebinding.yaml, charts/kubescape-operator/templates/kubescape/networkpolicy.yaml
Updated RBAC and network policy annotations with conditional with blocks.
Kubescape Core Services
charts/kubescape-operator/templates/kubescape/deployment.yaml, charts/kubescape-operator/templates/kubescape/host-scanner-definition-configmap.yaml, charts/kubescape-operator/templates/kubescape/service.yaml, charts/kubescape-operator/templates/kubescape/serviceaccount.yaml, charts/kubescape-operator/templates/kubescape/servicemonitor.yaml
Applied annotation fix to core deployment, service, and monitoring resources.
Kubevuln Scheduler Components
charts/kubescape-operator/templates/kubevuln-scheduler/cronjob.yaml
Updated CronJob annotations rendering with conditional block.
Kubevuln RBAC & Infrastructure
charts/kubescape-operator/templates/kubevuln/clusterrole.yaml, charts/kubescape-operator/templates/kubevuln/clusterrolebinding.yaml, charts/kubescape-operator/templates/kubevuln/deployment.yaml, charts/kubescape-operator/templates/kubevuln/networkpolicy.yaml, charts/kubescape-operator/templates/kubevuln/pvc.yaml, charts/kubescape-operator/templates/kubevuln/scc-rolebinding.yaml, charts/kubescape-operator/templates/kubevuln/service.yaml, charts/kubescape-operator/templates/kubevuln/serviceaccount.yaml
Consistently wrapped annotation includes across all kubevuln resources.
Node Agent RBAC Components
charts/kubescape-operator/templates/node-agent/clusterrole.yaml, charts/kubescape-operator/templates/node-agent/clusterrolebinding.yaml, charts/kubescape-operator/templates/node-agent/scc-rolebinding.yaml
Updated node-agent RBAC role and binding annotations with conditional rendering.
Node Agent Infrastructure
charts/kubescape-operator/templates/node-agent/configmap.yaml, charts/kubescape-operator/templates/node-agent/daemonset.yaml, charts/kubescape-operator/templates/node-agent/daemonsets.yaml, charts/kubescape-operator/templates/node-agent/networkpolicy.yaml, charts/kubescape-operator/templates/node-agent/service.yaml, charts/kubescape-operator/templates/node-agent/serviceaccount.yaml, charts/kubescape-operator/templates/node-agent/servicemonitor.yaml, charts/kubescape-operator/templates/node-agent/template-configmap.yaml
Applied annotation fix across node-agent deployment and configuration resources.
Node Agent Runtime Rules
charts/kubescape-operator/templates/node-agent/default-rule-binding-namespaced.yaml, charts/kubescape-operator/templates/node-agent/default-rule-binding.yaml, charts/kubescape-operator/templates/node-agent/default-rules.yaml
Updated RuntimeRuleAlertBinding and Rules resource annotations with conditional with blocks.
Operator RBAC Components
charts/kubescape-operator/templates/operator/clusterrole.yaml, charts/kubescape-operator/templates/operator/clusterrolebinding.yaml, charts/kubescape-operator/templates/operator/role.yaml, charts/kubescape-operator/templates/operator/rolebinding.yaml, charts/kubescape-operator/templates/operator/scc-rolebinding.yaml
Applied conditional annotation rendering to operator RBAC resources.
Operator Services & Configuration
charts/kubescape-operator/templates/operator/admission-service.yaml, charts/kubescape-operator/templates/operator/admission-webhook.yaml, charts/kubescape-operator/templates/operator/configmap.yaml, charts/kubescape-operator/templates/operator/deployment.yaml, charts/kubescape-operator/templates/operator/service.yaml, charts/kubescape-operator/templates/operator/serviceaccount.yaml
Updated operator service and webhook annotations with conditional with blocks (admission-webhook has 2 annotations blocks: TLS Secret and ValidatingWebhookConfiguration).
Operator CronJob Templates
charts/kubescape-operator/templates/operator/ks-recurring-cronjob-configmap.yaml, charts/kubescape-operator/templates/operator/kv-recurring-cronjob-configmap.yaml, charts/kubescape-operator/templates/operator/registry-scan-recurring-cronjob-configmap.yaml
Applied annotation fix to operator CronJob ConfigMap templates.
Operator Network Policy
charts/kubescape-operator/templates/operator/networkpolicy.yaml
Updated NetworkPolicy annotations with conditional rendering.
OTEL Collector Components
charts/kubescape-operator/templates/otel-collector/configmap.yaml, charts/kubescape-operator/templates/otel-collector/deployment.yaml
Applied conditional annotation rendering to OTEL collector resources.
Prometheus Exporter Components
charts/kubescape-operator/templates/prometheus-exporter/deployment.yaml, charts/kubescape-operator/templates/prometheus-exporter/networkpolicy.yaml, charts/kubescape-operator/templates/prometheus-exporter/servicemonitor.yaml
Updated prometheus-exporter deployment and monitoring resource annotations.
Storage RBAC & Services
charts/kubescape-operator/templates/storage/clusterrole.yaml, charts/kubescape-operator/templates/storage/clusterrolebinding.yaml, charts/kubescape-operator/templates/storage/rolebinding.yaml, charts/kubescape-operator/templates/storage/scc-rolebinding.yaml, charts/kubescape-operator/templates/storage/service.yaml, charts/kubescape-operator/templates/storage/serviceaccount.yaml
Applied conditional annotation rendering across storage RBAC and service resources.
Storage Infrastructure
charts/kubescape-operator/templates/storage/apiservice.yaml, charts/kubescape-operator/templates/storage/ca-secret.yaml, charts/kubescape-operator/templates/storage/deployment.yaml, charts/kubescape-operator/templates/storage/networkpolicy.yaml, charts/kubescape-operator/templates/storage/pvc.yaml, charts/kubescape-operator/templates/storage/seccompprofile-crd.yaml, charts/kubescape-operator/templates/storage/tests/test-connection.yaml
Updated storage deployment, networking, persistence, and CRD annotations with conditional with blocks.
Synchronizer Components
charts/kubescape-operator/templates/synchronizer/clusterrole.yaml, charts/kubescape-operator/templates/synchronizer/configmap.yaml, charts/kubescape-operator/templates/synchronizer/deployment.yaml, charts/kubescape-operator/templates/synchronizer/networkpolicy.yaml
Applied conditional annotation rendering pattern to synchronizer resources.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~10 minutes

This is a highly homogeneous change repeated identically across 65+ files. The pattern is simple and straightforward: wrapping existing includes in conditional with blocks to eliminate empty lines when annotations are not set. Each file modification follows the same structure, requiring minimal reasoning per file and benefiting from pattern recognition across the cohort.

Poem

🐰 Hops of joy through template fields,
Conditional blocks now seal each deal,
Empty lines begone, my dear!
Annotations clean, the fix is clear,
Sixty files dance with grace so neat!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: updating global annotations to not include empty lines in Helm output, which matches the consistent templating changes across all 60+ files.
Linked Issues check ✅ Passed All changes implement the exact fix requested in issue #814: wrapping annotation includes in conditional with blocks to prevent empty indented lines in rendered Helm manifests.
Out of Scope Changes check ✅ Passed All changes are strictly limited to updating annotation rendering in Helm templates using the with block pattern. No other functionality, configuration, or code structure was modified.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
charts/kubescape-operator/templates/grype-offline-db/deployment.yaml (1)

27-29: ⚠️ Potential issue | 🟡 Minor

Inconsistent pattern: pod template annotations not wrapped in with block.

Same issue as the kubescape deployment—the pod template metadata annotations on line 28 still use the old pattern and will produce empty indented lines when global annotations are not set.

Proposed fix
      annotations:
-        {{- include "kubescape-operator.annotations" (dict "Values" .Values) | nindent 8 }}
+        {{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
+        {{ . | nindent 8 }}
+        {{- end }}
         {{- with .Values.grypeOfflineDB.podAnnotations }}{{- toYaml . | nindent 8 }}{{- end }}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kubescape-operator/templates/grype-offline-db/deployment.yaml` around
lines 27 - 29, The pod template metadata annotations use the standalone include
"kubescape-operator.annotations" which can emit empty indented lines when global
annotations are absent; change this to the same guarded pattern used elsewhere
by wrapping the include in a `with`/guard so the annotations block is only
rendered if non-empty, and keep the existing fallback that still renders
`.Values.grypeOfflineDB.podAnnotations` (reference: the include
"kubescape-operator.annotations" invocation and the
`.Values.grypeOfflineDB.podAnnotations` block in the pod template metadata).
charts/kubescape-operator/templates/kubescape/deployment.yaml (1)

31-33: ⚠️ Potential issue | 🟡 Minor

Inconsistent pattern: pod template annotations not wrapped in with block.

The deployment metadata annotations (lines 12-14) use the new with pattern, but the pod template metadata annotations on line 32 still use the old direct include pattern. If global annotations are empty, this will still produce an empty indented line in the rendered pod spec.

Proposed fix
      annotations:
-        {{- include "kubescape-operator.annotations" (dict "Values" .Values) | nindent 8 }}
+        {{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
+        {{ . | nindent 8 }}
+        {{- end }}
         {{- with .Values.kubescape.podAnnotations }}{{- toYaml . | nindent 8 }}{{- end }}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kubescape-operator/templates/kubescape/deployment.yaml` around lines
31 - 33, The pod template annotations block in deployment.yaml uses a direct
include of the "kubescape-operator.annotations" template and
.Values.kubescape.podAnnotations which can emit an empty indented line; change
it to the same `with`-guard pattern used for deployment metadata so the block is
omitted when empty: wrap the include "kubescape-operator.annotations" (dict
"Values" .Values) and the .Values.kubescape.podAnnotations YAML in `with`/`end`
guards around the nindent call so nothing is rendered if those values are empty,
keeping the template names ("kubescape-operator.annotations") and the value key
(.Values.kubescape.podAnnotations) intact.
charts/kubescape-operator/templates/prometheus-exporter/deployment.yaml (1)

25-27: ⚠️ Potential issue | 🟡 Minor

Inconsistent fix: pod template annotations still uses the old pattern.

The metadata annotations were updated to use the with block (lines 10-12), but the pod template's annotations at line 26 still use the old {{- include ... | nindent 8 }} pattern that can produce empty lines when annotations are unset.

For consistency, apply the same fix here:

Proposed fix
     metadata:
       annotations:
-        {{- include "kubescape-operator.annotations" (dict "Values" .Values) | nindent 8 }}
+        {{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
+        {{ . | nindent 8 }}
+        {{- end }}
         {{- with .Values.prometheusExporter.podAnnotations }}{{- toYaml . | nindent 8 }}{{- end }}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kubescape-operator/templates/prometheus-exporter/deployment.yaml`
around lines 25 - 27, The pod template annotations still use the old include
pattern ({{- include "kubescape-operator.annotations" ...) which can emit empty
lines when no annotations exist; replace that include invocation with the same
`with` pattern used for metadata (i.e., wrap the include and any podAnnotations
merge inside a `{{- with ... }}` so you only render the block when annotations
exist), updating the pod template annotations block that references include
"kubescape-operator.annotations" and .Values.prometheusExporter.podAnnotations
to use the `with` conditional merge used for metadata to avoid empty lines.
charts/kubescape-operator/templates/grype-offline-db/cronjob.yaml (1)

26-28: ⚠️ Potential issue | 🟡 Minor

Inconsistent fix: pod template annotations still uses the old pattern.

Same issue as other templates—the job template's pod annotations at line 27 still use the old pattern that can produce empty lines.

Proposed fix
         metadata:
           annotations:
-            {{- include "kubescape-operator.annotations" (dict "Values" .Values) | nindent 12 }}
+            {{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
+            {{ . | nindent 12 }}
+            {{- end }}
             {{- with .Values.grypeOfflineDB.podAnnotations }}{{- toYaml . | nindent 12 }}{{- end }}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kubescape-operator/templates/grype-offline-db/cronjob.yaml` around
lines 26 - 28, Replace the old pod-annotations block in cronjob.yaml so it
conditionally renders without introducing blank lines: instead of the current
{{- with .Values.grypeOfflineDB.podAnnotations }}{{- toYaml . | nindent 12 }}{{-
end }}, use an explicit if that references .Values.grypeOfflineDB.podAnnotations
(eg. {{- if .Values.grypeOfflineDB.podAnnotations }}{{ toYaml
.Values.grypeOfflineDB.podAnnotations | nindent 12 }}{{- end }}) so the pod
template annotations (the include "kubescape-operator.annotations" and the
Values.grypeOfflineDB.podAnnotations rendering) do not produce empty lines when
the value is absent.
🧹 Nitpick comments (2)
charts/kubescape-operator/templates/node-agent/template-configmap.yaml (1)

24-25: Consider applying the same pattern to the embedded DaemonSet template annotations.

The embedded DaemonSet template at line 25 still uses the direct include ... | nindent 8 pattern. While this is stored as ConfigMap data and processed by the operator autoscaler at runtime, it will still produce empty indented lines in the rendered DaemonSet manifest when annotations are empty.

For full consistency with the PR objective, consider applying the same with block pattern here.

♻️ Suggested change for embedded template
       annotations:
-        {{- include "kubescape-operator.annotations" (dict "Values" .Values) | nindent 8 }}
+        {{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
+        {{ . | nindent 8 }}
+        {{- end }}
       labels:
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kubescape-operator/templates/node-agent/template-configmap.yaml`
around lines 24 - 25, The embedded DaemonSet annotations currently use the
direct include pattern "{{ include "kubescape-operator.annotations" ... |
nindent 8 }}" which generates empty indented lines when annotations are absent;
update the embedded DaemonSet template to use the same "with" wrapper pattern
used elsewhere (i.e., wrap the include in a "with" conditional so it only
renders when .Values or the annotations dict is non-empty) to avoid empty lines
— locate the embedded DaemonSet annotations in template-configmap.yaml and
replace the direct include of "kubescape-operator.annotations" with the
conditional "with" usage.
charts/kubescape-operator/templates/kubevuln/deployment.yaml (1)

27-29: Consider applying the same pattern to pod template annotations for consistency.

The pod template annotations at line 28 still use the direct include ... | nindent 8 pattern without a with block. While this is less problematic here since there are subsequent annotations (podAnnotations, checksums), it may still produce an empty indented line when additionalAnnotations is empty.

If the goal is to eliminate all empty lines from annotations includes, consider applying the same with block pattern here as well.

♻️ Suggested change for consistency
     metadata:
       annotations:
-        {{- include "kubescape-operator.annotations" (dict "Values" .Values) | nindent 8 }}
+        {{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
+        {{ . | nindent 8 }}
+        {{- end }}
         {{- with .Values.kubevuln.podAnnotations }}{{- toYaml . | nindent 8 }}{{- end }}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kubescape-operator/templates/kubevuln/deployment.yaml` around lines 27
- 29, The pod template annotations use a direct include of
"kubescape-operator.annotations" which can emit an empty indented line when the
result is empty; wrap that include in a conditional `with` block (similar to the
pattern used for `.Values.kubevuln.podAnnotations`) so the include is rendered
only when it produces content, ensuring no blank indented lines; update the pod
template annotations block to use `with` around the include
"kubescape-operator.annotations" and keep the existing
`.Values.kubevuln.podAnnotations` and checksum annotations intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@charts/kubescape-operator/templates/kubescape/scc-rolebinding.yaml`:
- Around line 9-11: The template opens the with block using '{{- with (include
"kubescape-operator.annotations" (dict "Values" .Values)) }}' which leaves a
trailing blank line; change the opening tag to include the trailing dash ('-}}')
so it becomes '{{- with (include "kubescape-operator.annotations" (dict "Values"
.Values)) -}}' to suppress the extra newline and keep formatting consistent with
other templates — update the with/opening tag for the annotations block (and
verify matching end blocks remain '{{- end }}') accordingly.

In `@charts/kubescape-operator/templates/kubevuln/serviceaccount.yaml`:
- Around line 7-9: The with block in the serviceaccount template preserves an
extra newline after rendering annotations; change the with closing delimiter to
trim the trailing newline by replacing the current `{{- with (include
"kubescape-operator.annotations" (dict "Values" .Values)) }}`/`{{- end }}`
pattern so the opening or closing tag uses a `-}}` (i.e., use `-}}` after the
with) to suppress the blank indented line; update the block that calls include
"kubescape-operator.annotations" (and any identical blocks in this template) to
use the trimmed delimiter so no extra blank line is emitted.

In `@charts/kubescape-operator/templates/node-agent/default-rule-binding.yaml`:
- Around line 7-9: The extra blank line comes from the trailing newline after
the with block before nindent; in the templates using the with block around
include "kubescape-operator.annotations" change the closing delimiter from "}}"
to "-}}" so the trailing whitespace/newline is stripped (i.e. update the with
block that calls include "kubescape-operator.annotations" and the subsequent {{
. | nindent 4 }} usage) to prevent the extra blank line when annotations are
present.

In `@charts/kubescape-operator/templates/operator/serviceaccount.yaml`:
- Around line 7-9: The with-block in the template that wraps the include
"kubescape-operator.annotations" is leaving an extra blank line; update the with
tag to trim whitespace on the right by changing the opening tag to use a
trailing -}} (i.e., use {{- with (include "kubescape-operator.annotations" (dict
"Values" .Values)) -}}) so the rendered output doesn’t add an extra blank line
when annotations are present; leave the inner {{ . | nindent 4 }} and the
existing {{- end }} unchanged.

In `@charts/kubescape-operator/templates/storage/networkpolicy.yaml`:
- Around line 9-11: The template leaves an extra blank line because the `with`
action is not closed with a trimmed delimiter; update the Helm template block
that uses include "kubescape-operator.annotations" so the opening tag trims
following whitespace by changing `{{- with (include
"kubescape-operator.annotations" (dict "Values" .Values)) }}` to use a trailing
hyphen `-}}` (i.e., `{{- with (include "kubescape-operator.annotations" (dict
"Values" .Values)) -}}`), leaving the rest of the block (`{{ . | nindent 4 }}`
and `{{- end }}`) as-is to remove the extra blank line when annotations are
present.

---

Outside diff comments:
In `@charts/kubescape-operator/templates/grype-offline-db/cronjob.yaml`:
- Around line 26-28: Replace the old pod-annotations block in cronjob.yaml so it
conditionally renders without introducing blank lines: instead of the current
{{- with .Values.grypeOfflineDB.podAnnotations }}{{- toYaml . | nindent 12 }}{{-
end }}, use an explicit if that references .Values.grypeOfflineDB.podAnnotations
(eg. {{- if .Values.grypeOfflineDB.podAnnotations }}{{ toYaml
.Values.grypeOfflineDB.podAnnotations | nindent 12 }}{{- end }}) so the pod
template annotations (the include "kubescape-operator.annotations" and the
Values.grypeOfflineDB.podAnnotations rendering) do not produce empty lines when
the value is absent.

In `@charts/kubescape-operator/templates/grype-offline-db/deployment.yaml`:
- Around line 27-29: The pod template metadata annotations use the standalone
include "kubescape-operator.annotations" which can emit empty indented lines
when global annotations are absent; change this to the same guarded pattern used
elsewhere by wrapping the include in a `with`/guard so the annotations block is
only rendered if non-empty, and keep the existing fallback that still renders
`.Values.grypeOfflineDB.podAnnotations` (reference: the include
"kubescape-operator.annotations" invocation and the
`.Values.grypeOfflineDB.podAnnotations` block in the pod template metadata).

In `@charts/kubescape-operator/templates/kubescape/deployment.yaml`:
- Around line 31-33: The pod template annotations block in deployment.yaml uses
a direct include of the "kubescape-operator.annotations" template and
.Values.kubescape.podAnnotations which can emit an empty indented line; change
it to the same `with`-guard pattern used for deployment metadata so the block is
omitted when empty: wrap the include "kubescape-operator.annotations" (dict
"Values" .Values) and the .Values.kubescape.podAnnotations YAML in `with`/`end`
guards around the nindent call so nothing is rendered if those values are empty,
keeping the template names ("kubescape-operator.annotations") and the value key
(.Values.kubescape.podAnnotations) intact.

In `@charts/kubescape-operator/templates/prometheus-exporter/deployment.yaml`:
- Around line 25-27: The pod template annotations still use the old include
pattern ({{- include "kubescape-operator.annotations" ...) which can emit empty
lines when no annotations exist; replace that include invocation with the same
`with` pattern used for metadata (i.e., wrap the include and any podAnnotations
merge inside a `{{- with ... }}` so you only render the block when annotations
exist), updating the pod template annotations block that references include
"kubescape-operator.annotations" and .Values.prometheusExporter.podAnnotations
to use the `with` conditional merge used for metadata to avoid empty lines.

---

Nitpick comments:
In `@charts/kubescape-operator/templates/kubevuln/deployment.yaml`:
- Around line 27-29: The pod template annotations use a direct include of
"kubescape-operator.annotations" which can emit an empty indented line when the
result is empty; wrap that include in a conditional `with` block (similar to the
pattern used for `.Values.kubevuln.podAnnotations`) so the include is rendered
only when it produces content, ensuring no blank indented lines; update the pod
template annotations block to use `with` around the include
"kubescape-operator.annotations" and keep the existing
`.Values.kubevuln.podAnnotations` and checksum annotations intact.

In `@charts/kubescape-operator/templates/node-agent/template-configmap.yaml`:
- Around line 24-25: The embedded DaemonSet annotations currently use the direct
include pattern "{{ include "kubescape-operator.annotations" ... | nindent 8 }}"
which generates empty indented lines when annotations are absent; update the
embedded DaemonSet template to use the same "with" wrapper pattern used
elsewhere (i.e., wrap the include in a "with" conditional so it only renders
when .Values or the annotations dict is non-empty) to avoid empty lines — locate
the embedded DaemonSet annotations in template-configmap.yaml and replace the
direct include of "kubescape-operator.annotations" with the conditional "with"
usage.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: efbea9c3-efd0-41cf-b58d-b5d7c5157562

📥 Commits

Reviewing files that changed from the base of the PR and between cdac526 and 4bf19c1.

📒 Files selected for processing (85)
  • charts/kubescape-operator/assets/host-scanner-definition.yaml
  • charts/kubescape-operator/templates/autoupdater/cronjob.yaml
  • charts/kubescape-operator/templates/autoupdater/serviceaccount.yaml
  • charts/kubescape-operator/templates/configs/cloud-secret.yaml
  • charts/kubescape-operator/templates/configs/cloudapi-configmap.yaml
  • charts/kubescape-operator/templates/configs/components-configmap.yaml
  • charts/kubescape-operator/templates/configs/custom-ca-certificates.yaml
  • charts/kubescape-operator/templates/configs/matchingRules-configmap.yaml
  • charts/kubescape-operator/templates/configs/priority-class.yaml
  • charts/kubescape-operator/templates/configs/private-registries-creds-secret.yaml
  • charts/kubescape-operator/templates/grype-offline-db/cronjob.yaml
  • charts/kubescape-operator/templates/grype-offline-db/deployment.yaml
  • charts/kubescape-operator/templates/kubescape-scheduler/configmap.yaml
  • charts/kubescape-operator/templates/kubescape-scheduler/cronjob.yaml
  • charts/kubescape-operator/templates/kubescape/clusterrole.yaml
  • charts/kubescape-operator/templates/kubescape/clusterrolebinding.yaml
  • charts/kubescape-operator/templates/kubescape/deployment.yaml
  • charts/kubescape-operator/templates/kubescape/host-scanner-definition-configmap.yaml
  • charts/kubescape-operator/templates/kubescape/networkpolicy.yaml
  • charts/kubescape-operator/templates/kubescape/role.yaml
  • charts/kubescape-operator/templates/kubescape/rolebinding.yaml
  • charts/kubescape-operator/templates/kubescape/scc-rolebinding.yaml
  • charts/kubescape-operator/templates/kubescape/service.yaml
  • charts/kubescape-operator/templates/kubescape/serviceaccount.yaml
  • charts/kubescape-operator/templates/kubescape/servicemonitor.yaml
  • charts/kubescape-operator/templates/kubevuln-scheduler/cronjob.yaml
  • charts/kubescape-operator/templates/kubevuln/clusterrole.yaml
  • charts/kubescape-operator/templates/kubevuln/clusterrolebinding.yaml
  • charts/kubescape-operator/templates/kubevuln/deployment.yaml
  • charts/kubescape-operator/templates/kubevuln/networkpolicy.yaml
  • charts/kubescape-operator/templates/kubevuln/pvc.yaml
  • charts/kubescape-operator/templates/kubevuln/scc-rolebinding.yaml
  • charts/kubescape-operator/templates/kubevuln/service.yaml
  • charts/kubescape-operator/templates/kubevuln/serviceaccount.yaml
  • charts/kubescape-operator/templates/node-agent/clusterrole.yaml
  • charts/kubescape-operator/templates/node-agent/clusterrolebinding.yaml
  • charts/kubescape-operator/templates/node-agent/configmap.yaml
  • charts/kubescape-operator/templates/node-agent/daemonset.yaml
  • charts/kubescape-operator/templates/node-agent/daemonsets.yaml
  • charts/kubescape-operator/templates/node-agent/default-rule-binding-namespaced.yaml
  • charts/kubescape-operator/templates/node-agent/default-rule-binding.yaml
  • charts/kubescape-operator/templates/node-agent/default-rules.yaml
  • charts/kubescape-operator/templates/node-agent/networkpolicy.yaml
  • charts/kubescape-operator/templates/node-agent/scc-rolebinding.yaml
  • charts/kubescape-operator/templates/node-agent/service.yaml
  • charts/kubescape-operator/templates/node-agent/serviceaccount.yaml
  • charts/kubescape-operator/templates/node-agent/servicemonitor.yaml
  • charts/kubescape-operator/templates/node-agent/template-configmap.yaml
  • charts/kubescape-operator/templates/operator/admission-service.yaml
  • charts/kubescape-operator/templates/operator/admission-webhook.yaml
  • charts/kubescape-operator/templates/operator/clusterrole.yaml
  • charts/kubescape-operator/templates/operator/clusterrolebinding.yaml
  • charts/kubescape-operator/templates/operator/configmap.yaml
  • charts/kubescape-operator/templates/operator/deployment.yaml
  • charts/kubescape-operator/templates/operator/ks-recurring-cronjob-configmap.yaml
  • charts/kubescape-operator/templates/operator/kv-recurring-cronjob-configmap.yaml
  • charts/kubescape-operator/templates/operator/networkpolicy.yaml
  • charts/kubescape-operator/templates/operator/registry-scan-recurring-cronjob-configmap.yaml
  • charts/kubescape-operator/templates/operator/role.yaml
  • charts/kubescape-operator/templates/operator/rolebinding.yaml
  • charts/kubescape-operator/templates/operator/scc-rolebinding.yaml
  • charts/kubescape-operator/templates/operator/service.yaml
  • charts/kubescape-operator/templates/operator/serviceaccount.yaml
  • charts/kubescape-operator/templates/otel-collector/configmap.yaml
  • charts/kubescape-operator/templates/otel-collector/deployment.yaml
  • charts/kubescape-operator/templates/prometheus-exporter/deployment.yaml
  • charts/kubescape-operator/templates/prometheus-exporter/networkpolicy.yaml
  • charts/kubescape-operator/templates/prometheus-exporter/servicemonitor.yaml
  • charts/kubescape-operator/templates/storage/apiservice.yaml
  • charts/kubescape-operator/templates/storage/ca-secret.yaml
  • charts/kubescape-operator/templates/storage/clusterrole.yaml
  • charts/kubescape-operator/templates/storage/clusterrolebinding.yaml
  • charts/kubescape-operator/templates/storage/deployment.yaml
  • charts/kubescape-operator/templates/storage/networkpolicy.yaml
  • charts/kubescape-operator/templates/storage/pvc.yaml
  • charts/kubescape-operator/templates/storage/rolebinding.yaml
  • charts/kubescape-operator/templates/storage/scc-rolebinding.yaml
  • charts/kubescape-operator/templates/storage/seccompprofile-crd.yaml
  • charts/kubescape-operator/templates/storage/service.yaml
  • charts/kubescape-operator/templates/storage/serviceaccount.yaml
  • charts/kubescape-operator/templates/storage/tests/test-connection.yaml
  • charts/kubescape-operator/templates/synchronizer/clusterrole.yaml
  • charts/kubescape-operator/templates/synchronizer/configmap.yaml
  • charts/kubescape-operator/templates/synchronizer/deployment.yaml
  • charts/kubescape-operator/templates/synchronizer/networkpolicy.yaml

Comment on lines +9 to +11
{{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
{{ . | nindent 4 }}
{{- end }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Same whitespace issue: use -}} after with.

Consistent with the other templates — add -}} to avoid the extra blank line when annotations are present.

Proposed fix
-    {{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
+    {{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) -}}
     {{ . | nindent 4 }}
     {{- end }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
{{ . | nindent 4 }}
{{- end }}
{{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) -}}
{{ . | nindent 4 }}
{{- end }}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kubescape-operator/templates/kubescape/scc-rolebinding.yaml` around
lines 9 - 11, The template opens the with block using '{{- with (include
"kubescape-operator.annotations" (dict "Values" .Values)) }}' which leaves a
trailing blank line; change the opening tag to include the trailing dash ('-}}')
so it becomes '{{- with (include "kubescape-operator.annotations" (dict "Values"
.Values)) -}}' to suppress the extra newline and keep formatting consistent with
other templates — update the with/opening tag for the annotations block (and
verify matching end blocks remain '{{- end }}') accordingly.

Comment on lines +7 to +9
{{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
{{ . | nindent 4 }}
{{- end }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Same whitespace issue: use -}} after with.

Same issue as the other templates — when annotations exist, an extra blank indented line is produced due to the preserved newline after }}.

Proposed fix
-    {{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
+    {{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) -}}
     {{ . | nindent 4 }}
     {{- end }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
{{ . | nindent 4 }}
{{- end }}
{{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) -}}
{{ . | nindent 4 }}
{{- end }}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kubescape-operator/templates/kubevuln/serviceaccount.yaml` around
lines 7 - 9, The with block in the serviceaccount template preserves an extra
newline after rendering annotations; change the with closing delimiter to trim
the trailing newline by replacing the current `{{- with (include
"kubescape-operator.annotations" (dict "Values" .Values)) }}`/`{{- end }}`
pattern so the opening or closing tag uses a `-}}` (i.e., use `-}}` after the
with) to suppress the blank indented line; update the block that calls include
"kubescape-operator.annotations" (and any identical blocks in this template) to
use the trimmed delimiter so no extra blank line is emitted.

Comment on lines +7 to +9
{{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
{{ . | nindent 4 }}
{{- end }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Extra blank line produced when annotations are present.

The with block correctly suppresses output when annotations are empty. However, when annotations are set, the }} on line 7 preserves the trailing newline and indentation, and then nindent 4 prepends another newline. This produces:

  annotations:
    
    key: value

Use -}} to strip trailing whitespace after with:

Proposed fix
-    {{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
+    {{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) -}}
     {{ . | nindent 4 }}
     {{- end }}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kubescape-operator/templates/node-agent/default-rule-binding.yaml`
around lines 7 - 9, The extra blank line comes from the trailing newline after
the with block before nindent; in the templates using the with block around
include "kubescape-operator.annotations" change the closing delimiter from "}}"
to "-}}" so the trailing whitespace/newline is stripped (i.e. update the with
block that calls include "kubescape-operator.annotations" and the subsequent {{
. | nindent 4 }} usage) to prevent the extra blank line when annotations are
present.

Comment on lines +7 to +9
{{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
{{ . | nindent 4 }}
{{- end }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Same whitespace issue: use -}} after with.

Consistent with the other templates — add -}} to avoid the extra blank line when annotations are present.

Proposed fix
-    {{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
+    {{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) -}}
     {{ . | nindent 4 }}
     {{- end }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
{{ . | nindent 4 }}
{{- end }}
{{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) -}}
{{ . | nindent 4 }}
{{- end }}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kubescape-operator/templates/operator/serviceaccount.yaml` around
lines 7 - 9, The with-block in the template that wraps the include
"kubescape-operator.annotations" is leaving an extra blank line; update the with
tag to trim whitespace on the right by changing the opening tag to use a
trailing -}} (i.e., use {{- with (include "kubescape-operator.annotations" (dict
"Values" .Values)) -}}) so the rendered output doesn’t add an extra blank line
when annotations are present; leave the inner {{ . | nindent 4 }} and the
existing {{- end }} unchanged.

Comment on lines +9 to +11
{{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
{{ . | nindent 4 }}
{{- end }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Same whitespace issue: use -}} after with.

Consistent with the other templates — add -}} to avoid the extra blank line when annotations are present.

Proposed fix
-    {{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
+    {{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) -}}
     {{ . | nindent 4 }}
     {{- end }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) }}
{{ . | nindent 4 }}
{{- end }}
{{- with (include "kubescape-operator.annotations" (dict "Values" .Values)) -}}
{{ . | nindent 4 }}
{{- end }}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kubescape-operator/templates/storage/networkpolicy.yaml` around lines
9 - 11, The template leaves an extra blank line because the `with` action is not
closed with a trimmed delimiter; update the Helm template block that uses
include "kubescape-operator.annotations" so the opening tag trims following
whitespace by changing `{{- with (include "kubescape-operator.annotations" (dict
"Values" .Values)) }}` to use a trailing hyphen `-}}` (i.e., `{{- with (include
"kubescape-operator.annotations" (dict "Values" .Values)) -}}`), leaving the
rest of the block (`{{ . | nindent 4 }}` and `{{- end }}`) as-is to remove the
extra blank line when annotations are present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Global annotation include results in empty lines in helm build

1 participant