This is an automated email from the ASF dual-hosted git repository. markusthoemmes pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git
The following commit(s) were added to refs/heads/master by this push: new 64cb8ec Move runtimesRegistry to pureconfig. (#4343) 64cb8ec is described below commit 64cb8ecc60c158226415909a00958c758ca0ebe1 Author: Christian Bickel <git...@cbickel.de> AuthorDate: Mon Mar 18 10:09:11 2019 +0100 Move runtimesRegistry to pureconfig. (#4343) This PR moves the config of the runtimes-registry to pureconfig. In addition it adds the ability to provide credentials for this registry. They are not used yet in the default implementations of the container factory. But they can be used in the SPIs. --- ansible/roles/invoker/tasks/deploy.yml | 2 +- .../org/apache/openwhisk/core/WhiskConfig.scala | 3 +-- .../core/containerpool/ContainerFactory.scala | 4 ++++ .../core/mesos/MesosContainerFactory.scala | 11 ++++++----- .../openwhisk/core/loadBalancer/LeanBalancer.scala | 3 +-- core/invoker/src/main/resources/application.conf | 19 ++++++++++++------- .../docker/DockerContainerFactory.scala | 10 +++++----- .../kubernetes/KubernetesContainerFactory.scala | 20 ++++++++++++-------- .../apache/openwhisk/core/invoker/Invoker.scala | 2 +- tests/src/test/resources/application.conf.j2 | 4 ++++ .../docker/test/DockerContainerFactoryTests.scala | 17 ++++++++++++----- .../mesos/test/MesosContainerFactoryTest.scala | 22 +++++++++++----------- 12 files changed, 70 insertions(+), 47 deletions(-) diff --git a/ansible/roles/invoker/tasks/deploy.yml b/ansible/roles/invoker/tasks/deploy.yml index 09f0daf..5a2f298 100644 --- a/ansible/roles/invoker/tasks/deploy.yml +++ b/ansible/roles/invoker/tasks/deploy.yml @@ -227,7 +227,7 @@ "WHISK_API_HOST_PROTO": "{{ whisk_api_host_proto | default('https') }}" "WHISK_API_HOST_PORT": "{{ whisk_api_host_port | default('443') }}" "WHISK_API_HOST_NAME": "{{ whisk_api_host_name | default(groups['edge'] | first) }}" - "RUNTIMES_REGISTRY": "{{ runtimes_registry | default('') }}" + "CONFIG_whisk_containerFactory_runtimesRegistry_url": "{{ runtimes_registry | default('') }}" "RUNTIMES_MANIFEST": "{{ runtimesManifest | to_json }}" "CONFIG_whisk_runtimes_bypassPullForLocalImages": "{{ runtimes_bypass_pull_for_local_images | default() | string }}" "CONFIG_whisk_runtimes_localImagePrefix": "{{ runtimes_local_image_prefix | default() }}" diff --git a/common/scala/src/main/scala/org/apache/openwhisk/core/WhiskConfig.scala b/common/scala/src/main/scala/org/apache/openwhisk/core/WhiskConfig.scala index 1111e10..06b797b 100644 --- a/common/scala/src/main/scala/org/apache/openwhisk/core/WhiskConfig.scala +++ b/common/scala/src/main/scala/org/apache/openwhisk/core/WhiskConfig.scala @@ -70,7 +70,6 @@ class WhiskConfig(requiredProperties: Map[String, String], val dbPrefix = this(WhiskConfig.dbPrefix) val mainDockerEndpoint = this(WhiskConfig.mainDockerEndpoint) - val runtimesRegistry = this(WhiskConfig.runtimesRegistry) val runtimesManifest = this(WhiskConfig.runtimesManifest) val actionInvokePerMinuteLimit = this(WhiskConfig.actionInvokePerMinuteLimit) val actionInvokeConcurrentLimit = this(WhiskConfig.actionInvokeConcurrentLimit) @@ -175,7 +174,6 @@ object WhiskConfig { val kafkaHosts = Map(kafkaHostList -> null) val zookeeperHosts = Map(zookeeperHostList -> null) - val runtimesRegistry = "runtimes.registry" val runtimesManifest = "runtimes.manifest" val actionSequenceMaxLimit = "limits.actions.sequence.maxLength" @@ -220,6 +218,7 @@ object ConfigKeys { val containerFactory = "whisk.container-factory" val containerArgs = s"$containerFactory.container-args" + val runtimesRegistry = s"$containerFactory.runtimes-registry" val containerPool = "whisk.container-pool" val blacklist = "whisk.blacklist" diff --git a/common/scala/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerFactory.scala b/common/scala/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerFactory.scala index eeb37f3..553c909 100644 --- a/common/scala/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerFactory.scala +++ b/common/scala/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerFactory.scala @@ -47,6 +47,10 @@ case class ContainerPoolConfig(userMemory: ByteSize, concurrentPeekFactor: Doubl def cpuShare(reservedMemory: ByteSize) = (totalShare / (userMemory.toBytes / reservedMemory.toBytes)).toInt } +case class RuntimesRegistryCredentials(user: String, password: String) + +case class RuntimesRegistryConfig(url: String, credentials: Option[RuntimesRegistryCredentials]) + /** * An abstraction for Container creation */ diff --git a/common/scala/src/main/scala/org/apache/openwhisk/core/mesos/MesosContainerFactory.scala b/common/scala/src/main/scala/org/apache/openwhisk/core/mesos/MesosContainerFactory.scala index 53a6543..5aeb576 100644 --- a/common/scala/src/main/scala/org/apache/openwhisk/core/mesos/MesosContainerFactory.scala +++ b/common/scala/src/main/scala/org/apache/openwhisk/core/mesos/MesosContainerFactory.scala @@ -29,7 +29,9 @@ import com.adobe.api.platform.runtime.mesos.SubscribeComplete import com.adobe.api.platform.runtime.mesos.Teardown import com.adobe.api.platform.runtime.mesos.UNLIKE import java.time.Instant + import pureconfig.loadConfigOrThrow + import scala.concurrent.Await import scala.concurrent.ExecutionContext import scala.concurrent.Future @@ -41,10 +43,7 @@ import org.apache.openwhisk.common.Logging import org.apache.openwhisk.common.TransactionId import org.apache.openwhisk.core.ConfigKeys import org.apache.openwhisk.core.WhiskConfig -import org.apache.openwhisk.core.containerpool.Container -import org.apache.openwhisk.core.containerpool.ContainerArgsConfig -import org.apache.openwhisk.core.containerpool.ContainerFactory -import org.apache.openwhisk.core.containerpool.ContainerFactoryProvider +import org.apache.openwhisk.core.containerpool._ import org.apache.openwhisk.core.entity.ByteSize import org.apache.openwhisk.core.entity.ExecManifest import org.apache.openwhisk.core.entity.InvokerInstanceId @@ -91,6 +90,8 @@ class MesosContainerFactory(config: WhiskConfig, parameters: Map[String, Set[String]], containerArgs: ContainerArgsConfig = loadConfigOrThrow[ContainerArgsConfig](ConfigKeys.containerArgs), + runtimesRegistryConfig: RuntimesRegistryConfig = + loadConfigOrThrow[RuntimesRegistryConfig](ConfigKeys.runtimesRegistry), mesosConfig: MesosConfig = loadConfigOrThrow[MesosConfig](ConfigKeys.mesos), clientFactory: (ActorSystem, MesosConfig) => ActorRef = MesosContainerFactory.createClient, taskIdGenerator: () => String = MesosContainerFactory.taskIdGenerator _) @@ -128,7 +129,7 @@ class MesosContainerFactory(config: WhiskConfig, val image = if (userProvidedImage) { actionImage.publicImageName } else { - actionImage.localImageName(config.runtimesRegistry) + actionImage.localImageName(runtimesRegistryConfig.url) } val constraintStrings = if (userProvidedImage) { mesosConfig.blackboxConstraints diff --git a/core/controller/src/main/scala/org/apache/openwhisk/core/loadBalancer/LeanBalancer.scala b/core/controller/src/main/scala/org/apache/openwhisk/core/loadBalancer/LeanBalancer.scala index af84662..76482b8 100644 --- a/core/controller/src/main/scala/org/apache/openwhisk/core/loadBalancer/LeanBalancer.scala +++ b/core/controller/src/main/scala/org/apache/openwhisk/core/loadBalancer/LeanBalancer.scala @@ -98,7 +98,6 @@ object LeanBalancer extends LoadBalancerProvider { } def requiredProperties = - Map(runtimesRegistry -> "") ++ - ExecManifest.requiredProperties ++ + ExecManifest.requiredProperties ++ wskApiHost } diff --git a/core/invoker/src/main/resources/application.conf b/core/invoker/src/main/resources/application.conf index c1d4bf7..83eb3ac 100644 --- a/core/invoker/src/main/resources/application.conf +++ b/core/invoker/src/main/resources/application.conf @@ -67,13 +67,18 @@ whisk { } # args for 'docker run' to use - container-factory.container-args { - network: bridge - # See https://docs.docker.com/config/containers/container-networking/#dns-services for documentation of dns-* - dns-servers: [] - dns-search: [] - dns-options: [] - extra-args: {} # to pass additional args to 'docker run'; format is `{key1: [v1, v2], key2: [v1, v2]}` + container-factory { + container-args { + network: bridge + # See https://docs.docker.com/config/containers/container-networking/#dns-services for documentation of dns-* + dns-servers: [] + dns-search: [] + dns-options: [] + extra-args: {} # to pass additional args to 'docker run'; format is `{key1: [v1, v2], key2: [v1, v2]}` + } + runtimes-registry { + url: "" + } } container-proxy { diff --git a/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/docker/DockerContainerFactory.scala b/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/docker/DockerContainerFactory.scala index 0fad560..9035d96 100644 --- a/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/docker/DockerContainerFactory.scala +++ b/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/docker/DockerContainerFactory.scala @@ -25,10 +25,7 @@ import scala.concurrent.Future import org.apache.openwhisk.common.Logging import org.apache.openwhisk.common.TransactionId import org.apache.openwhisk.core.WhiskConfig -import org.apache.openwhisk.core.containerpool.Container -import org.apache.openwhisk.core.containerpool.ContainerFactory -import org.apache.openwhisk.core.containerpool.ContainerFactoryProvider -import org.apache.openwhisk.core.containerpool.ContainerArgsConfig +import org.apache.openwhisk.core.containerpool._ import org.apache.openwhisk.core.entity.ByteSize import org.apache.openwhisk.core.entity.ExecManifest import org.apache.openwhisk.core.entity.InvokerInstanceId @@ -45,6 +42,8 @@ class DockerContainerFactory(instance: InvokerInstanceId, parameters: Map[String, Set[String]], containerArgsConfig: ContainerArgsConfig = loadConfigOrThrow[ContainerArgsConfig](ConfigKeys.containerArgs), + runtimesRegistryConfig: RuntimesRegistryConfig = + loadConfigOrThrow[RuntimesRegistryConfig](ConfigKeys.runtimesRegistry), dockerContainerFactoryConfig: DockerContainerFactoryConfig = loadConfigOrThrow[DockerContainerFactoryConfig](ConfigKeys.dockerContainerFactory))( implicit actorSystem: ActorSystem, @@ -63,7 +62,8 @@ class DockerContainerFactory(instance: InvokerInstanceId, cpuShares: Int)(implicit config: WhiskConfig, logging: Logging): Future[Container] = { DockerContainer.create( tid, - image = if (userProvidedImage) Left(actionImage) else Right(actionImage.localImageName(config.runtimesRegistry)), + image = + if (userProvidedImage) Left(actionImage) else Right(actionImage.localImageName(runtimesRegistryConfig.url)), memory = memory, cpuShares = cpuShares, environment = Map("__OW_API_HOST" -> config.wskApiHost), diff --git a/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/kubernetes/KubernetesContainerFactory.scala b/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/kubernetes/KubernetesContainerFactory.scala index f9b538a..49f8edc 100644 --- a/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/kubernetes/KubernetesContainerFactory.scala +++ b/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/kubernetes/KubernetesContainerFactory.scala @@ -24,20 +24,24 @@ import scala.concurrent.Await import scala.concurrent.ExecutionContext import scala.concurrent.Future import scala.concurrent.duration._ - import org.apache.openwhisk.common.Logging import org.apache.openwhisk.common.TransactionId -import org.apache.openwhisk.core.containerpool.Container -import org.apache.openwhisk.core.containerpool.ContainerFactory -import org.apache.openwhisk.core.containerpool.ContainerFactoryProvider +import org.apache.openwhisk.core.containerpool.{ + Container, + ContainerFactory, + ContainerFactoryProvider, + RuntimesRegistryConfig +} import org.apache.openwhisk.core.entity.ByteSize import org.apache.openwhisk.core.entity.ExecManifest.ImageName import org.apache.openwhisk.core.entity.InvokerInstanceId import org.apache.openwhisk.core.{ConfigKeys, WhiskConfig} -class KubernetesContainerFactory(label: String, config: WhiskConfig)(implicit actorSystem: ActorSystem, - ec: ExecutionContext, - logging: Logging) +class KubernetesContainerFactory( + label: String, + config: WhiskConfig, + runtimesRegistryConfig: RuntimesRegistryConfig = loadConfigOrThrow[RuntimesRegistryConfig]( + ConfigKeys.runtimesRegistry))(implicit actorSystem: ActorSystem, ec: ExecutionContext, logging: Logging) extends ContainerFactory { implicit val kubernetes = initializeKubeClient() @@ -69,7 +73,7 @@ class KubernetesContainerFactory(label: String, config: WhiskConfig)(implicit ac val image = if (userProvidedImage) { actionImage.publicImageName } else { - actionImage.localImageName(config.runtimesRegistry) + actionImage.localImageName(runtimesRegistryConfig.url) } KubernetesContainer.create( diff --git a/core/invoker/src/main/scala/org/apache/openwhisk/core/invoker/Invoker.scala b/core/invoker/src/main/scala/org/apache/openwhisk/core/invoker/Invoker.scala index 5f42040..9e59232 100644 --- a/core/invoker/src/main/scala/org/apache/openwhisk/core/invoker/Invoker.scala +++ b/core/invoker/src/main/scala/org/apache/openwhisk/core/invoker/Invoker.scala @@ -50,7 +50,7 @@ object Invoker { * An object which records the environment variables required for this component to run. */ def requiredProperties = - Map(servicePort -> 8080.toString, runtimesRegistry -> "") ++ + Map(servicePort -> 8080.toString) ++ ExecManifest.requiredProperties ++ kafkaHosts ++ zookeeperHosts ++ diff --git a/tests/src/test/resources/application.conf.j2 b/tests/src/test/resources/application.conf.j2 index 20dc8cc..eaf17f7 100644 --- a/tests/src/test/resources/application.conf.j2 +++ b/tests/src/test/resources/application.conf.j2 @@ -80,6 +80,10 @@ whisk { user-events { enabled = {{ user_events }} } + + container-factory.runtimes-registry { + url = "{{ runtimes_registry | default('') }}" + } } #test-only overrides so that tests can override defaults in application.conf (todo: move all defaults to reference.conf) diff --git a/tests/src/test/scala/org/apache/openwhisk/core/containerpool/docker/test/DockerContainerFactoryTests.scala b/tests/src/test/scala/org/apache/openwhisk/core/containerpool/docker/test/DockerContainerFactoryTests.scala index 4bd6e3b..ff381d1 100644 --- a/tests/src/test/scala/org/apache/openwhisk/core/containerpool/docker/test/DockerContainerFactoryTests.scala +++ b/tests/src/test/scala/org/apache/openwhisk/core/containerpool/docker/test/DockerContainerFactoryTests.scala @@ -26,20 +26,25 @@ import org.scalatest.BeforeAndAfterEach import org.scalatest.FlatSpec import org.scalatest.Matchers import org.scalatest.junit.JUnitRunner + import scala.concurrent.Await import scala.concurrent.Future import scala.concurrent.duration._ import org.apache.openwhisk.common.TransactionId -import org.apache.openwhisk.core.WhiskConfig -import org.apache.openwhisk.core.containerpool.ContainerAddress -import org.apache.openwhisk.core.containerpool.ContainerArgsConfig -import org.apache.openwhisk.core.containerpool.ContainerId +import org.apache.openwhisk.core.{ConfigKeys, WhiskConfig} +import org.apache.openwhisk.core.containerpool.{ + ContainerAddress, + ContainerArgsConfig, + ContainerId, + RuntimesRegistryConfig +} import org.apache.openwhisk.core.containerpool.docker.DockerApiWithFileAccess import org.apache.openwhisk.core.containerpool.docker.DockerContainerFactory import org.apache.openwhisk.core.containerpool.docker.DockerContainerFactoryConfig import org.apache.openwhisk.core.containerpool.docker.RuncApi import org.apache.openwhisk.core.entity.{ByteSize, ExecManifest, InvokerInstanceId} import org.apache.openwhisk.core.entity.size._ +import pureconfig.loadConfigOrThrow @RunWith(classOf[JUnitRunner]) class DockerContainerFactoryTests @@ -53,6 +58,7 @@ class DockerContainerFactoryTests implicit val config = new WhiskConfig(ExecManifest.requiredProperties) ExecManifest.initialize(config) should be a 'success + val runtimesRegistryConfig = loadConfigOrThrow[RuntimesRegistryConfig](ConfigKeys.runtimesRegistry) behavior of "DockerContainerFactory" @@ -68,7 +74,7 @@ class DockerContainerFactoryTests (dockerApiStub .run(_: String, _: Seq[String])(_: TransactionId)) .expects( - image.localImageName(config.runtimesRegistry), + image.localImageName(runtimesRegistryConfig.url), List( "--cpu-shares", "32", //should be calculated as 1024/(numcore * sharefactor) via ContainerFactory.cpuShare @@ -112,6 +118,7 @@ class DockerContainerFactoryTests InvokerInstanceId(0, userMemory = defaultUserMemory), Map.empty, ContainerArgsConfig("net1", Seq("dns1", "dns2"), Seq.empty, Seq.empty, Map("env" -> Set("e1", "e2"))), + runtimesRegistryConfig, DockerContainerFactoryConfig(true))(actorSystem, executionContext, logging, dockerApiStub, mock[RuncApi]) val cf = factory.createContainer(tid, "testContainer", image, false, 10.MB, 32) diff --git a/tests/src/test/scala/org/apache/openwhisk/core/containerpool/mesos/test/MesosContainerFactoryTest.scala b/tests/src/test/scala/org/apache/openwhisk/core/containerpool/mesos/test/MesosContainerFactoryTest.scala index 225a79b..c4f68b4 100644 --- a/tests/src/test/scala/org/apache/openwhisk/core/containerpool/mesos/test/MesosContainerFactoryTest.scala +++ b/tests/src/test/scala/org/apache/openwhisk/core/containerpool/mesos/test/MesosContainerFactoryTest.scala @@ -112,8 +112,8 @@ class MesosContainerFactoryTest logging, Map("--arg1" -> Set("v1", "v2")), containerArgsConfig, - mesosConfig, - (system, mesosConfig) => testActor) + mesosConfig = mesosConfig, + clientFactory = (system, mesosConfig) => testActor) expectMsg(Subscribe) } @@ -140,9 +140,9 @@ class MesosContainerFactoryTest logging, Map("--arg1" -> Set("v1", "v2"), "--arg2" -> Set("v3", "v4"), "other" -> Set("v5", "v6")), containerArgsConfig, - mesosConfig, - (_, _) => testActor, - testTaskId _) + mesosConfig = mesosConfig, + clientFactory = (_, _) => testActor, + taskIdGenerator = testTaskId _) expectMsg(Subscribe) factory.createContainer( @@ -184,9 +184,9 @@ class MesosContainerFactoryTest logging, Map("--arg1" -> Set("v1", "v2"), "--arg2" -> Set("v3", "v4"), "other" -> Set("v5", "v6")), containerArgsConfig, - mesosConfig, - (system, mesosConfig) => probe.testActor, - testTaskId _) + mesosConfig = mesosConfig, + clientFactory = (system, mesosConfig) => probe.testActor, + taskIdGenerator = testTaskId _) probe.expectMsg(Subscribe) //emulate successful subscribe @@ -258,9 +258,9 @@ class MesosContainerFactoryTest Seq.empty, Seq.empty, Map("extra1" -> Set("e1", "e2"), "extra2" -> Set("e3", "e4"))), - mesosConfig, - (system, mesosConfig) => probe.testActor, - testTaskId _) + mesosConfig = mesosConfig, + clientFactory = (system, mesosConfig) => probe.testActor, + taskIdGenerator = testTaskId _) probe.expectMsg(Subscribe) //emulate successful subscribe