Skip to content
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

Environment variable names are silently changed to snake_case #4265

Closed
3 tasks done
fernandrone opened this issue Oct 28, 2024 · 0 comments · Fixed by #4267
Closed
3 tasks done

Environment variable names are silently changed to snake_case #4265

fernandrone opened this issue Oct 28, 2024 · 0 comments · Fixed by #4267
Labels
bug Something isn't working

Comments

@fernandrone
Copy link
Contributor

fernandrone commented Oct 28, 2024

Component

server

Describe the bug

One of our pipelines runs an elasticsearch container as a service. For some reason elasticsearch uses "dot case format" for environment variables, as can be seen in their official docker-compose file:

    environment:
      - node.name=es01
      - cluster.name=${CLUSTER_NAME}
      - cluster.initial_master_nodes=es01,es02,es03

This is how the service is configured in woodpecker:

services:
  elastic:
    image: public.ecr.aws/elastic/elasticsearch:7.17.7
    environment:
      - node.name=elasticsearch
      - bootstrap.memory_lock=true
      - discovery.type=single-node
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ports:
      - 9200/tcp
      - 9300/tcp

This worked fine for a long time. However since we updated Woodpecker from 2.3.0 to 2.7.0 the variables started to be converted from "dot case" to "snake case". If we describe the pods in Kubernetes we can see:

    Environment:
       node_name:         elasticsearch

This is causing the pipeline to fail, as we can't properly set the cluster's node name and the other steps executing in this pipeline won't be able to find the elasticsearch service in the cluster.

The issue seems to be related to this function: https://github.com/qwerty287/woodpecker/blob/main/pipeline/frontend/yaml/compiler/settings/params.go#L47

// sanitizeParamKey formats the environment variable key.
func sanitizeParamKey(prefix string, upper bool, k string) string {
	r := strings.ReplaceAll(strings.ReplaceAll(k, ".", "_"), "-", "_")
	if upper {
		r = strings.ToUpper(r)
	}
	return prefix + r
}

I'm not 100% sure why it worked in 2.3.0 and stopped working after the update but I saw #3515 which seems related.

I think that #3406 which also caused that issue and was introduced in 2.4.0 might have caused this issue too. And then its fix #3516 only addressed the uppercase element, but not the dot case to snake case conversion.

Steps to reproduce

  1. Install Woodpecker 2.7.0+ (probably reproducible starting at 2.4.0)
  2. Create a pipeline using
services:
  elastic:
    image: public.ecr.aws/elastic/elasticsearch:7.17.7
    environment:
      - node.name=elasticsearch
      - bootstrap.memory_lock=true
      - discovery.type=single-node
    ports:
      - 9200/tcp
      - 9300/tcp
  1. See that env vars are replaced to snake_case

Expected behavior

No response

System Info

Woodpecker 2.7.0+, Kubernetes installation

Additional context

No response

Validations

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Checked that the bug isn't fixed in the next version already [https://woodpecker-ci.org/faq#which-version-of-woodpecker-should-i-use]
@fernandrone fernandrone added the bug Something isn't working label Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant