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

linter shows incorrect error about no matched label in deployments in helm. #82

Closed
moabu opened this issue Nov 19, 2020 · 1 comment · Fixed by #83
Closed

linter shows incorrect error about no matched label in deployments in helm. #82

moabu opened this issue Nov 19, 2020 · 1 comment · Fixed by #83
Labels
bug Something isn't working

Comments

@moabu
Copy link

moabu commented Nov 19, 2020

Describe the bug
Kubelinter miss interprets helm charts service matched labels in deployments.

To Reproduce
Steps to reproduce the behavior:

  1. Install kube-linter on linux (ubuntu server 18.04) using brew install kube-linter
  2. Download the example chart zipped.
  3. Unzip it
  4. Walk in the example directory and run /home/ubuntu/.linuxbrew/bin/kube-linter lint .

Expected behavior
No errors to appear regarding a dangling service

Screenshots
helm template . of the example showing service label exists inside deployment

# Source: example/templates/service.yml
apiVersion: v1
kind: Service
metadata:
  name: example
  namespace: default
  labels:
    app: example
    helm.sh/chart: example-1.0.0
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/version: "1.0.0"
    app.kubernetes.io/managed-by: Helm
spec:
  ports:
  - port: 8080
    name: http-example
  selector:
    app: example
---
# Source: example/templates/deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: RELEASE-NAME-example
  namespace: default
  labels:
    APP_NAME: example
    app: example
    helm.sh/chart: example-1.0.0
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/version: "1.0.0"
    app.kubernetes.io/managed-by: Helm
spec:
  replicas: 1
  selector:
    matchLabels:
      app: example
  template:
    metadata:
      labels:
        APP_NAME: example
        app: example
    spec:
      containers:
      - name: example
        imagePullPolicy: Always
        image: alpine:3.11
        securityContext:
          runAsUser: 1000
          runAsNonRoot: true
          readOnlyRootFilesystem: true
        ports:
        - containerPort: 8080
        livenessProbe:
          exec:
            command:
              - python3
              - /app/scripts/healthcheck.py
          initialDelaySeconds: 30
          periodSeconds: 30
          timeoutSeconds: 5
        readinessProbe:
          exec:
            command:
              - python3
              - /app/scripts/healthcheck.py
          initialDelaySeconds: 25
          periodSeconds: 25
          timeoutSeconds: 5
        resources:
          limits:
            cpu: 500m
            memory: 500Mi
          requests:
            cpu: 500m
            memory: 500Mi

Error:

/home/ubuntu/.linuxbrew/bin/kube-linter lint .
example/templates/service.yml: (object: default/example /v1, Kind=Service) no pods found matching service labels (map[app:example]) (check: dangling-service, remediation: Make sure your service's selector correctly matches the labels on one of your deployments.)

Error: found 1 lint errors

Please let me know if i am missing anything.

helm_chart_example.zip

@misberner
Copy link
Contributor

Hello @moabu,

thank you for your submission. This is a legitimate bug in kube-linter caused by an incorrect namespace matching logic. You should find that specifying namespace: default within the spec.template.metadata of your deployment will serve as a workaround to make the chart pass linting. However, this is not required by K8s, so will need to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants