Skip to content

Commit a5f5117

Browse files
committed
Get enabled featuregates from metrics endpoint
1 parent cec6222 commit a5f5117

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

pkg/test/ginkgo/cmd_runsuite.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"os/signal"
1313
"path/filepath"
14+
"regexp"
1415
"sort"
1516
"strings"
1617
"sync"
@@ -823,8 +824,13 @@ func determineEnvironmentFlags(ctx context.Context, upgrade bool, dryRun bool) (
823824
if apiGroups.Has("config.openshift.io") {
824825
featureGates, err := determineEnabledFeatureGates(ctx, clientConfig)
825826
if err != nil {
826-
return nil, errors.WithMessage(err, "couldn't determine feature gates")
827+
return nil, errors.WithMessage(err, "couldn't determine OpenShift feature gates")
827828
}
829+
featureGatesAPI, err := getFeatureGatesAPIServerMetrics(ctx, clientConfig)
830+
if err != nil {
831+
return nil, errors.WithMessage(err, "couldn't determine FeatureGates from API /metrics")
832+
}
833+
featureGates = append(featureGates, featureGatesAPI...)
828834
envFlagBuilder.AddFeatureGates(featureGates...)
829835
}
830836

@@ -902,6 +908,27 @@ func determineEnabledAPIGroups(discoveryClient discovery.AggregatedDiscoveryInte
902908
return apiGroups, nil
903909
}
904910

911+
// getFeatureGatesAPIServerMetrics extracts enabled feature gates from the API server metrics endpoint.
912+
// It returns a list of feature gate names that are enabled.
913+
func getFeatureGatesAPIServerMetrics(ctx context.Context, clientConfig *clientconfigv1.Clientset) ([]string, error) {
914+
rsp, err := clientConfig.RESTClient().Get().AbsPath("/metrics").Do(ctx).Raw()
915+
if err != nil {
916+
return nil, err
917+
}
918+
featureGates := sets.NewString()
919+
lines := strings.Split(string(rsp), "\n")
920+
for _, line := range lines {
921+
if strings.HasPrefix(line, "kubernetes_feature_enabled{") && strings.HasSuffix(line, "} 1") {
922+
re := regexp.MustCompile(`kubernetes_feature_enabled\{name="([^"]+)".*\} 1`)
923+
matches := re.FindStringSubmatch(line)
924+
if len(matches) == 2 {
925+
featureGates.Insert(matches[1])
926+
}
927+
}
928+
}
929+
return featureGates.List(), nil
930+
}
931+
905932
func determineEnabledFeatureGates(ctx context.Context, configClient clientconfigv1.Interface) ([]string, error) {
906933
featureGate, err := configClient.ConfigV1().FeatureGates().Get(ctx, "cluster", metav1.GetOptions{})
907934
if err != nil {

0 commit comments

Comments
 (0)