-
Couldn't load subscription status.
- Fork 504
Kubernetes API refactor #1603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Kubernetes API refactor #1603
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8c03ddb
Make Kubernetes Objects watchable (#1527)
hawkw 386c12a
Add interpreter for reading from a k8s ConfigMap (#1532)
hawkw 03ec251
K8s namers watch individual objects, rather than the entire ns (#1587)
hawkw e36f7d5
Change note "Dentries are from namerd" to "...from an external source"
hawkw d215b98
Add changes to precompiled template
hawkw faf3dc5
Review feedback + style fixes
hawkw 9688dc4
Minor ServiceNamer improvements
hawkw 899d938
Add more comments to EndpointsNamer
hawkw 8e03a5a
Merge branch 'master' into kube-refactor
hawkw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
126 changes: 63 additions & 63 deletions
126
admin/src/main/resources/io/buoyant/admin/js/template/compiled_templates.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
1 change: 1 addition & 0 deletions
1
interpreter/k8s/src/main/resources/META-INF/services/io.buoyant.namer.InterpreterInitializer
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| io.buoyant.interpreter.k8s.ConfigMapInterpreterInitializer | ||
| io.buoyant.interpreter.k8s.IstioInterpreterInitializer |
88 changes: 88 additions & 0 deletions
88
...reter/k8s/src/main/scala/io/buoyant/interpreter/k8s/ConfigMapInterpreterInitializer.scala
This file contains hidden or 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,88 @@ | ||
| package io.buoyant.interpreter | ||
| package k8s | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnore | ||
| import com.twitter.finagle.Dtab | ||
| import com.twitter.finagle.Stack.Params | ||
| import com.twitter.finagle.naming.NameInterpreter | ||
| import com.twitter.finagle.param.Label | ||
| import com.twitter.logging.Logger | ||
| import com.twitter.util._ | ||
| import io.buoyant.config.types.Port | ||
| import io.buoyant.k8s.ClientConfig | ||
| import io.buoyant.k8s.v1._ | ||
| import io.buoyant.namer.{ConfiguredDtabNamer, InterpreterConfig, InterpreterInitializer, Param} | ||
| import java.util.concurrent.atomic.AtomicReference | ||
|
|
||
| class ConfigMapInterpreterInitializer extends InterpreterInitializer { | ||
| val configClass = classOf[ConfigMapInterpreterConfig] | ||
| override def configId: String = "io.l5d.k8s.configMap" | ||
| } | ||
|
|
||
| object ConfigMapInterpreterInitializer extends ConfigMapInterpreterInitializer | ||
|
|
||
| case class ConfigMapInterpreterConfig( | ||
| host: Option[String], | ||
| port: Option[Port], | ||
| namespace: Option[String], | ||
| name: String, | ||
| filename: String | ||
| ) extends InterpreterConfig with ClientConfig { | ||
| require(name != null, "ConfigMap name is required!") | ||
| require(filename != null, "ConfigMap dtab filename is required!") | ||
|
|
||
| @JsonIgnore | ||
| override def experimentalRequired = true | ||
|
|
||
| @JsonIgnore | ||
| def portNum = port.map(_.port) | ||
|
|
||
| @JsonIgnore | ||
| private[this] val log = Logger() | ||
|
|
||
| @JsonIgnore | ||
| val api = { | ||
| val client = mkClient(Params.empty).configured(Label("configMapInterpreter")) | ||
| val nsOrDefault = namespace.getOrElse(DefaultNamespace) | ||
| Api(client.newService(dst)).withNamespace(nsOrDefault) | ||
| } | ||
|
|
||
| @JsonIgnore | ||
| val act = api.configMap(name) | ||
| .activity(extractDtab) { | ||
| (dtab, event) => | ||
| event match { | ||
| case ConfigMapAdded(a) => getDtab(a) | ||
| case ConfigMapModified(m) => getDtab(m) | ||
| case ConfigMapDeleted(_) => | ||
| log.warning(s"k8s ConfigMap $name was deleted!") | ||
| Dtab.empty | ||
| case ConfigMapError(e) => | ||
| log.error("k8s watch error: %s", e) | ||
| dtab | ||
| } | ||
| } | ||
|
|
||
| @JsonIgnore | ||
| @inline | ||
| private[this] def extractDtab(response: Option[ConfigMap]): Dtab = | ||
| response.map(getDtab).getOrElse { | ||
| log.warning(s"K8s ConfigMap %s doesn't exist, assuming it will be created", name) | ||
| Dtab.empty | ||
| } | ||
|
|
||
| @JsonIgnore | ||
| def getDtab(configMap: ConfigMap): Dtab = | ||
| configMap.data.get(filename) match { | ||
| case None => | ||
| log.warning(s"dtab at %s in k8s ConfigMap %s did not exist!", filename, name) | ||
| Dtab.empty | ||
| case Some(data) => Dtab.read(data) | ||
| } | ||
|
|
||
| @JsonIgnore | ||
| override def newInterpreter(params: Params): NameInterpreter = { | ||
| val Param.Namers(namers) = params[Param.Namers] | ||
| ConfiguredDtabNamer(act, namers) | ||
| } | ||
| } |
69 changes: 69 additions & 0 deletions
69
interpreter/k8s/src/test/scala/io/buoyant/interpreter/k8s/ConfigMapInterpreterTest.scala
This file contains hidden or 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,69 @@ | ||
| package io.buoyant.interpreter.k8s | ||
|
|
||
| import com.twitter.finagle.Dtab | ||
| import com.twitter.finagle.util.LoadService | ||
| import io.buoyant.config.Parser | ||
| import io.buoyant.config.types.Port | ||
| import io.buoyant.k8s.v1.ConfigMap | ||
| import io.buoyant.namer.{InterpreterConfig, InterpreterInitializer} | ||
| import io.buoyant.test.FunSuite | ||
| import org.scalatest.{Inside, OptionValues} | ||
|
|
||
| class ConfigMapInterpreterTest extends FunSuite | ||
| with Inside { | ||
|
|
||
| test("interpreter registration") { | ||
| assert(LoadService[InterpreterInitializer]() | ||
| .exists(_.isInstanceOf[ConfigMapInterpreterInitializer])) | ||
| } | ||
|
|
||
| private[this] def parse(yaml: String): ConfigMapInterpreterConfig = Parser.objectMapper(yaml, Iterable(Seq(ConfigMapInterpreterInitializer))) | ||
| .readValue[InterpreterConfig](yaml) | ||
| .asInstanceOf[ConfigMapInterpreterConfig] | ||
|
|
||
| test("parse config") { | ||
| val yaml = | ||
| s"""|kind: io.l5d.k8s.configMap | ||
| |host: "foo" | ||
| |port: 8888 | ||
| |namespace: "my-great-namespace" | ||
| |name: "configMap" | ||
| |filename: "test.dtab" | ||
| |""".stripMargin | ||
| val config = parse(yaml) | ||
| inside(config) { | ||
| case ConfigMapInterpreterConfig(host, port, namespace, name, filename) => | ||
| assert(host.contains("foo")) | ||
| assert(port.contains(Port(8888))) | ||
| assert(namespace.contains("my-great-namespace")) | ||
| assert(name == "configMap") | ||
| assert(filename == "test.dtab") | ||
| } | ||
| } | ||
|
|
||
| test("get empty dtab") { | ||
| val yaml = | ||
| s"""|kind: io.l5d.k8s.configMap | ||
| |name: "configMap" | ||
| |filename: "test.dtab" | ||
| |""".stripMargin | ||
| val config = parse(yaml) | ||
| val configMap = ConfigMap(Map[String, String]()) | ||
| assert(config.getDtab(configMap).isEmpty) | ||
| } | ||
|
|
||
| test("get non-empty dtab") { | ||
| val yaml = | ||
| s"""|kind: io.l5d.k8s.configMap | ||
| |name: "configMap" | ||
| |filename: "test.dtab" | ||
| |""".stripMargin | ||
| val config = parse(yaml) | ||
| val dtab = "/foo => /bar/baz;" | ||
| val configMap = ConfigMap(Map( | ||
| "test.dtab" -> dtab, | ||
| "otherTest.dtab" -> "quux => quuux" | ||
| )) | ||
| assert(config.getDtab(configMap) == Dtab.read(dtab)) | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, this has been bothering me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I think you'll need to recompile the templates in order for this change to take effect)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I realized that: d215b98 :)