@@ -54,14 +54,13 @@ const (
5454)
5555
5656type Reconciler struct {
57- localClient ctrlruntimeclient.Client
58- kcpClient ctrlruntimeclient.Client
59- restConfig * rest.Config
60- log * zap.SugaredLogger
61- recorder record.EventRecorder
62- lcName logicalcluster.Name
63- agentName string
64- apiExportName string
57+ localClient ctrlruntimeclient.Client
58+ kcpClient ctrlruntimeclient.Client
59+ restConfig * rest.Config
60+ log * zap.SugaredLogger
61+ recorder record.EventRecorder
62+ lcName logicalcluster.Name
63+ agentName string
6564}
6665
6766// Add creates a new controller and adds it to the given manager.
@@ -72,18 +71,16 @@ func Add(
7271 log * zap.SugaredLogger ,
7372 numWorkers int ,
7473 agentName string ,
75- apiExportName string ,
7674 prFilter labels.Selector ,
7775) error {
7876 reconciler := & Reconciler {
79- localClient : mgr .GetClient (),
80- kcpClient : kcpCluster .GetClient (),
81- restConfig : mgr .GetConfig (),
82- lcName : lcName ,
83- log : log .Named (ControllerName ),
84- recorder : mgr .GetEventRecorderFor (ControllerName ),
85- agentName : agentName ,
86- apiExportName : apiExportName ,
77+ localClient : mgr .GetClient (),
78+ kcpClient : kcpCluster .GetClient (),
79+ restConfig : mgr .GetConfig (),
80+ lcName : lcName ,
81+ log : log .Named (ControllerName ),
82+ recorder : mgr .GetEventRecorderFor (ControllerName ),
83+ agentName : agentName ,
8784 }
8885
8986 _ , err := builder .ControllerManagedBy (mgr ).
@@ -138,14 +135,14 @@ func (r *Reconciler) reconcile(ctx context.Context, log *zap.SugaredLogger, pubR
138135 }
139136
140137 // project the CRD
141- projectedCRD , err := r .applyProjection (r . apiExportName , crd , pubResource )
138+ projectedCRD , err := r .applyProjection (crd , pubResource )
142139 if err != nil {
143140 return nil , fmt .Errorf ("failed to apply projection rules: %w" , err )
144141 }
145142
146143 // to prevent changing the source GVK e.g. from "apps/v1 Daemonset" to "core/v1 Pod",
147144 // we include the source GVK in hashed form in the final APIResourceSchema name.
148- arsName := r .getAPIResourceSchemaName (r . apiExportName , projectedCRD )
145+ arsName := r .getAPIResourceSchemaName (projectedCRD )
149146
150147 // ARS'es cannot be updated, their entire spec is immutable. For now we do not care about
151148 // CRDs being updated on the service cluster, but in the future (TODO) we must allow
@@ -155,7 +152,7 @@ func (r *Reconciler) reconcile(ctx context.Context, log *zap.SugaredLogger, pubR
155152 err = r .kcpClient .Get (wsCtx , types.NamespacedName {Name : arsName }, ars , & ctrlruntimeclient.GetOptions {})
156153
157154 if apierrors .IsNotFound (err ) {
158- if err := r .createAPIResourceSchema (wsCtx , log , r . apiExportName , projectedCRD , arsName ); err != nil {
155+ if err := r .createAPIResourceSchema (wsCtx , log , projectedCRD , arsName ); err != nil {
159156 return nil , fmt .Errorf ("failed to create APIResourceSchema: %w" , err )
160157 }
161158 } else if err != nil {
@@ -178,7 +175,7 @@ func (r *Reconciler) reconcile(ctx context.Context, log *zap.SugaredLogger, pubR
178175 return nil , nil
179176}
180177
181- func (r * Reconciler ) createAPIResourceSchema (ctx context.Context , log * zap.SugaredLogger , apigroup string , projectedCRD * apiextensionsv1.CustomResourceDefinition , arsName string ) error {
178+ func (r * Reconciler ) createAPIResourceSchema (ctx context.Context , log * zap.SugaredLogger , projectedCRD * apiextensionsv1.CustomResourceDefinition , arsName string ) error {
182179 // prefix is irrelevant as the reconciling framework will use arsName anyway
183180 converted , err := kcpdevv1alpha1 .CRDToAPIResourceSchema (projectedCRD , "irrelevant" )
184181 if err != nil {
@@ -191,9 +188,6 @@ func (r *Reconciler) createAPIResourceSchema(ctx context.Context, log *zap.Sugar
191188 syncagentv1alpha1 .SourceGenerationAnnotation : fmt .Sprintf ("%d" , projectedCRD .Generation ),
192189 syncagentv1alpha1 .AgentNameAnnotation : r .agentName ,
193190 }
194- ars .Labels = map [string ]string {
195- syncagentv1alpha1 .APIGroupLabel : apigroup ,
196- }
197191 ars .Spec .Group = converted .Spec .Group
198192 ars .Spec .Names = converted .Spec .Names
199193 ars .Spec .Scope = converted .Spec .Scope
@@ -204,9 +198,8 @@ func (r *Reconciler) createAPIResourceSchema(ctx context.Context, log *zap.Sugar
204198 return r .kcpClient .Create (ctx , ars )
205199}
206200
207- func (r * Reconciler ) applyProjection (apiGroup string , crd * apiextensionsv1.CustomResourceDefinition , pr * syncagentv1alpha1.PublishedResource ) (* apiextensionsv1.CustomResourceDefinition , error ) {
201+ func (r * Reconciler ) applyProjection (crd * apiextensionsv1.CustomResourceDefinition , pr * syncagentv1alpha1.PublishedResource ) (* apiextensionsv1.CustomResourceDefinition , error ) {
208202 result := crd .DeepCopy ()
209- result .Spec .Group = apiGroup
210203
211204 // Currently CRDs generated by our discovery mechanism already set these to true, but that's just
212205 // because it doesn't care to set them correctly; we keep this code here because from here on,
@@ -219,6 +212,10 @@ func (r *Reconciler) applyProjection(apiGroup string, crd *apiextensionsv1.Custo
219212 return result , nil
220213 }
221214
215+ if projection .Group != "" {
216+ result .Spec .Group = projection .Group
217+ }
218+
222219 if projection .Version != "" {
223220 result .Spec .Versions [0 ].Name = projection .Version
224221 }
@@ -252,9 +249,9 @@ func (r *Reconciler) applyProjection(apiGroup string, crd *apiextensionsv1.Custo
252249
253250// getAPIResourceSchemaName generates the name for the ARS in kcp. Note that
254251// kcp requires, just like CRDs, that ARS are named following a specific pattern.
255- func (r * Reconciler ) getAPIResourceSchemaName (apiGroup string , crd * apiextensionsv1.CustomResourceDefinition ) string {
252+ func (r * Reconciler ) getAPIResourceSchemaName (crd * apiextensionsv1.CustomResourceDefinition ) string {
256253 checksum := crypto .Hash (crd .Spec .Names )
257254
258255 // include a leading "v" to prevent SHA-1 hashes with digits to break the name
259- return fmt .Sprintf ("v%s.%s.%s" , checksum [:8 ], crd .Spec .Names .Plural , apiGroup )
256+ return fmt .Sprintf ("v%s.%s.%s" , checksum [:8 ], crd .Spec .Names .Plural , crd . Spec . Group )
260257}
0 commit comments