Skip to content

Commit

Permalink
fix: make serviceAccountName configurable
Browse files Browse the repository at this point in the history
also rename workerImage to elasticWorkerImage and workerJVMOptions to elasticWorkerJVMOptions
  • Loading branch information
D-D-H committed Oct 18, 2023
1 parent a56d7ac commit e4e0689
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
3 changes: 2 additions & 1 deletion cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ spec:
- --jifa.scheduling-strategy=elastic
- --jifa.storage-pvc-name=jifa-pvc
- --jifa.storage-path=/jifa-storage
- --jifa.worker-image=eclipsejifa/jifa:0.2.0-SNAPSHOT
- --jifa.service-account-name=jifa-service-account
- --jifa.elastic-worker-image=eclipsejifa/jifa:0.2.0-SNAPSHOT
ports:
- name: jifa-port
containerPort: 8102
Expand Down
15 changes: 11 additions & 4 deletions server/src/main/java/org/eclipse/jifa/server/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,20 @@ public class Configuration {
*/
private String storagePVCName;

/**
* The name of ServiceAccount
*/
private String serviceAccountName;

/**
* The container image of elastic workers.
*/
private String workerImage;
private String elasticWorkerImage;

/**
* The JVM options of elastic workers.
*/
private String workerJVMOptions;
private String elasticWorkerJVMOptions;

/**
* The port of elastic workers.
Expand Down Expand Up @@ -145,8 +150,10 @@ private void init() {
if (schedulingStrategy == SchedulingStrategy.ELASTIC) {
Validate.notBlank(storagePVCName,
"jifa.storage-pvc-name must be set and not blank when role is master and scheduling strategy is elastic");
Validate.notBlank(workerImage,
"jifa.worker-image name must be set and not blank when role is master and scheduling strategy is elastic");
Validate.notBlank(serviceAccountName,
"jifa.service-account-name must be set and not blank when role is master and scheduling strategy is elastic");
Validate.notBlank(elasticWorkerImage,
"jifa.elastic-worker-image name must be set and not blank when role is master and scheduling strategy is elastic");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void scheduleAsync(long identity, long requestedMemSize, BiConsumer<Strin

V1Container container = new V1Container()
.name(WORKER_CONTAINER_NAME)
.image(config.getWorkerImage())
.image(config.getElasticWorkerImage())
.imagePullPolicy("Always")
.addVolumeMountsItem(new V1VolumeMount().name("jifa-pv").mountPath(config.getStoragePath().toString()))
.addEnvItem(new V1EnvVar().name(ELASTIC_WORKER_IDENTITY_ENV_KEY).value(Long.toString(identity)))
Expand All @@ -110,18 +110,19 @@ public void scheduleAsync(long identity, long requestedMemSize, BiConsumer<Strin
.addEnvItem(new V1EnvVar().name("MYSQL_PASSWORD").value(config.getDatabasePassword()))
.args(List.of(
"--jifa.role=elastic-worker",
"--jifa.storage-path=" + config.getStoragePath().toString()))
.addPortsItem(new V1ContainerPort().containerPort(DEFAULT_PORT))
"--jifa.storage-path=" + config.getStoragePath().toString(),
"--jifa.port=" + config.getElasticWorkerPort()))
.addPortsItem(new V1ContainerPort().containerPort(config.getElasticWorkerPort()))
.resources(resourceRequirements)
.startupProbe(healthCheck);

String workerJVMOptions = config.getWorkerJVMOptions();
if (StringUtils.isNotBlank(workerJVMOptions)) {
container.addEnvItem(new V1EnvVar().name("JAVA_TOOL_OPTIONS").value(workerJVMOptions));
String jvmOptions = config.getElasticWorkerJVMOptions();
if (StringUtils.isNotBlank(jvmOptions)) {
container.addEnvItem(new V1EnvVar().name("JAVA_TOOL_OPTIONS").value(jvmOptions));
}

pod.spec(new V1PodSpec().addContainersItem(container).addVolumesItem(volume)
.serviceAccountName("jifa-service-account")
.serviceAccountName(config.getServiceAccountName())
.restartPolicy("Never"));

api.createNamespacedPod(K8S_NAMESPACE, pod, null, null, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@WebMvcTest(
properties = {"jifa.role=master", "jifa.scheduling-strategy=elastic", "jifa.storage-pvc-name=storage-pvc", "jifa.worker-image=image"},
properties = {
"jifa.role=master",
"jifa.scheduling-strategy=elastic",
"jifa.storage-pvc-name=storage-pvc",
"jifa.service-account-name=service-account",
"jifa.elastic-worker-image=image"
},
value = ElasticWorkerController.class, excludeAutoConfiguration = {SecurityAutoConfiguration.class}
)
public class TestElasticWorkerController {
Expand Down
14 changes: 11 additions & 3 deletions site/docs/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,29 @@ Default: null

## storage-pvc-name

The PVC used in an elastic cluster.
The name of PersistentVolumeClaim used in an elastic cluster.

Type: String

Default: null

## worker-image
## service-account-name

The name of ServiceAccount used in an elastic cluster.

Type: String

Default: null

## elastic-worker-image

Docker image used in an elastic cluster to run `WORKER` nodes.

Type: String

Default: null

## worker-jvm-options
## elastic-worker-jvm-options

JVM options used by `WORKER` nodes in an elastic cluster

Expand Down
14 changes: 11 additions & 3 deletions site/docs/zh/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,29 @@

## storage-pvc-name

弹性集群中使用的 PVC
弹性集群中使用的 PersistentVolumeClaim 名称

类型:String

默认值:null

## worker-image
## service-account-name

弹性集群中使用的 ServiceAccount 名称。

类型: String

默认值: null

## elastic-worker-image

弹性集群中用于运行 `WORKER` 节点的镜像。

类型:String

默认值:null

## worker-jvm-options
## elastic-worker-jvm-options

弹性集群中用于设置 `WORKER` 节点的 JVM 参数。

Expand Down

0 comments on commit e4e0689

Please sign in to comment.