Skip to content

Commit 3d2d8db

Browse files
Add option to explicitly enable future gv or gvr in runtime-config.
Signed-off-by: Siyuan Zhang <[email protected]>
1 parent 819cb8f commit 3d2d8db

File tree

14 files changed

+1067
-143
lines changed

14 files changed

+1067
-143
lines changed

cmd/kube-apiserver/app/options/options_test.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ func TestAddFlags(t *testing.T) {
129129
"--lease-reuse-duration-seconds=100",
130130
"--emulated-version=test=1.31",
131131
"--emulation-forward-compatible=true",
132+
"--runtime-config-emulation-forward-compatible=true",
132133
}
133134
fs.Parse(args)
134135
utilruntime.Must(componentGlobalsRegistry.Set())
@@ -137,18 +138,19 @@ func TestAddFlags(t *testing.T) {
137138
expected := &ServerRunOptions{
138139
Options: &controlplaneapiserver.Options{
139140
GenericServerRunOptions: &apiserveroptions.ServerRunOptions{
140-
AdvertiseAddress: netutils.ParseIPSloppy("192.168.10.10"),
141-
CorsAllowedOriginList: []string{"10.10.10.100", "10.10.10.200"},
142-
MaxRequestsInFlight: 400,
143-
MaxMutatingRequestsInFlight: 200,
144-
RequestTimeout: time.Duration(2) * time.Minute,
145-
MinRequestTimeout: 1800,
146-
StorageInitializationTimeout: time.Minute,
147-
JSONPatchMaxCopyBytes: int64(3 * 1024 * 1024),
148-
MaxRequestBodyBytes: int64(3 * 1024 * 1024),
149-
ComponentGlobalsRegistry: componentGlobalsRegistry,
150-
ComponentName: basecompatibility.DefaultKubeComponent,
151-
EmulationForwardCompatible: true,
141+
AdvertiseAddress: netutils.ParseIPSloppy("192.168.10.10"),
142+
CorsAllowedOriginList: []string{"10.10.10.100", "10.10.10.200"},
143+
MaxRequestsInFlight: 400,
144+
MaxMutatingRequestsInFlight: 200,
145+
RequestTimeout: time.Duration(2) * time.Minute,
146+
MinRequestTimeout: 1800,
147+
StorageInitializationTimeout: time.Minute,
148+
JSONPatchMaxCopyBytes: int64(3 * 1024 * 1024),
149+
MaxRequestBodyBytes: int64(3 * 1024 * 1024),
150+
ComponentGlobalsRegistry: componentGlobalsRegistry,
151+
ComponentName: basecompatibility.DefaultKubeComponent,
152+
EmulationForwardCompatible: true,
153+
RuntimeConfigEmulationForwardCompatible: true,
152154
},
153155
Admission: &kubeoptions.AdmissionOptions{
154156
GenericAdmission: &apiserveroptions.AdmissionOptions{

pkg/controlplane/apiserver/apis.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ func (s *Server) InstallAPIs(restStorageProviders ...RESTStorageProvider) error
8989
nonLegacy := []*genericapiserver.APIGroupInfo{}
9090

9191
// used later in the loop to filter the served resource by those that have expired.
92-
resourceExpirationEvaluator, err := genericapiserver.NewResourceExpirationEvaluator(s.GenericAPIServer.EffectiveVersion.EmulationVersion(), s.GenericAPIServer.EmulationForwardCompatible)
92+
resourceExpirationEvaluatorOpts := genericapiserver.ResourceExpirationEvaluatorOptions{
93+
CurrentVersion: s.GenericAPIServer.EffectiveVersion.EmulationVersion(),
94+
EmulationForwardCompatible: s.GenericAPIServer.EmulationForwardCompatible,
95+
RuntimeConfigEmulationForwardCompatible: s.GenericAPIServer.RuntimeConfigEmulationForwardCompatible,
96+
}
97+
resourceExpirationEvaluator, err := genericapiserver.NewResourceExpirationEvaluatorFromOptions(resourceExpirationEvaluatorOpts)
9398
if err != nil {
9499
return err
95100
}
@@ -107,11 +112,13 @@ func (s *Server) InstallAPIs(restStorageProviders ...RESTStorageProvider) error
107112
continue
108113
}
109114

110-
// Remove resources that serving kinds that are removed.
115+
// Remove resources that serving kinds that are removed or not introduced yet at the current version.
111116
// We do this here so that we don't accidentally serve versions without resources or openapi information that for kinds we don't serve.
112117
// This is a spot above the construction of individual storage handlers so that no sig accidentally forgets to check.
113-
resourceExpirationEvaluator.RemoveDeletedKinds(groupName, apiGroupInfo.Scheme, apiGroupInfo.VersionedResourcesStorageMap)
114-
resourceExpirationEvaluator.RemoveUnIntroducedKinds(groupName, apiGroupInfo.Scheme, apiGroupInfo.VersionedResourcesStorageMap)
118+
err = resourceExpirationEvaluator.RemoveUnavailableKinds(groupName, apiGroupInfo.Scheme, apiGroupInfo.VersionedResourcesStorageMap, s.APIResourceConfigSource)
119+
if err != nil {
120+
return err
121+
}
115122
if len(apiGroupInfo.VersionedResourcesStorageMap) == 0 {
116123
klog.V(1).Infof("Removing API group %v because it is time to stop serving it because it has no versions per APILifecycle.", groupName)
117124
continue

staging/src/k8s.io/apiserver/pkg/server/config.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,15 @@ type Config struct {
154154
// EffectiveVersion determines which apis and features are available
155155
// based on when the api/feature lifecyle.
156156
EffectiveVersion basecompatibility.EffectiveVersion
157-
// EmulationForwardCompatible indicates APIs introduced after the emulation version are installed.
158-
// If true, APIs that have higher priority than the APIs of the same group resource enabled at the emulation version will be installed.
159-
// This is useful if a controller has switched to use newer APIs in the binary version, and we want it still functional in an older emulation version.
157+
// EmulationForwardCompatible is an option to implicitly enable all APIs which are introduced after the emulation version and
158+
// have higher priority than APIs of the same group resource enabled at the emulation version.
159+
// If true, all APIs that have higher priority than the APIs of the same group resource enabled at the emulation version will be installed.
160+
// This is needed when a controller implementation migrates to newer API versions, for the binary version, and also uses the newer API versions even when emulation version is set.
160161
EmulationForwardCompatible bool
162+
// RuntimeConfigEmulationForwardCompatible is an option to explicitly enable specific APIs introduced after the emulation version through the runtime-config.
163+
// If true, APIs identified by group/version that are enabled in the --runtime-config flag will be installed even if it is introduced after the emulation version. --runtime-config flag values that identify multiple APIs, such as api/all,api/ga,api/beta, are not influenced by this flag and will only enable APIs available at the current emulation version.
164+
// If false, error would be thrown if any GroupVersion or GroupVersionResource explicitly enabled in the --runtime-config flag is introduced after the emulation version.
165+
RuntimeConfigEmulationForwardCompatible bool
161166
// FeatureGate is a way to plumb feature gate through if you have them.
162167
FeatureGate featuregate.FeatureGate
163168
// AuditBackend is where audit events are sent to.
@@ -843,9 +848,10 @@ func (c completedConfig) New(name string, delegationTarget DelegationTarget) (*G
843848
StorageReadinessHook: NewStorageReadinessHook(c.StorageInitializationTimeout),
844849
StorageVersionManager: c.StorageVersionManager,
845850

846-
EffectiveVersion: c.EffectiveVersion,
847-
EmulationForwardCompatible: c.EmulationForwardCompatible,
848-
FeatureGate: c.FeatureGate,
851+
EffectiveVersion: c.EffectiveVersion,
852+
EmulationForwardCompatible: c.EmulationForwardCompatible,
853+
RuntimeConfigEmulationForwardCompatible: c.RuntimeConfigEmulationForwardCompatible,
854+
FeatureGate: c.FeatureGate,
849855

850856
muxAndDiscoveryCompleteSignals: map[string]<-chan struct{}{},
851857
}

0 commit comments

Comments
 (0)