Skip to content

Feat expose deployment ingress #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

roylee17
Copy link

@roylee17 roylee17 commented Jun 15, 2025

Add ingress environment variables to containers

Fixes akash-network/support#44

Summary

This PR adds two new environment variables to deployment containers to expose ingress information, enabling applications to discover their externally accessible URLs and provider ingress addresses.

Changes

Environment Variables Added

  • AKASH_INGRESS_URIS: Comma-separated list of all ingress URIs for the deployment
  • AKASH_PROVIDER_INGRESS: Provider's ingress address for nodePort services

Implementation Details

  • Location: cluster/kube/builder/workload.go
  • Method: Direct environment variable injection during workload creation
  • Function: collectIngressURIs() - Gathers all ingress-capable service exposures
  • Integration: Seamlessly integrated into existing addEnvVarsForDeployment() function

Features

Comprehensive URI Collection: Handles both provider-generated static hosts and custom SDL-specified hosts
Protocol Detection: Automatically detects HTTP/HTTPS based on port 443
Port Handling: Correctly formats URIs with non-standard ports
Zero Runtime Overhead: Variables computed at deployment creation time
Backwards Compatible: No breaking changes to existing functionality

Example Usage

For a deployment with ingress services, containers will receive:

# Multiple ingress URIs
AKASH_INGRESS_URIS="http://app.provider.com,https://myapp.example.com:8443"

# Provider ingress address for nodePort services  
AKASH_PROVIDER_INGRESS="provider.akash.network"

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Deployment containers now automatically receive environment variables with ingress-related information, enabling applications to discover their external endpoints programmatically.
  - Two new environment variables are available: one listing accessible ingress URIs and another providing the provider's public hostname or IP address.
- **Documentation**
  - Added comprehensive documentation explaining ingress environment variables, usage examples, limitations, compatibility, and future enhancement suggestions.
- **Tests**
  - Extended and added tests to verify correct injection of ingress environment variables into deployment containers and ensure URI deduplication and protocol handling correctness.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

@roylee17 roylee17 requested review from boz and troian as code owners June 15, 2025 16:16
Copy link

coderabbitai bot commented Jun 15, 2025

Walkthrough

This change introduces support for injecting ingress-related environment variables into Akash Provider deployment containers. It adds logic to collect all ingress URIs and the provider's ingress address, sets them as environment variables, documents the feature, and extends tests to verify correct variable injection.

Changes

Files/Groups Change Summary
_docs/ingress-environment-variables.md Adds documentation describing ingress environment variables, usage examples, and implementation notes.
cluster/kube/builder/builder.go Adds constants for AKASH_INGRESS_URIS and AKASH_PROVIDER_INGRESS environment variables.
cluster/kube/builder/workload.go Implements logic to collect ingress URIs and inject them, along with provider ingress, as environment variables.
cluster/kube/builder/deployment_test.go Adds and extends tests to verify environment variable injection for ingress URIs and provider ingress.
cluster/kube/builder/workload_test.go Adds unit tests for ingress URI collection, protocol detection, and deduplication logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Deployment YAML (SDL)
    participant Workload Builder
    participant K8s Container

    User->>Deployment YAML (SDL): Defines exposes/ingresses
    Deployment YAML (SDL)->>Workload Builder: Deployment spec parsed
    Workload Builder->>Workload Builder: collectIngressURIs()
    Workload Builder->>Workload Builder: Determine static/custom hosts, protocols, ports
    Workload Builder->>Workload Builder: Compose ingress URIs
    Workload Builder->>K8s Container: Inject AKASH_INGRESS_URIS, AKASH_PROVIDER_INGRESS env vars
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Expose all deployment's ingress HTTP URIs in the container via environment variable (AKASH_INGRESS_URIS) (#44)
Expose provider's ingress address as environment variable (AKASH_PROVIDER_INGRESS) (#44)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Poem

In fields of code where containers run free,
A rabbit hops with glee—
"Now every ingress URI,
Will greet your app inside, oh my!
And with the provider’s address in tow,
Your service will always know
Where the outside breezes blow!" 🐇🌐


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aa7ffe4 and 9ce59a4.

