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

Support List kinds #596

Open
DazWilkin opened this issue Jul 11, 2023 · 1 comment
Open

Support List kinds #596

DazWilkin opened this issue Jul 11, 2023 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@DazWilkin
Copy link

DazWilkin commented Jul 11, 2023

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
@janisz janisz added enhancement New feature or request help wanted Extra attention is needed labels Jul 17, 2023
@janisz
Copy link
Collaborator

janisz commented Jul 17, 2023

Keep in mind that kind: List is not part of the Kubernetes API; it is exposing an implementation detail from client-side code in those tools, used to handle groups of mixed resources.

Although Lists are not part of official API I think we should consider supporting them as kubelinter is meant to lint files applied by kubectl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants