spring-cloud-kubernetes icon indicating copy to clipboard operation
spring-cloud-kubernetes copied to clipboard

Questions about reload properties

Open audtjddld opened this issue 1 year ago • 7 comments

Describe the bug Please provide details of the problem, including the version of Spring Cloud that you are using.

Is not a bug.

I try to reload properties with spring cloud kubernates library.

Here is my configuration

gradle

implementation("org.springframework.cloud:spring-cloud-starter-kubernetes-fabric8-all:3.1.2")

properties

spring:
  config:
    import: 'kubernetes:'
  cloud:
    kubernetes:
      config:
        name: config-name
        namespace: config-name-namespace
        sources:
          - name: test.message
        enabled: true
      reload:
        enabled: true
        strategy: refresh
        mode: event
        namespaces: config-name-namespace

source code

@Configuration
@ConfigurationProperties(prefix = "test")
class SampleProperty {
    var message: String = ""
}


@RefreshScope
@Component
class SampleService(
    private val sampleProperty: SampleProperty
) {
    fun test(): String {
        return "The Message is ${sampleProperty.message}"
    }

    @Scheduled(fixedRate = 5000)
    fun print() {
        println(test())
    }
}

I used kustomize.

k8s manifests

role

apiVersion: v1
kind: ServiceAccount
metadata:
  name: config-service
  namespace: config-name-namespace

---

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: config-role
rules:
  - apiGroups: [""]
    resources: ["configmaps", "pods", "services", "endpoints", "secrets"]
    verbs: ["get", "list", "watch"]

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: config-name
  namespace: config-name-namespace
subjects:
- kind: ServiceAccount
  name: config-service
  apiGroup: ""
roleRef:
  kind: ClusterRole
  name: config-role
  apiGroup: rbac.authorization.k8s.io

I changed a property in the k8s configuration map. I found this log

2024-06-07T18:52:00.825+09:00 DEBUG 1 --- [-253011924-pool-2-thread-3] o.s.c.k.c.c.reload.ConfigReloadUtil      : findPropertySources : []
2024-06-07T18:52:00.825+09:00 DEBUG 1 --- [-253011924-pool-2-thread-3] o.s.c.k.c.c.reload.ConfigReloadUtil      : left size: 1
2024-06-07T18:52:00.825+09:00 DEBUG 1 --- [-253011924-pool-2-thread-3] o.s.c.k.c.c.reload.ConfigReloadUtil      : Fabric8ConfigMapPropertySource@128468998 {name='configmap.test.message.<namespace>, properties={}}
2024-06-07T18:52:00.825+09:00 DEBUG 1 --- [-253011924-pool-2-thread-3] o.s.c.k.c.c.reload.ConfigReloadUtil      : right size: 0
2024-06-07T18:52:00.825+09:00  WARN 1 --- [-253011924-pool-2-thread-3] o.s.c.k.c.c.reload.ConfigReloadUtil      : The current number of ConfigMap PropertySources does not match the ones loaded from Kubernetes - No reload will take place
2024-06-07T18:52:00.825+09:00 DEBUG 1 --- [-253011924-pool-2-thread-3] o.s.c.k.c.c.reload.ConfigReloadUtil      : No change detected in config maps/secrets, reload will not happen

So I checked the configuration map. I confirmed that it has changed.

It doesn't reload. Is there a problem with the information I set?

Note: I have changed the setup information to be different from what I am currently working with.

Sample If possible, please provide a test case or sample application that reproduces the problem. This makes it much easier for us to diagnose the problem and to verify that we have fixed it.

audtjddld avatar Jun 18 '24 11:06 audtjddld

Can you also provide your configmaps?

ryanjbaxter avatar Jun 18 '24 12:06 ryanjbaxter

Can you also provide your configmaps?

Here is my configmap

overlays/dev/config/application.properties

spring.profiles.active=dev
test.message=here test message

overlays/dev/configmap.yaml

apiVersion: builtin
kind: ConfigMapGenerator
metadata:
  name: config-name
behavior: merge
envs:
  - config/application.properties

base/configmap.yaml

apiVersion: builtin
kind: ConfigMapGenerator
metadata:
  name: config-name
options:
  disableNameSuffixHash: true
envs:
  - config/application.properties

generated configmap

apiVersion: v1
data:
  test.message: here test message
kind: ConfigMap
metadata:
  labels:
    app.kubernetes.io/name: config-name
    vector.dev/label: config-name-label
  name: config-name
  namespace: config-name-namespace

audtjddld avatar Jun 19 '24 01:06 audtjddld

Can you provide a sample that for example is a github repo, with clear instructions how to re-produce the issue, let's say to deploy it in minikube or kind?

wind57 avatar Jun 19 '24 08:06 wind57

I dont think this is correct

        sources:
          - name: test.message

That is the data in your config map. The sources.name property should be the name of the config map.

ryanjbaxter avatar Jun 19 '24 20:06 ryanjbaxter

Can you provide a sample that for example is a github repo, with clear instructions how to re-produce the issue, let's say to deploy it in minikube or kind?

Thank you for answer

The sample will probably take some time. (I have other things to do) I used the in-house kubernetes cloud to test it.

If the issue is open for a long time, it would be a good idea to close the issue and prepare the sample before reopening it.

audtjddld avatar Jun 20 '24 02:06 audtjddld

See my comment here I think that might help https://github.com/spring-cloud/spring-cloud-kubernetes/issues/1666#issuecomment-2179405315

ryanjbaxter avatar Jun 20 '24 09:06 ryanjbaxter

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-cloud-issues avatar Jun 27 '24 09:06 spring-cloud-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

spring-cloud-issues avatar Jul 04 '24 09:07 spring-cloud-issues