Provisioning: introduce concept of provisioning extras (#104981)
* Spike: Extras * Attempt to wire it up * Hack * Fix issue with jobs * Wire more things up * Fix more wiring stuff * Remove webhook secret key from main registration * Move secret encryption also outside register * Add TODOs in code * Add more explanations * Move connectors to different package * Move pull request job into webhooks * Separate registration * Remove duplicate files * Fix missing function * Extract webhook repository logic out of the core github repository * Use status patcher in webhook connector * Fix change in go mod * Change hooks signature * Remove TODOs * Remove Webhook methos from go-git * Remove leftover * Fix mistake in OpenAPI spec * Fix some tests * Fix some issues * Fix linting
This commit is contained in:
@@ -310,7 +310,7 @@ func (rc *RepositoryController) shouldResync(obj *provisioning.Repository) bool
|
||||
return obj.Spec.Sync.Enabled && syncAge >= (syncInterval-tolerance) && !pendingForTooLong && !isRunning
|
||||
}
|
||||
|
||||
func (rc *RepositoryController) runHooks(ctx context.Context, repo repository.Repository, obj *provisioning.Repository) (*provisioning.WebhookStatus, error) {
|
||||
func (rc *RepositoryController) runHooks(ctx context.Context, repo repository.Repository, obj *provisioning.Repository) ([]map[string]interface{}, error) {
|
||||
logger := logging.FromContext(ctx)
|
||||
hooks, _ := repo.(repository.Hooks)
|
||||
if hooks == nil || obj.Generation == obj.Status.ObservedGeneration {
|
||||
@@ -319,20 +319,20 @@ func (rc *RepositoryController) runHooks(ctx context.Context, repo repository.Re
|
||||
|
||||
if obj.Status.ObservedGeneration < 1 {
|
||||
logger.Info("handle repository create")
|
||||
webhookStatus, err := hooks.OnCreate(ctx)
|
||||
patchOperations, err := hooks.OnCreate(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error running OnCreate: %w", err)
|
||||
}
|
||||
return webhookStatus, nil
|
||||
return patchOperations, nil
|
||||
}
|
||||
|
||||
logger.Info("handle repository spec update", "Generation", obj.Generation, "ObservedGeneration", obj.Status.ObservedGeneration)
|
||||
webhookStatus, err := hooks.OnUpdate(ctx)
|
||||
patchOperations, err := hooks.OnUpdate(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error running OnUpdate: %w", err)
|
||||
}
|
||||
|
||||
return webhookStatus, nil
|
||||
return patchOperations, nil
|
||||
}
|
||||
|
||||
func (rc *RepositoryController) determineSyncStrategy(ctx context.Context, obj *provisioning.Repository, shouldResync bool, healthStatus provisioning.HealthStatus) *provisioning.SyncJobOptions {
|
||||
@@ -498,16 +498,12 @@ func (rc *RepositoryController) process(item *queueItem) error {
|
||||
}
|
||||
|
||||
// Run hooks
|
||||
webhookStatus, err := rc.runHooks(ctx, repo, obj)
|
||||
hookOps, err := rc.runHooks(ctx, repo, obj)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case webhookStatus != nil:
|
||||
patchOperations = append(patchOperations, map[string]interface{}{
|
||||
"op": "replace",
|
||||
"path": "/status/webhook",
|
||||
"value": webhookStatus,
|
||||
})
|
||||
case len(hookOps) > 0:
|
||||
patchOperations = append(patchOperations, hookOps...)
|
||||
}
|
||||
|
||||
// determine the sync strategy and sync status to apply
|
||||
|
||||
@@ -21,7 +21,7 @@ func NewRepositoryStatusPatcher(client client.ProvisioningV0alpha1Interface) *Re
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RepositoryStatusPatcher) Patch(ctx context.Context, repo *provisioning.Repository, patchOperations []map[string]interface{}) error {
|
||||
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)
|
||||
|
||||
@@ -104,7 +104,7 @@ func TestRepositoryStatusPatcher_Patch(t *testing.T) {
|
||||
}
|
||||
|
||||
patcher := NewRepositoryStatusPatcher(&client)
|
||||
err := patcher.Patch(context.Background(), tt.repo, tt.patchOperations)
|
||||
err := patcher.Patch(context.Background(), tt.repo, tt.patchOperations...)
|
||||
|
||||
if tt.expectedError != "" {
|
||||
require.EqualError(t, err, tt.expectedError)
|
||||
|
||||
Reference in New Issue
Block a user