Provisioning: Remove temporary logic to test clients in jobs operator (#110758)

Remove temporary logic to test clients in jobs operator
This commit is contained in:
Roberto Jiménez Sánchez
2025-09-08 14:15:13 +02:00
committed by GitHub
parent 958f5a7c52
commit ace05e999d
3 changed files with 9 additions and 89 deletions
+8 -8
View File
@@ -4,12 +4,6 @@ Git sync has two different controllers: the jobs controller and the repo control
## Jobs Controller
> [!WARNING]
> This controller has current limitations:
>
> - Does not start the ConcurrentJobDriver yet. Notifications are logged but not consumed by workers here.
> - Job processing (claim/renew/update/complete) isn't implemented yet as it requires refactoring of some components.
### Behavior
- Watches provisioning `Jobs` and emits notifications on job creation.
@@ -51,6 +45,7 @@ This binary currently wires informers and emits job-create notifications. In the
- `make build`
2. Ensure the following services are running locally: provisioning API server, secrets service API server, repository controller, unified storage, and auth.
3. Create a operator.ini file:
```
[database]
ensure_default_org_and_user = false
@@ -65,12 +60,15 @@ token_exchange_url = http://localhost:6481/sign/access-token
# Uncomment to enable history cleanup via Loki. First ensure the Provisioning API is configured with Loki for job history (see `createJobHistoryConfigFromSettings` in `pkg/registry/apis/provisioning/register.go`).
# history_expiration = 24h
```
3. Start the controller:
- `GF_DEFAULT_TARGET=operator GF_OPERATOR_NAME=provisioning-jobs ./bin/darwin-arm64/grafana server target --config=conf/operator.ini`
- `GF_DEFAULT_TARGET=operator GF_OPERATOR_NAME=provisioning-jobs ./bin/darwin-arm64/grafana server target --config=conf/operator.ini`
#### TLS Configuration Examples
- **Production with proper TLS verification**:
```
[operator]
provisioning_server_url = https://localhost:6446
@@ -83,6 +81,7 @@ token_exchange_url = http://localhost:6481/sign/access-token
```
- **Mutual TLS authentication**:
```
[operator]
provisioning_server_url = https://localhost:6446
@@ -97,6 +96,7 @@ token_exchange_url = http://localhost:6481/sign/access-token
```
- **Development with self-signed certificates (insecure)**:
```
[operator]
provisioning_server_url = https://localhost:6446
@@ -155,4 +155,4 @@ curl -X POST https://localhost:6446/apis/provisioning.grafana.app/v0alpha1/names
This controller is responsible for watching repositories. It will eventually do health checks, queue sync jobs, and create/delete github hooks.
To run locally, run `GF_DEFAULT_TARGET=operator GF_OPERATOR_NAME=provisioning-repo ./bin/darwin-arm64/grafana server target --config=conf/operator.ini`
To run locally, run `GF_DEFAULT_TARGET=operator GF_OPERATOR_NAME=provisioning-repo ./bin/darwin-arm64/grafana server target --config=conf/operator.ini`
@@ -13,8 +13,6 @@ import (
"github.com/urfave/cli/v2"
"k8s.io/client-go/tools/cache"
"github.com/grafana/grafana/pkg/apimachinery/identity"
"github.com/grafana/grafana/pkg/apimachinery/utils"
"github.com/grafana/grafana/pkg/registry/apis/provisioning/jobs"
"github.com/grafana/grafana/pkg/registry/apis/provisioning/jobs/export"
"github.com/grafana/grafana/pkg/registry/apis/provisioning/jobs/migrate"
@@ -23,8 +21,6 @@ import (
"github.com/grafana/grafana/pkg/registry/apis/provisioning/resources"
"github.com/grafana/grafana/pkg/services/apiserver/standalone"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/storage/unified/resourcepb"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/grafana/grafana/apps/provisioning/pkg/controller"
informer "github.com/grafana/grafana/apps/provisioning/pkg/generated/informers/externalversions"
@@ -54,11 +50,6 @@ func RunJobController(opts standalone.BuildInfo, c *cli.Context, cfg *setting.Cf
cancel()
}()
// Use unified storage client and API clients for testing purposes.
// TODO: remove this once the processing logic is in place
// https://github.com/grafana/git-ui-sync-project/issues/467
go temporaryPeriodicTestClients(ctx, logger, controllerCfg)
// Jobs informer and controller (resync ~60s like in register.go)
jobInformerFactory := informer.NewSharedInformerFactoryWithOptions(
controllerCfg.provisioningClient,
@@ -223,74 +214,3 @@ func setupWorkers(controllerCfg *jobsControllerConfig) ([]jobs.Worker, error) {
return workers, nil
}
// Use unified storage client for testing purposes.
// TODO: remove this once the processing logic is in place
// https://github.com/grafana/git-ui-sync-project/issues/467
func temporaryPeriodicTestClients(ctx context.Context, logger logging.Logger, controllerCfg *jobsControllerConfig) {
tick := time.NewTicker(controllerCfg.resyncInterval)
logger.Info("starting periodic using clients", "interval", controllerCfg.resyncInterval.String())
fetchAndLog := func(ctx context.Context) {
ctx, _, err := identity.WithProvisioningIdentity(ctx, "*") // "*" grants us access to all namespaces.
if err != nil {
logger.Error("failed to set identity", "error", err)
return
}
resp, err := controllerCfg.unified.CountManagedObjects(ctx, &resourcepb.CountManagedObjectsRequest{
Kind: string(utils.ManagerKindRepo),
})
if err != nil {
logger.Error("failed to list managed objects", "error", err)
} else {
if len(resp.Items) == 0 {
logger.Info("no managed objects found")
} else {
for _, obj := range resp.Items {
logger.Info("manage object counts", "item", obj)
}
}
}
// List all supported resources
client, err := controllerCfg.clients.Clients(ctx, "")
if err != nil {
logger.Error("failed to get resource clients", "error", err)
return
}
for kind, gvr := range resources.SupportedProvisioningResources {
logger := logger.With("kind", kind, "gvr", gvr.String())
logger.Info("fetching resources")
resourceClient, gvk, err := client.ForResource(ctx, gvr)
if err != nil {
logger.Error("failed to get resource client", "error", err)
continue
}
logger = logger.With("gvk", gvk.String())
list, err := resourceClient.List(ctx, metav1.ListOptions{})
if err != nil {
logger.Error("failed to list resources", "error", err)
continue
}
for _, item := range list.Items {
logger.Info("resource", "name", item.GetName(), "namespace", item.GetNamespace())
}
}
}
fetchAndLog(ctx) // Initial fetch
for {
select {
case <-ctx.Done():
tick.Stop()
return
case <-tick.C:
// Periodic fetch
fetchAndLog(ctx)
}
}
}
+1 -1
View File
@@ -50,7 +50,7 @@ func RunRepoController(opts standalone.BuildInfo, c *cli.Context, cfg *setting.C
controllerCfg.resyncInterval,
)
resourceLister := resources.NewResourceListerForMigrations(controllerCfg.unified, nil, nil)
resourceLister := resources.NewResourceLister(controllerCfg.unified)
jobs, err := jobs.NewJobStore(controllerCfg.provisioningClient.ProvisioningV0alpha1(), 30*time.Second)
if err != nil {
return fmt.Errorf("create API client job store: %w", err)