-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 merge docker and kubernetes provider (#333)
Docker and Kubernetes providers share a lot of similarities. ref: #332
- Loading branch information
1 parent
52ebd33
commit b326289
Showing
29 changed files
with
343 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
unisonui { | ||
providers += "tech.unisonui.providers.container.ContainerProvider" | ||
provider.container { | ||
kubernetes { | ||
enabled = yes | ||
polling-interval = "1 minute" | ||
} | ||
|
||
docker { | ||
enabled = yes | ||
host = "unix:///var/run/docker.sock" | ||
} | ||
|
||
labels { | ||
service-name = "unisonui.service-name" | ||
|
||
openapi { | ||
port = "unisonui.specification.port" | ||
protocol = "unisonui.specification.protocol" | ||
specification-path = "unisonui.specification.path" | ||
use-proxy = "unisonui.specification.use-proxy" | ||
} | ||
|
||
grpc { | ||
port = "unisonui.grpc.port" | ||
tls = "unisonui.grpc.tls" | ||
} | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
providers/container/src/main/scala/tech/unisonui/providers/container/ContainerProvider.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package tech.unisonui.providers.container | ||
|
||
import akka.NotUsed | ||
import akka.actor.typed.ActorSystem | ||
import akka.stream.scaladsl.{Merge, Source} | ||
import com.typesafe.config.Config | ||
import com.typesafe.scalalogging.LazyLogging | ||
import tech.unisonui.grpc.ReflectionClientImpl | ||
import tech.unisonui.models.ServiceEvent | ||
import tech.unisonui.providers.Provider | ||
import tech.unisonui.providers.container.docker.client.impl.HttpClient | ||
import tech.unisonui.providers.container.settings.Settings | ||
import tech.unisonui.providers.container.sources.{ | ||
DockerSource, | ||
KubernetesSource | ||
} | ||
// $COVERAGE-OFF$ | ||
class ContainerProvider extends Provider with LazyLogging { | ||
|
||
override def start( | ||
actorSystem: ActorSystem[_], | ||
config: Config): Source[(String, ServiceEvent), NotUsed] = { | ||
implicit val system: ActorSystem[_] = actorSystem | ||
val name = classOf[ContainerProvider].getCanonicalName | ||
val settings = Settings.from(config) | ||
val reflectionClient = new ReflectionClientImpl() | ||
val dockerSource = settings.docker.fold(Source.empty[ServiceEvent]) { | ||
setting => | ||
val client = new HttpClient(setting.host) | ||
new DockerSource(client, reflectionClient, settings).startStreaming | ||
} | ||
val kubernetesSource = | ||
settings.kubernetes.fold(Source.empty[ServiceEvent]) { setting => | ||
new KubernetesSource(setting.pollingInterval, | ||
settings.labels, | ||
reflectionClient).listCurrentAndFutureServices | ||
} | ||
logger.debug("Initialising container provider") | ||
Source | ||
.combine(dockerSource, kubernetesSource)(Merge(_)) | ||
.map(name -> _) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../providers/docker/client/HttpClient.scala → .../container/docker/client/HttpClient.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ders/docker/client/models/Container.scala → ...iner/docker/client/models/Container.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...roviders/docker/client/models/Event.scala → ...ontainer/docker/client/models/Event.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...viders/docker/client/models/Network.scala → ...tainer/docker/client/models/Network.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ocker/client/models/NetworkSettings.scala → ...ocker/client/models/NetworkSettings.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...roviders/docker/client/models/State.scala → ...ontainer/docker/client/models/State.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../docker/client/transport/DockerSock.scala → .../docker/client/transport/DockerSock.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
.../container/src/main/scala/tech/unisonui/providers/container/settings/DockerSettings.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package tech.unisonui.providers.container.settings | ||
|
||
final case class DockerSettings(host: String) |
4 changes: 4 additions & 0 deletions
4
...tainer/src/main/scala/tech/unisonui/providers/container/settings/KubernetesSettings.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package tech.unisonui.providers.container.settings | ||
|
||
import scala.concurrent.duration.FiniteDuration | ||
final case class KubernetesSettings(pollingInterval: FiniteDuration) |
Oops, something went wrong.