Skip to content
This repository has been archived by the owner on Jun 19, 2022. It is now read-only.

Add configuration for data residency #1681

Merged
merged 17 commits into from
Sep 19, 2020

Conversation

zhongduo
Copy link
Contributor

@zhongduo zhongduo commented Sep 10, 2020

Fixes #1680

Proposed Changes

  • Add a new configuration map for data residency
  • Update Topic CRD reconciler to use data residency configuration map
  • Update broker and trigger reconciler to use data residency configuration when creating topics.

Release Note

- 🎁 Add data residency support through configuration map.

Docs

@google-cla google-cla bot added the cla: yes (override cla status due to multiple authors bug) label Sep 10, 2020
@zhongduo
Copy link
Contributor Author

This PR and the issue is open to input about if we should keep a config map called "config-data-residency" or make it larger scope to "config-gcp-features" which is what I am using now.

@zhongduo
Copy link
Contributor Author

/assign @yolocs

# messagestoragepolicy.allowedpersistenceregions field specifies
# all the allowed regions for data residency. The default or an empty value will
# mean no data residency requirement.
messagestoragepolicy.allowedpersistenceregions: "us-east1,us-west1"
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are essentially dealing with YAML, can this be a list of strings, rather than a csv?

Suggested change
messagestoragepolicy.allowedpersistenceregions: "us-east1,us-west1"
messagestoragepolicy.allowedpersistenceregions:
- us-east1
- us-west1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. This field is a field used in the topic config, I was thinking to simply pass whatever in the field to the topic config, but I think the topic is also using []string.

@zhongduo zhongduo force-pushed the data-residency-config branch from e4b205d to 4179e22 Compare September 11, 2020 13:27
Copy link
Member

@yolocs yolocs left a comment

Choose a reason for hiding this comment

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

Update the release note section in the description with something like "Add data residency configmap placeholder"

config/core/configmaps/data-residency.yaml Outdated Show resolved Hide resolved
name: config-data-residency
namespace: cloud-run-events
data:
_example: |
Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with creating such a placeholder since it does nothing. But I'm looking for more details on how this will be used.

  1. How this configmap will be read? Volume mount? Watch?
  2. Do you allow finer grained control? Like per broker? How it would impact the configmap structure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add the actual code for this configuration to this PR too. For your question:

  1. This is still being discussed, but watch seems better since our system already uses watch for other config maps, also, it provides easier interface for reacting to the change.

  2. Personally I think even if we allow per broker configuration, this will still serve as a default and same configuration will be added to per broker and get reconciled by the broker controller instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR has been extended to have the full implementation, so to answer this original question:

  1. The configmap is read through watch from Store object.
  2. For now, we only support cluster wide, but we can for sure add per namespace or broker in the future. Note that triggers also create new topics, but topics for retry should be same as the main broker topic.

@zhongduo zhongduo changed the title add configuration for data residency WIP: add configuration for data residency Sep 11, 2020
@zhongduo
Copy link
Contributor Author

Open for suggestions: I have added a default config to the data residency. However, since the data residency really is optional, I am treating empty or non key as no configuration so that it will allow all region too. The only downside I can think of is that it will not catch typos in keys like

"datareside.error-key':
    - us-east-1

Any suggestions?

@zhongduo zhongduo changed the title WIP: add configuration for data residency Add configuration for data residency Sep 14, 2020
@zhongduo
Copy link
Contributor Author

I personally think it is better to make this its own commit, and the logic to propagate to controller etc another one, as it will make the history look cleaner.

@zhongduo zhongduo requested review from yolocs and Harwayne September 14, 2020 22:04
@zhongduo zhongduo changed the title Add configuration for data residency WIP: Add configuration for data residency Sep 16, 2020
@zhongduo zhongduo changed the title WIP: Add configuration for data residency Add configuration for data residency Sep 16, 2020
@zhongduo zhongduo force-pushed the data-residency-config branch from db592fc to a61b0d5 Compare September 16, 2020 17:29
Copy link
Contributor

@grantr grantr left a comment

Choose a reason for hiding this comment

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

Thanks @zhongduo!

Looks like we're missing a few tests. All my other comments are optional nits.


# default-dataresidency-config is the configuration for determining the default
# data residency to apply to all objects that require data residency but,
# do not specify it. This is expected to be Channels and Sources.
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove but, do not specify it. That is already implied by "default data residency".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix as suggested.


# default-dataresidency-config is the configuration for determining the default
# data residency to apply to all objects that require data residency but,
# do not specify it. This is expected to be Channels and Sources.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's Channels, Sources, and Brokers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed as suggested.


