Posted in

在 client-go 中引入特性开关:增强灵活性和控制力_AI阅读总结 — 包阅AI

包阅导读总结

1.

“`

Client-Go、Feature Gates、Kubernetes、Control、Flexibility

“`

2.

Kubernetes 组件使用特征门管理新功能风险,client-go 现引入自身的特征门机制,为开发者和管理员提供更多控制。文中介绍了其动机、优势、覆盖和定制方法,使推出新 client-go 功能更安全便捷,用户能控制采用功能的节奏。

3.

– Client-Go 引入特征门机制

– 背景:Kubernetes 组件用特征门管理新功能风险,client-go 与 API 交互,此前新功能的可用性和启用方式各异。

– 动机:之前方式存在问题,如默认设置变更影响范围大,缺乏对部分启用的良好支持。

– 机制特点

– 为使用者带来的好处:早期采用者可按进程启用功能,能禁用行为不当的功能,记录特征门状态供用户检查。

– 为开发者带来的好处:默认从环境变量读取覆盖,发现 bug 可禁用,能自定义覆盖方式。

– 覆盖特征门

– 方法:通过设置特定环境变量启用或禁用。

– 注意:环境变量在某些系统上区分大小写。

– 定制特征门

– 方式:可使用自定义特征门提供者替代默认机制。

– 示例:如 Kubernetes 组件用 shim 替代默认提供者。

– 总结

– client-go 引入特征门使新功能推出更安全便捷,用户和开发者能更好控制。

思维导图:

文章地址:https://kubernetes.io/blog/2024/08/12/feature-gates-in-client-go/

文章来源:kubernetes.io

作者:Kubernetes Blog

发布时间:2024/8/12 0:00

语言:英文

总字数:849字

预计阅读时间:4分钟

评分:88分

标签:Kubernetes,client-go,特性开关,软件开发,集群管理


以下为原文内容

本内容来源于用户推荐转载,旨在分享知识与观点,如有侵权请联系删除 联系邮箱 media@ilingban.com

Introducing Feature Gates to Client-Go: Enhancing Flexibility and Control

By Ben Luddy (Red Hat), Lukasz Szaszkiewicz (Red Hat) |

Kubernetes components use on-off switches called feature gates to manage the risk of adding a new feature.The feature gate mechanism is what enables incremental graduation of a feature through the stages Alpha, Beta, and GA.

Kubernetes components, such as kube-controller-manager and kube-scheduler, use the client-go library to interact with the API.The same library is used across the Kubernetes ecosystem to build controllers, tools, webhooks, and more. client-go now includesits own feature gating mechanism, giving developers and cluster administrators more control over how they adopt client features.

To learn more about feature gates in Kubernetes, visit Feature Gates.

Motivation

In the absence of client-go feature gates, each new feature separated feature availability from enablement in its own way, if at all.Some features were enabled by updating to a newer version of client-go. Others needed to be actively configured in each program that used them.A few were configurable at runtime using environment variables. Consuming a feature-gated functionality exposed by the kube-apiserver sometimesrequired a client-side fallback mechanism to remain compatible with servers that don’t support the functionality due to their age or configuration.In cases where issues were discovered in these fallback mechanisms, mitigation required updating to a fixed version of client-go or rolling back.

None of these approaches offer good support for enabling a feature by default in some, but not all, programs that consume client-go.Instead of enabling a new feature at first only for a single component, a change in the default setting immediately affects the defaultfor all Kubernetes components, which broadens the blast radius significantly.

Feature gates in client-go

To address these challenges, substantial client-go features will be phased in using the new feature gate mechanism.It will allow developers and users to enable or disable features in a way that will be familiar to anyone who has experiencewith feature gates in the Kubernetes components.

Out of the box, simply by using a recent version of client-go, this offers several benefits.

For people who use software built with client-go:

  • Early adopters can enable a default-off client-go feature on a per-process basis.
  • Misbehaving features can be disabled without building a new binary.
  • The state of all known client-go feature gates is logged, allowing users to inspect it.

For people who develop software built with client-go:

  • By default, client-go feature gate overrides are read from environment variables.If a bug is found in a client-go feature, users will be able to disable it without waiting for a new release.
  • Developers can replace the default environment-variable-based overrides in a program to change defaults,read overrides from another source, or disable runtime overrides completely.The Kubernetes components use this customizability to integrate client-go feature gates withthe existing --feature-gates command-line flag, feature enablement metrics, and logging.

Overriding client-go feature gates

Note: This describes the default method for overriding client-go feature gates at runtime.It can be disabled or customized by the developer of a particular program.In Kubernetes components, client-go feature gate overrides are controlled by the --feature-gates flag.

Features of client-go can be enabled or disabled by setting environment variables prefixed with KUBE_FEATURE.For example, to enable a feature named MyFeature, set the environment variable as follows:

 KUBE_FEATURE_MyFeature=true

To disable the feature, set the environment variable to false:

 KUBE_FEATURE_MyFeature=false

Note: Environment variables are case-sensitive on some operating systems.Therefore, KUBE_FEATURE_MyFeature and KUBE_FEATURE_MYFEATURE would be considered two different variables.

Customizing client-go feature gates

The default environment-variable based mechanism for feature gate overrides can be sufficient for many programs in the Kubernetes ecosystem,and requires no special integration. Programs that require different behavior can replace it with their own custom feature gate provider.This allows a program to do things like force-disable a feature that is known to work poorly,read feature gates directly from a remote configuration service, or accept feature gate overrides through command-line options.

The Kubernetes components replace client-go’s default feature gate provider with a shim to the existing Kubernetes feature gate provider.For all practical purposes, client-go feature gates are treated the same as other Kubernetesfeature gates: they are wired to the --feature-gates command-line flag, included in feature enablement metrics, and logged on startup.

To replace the default feature gate provider, implement the Gates interface and call ReplaceFeatureGatesat package initialization time, as in this simple example:

import ( k8s.io/client-go/features)type AlwaysEnabledGates struct{}func (AlwaysEnabledGates) Enabled(features.Feature) bool { return true}func init() { features.ReplaceFeatureGates(AlwaysEnabledGates{})}

Implementations that need the complete list of defined client-go features can get it by implementing the Registry interfaceand calling AddFeaturesToExistingFeatureGates.For a complete example, refer to the usage within Kubernetes.

Summary

With the introduction of feature gates in client-go v1.30, rolling out a new client-go feature has become safer and easier.Users and developers can control the pace of their own adoption of client-go features.The work of Kubernetes contributors is streamlined by having a common mechanism for graduating features that span both sides of the Kubernetes API boundary.

Special shoutout to @sttts and @deads2k for their help in shaping this feature.