@@ -37,7 +37,6 @@ func (u byUID) Swap(i, j int) { u[i], u[j] = u[j], u[i] }
37
37
38
38
type conflictChecker struct {
39
39
listAPIBindings func (clusterName logicalcluster.Name ) ([]* apisv1alpha1.APIBinding , error )
40
- getAPIExportByPath func (path logicalcluster.Path , name string ) (* apisv1alpha1.APIExport , error )
41
40
getAPIResourceSchema func (clusterName logicalcluster.Name , name string ) (* apisv1alpha1.APIResourceSchema , error )
42
41
getCRD func (clusterName logicalcluster.Name , name string ) (* apiextensionsv1.CustomResourceDefinition , error )
43
42
listCRDs func (clusterName logicalcluster.Name ) ([]* apiextensionsv1.CustomResourceDefinition , error )
@@ -50,14 +49,12 @@ type conflictChecker struct {
50
49
// newConflictChecker creates a CRD conflict checker for the given cluster.
51
50
func newConflictChecker (clusterName logicalcluster.Name ,
52
51
listAPIBindings func (clusterName logicalcluster.Name ) ([]* apisv1alpha1.APIBinding , error ),
53
- getAPIExportByPath func (path logicalcluster.Path , name string ) (* apisv1alpha1.APIExport , error ),
54
52
getAPIResourceSchema func (clusterName logicalcluster.Name , name string ) (* apisv1alpha1.APIResourceSchema , error ),
55
53
getCRD func (clusterName logicalcluster.Name , name string ) (* apiextensionsv1.CustomResourceDefinition , error ),
56
54
listCRDs func (clusterName logicalcluster.Name ) ([]* apiextensionsv1.CustomResourceDefinition , error ),
57
55
) (* conflictChecker , error ) {
58
56
ncc := & conflictChecker {
59
57
listAPIBindings : listAPIBindings ,
60
- getAPIExportByPath : getAPIExportByPath ,
61
58
getAPIResourceSchema : getAPIResourceSchema ,
62
59
getCRD : getCRD ,
63
60
listCRDs : listCRDs ,
@@ -71,35 +68,8 @@ func newConflictChecker(clusterName logicalcluster.Name,
71
68
return nil , err
72
69
}
73
70
for _ , b := range bindings {
74
- if b .Spec .Reference .Export == nil {
75
- // this should not happen because of validation.
76
- return nil , fmt .Errorf ("APIBinding %s|%s has no cluster reference" , logicalcluster .From (b ), b .Name )
77
- }
78
- path := logicalcluster .NewPath (b .Spec .Reference .Export .Path )
79
- if path .Empty () {
80
- path = logicalcluster .From (b ).Path ()
81
- }
82
- apiExport , err := ncc .getAPIExportByPath (path , b .Spec .Reference .Export .Name )
83
- if err != nil {
84
- return nil , err
85
- }
86
-
87
- boundSchemaUIDs := sets .New [string ]()
88
- for _ , boundResource := range b .Status .BoundResources {
89
- boundSchemaUIDs .Insert (boundResource .Schema .UID )
90
- }
91
-
92
- for _ , schemaName := range apiExport .Spec .LatestResourceSchemas {
93
- schema , err := ncc .getAPIResourceSchema (logicalcluster .From (apiExport ), schemaName )
94
- if err != nil {
95
- return nil , err
96
- }
97
-
98
- if ! boundSchemaUIDs .Has (string (schema .UID )) {
99
- continue
100
- }
101
-
102
- crd , err := ncc .getCRD (SystemBoundCRDsClusterName , string (schema .UID ))
71
+ for _ , br := range b .Status .BoundResources {
72
+ crd , err := ncc .getCRD (SystemBoundCRDsClusterName , br .Schema .UID )
103
73
if err != nil {
104
74
return nil , err
105
75
}
@@ -121,6 +91,8 @@ func newConflictChecker(clusterName logicalcluster.Name,
121
91
return ncc , nil
122
92
}
123
93
94
+ // Check checks if the given schema from the given APIBinding conflicts with any
95
+ // CRD or any other APIBinding.
124
96
func (ncc * conflictChecker ) Check (binding * apisv1alpha1.APIBinding , s * apisv1alpha1.APIResourceSchema ) error {
125
97
for _ , crd := range ncc .crds {
126
98
if other , found := ncc .crdToBinding [crd .Name ]; found && other .Name == binding .Name {
0 commit comments