Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update instance connectors on a connector reconcile #4992

Merged
merged 8 commits into from
Jun 3, 2024

Conversation

esevastyanov
Copy link
Contributor

@esevastyanov esevastyanov commented May 31, 2024

The aim is to update project connectors on connector update

@esevastyanov esevastyanov marked this pull request as ready for review May 31, 2024 10:16
Comment on lines 63 to 90
// Get and sync repo
repo, release, err := r.C.Runtime.Repo(ctx, r.C.InstanceID)
if err != nil {
return runtime.ReconcileResult{Err: fmt.Errorf("failed to access repo: %w", err)}
}
defer release()
err = repo.Sync(ctx)
if err != nil {
return runtime.ReconcileResult{Err: fmt.Errorf("failed to sync repo: %w", err)}
}

// Get instance
inst, err := r.C.Runtime.Instance(ctx, r.C.InstanceID)
if err != nil {
return runtime.ReconcileResult{Err: fmt.Errorf("failed to find instance: %w", err)}
}

// Parse the project
parser, err := rillv1.Parse(ctx, repo, r.C.InstanceID, inst.Environment, inst.OLAPConnector)
if err != nil {
return runtime.ReconcileResult{Err: fmt.Errorf("failed to parse: %w", err)}
}

// Update instance connectors
err = r.C.Runtime.UpdateInstanceWithRillYAML(ctx, inst.ID, parser, false)
if err != nil {
return runtime.ReconcileResult{Err: fmt.Errorf("failed to update instance: %w", err)}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file watcher already parsed the file and created the Connector resource (returned from self.GetConnector() above). Doing a repo sync (clone or pull) and full project parse again here is redundant, and potentially quite slow if there are many connectors.

Instead, you will probably want to add new functions, separate from UpdateInstanceWithRillYAML, for upserting/deleting connectors for an instance. They should also take care only to update in the DB (invalidating various caches) if the connector actually changed. (Since the reconciler can trigger even if there are no changes, e.g. on process restart.)

The delete case needs to be handled in the if self.Meta.DeletedOn != nil { case below.

@esevastyanov esevastyanov changed the title UpdateInstanceWithRillYAML on connector reconcile Update instance connectors on a connector reconcile Jun 3, 2024
Copy link
Contributor

@begelundmuller begelundmuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have two minor comments, but overall this looks good!

@@ -1390,7 +1390,8 @@ name: my-gcs
},
Resource: &runtimev1.Resource_Connector{
Connector: &runtimev1.ConnectorV2{
Spec: &runtimev1.ConnectorSpec{Driver: "s3", Properties: map[string]string{"region": "us-west-2"}},
Spec: &runtimev1.ConnectorSpec{Driver: "s3", Properties: map[string]string{"region": "us-west-2"}},
State: &runtimev1.ConnectorState{SpecHash: "76b3819c673b0a4e4755418614d8cb62"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can nil the field here to omit it from tests:

// Some kind-specific fields are not stable. We reset those to stable values before comparing.

Comment on lines 90 to 92
if t.State == nil {
t.State = &runtimev1.ConnectorState{}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you update func (r *ConnectorReconciler) ResetState(res *runtimev1.Resource) error { to set an empty state, then this isn't needed. We do that in most other reconcilers, but actually looks like there's some inconsistency, so I understand the confusion. There might be some other code that assumes the state is not nil, so it's probably best to set it there.

@esevastyanov esevastyanov merged commit 4632b9c into main Jun 3, 2024
7 checks passed
@esevastyanov esevastyanov deleted the connector-reconcile branch June 3, 2024 18:04
ericpgreen2 pushed a commit that referenced this pull request Jun 3, 2024
* UpdateInstanceWithRillYAML on connector reconcile

* Simplified connector reconcile

* Merged main

* Fixed test

* fmt fix

* ResetState
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants