spring-cloud / spring-cloud-deployer-kubernetes

The Spring Cloud Deployer implementation for Kubernetes
Apache License 2.0
157 stars 98 forks source link

Fail to parse empty Dir in deployer properties #465

Closed thesoundofsilent closed 2 years ago

thesoundofsilent commented 2 years ago

I need to create empty volume for my worker pod

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /cache
      name: cache-volume
  volumes:
  - name: cache-volume
    emptyDir: {}

The deployer properties I used is as below:

spring.cloud.deployer.kubernetes.volumes[0].name=cache-volume spring.cloud.deployer.kubernetes.volumes[0].emptyDir={}

But I got json parse error, it seems the {} can't be parse and I can't find any document about how to set properties for emptyDir

sabbyanandan commented 2 years ago

@thesoundofsilent: Ah, interesting! Also, any reasoning to back the ask would be helpful. Feel free to submit a PR to kickstart the conversation, too.

onobc commented 2 years ago

@thesoundofsilent

The volumes are specified in yaml format as per DeploymentPropertiesResolver#getVolumes().

Try this:

spring.cloud.deployer.kubernetes.volumes=[{ name: cache-volume, emptyDir: { } }]
onobc commented 2 years ago

@thesoundofsilent

My above suggestion works for a "deployment" property because the DeploymentPropertiesResolver converts from yaml to the expected list of volumes correctly. However, as a "deployer" property (as listed in your example), it fails to convert w/ the following:

Failed to bind properties under 'spring.cloud.skipper.server.platform.kubernetes.accounts.default.volumes[0].empty-dir' to io.fabric8.kubernetes.api.model.EmptyDirVolumeSource:

    Reason: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.LinkedHashMap<?, ?>] to type [@com.fasterxml.jackson.annotation.JsonProperty io.fabric8.kubernetes.api.model.EmptyDirVolumeSource]

I was able to workaround this by setting the "emptyDir.medium" property to null which creates the EmptyVolumeSource but does not actually set any fields on it.

This should work for you:

spring.cloud.deployer.kubernetes.volumes[0].emptyDir.medium=null

ℹ️ This would be a workaround and not a fix.

onobc commented 2 years ago

Hi @thesoundofsilent ,

Were you able to try the above workaround?

markpollack commented 2 years ago

closing as the issue has gone stale. If you feel we closed this issue in error, please add a comment.

Will create an issue around better documentation for these properties.