47664a7d51
* Split in multiple files * Refactor sync even further * Move more things between RepositoryResources * Add status patcher * Interface for sync functions * Interface for compare function * Add syncer back * Move interfaces * Move execute complete * Return currentRef in syncer * Add repository status test * Add initial sync tests * Fix a couple of spots * Make initial sync tests work * Fix register.go * Add initial tests for sync worker * Finish tests for sync * Add incremental tests * Add TODO * Finish incremental tests * Move folder creation to full sync * Move interfaces * Add initial full sync tests * Update tests * Reshape things * Add changes test * Fix register * Add some tests * Add more tests * Add test * WIP * WIP: delete test * Add more full test * More tests * Add tests for folder creation * Add folder tests full sync * Full coverage full sync * Clean up tests * Add more tests for changes function * Enhance tests for Changes function to cover error scenarios and empty paths - Added test cases for handling empty file paths and folder resources. - Updated error message formatting in the Compare function for clarity. * Add unit tests * Failed initial patch * Add tests failed repository resources * Add test failed getting client * Test for successful and unsuccessful syncs * Add final tests for worker * Fix existing tests * Add missing test * Fix spelling mistake * Fix flake in changes test
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
package controller
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
provisioning "github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1"
|
|
client "github.com/grafana/grafana/pkg/generated/clientset/versioned/typed/provisioning/v0alpha1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/types"
|
|
)
|
|
|
|
type RepositoryStatusPatcher struct {
|
|
client client.ProvisioningV0alpha1Interface
|
|
}
|
|
|
|
func NewRepositoryStatusPatcher(client client.ProvisioningV0alpha1Interface) *RepositoryStatusPatcher {
|
|
return &RepositoryStatusPatcher{
|
|
client: client,
|
|
}
|
|
}
|
|
|
|
func (r *RepositoryStatusPatcher) Patch(ctx context.Context, repo *provisioning.Repository, patchOperations []map[string]interface{}) error {
|
|
patch, err := json.Marshal(patchOperations)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to marshal patch data: %w", err)
|
|
}
|
|
|
|
_, err = r.client.Repositories(repo.Namespace).
|
|
Patch(ctx, repo.Name, types.JSONPatchType, patch, metav1.PatchOptions{}, "status")
|
|
if err != nil {
|
|
return fmt.Errorf("unable to update repo with job status: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|