Skip to content
This repository was archived by the owner on Apr 25, 2023. It is now read-only.

Commit d188d22

Browse files
authored
Merge pull request #1012 from marun/fix-cluster-scoped-ftc
Ensure cluster scoped sync controller starts without namespace ftc
2 parents 84e6d3c + 0750db2 commit d188d22

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

pkg/controller/federatedtypeconfig/controller.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,25 @@ func (c *Controller) startSyncController(tc *corev1b1.FederatedTypeConfig) error
296296
// cluster-scoped KubeFed control plane. A namespace-scoped
297297
// control plane would still have to use a non-shared informer due
298298
// to it not being possible to limit its scope.
299+
300+
ftc := tc.DeepCopyObject().(*corev1b1.FederatedTypeConfig)
299301
kind := tc.Spec.FederatedType.Kind
300-
fedNamespaceAPIResource, err := c.getFederatedNamespaceAPIResource()
301-
if err != nil {
302-
return errors.Wrapf(err, "Unable to start sync controller for %q due to missing FederatedTypeConfig for namespaces", kind)
302+
303+
// A sync controller for a namespaced resource must be supplied
304+
// with the ftc for namespaces so that it can consider federated
305+
// namespace placement when determining the placement for
306+
// contained resources.
307+
var fedNamespaceAPIResource *metav1.APIResource
308+
if ftc.GetNamespaced() {
309+
var err error
310+
fedNamespaceAPIResource, err = c.getFederatedNamespaceAPIResource()
311+
if err != nil {
312+
return errors.Wrapf(err, "Unable to start sync controller for %q due to missing FederatedTypeConfig for namespaces", kind)
313+
}
303314
}
315+
304316
stopChan := make(chan struct{})
305-
ftc := tc.DeepCopyObject().(*corev1b1.FederatedTypeConfig)
306-
err = synccontroller.StartKubeFedSyncController(c.controllerConfig, stopChan, ftc, fedNamespaceAPIResource)
317+
err := synccontroller.StartKubeFedSyncController(c.controllerConfig, stopChan, ftc, fedNamespaceAPIResource)
307318
if err != nil {
308319
close(stopChan)
309320
return errors.Wrapf(err, "Error starting sync controller for %q", kind)
@@ -375,9 +386,6 @@ func (c *Controller) namespaceFTCExists() bool {
375386
}
376387

377388
func (c *Controller) getFederatedNamespaceAPIResource() (*metav1.APIResource, error) {
378-
c.lock.Lock()
379-
defer c.lock.Unlock()
380-
381389
qualifiedName := util.QualifiedName{
382390
Namespace: c.controllerConfig.KubeFedNamespace,
383391
Name: util.NamespaceName,

0 commit comments

Comments
 (0)