Skip to content

Commit c57d144

Browse files
authored
Merge pull request #211 from limhawjia/feat-federate-controller-adoption
feat: allow adoption of orphaned federated objects
2 parents 8c01e4a + f2d1ff4 commit c57d144

File tree

11 files changed

+73
-26
lines changed

11 files changed

+73
-26
lines changed

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ jobs:
4545
version: v1.53.3
4646
only-new-issues: true
4747
args: >
48-
--timeout=5m
49-
--max-issues-per-linter=0
50-
--max-same-issues=0
48+
--timeout=8m
49+
--max-issues-per-linter=10
50+
--max-same-issues=10
5151
--uniq-by-line=false
5252
5353
verify-codegen:

.golangci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,9 @@ linters-settings:
256256
Copyright {{ YEAR }} The KubeAdmiral Authors\.
257257
258258
{{ MAIN }}
259-
BOILERPLATE: "^({{ KUBERNETES_BOILERPLATE }}|{{ KUBEADMIRAL_BOILERPLATE }})$"
259+
CREDIT_BOILERPLATE: |-
260+
The design of (the )?[a-zA-z0-9 ]*is inspired by [a-zA-z0-9 '-]*\. Kudos!
261+
BOILERPLATE: "^({{ KUBERNETES_BOILERPLATE }}|{{ KUBEADMIRAL_BOILERPLATE }}|{{ CREDIT_BOILERPLATE }})$"
260262
template: "{{ BOILERPLATE }}"
261263
forbidigo:
262264
# Forbid the following identifiers (list of regexp).

pkg/apis/core/v1alpha1/types_collectedstatus.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
66
You may obtain a copy of the License at
77
8-
http://www.apache.org/licenses/LICENSE-2.0
8+
http://www.apache.org/licenses/LICENSE-2.0
99
1010
Unless required by applicable law or agreed to in writing, software
1111
distributed under the License is distributed on an "AS IS" BASIS,

pkg/controllers/federate/controller.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -306,18 +306,19 @@ func (c *FederateController) reconcile(ctx context.Context, key workerKey) (stat
306306
}
307307

308308
if fedObject != nil {
309-
// To account for the very small chance of name collision, we verify the owner reference before proceeding.
310-
ownedbySource := false
311-
312-
for _, ref := range fedObject.GetOwnerReferences() {
313-
if schema.FromAPIVersionAndKind(ref.APIVersion, ref.Kind) == key.gvk &&
314-
sourceObject.GetName() == ref.Name {
315-
ownedbySource = true
309+
var owner *metav1.OwnerReference
310+
ownerRefs := fedObject.GetOwnerReferences()
311+
for i, ref := range ownerRefs {
312+
if ref.Controller != nil && *ref.Controller {
313+
owner = &ownerRefs[i]
316314
break
317315
}
318316
}
319317

320-
if !ownedbySource {
318+
// To account for the very small chance of name collision, we verify the owner reference before proceeding.
319+
// Note that we allow the adoption of orphaned federated objects.
320+
if owner != nil &&
321+
(schema.FromAPIVersionAndKind(owner.APIVersion, owner.Kind) != key.gvk || owner.Name != sourceObject.GetName()) {
321322
logger.Error(nil, "Federated object not owned by source object, possible name collision detected")
322323
return worker.StatusErrorNoRetry
323324
}

pkg/controllers/nsautoprop/controller.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2929
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3030
"k8s.io/apimachinery/pkg/labels"
31-
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3231
corev1informers "k8s.io/client-go/informers/core/v1"
3332
kubeclient "k8s.io/client-go/kubernetes"
3433
"k8s.io/client-go/tools/cache"
@@ -282,7 +281,7 @@ func (c *Controller) reconcile(ctx context.Context, qualifiedName common.Qualifi
282281
string(adoption.ConflictResolutionAdopt),
283282
)
284283
if err != nil {
285-
utilruntime.HandleError(err)
284+
keyedLogger.Error(err, "Failed to ensure annotation")
286285
return worker.StatusError
287286
}
288287
needsUpdate = needsUpdate || isDirty
@@ -294,7 +293,7 @@ func (c *Controller) reconcile(ctx context.Context, qualifiedName common.Qualifi
294293
string(orphaning.OrphanManagedResourcesAdopted),
295294
)
296295
if err != nil {
297-
utilruntime.HandleError(err)
296+
keyedLogger.Error(err, "Failed to ensure annotation")
298297
return worker.StatusError
299298
}
300299
needsUpdate = needsUpdate || isDirty
@@ -307,7 +306,7 @@ func (c *Controller) reconcile(ctx context.Context, qualifiedName common.Qualifi
307306
typeConfig.GetControllers(),
308307
)
309308
if err != nil {
310-
utilruntime.HandleError(err)
309+
keyedLogger.Error(err, "Failed to update pending controllers")
311310
return worker.StatusError
312311
}
313312
needsUpdate = needsUpdate || isDirty

pkg/controllers/scheduler/framework/plugins/apiresources/apiresources.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// The design of this plugin is heavily inspired by karmada-scheduler. Kudos!
1+
// The design of this plugin is inspired by karmada-scheduler. Kudos!
22

33
package apiresources
44

pkg/controllers/scheduler/framework/plugins/apiresources/apiresources_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2023 The KubeAdmiral 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+
117
package apiresources
218

319
import (

pkg/util/collectedstatusadapters/adapter.go

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2023 The KubeAdmiral 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+
117
package collectedstatusadapters
218

319
import (

pkg/util/fedobjectadapters/adapters.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2023 The KubeAdmiral 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+
117
package fedobjectadapters
218

319
import (
@@ -138,4 +154,3 @@ func Delete(
138154
return fedv1a1Client.FederatedObjects(namespace).Delete(ctx, name, opts)
139155
}
140156
}
141-

pkg/util/informermanager/federatedinformermanager.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ func NewFederatedInformerManager(
105105
queue: workqueue.NewRateLimitingQueue(
106106
workqueue.NewItemExponentialFailureRateLimiter(100*time.Millisecond, 10*time.Second),
107107
),
108-
podListerSemaphore: semaphore.NewWeighted(3), // TODO: make this configurable
109-
initialClusters: sets.New[string](),
110-
podEventHandlers: []*ResourceEventHandlerWithClusterFuncs{},
111-
podEventRegistrations: map[string]map[*ResourceEventHandlerWithClusterFuncs]cache.ResourceEventHandlerRegistration{},
108+
podListerSemaphore: semaphore.NewWeighted(3), // TODO: make this configurable
109+
initialClusters: sets.New[string](),
110+
podEventHandlers: []*ResourceEventHandlerWithClusterFuncs{},
111+
podEventRegistrations: map[string]map[*ResourceEventHandlerWithClusterFuncs]cache.ResourceEventHandlerRegistration{},
112112
}
113113

114114
clusterInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{

pkg/util/signals/signal.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ import (
2525
"k8s.io/klog/v2"
2626
)
2727

28-
var (
29-
gracefulShutdownSignals = []os.Signal{os.Interrupt, syscall.SIGTERM}
30-
)
28+
var gracefulShutdownSignals = []os.Signal{os.Interrupt, syscall.SIGTERM}
3129

3230
// SetupSignalHandler configures the cancel func to be called when one of the gracefulShutdownSignals is received. A
3331
// subsequent gracefulShutdownSignal would trigger a forceful termination of the program.

0 commit comments

Comments
 (0)