BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Feature Gates in Client-Go: Enhancing Control and Simplifying Feature Adoption in Kubernetes

Feature Gates in Client-Go: Enhancing Control and Simplifying Feature Adoption in Kubernetes

Kubernetes has integrated feature gates into the client-go library, providing developers and administrators with more granular control over feature adoption within their Kubernetes environments. Kubernetes components utilize the client-go library for API interaction. This library is also widely adopted across the Kubernetes ecosystem for building extensions like controllers, tools, and webhooks.

Ben Luddy and Lukasz Szaszkiewicz, Principal Software Engineers at Red Hat elaborated on the announcement in a blog post.

Without client-go feature gates, managing new features in Kubernetes was inconsistent and problematic. Feature availability and enablement were handled differently, leading to a fragmented approach. Some features relied on client-go version updates, others required manual configuration, and a few used environment variables.

Additionally, compatibility with older servers often required client-side fallbacks, which introduced potential issues and required updates or rollbacks. The lack of a centralized mechanism made it challenging to selectively enable features for specific components, increasing the risk of widespread impact.

For many Kubernetes programs, the default environment variable-based feature gate overrides will be sufficient, requiring no additional integration. However, programs needing different behavior can replace this with their own custom feature gate provider.

Kubernetes components themselves leverage this ability by replacing the default provider with a shim to the existing Kubernetes feature gate provider. Effectively, this aligns client-go feature gates with other Kubernetes feature gates, connecting them to the --feature-gates flag, metrics, and startup logging.

Replacing the default provider involves implementing the Gates interface and calling ReplaceFeatureGates during package initialization.

import (
 “k8s.io/client-go/features”
)

type AlwaysEnabledGates struct{}

func (AlwaysEnabledGates) Enabled(features.Feature) bool {
 return true
}

func init() {
 features.ReplaceFeatureGates(AlwaysEnabledGates{})
}

Kubernetes was in news in 2024 Q3 for the release of Kubernetes v1.31, AWS releasing Karpenter v1.0, an open-source Kubernetes cluster auto-scaling tool. Also, Figma migrating its compute platform from AWS ECS to Kubernetes (EKS)

The benefits of feature-gates for early adopters of client-go include ability to enable a default-off client-go feature on a per-process basis. This helps disable the misbehaving features 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, client-go feature gate overrides are read from environment variables by default. 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 customization to integrate client-go feature gates with the existing --feature-gates command-line flag, feature enablement metrics, and logging.

The introduction of feature gates in client-go v1.30 improves the process of rolling out new features. It allows users and developers to control their adoption of new client-go features, and it simplifies the work of Kubernetes contributors by providing a consistent method for managing feature releases.

For further reading, check out the official Feature Gates documentation.

About the Author

Rate this Article

Adoption
Style

BT