📒 Files selected for processing (5)
  • _docs/ingress-environment-variables.md (1 hunks)
  • cluster/kube/builder/builder.go (1 hunks)
  • cluster/kube/builder/deployment_test.go (1 hunks)
  • cluster/kube/builder/workload.go (4 hunks)
  • cluster/kube/builder/workload_test.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • _docs/ingress-environment-variables.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • cluster/kube/builder/builder.go
  • cluster/kube/builder/deployment_test.go
  • cluster/kube/builder/workload.go
  • cluster/kube/builder/workload_test.go
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

🧹 Nitpick comments (3)
cluster/kube/builder/deployment_test.go (2)

81-86: Variable name shadows imported package

TestDeploySetsEnvironmentVariables declares

sdl, err := sdl.ReadFile(...)

shadowing the imported github.com/akash-network/node/sdl package for the rest of the function.
While it compiles, it is easy to mis-read and prevents future package references.

-   sdl, err := sdl.ReadFile(...)
+   sdlBytes, err := sdl.ReadFile(...)

Same issue exists in the new test below – please rename both locals.


88-142: Strengthen new ingress test & reduce duplication

The new test duplicates ~40 lines of setup already present above. Extract a small
helper that returns env map[string]string to keep tests concise.

Additionally, the purpose of this test is to validate AKASH_INGRESS_URIS, yet
it only asserts AKASH_PROVIDER_INGRESS. Consider asserting that the variable
exists and is non-empty (or matches an expected value derived from the test
fixture). Otherwise the test may pass even if URI collection silently breaks.

_docs/ingress-environment-variables.md (1)

180-182: Grammar nit – hyphenate compound adjective

“Fully backward compatible” → “Fully backward-compatible”.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~181-~181: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ... providers Compatibility: - Fully backward compatible - Optional usage - applications can ign...

(EN_COMPOUND_ADJECTIVE_INTERNAL)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 04097f4 and 00b2c90.

📒 Files selected for processing (4)
  • _docs/ingress-environment-variables.md (1 hunks)
  • cluster/kube/builder/builder.go (1 hunks)
  • cluster/kube/builder/deployment_test.go (1 hunks)
  • cluster/kube/builder/workload.go (3 hunks)
🧰 Additional context used
🪛 golangci-lint (1.64.8)
cluster/kube/builder/workload.go

423-423: string https has 3 occurrences, make it a constant

(goconst)


421-421: string http has 3 occurrences, make it a constant

(goconst)

🪛 LanguageTool
_docs/ingress-environment-variables.md

[uncategorized] ~181-~181: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ... providers Compatibility: - Fully backward compatible - Optional usage - applications can ign...

(EN_COMPOUND_ADJECTIVE_INTERNAL)

🔇 Additional comments (2)
cluster/kube/builder/builder.go (1)

60-62: New env-var constants fit existing naming scheme – LGTM

The additions are self-explanatory and keep the AKASH_* convention consistent.
No concerns here.

cluster/kube/builder/workload.go (1)

467-477: Minor: skip env insertion when hostname empty

The guard already checks b.settings.ClusterPublicHostname != "", so the call to
addIfNotPresent never receives an empty value. Good.

(Just noting this because the earlier block adds AKASH_CLUSTER_PUBLIC_HOSTNAME unconditionally – the asymmetry is intentional and fine.)

@roylee17 roylee17 force-pushed the feat-expose-deployment-ingress branch from 00b2c90 to aa7ffe4 Compare June 15, 2025 16:40
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: 0

🧹 Nitpick comments (4)
cluster/kube/builder/workload_test.go (3)

12-18: Run tests concurrently with t.Parallel()

