Skip to content

Conversation

ifbyol
Copy link
Member

@ifbyol ifbyol commented Apr 10, 2025

PROD-344

Description

This PR adds two environment variables to the divert drivers (nginx and istio) to provide information about the shared and diverted environments:

  • OKTETO_SHARED_ENVIRONMENT: Contains the namespace of the shared environment (d.divert.Namespace)
  • OKTETO_DIVERTED_ENVIRONMENT: Contains the namespace of the diverted environment (d.namespace)

Changes made:

  1. Added two new constants in pkg/constants/constants.go:

    • OktetoSharedEnvironmentEnvVar
    • OktetoDivertedEnvironmentEnvVar
  2. Modified the UpdatePod function in both divert drivers:

    • pkg/divert/nginx/divert.go
    • pkg/divert/istio/divert.go
  3. Added a helper function updateEnvVar to both drivers to handle adding or updating environment variables.

  4. Added comprehensive unit tests for both drivers:

    • Test_updateEnvVar: Tests the helper function
    • Test_UpdatePod: Tests the main functionality with various scenarios

Testing:

  • Added unit tests for all new functionality
  • All existing tests continue to pass

This change will allow applications running in diverted environments to be aware of both the shared and diverted namespaces, which can be useful for various integration scenarios.

@ifbyol ifbyol requested a review from a team as a code owner April 10, 2025 13:58
ifbyol added 2 commits April 10, 2025 16:00
Signed-off-by: Nacho Fuertes <nacho@okteto.com>
Signed-off-by: Nacho Fuertes <nacho@okteto.com>
Copy link

codecov bot commented Apr 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 48.84%. Comparing base (11e05ab) to head (223d7eb).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4699      +/-   ##
==========================================
+ Coverage   48.75%   48.84%   +0.08%     
==========================================
  Files         354      354              
  Lines       29480    29510      +30     
==========================================
+ Hits        14374    14415      +41     
+ Misses      13960    13949      -11     
  Partials     1146     1146              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Nacho Fuertes <nacho@okteto.com>
@ifbyol ifbyol added the run-e2e When used on a PR run windows & unix e2e label Apr 11, 2025
@jLopezbarb
Copy link
Contributor

Tested and it's working but I have one question.

If I do a okteto up should the init containers (the ones generated by okteto) have the env vars?

@ifbyol
Copy link
Member Author

ifbyol commented Apr 11, 2025

Tested and it's working but I have one question.

If I do a okteto up should the init containers (the ones generated by okteto) have the env vars?

I don't think so. The idea of having those environment variables is that user's application might used them in some scenarios, like to decide to which queue should be connected based on a message header. In our init containers, at least for now, we don't need those environment variables, as our logic doesn't need them. But for the ones specified by users, might be necessary, for example, if they want to pre-load some data in a database

@ifbyol ifbyol merged commit 8e49dfb into master Apr 14, 2025
29 checks passed
@ifbyol ifbyol deleted the feature/add-divert-env-vars branch April 14, 2025 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release/internal run-e2e When used on a PR run windows & unix e2e
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants