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

upgrade controller-runtime version from 0.14 to 0.16 #110

Closed

Conversation

AiRanthem
Copy link

The original content described below was written in Chinese on aliyuque, and translated into English using GPT-4o. If you have any confusion while reading, please contact me directly.

Upgrading the controller-runtime has introduced several changes, particularly to the client.Client interface and related components. Here's a breakdown of the changes and adaptations required:

Issue 1: New Methods in client.Client

After upgrading, the client.Client interface now includes two additional methods, GroupVersionKindFor and IsObjectNamespaced. Since your package implements several clients, you will need to implement these new methods for each client.

Issue 2: Function Parameter Changes

Functions like apiutil.NewDiscoveryRESTMapper now require an external client to be passed in. To adapt, you can use rest.HttpClientFor to construct the new parameter using the first parameter config.

Issue 3: Refactoring Related to cache.Options

Current State (version 0.14.x)

In version 0.14.x, the package has a BuildCacheWithOptions function, which directly uses cache.BuilderWithOptions to customize a NewCacheFunc. This NewCacheFunc is used in the vela main repository as the NewCacheFunc for the manager to customize the cache. This customization is necessary because older versions of the manager could not directly customize the cache, requiring a custom function to handle cache options.

Changes in 0.15.x

  • The manager options now include a Cache struct for cache.Options.
  • The manager's default NewCacheFunc now processes the cache options configured in the manager options, and it's no longer recommended to pass a custom NewCacheFunc.
  • There has been a significant refactoring of the cache.Options structure.

Refactoring

To adapt to these changes, the following adjustments have been made on the package side:

  1. Removed the functions BuildCacheWithOptions and BuildCache.
  2. Added a function BuildCacheOptionsWithShardingObjects, which executes the original logic up to the construction of cache.Options and returns them directly.
  3. In the unit test for BuildCacheWithOptions, the logic has been changed to first use BuildCacheOptionsWithShardingObjects to construct the options, and then use cache.New to construct the cache object. After verification, the test logic works correctly.

Follow-up in Vela

The following adjustments need to be made in Vela:

  • Change places that directly use NewCacheFunc to use cache.Options.

Issue 4: Unit Testing

In version 0.15.0, the serialization logic for unstructured has been optimized. Previously, values like replicas were represented as int64, but now they use float64. As a result, unit tests have been modified to check for value equality rather than strict equality. For example:

require.Equal(t, int64(1), deploy.Object["spec"].(map[string]interface{})["replicas"])

has been changed to:

require.EqualValues(t, 1, deploy.Object["spec"].(map[string]interface{})["replicas"])

In version 0.16.0, some shortcut functions were removed from the testing framework. These have been migrated according to the Deprecated documentation without affecting the test logic.

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.78%. Comparing base (eaacca6) to head (fd3752a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #110      +/-   ##
==========================================
- Coverage   88.41%   86.78%   -1.63%     
==========================================
  Files          81       81              
  Lines        3366     3965     +599     
==========================================
+ Hits         2976     3441     +465     
- Misses        261      394     +133     
- Partials      129      130       +1     
Flag Coverage Δ
unit-test 86.78% <100.00%> (-1.63%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@AiRanthem AiRanthem force-pushed the feature/upgrade-k8s-to-1.28-241104 branch from fd3752a to fed03a9 Compare November 8, 2024 02:40
@AiRanthem AiRanthem closed this Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant