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

Support Check-And-Set deletion of config entries #11419

Merged
merged 13 commits into from
Nov 1, 2021

Conversation

boxofrad
Copy link
Contributor

Adds support for Check-And-Set (CAS) deletion of config entries, similar to that of KVs.

This is useful for cases where it is desirable to delete a config entry, but only if it has not been modified by another process since reading it (such as the scenario described in #11372).

Sidenote: this is my first PR to Consul 🎉 so any meta/style feedback is greatly appreciated!

@hashicorp-cla
Copy link

hashicorp-cla commented Oct 26, 2021

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added theme/api Relating to the HTTP API interface theme/cli Flags and documentation for the CLI interface type/docs Documentation needs to be created/updated/clarified labels Oct 26, 2021
@hashicorp-ci
Copy link
Contributor

🤔 This PR has changes in the website/ directory but does not have a type/docs-cherrypick label. If the changes are for the next version, this can be ignored. If they are updates to current docs, attach the label to auto cherrypick to the stable-website branch after merging.

@vercel vercel bot temporarily deployed to Preview – consul-ui-staging October 26, 2021 12:33 Inactive
@vercel vercel bot temporarily deployed to Preview – consul October 26, 2021 12:33 Inactive
@boxofrad boxofrad marked this pull request as ready for review October 26, 2021 12:35
@boxofrad boxofrad requested a review from a team as a code owner October 26, 2021 12:35
@boxofrad boxofrad requested a review from a team October 26, 2021 12:36
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging October 26, 2021 14:59 Inactive
@vercel vercel bot temporarily deployed to Preview – consul October 26, 2021 14:59 Inactive
Copy link
Contributor

@freddygv freddygv left a comment

Choose a reason for hiding this comment

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

Awesome work with your first PR! Thanks for tackling this gap.

I left some comments/questions below.

command/config/delete/config_delete.go Show resolved Hide resolved
agent/consul/config_endpoint.go Outdated Show resolved Hide resolved
reply.Deleted = deleted
} else {
// For non-CAS deletions any non-error result indicates a successful deletion.
reply.Deleted = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this backwards compatible with older clients?

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 think so, yeah. Older clients will unmarshal the response into a struct{} which seems to be fine:

package compattest

import (
	"testing"
	"bytes"

	"github.com/hashicorp/go-msgpack/codec"

	"github.com/hashicorp/consul/agent/structs"
)

func TestBackwardCompatibility(t *testing.T) {
	var b bytes.Buffer
	encoder := codec.NewEncoder(&b, structs.MsgpackHandle)
	decoder := codec.NewDecoder(&b, structs.MsgpackHandle)

	if err := encoder.Encode(&structs.ConfigEntryDeleteResponse{Deleted: true}); err != nil {
		t.Fatal(err)
	}

	var foo struct{}
	if err := decoder.Decode(&foo); err != nil {
		t.Fatal(err)
	}

	var bar string
	if err := decoder.Decode(&bar); err == nil {
		t.Fatal("should not have been able to decode into a string")
	}
}

Copy link
Contributor

@freddygv freddygv Oct 28, 2021

Choose a reason for hiding this comment

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

Cool, I also tried it out locally with two agents on different versions and it worked

agent/config_endpoint_test.go Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview – consul October 28, 2021 11:01 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging October 28, 2021 11:01 Inactive
Copy link
Contributor

@freddygv freddygv left a comment

Choose a reason for hiding this comment

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

🚀

@boxofrad boxofrad force-pushed the boxofrad/config-entry-delete-cas branch from 7a2f93d to 79824b6 Compare November 1, 2021 16:27
@vercel vercel bot temporarily deployed to Preview – consul November 1, 2021 16:27 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging November 1, 2021 16:27 Inactive
@boxofrad boxofrad merged commit d47b731 into main Nov 1, 2021
@boxofrad boxofrad deleted the boxofrad/config-entry-delete-cas branch November 1, 2021 16:42
@hc-github-team-consul-core
Copy link
Contributor

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/490134.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/api Relating to the HTTP API interface theme/cli Flags and documentation for the CLI interface type/docs Documentation needs to be created/updated/clarified
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants