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

Add param of withBindVolumn for EtcdClusterExtension #1092

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public static class Builder {
private boolean ssl = false;
private List<String> additionalArgs;
private Network network;
private boolean bindVolumn = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • the default value is usually set in the constructor
  • maybe use a better name that describe the intention i.e. bindDataDirectory


public Builder withClusterName(String clusterName) {
this.clusterName = clusterName;
Expand Down Expand Up @@ -87,6 +88,11 @@ public Builder withNetwork(Network network) {
return this;
}

public Builder withBindVolumn(boolean bindVolumn) {
this.bindVolumn = bindVolumn;
return this;
}

public EtcdCluster build() {
return new EtcdClusterImpl(
image,
Expand All @@ -95,7 +101,8 @@ public EtcdCluster build() {
nodes,
ssl,
additionalArgs,
network != null ? network : Network.newNetwork());
network != null ? network : Network.newNetwork(),
bindVolumn);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public EtcdClusterImpl(
int nodes,
boolean ssl,
Collection<String> additionalArgs,
Network network) {
Network network,
boolean bindVolumn) {

this.clusterName = clusterName;
this.network = network;
Expand All @@ -57,6 +58,7 @@ public EtcdClusterImpl(
.withClusterToken(clusterName)
.withSll(ssl)
.withAdditionalArgs(additionalArgs)
.withBindVolumn(bindVolumn)
Copy link
Collaborator

Choose a reason for hiding this comment

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

must be formatted

.withNetwork(network);

return answer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class EtcdContainer extends GenericContainer<EtcdContainer> {
private final Set<String> nodes;

private String clusterToken;
private boolean bindVolumn = true;
private boolean ssl;
private Path dataDirectory;
private Collection<String> additionalArgs;
Expand All @@ -79,6 +80,11 @@ public EtcdContainer withClusterToken(String clusterToken) {
this.clusterToken = clusterToken;
return self();
}

public EtcdContainer withBindVolumn(boolean bindVolumn){
this.bindVolumn=bindVolumn;
Copy link
Collaborator

Choose a reason for hiding this comment

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

probably a checkstyle violation, please reformat the code

return self();
}

public EtcdContainer withAdditionalArgs(Collection<String> additionalArgs) {
if (additionalArgs != null) {
Expand All @@ -94,8 +100,10 @@ protected void configure() {
return;
}

dataDirectory = createDataDirectory(node);
addFileSystemBind(dataDirectory.toString(), Etcd.ETCD_DATA_DIR, BindMode.READ_WRITE, SelinuxContext.SHARED);
if(bindVolumn){
dataDirectory = createDataDirectory(node);
addFileSystemBind(dataDirectory.toString(), Etcd.ETCD_DATA_DIR, BindMode.READ_WRITE, SelinuxContext.SHARED);
}

withExposedPorts(Etcd.ETCD_PEER_PORT, Etcd.ETCD_CLIENT_PORT);
withNetworkAliases(node);
Expand Down Expand Up @@ -203,7 +211,9 @@ public void start() {
@Override
public void close() {
super.close();
deleteDataDirectory(dataDirectory);
if(bindVolumn) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this check may not be needed as if the data directory os null, then the method won't do anything

deleteDataDirectory(dataDirectory);
}
}

public String node() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ public Builder withSsl(boolean ssl) {
return this;
}

public Builder withBindVolumn(boolean bindVolumn) {
builder.withBindVolumn(bindVolumn);
return this;
}

public Builder withAdditionalArgs(Collection<String> additionalArgs) {
builder.withAdditionalArgs(additionalArgs);
return this;
Expand Down