feat: add a way to sync Kubernetes manifests in Omni#2231
feat: add a way to sync Kubernetes manifests in Omni#2231Unix4ever wants to merge 1 commit intosiderolabs:mainfrom
Conversation
Orzelius
left a comment
There was a problem hiding this comment.
Not as much a code review as just a bunch of questions from my part
client/pkg/omni/resources/omni/cluster_kubernetes_manifest_status.go
Outdated
Show resolved
Hide resolved
internal/backend/runtime/omni/controllers/omni/kubernetes/cluster_manifest_status.go
Outdated
Show resolved
Hide resolved
internal/backend/runtime/omni/controllers/omni/kubernetes/cluster_manifest_status.go
Outdated
Show resolved
Hide resolved
internal/backend/runtime/omni/controllers/omni/kubernetes/cluster_manifest_status.go
Outdated
Show resolved
Hide resolved
internal/backend/runtime/omni/controllers/omni/kubernetes/cluster_manifest_status.go
Outdated
Show resolved
Hide resolved
internal/backend/runtime/omni/controllers/omni/kubernetes/cluster_manifest_status.go
Outdated
Show resolved
Hide resolved
internal/backend/runtime/omni/controllers/omni/kubernetes/cluster_manifest_status.go
Outdated
Show resolved
Hide resolved
client/pkg/omni/resources/omni/cluster_kubernetes_manifest_status.go
Outdated
Show resolved
Hide resolved
|
How is someone intended to use this initially? Is this only part of cluster templates or can it be added to any cluster in Omni? |
I'm going to make it part of the cluster templates in the next PR. |
7a46b50 to
d28cbd8
Compare
|
Pretty much rewrote the controller. Made the status updates more frequent, fixed more issues there:
The status now contains more phases as well as the information about the resource being created. Example: metadata:
namespace: default
type: ClusterKubernetesManifestsStatuses.omni.sidero.dev
id: talos-default
version: 34
owner: ClusterKubernetesManifestsStatusController
phase: running
created: 2026-02-06T12:38:46Z
updated: 2026-02-06T13:20:00Z
spec:
manifests:
default_nginx-deployment_apps_Deployment:
phase: 3
lasterror: ""
mode: 1
kind: Deployment
name: nginx-deployment
namespace: default
errors: {}
outofsync: 0
total: 1 |
Manifests support two modes: - `FULL` - Omni will keep the manifest in sync always. - `ONE_TIME` - Omni will apply the manifest only if it doesn't exist. If the manifest is removed by hand and then changed in Omni it will be applied too. Manifests are applied using service side apply, Omni now has two inventories: `omni-internal-inventory` and `omni-user-inventory`: - User inventory will be used for user managed manifests. - Internal one will be used for the manifests which are created by Omni controllers (workloadproxy, advanced healtcheck service). Manifests also support setting namespace to all namespaced resources. It might be useful for the huge manifest files which are supplied without the namespace (similar to `kubectl apply -n namespace -f manifest.yaml`). Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
|
|
||
| compressedData := doCompress(data, config) | ||
|
|
||
| x.Data = "" |
There was a problem hiding this comment.
What if we compress them unconditionally? Our old compressing resources were done kinda that way for kind of backwards compatibility. Maybe we can just do this simpler.
There was a problem hiding this comment.
It has more than that. It also doesn't compress if the manifest size is small. So I thought it kinda makes sense to use the same approach here.
| string namespace = 6; | ||
| } | ||
|
|
||
| map<string, ManifestStatus> manifests = 1; |
There was a problem hiding this comment.
Curious, does this mean there is no order of apply between manifests? I guess it'd probably work anyway, our code would keep trying to apply them, but normally there can be an order in k8s manifests - an example is creating a CRD and a CR. If so, we could maybe turn these into slices instead?
There was a problem hiding this comment.
This is the status resource.
While the manifests are ordered: separate KubernetesManifest resources are ordered by COSI using the ID, and it's possible to put many manifests to a single resource delimiting by ---, then it's a slice.
|
|
||
| // LabelSystemManifest marks the manifest as the system manifest, so it shouldn't be editable by the user. | ||
| // tsgen:LabelSystemManifest | ||
| LabelSystemManifest = SystemLabelPrefix + "system-manifest" |
There was a problem hiding this comment.
Show the system manifest flag inside the ClusterKubernetesManifestsStatus.
|
|
||
| if len(oneTimeManifests) > 0 { | ||
| if err = ctrl.syncOneTime(ctx, logger, oneTimeManifests, client, clusterKubernetesManifestsStatus); err != nil { | ||
| errs = errors.Join(errs, err) |
There was a problem hiding this comment.
wrap the error to add more context
|
|
||
| for inventory, objects := range manifestsByInventory { | ||
| if err = ctrl.sync(ctx, logger, objects, inventory, client, clusterKubernetesManifestsStatus); err != nil { | ||
| errs = errors.Join(errs, err) |
There was a problem hiding this comment.
wrap the error to add more context
| KubernetesManifestSpec.Mode mode = 3; | ||
| string kind = 4; | ||
| string name = 5; | ||
| string namespace = 6; |
There was a problem hiding this comment.
add last modified date.
| return apierrors.IsInvalid(err) || apierrors.IsBadRequest(err) || apierrors.IsForbidden(err) || | ||
| apierrors.IsRequestEntityTooLargeError(err) || webhookError(err) || validationError(err) || strings.Contains(err.Error(), "reconcile failed") |
There was a problem hiding this comment.
Consider making it less restricted
|
|
||
| //nolint:exhaustive | ||
| switch result.Type { | ||
| case event.PruneType: |
There was a problem hiding this comment.
Try to use inventory to track prune/delete events.
| continue | ||
| } | ||
|
|
||
| _, err = dr.Create(ctx, manifest, v1.CreateOptions{FieldManager: constants.KubernetesFieldManagerName}) |
There was a problem hiding this comment.
| _, err = dr.Create(ctx, manifest, v1.CreateOptions{FieldManager: constants.KubernetesFieldManagerName}) | |
| _, err = dr.Apply(ctx, manifest, v1.CreateOptions{FieldManager: constants.KubernetesFieldManagerName}) |
Manifests support two modes:
FULL- Omni will keep the manifest in sync always.ONE_TIME- Omni will apply the manifest only if it doesn't exist. If the manifest is removed by hand and then changed in Omni it will be applied too.Manifests are applied using service side apply, Omni now has two inventories:
omni-internal-inventoryandomni-user-inventory:Manifests also support setting namespace to all namespaced resources. It might be useful for the huge manifest files which are supplied without the namespace (similar to
kubectl apply -n namespace -f manifest.yaml).