Skip to content

refactor(hooks): discover kube feature gates via metrics endpoint#2137

Merged
yaroslavborbat merged 2 commits into
mainfrom
refactor/hooks/discover-kube-feature-gates-via-metrics
Mar 24, 2026
Merged

refactor(hooks): discover kube feature gates via metrics endpoint#2137
yaroslavborbat merged 2 commits into
mainfrom
refactor/hooks/discover-kube-feature-gates-via-metrics

Conversation

@yaroslavborbat
Copy link
Copy Markdown
Member

@yaroslavborbat yaroslavborbat commented Mar 23, 2026

Description

Refactored the discover-kube-apiserver-feature-gates hook to discover enabled feature gates
by scraping the kube-apiserver /metrics endpoint instead of parsing the kube-apiserver pod's
command-line arguments (--feature-gates=...).

Key changes:

  • Removed the Kubernetes watch on kube-apiserver pods and the associated JqFilter snapshot logic.
  • Added fetchMetrics — fetches raw Prometheus metrics from /metrics via the REST client.
  • Added parseEnabledFeatureGates — parses kubernetes_feature_enabled{...} 1 lines to extract enabled gate names.
  • Fixed draFeatureGatesPath condition: DRAResourceClaimDeviceStatus was previously assumed always enabled; it is now explicitly checked.
  • Added unit tests covering parseEnabledFeatureGates and the full reconciliation flow with a mock HTTP server.

Why do we need it, and what problem does it solve?

The previous implementation parsed the --feature-gates CLI flag from the kube-apiserver pod spec.
This approach is fragile: it only captures explicitly set gates and misses all gates that are
enabled by default (i.e., those not listed in the flag). This caused incorrect detection of DRA
feature gates in environments where gates are enabled by default without being explicitly passed
to the API server.

The /metrics endpoint exposes kubernetes_feature_enabled gauge for all known feature gates,
including defaults, giving a complete and authoritative picture of what is actually enabled at runtime.

What is the expected result?

  1. Deploy the module in a cluster where DRA feature gates are enabled by default (not via --feature-gates).
  2. Observe that virtualization.internal.kubeAPIServerFeatureGates is correctly populated with
    all enabled gates.
  3. Observe that virtualization.internal.hasDraFeatureGates is set to "true" when
    DRAResourceClaimDeviceStatus, DRADeviceBindingConditions, and DRAConsumableCapacity are all enabled.

Checklist

  • The code is covered by unit tests.
  • e2e tests passed.
  • Documentation updated according to the changes.
  • Changes were tested in the Kubernetes cluster manually.

Changelog entries

section: vm
type: fix
summary: Stabilized the operation of USB devices for virtualization on Deckhouse version ≥1.76 and Kubernetes version ≥1.33.

Signed-off-by: Yaroslav Borbat <yaroslav.borbat@flant.com>
Signed-off-by: Yaroslav Borbat <yaroslav.borbat@flant.com>
@yaroslavborbat yaroslavborbat merged commit 251313d into main Mar 24, 2026
27 of 28 checks passed
@yaroslavborbat yaroslavborbat deleted the refactor/hooks/discover-kube-feature-gates-via-metrics branch March 24, 2026 12:30
Isteb4k pushed a commit that referenced this pull request Mar 25, 2026
)

refactor(hooks): discover kube feature gates via metrics endpoint
---------
Signed-off-by: Yaroslav Borbat <yaroslav.borbat@flant.com>
(cherry picked from commit 251313d)
This was referenced Mar 30, 2026
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.

2 participants