Repository: knative/pkg
Pull request #1765 (2020-10-01 23:51:18)

Add IsWithinParent
Subj.

/assign mattmoor @dprotaso 

knative-prow-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/1765#" title="Author self-approved">vagababov</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fpkg).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[apis/OWNERS](https://github.com/knative/pkg/blob/master/apis/OWNERS)~~ [vagababov]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
codecov[bot]: # [Codecov](https://codecov.io/gh/knative/pkg/pull/1765?src=pr&el=h1) Report
> Merging [#1765](https://codecov.io/gh/knative/pkg/pull/1765?src=pr&el=desc) into [master](https://codecov.io/gh/knative/pkg/commit/7c082ac1c01d4fa75ffae0843761aef0a7f0c88f?el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/knative/pkg/pull/1765/graphs/tree.svg?width=650&height=150&src=pr&token=rlqpDnfxbO)](https://codecov.io/gh/knative/pkg/pull/1765?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1765      +/-   ##
==========================================
- Coverage   68.54%   68.53%   -0.02%     
==========================================
  Files         215      215              
  Lines        9214     9216       +2     
==========================================
  Hits         6316     6316              
- Misses       2583     2584       +1     
- Partials      315      316       +1     
```


| [Impacted Files](https://codecov.io/gh/knative/pkg/pull/1765?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [apis/contexts.go](https://codecov.io/gh/knative/pkg/pull/1765/diff?src=pr&el=tree#diff-YXBpcy9jb250ZXh0cy5nbw==) | `100.00% <100.00%> (ø)` | |
| [test/gcs/mock/mock.go](https://codecov.io/gh/knative/pkg/pull/1765/diff?src=pr&el=tree#diff-dGVzdC9nY3MvbW9jay9tb2NrLmdv) | `91.39% <0.00%> (-1.08%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/knative/pkg/pull/1765?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/knative/pkg/pull/1765?src=pr&el=footer). Last update [7c082ac...d3826e7](https://codecov.io/gh/knative/pkg/pull/1765?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/apis/contexts.go b/apis/contexts.go
index 4e8b60d6a..a8c7683a4 100644
--- a/apis/contexts.go
+++ b/apis/contexts.go
@@ -134,6 +134,12 @@ func WithinParent(ctx context.Context, om metav1.ObjectMeta) context.Context {
 	return context.WithValue(ctx, parentMetaKey{}, om)
 }
 
+// IsWithinParent returns true if we're within parent context.
+func IsWithinParent(ctx context.Context) bool {
+	_, ok := ctx.Value(parentMetaKey{}).(metav1.ObjectMeta)
+	return ok
+}
+
 // ParentMeta accesses the ObjectMeta of the enclosing parent resource
 // from the context.  See WithinParent for how to attach the parent's
 // ObjectMeta to the context.
diff --git a/go.mod b/go.mod
index 6ef820fee..1354b9fbe 100644
--- a/go.mod
+++ b/go.mod
@@ -55,7 +55,7 @@ require (
 	k8s.io/code-generator v0.18.8
 	k8s.io/gengo v0.0.0-20200205140755-e0e292d8aa12
 	k8s.io/klog v1.0.0
-	knative.dev/test-infra v0.0.0-20200930161929-242b7529399e
+	knative.dev/test-infra v0.0.0-20201001200229-a6988e3b3b38
 	sigs.k8s.io/boskos v0.0.0-20200729174948-794df80db9c9
 )
 
diff --git a/go.sum b/go.sum
index 4bf7df652..d81636e2c 100644
--- a/go.sum
+++ b/go.sum
@@ -1846,8 +1846,8 @@ knative.dev/test-infra v0.0.0-20200505052144-5ea2f705bb55/go.mod h1:WqF1Azka+FxP
 knative.dev/test-infra v0.0.0-20200513011557-d03429a76034/go.mod h1:aMif0KXL4g19YCYwsy4Ocjjz5xgPlseYV+B95Oo4JGE=
 knative.dev/test-infra v0.0.0-20200519015156-82551620b0a9/go.mod h1:A5b2OAXTOeHT3hHhVQm3dmtbuWvIDP7qzgtqxA3/2pE=
 knative.dev/test-infra v0.0.0-20200707183444-aed09e56ddc7/go.mod h1:RjYAhXnZqeHw9+B0zsbqSPlae0lCvjekO/nw5ZMpLCs=
-knative.dev/test-infra v0.0.0-20200930161929-242b7529399e h1:z9UxB9wzoha4KlCnrcJiYv/EOpoDyclRjNf38TFFHcU=
-knative.dev/test-infra v0.0.0-20200930161929-242b7529399e/go.mod h1:Pmg2c7Z7q7BGFUV/GOpU5BlrD3ePJft4MPqx8AYBplc=
+knative.dev/test-infra v0.0.0-20201001200229-a6988e3b3b38 h1:g2LdlRp7jB6QHz3D69fnvn2OfX5C6bydIzubyLpFNl0=
+knative.dev/test-infra v0.0.0-20201001200229-a6988e3b3b38/go.mod h1:Pmg2c7Z7q7BGFUV/GOpU5BlrD3ePJft4MPqx8AYBplc=
 mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
 mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
 mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
diff --git a/vendor/modules.txt b/vendor/modules.txt
index 866ce178b..77adf96fa 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -972,7 +972,7 @@ k8s.io/utils/buffer
 k8s.io/utils/integer
 k8s.io/utils/pointer
 k8s.io/utils/trace
-# knative.dev/test-infra v0.0.0-20200930161929-242b7529399e
+# knative.dev/test-infra v0.0.0-20201001200229-a6988e3b3b38
 ## explicit
 knative.dev/test-infra/scripts
 # sigs.k8s.io/boskos v0.0.0-20200729174948-794df80db9c9


Test patch:
diff --git a/apis/contexts_test.go b/apis/contexts_test.go
index 7d3e2856a..e55fddbbb 100644
--- a/apis/contexts_test.go
+++ b/apis/contexts_test.go
@@ -153,6 +153,16 @@ func TestContexts(t *testing.T) {
 		ctx:   WithDryRun(ctx),
 		check: IsDryRun,
 		want:  true,
+	}, {
+		name:  "within parent",
+		ctx:   WithDryRun(ctx),
+		check: IsWithinParent,
+		want:  false,
+	}, {
+		name:  "in dry run",
+		ctx:   WithinParent(ctx, metav1.ObjectMeta{Name: "jack"}),
+		check: IsWithinParent,
+		want:  true,
 	}}
 
 	for _, tc := range tests {