Skip to content

Commit

Permalink
Fix local run for orchestrator (#2106)
Browse files Browse the repository at this point in the history
  • Loading branch information
nulls authored Apr 26, 2023
1 parent 4971ab8 commit 9d694e0
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
push:
branches:
- 'master'

concurrency:
# https://docs.github.com/en/actions/using-jobs/using-concurrency
# The latest queued workflow is preferred; the ones already in progress get cancelled
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ jobs:
path: save
fetch-depth: 0
submodules: true
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 11
java-version: 17
distribution: temurin
- name: Install system packages
# libcurl is needed for ktor-client-curl
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 11
java-version: 17
distribution: temurin
- uses: gradle/gradle-build-action@v2
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/diktat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 11
java-version: 17
distribution: temurin
- uses: gradle/gradle-build-action@v2
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/save-api-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 11
java-version: 17
distribution: temurin
- name: Install system packages
# libcurl is needed for ktor-client-curl, libc-bin for orchestrator
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ liquibaseTaskPrefix=liquibase
#build.docker.cert-path=C:\\Users\\<User>\\.minikube\\certs

# gradle performance
org.gradle.jvmargs=-Xmx3g -XX:MaxMetaspaceSize=512m
org.gradle.jvmargs=-Xmx4g -Xms3g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.vfs.watch=true
## https://docs.gradle.org/current/userguide/multi_project_configuration_and_execution.html#sec:configuration_on_demand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.saveourtool.save.agent.utils.TEST_SUITES_DIR_NAME
import com.saveourtool.save.core.config.LogType
import com.saveourtool.save.core.config.OutputStreamType
import com.saveourtool.save.core.config.ReportType
import com.saveourtool.save.utils.optionalEnv
import com.saveourtool.save.utils.requiredEnv
import generated.SAVE_CLOUD_VERSION

Expand All @@ -26,6 +27,7 @@ import kotlinx.serialization.Serializable
* @property testSuitesDir directory where tests and additional files need to be stored into
* @property logFilePath path to logs of save-cli execution
* @property save additional configuration for save-cli
* @property kubernetes a flag which shows that agent runs in k8s
*/
@Serializable
data class AgentConfiguration(
Expand All @@ -37,6 +39,7 @@ data class AgentConfiguration(
val debug: Boolean = false,
val testSuitesDir: String = TEST_SUITES_DIR_NAME,
val logFilePath: String = "logs.txt",
val kubernetes: Boolean = false,
val save: SaveCliConfig = SaveCliConfig(),
) {
companion object {
Expand All @@ -52,6 +55,7 @@ data class AgentConfiguration(
heartbeat = HeartbeatConfig(
url = requiredEnv(AgentEnvName.HEARTBEAT_URL.name),
),
kubernetes = optionalEnv(AgentEnvName.KUBERNETES.name).toBoolean(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,7 @@ private fun configureHttpClient(agentConfiguration: AgentConfiguration) = HttpCl
logger = ktorLogger
level = if (agentConfiguration.debug) LogLevel.ALL else LogLevel.INFO
}
install(KubernetesServiceAccountAuthHeaderPlugin)
if (agentConfiguration.kubernetes) {
install(KubernetesServiceAccountAuthHeaderPlugin)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ enum class AgentEnvName {
DEBUG,
EXECUTION_ID,
HEARTBEAT_URL,
KUBERNETES,
TEST_SUITES_DIR,
;
}
2 changes: 1 addition & 1 deletion save-deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ two reasons:
Under WSL, from a separate local _Git_ repository run:

```bash
./gradlew :save-agent:copyAgentDistribution -Preckon.stage=snapshot
./gradlew :save-agent:clean :save-agent:build :save-agent:copyAgentDistribution -x spotlessKotlin -Preckon.stage=snapshot -Psave.profile=dev
```

and provide the path to the JAR archive which contains `save-agent.kexe` via the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class DockerContainerRunner(
override fun isStopped(containerId: String): Boolean = dockerClient.inspectContainerCmd(containerId)
.exec()
.state
.also { log.debug("Container $containerId has state $it") }
.also { state -> log.debug { "Container $containerId has state $state" } }
.status != RUNNING_STATUS

override fun cleanupAllByExecution(executionId: Long) {
Expand Down Expand Up @@ -113,7 +113,7 @@ class DockerContainerRunner(
for (type in PruneType.values().filterNot { it == PruneType.VOLUMES }) {
val pruneCmd = dockerClient.pruneCmd(type).withUntilFilter(configProperties.dockerResourcesLifetime).exec()
val currentReclaimedBytes = pruneCmd.spaceReclaimed ?: 0
log.debug("Reclaimed $currentReclaimedBytes bytes after prune of docker $type")
log.debug { "Reclaimed $currentReclaimedBytes bytes after prune of docker $type" }
reclaimedBytes += currentReclaimedBytes
}
log.info("Reclaimed $reclaimedBytes bytes after prune command")
Expand All @@ -136,9 +136,9 @@ class DockerContainerRunner(
val baseImageTag = configuration.imageTag
val runCmd = configuration.runCmd
val envFileTargetPath = "$SAVE_AGENT_USER_HOME/.env"
val envVariables = configuration.env.map { (key, value) ->
"$key=$value"
} + "${AgentEnvName.CONTAINER_NAME.name}=$containerName"
val envVariables = configuration.env.mapToEnvs() +
AgentEnvName.CONTAINER_NAME.toEnv(containerName) +
kubernetesEnv

// createContainerCmd accepts image name, not id, so we retrieve it from tags
val createContainerCmdResponse: CreateContainerResponse = dockerClient.createContainerCmd(baseImageTag)
Expand Down Expand Up @@ -218,5 +218,10 @@ class DockerContainerRunner(
companion object {
private val log: Logger = getLogger<DockerContainerRunner>()
private const val RUNNING_STATUS = "running"
private val kubernetesEnv: String = AgentEnvName.KUBERNETES.toEnv(false)

private fun Map<AgentEnvName, Any>.mapToEnvs(): List<String> = entries.map { (key, value) -> key.toEnv(value) }

private fun AgentEnvName.toEnv(value: Any): String = "${this.name}=$value"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class KubernetesManager(
imagePullPolicy = "IfNotPresent" // so that local images could be used

val staticEnvs = env.mapToEnvs()
this.env = staticEnvs + containerIdEnv
this.env = staticEnvs + containerIdEnv + kubernetesEnv

this.command = agentRunCmd.dropLast(1)
this.args = listOf(agentRunCmd.last())
Expand All @@ -176,13 +176,6 @@ class KubernetesManager(
}
}

private fun Map<AgentEnvName, Any>.mapToEnvs(): List<EnvVar> = map { (envName, envValue) ->
EnvVar().apply {
name = envName.name
value = envValue.toString()
}
}

companion object {
private val logger = LoggerFactory.getLogger(KubernetesManager::class.java)
private const val EXECUTION_ID_LABEL = "executionId"
Expand All @@ -198,5 +191,13 @@ class KubernetesManager(
}
}
}
private val kubernetesEnv: EnvVar = AgentEnvName.KUBERNETES.toEnv(true)

private fun Map<AgentEnvName, Any>.mapToEnvs(): List<EnvVar> = entries.map { (key, value) -> key.toEnv(value) }

private fun AgentEnvName.toEnv(value: Any): EnvVar = EnvVar().apply {
this.name = this@toEnv.name
this.value = value.toString()
}
}
}

0 comments on commit 9d694e0

Please sign in to comment.