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

Load the configmap changes into the code dynamically in Micronaut without pod restart is not happening. #788

Open
sasirekhamurakonda opened this issue Nov 17, 2024 · 0 comments

Comments

@sasirekhamurakonda
Copy link

Issue description

I want to load the config changes into the pod and start using it without pod restart in Micronaut. I have created a sample application to try this out. Used Minikube to the test the changes.

Created 2 simple classes along with the Application.java
DummyConfiguration.java

@Refreshable
@ConfigurationProperties("dummy-configuration")
public class DummyConfiguration {
    private String color;

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }
}

ConfigResource.java

@Controller("/config")
public class ConfigResource{

    private final DummyConfiguration dummyConfiguration;

    public ConfigResource(DummyConfiguration dummyConfiguration) {
        this.dummyConfiguration = dummyConfiguration;
    }

    @Get("/color")
    public String getColor() {
        return "The color is: " + dummyConfiguration.getColor();
    }
}

Application.java

import io.micronaut.runtime.Micronaut;

public class Application {

    public static void main(String[] args) {
        Micronaut.run(Application.class, args);
    }
}

Dockerfile

FROM openjdk:18-alpine

EXPOSE 8080

COPY target/k8s-0.1.jar /etc/configdemo.jar
COPY target/classes/application.yml /etc/configuration/


WORKDIR /etc

ENTRYPOINT ["java", "-Dmicronaut.config.files=file:/etc/configuration/application.yml", "-jar", "configdemo.jar"]

configmap.yml

apiVersion: v1
kind: ConfigMap
metadata:
  name: k8s-config
data:
  bootstrap.yaml: |
    kubernetes:
      client:
        config-maps:
          watch: true
        config:
          enabled: true
          namespace: default

  config.yaml: |
    micronaut:
      application:
        name: k8s
      config-client:
        enabled: true

    dummy-configuration:
      color: white

And mounted the configmap.yml to the deployment.yml
Deployment.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: k8s
spec:
  replicas: 1
  selector:
    matchLabels:
      app: k8s
  template:
    metadata:
      labels:
        app: k8s
    spec:
      containers:
        - name: k8s
          image: k8s:1
          imagePullPolicy: Never
          env:
            - name: MICRONAUT_CONFIG_FILES
              value: "/etc/configuration/bootstrap.yml,/etc/configuration/application.yml"
          ports:
            - containerPort: 8080
          volumeMounts:
            - name: config-volume
              mountPath: /etc/configuration
      volumes:
        - name: config-volume
          configMap:
            name: k8s-config

According to the micronaut ideally the code also should start populating the new values which isn't happening(https://micronaut-projects.github.io/micronaut-kubernetes/snapshot/guide/). I have changed the color in the configmap and then applied it which isn't reflecting when I am calling the api.
I am new to Micronaut. Not sure what am I missing out. Thanks in Advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant