This change is extracted from - https://github.com/cozystack/cozystack/pull/1641 and reworked to work standalone ## What this PR does This PR extracts changes from the https://github.com/cozystack/cozystack/pull/1641. It adds application metadata labels to HelmReleases and updates the filtering mechanism to use labels instead of chart/sourceRef matching. Changes: - Add three application metadata labels (`apps.cozystack.io/application.kind`, `apps.cozystack.io/application.group`, `apps.cozystack.io/application.name`) when creating/updating HelmRelease via Cozystack-API - Replace `shouldIncludeHelmRelease` filtering with label-based filtering in Get, List, and Update methods - Always add kind and group label requirements in List for precise filtering - Update CozystackResourceDefinitionController to watch only HelmReleases with `cozystack.io/ui=true` label - Update LineageControllerWebhook to extract metadata directly from HelmRelease labels instead of using chart mapping configuration - Add functionality to update HelmRelease chart from CozystackResourceDefinition using label selectors ### Release note ```release-note [registry] Add application labels and update filtering mechanism to use label-based filtering instead of chart/sourceRef matching ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added application metadata labels (kind, group, name) and exported label keys for HelmRelease identification. * New reconciler keeps HelmRelease charts in sync with application CRDs. * **Refactor** * Mapping, listing and selection moved to label-driven logic; reconciliation responsibilities split so core reconciler focuses on restart/debounce while a separate reconciler updates HelmReleases. * **Chores** * Migration script to backfill application labels on existing HelmReleases. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package lineagecontrollerwebhook
|
|
|
|
import (
|
|
"context"
|
|
|
|
cozyv1alpha1 "github.com/cozystack/cozystack/api/v1alpha1"
|
|
ctrl "sigs.k8s.io/controller-runtime"
|
|
"sigs.k8s.io/controller-runtime/pkg/log"
|
|
)
|
|
|
|
// +kubebuilder:rbac:groups=cozystack.io,resources=cozystackresourcedefinitions,verbs=list;watch;get
|
|
|
|
func (c *LineageControllerWebhook) SetupWithManagerAsController(mgr ctrl.Manager) error {
|
|
return ctrl.NewControllerManagedBy(mgr).
|
|
For(&cozyv1alpha1.CozystackResourceDefinition{}).
|
|
Complete(c)
|
|
}
|
|
|
|
func (c *LineageControllerWebhook) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
|
l := log.FromContext(ctx)
|
|
crds := &cozyv1alpha1.CozystackResourceDefinitionList{}
|
|
if err := c.List(ctx, crds); err != nil {
|
|
l.Error(err, "failed reading CozystackResourceDefinitions")
|
|
return ctrl.Result{}, err
|
|
}
|
|
cfg := &runtimeConfig{
|
|
appCRDMap: make(map[appRef]*cozyv1alpha1.CozystackResourceDefinition),
|
|
}
|
|
for _, crd := range crds.Items {
|
|
appRef := appRef{
|
|
"apps.cozystack.io",
|
|
crd.Spec.Application.Kind,
|
|
}
|
|
|
|
newRef := crd
|
|
if _, exists := cfg.appCRDMap[appRef]; exists {
|
|
l.Info("duplicate app mapping detected; ignoring subsequent entry", "key", appRef)
|
|
} else {
|
|
cfg.appCRDMap[appRef] = &newRef
|
|
}
|
|
}
|
|
c.config.Store(cfg)
|
|
return ctrl.Result{}, nil
|
|
}
|