Kubernetes If/Or Statement in Configmap

3/18/2020

Im trying to write an IF statement in my configmap but I cannot find any sites that combine and IF statement with OR. For example:

      <% if @project_name == 'site-a' || 'site-b' %>
      security:
        default-groups:
          - reader # Read only for everybody
      <% end %>

Would this be accurate? Ideally, if the variable is called site a or site b. I can probably do an else block but it's not necessary.

Thanks.

-- b0uncyfr0
configmap
if-statement
kubernetes

1 Answer

3/19/2020

The initial code was not using the comparison correctly. In the first line you only evaluated the the project in the first part and assumed that computer will know that the same operation is applied to both values.

<% if @project_name == 'site-a' || 'site-b' %>

The operator doesn't checks if a value is a member of a set which means you should check each @project_name explicitly so that both values are compared:

<% if @project_name == 'site-a' || @project_name == 'site-b' %>
-- acid_fuji
Source: StackOverflow