Skip to content

Commit 10933df

Browse files
committed
Add imageRebuildTrigger field to force module image rebuilds
This change introduces a new optional field `imageRebuildTrigger` in the Module and ManagedClusterModule CRDs. When the user changes this field's value, KMM clears all image statuses in the corresponding ModuleImagesConfig and re-verifies image existence, potentially triggering a rebuild.
1 parent a139564 commit 10933df

23 files changed

+393
-39
lines changed

api/v1beta1/module_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,12 @@ type ModuleSpec struct {
337337
// If specified, the pod's tolerations.
338338
// +optional
339339
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
340+
341+
// ImageRebuildTriggerGeneration is an optional counter that can be incremented to trigger a rebuild of the module images.
342+
// When this value changes (compared to the value stored in status), KMM will re-verify and potentially rebuild
343+
// all module images.
344+
// +optional
345+
ImageRebuildTriggerGeneration *int `json:"imageRebuildTriggerGeneration,omitempty"`
340346
}
341347

342348
// DaemonSetStatus contains the status for a daemonset deployed during
@@ -357,6 +363,10 @@ type ModuleStatus struct {
357363
DevicePlugin DaemonSetStatus `json:"devicePlugin,omitempty"`
358364
// ModuleLoader contains the status of the ModuleLoader daemonset
359365
ModuleLoader DaemonSetStatus `json:"moduleLoader,omitempty"`
366+
// ImageRebuildTriggerGeneration contains the last value of spec.imageRebuildTriggerGeneration that was applied.
367+
// When this differs from spec.imageRebuildTriggerGeneration, all module images will be re-verified and potentially rebuilt.
368+
// +optional
369+
ImageRebuildTriggerGeneration *int `json:"imageRebuildTriggerGeneration,omitempty"`
360370
}
361371

362372
//+kubebuilder:object:root=true

api/v1beta1/moduleimagesconfig_types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ type ModuleImagesConfigSpec struct {
7777
// be pushed to a defined repository
7878
// +optional
7979
PushBuiltImage bool `json:"pushBuiltImage"`
80+
81+
// ImageRebuildTriggerGeneration is an optional counter that, when incremented, triggers a re-verification
82+
// and potential rebuild of all module images. Propagated from Module.spec.imageRebuildTriggerGeneration.
83+
// +optional
84+
ImageRebuildTriggerGeneration *int `json:"imageRebuildTriggerGeneration,omitempty"`
8085
}
8186

