Where does the environment variable is set?

Hi all
The https://istio.io/docs/examples/bookinfo/ sample, there are environment variables for example in the productpage.py file:

servicesDomain = "" if (os.environ.get("SERVICES_DOMAIN") is None) else "." + os.environ.get("SERVICES_DOMAIN")

detailsHostname = "details" if (os.environ.get("DETAILS_HOSTNAME") is None) else os.environ.get("DETAILS_HOSTNAME")

ratingsHostname = "ratings" if (os.environ.get("RATINGS_HOSTNAME") is None) else os.environ.get("RATINGS_HOSTNAME")

reviewsHostname = "reviews" if (os.environ.get("REVIEWS_HOSTNAME") is None) else os.environ.get("REVIEWS_HOSTNAME") 

I could not figure out, where those variables are set.
Could someone please tell me?

Thanks a lot

I would check out the Preparing for Development Wiki guide for Istio below.

The Wiki guide does not say much about, how RATINGS_HOSTNAME is setup or environment variables are setup.

What I am trying to achieve is, I would like to create two services, for example Foo and Boo. Foo will call Boo and it has to know the address of Boo. How can I find out the address or how to define it for Boo.

I deployed the app BookInfo on my k8s cluster and it works as expected.

Looking at the review app and how the url of the ratings app is build:

private final static String services_domain = System.getenv("SERVICES_DOMAIN") == null ? "" : ("." + System.getenv("SERVICES_DOMAIN"));
private final static String ratings_hostname = System.getenv("RATINGS_HOSTNAME") == null ? "ratings" : System.getenv("RATINGS_HOSTNAME");
private final static String ratings_service = "http://" + ratings_hostname + services_domain + ":9080/ratings";

Those environment variables have to be set somewhere before the app is deployed.

Thanks

Hi, actually they are not set anywhere in the examples. They can be used to change example behavior if You need it.

But how the review app knows, which address that rating has? The review app has to know the url of rating app.

There in code are default values if env not set

private final static String services_domain = System.getenv("SERVICES_DOMAIN") == null ? "" : ("." + System.getenv("SERVICES_DOMAIN"));
private final static String ratings_hostname = System.getenv("RATINGS_HOSTNAME") == null ? "ratings" : System.getenv("RATINGS_HOSTNAME");
private final static String ratings_service = "http://" + ratings_hostname + services_domain + ":9080/ratings";

actual url if not set will be

http://ratings:9080/ratings

1 Like

Thanks a lot, I am appreciate a lot.

The discussion is helpful, since I did the same thing and had the same confusion.

▶ rg SERVICES_DOMAIN
src/productpage/productpage.py
60:servicesDomain = "" if (os.environ.get("SERVICES_DOMAIN") is None) else "." + os.environ.get("SERVICES_DOMAIN")

src/reviews/reviews-application/src/main/java/application/rest/LibertyRestEndpoint.java
41:    private final static String services_domain = System.getenv("SERVICES_DOMAIN") == null ? "" : ("." + System.getenv("SERVICES_DOMAIN"));

And it’s clear for me now, thanks a lot!

However, I desire to know what’s the best practice to set the env, actually. For example, in deployment yam?

1 Like