mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-02 07:35:21 +00:00
client-go/features: warn when ordering initialization issue
ReplaceFeatureGates logs a warning when the default env var implementation has been already used. Such a situation indicates a potential ordering issue and usually is unwanted. Kubernetes-commit: 04bbd3481f70825eea54b4b154a04d2496dcf652
This commit is contained in:
committed by
Kubernetes Publisher
parent
ca4f3a73f7
commit
e8a81a3a43
@@ -17,6 +17,9 @@ limitations under the License.
|
||||
package features
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
@@ -99,8 +102,23 @@ func AddFeaturesToExistingFeatureGates(registry Registry) error {
|
||||
// // then replace client-go's feature gates implementation with your implementation
|
||||
// clientgofeaturegate.ReplaceFeatureGates(utilfeature.DefaultMutableFeatureGate)
|
||||
func ReplaceFeatureGates(newFeatureGates Gates) {
|
||||
if replaceFeatureGatesWithWarningIndicator(newFeatureGates) {
|
||||
utilruntime.HandleError(errors.New("the default feature gates implementation has already been used and now it's being overwritten. This might lead to unexpected behaviour. Check your initialization order"))
|
||||
}
|
||||
}
|
||||
|
||||
func replaceFeatureGatesWithWarningIndicator(newFeatureGates Gates) bool {
|
||||
shouldProduceWarning := false
|
||||
|
||||
if defaultFeatureGates, ok := FeatureGates().(*envVarFeatureGates); ok {
|
||||
if defaultFeatureGates.hasAlreadyReadEnvVar() {
|
||||
shouldProduceWarning = true
|
||||
}
|
||||
}
|
||||
wrappedFeatureGates := &featureGatesWrapper{newFeatureGates}
|
||||
featureGates.Store(wrappedFeatureGates)
|
||||
|
||||
return shouldProduceWarning
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
Reference in New Issue
Block a user