Skip to content

Conversation

@rafabene
Copy link
Contributor

@rafabene rafabene commented Feb 4, 2026

Summary

  • Make HYPERFLEET_CLUSTER_ADAPTERS and HYPERFLEET_NODEPOOL_ADAPTERS environment variables required
  • Remove hardcoded default adapter values
  • Application now fails to start with a clear error message if adapters are not configured

Changes

pkg/config/adapter.go

  • NewAdapterRequirementsConfig() now returns (*AdapterRequirementsConfig, error)
  • Returns error if HYPERFLEET_CLUSTER_ADAPTERS or HYPERFLEET_NODEPOOL_ADAPTERS are not set
  • Returns error if environment variables contain invalid JSON

plugins/clusters/plugin.go & plugins/nodePools/plugin.go

  • Added error handling for NewAdapterRequirementsConfig()
  • Application panics on startup if adapter configuration fails (fail-fast behavior)

charts/templates/deployment.yaml

  • Removed conditional logic for adapter environment variables
  • Added required validation - Helm install fails if adapters are not provided

charts/values.yaml

  • Changed default adapter values from [] to null
  • Added comments indicating these are required fields

docs/deployment.md

  • Updated documentation to reflect mandatory adapter configuration
  • Updated all deployment examples to include adapter configuration

Test plan

  • make test - All 375 tests pass
  • make lint - No lint issues
  • Verify Helm install fails without adapters configuration
  • Verify application fails to start without env vars
  • Verify application starts correctly with adapters configured

Jira

https://issues.redhat.com/browse/HYPERFLEET-606

Summary by CodeRabbit

  • Breaking Changes

    • Cluster and nodepool adapter lists are now required at startup: HYPERFLEET_CLUSTER_ADAPTERS and HYPERFLEET_NODEPOOL_ADAPTERS must be provided (env or chart) or the service will fail to start.
  • New Features

    • Prometheus ServiceMonitor support added (enable, interval, scrape timeout, labels, namespace).
  • Documentation

    • Deployment and Helm docs updated with REQUIRED adapter guidance and usage examples.
  • Tests

    • Tests and integration setup updated to validate required adapter envs.

- Remove default adapter values from pkg/config/adapter.go
- NewAdapterRequirementsConfig() now returns error if env vars are missing
- Update plugins to panic on startup if adapter config fails
- Helm chart now requires adapters.cluster and adapters.nodepool values
- Update documentation to reflect mandatory configuration
- Update tests to use helper functions for adapter config
@openshift-ci openshift-ci bot requested review from jsell-rh and rh-amarin February 4, 2026 17:09
@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 2026

Walkthrough

Helm templates now require and always render HYPERFLEET_CLUSTER_ADAPTERS and HYPERFLEET_NODEPOOL_ADAPTERS. Values/docs mark adapters as REQUIRED and include a new ServiceMonitor block. The Go config layer adds Adapters to ApplicationConfig and introduces NewAdapterRequirementsConfig() returning (config, error) with LoadFromEnv validating and parsing required env vars; initialization now fails on missing/invalid adapter env. Tests and integration harness set adapter env for runs; plugin constructors consume env.Config.Adapters instead of building their own adapter config.

Sequence Diagram(s)

sequenceDiagram
    participant Helm as Helm (chart/templates)
    participant K8s as Kubernetes Deployment
    participant Pod as Container/App
    participant Config as pkg/config (LoadAdapters)
    participant Plugin as plugins (clusters/nodePools)

    Helm->>K8s: Render Deployment with required HYPERFLEET_CLUSTER_ADAPTERS & HYPERFLEET_NODEPOOL_ADAPTERS
    K8s->>Pod: Start Pod with env vars
    Pod->>Config: Initialize adapters (NewAdapterRequirementsConfig / LoadFromEnv)
    Config-->>Pod: return AdapterRequirementsConfig or error
    alt adapters loaded
        Pod->>Plugin: pass env.Config.Adapters to New*Service
        Plugin-->>Pod: service initialized
    else load failed
        Pod->>Pod: log error and exit
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

lgtm, approved

Suggested reviewers

  • aredenba-rh
  • xueli181114
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 34.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the main change: making adapter configuration mandatory rather than optional with defaults.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Copy link

@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: 1

🤖 Fix all issues with AI agents
In `@charts/templates/deployment.yaml`:
- Around line 77-80: Replace the use of required on .Values.adapters.cluster and
.Values.adapters.nodepool (which treats [] as empty and fails) with a presence
check and safe rendering: check the adapters keys with hasKey (e.g., verify
.Values.adapters exists and hasKey .Values.adapters "cluster"/"nodepool" and
call fail with a clear message only if the key is missing), then render the env
values using default to allow an empty array (e.g., default []
.Values.adapters.cluster | toJson | quote). Update the
HYPERFLEET_CLUSTER_ADAPTERS and HYPERFLEET_NODEPOOL_ADAPTERS template lines to
use the presence check + default instead of required so [] is accepted at
runtime.
🧹 Nitpick comments (2)
pkg/config/adapter.go (1)

3-8: Avoid unstructured log.Printf in config loading.

These logs bypass the context-aware structured logger (opid/accountID/tx_id). Consider dropping these success logs or wiring a contextual logger instead.

🔧 Minimal change (drop unstructured logs)
 import (
 	"encoding/json"
 	"fmt"
-	"log"
 	"os"
 )
@@
-	log.Printf("Loaded HYPERFLEET_CLUSTER_ADAPTERS from env: %v", clusterAdapters)
@@
-	log.Printf("Loaded HYPERFLEET_NODEPOOL_ADAPTERS from env: %v", nodepoolAdapters)

As per coding guidelines: Use structured logging via logger.NewOCMLogger(ctx) with context information including [opid], [accountID], and [tx_id].

Also applies to: 39-58

pkg/services/node_pool_test.go (1)

21-27: Consider a shared test helper for adapter config.

This helper duplicates the one in pkg/services/cluster_test.go, which risks divergence if required adapters change. A small shared test util would keep defaults centralized.

@rafabene
Copy link
Contributor Author

rafabene commented Feb 4, 2026

Manual Testing

Validated all critical scenarios:

Test Result
Helm fails without adapters.cluster/adapters.nodepool
Helm accepts empty arrays [] via values file
Application panics on startup without env vars
Application starts correctly with adapters configured

@rafabene
Copy link
Contributor Author

rafabene commented Feb 4, 2026

/retest

1 similar comment
@rafabene
Copy link
Contributor Author

rafabene commented Feb 5, 2026

/retest

- Use hasKey + fail pattern instead of required function
- Allows empty arrays [] when explicitly configured
- Provides clear error messages when adapters not specified
- Add Adapters field to ApplicationConfig
- Add LoadAdapters() method called once during environment initialization
- Update plugins to use env.Config.Adapters instead of creating their own
- Remove duplicate NewAdapterRequirementsConfig() calls from plugins
- Add required env vars to framework_test.go
@rh-amarin
Copy link
Contributor

/lgtm

@openshift-ci
Copy link

openshift-ci bot commented Feb 6, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rh-amarin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved label Feb 6, 2026
@openshift-merge-bot openshift-merge-bot bot merged commit c79db9d into openshift-hyperfleet:main Feb 6, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants