Skip to content

Commit

Permalink
🐛 ENVAR replaced when defined. (#648)
Browse files Browse the repository at this point in the history
ENVAR replaced (only) when defined. This prevents replacing variables
not associated with ENVAR. For example, in the addon-analyzer, requested
resources are expressed in the metadata as $(var).

For example:
```
  metadata:
    provider:
      address: localhost:$(PORT)
      initConfig:
      - providerSpecificConfig:
          bundles: /jdtls/java-analyzer-bundle/java-analyzer-bundle.core/target/java-analyzer-bundle.core-1.0.0-SNAPSHOT.jar
          depOpenSourceLabelsFile: /usr/local/etc/maven.default.index
          lspServerPath: /jdtls/bin/jdtls
          mavenSettingsFile: $(maven.settings.path)
      name: java
    resources:
    - fields:
      - key: maven.settings.path
        name: settings
        path: /shared/creds/maven/settings.xml
      selector: identity:kind=maven
  selector: tag:Language=Java || !tag:Language
```
An alternative would be a different syntax. Perhaps $((var)). $[var]
$/maven.settings.path/
The `$(maven.settings.path)` should not be replaced with "" since it's
not an ENVAR.

Signed-off-by: Jeff Ortel <jortel@redhat.com>
  • Loading branch information
jortel committed Jun 10, 2024
1 parent 6e91e64 commit a2365a6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion addon/injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,15 @@ func (r *EnvInjector) inject(in any) (out any) {
if len(match) < 3 {
break
}
k := match[2]
v := r.env[k]
if v == "" {
break
}
node = strings.Replace(
node,
match[0],
r.env[match[2]],
v,
-1)
}
out = node
Expand Down

0 comments on commit a2365a6

Please sign in to comment.