java icon indicating copy to clipboard operation
java copied to clipboard

Exception in YAML.load(File file): NoSuchMethodException:io.kubernetes.client.custom.Quantity.<init>()

Open john-meeder opened this issue 2 years ago • 0 comments

Describe the bug Hi guys,

we have a service in our system which should write some k8s-resource files (Deployement, StatefulSet etc.). For instantiation we're using the provided k8s model classes from the java-client. The object is written to file using the jackson object-mapper.

Afterwards the service is able to load these files and apply the resources on the cluster. e.g. V1StatefulSet statefulSet = (V1StatefulSet) Yaml.load(new File(filename));

In case of a StatefulSet file, loading results in the following Exception:

java.lang.InstantiationException: NoSuchMethodException:io.kubernetes.client.custom.Quantity.<init>()
 in 'reader', line 49, column 11:
              storage:
              ^

at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:291)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:172)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:230)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:220)
at io.kubernetes.client.util.Yaml$CustomConstructor.constructObject(Yaml.java:246)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:268)

The resource-file:

---
apiVersion: "apps/v1"
kind: "StatefulSet"
metadata:
  labels:
    com.fujitsu.ceasf.service: "testmandant-db"
  name: "testmandant-db"
spec:
  replicas: 1
  selector:
    matchLabels:
      com.fujitsu.ceasf.service: "testmandant-db"
  serviceName: "testmandant-db"
  template:
    metadata:
      labels:
        com.fujitsu.ceasf.network/ceasf-network: "true"
        com.fujitsu.ceasf.service: "testmandant-db"
    spec:
      containers:
        - args:
            - "/bin/sh"
            - "/opt/oracle/runOracleSecDocs.sh"
          env:
            - name: "MANDANT"
              value: "Testmandant"
          image: "***"
          name: "testmandant-db"
          ports:
            - containerPort: 1521
          volumeMounts:
            - mountPath: "/opt/oracle/oradata"
              name: "pvc-testmandant-oracle"
              subPathExpr: "$(MANDANT)/"
      hostname: "testmandant-db"
      restartPolicy: "Always"
  volumeClaimTemplates:
  - metadata:
      name: "testmandant-db-claim0"
    spec:
      accessModes:
      - "ReadWriteOnce"
      resources:
        requests:
          storage:
            number: 10737418240
            format: "BINARY_SI"
      storageClassName: "preservation-storage"

It seems that the io.kubernetes.client.util.Yaml needs a basis constructor for the io.kubernetes.client.custom.Quantity instantiation, which is not provided in the generated code.

Any help on this would be appreciated :)

Client Version 16.0.0

Kubernetes Version k3s version v1.24.4+k3s1 (c3f830e9) go version go1.18.1

Java Version Java 11.0.14.1

To Reproduce Steps to reproduce the behavior: V1StatefulSet statefulSet = (V1StatefulSet) Yaml.load(new File(filename));

Additional context When the RequestsItem is written as a String Yaml.loadFile is working without any issue.

...
resources:
  requests:
    storage: "10Gi"

john-meeder avatar Oct 13 '22 11:10 john-meeder