Skip to content

Commit

Permalink
feat(provider/kubernetes): make kubectl configurable per-account (#2337)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwander authored Feb 1, 2018
1 parent fdc8376 commit 1d08c99
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class KubernetesNamedAccountCredentials<C extends KubernetesCredentials>
final private String user;
final private String userAgent;
final private String kubeconfigFile;
final private String kubectlExecutable;
final private Boolean serviceAccount;
private List<String> namespaces;
private List<String> omitNamespaces;
Expand All @@ -71,6 +72,7 @@ public class KubernetesNamedAccountCredentials<C extends KubernetesCredentials>
String cluster,
String user,
String kubeconfigFile,
String kubectlExecutable,
Boolean serviceAccount,
List<String> namespaces,
List<String> omitNamespaces,
Expand All @@ -89,6 +91,7 @@ public class KubernetesNamedAccountCredentials<C extends KubernetesCredentials>
this.user = user;
this.userAgent = userAgent;
this.kubeconfigFile = kubeconfigFile;
this.kubectlExecutable = kubectlExecutable;
this.serviceAccount = serviceAccount;
this.namespaces = namespaces;
this.omitNamespaces = omitNamespaces;
Expand Down Expand Up @@ -130,6 +133,10 @@ public C getCredentials() {
return credentials;
}

public String getKubectlExecutable() {
return kubectlExecutable;
}

@Override
public String getCloudProvider() {
return cloudProvider;
Expand Down Expand Up @@ -164,6 +171,7 @@ static class Builder<C extends KubernetesCredentials> {
String user;
String userAgent;
String kubeconfigFile;
String kubectlExecutable;
Boolean serviceAccount;
Boolean configureImagePullSecrets;
List<String> namespaces;
Expand Down Expand Up @@ -234,6 +242,11 @@ Builder kubeconfigFile(String kubeconfigFile) {
return this;
}

Builder kubectlExecutable(String kubectlExecutable) {
this.kubectlExecutable = kubectlExecutable;
return this;
}

Builder serviceAccount(Boolean serviceAccount) {
this.serviceAccount = serviceAccount;
return this;
Expand Down Expand Up @@ -333,6 +346,7 @@ private C buildCredentials() {
return (C) new KubernetesV2Credentials.Builder()
.accountName(name)
.kubeconfigFile(kubeconfigFile)
.kubectlExecutable(kubectlExecutable)
.context(context)
.oAuthServiceAccount(oAuthServiceAccount)
.oAuthScopes(oAuthScopes)
Expand Down Expand Up @@ -394,6 +408,7 @@ KubernetesNamedAccountCredentials build() {
cluster,
user,
kubeconfigFile,
kubectlExecutable,
serviceAccount,
namespaces,
omitNamespaces,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,11 @@ private void logDebugMessages(String jobId, JobStatus jobStatus) {

private List<String> kubectlAuthPrefix(KubernetesV2Credentials credentials) {
List<String> command = new ArrayList<>();
command.add(executable);
if (StringUtils.isNotEmpty(credentials.getKubectlExecutable())) {
command.add(credentials.getKubectlExecutable());
} else {
command.add(executable);
}

if (credentials.isDebug()) {
command.add("-v");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public class KubernetesV2Credentials implements KubernetesCredentials {
private final List<String> namespaces;
private final List<String> omitNamespaces;

// remove when kubectl is no longer a dependency
@Getter
private final String kubectlExecutable;

// remove when kubectl is no longer a dependency
@Getter
private final String kubeconfigFile;
Expand Down Expand Up @@ -95,6 +99,7 @@ public static class Builder {
String accountName;
String kubeconfigFile;
String context;
String kubectlExecutable;
String oAuthServiceAccount;
List<String> oAuthScopes;
String userAgent;
Expand All @@ -114,6 +119,11 @@ public Builder kubeconfigFile(String kubeconfigFile) {
return this;
}

public Builder kubectlExecutable(String kubectlExecutable) {
this.kubectlExecutable = kubectlExecutable;
return this;
}

public Builder context(String context) {
this.context = context;
return this;
Expand Down Expand Up @@ -185,6 +195,7 @@ public KubernetesV2Credentials build() {
omitNamespaces,
registry,
kubeconfigFile,
kubectlExecutable,
context,
oAuthServiceAccount,
oAuthScopes,
Expand All @@ -199,6 +210,7 @@ private KubernetesV2Credentials(@NotNull String accountName,
@NotNull List<String> omitNamespaces,
@NotNull Registry registry,
String kubeconfigFile,
String kubectlExecutable,
String context,
String oAuthServiceAccount,
List<String> oAuthScopes,
Expand All @@ -210,7 +222,7 @@ private KubernetesV2Credentials(@NotNull String accountName,
this.omitNamespaces = omitNamespaces;
this.jobExecutor = jobExecutor;
this.debug = debug;

this.kubectlExecutable = kubectlExecutable;
this.kubeconfigFile = kubeconfigFile;
this.context = context;
this.oAuthServiceAccount = oAuthServiceAccount;
Expand Down

0 comments on commit 1d08c99

Please sign in to comment.