- Add three application metadata labels to HelmRelease: - apps.cozystack.io/application.kind - apps.cozystack.io/application.group - apps.cozystack.io/application.name - 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 mapping configuration - Add functionality to update HelmRelease chart from CozystackResourceDefinition using label selectors Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
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
|
|
}
|