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

TrackAndGet #232

Merged
merged 1 commit into from May 10, 2022
Merged

TrackAndGet #232

merged 1 commit into from May 10, 2022

Conversation

scothis
Copy link
Contributor

@scothis scothis commented May 9, 2022

Streamline the flow for looking up a resource and watching it for
changes. The Tracker has long lived on the Config object as a peer to
the Client, it's very common to Track() a resource and then Get() that
same resource. Now we can do both, this effectively makes tracking
transparent as TrackAndGet() and Get() have the same method signature.

Before:

c.Tracker.Track(
    ctx,
    tracker.NewKey(
       schema.GroupVersionKind{Version: "v1", Kind: "ServiceAccount"},
       types.NamespacedName{Namespace: parent.Namespace, Name: serviceAccountName},
    ),
    types.NamespacedName{Namespace: parent.Namespace, Name: parent.Name},
)
serviceAccount := corev1.ServiceAccount{}
err := c.Get(ctx, types.NamespacedName{Namespace: parent.Namespace, Name: serviceAccountName}, &serviceAccount)

After:

serviceAccount := corev1.ServiceAccount{}
err := c.TrackAndGet(ctx, types.NamespacedName{Namespace: parent.Namespace, Name: serviceAccountName}, &serviceAccount)

The implementation assumes the ctx extends from a ParentReconciler.

Resolves #164

@codecov
Copy link

codecov bot commented May 9, 2022

Codecov Report

Merging #232 (b0a4344) into main (c7766dc) will increase coverage by 0.39%.
The diff coverage is 87.50%.

❗ Current head b0a4344 differs from pull request most recent head d5a278f. Consider uploading reports for the commit d5a278f to get more accurate results

@@            Coverage Diff             @@
##             main     #232      +/-   ##
==========================================
+ Coverage   65.01%   65.41%   +0.39%     
==========================================
  Files           9        9              
  Lines        1052     1067      +15     
==========================================
+ Hits          684      698      +14     
- Misses        347      348       +1     
  Partials       21       21              
Impacted Files Coverage Δ
reconcilers/reconcilers.go 80.84% <87.50%> (+0.26%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c7766dc...d5a278f. Read the comment docs.

Streamline the flow for looking up a resource and watching it for
changes. The Tracker has long lived on the Config object as a peer to
the Client, it's very common to Track() a resource and then Get() that
same resource. Now we can do both, this effectively makes tracking
transparent as TrackAndGet() and Get() have the same method signature.

Before:

    c.Tracker.Track(
        ctx,
        tracker.NewKey(
           schema.GroupVersionKind{Version: "v1", Kind: "ServiceAccount"},
           types.NamespacedName{Namespace: parent.Namespace, Name: serviceAccountName},
        ),
        types.NamespacedName{Namespace: parent.Namespace, Name: parent.Name},
    )
    serviceAccount := corev1.ServiceAccount{}
    err := c.Get(ctx, types.NamespacedName{Namespace: parent.Namespace, Name: serviceAccountName}, &serviceAccount)

After:

    serviceAccount := corev1.ServiceAccount{}
    err := c.TrackAndGet(ctx, types.NamespacedName{Namespace: parent.Namespace, Name: serviceAccountName}, &serviceAccount)

The implementation assumes the ctx extends from a ParentReconciler.

Signed-off-by: Scott Andrews <andrewssc@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto track resources
2 participants