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

Set OwnerReference on Plugin resources #845

Merged
merged 1 commit into from
Aug 16, 2019

Conversation

zubron
Copy link
Contributor

@zubron zubron commented Aug 16, 2019

What this PR does / why we need it:
When creating Pod or DaemonSet resources when running plugins, we didn't
mark them as owned by the Sonobuoy aggregator pod. This meant that if
the aggregator pod was deleted, the resources created by that pod would
be orphaned and would have to be deleted manually. This change sets the
OwnerReference for all resources to be the Sonobuoy aggregator pod so
that when the aggregator is deleted, all child resources are also
deleted.

Signed-off-by: Bridget McErlean [email protected]

Which issue(s) this PR fixes

Release note:

Sonobuoy now sets the `OwnerReference` on all Pod and DaemonSet resources that are created when running plugins. This means that if the main aggregator pod is deleted, all resources created by that pod will also be deleted.

@zubron zubron requested a review from johnSchnake August 16, 2019 12:32
@zubron zubron force-pushed the set-owner-reference-818 branch from 5f73888 to 17b70f1 Compare August 16, 2019 12:32
@zubron
Copy link
Contributor Author

zubron commented Aug 16, 2019

Marking this as a draft until I add some tests for GetAggregatorPod.

@zubron zubron force-pushed the set-owner-reference-818 branch from 17b70f1 to f9a01da Compare August 16, 2019 12:34
@codecov-io
Copy link

codecov-io commented Aug 16, 2019

Codecov Report

Merging #845 into master will increase coverage by 0.38%.
The diff coverage is 76.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #845      +/-   ##
==========================================
+ Coverage   46.29%   46.67%   +0.38%     
==========================================
  Files          75       75              
  Lines        4800     4831      +31     
==========================================
+ Hits         2222     2255      +33     
  Misses       2448     2448              
+ Partials      130      128       -2
Impacted Files Coverage Δ
pkg/discovery/discovery.go 7.93% <0%> (ø) ⬆️
pkg/plugin/aggregation/status.go 45.45% <0%> (ø) ⬆️
pkg/client/retrieve.go 4.95% <0%> (ø) ⬆️
pkg/plugin/aggregation/run.go 25.83% <33.33%> (-0.67%) ⬇️
pkg/plugin/driver/daemonset/daemonset.go 66.25% <81.81%> (+1.77%) ⬆️
pkg/plugin/driver/job/job.go 74.19% <81.81%> (+1.77%) ⬆️
pkg/plugin/aggregation/update.go 52.52% <95%> (+6.54%) ⬆️
pkg/plugin/aggregation/aggregator.go 83.2% <0%> (+4%) ⬆️

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 2bec2b1...86d4c6f. Read the comment docs.

func GetAggregatorPodName(client kubernetes.Interface, namespace string) (string, error) {
ap, err := GetAggregatorPod(client, namespace)

if _, ok := err.(NoPodWithLabelError); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: when doing multi-step error checking like this I tend to prefer a switch statement so it is a single block and the if err != nil section doesn't drift away from the call generating the error.

if err != nil {
        switch err.(type) {
        case * NoPodWithLabelError:
            fmt.Println(err.Error())
        default:
            fmt.Println("ah!?")
        }
    }

It is one extra layer of indentation, but effectively one unit of error handling. (again, just a nit)

@zubron zubron force-pushed the set-owner-reference-818 branch from f9a01da to 4147bfb Compare August 16, 2019 15:05
@zubron zubron marked this pull request as ready for review August 16, 2019 15:05
@zubron zubron force-pushed the set-owner-reference-818 branch from 4147bfb to f01c97a Compare August 16, 2019 15:07
Copy link
Contributor

@johnSchnake johnSchnake left a comment

Choose a reason for hiding this comment

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

LGTM, just squash to 1 commit and ensure it is signed off.

Good to merge after that.

When creating Pod or DaemonSet resources when running plugins, we didn't
mark them as owned by the Sonobuoy aggregator pod. This meant that if
the aggregator pod was deleted, the resources created by that pod would
be orphaned and would have to be deleted manually. This change sets the
OwnerReference for all resources to be the Sonobuoy aggregator pod so
that when the aggregator is deleted, all child resources are also
deleted.

Signed-off-by: Bridget McErlean <[email protected]>
@zubron zubron force-pushed the set-owner-reference-818 branch from 687e71a to 86d4c6f Compare August 16, 2019 18:07
@zubron zubron merged commit 031d29d into vmware-tanzu:master Aug 16, 2019
@zubron zubron deleted the set-owner-reference-818 branch August 16, 2019 18:39
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.

The master should be setting the metadata.OwnerReference for all the pods that it creates
3 participants