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

Add: Kubernetes recommande labels #1387

Closed
wants to merge 6 commits into from

Conversation

nlamirault
Copy link

@nlamirault nlamirault commented Feb 20, 2021

Signed-off-by: Nicolas Lamirault nicolas.lamirault@gmail.com

What this PR does / why we need it:

Add Kubernetes recommanded labels https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/

Ex:

---
# Source: kube-state-metrics/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    app: kube-state-metrics
    
    app.kubernetes.io/name: kube-state-metrics
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/version: "2.13.0"
    app.kubernetes.io/part-of: kube-state-metrics 
    helm.sh/chart: kube-state-metrics-2.13.0
  name: RELEASE-NAME-kube-state-metrics
  namespace: default
imagePullSecrets:
  []

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Output :

$ helm template charts/kube-state-metrics
---
# Source: kube-state-metrics/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    app: kube-state-metrics    
    app.kubernetes.io/name: kube-state-metrics
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/version: "2.13.0"
    app.kubernetes.io/part-of: kube-state-metrics 
    helm.sh/chart: kube-state-metrics-2.13.0
  name: RELEASE-NAME-kube-state-metrics
  namespace: default
imagePullSecrets:
  []
---
# Source: kube-state-metrics/templates/role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  labels:
    app: kube-state-metrics    
    app.kubernetes.io/name: kube-state-metrics
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/version: "2.13.0"
    app.kubernetes.io/part-of: kube-state-metrics 
    helm.sh/chart: kube-state-metrics-2.13.0
  name: RELEASE-NAME-kube-state-metrics
rules:

- apiGroups: ["certificates.k8s.io"]
  resources:
  - certificatesigningrequests
  verbs: ["list", "watch"]

- apiGroups: [""]
  resources:
  - configmaps
  verbs: ["list", "watch"]

- apiGroups: ["batch"]
  resources:
  - cronjobs
  verbs: ["list", "watch"]

- apiGroups: ["extensions", "apps"]
  resources:
  - daemonsets
  verbs: ["list", "watch"]

- apiGroups: ["extensions", "apps"]
  resources:
  - deployments
  verbs: ["list", "watch"]

- apiGroups: [""]
  resources:
  - endpoints
  verbs: ["list", "watch"]

- apiGroups: ["autoscaling"]
  resources:
  - horizontalpodautoscalers
  verbs: ["list", "watch"]

- apiGroups: ["extensions", "networking.k8s.io"]
  resources:
  - ingresses
  verbs: ["list", "watch"]

- apiGroups: ["batch"]
  resources:
  - jobs
  verbs: ["list", "watch"]

- apiGroups: [""]
  resources:
  - limitranges
  verbs: ["list", "watch"]

- apiGroups: ["admissionregistration.k8s.io"]
  resources:
    - mutatingwebhookconfigurations
  verbs: ["list", "watch"]

- apiGroups: [""]
  resources:
  - namespaces
  verbs: ["list", "watch"]

- apiGroups: ["networking.k8s.io"]
  resources:
  - networkpolicies
  verbs: ["list", "watch"]

- apiGroups: [""]
  resources:
  - nodes
  verbs: ["list", "watch"]

- apiGroups: [""]
  resources:
  - persistentvolumeclaims
  verbs: ["list", "watch"]

- apiGroups: [""]
  resources:
  - persistentvolumes
  verbs: ["list", "watch"]

- apiGroups: ["policy"]
  resources:
    - poddisruptionbudgets
  verbs: ["list", "watch"]

- apiGroups: [""]
  resources:
  - pods
  verbs: ["list", "watch"]

- apiGroups: ["extensions", "apps"]
  resources:
  - replicasets
  verbs: ["list", "watch"]

- apiGroups: [""]
  resources:
  - replicationcontrollers
  verbs: ["list", "watch"]

- apiGroups: [""]
  resources:
  - resourcequotas
  verbs: ["list", "watch"]

- apiGroups: [""]
  resources:
  - secrets
  verbs: ["list", "watch"]

- apiGroups: [""]
  resources:
  - services
  verbs: ["list", "watch"]

- apiGroups: ["apps"]
  resources:
  - statefulsets
  verbs: ["list", "watch"]

- apiGroups: ["storage.k8s.io"]
  resources:
    - storageclasses
  verbs: ["list", "watch"]

- apiGroups: ["admissionregistration.k8s.io"]
  resources:
    - validatingwebhookconfigurations
  verbs: ["list", "watch"]

- apiGroups: ["storage.k8s.io"]
  resources:
    - volumeattachments
  verbs: ["list", "watch"]
---
# Source: kube-state-metrics/templates/clusterrolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  labels:
    app: kube-state-metrics    
    app.kubernetes.io/name: kube-state-metrics
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/version: "2.13.0"
    app.kubernetes.io/part-of: kube-state-metrics 
    helm.sh/chart: kube-state-metrics-2.13.0
  name: RELEASE-NAME-kube-state-metrics
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: RELEASE-NAME-kube-state-metrics
subjects:
- kind: ServiceAccount
  name: RELEASE-NAME-kube-state-metrics
  namespace: default
---
# Source: kube-state-metrics/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: RELEASE-NAME-kube-state-metrics
  namespace: default
  labels:
    app: kube-state-metrics    
    app.kubernetes.io/name: kube-state-metrics
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/version: "2.13.0"
    app.kubernetes.io/part-of: kube-state-metrics 
    helm.sh/chart: kube-state-metrics-2.13.0
  annotations:
    prometheus.io/scrape: 'true'
