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

Give better error if config entry already created #420

Merged
merged 1 commit into from
Jan 26, 2021

Conversation

lkysow
Copy link
Member

@lkysow lkysow commented Jan 12, 2021

Previously if the config entry already existed in Consul we'd give an
error like:

config entry managed in different datacenter: "other-dc"

This worked well if the config entry had been created by a controller
running in another Kube cluster, but if the user had created the config
entry directly in Consul then it wouldn't have the datacenter annotation
and so the error would actually read:

config entry managed in different datacenter: ""

Which was confusing.

This change changes the error in that case to read:

config entry already exists in Consul

How I've tested this PR:

How I expect reviewers to test this PR:

Checklist:

  • Tests added
  • CHANGELOG entry added (HashiCorp engineers only, community PRs should not add a changelog entry)

@lkysow lkysow force-pushed the crd-migration branch 2 times, most recently from e3a313f to 3201ba5 Compare January 25, 2021 17:44
Base automatically changed from crd-migration to master January 25, 2021 20:25
Previously if the config entry already existed in Consul we'd give an
error like:

  config entry managed in different datacenter: "other-dc"

This worked well if the config entry had been created by a controller
running in another Kube cluster, but if the user had created the config
entry directly in Consul then it wouldn't have the datacenter annotation
and so the error would actually read:

  config entry managed in different datacenter: ""

Which was confusing.

This change changes the error in that case to read:

  config entry already exists in Consul
@@ -1843,292 +1843,36 @@ func TestConfigEntryControllers_doesNotCreateUnownedConfigEntry(t *testing.T) {
kubeNS := "default"

cases := []struct {
kubeKind string
Copy link
Member Author

@lkysow lkysow Jan 25, 2021

Choose a reason for hiding this comment

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

I removed the cases for each config entry and instead added cases based on the value of the source-datacenter metadata since now we expect a different error message if it's empty vs set to something else.

I think it's okay to remove the per-config-entry cases because

  1. they were testing the same underlying code
  2. I would need to add config entry x cases permutations to test this new functionality which I think is going to make the tests too complicated
  3. each config entry has unit tests to ensure it implements the ConfigEntry interface properly (which is all we require to be working here)

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add an Asana task to clean up the other tests as well when appropriate? Unless youve done that already :)

Copy link
Member Author

Choose a reason for hiding this comment

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

@lkysow lkysow requested review from a team and kschoche and removed request for a team January 25, 2021 21:34
@lkysow lkysow marked this pull request as ready for review January 25, 2021 21:34
Copy link
Contributor

@thisisnotashwin thisisnotashwin left a comment

Choose a reason for hiding this comment

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

🎉

Comment on lines +350 to +353
if sourceDatacenter == "" {
return fmt.Errorf("config entry already exists in Consul")
}
return fmt.Errorf("config entry managed in different datacenter: %q", sourceDatacenter)
Copy link
Contributor

Choose a reason for hiding this comment

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

NICE!

@@ -1843,292 +1843,36 @@ func TestConfigEntryControllers_doesNotCreateUnownedConfigEntry(t *testing.T) {
kubeNS := "default"

cases := []struct {
kubeKind string
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add an Asana task to clean up the other tests as well when appropriate? Unless youve done that already :)

Copy link
Contributor

@kschoche kschoche left a comment

Choose a reason for hiding this comment

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

🔥

@lkysow lkysow merged commit 3b85413 into master Jan 26, 2021
@lkysow lkysow deleted the crd-better-error-other-dc branch January 26, 2021 18:43
ndhanushkodi pushed a commit to ndhanushkodi/consul-k8s that referenced this pull request Jul 9, 2021
* server-acl-init-job sets server addresses
  if 'externalServers.enabled' is true
* server-acl-init and server-acl-init-cleanup jobs
  and their related resources now run either when
  servers are enabled or when externalServers are enabled
* Add new acls.bootstrapToken value for providing your own
  bootstrap token.
* Allow custom auth method configuration
* Fail if both server and externalServers are enabled
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.

3 participants