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

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