question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stop sorting the fields in alphabetical order in generated yaml file

See original GitHub issue

Description of the feature or enhancement:

Hi, I don’t know whether this feature already exist or not, Can someone please help me with this issue.

When I run cdk8s synth yaml files are getting generated in dist folder. List or directory declared in .ts file is getting sorted alphabetically in generated yaml file, is there a way to not sort these fields…?

Use Case: Avoiding alphabetical sort of dictionary or list resolves some pods to be not stuck in Creating Container

let tenant = new Tenant(this, 'tenant', {
            metadata: {
                name: 'minio',
                creationTimestamp: null,
                labels: {
                    app: 'minio'
                },
                scheduler: {
                    name: ""
                }
            },
            spec: {
                console: {
                    consoleSecret: {
                        name: 'minio-console-secret'
                    },
                    image: 'minio/console:v0.4.6',
                    replicas: 2,
                    resources: {},
                },
                credsSecret: {
                    name: 'minio-creds-secret'
                },
                image: 'minio/minio:RELEASE.2020-12-23T02-24-12Z',
                mountPath: '/export',
                requestAutoCert: true,
                zones: [
                    {
                        resources: {},
                        servers: 4,
                        volumeClaimTemplate: {
                            apiVersion: 'v1',
                            kind: 'persistentvolumeclaims',
                            spec: {
                                storageClassName: 'provisioner',
                                accessModes: ['ReadWriteOnce'],
                                resources: {
                                    requests: {
                                        storage: '1G'
                                    }
                                }
                            }
                        },
                        volumesPerServer: 1,
                        affinity: {
                            podAntiAffinity: {
                                preferredDuringSchedulingIgnoredDuringExecution: [
                                    {
                                        weight: 1,
                                        podAffinityTerm: {
                                            labelSelector: {
                                                matchExpressions: [
                                                    {
                                                        key: 'app',
                                                        operator: 'In',
                                                        values: ['minio']
                                                    }
                                                ]
                                            },
                                            topologyKey: 'kubernetes.io/hostname'
                                        }
                                    }
                                ]
                            }
                        }
                    }]
            }
        });

The generated yaml file from above .ts file is

kind: "Tenant"
metadata:
  labels:
    app: "minio"
  name: "minio"
  namespace: "minio"
  scheduler:
    name: ""
spec:
  console:
    consoleSecret:
      name: "minio-console-secret"
    image: "minio/console:v0.4.6"
    replicas: 2
    resources: {}
  credsSecret:
    name: "minio-creds-secret"
  image: "minio/minio:RELEASE.2020-12-23T02-24-12Z"
  mountPath: "/export"
  requestAutoCert: true
  zones:
    - affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - podAffinityTerm:
                labelSelector:
                  matchExpressions:
                    - key: "app"
                      operator: "In"
                      values:
                        - "minio"
                topologyKey: "kubernetes.io/hostname"
              weight: 1
      resources: {}
      servers: 4
      volumeClaimTemplate:
        apiVersion: "v1"
        kind: "persistentvolumeclaims"
        spec:
          accessModes:
            - "ReadWriteOnce"
          resources:
            requests:
              storage: "1G"
          storageClassName: "provisioner"
      volumesPerServer: 

Proposed Solution: Generate YAML file without alphabetical sort

kind: "Tenant"
metadata:
  labels:
    app: "minio"
  name: "minio"
  namespace: "minio"
  scheduler:
    name: ""
spec:
  console:
    consoleSecret:
      name: "minio-console-secret"
    image: "minio/console:v0.4.6"
    replicas: 2
    resources: {}
  credsSecret:
    name: "minio-creds-secret"
  image: "minio/minio:RELEASE.2020-12-23T02-24-12Z"
  mountPath: "/export"
  requestAutoCert: true
  zones:
    - resources: {}
      servers: 4
      volumeClaimTemplate:
        apiVersion: "v1"
        kind: "persistentvolumeclaims"
        spec:
          accessModes:
            - "ReadWriteOnce"
          resources:
            requests:
              storage: "1G"
          storageClassName: "provisioner"
      volumesPerServer: 1
      affinity:
      podAntiAffinity:
        preferredDuringSchedulingIgnoredDuringExecution:
        - weight: 1
          podAffinityTerm:
            labelSelector:
              matchExpressions:
                - key: "app"
                  operator: In
                  values:
                  - minio
            topologyKey: "kubernetes.io/hostname"

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
eladbcommented, Feb 23, 2021

Either export it in your shell before you synth or set it in-process using something like:

process.env.CDK_DISABLE_SORT='true';

Before you create the App object.

Let me know if everything works as expected.

1reaction
eladbcommented, Feb 18, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Stop sorting the fields in alphabetical order in generated yaml ...
When I run cdk8s synth yaml files are getting generated in dist folder. List or directory declared in .ts file is getting sorted...
Read more >
How do I avoid Python I/O operation from auto-sorting the ...
When I change the value of the keys, the code sorts the keys in the file alphabetically. I want to avoid sorting. Below...
Read more >
Sorting and ordering issue lists - GitLab Docs
Issues created most recently are first. ... When you sort by Title, the issue order changes to sort alphabetically by the issue title...
Read more >
Code completion | IntelliJ IDEA Documentation - JetBrains
Select if you want to sort items in the suggestions list in the alphabetical order instead of sorting them by relevance. You can...
Read more >
Search experience - OpenSearch documentation
You get back results sorted by the play_name field in alphabetic order. Use sort with search_after parameter for more efficient scrolling. You get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found