Skip to content

refactor(etcdutils): encapsulate client settings in ClientConfig struct#431

Merged
ahrtr merged 1 commit into
etcd-io:customized-controllerfrom
silentred:tls-step2-etcdutils-options
Jul 20, 2026
Merged

refactor(etcdutils): encapsulate client settings in ClientConfig struct#431
ahrtr merged 1 commit into
etcd-io:customized-controllerfrom
silentred:tls-step2-etcdutils-options

Conversation

@silentred

Copy link
Copy Markdown
Contributor

sub-task 2 of #428
link to #409 and #362

/cc @ahrtr @nwnt

Comment thread internal/etcdutils/etcdutils.go Outdated
// Option configures a clientv3.Config built by the helpers in this package.
// It is the single, backward-compatible extension point that callers use to add
// TLS (WithTLS) without changing positional signatures.
type Option func(*clientConfig)

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.

It seems that it is and will only be used for TLS thing? Note that etcd-operator doesn't care about any other parameters/options provided by users.

ref: #93

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was kind of over-designed. How about changing signature to

func MemberList(eps []string, *tls.Config) (*clientv3.MemberListResponse, error) {

instead of

func MemberList(eps []string, opts ...Option) (*clientv3.MemberListResponse, error) {

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.

func MemberList(eps []string, *tls.Config) (*clientv3.MemberListResponse, error) {

This might not be extensible. I just realized that my previous comment #431 (comment) confused etcd itself's options with the client options used by etcd-operator to connect to etcd. This specific change should be the latter, but I think we need to resolve both cases.

@ahrtr ahrtr Jul 19, 2026

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.

@silentred silentred Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ConfigSpec might not be the best choice for an input parameter. Since SecureConfig contains TLS file paths, but the operator doesn't actually need these files (it can generate tls.Config directly), using ConfigSpec seems unnecessary. If the goal is extensibility, I believe we should just use clientv3.Config directly. (https://github.com/etcd-io/etcd/blob/6006f405800929b5e7e839e7a821d608a311579f/client/v3/config.go#L28)

However, using clientv3.Config directly exposes too many options to the caller, even if the caller is the operator itself. Alternatively, we could encapsulate ep []string and *tls.Config into a new struct, such as etcdClientConfig. This would allow us to add more client configuration fields in the future if needed.

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.

Since SecureConfig contains TLS file paths, but the operator doesn't actually need these files (it can generate tls.Config directly), using ConfigSpec seems unnecessary.

Right. The point is that we need to support all the options in ConfigSpec to be configurable.

we could encapsulate ep []string and *tls.Config into a new struct, such as etcdClientConfig

OK, we can proceed with this for now.

}
cancel()
}()
defer func() { closeAndCancel(c, cancel) }()

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.

If you move such kind of minor & clear change into a separate PR, it will be merged right away.

@silentred
silentred force-pushed the tls-step2-etcdutils-options branch from aef76fd to c203d0b Compare July 18, 2026 08:20
@silentred silentred changed the title refactor(etcdutils): add config options for etcdutils helper methods refactor(etcdutils): add tls.Config parameter to etcdutils helper methods Jul 18, 2026
@silentred
silentred force-pushed the tls-step2-etcdutils-options branch from c203d0b to 500e0c0 Compare July 20, 2026 09:14
Signed-off-by: shenmu.wy <shenmu.wy@antfin.com>
@silentred
silentred force-pushed the tls-step2-etcdutils-options branch from 500e0c0 to de8f26a Compare July 20, 2026 09:18
@silentred silentred changed the title refactor(etcdutils): add tls.Config parameter to etcdutils helper methods refactor(etcdutils): encapsulate client settings in ClientConfig struct Jul 20, 2026
@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahrtr, silentred

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

@ahrtr
ahrtr merged commit 5ed6f49 into etcd-io:customized-controller Jul 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants