@@ -54,14 +54,13 @@ const (
54
54
)
55
55
56
56
type 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
65
64
}
66
65
67
66
// Add creates a new controller and adds it to the given manager.
@@ -72,18 +71,16 @@ func Add(
72
71
log * zap.SugaredLogger ,
73
72
numWorkers int ,
74
73
agentName string ,
75
- apiExportName string ,
76
74
prFilter labels.Selector ,
77
75
) error {
78
76
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 ,
87
84
}
88
85
89
86
_ , err := builder .ControllerManagedBy (mgr ).
@@ -138,14 +135,14 @@ func (r *Reconciler) reconcile(ctx context.Context, log *zap.SugaredLogger, pubR
138
135
}
139
136
140
137
// project the CRD
141
- projectedCRD , err := r .applyProjection (r . apiExportName , crd , pubResource )
138
+ projectedCRD , err := r .applyProjection (crd , pubResource )
142
139
if err != nil {
143
140
return nil , fmt .Errorf ("failed to apply projection rules: %w" , err )
144
141
}
145
142
146
143
// to prevent changing the source GVK e.g. from "apps/v1 Daemonset" to "core/v1 Pod",
147
144
// 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 )
149
146
150
147
// ARS'es cannot be updated, their entire spec is immutable. For now we do not care about
151
148
// 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
155
152
err = r .kcpClient .Get (wsCtx , types.NamespacedName {Name : arsName }, ars , & ctrlruntimeclient.GetOptions {})
156
153
157
154
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 {
159
156
return nil , fmt .Errorf ("failed to create APIResourceSchema: %w" , err )
160
157
}
161
158
} else if err != nil {
@@ -178,7 +175,7 @@ func (r *Reconciler) reconcile(ctx context.Context, log *zap.SugaredLogger, pubR
178
175
return nil , nil
179
176
}
180
177
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 {
182
179
// prefix is irrelevant as the reconciling framework will use arsName anyway
183
180
converted , err := kcpdevv1alpha1 .CRDToAPIResourceSchema (projectedCRD , "irrelevant" )
184
181
if err != nil {
@@ -191,9 +188,6 @@ func (r *Reconciler) createAPIResourceSchema(ctx context.Context, log *zap.Sugar
191
188
syncagentv1alpha1 .SourceGenerationAnnotation : fmt .Sprintf ("%d" , projectedCRD .Generation ),
192
189
syncagentv1alpha1 .AgentNameAnnotation : r .agentName ,
193
190
}
194
- ars .Labels = map [string ]string {
195
- syncagentv1alpha1 .APIGroupLabel : apigroup ,
196
- }
197
191
ars .Spec .Group = converted .Spec .Group
198
192
ars .Spec .Names = converted .Spec .Names
199
193
ars .Spec .Scope = converted .Spec .Scope
@@ -204,9 +198,8 @@ func (r *Reconciler) createAPIResourceSchema(ctx context.Context, log *zap.Sugar
204
198
return r .kcpClient .Create (ctx , ars )
205
199
}
206
200
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 ) {
208
202
result := crd .DeepCopy ()
209
- result .Spec .Group = apiGroup
210
203
211
204
// Currently CRDs generated by our discovery mechanism already set these to true, but that's just
212
205
// 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
219
212
return result , nil
220
213
}
221
214
215
+ if projection .Group != "" {
216
+ result .Spec .Group = projection .Group
217
+ }
218
+
222
219
if projection .Version != "" {
223
220
result .Spec .Versions [0 ].Name = projection .Version
224
221
}
@@ -252,9 +249,9 @@ func (r *Reconciler) applyProjection(apiGroup string, crd *apiextensionsv1.Custo
252
249
253
250
// getAPIResourceSchemaName generates the name for the ARS in kcp. Note that
254
251
// 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 {
256
253
checksum := crypto .Hash (crd .Spec .Names )
257
254
258
255
// 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 )
260
257
}
0 commit comments