Skip to content

[Bug] The sidecar doesn't work well with env injected by mutation hooks #377

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

Open
mnencia opened this issue May 30, 2025 · 0 comments · May be fixed by #378
Open

[Bug] The sidecar doesn't work well with env injected by mutation hooks #377

mnencia opened this issue May 30, 2025 · 0 comments · May be fixed by #378
Labels
bug Something isn't working

Comments

@mnencia
Copy link
Member

mnencia commented May 30, 2025

After #354, released in version 0.4.1, the sidecar injection conflicts with any MutatingWebhookConfiguration that adds environment variables to all containers. This issue is affecting all EKS users.

This is the error returned by the API server:

cannot updated metadata on pods: Pod "postgres-cluster-example-1" is invalid: spec: Forbidden: pod updates may not change fields other than `spec.containers[*].image`,`spec.initContainers[*].image`,`spec.activeDeadlineSeconds`,`spec.tolerations` (only additions to existing tolerations),`spec.terminationGracePeriodSeconds` (allow it to be set to 1 if it was previously negative)
  core.PodSpec{
  	Volumes: {{Name: "eks-pod-identity-token", VolumeSource: {Projected: &{Sources: {{ServiceAccountToken: &{Audience: "pods.eks.amazonaws.com", ExpirationSeconds: 80277, Path: "eks-pod-identity-token"}}}, DefaultMode: &420}}}, {Name: "pgdata", VolumeSource: {PersistentVolumeClaim: &{ClaimName: "postgres-cluster-example-1"}}}, {Name: "scratch-data", VolumeSource: {EmptyDir: &{}}}, {Name: "shm", VolumeSource: {EmptyDir: &{Medium: "Memory"}}}, ...},
  	InitContainers: []core.Container{
  		{Name: "bootstrap-controller", Image: "ghcr.io/cloudnative-pg/cloudnative-pg:1.26.0", Command: {"/manager", "bootstrap", "/controller/manager", "--log-level=info"}, Env: {{Name: "AWS_STS_REGIONAL_ENDPOINTS", Value: "regional"}, {Name: "AWS_DEFAULT_REGION", Value: "us-east-1"}, {Name: "AWS_REGION", Value: "us-east-1"}, {Name: "AWS_CONTAINER_CREDENTIALS_FULL_URI", Value: "http://169.254.170.23/v1/credentials"}, ...}, ...},
  		{
  			... // 5 identical fields
  			Ports:   nil,
  			EnvFrom: nil,
  			Env: []core.EnvVar{
  				... // 6 identical elements
  				{Name: "PGHOST", Value: "/controller/run"},
  				{Name: "TMPDIR", Value: "/controller/tmp"},
- 				{Name: "SPOOL_DIRECTORY", Value: "/controller/wal-restore-spool"},
- 				{Name: "CUSTOM_CNPG_GROUP", Value: "postgresql.cnpg.io"},
- 				{Name: "CUSTOM_CNPG_VERSION", Value: "v1"},
  				{Name: "AWS_STS_REGIONAL_ENDPOINTS", Value: "regional"},
  				{Name: "AWS_DEFAULT_REGION", Value: "us-east-1"},
  				{Name: "AWS_REGION", Value: "us-east-1"},
  				{Name: "AWS_CONTAINER_CREDENTIALS_FULL_URI", Value: "http://169.254.170.23/v1/credentials"},
  				{Name: "AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE", Value: "/var/run/secrets/pods.eks.amazonaws.com/serviceaccount/eks-pod-i"...},
+ 				{Name: "SPOOL_DIRECTORY", Value: "/controller/wal-restore-spool"},
+ 				{Name: "CUSTOM_CNPG_GROUP", Value: "postgresql.cnpg.io"},
+ 				{Name: "CUSTOM_CNPG_VERSION", Value: "v1"},
  			},
  			Resources:    {},
  			ResizePolicy: nil,
  			... // 14 identical fields
  		},
  	},
  	Containers:          {{Name: "postgres", Image: "ghcr.io/cloudnative-pg/postgresql:17.5-standard-bookworm", Command: {"/controller/manager", "instance", "run", "--status-port-tls", ...}, Ports: {{Name: "postgresql", ContainerPort: 5432, Protocol: "TCP"}, {Name: "metrics", ContainerPort: 9187, Protocol: "TCP"}, {Name: "status", ContainerPort: 8000, Protocol: "TCP"}}, ...}},
  	EphemeralContainers: nil,
  	... // 30 identical fields
  }

When creating the sidecar configuration, we should refrain from altering the order of environment variables if all required variables are already included in the configuration.

@mnencia mnencia added the bug Something isn't working label May 30, 2025
mnencia added a commit that referenced this issue May 30, 2025
@mnencia mnencia linked a pull request May 30, 2025 that will close this issue
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