@@ -27,13 +27,16 @@ import (
27
27
"github.com/spf13/pflag"
28
28
noopoteltrace "go.opentelemetry.io/otel/trace/noop"
29
29
30
+ utilruntime "k8s.io/apimachinery/pkg/util/runtime"
30
31
"k8s.io/apiserver/pkg/admission"
31
32
apiserveroptions "k8s.io/apiserver/pkg/server/options"
32
33
"k8s.io/apiserver/pkg/storage/etcd3"
33
34
"k8s.io/apiserver/pkg/storage/storagebackend"
35
+ utilversion "k8s.io/apiserver/pkg/util/version"
34
36
auditbuffered "k8s.io/apiserver/plugin/pkg/audit/buffered"
35
37
audittruncate "k8s.io/apiserver/plugin/pkg/audit/truncate"
36
38
cliflag "k8s.io/component-base/cli/flag"
39
+ "k8s.io/component-base/featuregate"
37
40
"k8s.io/component-base/logs"
38
41
"k8s.io/component-base/metrics"
39
42
kapi "k8s.io/kubernetes/pkg/apis/core"
@@ -45,7 +48,13 @@ import (
45
48
)
46
49
47
50
func TestAddFlags (t * testing.T ) {
51
+ componentGlobalsRegistry := utilversion .DefaultComponentGlobalsRegistry
52
+ t .Cleanup (func () {
53
+ componentGlobalsRegistry .Reset ()
54
+ })
48
55
fs := pflag .NewFlagSet ("addflagstest" , pflag .PanicOnError )
56
+
57
+ utilruntime .Must (componentGlobalsRegistry .Register ("test" , utilversion .NewEffectiveVersion ("1.32" ), featuregate .NewFeatureGate ()))
49
58
s := NewServerRunOptions ()
50
59
for _ , f := range s .Flags ().FlagSets {
51
60
fs .AddFlagSet (f )
@@ -121,8 +130,10 @@ func TestAddFlags(t *testing.T) {
121
130
"--storage-backend=etcd3" ,
122
131
"--service-cluster-ip-range=192.168.128.0/17" ,
123
132
"--lease-reuse-duration-seconds=100" ,
133
+ "--emulated-version=test=1.31" ,
124
134
}
125
135
fs .Parse (args )
136
+ utilruntime .Must (componentGlobalsRegistry .Set ())
126
137
127
138
// This is a snapshot of expected options parsed by args.
128
139
expected := & ServerRunOptions {
@@ -136,6 +147,8 @@ func TestAddFlags(t *testing.T) {
136
147
MinRequestTimeout : 1800 ,
137
148
JSONPatchMaxCopyBytes : int64 (3 * 1024 * 1024 ),
138
149
MaxRequestBodyBytes : int64 (3 * 1024 * 1024 ),
150
+ ComponentGlobalsRegistry : componentGlobalsRegistry ,
151
+ ComponentName : utilversion .DefaultKubeComponent ,
139
152
},
140
153
Admission : & kubeoptions.AdmissionOptions {
141
154
GenericAdmission : & apiserveroptions.AdmissionOptions {
@@ -337,4 +350,8 @@ func TestAddFlags(t *testing.T) {
337
350
if ! reflect .DeepEqual (expected , s ) {
338
351
t .Errorf ("Got different run options than expected.\n Difference detected on:\n %s" , cmp .Diff (expected , s , cmpopts .IgnoreUnexported (admission.Plugins {}, kubeoptions.OIDCAuthenticationOptions {})))
339
352
}
353
+ testEffectiveVersion := s .GenericServerRunOptions .ComponentGlobalsRegistry .EffectiveVersionFor ("test" )
354
+ if testEffectiveVersion .EmulationVersion ().String () != "1.31" {
355
+ t .Errorf ("Got emulation version %s, wanted %s" , testEffectiveVersion .EmulationVersion ().String (), "1.31" )
356
+ }
340
357
}
0 commit comments