mirror of
https://github.com/stakater/Reloader.git
synced 2026-08-20 12:36:26 +00:00
refactor(reloader): replace CreateOrUpdate with Runnable for metadata publishing and update RBAC to include watch permission
This commit is contained in:
@@ -119,8 +119,8 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("setting up reconcilers: %w", err)
|
||||
}
|
||||
|
||||
if err := metadata.CreateOrUpdate(mgr.GetClient(), cfg, log); err != nil {
|
||||
log.Error(err, "Failed to create metadata ConfigMap")
|
||||
if err := mgr.Add(metadata.Runnable(mgr.GetClient(), cfg, log)); err != nil {
|
||||
log.Error(err, "Failed to add metadata publisher")
|
||||
// Non-fatal, continue starting
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
apiVersion: v1
|
||||
name: reloader
|
||||
description: Reloader chart that runs on kubernetes
|
||||
version: 2.2.7
|
||||
version: 2.3.0
|
||||
appVersion: v1.4.12
|
||||
keywords:
|
||||
- Reloader
|
||||
|
||||
@@ -76,6 +76,7 @@ rules:
|
||||
- get
|
||||
- update
|
||||
- patch
|
||||
- watch
|
||||
{{- if .Values.reloader.ignoreCronJobs }}{{- else }}
|
||||
- apiGroups:
|
||||
- "batch"
|
||||
|
||||
@@ -67,6 +67,7 @@ rules:
|
||||
- get
|
||||
- update
|
||||
- patch
|
||||
- watch
|
||||
- apiGroups:
|
||||
- "batch"
|
||||
resources:
|
||||
|
||||
@@ -40,10 +40,12 @@ func (p *Publisher) Publish(ctx context.Context) error {
|
||||
configMap := metaInfo.ToConfigMap()
|
||||
|
||||
existing := &corev1.ConfigMap{}
|
||||
err := p.client.Get(ctx, client.ObjectKey{
|
||||
Name: ConfigMapName,
|
||||
Namespace: namespace,
|
||||
}, existing)
|
||||
err := p.client.Get(
|
||||
ctx, client.ObjectKey{
|
||||
Name: ConfigMapName,
|
||||
Namespace: namespace,
|
||||
}, existing,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
if !errors.IsNotFound(err) {
|
||||
@@ -73,8 +75,23 @@ func PublishMetaInfoConfigMap(ctx context.Context, c client.Client, cfg *config.
|
||||
return publisher.Publish(ctx)
|
||||
}
|
||||
|
||||
// CreateOrUpdate creates or updates the metadata ConfigMap using the provided client.
|
||||
func CreateOrUpdate(c client.Client, cfg *config.Config, log logr.Logger) error {
|
||||
ctx := context.Background()
|
||||
return PublishMetaInfoConfigMap(ctx, c, cfg, log)
|
||||
// Runnable returns a controller-runtime Runnable that publishes the metadata ConfigMap
|
||||
// when the manager starts. This ensures the cache is ready before accessing the API.
|
||||
func Runnable(c client.Client, cfg *config.Config, log logr.Logger) RunnableFunc {
|
||||
return func(ctx context.Context) error {
|
||||
if err := PublishMetaInfoConfigMap(ctx, c, cfg, log); err != nil {
|
||||
log.Error(err, "Failed to create metadata ConfigMap")
|
||||
// Non-fatal, don't return error to avoid crashing the manager
|
||||
}
|
||||
<-ctx.Done()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// RunnableFunc is a function that implements the controller-runtime Runnable interface.
|
||||
type RunnableFunc func(context.Context) error
|
||||
|
||||
// Start implements the Runnable interface.
|
||||
func (r RunnableFunc) Start(ctx context.Context) error {
|
||||
return r(ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user