8287
type ModuleImageState struct {
@@ -92,6 +97,12 @@ type ModuleImageState struct {
9297
// +kubebuilder:validation:Required
9398
type ModuleImagesConfigStatus struct {
9499
ImagesStates []ModuleImageState `json:"imagesStates"`
100+
101+
// ImageRebuildTriggerGeneration contains the last value of spec.imageRebuildTriggerGeneration that was applied.
102+
// When spec.imageRebuildTriggerGeneration differs from this value, all image statuses will be cleared
103+
// to trigger re-verification and potential rebuilds.
104+
// +optional
105+
ImageRebuildTriggerGeneration *int `json:"imageRebuildTriggerGeneration,omitempty"`
95106
}
96107

97108
// +kubebuilder:object:root=true

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd-hub/bases/hub.kmm.sigs.x-k8s.io_managedclustermodules.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,6 +2447,12 @@ spec:
24472447
required:
24482448
- container
24492449
type: object
2450+
imageRebuildTriggerGeneration:
2451+
description: |-
2452+
ImageRebuildTriggerGeneration is an optional counter that can be incremented to trigger a rebuild of the module images.
2453+
When this value changes (compared to the value stored in status), KMM will re-verify and potentially rebuild
2454+
all module images.
2455+
type: integer
24502456
imageRepoSecret:
24512457
description: |-
24522458
ImageRepoSecret is an optional secret that is used to pull both the module loader and the device plugin, and

config/crd-hub/bases/kmm.sigs.x-k8s.io_moduleimagesconfigs.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ spec:
4949
description: ImagePullPolicy defines the pull policy used for verifying
5050
the presence of the image
5151
type: string
52+
imageRebuildTriggerGeneration:
53+
description: |-
54+
ImageRebuildTriggerGeneration is an optional counter that, when incremented, triggers a re-verification
55+
and potential rebuild of all module images. Propagated from Module.spec.imageRebuildTriggerGeneration.
56+
type: integer
5257
imageRepoSecret:
5358
description: ImageRepoSecret contains pull secret for the image's
5459
repo, if needed
@@ -260,6 +265,12 @@ spec:
260265
ModuleImagesConfigStatus describes the status of the images that need to be verified (defined in the spec)
261266
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
262267
properties:
268+
imageRebuildTriggerGeneration:
269+
description: |-
270+
ImageRebuildTriggerGeneration contains the last value of spec.imageRebuildTriggerGeneration that was applied.
271+
When spec.imageRebuildTriggerGeneration differs from this value, all image statuses will be cleared
272+
to trigger re-verification and potential rebuilds.
273+
type: integer
263274
imagesStates:
264275
items:
265276
properties:

config/crd-hub/bases/kmm.sigs.x-k8s.io_modules.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2429,6 +2429,12 @@ spec:
24292429
required:
24302430
- container
24312431
type: object
2432+
imageRebuildTriggerGeneration:
2433+
description: |-
2434+
ImageRebuildTriggerGeneration is an optional counter that can be incremented to trigger a rebuild of the module images.
2435+
When this value changes (compared to the value stored in status), KMM will re-verify and potentially rebuild
2436+
all module images.
2437+
type: integer
24322438
imageRepoSecret:
24332439
description: |-
24342440
ImageRepoSecret is an optional secret that is used to pull both the module loader and the device plugin, and
@@ -3021,6 +3027,11 @@ spec:
30213027
format: int32
30223028
type: integer
30233029
type: object
3030+
imageRebuildTriggerGeneration:
3031+
description: |-
3032+
ImageRebuildTriggerGeneration contains the last value of spec.imageRebuildTriggerGeneration that was applied.
3033+
When this differs from spec.imageRebuildTriggerGeneration, all module images will be re-verified and potentially rebuilt.
3034+
type: integer
30243035
moduleLoader:
30253036
description: ModuleLoader contains the status of the ModuleLoader
30263037
daemonset

config/crd/bases/kmm.sigs.x-k8s.io_moduleimagesconfigs.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ spec:
4949
description: ImagePullPolicy defines the pull policy used for verifying
5050
the presence of the image
5151
type: string
52+
imageRebuildTriggerGeneration:
53+
description: |-
54+
ImageRebuildTriggerGeneration is an optional counter that, when incremented, triggers a re-verification
55+
and potential rebuild of all module images. Propagated from Module.spec.imageRebuildTriggerGeneration.
56+
type: integer
5257
imageRepoSecret:
5358
description: ImageRepoSecret contains pull secret for the image's
5459
repo, if needed
@@ -260,6 +265,12 @@ spec:
260265
ModuleImagesConfigStatus describes the status of the images that need to be verified (defined in the spec)
261266
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
262267
properties:
268+
imageRebuildTriggerGeneration:
269+
description: |-
270+
ImageRebuildTriggerGeneration contains the last value of spec.imageRebuildTriggerGeneration that was applied.
271+
When spec.imageRebuildTriggerGeneration differs from this value, all image statuses will be cleared
272+
to trigger re-verification and potential rebuilds.
273+
type: integer
263274
imagesStates:
264275
items:
265276
properties:

config/crd/bases/kmm.sigs.x-k8s.io_modules.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2429,6 +2429,12 @@ spec:
24292429
required:
24302430
- container
24312431
type: object
2432+
imageRebuildTriggerGeneration:
2433+
description: |-
2434+
ImageRebuildTriggerGeneration is an optional counter that can be incremented to trigger a rebuild of the module images.
2435+
When this value changes (compared to the value stored in status), KMM will re-verify and potentially rebuild
2436+
all module images.
2437+
type: integer
24322438
imageRepoSecret:
24332439
description: |-
24342440
ImageRepoSecret is an optional secret that is used to pull both the module loader and the device plugin, and
@@ -3021,6 +3027,11 @@ spec:
30213027
format: int32
30223028
type: integer
30233029
type: object
3030+
imageRebuildTriggerGeneration:
3031+
description: |-
3032+
ImageRebuildTriggerGeneration contains the last value of spec.imageRebuildTriggerGeneration that was applied.
3033+
When this differs from spec.imageRebuildTriggerGeneration, all module images will be re-verified and potentially rebuilt.
3034+
type: integer
30243035
moduleLoader:
30253036
description: ModuleLoader contains the status of the ModuleLoader
30263037
daemonset

config/rbac/role.yaml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ rules:
6969
- kmm.sigs.x-k8s.io
7070
resources:
7171
- modulebuildsignconfigs
72+
- preflightvalidations
7273
verbs:
7374
- create
75+
- delete
7476
- get
7577
- list
7678
- patch
@@ -115,15 +117,3 @@ rules:
115117
- nodemodulesconfigs/status
116118
verbs:
117119
- patch
118-
- apiGroups:
119-
- kmm.sigs.x-k8s.io
120-
resources:
121-
- preflightvalidations
122-
verbs:
123-
- create
124-
- delete
125-
- get
126-
- list
127-
- patch
128-
- update
129-
- watch

internal/controllers/hub/managedclustermodule_reconciler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func (rh *managedClusterModuleReconcilerHelper) setMicAsDesired(ctx context.Cont
231231
micName := mcm.Name + "-" + clusterName
232232
micNamespace := rh.clusterAPI.GetDefaultArtifactsNamespace()
233233
if err := rh.micAPI.CreateOrPatch(ctx, micName, micNamespace, images, mcm.Spec.ModuleSpec.ImageRepoSecret,
234-
mcm.Spec.ModuleSpec.ModuleLoader.Container.ImagePullPolicy, true, mcm); err != nil {
234+
mcm.Spec.ModuleSpec.ModuleLoader.Container.ImagePullPolicy, true, mcm.Spec.ModuleSpec.ImageRebuildTriggerGeneration, mcm); err != nil {
235235
return fmt.Errorf("failed to createOrPatch MIC %s: %v", micName, err)
236236
}
237237

0 commit comments

Comments
 (0)