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 "True" and "False" as string in custom-resource-state #1963

Conversation

jabdoa2
Copy link
Contributor

@jabdoa2 jabdoa2 commented Jan 26, 2023

What this PR does / why we need it:
Kubernetes Operators usually store status conditions in the following format:

status:
  conditions:
    - lastTransitionTime: "2019-10-22T16:29:31Z"
      status: "True"
      type: Ready

Note that status is actually a string. This previously broke KSM custom-resource-state gauges because it could not convert strings to float. This PR maps "True", "true", "Yes" and "yes" to 1.0 and "False", "false", "No", "no" to 0.0. This allows us to use custom-resource-state for all CRD objects of standard kubernetes operators.

For a single condition you can use (as in unit test status_conditions):

      - --custom-resource-state-config
      # in YAML files, | allows a multi-line string to be passed as a flag value
      # see https://yaml-multiline.info
      -  |
          spec:
            resources:
            - groupVersionKind:
                group: xxxxx.xxx
                kind: "xxx"
                version: "v1"
              metrics:
              - name: "xxx_ready"
                help: "xxx ready state"
                each:
                  type: Gauge
                  gauge:
                    path: [status, conditions, "[type=Ready]", status]

To expose one metric per status type (as in unit test status_conditions_all):

      - --custom-resource-state-config
      # in YAML files, | allows a multi-line string to be passed as a flag value
      # see https://yaml-multiline.info
      -  |
          spec:
            resources:
            - groupVersionKind:
                group: xxxxx.xxx
                kind: "xxx"
                version: "v1"
              metrics:
              - name: "xxx_status"
                help: "xxx status"
                each:
                  type: Gauge
                  gauge:
                    path: [status, conditions]
                    labelsFromPath:
                      type: ["type"]
                    valueFrom: ["status"]

Guess this could be something for the documentation as it will be a very common usecase for controller CRDs.

How does this change affect the cardinality of KSM: (increases, decreases or does not change cardinality)
It does not change cardinality. It allows KSM to support .status.conditions used by standard kubernetes operators.

Which issue(s) this PR fixes
Fixes #1962

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 26, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jan 26, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @jabdoa2!

It looks like this is your first PR to kubernetes/kube-state-metrics 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kube-state-metrics has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 26, 2023
@jabdoa2 jabdoa2 force-pushed the support_string_bool_in_custom_resource_state branch from c537125 to eb67ca8 Compare January 26, 2023 16:20
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jan 26, 2023
@jabdoa2 jabdoa2 force-pushed the support_string_bool_in_custom_resource_state branch from eb67ca8 to 2b5460f Compare January 26, 2023 16:28
@mrueg
Copy link
Member

mrueg commented Jan 26, 2023

Since this really depends on the implementor of the CR, having some defaults make sense. Anything else really should be defined via a user supplied valuemap (e.g.if the implementation returns "Ok" etc.).

Co-authored-by: Manuel Rüger <manuel@rueg.eu>
@jabdoa2 jabdoa2 force-pushed the support_string_bool_in_custom_resource_state branch from 8c4be01 to e26d682 Compare January 26, 2023 16:56
@mrueg mrueg requested a review from rexagod January 26, 2023 17:08
@mrueg
Copy link
Member

mrueg commented Jan 26, 2023

/approve

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 26, 2023
@mrueg
Copy link
Member

mrueg commented Jan 26, 2023

It would be good to add a sentence or two to https://github.com/kubernetes/kube-state-metrics/blob/main/docs/customresourcestate-metrics.md about this conversion.

@rexagod
Copy link
Member

rexagod commented Jan 26, 2023

/approve

@logicalhan
Copy link
Member

/assign
/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jan 26, 2023
Copy link
Member

@dgrisonnet dgrisonnet left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 2, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dgrisonnet, jabdoa2, mrueg, rexagod

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

The pull request process is described 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 merged commit 5da24c2 into kubernetes:main Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CustomResourceStateMetrics Gauges do not work for Kubernetes Controller Status Conditions
6 participants