Skip to content

Support List kinds #596

Open
Open
@DazWilkin

Description

@DazWilkin

Description of the problem/feature request

kube-linter could be very useful, thanks for creating it!

As an alternative approach to combining multiple YAML files into one using the document start (---) and stop (...) separators, I prefer to use the List kind.

Unfortunately, this appears to be ignored by kube-linter.

Please consider supporting it.

Description of the existing behavior vs. expected behavior

Using your documentation example:

echo '
apiVersion: v1
kind: Pod
metadata:
  name: security-context-demo
spec:
  securityContext:
    runAsUser: 1000
    runAsGroup: 3000
    fsGroup: 2000
  volumes:
  - name: sec-ctx-vol
    emptyDir: {}
  containers:
  - name: sec-ctx-demo
    image: busybox
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
    command: [ "sh", "-c", "sleep 1h" ]
    volumeMounts:
    - name: sec-ctx-vol
      mountPath: /data/demo
    securityContext:
      allowPrivilegeEscalation: false
' | kube-linter lint -

Yields:

KubeLinter development

{elided}

Error: found 4 lint errors

But, incorporating the Pod into a List, fails:

echo '
apiVersion: v1
kind: List
metadata: {}
list:
- apiVersion: v1
  kind: Pod
  metadata:
    name: security-context-demo
  spec:
    securityContext:
      runAsUser: 1000
      runAsGroup: 3000
      fsGroup: 2000
    volumes:
    - name: sec-ctx-vol
      emptyDir: {}
    containers:
    - name: sec-ctx-demo
      image: busybox
      resources:
        requests:
          memory: "64Mi"
          cpu: "250m"
      command: [ "sh", "-c", "sleep 1h" ]
      volumeMounts:
      - name: sec-ctx-vol
        mountPath: /data/demo
      securityContext:
        allowPrivilegeEscalation: false
' | kube-linter lint -

Yields (incorrectly):

Warning: no valid objects found.

Additional context

I have various occurrences of List's in my deployments that successfully deploy using kubectl create ....

I'm unable to use these currently with kube-linter because kube-linter doesn't support List.

For example:

# Provide an Example YAML `List` with one `Deployment`, one `Service` and one `VPA`
cat example \
| kube-linter lint -
Warning: no valid objects found.
# Same Example YAML but using yq to extract the `Deployment`
cat example.yaml \
| yq '.items[0]' \
| kube-linter lint -
KubeLinter development

Error: found 4 lint errors
# Same Example YAML but using yq to extract the `Service`
cat example.yaml \
| yq '.items[1]' \
| kube-linter lint -
KubeLinter development

Error: found 1 lint errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions