Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

authorizer/webhook: make webhook authorizer cluster aware #43

Open
wants to merge 89 commits into
base: feature-logical-clusters-1.23
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
d4ede2e
DUPLICATE: Bootsptrap the generic control plane
smarterclayton Jul 21, 2020
4c9d920
NEW: Generic control plane based of the upstream kube-apiserver
smarterclayton Jul 21, 2020
59a083f
DUPLICATE: Bootstrap the creation of a minimal kcp config
davidfestal Aug 11, 2021
dd87be0
NEW: Minimal kcp config, stripped down from kube-apiserver
smarterclayton Aug 3, 2020
34e5eb9
NEW: Turn on authorization in the config
smarterclayton Nov 1, 2020
3d6ac63
DUPLICATE: Bootstrap the addition of a genericcontrolplane core group
davidfestal Aug 4, 2021
b847e3e
NEW: Add a controlplane core group that drops the legacy group ""
smarterclayton Nov 1, 2020
6acbf4e
DUPLICATE: Prepare changes on storage factory
davidfestal Aug 5, 2021
f46394b
NEW: Allow the storage factory to have no opinions about resource sto…
smarterclayton Nov 23, 2020
970325a
HACK: Inject an arbitrary key segment from "cluster" to etcd
smarterclayton Nov 23, 2020
b72964f
HACK: Move cluster context into a spot where we can change etcd keys
smarterclayton Dec 19, 2020
89bd94f
HACK: Allow wildcard watch across clusters
smarterclayton Jan 12, 2021
602cd36
HACK: Add consistent support of clusterName in all etcd store actions
davidfestal Aug 11, 2021
3eeb2da
HACK: Enable adding legacy scheme resources as CRDs...
davidfestal Mar 10, 2021
b6630c1
HACK: Use the dedicated table converter for legacy scheme CRDs (#6)
davidfestal May 19, 2021
07f788a
KUBEFIX: Add strategic merge patch support to CRDs ...
davidfestal Mar 30, 2021
8679582
WORKAROUND: Allow core Kube generated openapi to be available
smarterclayton Apr 1, 2021
326af03
HACK: Add CRD tenancy...
davidfestal Aug 11, 2021
84f2392
HACK: Better support client-go scheme CRDs
davidfestal Sep 20, 2021
2c724b1
MD file about KCP changes ...
davidfestal Sep 21, 2021
3e4c724
HACK: Make the Namespace admission multi-cluster-aware
davidfestal Sep 23, 2021
8f48114
HACK: Make the namepsace controller multi-cluster-aware
davidfestal Sep 27, 2021
b8ce5ef
HACK: fix klog import
ncdc Oct 20, 2021
e27ad74
HACK: fix hot-looping in naming controller
ncdc Nov 1, 2021
6c8577c
HACK: Search for the right CRD cluster when watching...
davidfestal Oct 7, 2021
34777ca
HACK: allow configuring the handler chain from options
stevekuznetsov Sep 16, 2021
e9ad3a0
HACK: opt kcp controllers out of multi-cluster
stevekuznetsov Sep 27, 2021
3b9864d
HACK: export continue token impl
stevekuznetsov Sep 27, 2021
4d2c563
HACK: expose unstructured creator and helpers
stevekuznetsov Sep 30, 2021
1089fca
HACK: rest: request: allow debugging incoming and outgoing requests
stevekuznetsov Oct 11, 2021
3b9bef0
HACK: tablewriter: allow a default type-less handler
stevekuznetsov Oct 11, 2021
1ae2f63
HACK: make e2e pass against kcp
stevekuznetsov Oct 11, 2021
6e55fe1
HACK: prefix cluster names with external host
stevekuznetsov Oct 12, 2021
10b9a57
server: move kcp-specific cluster handler to kcp
stevekuznetsov Oct 15, 2021
c60f28c
horrible hack: why?
stevekuznetsov Oct 19, 2021
9fcc14f
HACK: add generated bits for go 1.17
stevekuznetsov Nov 1, 2021
b34aaf8
client-go, client-gen: support cluster explicitly
stevekuznetsov Nov 3, 2021
24af74e
clients: regenerate
stevekuznetsov Nov 3, 2021
9b116af
e2e: add a kcp suite
stevekuznetsov Oct 19, 2021
53b9ea4
HACK: disable service and enpoint informers
stevekuznetsov Nov 16, 2021
3959037
HACK: etcd3: silence spam
stevekuznetsov Nov 18, 2021
60240c5
HACK: remove more spam
stevekuznetsov Nov 18, 2021
e835f37
HACK: fix etcd lib compilation
stevekuznetsov Nov 18, 2021
662e3cd
HACK: negotiation: tell the user what they did wrong
stevekuznetsov Nov 22, 2021
ee4d0a0
Additional checks to avoid panic due to a non-existant CRD.
jmprusi Nov 19, 2021
246d2c4
HACK: scope dynamic and discovery clients by cluster
stevekuznetsov Nov 22, 2021
8099635
HACK: chore: re-generate clientsets with clustered discovery
stevekuznetsov Nov 23, 2021
70c29bd
HACK: hard-code the number of servers again
stevekuznetsov Dec 3, 2021
06d5c72
HACK: add Cluster() to generated client Watch()
ncdc Dec 8, 2021
78304e6
Regenerate clients
ncdc Dec 8, 2021
97eb27e
HACK: Make discovery client logical-cluster aware
ncdc Dec 8, 2021
6b8774d
Add context to generated lister funcs
ncdc Dec 3, 2021
b66f238
Regenerate listers
ncdc Dec 3, 2021
d7cbe0a
Print old & new stacks for same path registrations
ncdc Dec 3, 2021
2876606
Add cluster name support to meta accessor
ncdc Dec 3, 2021
d45763c
HACK: let user set cert, key, token for loopback
ncdc Dec 6, 2021
452178b
HACK: fix crd openapi bug
ncdc Dec 6, 2021
11bb23e
HACK: discovery.GroupManager: expose Groups()
ncdc Dec 6, 2021
51ee520
Overridable client/informers for CRD apiserver
ncdc Dec 13, 2021
70d52d3
HACK: make CRDs more extensible
ncdc Dec 13, 2021
ef48aff
HACK: mini aggregator
ncdc Dec 6, 2021
850db6f
UNDO: contributed resources version hack
ncdc Dec 7, 2021
e3751b9
HACK: CRD discovery fixes
ncdc Dec 7, 2021
0f1328a
HACK: fix conversionLister
ncdc Dec 13, 2021
fc12ad6
UNDO: lcluster support for crdRegistrationController
ncdc Dec 13, 2021
c7acddc
REACT(1.23): correct import for clock
ncdc Dec 15, 2021
b599efe
REACT(1.23): update apiextensions-apiserver delegate
ncdc Dec 15, 2021
6563dc2
REACT(1.23): update flow control API version
ncdc Dec 15, 2021
f39d53d
REACT(1.23): s.Logs.Apply update
ncdc Dec 15, 2021
10e5e9f
REACT(1.23): revert any disabled OpenAPI features
ncdc Dec 15, 2021
146306f
FIXUP: regen clients to add missing cluster method to watch calls
ncdc Dec 15, 2021
b86d327
FIXUP: regen listers to add missing WithContext methods
ncdc Dec 15, 2021
a9ba39b
Regenerate openapi
ncdc Dec 15, 2021
67e40f9
REACT(1.23): enable flowcontrol v1b2
ncdc Dec 15, 2021
68a5158
UNDO: most kube-aggregator hacks
ncdc Dec 16, 2021
631c66d
revert logical cluster prefixing code
stevekuznetsov Jan 6, 2022
11a61c1
genericcontrolplane: make config plumbing composable
sttts Jan 28, 2022
efe4e65
Revert "HACK: let user set cert, key, token for loopback"
ncdc Jan 28, 2022
42bb0f5
enable multicluster for rbac resources
s-urbaniak Feb 2, 2022
0bfd266
add patch to multiclusterconfig
ncdc Feb 3, 2022
46effbf
mccrt: match 1.22 change
ncdc Feb 3, 2022
b96afb9
Add the clusterName to the PATCH object
davidfestal Feb 2, 2022
319da74
Now use cluster-aware clientset interface
davidfestal Feb 2, 2022
cfb7ceb
Merge pull request #30 from ncdc/kcp/prep-for-1.23
ncdc Feb 9, 2022
4662eb5
genericcontroleplane: split generic from kube-apiserver config
sttts Feb 1, 2022
b96caf9
genericcontrolplane: add CompletedServerRunOptions to make it composable
sttts Feb 4, 2022
39d9dac
genericcontrolplane: restore flags and validation
sttts Feb 4, 2022
50b2aff
Merge pull request #40 from sttts/sttts-split-generic-kube-apiserver-…
sttts Feb 10, 2022
64d2e2d
authorizer/webhook: make webhook authorizer cluster aware
s-urbaniak Feb 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ kubernetes.tar.gz
# generated files in any directory
# TODO(thockin): uncomment this when we stop committing the generated files.
#zz_generated.*
zz_generated.openapi.go
# HACK: Needed for short term dependencies on core openapi docs, will need to be refactored
# out of api dependencies in order to vendor a "pure" Kube API
# zz_generated.openapi.go
zz_generated_*_test.go

# TODO(roycaihw): remove this when we stop committing the generated definition
Expand Down
97 changes: 97 additions & 0 deletions KCP_RELATED_CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Why this forked repository ?

This repository carries the prototype branch which accumulates the hacks, prototypes, proto-KEP experiments, and workarounds required to make [KCP](https://github.com/kcp-dev/kcp/blob/main/README.md) a reality.
It is based on K8S 1.22 for now and commits are identified with basic labels like HACK/FEATURE/WORKAROUND.

# Summary of changes

The detailed explanation of the changes made on top of the Kubernetes code can be found in both the commit messages, and comments of the associated code.

However here is a summary of the changes, with the underlying requirements and motivations. Reading the linked investigation document first will help.

## A. Minimal API Server

__Investigation document:__ [minimal-api-server.md](https://github.com/kcp-dev/kcp/blob/main/docs/investigations/minimal-api-server.md)

1. New generic control plane based on kube api-server

It is mainly provided by code:

1. initially duplicated from kube api-server main code, and legacy scheme (`DUPLICATE` commits),

2. then stripped down from unnecessary things (ergress, api aggregation, webhooks) and APIs (Pods, Nodes, Deployments, etc ...) (`NEW` commits)

2. Support adding K8S built-in resources (`core/Pod`, `apps/Deployment`, ...) as CRDs

This is required since the new generic control plane scheme doesn't contain those resources any more.

This is provided by:

- hacks (`HACK` commits) that:

1. <a id="A-2-1"></a> allow the go-restful server to be bypassed for those resources, and route them to the CRD handler
2. <a id="A-2-2"></a> allow the CRD handler, and opanapi publisher, to support resources of the `core` group
3. <a id="A-2-3"></a> convert the `protobuf` requests sent to those resources resources to requests in the `application/json` content type, before letting the CRD handler serve them
4. <a id="A-2-4"></a> replace the table converter of CRDs that bring back those resources, with the default table converter of the related built-in resource

- a new feature, or potential kube fix (`KUBEFIX` commit), that:

5. <a id="A-2-5"></a> introduces the support of strategic merge patch for CRDs.
This support uses the OpenAPI v3 schema of the CRD to drive the SMP execution, but only adds a minimal implementation and doesn't fully support OpenAPI schemas that don't have expected `patchStrategy` and `patchMergeKey` annotations.
In order to avoid changing the behavior of existing client tools, the support is only added for those K8S built-in resources

## B. Logical clusters

__Investigation document:__ [logical-clusters.md](https://github.com/kcp-dev/kcp/blob/main/docs/investigations/logical-clusters.md)

1. Logical clusters represented as a prefix in etcd

It is mainly provided by hacks (`HACK` commits) that:

1. <a id="B-1-1"></a> allow intercepting the api server handler chain to set the expected logical cluster context value from either a given suffix in the request APIServer base URL, or a given header in the http request

2. <a id="B-1-2"></a> change etcd storage layer in order to use the logical cluster as a prefix in the etcd key

3. <a id="B-1-3"></a> allow wildcard watches that retrieve objects from all the logical clusters

4. <a id="B-1-4"></a> correctly get or set the `clusterName` metadata field in the storage layer operations based on the etcd key and its new prefix

2. Support of logical clusters (== tenancy) in the CRD management, OpenAPI and discovery endpoints, and clients used by controllers

<a id="B-2"></a>It is mainly provided by a hack (`HACK` commit) that adds CRD tenancy by ensuring that logical clusters are taken in account in:
- CRD-related controllers
- APIServices-related controllers
- Discovery + OpenAPI endpoints

In the current Kubernetes design, those 3 areas are highly coupled and intricated, which explains why this commit had to hack the code at various levels:
- client-go level
- controllers level,
- http handlers level.

While this gives a detailed idea of which code needs to be touched in order to enable CRD tenancy, a clean implementation would first require some refactoring, in order to build the required abstraction layers that would allow decoupling those areas.

# Potential client problems

Although these changes in the K8S codebase were made in order to keep the compatibility with Kuberntes client tools, there might be some problems:

## Incomplete protobuf support for built-in resources

In some contexts, like the `controller-runtime` library used by the Operator SDK, all the resources of the `client-go` scheme are created / updated using the `application/vnd.kubernetes.protobuf` content type.

However when these resources are in fact added as CRDs, in the KCP minimal API server scenario, these resources cannot be created / updated since the protobuf (de)serialization is not (and probably cannot be) supported for CRDs.
So for now in this case, the [A.2.3 hack mentioned above](#A-2-3) just converts the `protobuf` request to a `json` one, but this might not cover all the use-cases or corner cases.

The clean solution would probably be the negotiation of serialization type in `client-go`, which we haven't implemented yet, but which would work like this:
When a request for an unsupported serialization is returned, the server should reject it with a 406
and provide a list of supported content types. `client-go` should then examine whether it can satisfy such a request by encoding the object with a different scheme.
This would require a KEP but at least is in keeping with content negotiation on GET / WATCH in Kube

## Incomplete Strategic merge patch support for built-in resources

Client tools like `kubectl` assume that all K8S native resources (== `client-go` schema resources)
support strategic merge patch, and use it by default when updating or patching a resource.

In Kube, currently, strategic merge patch is not supported for CRDs, which would break compatibility with client tools for all the K8S natives resources that are in fact added as CRD in the KCP minimal api server.
The [A-2-5 change mentioned above](#A-2-5) tries to fix this by using the CRD openAPI v3 schema as the source of the required information that will drive the strategic merge patch execution.

While this fixes the problem in most cases, there might still be errors in case the OpenAPI v2 schema for such a resource is missing `x-kubernetes-patch-strategy` and `x-kubernetes-patch-merge-key` annotations when imported from the CRD OpenAPI v3 schema.
2 changes: 1 addition & 1 deletion cmd/kube-apiserver/app/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ var apiVersionPriorities = map[schema.GroupVersion]priority{
func apiServicesToRegister(delegateAPIServer genericapiserver.DelegationTarget, registration autoregister.AutoAPIServiceRegistration) []*v1.APIService {
apiServices := []*v1.APIService{}

for _, curr := range delegateAPIServer.ListedPaths() {
for _, curr := range delegateAPIServer.ListedPaths("") {
if curr == "/api/v1" {
apiService := makeAPIService(schema.GroupVersion{Group: "", Version: "v1"})
registration.AddAPIServiceToSyncOnStart(apiService)
Expand Down
2 changes: 1 addition & 1 deletion cmd/kube-apiserver/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func buildGenericConfig(
kubeVersion := version.Get()
genericConfig.Version = &kubeVersion

storageFactoryConfig := kubeapiserver.NewStorageFactoryConfig()
storageFactoryConfig := kubeapiserver.NewStorageFactoryConfig(legacyscheme.Scheme, legacyscheme.Codecs)
storageFactoryConfig.APIResourceConfig = genericConfig.MergedResourceConfig
completedStorageFactoryConfig, err := storageFactoryConfig.Complete(s.Etcd)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion cmd/kube-controller-manager/app/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"k8s.io/klog/v2"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apiserver/pkg/quota/v1/generic"
utilfeature "k8s.io/apiserver/pkg/util/feature"
Expand Down Expand Up @@ -466,7 +467,9 @@ func startModifiedNamespaceController(ctx context.Context, controllerContext Con
return nil, true, err
}

discoverResourcesFn := namespaceKubeClient.Discovery().ServerPreferredNamespacedResources
discoverResourcesFn := func(clusterName string) ([]*metav1.APIResourceList, error) {
return namespaceKubeClient.Discovery().ServerPreferredNamespacedResources()
}

namespaceController := namespacecontroller.NewNamespaceController(
namespaceKubeClient,
Expand Down
26 changes: 26 additions & 0 deletions hack/run-kcp-e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail
set -o xtrace

time make WHAT=test/e2e/e2e.test

kubeconfig="${WORKDIR}/.kcp2/data/admin.kubeconfig"

## each of the single-cluster contexts passes normal e2e
for context in "admin" "user" "other"; do
_output/local/bin/linux/amd64/e2e.test --e2e-verify-service-account=false --ginkgo.focus "Watchers" \
--kubeconfig "${kubeconfig}" --context "${context}" \
--provider local
done

# the multi-cluster list/watcher works with all the single-cluster contexts
_output/local/bin/linux/amd64/e2e.test --e2e-verify-service-account=false --ginkgo.focus "MultiClusterWorkflow" \
--kubeconfig "${kubeconfig}" --context "admin" \
--provider kcp \
--kcp-multi-cluster-kubeconfig "${kubeconfig}" --kcp-multi-cluster-context "cross-cluster" \
--kcp-secondary-kubeconfig "${kubeconfig}" --kcp-secondary-context "user" \
--kcp-tertiary-kubeconfig "${kubeconfig}" --kcp-tertiary-context "other" \
--kcp-clusterless-kubeconfig "${kubeconfig}" --kcp-clusterless-context "admin"
37 changes: 37 additions & 0 deletions pkg/api/genericcontrolplanescheme/scheme.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2014 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package genericcontrolplanescheme

import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
)

var (
// Scheme is the default instance of runtime.Scheme to which control plane types
// in the Kubernetes API are already registered.
// NOTE: If you are copying this file to start a new api group, STOP! This Scheme
// is special and should appear ONLY in the api group, unless you really know what
// you're doing.
Scheme = runtime.NewScheme()

// Codecs provides access to encoding and decoding for the scheme
Codecs = serializer.NewCodecFactory(Scheme)

// ParameterCodec handles versioning of objects that are converted to query parameters.
ParameterCodec = runtime.NewParameterCodec(Scheme)
)
33 changes: 33 additions & 0 deletions pkg/apis/core/install/genericcontrolplane/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2014 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package install installs the v1 monolithic api, making it available as an
// option to all of the API encoding/decoding machinery.
package genericcontrolplane

import (
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/kubernetes/pkg/apis/core"
v1 "k8s.io/kubernetes/pkg/apis/core/v1"
)

// Install registers the API group and adds types to a scheme
func Install(scheme *runtime.Scheme) {
utilruntime.Must(core.AddToGenericControlPlaneScheme(scheme))
utilruntime.Must(v1.AddToControlPlaneScheme(scheme))
utilruntime.Must(scheme.SetVersionPriority(v1.SchemeGroupVersion))
}
85 changes: 85 additions & 0 deletions pkg/apis/core/register_generic_control_plane.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Copyright 2020 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package core

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

var (
// GenericControlPlaneGroupName is the name of the group when installed in the generic control plane
GenericControlPlaneGroupName = "core"

// GenericControlPlaneSchemeGroupVersion is group version used to register these objects
GenericControlPlaneSchemeGroupVersion = schema.GroupVersion{Group: GenericControlPlaneGroupName, Version: "v1"}

// GenericControlPlaneSchemeBuilder object to register various known types for the control plane
GenericControlPlaneSchemeBuilder = runtime.NewSchemeBuilder(addGenericControlPlaneKnownTypes)

// AddToGenericControlPlaneScheme represents a func that can be used to apply all the registered
// funcs in a scheme
AddToGenericControlPlaneScheme = GenericControlPlaneSchemeBuilder.AddToScheme
)

func addGenericControlPlaneKnownTypes(scheme *runtime.Scheme) error {
if err := scheme.AddIgnoredConversionType(&metav1.TypeMeta{}, &metav1.TypeMeta{}); err != nil {
return err
}
scheme.AddKnownTypes(SchemeGroupVersion,
&Event{},
&EventList{},
&List{},
&LimitRange{},
&LimitRangeList{},
&ResourceQuota{},
&ResourceQuotaList{},
&Namespace{},
&NamespaceList{},
&ServiceAccount{},
&ServiceAccountList{},
&Secret{},
&SecretList{},
&SerializedReference{},
&RangeAllocation{},
&ConfigMap{},
&ConfigMapList{},
)

scheme.AddKnownTypes(GenericControlPlaneSchemeGroupVersion,
&Event{},
&EventList{},
&List{},
&LimitRange{},
&LimitRangeList{},
&ResourceQuota{},
&ResourceQuotaList{},
&Namespace{},
&NamespaceList{},
&ServiceAccount{},
&ServiceAccountList{},
&Secret{},
&SecretList{},
&SerializedReference{},
&RangeAllocation{},
&ConfigMap{},
&ConfigMapList{},
)

return nil
}
33 changes: 33 additions & 0 deletions pkg/apis/core/v1/register_generic_control_plane.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2017 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
v1 "k8s.io/api/core/v1"
)

var (
localGenericControlPlaneSchemeBuilder = &v1.GenericControlPlaneSchemeBuilder
AddToControlPlaneScheme = localGenericControlPlaneSchemeBuilder.AddToScheme
)

func init() {
// We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing.
localGenericControlPlaneSchemeBuilder.Register(addDefaultingFuncs, addConversionFuncs, RegisterConversions)
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (c *ClusterRoleAggregationController) syncClusterRole(ctx context.Context,
}

if utilfeature.DefaultFeatureGate.Enabled(features.ServerSideApply) {
err = c.applyClusterRoles(ctx, sharedClusterRole.Name, newPolicyRules)
err = c.applyClusterRoles(ctx, sharedClusterRole, newPolicyRules)
if errors.IsUnsupportedMediaType(err) { // TODO: Remove this fallback at least one release after ServerSideApply GA
// When Server Side Apply is not enabled, fallback to Update. This is required when running
// 1.21 since api-server can be 1.20 during the upgrade/downgrade.
Expand All @@ -140,8 +140,8 @@ func (c *ClusterRoleAggregationController) syncClusterRole(ctx context.Context,
return err
}

func (c *ClusterRoleAggregationController) applyClusterRoles(ctx context.Context, name string, newPolicyRules []rbacv1.PolicyRule) error {
clusterRoleApply := rbacv1ac.ClusterRole(name).
func (c *ClusterRoleAggregationController) applyClusterRoles(ctx context.Context, sharedClusterRole *rbacv1.ClusterRole, newPolicyRules []rbacv1.PolicyRule) error {
clusterRoleApply := rbacv1ac.ClusterRole(sharedClusterRole.Name).WithClusterName(sharedClusterRole.ClusterName).
WithRules(toApplyPolicyRules(newPolicyRules)...)

opts := metav1.ApplyOptions{FieldManager: "clusterrole-aggregation-controller", Force: true}
Expand Down
Loading