@@ -28,6 +28,7 @@ import (
2828 "github.com/kcp-dev/api-syncagent/internal/crypto"
2929 "github.com/kcp-dev/api-syncagent/internal/discovery"
3030 "github.com/kcp-dev/api-syncagent/internal/projection"
31+ "github.com/kcp-dev/api-syncagent/internal/resources/reconciling"
3132 syncagentv1alpha1 "github.com/kcp-dev/api-syncagent/sdk/apis/syncagent/v1alpha1"
3233
3334 kcpdevv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1"
@@ -135,16 +136,28 @@ func (r *Reconciler) reconcile(ctx context.Context, log *zap.SugaredLogger, pubR
135136 }
136137
137138 // project the CRD (i.e. strip unwanted versions, rename values etc.)
138- projectedCRD , err := projection .ApplyProjection (crd , pubResource )
139+ projectedCRD , err := projection .ProjectCRD (crd , pubResource )
139140 if err != nil {
140141 return nil , fmt .Errorf ("failed to apply projection rules: %w" , err )
141142 }
142143
143144 // generate a unique name for this exact state of the CRD
144145 arsName := r .getAPIResourceSchemaName (projectedCRD )
146+ wsCtx := kontext .WithCluster (ctx , r .lcName )
147+
148+ projectedConversions , err := projection .ProjectConversionRules (pubResource )
149+ if err != nil {
150+ return nil , fmt .Errorf ("failed to apply projection rules to conversions: %w" , err )
151+ }
152+
153+ // only reconcile if there are rules because APIConversions must contain at least one conversion
154+ if len (projectedConversions ) > 0 {
155+ if err := r .reconcileConversions (wsCtx , arsName , projectedConversions ); err != nil {
156+ return nil , fmt .Errorf ("failed to reconcile APIConversions: %w" , err )
157+ }
158+ }
145159
146160 // ensure ARS exists (don't try to reconcile it, it's basically entirely immutable)
147- wsCtx := kontext .WithCluster (ctx , r .lcName )
148161 ars := & kcpdevv1alpha1.APIResourceSchema {}
149162 err = r .kcpClient .Get (wsCtx , types.NamespacedName {Name : arsName }, ars , & ctrlruntimeclient.GetOptions {})
150163
@@ -169,6 +182,8 @@ func (r *Reconciler) reconcile(ctx context.Context, log *zap.SugaredLogger, pubR
169182 }
170183 }
171184
185+ // reconcile a matching APIConversion object
186+
172187 return nil , nil
173188}
174189
@@ -206,3 +221,11 @@ func (r *Reconciler) getAPIResourceSchemaName(crd *apiextensionsv1.CustomResourc
206221 // include a leading "v" to prevent SHA-1 hashes with digits to break the name
207222 return fmt .Sprintf ("v%s.%s.%s" , checksum [:8 ], crd .Spec .Names .Plural , crd .Spec .Group )
208223}
224+
225+ func (r * Reconciler ) reconcileConversions (ctx context.Context , arsName string , rules []kcpdevv1alpha1.APIVersionConversion ) error {
226+ factories := []reconciling.NamedAPIConversionReconcilerFactory {
227+ r .createAPIConversionReconciler (arsName , r .agentName , rules ),
228+ }
229+
230+ return reconciling .ReconcileAPIConversions (ctx , factories , "" , r .kcpClient )
231+ }
0 commit comments