All test functions in this file are independent and have no shared state. Calling t.Parallel() at the top of each test speeds up the suite and is idiomatic in Go.

 func TestCollectIngressURIsDeduplication(t *testing.T) {
-	log := testutil.Logger(t)
+	t.Parallel()
+	log := testutil.Logger(t)

(Apply the same one-liner to the other test functions.)


66-75: Simplify duplicate-detection assertion

Creating a map and looping manually works, but require.ElementsMatch (or assert.ElementsMatch) is clearer and less error-prone for set comparisons.

-// Basic test - ensure no duplicates exist
-uriSet := make(map[string]bool)
-for _, uri := range uris {
-	require.False(t, uriSet[uri], "Found duplicate URI: %s", uri)
-	uriSet[uri] = true
-}
-
-// Test passes if we have some URIs and no duplicates
-require.Greater(t, len(uris), 0, "collectIngressURIs should return URIs for the configured ingress")
+require.Greater(t, len(uris), 0, "collectIngressURIs should return at least one URI")
+require.ElementsMatch(t, uris, uris, "collectIngressURIs returned duplicates") // ElementsMatch de-dupes internally

111-136: Constant re-evaluation duplicates earlier test

TestProtocolConstantsUsage largely re-executes logic already covered by TestProtocolConstants and TestDeduplicationLogic. If the intent is to unit-test collectIngressURIs, consider turning this into a table-driven test of that function directly to avoid redundant coverage.

Not blocking, but pruning duplicated tests keeps the suite lean.

_docs/ingress-environment-variables.md (1)

179-183: Hyphenate compound adjective

“Backward-compatible” should be hyphenated when used as a compound adjective.

- - Fully backward compatible
+ - Fully backward-compatible
🧰 Tools
🪛 LanguageTool

[uncategorized] ~181-~181: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ... providers Compatibility: - Fully backward compatible - Optional usage - applications can ign...

(EN_COMPOUND_ADJECTIVE_INTERNAL)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 00b2c90 and aa7ffe4.

📒 Files selected for processing (5)
  • _docs/ingress-environment-variables.md (1 hunks)
  • cluster/kube/builder/builder.go (1 hunks)
  • cluster/kube/builder/deployment_test.go (1 hunks)
  • cluster/kube/builder/workload.go (4 hunks)
  • cluster/kube/builder/workload_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • cluster/kube/builder/deployment_test.go
  • cluster/kube/builder/builder.go
  • cluster/kube/builder/workload.go
🧰 Additional context used
🪛 LanguageTool
_docs/ingress-environment-variables.md

[uncategorized] ~181-~181: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ... providers Compatibility: - Fully backward compatible - Optional usage - applications can ign...

(EN_COMPOUND_ADJECTIVE_INTERNAL)

🔇 Additional comments (1)
cluster/kube/builder/workload_test.go (1)

86-109: Unit test doesn’t reflect real-world normalisation

collectIngressURIs omits default ports (80/443). In this synthetic test the URI https://example.com:443 would never be produced by the production code, so the scenario is not representative and risks future confusion.

Consider changing the sample data to match the real normalisation (https://example.com) or explicitly documenting why the port is kept here.

@roylee17 roylee17 force-pushed the feat-expose-deployment-ingress branch from aa7ffe4 to 22e6c44 Compare June 15, 2025 16:52
roylee17 added 2 commits June 15, 2025 12:55
This change adds two new environment variables that are automatically
injected into all containers in a deployment:

1. AKASH_INGRESS_URIS: Comma-separated list of all ingress URIs
   for the deployment, including both provider-generated static hosts
   and custom hosts specified in the SDL

2. AKASH_PROVIDER_INGRESS: The provider's public hostname/IP address
   that can be used for nodePort services

These environment variables enable applications to:
- Discover their own ingress endpoints programmatically
- Build correct URLs for inter-service communication
- Configure callback URLs and webhooks dynamically
- Implement health checks and service discovery

The implementation automatically detects ingress-capable services,
handles both HTTP and HTTPS protocols, and properly formats URLs
with or without non-standard ports.
@roylee17 roylee17 force-pushed the feat-expose-deployment-ingress branch from 22e6c44 to 9ce59a4 Compare June 15, 2025 16:55
@pcfreak30
Copy link

pcfreak30 commented Jun 23, 2025

see #273. I basically already did about half of this? though the more important part, IMO, is the node ports which are more involved and require a init script.

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.

expose all deployment's ingresses to the container
2 participants