| 
									
										
										
										
											2025-08-01 06:31:57 +08:00
										 |  |  | package app | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"context" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/grafana/grafana-app-sdk/app" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana-app-sdk/logging" | 
					
						
							| 
									
										
										
										
											2025-10-04 17:33:10 +08:00
										 |  |  | 	"github.com/grafana/grafana-app-sdk/operator" | 
					
						
							| 
									
										
										
										
											2025-08-01 06:31:57 +08:00
										 |  |  | 	"github.com/grafana/grafana-app-sdk/simple" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/apps/alerting/rules/pkg/apis" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func New(cfg app.Config) (app.App, error) { | 
					
						
							|  |  |  | 	managedKinds := make([]simple.AppManagedKind, 0) | 
					
						
							|  |  |  | 	for _, kinds := range apis.GetKinds() { | 
					
						
							|  |  |  | 		for _, kind := range kinds { | 
					
						
							|  |  |  | 			managedKinds = append(managedKinds, simple.AppManagedKind{Kind: kind}) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	c := simple.AppConfig{ | 
					
						
							|  |  |  | 		Name:       "alerting.rules", | 
					
						
							|  |  |  | 		KubeConfig: cfg.KubeConfig, | 
					
						
							|  |  |  | 		InformerConfig: simple.AppInformerConfig{ | 
					
						
							| 
									
										
										
										
											2025-10-04 17:33:10 +08:00
										 |  |  | 			InformerOptions: operator.InformerOptions{ | 
					
						
							|  |  |  | 				ErrorHandler: func(ctx context.Context, err error) { | 
					
						
							|  |  |  | 					logging.DefaultLogger.With("error", err).Error("Informer processing error") | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2025-08-01 06:31:57 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		ManagedKinds: managedKinds, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	a, err := simple.NewApp(c) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = a.ValidateManifest(cfg.ManifestData) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return a, nil | 
					
						
							|  |  |  | } |