mirror of
https://github.com/outbackdingo/cozystack.git
synced 2026-01-27 10:18:39 +00:00
[cozystack-controller] Introduce new dashboard-controller [dashboard] Introduce new dashboard based on openapi-ui Co-authored-by: kklinch0 <kklinch0@gmail.com> Signed-off-by: kklinch0 <kklinch0@gmail.com> Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
55 lines
1.6 KiB
Go
55 lines
1.6 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{
|
|
chartAppMap: make(map[chartRef]*cozyv1alpha1.CozystackResourceDefinition),
|
|
appCRDMap: make(map[appRef]*cozyv1alpha1.CozystackResourceDefinition),
|
|
}
|
|
for _, crd := range crds.Items {
|
|
chRef := chartRef{
|
|
crd.Spec.Release.Chart.SourceRef.Name,
|
|
crd.Spec.Release.Chart.Name,
|
|
}
|
|
appRef := appRef{
|
|
"apps.cozystack.io",
|
|
crd.Spec.Application.Kind,
|
|
}
|
|
|
|
newRef := crd
|
|
if _, exists := cfg.chartAppMap[chRef]; exists {
|
|
l.Info("duplicate chart mapping detected; ignoring subsequent entry", "key", chRef)
|
|
} else {
|
|
cfg.chartAppMap[chRef] = &newRef
|
|
}
|
|
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
|
|
}
|