Skip to content

feat: Add SERVICE_URL environment variable to operator deployment#632

Draft
ruivieira wants to merge 1 commit intotrustyai-explainability:mainfrom
ruivieira:evalhub-service-url
Draft

feat: Add SERVICE_URL environment variable to operator deployment#632
ruivieira wants to merge 1 commit intotrustyai-explainability:mainfrom
ruivieira:evalhub-service-url

Conversation

@ruivieira
Copy link
Copy Markdown
Member

@ruivieira ruivieira commented Feb 3, 2026

Refer to RHOAIENG-48376.

Summary by Sourcery

Add a SERVICE_URL environment variable to the EvalHub operator deployment and cover it with tests.

New Features:

  • Expose a SERVICE_URL environment variable on the EvalHub deployment derived from the instance name and namespace.

Tests:

  • Extend EvalHub deployment tests to verify the SERVICE_URL environment variable is set correctly.

Summary by CodeRabbit

  • New Features
    • Deployments now automatically include a SERVICE_URL environment variable that provides internal cluster service discovery capabilities. This variable is automatically configured using the deployment's name and namespace, enabling applications to connect to services without manual configuration.
  • Tests
    • Added test coverage to verify the SERVICE_URL environment variable is correctly configured in deployment default environment variables.

Signed-off-by: Rui Vieira <ruidevieira@googlemail.com>
@ruivieira ruivieira self-assigned this Feb 3, 2026
@ruivieira ruivieira added the kind/enhancement New feature or request label Feb 3, 2026
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Feb 3, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found 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

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Feb 3, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR adds a new SERVICE_URL environment variable to the EvalHub operator deployment and covers it with a unit test to ensure the URL is constructed correctly from the EvalHub name and namespace.

Flow diagram for constructing SERVICE_URL environment variable

flowchart TD
    A[EvalHubReconciler.buildDeploymentSpec<br/>inputs: ctx, instance EvalHub] --> B[Read instance.Name]
    A --> C[Read instance.Namespace]
    B --> D[Format SERVICE_URL<br/>pattern: http://%s.%s.svc.cluster.local:8080]
    C --> D
    D --> E[Create EnvVar SERVICE_URL<br/>value: formatted URL]
    E --> F[Append SERVICE_URL to container env list]
    F --> G[Return Deployment spec<br/>with SERVICE_URL set]
Loading

File-Level Changes

Change Details Files
Add SERVICE_URL environment variable to EvalHub deployment container spec.
  • Extend the default environment variable slice in buildDeploymentSpec to include SERVICE_URL.
  • Construct SERVICE_URL using instance name and namespace in a cluster-local HTTP URL on port 8080.
  • Ensure SERVICE_URL participates in the existing env var merge logic where CR values can override defaults.
controllers/evalhub/deployment.go
Cover SERVICE_URL behavior in EvalHub deployment unit tests.
  • Add an assertion that SERVICE_URL is present in the resulting deployment Env vars.
  • Verify that SERVICE_URL matches the expected http://..svc.cluster.local:8080 format using evalHubName and testNamespace.
controllers/evalhub/deployment_test.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ruivieira ruivieira marked this pull request as draft February 3, 2026 11:00
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 3, 2026

📝 Walkthrough

Walkthrough

A new default environment variable SERVICE_URL was added to the evalhub deployment configuration, constructed with the instance's name and namespace in Kubernetes DNS format, with corresponding test coverage to validate the variable's assignment.

Changes

Cohort / File(s) Summary
EvalHub Deployment Configuration
controllers/evalhub/deployment.go, controllers/evalhub/deployment_test.go
Added SERVICE_URL as a default environment variable with value http://<name>.<namespace>.svc.cluster.local:8080, and added assertion to verify it is correctly set in deployment test.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A URL hops into view,
Service discovery made anew,
DNS names dance with grace,
In the cluster's cozy space—
One more variable in the queue! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and specifically describes the main change: adding a SERVICE_URL environment variable to the operator deployment.
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 docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Important

Action Needed: IP Allowlist Update

If your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:

  • 136.113.208.247/32 (new)
  • 34.170.211.100/32
  • 35.222.179.152/32

Failure to add the new IP will result in interrupted reviews.


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
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The SERVICE_URL value hardcodes both the port (8080) and assumes the Service name matches instance.Name; if either of these can differ from the deployment name, consider deriving them from the Service spec or shared constants instead of formatting directly from instance.
  • Embedding the namespace directly in the URL string ties this env var to in-cluster DNS; if this URL is intended to be consumed outside the cluster or across environments, you may want to make the scheme/host configurable via the CR or operator configuration rather than fully constructing it here.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `SERVICE_URL` value hardcodes both the port (`8080`) and assumes the Service name matches `instance.Name`; if either of these can differ from the deployment name, consider deriving them from the Service spec or shared constants instead of formatting directly from `instance`.
- Embedding the namespace directly in the URL string ties this env var to in-cluster DNS; if this URL is intended to be consumed outside the cluster or across environments, you may want to make the scheme/host configurable via the CR or operator configuration rather than fully constructing it here.

## Individual Comments

### Comment 1
<location> `controllers/evalhub/deployment.go:111` </location>
<code_context>
+		{
+			Name:  "SERVICE_URL",
+			Value: fmt.Sprintf("http://%s.%s.svc.cluster.local:8080", instance.Name, instance.Namespace),
</code_context>

<issue_to_address>
**suggestion:** Avoid hardcoding the cluster DNS suffix to support non-default cluster domains.

Hardcoding `svc.cluster.local` assumes the default cluster DNS suffix and will fail on clusters with a custom domain (e.g. `svc.cluster.mycorp`). Please make the cluster domain configurable (e.g. flag/env) or derive it from existing operator configuration and compose the URL from that.

Suggested implementation:

```golang
		{
			Name:  "SERVICE_URL",
			Value: fmt.Sprintf("http://%s.%s.svc.%s:8080", instance.Name, instance.Namespace, getClusterDomain()),
		},

```

To fully support a configurable cluster domain, you also need to:

1. **Add an import for `os`** at the top of `controllers/evalhub/deployment.go` (if it is not already there):

   ```go
   import (
       // existing imports...
       "os"
   )
   ```

2. **Define the `getClusterDomain()` helper** in `controllers/evalhub/deployment.go` (place it near other helper functions):

   ```go
   func getClusterDomain() string {
       if v := os.Getenv("CLUSTER_DOMAIN"); v != "" {
           return v
       }
       // Fallback to the default Kubernetes cluster domain
       return "cluster.local"
   }
   ```

3. Optionally, if your operator already has a configuration or flag system, you may want to:
   - Plumb the cluster domain from that configuration instead of directly reading `os.Getenv` in this file.
   - In that case, adjust the `getClusterDomain()` implementation to read from your existing config object rather than from the environment.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -109,6 +109,10 @@ func (r *EvalHubReconciler) buildDeploymentSpec(ctx context.Context, instance *e
Name: "PROVIDERS_CONFIG_PATH",
Value: "/etc/evalhub/providers.yaml",
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: Avoid hardcoding the cluster DNS suffix to support non-default cluster domains.

Hardcoding svc.cluster.local assumes the default cluster DNS suffix and will fail on clusters with a custom domain (e.g. svc.cluster.mycorp). Please make the cluster domain configurable (e.g. flag/env) or derive it from existing operator configuration and compose the URL from that.

Suggested implementation:

		{
			Name:  "SERVICE_URL",
			Value: fmt.Sprintf("http://%s.%s.svc.%s:8080", instance.Name, instance.Namespace, getClusterDomain()),
		},

To fully support a configurable cluster domain, you also need to:

  1. Add an import for os at the top of controllers/evalhub/deployment.go (if it is not already there):

    import (
        // existing imports...
        "os"
    )
  2. Define the getClusterDomain() helper in controllers/evalhub/deployment.go (place it near other helper functions):

    func getClusterDomain() string {
        if v := os.Getenv("CLUSTER_DOMAIN"); v != "" {
            return v
        }
        // Fallback to the default Kubernetes cluster domain
        return "cluster.local"
    }
  3. Optionally, if your operator already has a configuration or flag system, you may want to:

    • Plumb the cluster domain from that configuration instead of directly reading os.Getenv in this file.
    • In that case, adjust the getClusterDomain() implementation to read from your existing config object rather than from the environment.

Copy link
Copy Markdown
Contributor

@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 `@controllers/evalhub/deployment.go`:
- Around line 112-115: Replace the hardcoded "8080" with the shared
containerPort constant: change the SERVICE_URL env var construction (the
fmt.Sprintf call that uses instance.Name and instance.Namespace) to format using
the containerPort constant from constants.go, and set the API_PORT env var value
to the string form of that same containerPort constant (convert the constant to
a string rather than hardcoding "8080") so both SERVICE_URL and API_PORT derive
from containerPort.

Comment on lines +112 to +115
{
Name: "SERVICE_URL",
Value: fmt.Sprintf("http://%s.%s.svc.cluster.local:8080", instance.Name, instance.Namespace),
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# First, let's examine the specific file and context around lines 112-115
echo "=== Context around deployment.go lines 112-115 ==="
sed -n '100,130p' controllers/evalhub/deployment.go

echo -e "\n=== Search for Service creation/definitions ==="
rg -n --type=go 'corev1\.Service|Kind.*Service' -C 3

echo -e "\n=== Search for port-related constants and configurations ==="
rg -n --type=go 'containerPort|API_PORT|ServicePort|8080' -B 2 -A 2

echo -e "\n=== Check entire deployment.go for port references ==="
rg -n --type=go ':8080|8080' controllers/evalhub/deployment.go -C 2

Repository: trustyai-explainability/trustyai-service-operator

Length of output: 50405


🏁 Script executed:

#!/bin/bash
# Find containerPort definition in deployment.go
echo "=== Full deployment.go file to find containerPort definition ==="
cat -n controllers/evalhub/deployment.go | head -150

echo -e "\n=== Search for containerPort variable initialization ==="
rg -n 'containerPort\s*:?=' controllers/evalhub/deployment.go -B 2 -A 2

echo -e "\n=== Check if there's a constants file for EvalHub ==="
fd -e go . controllers/evalhub/ | grep -i const

echo -e "\n=== Look for any port constants in evalhub ==="
rg -n 'const.*[Pp]ort|8080' controllers/evalhub/deployment.go -B 1 -A 1

Repository: trustyai-explainability/trustyai-service-operator

Length of output: 5889


🏁 Script executed:

#!/bin/bash
# Check the constants.go file in evalhub
echo "=== evalhub/constants.go ==="
cat -n controllers/evalhub/constants.go

echo -e "\n=== Search for containerPort, API_PORT definitions across entire evalhub ==="
rg -n 'containerPort|apiPort|const.*Port|8080' controllers/evalhub/ --type=go | head -50

Repository: trustyai-explainability/trustyai-service-operator

Length of output: 4071


Derive SERVICE_URL and API_PORT from the port constant.

The SERVICE_URL hardcodes port 8080 in the fmt.Sprintf, and API_PORT hardcodes it as a string. A containerPort constant already exists in constants.go (line 17). To keep these in sync and avoid drift if the port changes, use the constant instead.

🔧 Suggested fix
 		{
 			Name:  "API_PORT",
-			Value: "8080",
+			Value: fmt.Sprintf("%d", containerPort),
 		},
 		{
 			Name:  "SERVICE_URL",
-			Value: fmt.Sprintf("http://%s.%s.svc.cluster.local:8080", instance.Name, instance.Namespace),
+			Value: fmt.Sprintf("http://%s.%s.svc.cluster.local:%d", instance.Name, instance.Namespace, containerPort),
 		},
📝 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
{
Name: "SERVICE_URL",
Value: fmt.Sprintf("http://%s.%s.svc.cluster.local:8080", instance.Name, instance.Namespace),
},
{
Name: "SERVICE_URL",
Value: fmt.Sprintf("http://%s.%s.svc.cluster.local:%d", instance.Name, instance.Namespace, containerPort),
},
🤖 Prompt for AI Agents
In `@controllers/evalhub/deployment.go` around lines 112 - 115, Replace the
hardcoded "8080" with the shared containerPort constant: change the SERVICE_URL
env var construction (the fmt.Sprintf call that uses instance.Name and
instance.Namespace) to format using the containerPort constant from
constants.go, and set the API_PORT env var value to the string form of that same
containerPort constant (convert the constant to a string rather than hardcoding
"8080") so both SERVICE_URL and API_PORT derive from containerPort.

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Mar 18, 2026

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

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.

1 participant