Skip to content

CPU resource unit comparison error #2509

Closed
@10000-ki

Description

@10000-ki

Bug Report

In Kubernetes, some resource units are automatically converted to a more convenient format internally. For example:

resources:
    limits:
      cpu: 2000m

Even if the CPU is set to 2000m, when you retrieve this configuration using kubectl, you might see:

resources:
    limits:
      cpu: 2

This indicates that the unit has been converted.

The problem arises when an Operator sets the CPU unit as 2000m, but the Kubernetes API server keeps converting it back to 2. This leads to a situation where, during the DependentResource.match process, the Operator and the API server identify the resources as different, causing match to return false.

스크린샷 2024-08-21 오후 5 07 14

The reason for this issue is that when comparing the actual and desired states, the values are checked through simple string comparison.

As a result, the operator keeps sending patch requests, causing the resourceVersion to increase infinitely.

Environment

$ java -version

17

$ kubectl version

v1.24

Possible Solution

Quantity("2000m") == Quantity("2")

In fact, when using Quantity in fabric8 for comparison, it can be determined that these two values are the same. It might be better to use Quantity for resource comparisons. However, given the current structure, this doesn't seem straightforward. Do you think it might be possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions