Skip to content

LimitRange default field missing #855

Description

@zabealbe

When creating a LimitRange I found out that this wouldn't work as expected

const lr_config = {
    apiVersion: 'v1',
    kind: 'LimitRange',
    metadata: {
        name: 'default',
    },
    spec: {
        limits: [
            {
                type: 'Container',
                default: {
                    cpu: '200m',
                    memory: '800Mi',
                },
                defaultRequest: {
                    cpu: '200m',
                    memory: '800Mi',
                },
            },
        ],
    },
};
k8sApi_core.createNamespacedLimitRange("default", lr_config);

In fact the resource was deployed in the cluster without the field "default"

apiVersion: v1
kind: LimitRange
metadata:
  creationTimestamp: ***
  name: default
  namespace: default
  resourceVersion: ***
  uid: ***
spec:
  limits:
  - defaultRequest:
      cpu: 200m
      memory: 800Mi
    type: Container

Digging the source code I managed to track the issue to this file

The solution for me was to replace "deafult" with "_default" as follows:

  const lr_config = {
      apiVersion: 'v1',
      kind: 'LimitRange',
      ...
      spec: {
          limits: [
              {
                  type: 'Container',
                  _default: {
                      cpu: '200m',
                      memory: '800Mi',
                  },
                  ...
              },
          ],
      },
  };
k8sApi_core.createNamespacedLimitRange("default", lr_config);

If not possible to use the expected field name I think we should make it clear in the documentation for clarity sake

Activity

brendandburns commented on Aug 12, 2022

@brendandburns
Contributor

This is happening because default is a reserved word in Javascript. In this specific context (embedded field name) it is ok to use, but it appears that the code generator is not sophisticated enough to understand that nuance.

I agree that it is subtle and confusing to an end-user, we should add this to a 'gotchas' section of the documentation.

It may be possible to fix this in the upstream code generator (https://github.com/OpenAPITools/openapi-generator) but I'm not sure if it is worth the effort, especially given that we are in the (slow) process of switching generators.

k8s-triage-robot commented on Nov 10, 2022

@k8s-triage-robot

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

added
lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.
on Nov 10, 2022

k8s-triage-robot commented on Dec 10, 2022

@k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

added
lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.
and removed
lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.
on Dec 10, 2022

brendandburns commented on Dec 16, 2022

@brendandburns
Contributor

/lifecycle freeze

added
lifecycle/frozenIndicates that an issue or PR should not be auto-closed due to staleness.
and removed
lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.
on Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/frozenIndicates that an issue or PR should not be auto-closed due to staleness.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions