java icon indicating copy to clipboard operation
java copied to clipboard

Can't create K8sDeployment object because of null creationTimestamp or deletionTimestamp fields in yaml file

Open ansh7jan opened this issue 5 years ago • 6 comments
trafficstars

I copied the yaml file from an existing deployed resource in cluster.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
    creationTimestamp: null
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80

The file had null creationTimestamp. When we try to read the manifest file as an object using below, then this is throwing an exception Yaml.loadAs(manifestFileYaml, V1Deployment.class)

The SDK is treating null as string value and giving the exception

Caused by: java.lang.IllegalArgumentException: Invalid format: "null"
 at org.joda.time.format.DateTimeParserBucket.doParseMillis(DateTimeParserBucket.java:187)
 at org.joda.time.format.DateTimeFormatter.parseMillis(DateTimeFormatter.java:826)
 at org.joda.time.convert.StringConverter.getInstantMillis(StringConverter.java:65)
 at org.joda.time.base.BaseDateTime.<init>(BaseDateTime.java:151)
 at org.joda.time.DateTime.<init>(DateTime.java:281)
 at io.kubernetes.client.util.Yaml$CustomConstructor.constructDateTime(Yaml.java:352)
 at io.kubernetes.client.util.Yaml$CustomConstructor.constructObject(Yaml.java:333)
 at 

Can we handle this.

ansh7jan avatar Dec 30 '19 19:12 ansh7jan

null value is supported since yaml 1.2 spec https://yaml.org/spec/1.2/spec.html#id2805071 while the serialization library (snakeyaml) is yet only supporting 1.1 i suppose, according to its wiki page https://bitbucket.org/asomov/snakeyaml/wiki/Documentation#markdown-header-yaml-syntax

yue9944882 avatar Dec 31 '19 03:12 yue9944882

Looks like we should switch to snakeyaml-engine:

https://mvnrepository.com/artifact/org.snakeyaml/snakeyaml-engine/1.0

brendandburns avatar Jan 06 '20 20:01 brendandburns

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

fejta-bot avatar Apr 05 '20 20:04 fejta-bot

/remove-lifecycle stale

sagarbhavsar4328 avatar Apr 07 '20 04:04 sagarbhavsar4328

/lifecycle frozen

brendandburns avatar May 11 '20 20:05 brendandburns