java
java copied to clipboard
Can't create K8sDeployment object because of null creationTimestamp or deletionTimestamp fields in yaml file
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.
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
Looks like we should switch to snakeyaml-engine:
https://mvnrepository.com/artifact/org.snakeyaml/snakeyaml-engine/1.0
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
/remove-lifecycle stale
/lifecycle frozen