* Add connection operator with health check updates - Add ConnectionController to watch and reconcile Connection resources - Add ConnectionStatusPatcher for updating connection status - Add connection_operator.go entry point for standalone operator - Register connection operator in pkg/operators/register.go - Add connection controller to in-process setup in register.go - Add unit tests for connection controller - Add integration tests for health check updates * Fix integration test: get latest version before update to avoid conflicts * refactor: move repoFactory to operator-specific configs - Remove repoFactory from shared provisioningControllerConfig - Add repoFactory to repoControllerConfig and jobsControllerConfig - This allows connection operator to run without repository setup * Remove unneccesary comments
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package controller
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
provisioning "github.com/grafana/grafana/apps/provisioning/pkg/apis/provisioning/v0alpha1"
|
|
client "github.com/grafana/grafana/apps/provisioning/pkg/generated/clientset/versioned/typed/provisioning/v0alpha1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/types"
|
|
)
|
|
|
|
// ConnectionStatusPatcher provides methods to patch Connection status subresources.
|
|
type ConnectionStatusPatcher struct {
|
|
client client.ProvisioningV0alpha1Interface
|
|
}
|
|
|
|
// NewConnectionStatusPatcher creates a new ConnectionStatusPatcher.
|
|
func NewConnectionStatusPatcher(client client.ProvisioningV0alpha1Interface) *ConnectionStatusPatcher {
|
|
return &ConnectionStatusPatcher{
|
|
client: client,
|
|
}
|
|
}
|
|
|
|
// Patch applies JSON patch operations to a Connection's status subresource.
|
|
func (p *ConnectionStatusPatcher) Patch(ctx context.Context, conn *provisioning.Connection, patchOperations ...map[string]interface{}) error {
|
|
patch, err := json.Marshal(patchOperations)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to marshal patch data: %w", err)
|
|
}
|
|
|
|
_, err = p.client.Connections(conn.Namespace).
|
|
Patch(ctx, conn.Name, types.JSONPatchType, patch, metav1.PatchOptions{}, "status")
|
|
if err != nil {
|
|
return fmt.Errorf("unable to update connection status: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|