const (
// configName is the name of config map for the default data residency that
// Sources and brokers should use.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe clearer to say "the default data residency that GCP resources should use"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed as suggested.

pkg/apis/configs/dataresidency/defaults.go Show resolved Hide resolved
pkg/reconciler/broker/broker.go Outdated Show resolved Hide resolved
pkg/reconciler/broker/broker.go Show resolved Hide resolved
pkg/reconciler/intevents/topic/topic.go Outdated Show resolved Hide resolved
pkg/reconciler/trigger/trigger.go Outdated Show resolved Hide resolved
pkg/reconciler/intevents/topic/topic.go Show resolved Hide resolved
pkg/reconciler/trigger/trigger.go Show resolved Hide resolved
Copy link
Contributor

@grantr grantr left a comment

Choose a reason for hiding this comment

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

Very close. I have one more testing request (test for empty AllowedPersistenceRegions) and one optional suggestion.

messagestoragepolicy.allowedpersistenceregions:
- us-east1`,
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: I recommend moving this declaration to a test helper function so it takes up less space and can be shared across multiple reconcilers. Something like:

"dataResidencyConfigMap": DataResidencyConfigMap("us-east1")

Test helpers are in pkg/reconciler/testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed as suggested.

@@ -304,6 +308,63 @@ func TestAllCases(t *testing.T) {
TopicExists("cre-bkr_testnamespace_test-broker_abc123"),
Copy link
Contributor

Choose a reason for hiding this comment

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

We can increase coverage by changing this to TopicExistsWithConfig so it verifies AllowedPersistenceRegions is empty by default. Would you mind making that change here and in the trigger tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed as suggested.

pkg/reconciler/broker/broker_test.go Show resolved Hide resolved
pkg/reconciler/intevents/topic/topic.go Show resolved Hide resolved
@grantr
Copy link
Contributor

grantr commented Sep 18, 2020

The only downside I can think of is that it will not catch typos in keys like

This is fine for now - it's the same behavior for our other configmaps. A future improvement can add validation webhooks to verify configmap structure.

@grantr
Copy link
Contributor

grantr commented Sep 18, 2020

it's the same behavior for our other configmaps.

Oops, I was wrong about this. We do validate the structure of other configmaps, see https://github.com/google/knative-gcp/blob/master/cmd/webhook/main.go#L171. Adding that can be a followup PR.

@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-google-knative-gcp-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/configs/dataresidency/dataresidency_defaults.go Do not exist 84.6%
pkg/apis/configs/dataresidency/defaults.go Do not exist 100.0%
pkg/apis/configs/dataresidency/singleton.go Do not exist 100.0%
pkg/apis/configs/dataresidency/store.go Do not exist 76.9%
pkg/reconciler/broker/broker.go 62.0% 64.0% 2.0
pkg/reconciler/broker/controller.go 59.4% 60.6% 1.2
pkg/reconciler/intevents/topic/topic.go 69.6% 68.4% -1.3
pkg/reconciler/trigger/controller.go 68.4% 69.2% 0.8
pkg/reconciler/trigger/trigger.go 56.4% 57.7% 1.3

Copy link
Contributor

@grantr grantr left a comment

Choose a reason for hiding this comment

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

Thanks @zhongduo!

/lgtm

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: grantr, zhongduo

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

The pull request process is described here

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

@zhongduo
Copy link
Contributor Author

/test pull-google-knative-gcp-wi-tests

@zhongduo
Copy link
Contributor Author

/retest

1 similar comment
@zhongduo
Copy link
Contributor Author

/retest

@knative-test-reporter-robot

The following jobs failed:

Test name Triggers Retries
pull-google-knative-gcp-wi-tests 2020-09-18 20:20:08.416 +0000 UTC
2020-09-18 21:00:38.547 +0000 UTC
2020-09-18 21:13:08.231 +0000 UTC
2020-09-18 21:56:08.487 +0000 UTC
2020-09-18 23:12:08.23 +0000 UTC
2020-09-19 01:43:08.462 +0000 UTC
3/3

Job pull-google-knative-gcp-wi-tests expended all 3 retries without success.

@zhongduo
Copy link
Contributor Author

/test pull-google-knative-gcp-wi-tests

@knative-prow-robot knative-prow-robot merged commit 1281791 into google:master Sep 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved cla: yes (override cla status due to multiple authors bug) lgtm size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add another configuration map for data residency configuration
7 participants