Commit 985bd76
authored
feat: Support cross-namespace package references with PackageRef field (#203)
### Motivation
The current Function CRD uses a simple `Package` field to reference packages, which limits the ability to reference packages from different namespaces. This change introduces a new `PackageRef` structure that supports cross-namespace package references while maintaining backward compatibility and proper label management.
The main problems this solves:
1. **Cross-namespace package references**: Functions can now reference packages from different namespaces
2. **Improved package label management**: Package labels now include namespace information to avoid conflicts
3. **Better validation**: Enhanced webhook validation for cross-namespace references
4. **Consistent labeling**: Automatic generation of package labels with namespace prefix
### Modifications
1. **Updated Function CRD structure**:
- Replaced `Package` field with `PackageRef` structure containing `Name` and `Namespace` fields
- Updated all test files to use the new `PackageRef` structure
2. **Enhanced webhook validation**:
- Modified `function_webhook.go` to validate cross-namespace package references
- Updated package label generation to include namespace prefix (format: `namespace.package-name`)
- Added comprehensive tests for cross-namespace scenarios
3. **Improved controller logic**:
- Updated `function_controller.go` to handle cross-namespace package lookups
- Modified `mapPackageToFunctions` to work with namespace-aware package labels
- Removed manual package label management from controller (now handled by webhook)
4. **Enhanced test coverage**:
- Added extensive tests for cross-namespace package references
- Updated existing tests to use `PackageRef` instead of `Package`
- Added tests for automatic package label generation
- Added integration tests for multiple functions with auto-generated labels
5. **Updated package webhook**:
- Modified `packages_webhook.go` to use namespace-aware package labels when finding referencing functions
The changes maintain backward compatibility while providing a more robust and flexible package reference system that supports cross-namespace operations.1 parent 2ce7841 commit 985bd76
File tree
11 files changed
+523
-141
lines changed- operator
- api/v1alpha1
- config
- crd/bases
- samples
- internal
- controller
- webhook/v1alpha1
11 files changed
+523
-141
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
24 | 36 | | |
25 | 37 | | |
26 | 38 | | |
| |||
31 | 43 | | |
32 | 44 | | |
33 | 45 | | |
34 | | - | |
| 46 | + | |
35 | 47 | | |
36 | | - | |
| 48 | + | |
37 | 49 | | |
38 | 50 | | |
39 | 51 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
58 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
59 | 68 | | |
60 | 69 | | |
61 | 70 | | |
| |||
107 | 116 | | |
108 | 117 | | |
109 | 118 | | |
110 | | - | |
| 119 | + | |
111 | 120 | | |
112 | 121 | | |
113 | 122 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
| 87 | + | |
| 88 | + | |
96 | 89 | | |
97 | 90 | | |
98 | 91 | | |
99 | | - | |
100 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
101 | 97 | | |
102 | 98 | | |
103 | 99 | | |
104 | 100 | | |
105 | 101 | | |
106 | 102 | | |
107 | 103 | | |
108 | | - | |
| 104 | + | |
109 | 105 | | |
110 | 106 | | |
111 | 107 | | |
| |||
213 | 209 | | |
214 | 210 | | |
215 | 211 | | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | 212 | | |
235 | 213 | | |
236 | 214 | | |
| |||
279 | 257 | | |
280 | 258 | | |
281 | 259 | | |
282 | | - | |
283 | | - | |
| 260 | + | |
| 261 | + | |
284 | 262 | | |
285 | 263 | | |
286 | 264 | | |
| |||
306 | 284 | | |
307 | 285 | | |
308 | 286 | | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
309 | 296 | | |
310 | 297 | | |
311 | 298 | | |
| |||
327 | 314 | | |
328 | 315 | | |
329 | 316 | | |
330 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
331 | 321 | | |
332 | 322 | | |
333 | | - | |
334 | | - | |
| 323 | + | |
335 | 324 | | |
336 | 325 | | |
337 | 326 | | |
338 | | - | |
339 | 327 | | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
346 | 343 | | |
347 | 344 | | |
348 | 345 | | |
| |||
0 commit comments