Skip to content

Populate a Subscriptions subscriber and reply namespace only if not set already#6671

Merged
knative-prow[bot] merged 1 commit intoknative:mainfrom
creydr:fix-sequence-step-namespace-populating
Jan 24, 2023
Merged

Populate a Subscriptions subscriber and reply namespace only if not set already#6671
knative-prow[bot] merged 1 commit intoknative:mainfrom
creydr:fix-sequence-step-namespace-populating

Conversation

@creydr
Copy link
Copy Markdown
Member

@creydr creydr commented Jan 9, 2023

Fixes #6539

In case a Subscription with a .spec.subscriber.ref pointing to a service in another namespace, the Subscription will not become ready because it is trying to find the service on the subscription's namespace (see #6539). Same happens with a subscriptions .spec.reply.ref.
This PR addresses it and only uses the namespace of the Subscription, if no namespace was given for the subscriber/reply.

Proposed Changes

  • 🐛 Populate a subscriptions subscriber & reply namespace field with the Subscriptions namespace only in case it is not set

Pre-review Checklist

  • At least 80% unit test coverage
  • E2E tests for any new behavior
  • Docs PR for any user-facing impact
  • Spec PR for any new API feature
  • Conformance test for any change to the spec

Release Note


How to verify

  1. Install a eventing with this patch
  2. Create a sequence with steps and a reply in different namespaces (e.g. https://gist.github.com/creydr/57235f35b03ab8f1285eee0a64350576)
  3. Check that the subscriptions and sequence becomes ready

…et already

Signed-off-by: Christoph Stäbler <cstabler@redhat.com>
@knative-prow knative-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 9, 2023
@knative-prow knative-prow Bot requested review from lberk and pierDipi January 9, 2023 11:47
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 9, 2023

Codecov Report

Base: 80.60% // Head: 80.55% // Decreases project coverage by -0.05% ⚠️

Coverage data is based on head (d9affc4) compared to base (9e692b8).
Patch coverage: 50.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6671      +/-   ##
==========================================
- Coverage   80.60%   80.55%   -0.05%     
==========================================
  Files         236      236              
  Lines       12018    12018              
==========================================
- Hits         9687     9681       -6     
- Misses       1851     1855       +4     
- Partials      480      482       +2     
Impacted Files Coverage Δ
pkg/reconciler/subscription/subscription.go 81.74% <50.00%> (-1.59%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

if subscriber.Ref != nil {
// Populate the namespace for the subscriber if required
if subscriber.Ref != nil && subscriber.Ref.Namespace == "" {
subscriber.Ref.Namespace = subscription.Namespace
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see that the defaulting was always happening here but it may be better to move it to the defaulting webhook for subscriptions.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for the review. I agree the defaulting webhook would be a better place. Let me move it...

Copy link
Copy Markdown
Member

@pierDipi pierDipi Jan 9, 2023

Choose a reason for hiding this comment

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

This defaulting should be kept here for backward compatibility since existing resources won't have it defaulted until an update happens

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@pierDipi: So we don't we resync the resources after a couple of time?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

resync is not necessarily producing an update (knative/pkg tries to reduce updates as much as possible to reduce API server load) therefore the webhook is not always applied

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

what I meant is that even with the current code (before this PR), the namespace was set (latest on a periodic resync) on the resource. So my chance from this PR (being in a webhook or not) would not change anything IIUC. My PR would only change anything on resources which don't have the namespace set on reply/subscribers - which should only be the case for new resources. Or am I missing something?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is only a status update:

func (r *reconcilerImpl) updateStatus(ctx context.Context, existing *v1.Subscription, desired *v1.Subscription) error {
existing = existing.DeepCopy()
return reconciler.RetryUpdateConflicts(func(attempts int) (err error) {
// The first iteration tries to use the injectionInformer's state, subsequent attempts fetch the latest state via API.
if attempts > 0 {
getter := r.Client.MessagingV1().Subscriptions(desired.Namespace)
existing, err = getter.Get(ctx, desired.Name, metav1.GetOptions{})
if err != nil {
return err
}
}
// If there's nothing to update, just return.
if equality.Semantic.DeepEqual(existing.Status, desired.Status) {
return nil
}
if diff, err := kmp.SafeDiff(existing.Status, desired.Status); err == nil && diff != "" {
logging.FromContext(ctx).Debug("Updating status with: ", diff)
}
existing.Status = desired.Status
updater := r.Client.MessagingV1().Subscriptions(existing.Namespace)
_, err = updater.UpdateStatus(ctx, existing, metav1.UpdateOptions{})
return err
})
}
, so spec changes in ReconcileKind are not persisted.

In addition, on upgrade controller and webhook are not atomically updated at the same time, so during this time period we might not have this logic running anywhere

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think I got the point. This logic is only operating on a copy of the subscription. The sequence webhook sets the namespace correctly, but it gets overwritten by the subscription reconciler. As the subscription reconciler needs the namespace of the ref, it must be set - and since we can create subscriptions directly without a namespace for the ref this is an issue (and there might be some out there without a ref.namespace already).

@creydr
Copy link
Copy Markdown
Member Author

creydr commented Jan 11, 2023

/assign @pierDipi @gab-satchi

@creydr creydr requested review from gab-satchi and pierDipi and removed request for gab-satchi, lberk and pierDipi January 18, 2023 14:56
Copy link
Copy Markdown
Member

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

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

We can make the webhook addition as a follow up PR

/lgtm
/approve

@knative-prow knative-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Jan 23, 2023
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented Jan 23, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: creydr, pierDipi

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 23, 2023
@creydr
Copy link
Copy Markdown
Member Author

creydr commented Jan 24, 2023

/test upgrade-tests

@knative-prow knative-prow Bot merged commit bd67450 into knative:main Jan 24, 2023
creydr added a commit to creydr/knative-eventing that referenced this pull request Jan 24, 2023
…et already (knative#6671)

Fixes knative#6539

In case a Subscription with a `.spec.subscriber.ref` pointing to a
service in another namespace, the Subscription will not become ready
because it is trying to find the service on the subscription's namespace
(see knative#6539). Same happens with a subscriptions `.spec.reply.ref`.
This PR addresses it and only uses the namespace of the Subscription, if
no namespace was given for the subscriber/reply.

## Proposed Changes
* 🐛 Populate a subscriptions subscriber & reply namespace field with
the Subscriptions namespace only in case it is not set

### Pre-review Checklist
- [ ] **At least 80% unit test coverage**
- [ ] **E2E tests** for any new behavior
- [ ] **Docs PR** for any user-facing impact
- [ ] **Spec PR** for any new API feature
- [ ] **Conformance test** for any change to the spec

**Release Note**
```release-note

```

**How to verify**
1. Install a eventing with this patch
2. Create a sequence with steps and a reply in different namespaces
(e.g. https://gist.github.com/creydr/57235f35b03ab8f1285eee0a64350576)
3. Check that the subscriptions and sequence becomes ready

Signed-off-by: Christoph Stäbler <cstabler@redhat.com>
(cherry picked from commit bd67450)
openshift-merge-robot pushed a commit to openshift-knative/eventing that referenced this pull request Jan 24, 2023
…et already (knative#6671) (#93)

Fixes knative#6539

In case a Subscription with a `.spec.subscriber.ref` pointing to a
service in another namespace, the Subscription will not become ready
because it is trying to find the service on the subscription's namespace
(see knative#6539). Same happens with a subscriptions `.spec.reply.ref`.
This PR addresses it and only uses the namespace of the Subscription, if
no namespace was given for the subscriber/reply.

## Proposed Changes
* 🐛 Populate a subscriptions subscriber & reply namespace field with
the Subscriptions namespace only in case it is not set

### Pre-review Checklist
- [ ] **At least 80% unit test coverage**
- [ ] **E2E tests** for any new behavior
- [ ] **Docs PR** for any user-facing impact
- [ ] **Spec PR** for any new API feature
- [ ] **Conformance test** for any change to the spec

**Release Note**
```release-note

```

**How to verify**
1. Install a eventing with this patch
2. Create a sequence with steps and a reply in different namespaces
(e.g. https://gist.github.com/creydr/57235f35b03ab8f1285eee0a64350576)
3. Check that the subscriptions and sequence becomes ready

Signed-off-by: Christoph Stäbler <cstabler@redhat.com>
(cherry picked from commit bd67450)
openshift-cherrypick-robot pushed a commit to openshift-cherrypick-robot/knative-eventing that referenced this pull request Jan 24, 2023
…et already (knative#6671)

Fixes knative#6539

In case a Subscription with a `.spec.subscriber.ref` pointing to a
service in another namespace, the Subscription will not become ready
because it is trying to find the service on the subscription's namespace
(see knative#6539). Same happens with a subscriptions `.spec.reply.ref`.
This PR addresses it and only uses the namespace of the Subscription, if
no namespace was given for the subscriber/reply.

## Proposed Changes
* 🐛 Populate a subscriptions subscriber & reply namespace field with
the Subscriptions namespace only in case it is not set

### Pre-review Checklist
- [ ] **At least 80% unit test coverage**
- [ ] **E2E tests** for any new behavior
- [ ] **Docs PR** for any user-facing impact
- [ ] **Spec PR** for any new API feature
- [ ] **Conformance test** for any change to the spec

**Release Note**
```release-note

```

**How to verify**
1. Install a eventing with this patch
2. Create a sequence with steps and a reply in different namespaces
(e.g. https://gist.github.com/creydr/57235f35b03ab8f1285eee0a64350576)
3. Check that the subscriptions and sequence becomes ready

Signed-off-by: Christoph Stäbler <cstabler@redhat.com>
(cherry picked from commit bd67450)
openshift-cherrypick-robot pushed a commit to openshift-cherrypick-robot/knative-eventing that referenced this pull request Jan 24, 2023
…et already (knative#6671)

Fixes knative#6539

In case a Subscription with a `.spec.subscriber.ref` pointing to a
service in another namespace, the Subscription will not become ready
because it is trying to find the service on the subscription's namespace
(see knative#6539). Same happens with a subscriptions `.spec.reply.ref`.
This PR addresses it and only uses the namespace of the Subscription, if
no namespace was given for the subscriber/reply.

## Proposed Changes
* 🐛 Populate a subscriptions subscriber & reply namespace field with
the Subscriptions namespace only in case it is not set

### Pre-review Checklist
- [ ] **At least 80% unit test coverage**
- [ ] **E2E tests** for any new behavior
- [ ] **Docs PR** for any user-facing impact
- [ ] **Spec PR** for any new API feature
- [ ] **Conformance test** for any change to the spec

**Release Note**
```release-note

```

**How to verify**
1. Install a eventing with this patch
2. Create a sequence with steps and a reply in different namespaces
(e.g. https://gist.github.com/creydr/57235f35b03ab8f1285eee0a64350576)
3. Check that the subscriptions and sequence becomes ready

Signed-off-by: Christoph Stäbler <cstabler@redhat.com>
(cherry picked from commit bd67450)
openshift-merge-robot pushed a commit to openshift-knative/eventing that referenced this pull request Jan 27, 2023
…et already (knative#6671) (#95)

Fixes knative#6539

In case a Subscription with a `.spec.subscriber.ref` pointing to a
service in another namespace, the Subscription will not become ready
because it is trying to find the service on the subscription's namespace
(see knative#6539). Same happens with a subscriptions `.spec.reply.ref`.
This PR addresses it and only uses the namespace of the Subscription, if
no namespace was given for the subscriber/reply.

## Proposed Changes
* 🐛 Populate a subscriptions subscriber & reply namespace field with
the Subscriptions namespace only in case it is not set

### Pre-review Checklist
- [ ] **At least 80% unit test coverage**
- [ ] **E2E tests** for any new behavior
- [ ] **Docs PR** for any user-facing impact
- [ ] **Spec PR** for any new API feature
- [ ] **Conformance test** for any change to the spec

**Release Note**
```release-note

```

**How to verify**
1. Install a eventing with this patch
2. Create a sequence with steps and a reply in different namespaces
(e.g. https://gist.github.com/creydr/57235f35b03ab8f1285eee0a64350576)
3. Check that the subscriptions and sequence becomes ready

Signed-off-by: Christoph Stäbler <cstabler@redhat.com>
(cherry picked from commit bd67450)

Co-authored-by: Christoph Stäbler <cstabler@redhat.com>
openshift-merge-robot pushed a commit to openshift-knative/eventing that referenced this pull request Jan 27, 2023
…et already (knative#6671) (#94)

Fixes knative#6539

In case a Subscription with a `.spec.subscriber.ref` pointing to a
service in another namespace, the Subscription will not become ready
because it is trying to find the service on the subscription's namespace
(see knative#6539). Same happens with a subscriptions `.spec.reply.ref`.
This PR addresses it and only uses the namespace of the Subscription, if
no namespace was given for the subscriber/reply.

## Proposed Changes
* 🐛 Populate a subscriptions subscriber & reply namespace field with
the Subscriptions namespace only in case it is not set

### Pre-review Checklist
- [ ] **At least 80% unit test coverage**
- [ ] **E2E tests** for any new behavior
- [ ] **Docs PR** for any user-facing impact
- [ ] **Spec PR** for any new API feature
- [ ] **Conformance test** for any change to the spec

**Release Note**
```release-note

```

**How to verify**
1. Install a eventing with this patch
2. Create a sequence with steps and a reply in different namespaces
(e.g. https://gist.github.com/creydr/57235f35b03ab8f1285eee0a64350576)
3. Check that the subscriptions and sequence becomes ready

Signed-off-by: Christoph Stäbler <cstabler@redhat.com>
(cherry picked from commit bd67450)

Co-authored-by: Christoph Stäbler <cstabler@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting the namespace of the sequence's step does not take effect

3 participants