Skip to content

Commit 95799cf

Browse files
Merge pull request #1862 from ncdc/0.7/skip-projected-resources
[release-0.7] deletors: skip projected resources
2 parents bfed9f6 + be47352 commit 95799cf

File tree

4 files changed

+63
-7
lines changed

4 files changed

+63
-7
lines changed

pkg/informer/informer.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ import (
4242
"k8s.io/client-go/tools/cache"
4343
"k8s.io/klog/v2"
4444

45-
"github.com/kcp-dev/kcp/pkg/apis/tenancy"
4645
metadataclient "github.com/kcp-dev/kcp/pkg/metadata"
46+
"github.com/kcp-dev/kcp/pkg/projection"
4747
)
4848

4949
const (
@@ -426,16 +426,17 @@ func (d *DynamicDiscoverySharedInformerFactory) updateInformers() {
426426
group := parts[0]
427427
version := parts[1]
428428
resource := parts[2]
429+
gvr := gvrFor(group, version, resource)
429430

430-
// Don't start a dynamic informer for tenancy.kcp.dev/v1beta1 Workspaces. These are a virtual projection of
431-
// data from tenancy.kcp.dev/v1alpha1 ClusterWorkspaces. Starting an informer for them causes problems when
432-
// the virtual-workspaces server is deployed separately. See https://github.com/kcp-dev/kcp/issues/1654 for
433-
// more details.
434-
if group == tenancy.GroupName && version == "v1beta1" && resource == "workspaces" {
431+
// Don't start a dynamic informer for projected resources such as tenancy.kcp.dev/v1beta1 Workspaces
432+
// (these are a virtual projection of data from tenancy.kcp.dev/v1alpha1 ClusterWorkspaces).
433+
// Starting an informer for them causes problems when the virtual-workspaces server is deployed
434+
// separately. See https://github.com/kcp-dev/kcp/issues/1654 for more details.
435+
if projection.Includes(gvr) {
435436
continue
436437
}
437438

438-
latest[gvrFor(group, version, resource)] = struct{}{}
439+
latest[gvr] = struct{}{}
439440
}
440441

441442
// Grab a read lock to compare against d.informers to see if we need to start or stop any informers

pkg/projection/projected_apis.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Copyright 2022 The KCP Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package projection
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/runtime/schema"
21+
22+
tenancyv1beta1 "github.com/kcp-dev/kcp/pkg/apis/tenancy/v1beta1"
23+
)
24+
25+
var projectedAPIs map[schema.GroupVersionResource]struct{}
26+
27+
func init() {
28+
projectedAPIs = map[schema.GroupVersionResource]struct{}{
29+
tenancyv1beta1.SchemeGroupVersion.WithResource("workspaces"): {},
30+
}
31+
}
32+
33+
// Includes returns true if gvr is for a projected API. An API is projected if it is not stored in etcd and instead
34+
// comes from some other data that is actually stored in etcd. For example, Workspaces (tenancy.kcp.dev/v1beta1) are
35+
// projected; the real data comes from ClusterWorkspaces (tenancy.kcp.dev/v1alpha1).
36+
func Includes(gvr schema.GroupVersionResource) bool {
37+
_, exists := projectedAPIs[gvr]
38+
return exists
39+
}

pkg/reconciler/apis/apibindingdeletion/apibinding_deletor.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"k8s.io/klog/v2"
3030

3131
apisv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/apis/v1alpha1"
32+
"github.com/kcp-dev/kcp/pkg/projection"
3233
)
3334

3435
type gvrDeletionMetadata struct {
@@ -58,6 +59,13 @@ func (c *Controller) deleteAllCRs(ctx context.Context, apibinding *apisv1alpha1.
5859
Version: version,
5960
}
6061

62+
// Don't try to delete projected resources such as tenancy.kcp.dev v1beta1 Workspaces - these are virtual
63+
// projections and we shouldn't try to delete them. The projections will disappear when the real underlying
64+
// data (e.g. ClusterWorkspaces) are deleted.
65+
if projection.Includes(gvr) {
66+
continue
67+
}
68+
6169
deletionMetadata, err := c.deleteAllCR(ctx, logicalcluster.From(apibinding), gvr)
6270
if err != nil {
6371
deleteContentErrs = append(deleteContentErrs, err)

pkg/reconciler/tenancy/clusterworkspacedeletion/deletion/workspace_resource_deletor.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import (
5252
tenancyv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/tenancy/v1alpha1"
5353
conditionsv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/third_party/conditions/apis/conditions/v1alpha1"
5454
"github.com/kcp-dev/kcp/pkg/apis/third_party/conditions/util/conditions"
55+
"github.com/kcp-dev/kcp/pkg/projection"
5556
)
5657

5758
const (
@@ -395,6 +396,13 @@ func (d *workspacedResourcesDeleter) deleteAllContent(ctx context.Context, ws *t
395396
}
396397
deleteContentErrs := []error{}
397398
for gvr, verbs := range groupVersionResources {
399+
// Don't try to delete projected resources such as tenancy.kcp.dev v1beta1 Workspaces - these are virtual
400+
// projections and we shouldn't try to delete them. The projections will disappear when the real underlying
401+
// data (e.g. ClusterWorkspaces) are deleted.
402+
if projection.Includes(gvr) {
403+
continue
404+
}
405+
398406
gvrDeletionMetadata, err := d.deleteAllContentForGroupVersionResource(ctx, wsClusterName, gvr, verbs, workspaceDeletedAt)
399407
if err != nil {
400408
// If there is an error, hold on to it but proceed with all the remaining

0 commit comments

Comments
 (0)