Skip to content

Commit 47d5aaa

Browse files
committed
prevent issues when people watch the APIExport and ARS are missing
On-behalf-of: @SAP christoph.mewes@sap.com
1 parent ae24d6c commit 47d5aaa

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

internal/controller/apiexport/controller.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,27 +157,36 @@ func (r *Reconciler) reconcile(ctx context.Context, apiExport *kcpdevv1alpha1.AP
157157
return err != nil
158158
})
159159

160-
// for each PR, we note down the created ARS and also the GVKs of related resources
161-
newARSList := sets.New[string]()
160+
// Create two lists of schema names: ready schemas are those already processed by the
161+
// apiresourceschema controller, the other list includes all possible schema names.
162+
// For calculating the required permission claims we need _all_ schemas, but we actually
163+
// only want to store ready schemas in the APIExport in order to not confuse other
164+
// downstream components.
165+
readySchemaNames := sets.New[string]()
166+
allSchemaNames := sets.New[string]()
162167
for _, pubResource := range filteredPubResources {
163168
schemaName, err := r.getSchemaName(ctx, &pubResource)
164169
if err != nil {
165170
return fmt.Errorf("failed to determine schema name for PublishedResource %s: %w", pubResource.Name, err)
166171
}
167172

168-
newARSList.Insert(schemaName)
173+
allSchemaNames.Insert(schemaName)
174+
175+
if pubResource.Status.ResourceSchemaName != "" {
176+
readySchemaNames.Insert(schemaName)
177+
}
169178
}
170179

171180
// To determine if the GVR of a related resource needs to be listed as a permission claim,
172181
// we first need to figure out all the GVRs our APIExport contains. This is not just the
173182
// list of ARS we just built, but also potentially other ARS's that exist in the APIExport
174183
// and that we would not touch.
175-
allARSList := mergeResourceSchemas(apiExport.Spec.LatestResourceSchemas, newARSList)
184+
mergedSchemaNames := mergeResourceSchemas(apiExport.Spec.LatestResourceSchemas, allSchemaNames)
176185

177186
// turn the flat list of schema names ("version.resource.group") into a lookup table consisting
178187
// of group/resource only
179188
ourOwnResources := sets.New[schema.GroupResource]()
180-
for _, schemaName := range allARSList {
189+
for _, schemaName := range mergedSchemaNames {
181190
gvr, err := parseSchemaName(schemaName)
182191
if err != nil {
183192
return fmt.Errorf("failed to assemble own resources: %w", err)
@@ -236,7 +245,7 @@ func (r *Reconciler) reconcile(ctx context.Context, apiExport *kcpdevv1alpha1.AP
236245

237246
// reconcile an APIExport in kcp
238247
factories := []reconciling.NamedAPIExportReconcilerFactory{
239-
r.createAPIExportReconciler(newARSList, claimedResources, r.agentName, r.apiExportName, r.recorder),
248+
r.createAPIExportReconciler(readySchemaNames, claimedResources, r.agentName, r.apiExportName, r.recorder),
240249
}
241250

242251
if err := reconciling.ReconcileAPIExports(ctx, factories, "", r.kcpClient); err != nil {

0 commit comments

Comments
 (0)