question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document valid schema for pod's set_spec function and how to set environment variables

See original GitHub issue

I am trying without any success to add an environment variable to a charm I’m building for OpenFaaS:

“env” (as per the Kubernetes schema) fails

“envConfig” as seen in the Istio example also fails.

https://github.com/juju-solutions/bundle-istio/blob/master/charms/istio-ingressgateway/reactive/charm.py#L130

ops.model.ModelError: b'ERROR json: unknown field "env"\n'
ops.model.ModelError: b'ERROR json: unknown field "envConfig"\n'
ops.model.ModelError: b'ERROR json: unknown field "envs"\n'

Attempted Charm:

    def _on_config_changed(self, _=None):
        pod_spec = self._build_pod_spec()
        self.model.pod.set_spec(pod_spec)
        self.unit.status = ActiveStatus("OpenFaaS pod ready.")

    def _build_pod_spec(self):
        spec = {
            "containers": [
                {
                    "name": self.app.name,
                    "imageDetails": {"imagePath": "openfaas/gateway:0.20.2"},
                    "ports": [{"containerPort": 8080, "protocol": "TCP"}],
                    "files": [],
                    "config": {},  # used to store hashes of config file text
                    "env": [
                        {"functions_provider_url": "192.168.0.15:8081"},
                        {"direct_functions": "false"},
                        {"basic_auth": "false"},
                        {"faas_prometheus_host": "192.168.0.35"},
                        {"faas_prometheus_port": "9090"},
                    ]
                }
            ]
        }

Kubernetes schema:

      containers:
      - name: gateway
        resources:
            requests:
              cpu: 50m
              memory: 120Mi
        image: openfaas/gateway:0.20.2
        imagePullPolicy: Always
        securityContext:
          readOnlyRootFilesystem: true
          runAsUser: 10001
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8080
          timeoutSeconds: 5
        readinessProbe:
          httpGet:
            path: /healthz
            port: 8080
          timeoutSeconds: 5
        env:
        - name: read_timeout
          value: "65s"
        - name: write_timeout
          value: "65s"
        - name: upstream_timeout

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
alexelliscommented, Dec 7, 2020

Unfortunately that code gives the error I shared above, would you be open to giving it a try to see if you can figure out what I’ve missed? https://github.com/alexellis/openfaas-charm-example

0reactions
lukemarsdencommented, Jan 20, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Define Environment Variables for a Container - Kubernetes
This page shows how to define environment variables for a container in a Kubernetes Pod. Before you begin. You need to have a...
Read more >
How To Handle Environment Variables With Kubernetes?
There are two ways to define environment variables with Kubernetes: by setting them directly in a configuration file, from an external ...
Read more >
Use environment variables in solutions - Power Apps
Environment variables allow you to specify which of these different external references should be updated as the application is moved across ...
Read more >
pod's name from an environment variables defined in yaml
Kubernetes allows you to set environment variables using the values of other fields in the Pod definition that are only available at the ......
Read more >
Using RabbitMQ Cluster Kubernetes Operator
If Pod security policies are not enabled, skip to Create a RabbitMQ Instance below. The Role and RoleBinding should be created before a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found