@@ -23,6 +23,7 @@ import (
2323 "encoding/json"
2424 "fmt"
2525 "reflect"
26+ "slices"
2627 "strings"
2728
2829 "github.com/kcp-dev/logicalcluster/v3"
@@ -146,7 +147,7 @@ func (r *Reconciler) reconcile(ctx context.Context, log *zap.SugaredLogger, pubR
146147 err = r .kcpClient .Get (wsCtx , types.NamespacedName {Name : arsName }, ars , & ctrlruntimeclient.GetOptions {})
147148
148149 if apierrors .IsNotFound (err ) {
149- if err := r .createAPIResourceSchema (wsCtx , log , r .apiExportName , projectedCRD , arsName ); err != nil {
150+ if err := r .createAPIResourceSchema (wsCtx , log , r .apiExportName , projectedCRD , arsName , pubResource . Spec . Resource . Version ); err != nil {
150151 return nil , fmt .Errorf ("failed to create APIResourceSchema: %w" , err )
151152 }
152153 } else if err != nil {
@@ -169,7 +170,17 @@ func (r *Reconciler) reconcile(ctx context.Context, log *zap.SugaredLogger, pubR
169170 return nil , nil
170171}
171172
172- func (r * Reconciler ) createAPIResourceSchema (ctx context.Context , log * zap.SugaredLogger , apigroup string , projectedCRD * apiextensionsv1.CustomResourceDefinition , arsName string ) error {
173+ func (r * Reconciler ) createAPIResourceSchema (ctx context.Context , log * zap.SugaredLogger , apigroup string , projectedCRD * apiextensionsv1.CustomResourceDefinition , arsName string , selectedVersion string ) error {
174+ // At this moment we ignore every non-selected version in the CRD, as we have not fully
175+ // decided on how to support the API version lifecycle yet. Having multiple versions in
176+ // the CRD will make kcp require a `conversion` to also be configured. Since we cannot
177+ // enforce that and want to instead work with existing CRDs as best as we can, we chose
178+ // this option (instead of error'ing out if a conversion is missing).
179+ projectedCRD .Spec .Conversion = nil
180+ projectedCRD .Spec .Versions = slices .DeleteFunc (projectedCRD .Spec .Versions , func (v apiextensionsv1.CustomResourceDefinitionVersion ) bool {
181+ return v .Name != selectedVersion
182+ })
183+
173184 // prefix is irrelevant as the reconciling framework will use arsName anyway
174185 converted , err := kcpdevv1alpha1 .CRDToAPIResourceSchema (projectedCRD , "irrelevant" )
175186 if err != nil {
0 commit comments