spec:
  type: "ClusterIP"
  ports:
  - name: "http"
    protocol: TCP
    port: 8080
    targetPort: 8080
  
  selector:
    app.kubernetes.io/name: kube-state-metrics
    app.kubernetes.io/instance: RELEASE-NAME
---
# Source: kube-state-metrics/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: RELEASE-NAME-kube-state-metrics
  namespace: default
  labels:
    app: kube-state-metrics    
    app.kubernetes.io/name: kube-state-metrics
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/version: "2.13.0"
    app.kubernetes.io/part-of: kube-state-metrics 
    helm.sh/chart: kube-state-metrics-2.13.0
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: kube-state-metrics
  replicas: 1
  template:
    metadata:
      labels:
        app: kube-state-metrics        
        app.kubernetes.io/name: kube-state-metrics
        app.kubernetes.io/instance: RELEASE-NAME
        app.kubernetes.io/managed-by: Helm
        app.kubernetes.io/version: "2.13.0"
        app.kubernetes.io/part-of: kube-state-metrics 
        helm.sh/chart: kube-state-metrics-2.13.0
    spec:
      hostNetwork: false
      serviceAccountName: RELEASE-NAME-kube-state-metrics
      securityContext:
        fsGroup: 65534
        runAsGroup: 65534
        runAsUser: 65534
      containers:
      - name: kube-state-metrics
        args:


        - --collectors=certificatesigningrequests


        - --collectors=configmaps


        - --collectors=cronjobs


        - --collectors=daemonsets


        - --collectors=deployments


        - --collectors=endpoints


        - --collectors=horizontalpodautoscalers


        - --collectors=ingresses


        - --collectors=jobs


        - --collectors=limitranges


        - --collectors=mutatingwebhookconfigurations


        - --collectors=namespaces


        - --collectors=networkpolicies


        - --collectors=nodes


        - --collectors=persistentvolumeclaims


        - --collectors=persistentvolumes


        - --collectors=poddisruptionbudgets


        - --collectors=pods


        - --collectors=replicasets


        - --collectors=replicationcontrollers


        - --collectors=resourcequotas


        - --collectors=secrets


        - --collectors=services


        - --collectors=statefulsets


        - --collectors=storageclasses


        - --collectors=validatingwebhookconfigurations



        - --collectors=volumeattachments





        - --telemetry-port=8081
        imagePullPolicy: IfNotPresent
        image: "quay.io/coreos/kube-state-metrics:v1.9.7"
        ports:
        - containerPort: 8080
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8080
          initialDelaySeconds: 5
          timeoutSeconds: 5
        readinessProbe:
          httpGet:
            path: /
            port: 8080
          initialDelaySeconds: 5
          timeoutSeconds: 5

Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>
Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 20, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: nlamirault
To complete the pull request process, please assign mrueg after the PR has been reviewed.
You can assign the PR to them by writing /assign @mrueg in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 20, 2021
@mrueg
Copy link
Member

mrueg commented Feb 22, 2021

Thanks for your contribution!
To make sure I understood the PR correctly, you don't add the labels and want to move them into a template macro?

@brancz brancz added the helm label Feb 22, 2021
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 23, 2021
Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>
Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 5, 2021
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app: {{ template "kube-state-metrics.name" . }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this lone app: label (not as part of templates) seems inconsistent to me. Why not add this app: label through .Values.customLabels?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do that to be consistent with other charts (Like : https://github.com/prometheus-community/helm-charts/blob/main/charts/kube-prometheus-stack/templates/prometheus/clusterrolebinding.yaml#L7).
Do you want i remove it and use customLabels ?

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 6, 2021
* master: (50 commits)
  RELEASE.md: Add missing bits to the release workflow
  update RBAC manifests to v1
  Regenerate cli docs
  Cut 2.0.0-rc.1
  Rename cli flag from label-metrics-allow-list to metric-labels-allowlist
  Fix docs README link to a nonexistent section
  cli-arguments.md: Fix docs
  go.mod: Update dependencies
  Makefile: Use promtool 2.25.2
  Make/Dockerfile: Switch to 1.16
  OWNERS: Add mrueg as reviewer
  examples: regenerate
  jsonnet/kube-state-metrics/kube-state-metrics.libsonnet: Remove old API
  internal/store/verticalpodautoscaler_test.go: Switch test to new API
  Update latest 1.9 version to 1.9.8 in README.md
  [Backport] Remove vendor directory
  cli-arguments.md: Fix docs
  go.mod: Update dependencies
  Make/Dockerfile: Switch to 1.16
  Combine 4-into-1
  ...

Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Apr 6, 2021
@k8s-ci-robot
Copy link
Contributor

@nlamirault: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@mrueg
Copy link
Member

mrueg commented Apr 12, 2021

/hold
Thanks for a contribution!
We are currently migrating the chart to a new location. Please feel free to create a new PR in https://github.com/prometheus-community/helm-charts/ once the migration has been completed.

#1448

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 12, 2021
@mrueg
Copy link
Member

mrueg commented Apr 27, 2021

Thanks for your contribution. We moved our helm charts to https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-state-metrics Feel free to reopen a PR on https://github.com/prometheus-community/helm-charts/ !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. helm needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants