Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Octal defaultMode notation in yaml not properly converted to json #6110

Closed
bearpaws opened this issue Jul 6, 2024 · 5 comments · Fixed by #6148
Closed

Octal defaultMode notation in yaml not properly converted to json #6110

bearpaws opened this issue Jul 6, 2024 · 5 comments · Fixed by #6148
Assignees
Labels
Milestone

Comments

@bearpaws
Copy link

bearpaws commented Jul 6, 2024

Describe the bug

I'm creating a CronJob from a yaml manifest that contains a ConfigMap volume with octal notation 0555 for the defaultMode.

When creating the resource on the kube server, the API returns this error:

CronJob.batch "conf" is invalid: [spec.jobTemplate.spec.template.spec.volumes[0].configMap.defaultMode: Invalid value: 555: must be a number between 0 and 0777 (octal)

This worked correctly in version 5.12.4 of the API, however in 6.13.1 it fails.

Fabric8 Kubernetes Client version

6.13.1

Steps to reproduce

Yaml manifest that contains a ConfigMap volume:

volumes:
- name: resources
  configMap:
    name: conf
    defaultMode: 0555

Create the resource via the API:

var resource = Serialization.unmarshal(Files.newInputStream(yamlFile), CronJob.class);

System.out.println(resource.getSpec().getJobTemplate().getSpec().getTemplate().getSpec().getVolumes().get(0).getConfigMap());

client.batch().v1().cronjobs()
  .inNamespace(resource.getMetadata().getNamespace())
  .createOrReplace(resource);

In version 5.12.4, it prints:

ConfigMapVolumeSource(defaultMode=365 ...)

In version 6.13.1, it prints the following and fails with the above error.

ConfigMapVolumeSource(defaultMode=555 ...)

Expected behavior

The library should properly convert the octal yaml value into the equivalent value required for json, as it did in previous versions.

Runtime

Kubernetes (vanilla)

Kubernetes API Server version

other (please specify in additional context)

Environment

other (please specify in additional context)

Fabric8 Kubernetes Client Logs

No response

Additional context

Related issue: #2572

@manusa manusa added the bug label Jul 8, 2024
@manusa
Copy link
Member

manusa commented Jul 8, 2024

If you specify the value as 365, does it work?

@bearpaws
Copy link
Author

bearpaws commented Jul 8, 2024

If you specify the value as 365, does it work?

Yes that works.

@rohanKanojia
Copy link
Member

This worked correctly in version 5.12.4 of the API, however in 6.13.1 it fails.

@bearpaws : Hello, I'm trying to run this simple test with KubernetesClient v5.12.4 but it's failing with the same error.

  @Test
  @DisplayName("unmarshal, when integer value has octal literal value, then octal literal value correctly deserialized")
  void unmarshal_whenIntegerValueHasOctalLiteralValue_thenCorrectlyDeserializeInteger() {
    // When
    final CronJob cronJob = Serialization.unmarshal(getClass().getResourceAsStream("/cronjob-octal.yml"), CronJob.class);
    // Then
    assertThat(cronJob)
      .extracting(CronJob::getSpec)
      .extracting(CronJobSpec::getJobTemplate)
      .extracting(JobTemplateSpec::getSpec)
      .extracting(JobSpec::getTemplate)
      .extracting(PodTemplateSpec::getSpec)
      .extracting(PodSpec::getVolumes)
      .asInstanceOf(InstanceOfAssertFactories.list(Volume.class))
      .singleElement()
      .extracting(Volume::getConfigMap)
      .hasFieldOrPropertyWithValue("defaultMode", Integer.valueOf("0555", 8))
      .isNotNull();
  }

Here is YAML that I'm loading :

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: update-db
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: update-fingerprints
              image: python:3.6.2-slim
              command: ["/bin/bash"]
              args: ["-c", "python /client/test.py"]
              volumeMounts:
                - name: application-code
                  mountPath: /where/ever
          restartPolicy: OnFailure
          volumes:
            - name: resources
              configMap:
                name: conf
                defaultMode: "0555"

@bearpaws
Copy link
Author

@rohanKanojia In your example the value is quoted ("0555") whereas in my example the value is unquoted (0555).

@manusa manusa self-assigned this Jul 18, 2024
@manusa
Copy link
Member

manusa commented Jul 18, 2024

Transcribing @rohanKanojia PR fix description so we keep the context of the issue and the solution together:

Jackson doesn't properly handle deserialization of octal integer value in YAML

Jenkins Kubernetes Plugin team also faced some issues for octal handling, here is the linked PR jenkinsci/kubernetes-plugin#1503

Originally posted by @rohanKanojia in #6148

@manusa manusa added this to the 7.0.0 milestone Jul 18, 2024 — with automated-tasks
dongjoon-hyun pushed a commit to apache/spark that referenced this issue Aug 12, 2024
### What changes were proposed in this pull request?
The pr aims to upgrade `kubernetes-client` from `6.13.1` to `6.13.2`.

### Why are the changes needed?
- The full release notes: https://github.com/fabric8io/kubernetes-client/releases/tag/v6.13.2
- The newest version fixed some bug, eg:
  Fix fabric8io/kubernetes-client#6066: Added support for missing v1.APIVersions in KubernetesClient
  Fix fabric8io/kubernetes-client#6110: VolumeSource (and other file mode fields) in Octal are correctly interpreted
  Fix fabric8io/kubernetes-client#6137: ConfigBuilder.withAutoConfigure is not working

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
Pass GA.

### Was this patch authored or co-authored using generative AI tooling?
No.

Closes #47703 from panbingkun/SPARK-49196.

Authored-by: panbingkun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
IvanK-db pushed a commit to IvanK-db/spark that referenced this issue Sep 20, 2024
### What changes were proposed in this pull request?
The pr aims to upgrade `kubernetes-client` from `6.13.1` to `6.13.2`.

### Why are the changes needed?
- The full release notes: https://github.com/fabric8io/kubernetes-client/releases/tag/v6.13.2
- The newest version fixed some bug, eg:
  Fix fabric8io/kubernetes-client#6066: Added support for missing v1.APIVersions in KubernetesClient
  Fix fabric8io/kubernetes-client#6110: VolumeSource (and other file mode fields) in Octal are correctly interpreted
  Fix fabric8io/kubernetes-client#6137: ConfigBuilder.withAutoConfigure is not working

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
Pass GA.

### Was this patch authored or co-authored using generative AI tooling?
No.

Closes apache#47703 from panbingkun/SPARK-49196.

Authored-by: panbingkun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
attilapiros pushed a commit to attilapiros/spark that referenced this issue Oct 4, 2024
### What changes were proposed in this pull request?
The pr aims to upgrade `kubernetes-client` from `6.13.1` to `6.13.2`.

### Why are the changes needed?
- The full release notes: https://github.com/fabric8io/kubernetes-client/releases/tag/v6.13.2
- The newest version fixed some bug, eg:
  Fix fabric8io/kubernetes-client#6066: Added support for missing v1.APIVersions in KubernetesClient
  Fix fabric8io/kubernetes-client#6110: VolumeSource (and other file mode fields) in Octal are correctly interpreted
  Fix fabric8io/kubernetes-client#6137: ConfigBuilder.withAutoConfigure is not working

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
Pass GA.

### Was this patch authored or co-authored using generative AI tooling?
No.

Closes apache#47703 from panbingkun/SPARK-49196.

Authored-by: panbingkun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
himadripal pushed a commit to himadripal/spark that referenced this issue Oct 19, 2024
### What changes were proposed in this pull request?
The pr aims to upgrade `kubernetes-client` from `6.13.1` to `6.13.2`.

### Why are the changes needed?
- The full release notes: https://github.com/fabric8io/kubernetes-client/releases/tag/v6.13.2
- The newest version fixed some bug, eg:
  Fix fabric8io/kubernetes-client#6066: Added support for missing v1.APIVersions in KubernetesClient
  Fix fabric8io/kubernetes-client#6110: VolumeSource (and other file mode fields) in Octal are correctly interpreted
  Fix fabric8io/kubernetes-client#6137: ConfigBuilder.withAutoConfigure is not working

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
Pass GA.

### Was this patch authored or co-authored using generative AI tooling?
No.

Closes apache#47703 from panbingkun/SPARK-49196.

Authored-by: panbingkun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment