check if federated type is referred by an existing FTC
@@ -282,6 +282,25 @@ func CreateResources(cmdOut io.Writer, config *rest.Config, resources *typeResou
} else if err != nil {
return errors.Wrapf(err, "Error getting CRD %q", resources.CRD.Name)
} else {
+ ftcs := &fedv1b1.FederatedTypeConfigList{}
+ err := client.List(context.TODO(), ftcs, namespace)
+ if err != nil {
+ return errors.Wrap(err, "Error getting FederatedTypeConfig list")
+ }
+
+ for _, ftc := range ftcs.Items {
+ if concreteTypeConfig.Name == ftc.Name {
+ continue
+ }
+
+ fedType := ftc.Spec.FederatedType
+ name := typeconfig.GroupQualifiedName(metav1.APIResource{Name: fedType.PluralName, Group: fedType.Group})
+ if name == existingCRD.Name {
+ return errors.Errorf("Failed to enable federation of %q due to the FederatedTypeConfig for %q already referencing a federated type CRD named %q. If these target types are distinct despite sharing the same kind, specifying a non-default --federation-group should allow %q to be enabled.",
+ concreteTypeConfig.Name, ftc.Name, name, concreteTypeConfig.Name)
+ }
+ }
+
existingCRD.Spec = resources.CRD.Spec
_, err = crdClient.CustomResourceDefinitions().Update(existingCRD)
if err != nil {
