-
Notifications
You must be signed in to change notification settings - Fork 83
Conversation
67f7539
to
ab1f51e
Compare
self
through property functionsself
through property functions
34589ab
to
2f4f5c3
Compare
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.
Minor comment, otherwise lgtm.
ksonnet-gen/ksonnet/emit.go
Outdated
body = fmt.Sprintf("{%s+: %s}", fieldName, paramName) | ||
setterBody = fmt.Sprintf("{%s: %s}", fieldName, paramName) | ||
mixinBody = fmt.Sprintf("{%s+: %s}", fieldName, paramName) | ||
emitMixin = true |
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.
emitMixin
is set to true
in both cases, can you take it out of the conditional? Same with above line 838.
This is super exciting! LGTM |
Currently the `+` pattern is used prodigiously by ksonnet-lib. For example, we might build up a container object with something like: container.new("nginx-depl", "nginx") + container.ports(port.new(80)) This commit introduces new "helper" construct that greatly cuts down on verbosity, so that something like the following is possible: container .new("nginx-depl", "nginx") .withPorts(port.new(80)) This is supported, essentially, by having every method return `self`. For example, in the case of `metadata.name`, we would have something like the example below. name(name):: self + __metadataMixin({name: name}), The essential nature of this change is to include the surrounding object in the return, so that all the methods of (e.g.) `metadata` are available on it. Signed-off-by: Alex Clemmer <clemmer.alexander@gmail.com>
Hi again, as of now it looks that current head is busted (for beta.3) actually @hausdorff example above won't work at all ... for it to behave, unless I'm missing something, it seems one has to manually patch diff --git a/ksonnet.beta.3/k8s.libsonnet b/ksonnet.beta.3/k8s.libsonnet
index 3b1bb7d..7cb3f16 100644
--- a/ksonnet.beta.3/k8s.libsonnet
+++ b/ksonnet.beta.3/k8s.libsonnet
@@ -348,7 +348,7 @@
// Deployment enables declarative updates for Pods and ReplicaSets.
deployment:: {
local kind = {kind: "Deployment"},
- new(name, replicas, containers, podLabels={app: name}):: apiVersion + kind + self.mixin.metadata.name(name) + self.mixin.spec.replicas(replicas) + self.mixin.spec.template.spec.containers(containers) + self.mixin.spec.template.metadata.labels(podLabels),
+ new(name, replicas, containers, podLabels={app: name}):: apiVersion + kind + self.mixin.metadata.withName(name) + self.mixin.spec.withReplicas(replicas) + self.mixin.spec.template.spec.withContainers(containers) + self.mixin.spec.template.metadata.withLabels(podLabels),
mixin:: {
// Standard object metadata.
metadata:: {
@@ -865,7 +865,7 @@
// The StatefulSet guarantees that a given network identity will always map to the same storage identity.
statefulSet:: {
local kind = {kind: "StatefulSet"},
- new(name, replicas, containers, volumeClaims, podLabels={app: name}):: apiVersion + kind + self.mixin.metadata.name(name) + self.mixin.spec.replicas(replicas) + self.mixin.spec.template.spec.containers(containers) + self.mixin.spec.volumeClaimTemplates(volumeClaims) + self.mixin.spec.template.metadata.labels(podLabels),
+ new(name, replicas, containers, volumeClaims, podLabels={app: name}):: apiVersion + kind + self.mixin.metadata.withName(name) + self.mixin.spec.withReplicas(replicas) + self.mixin.spec.template.spec.withContainers(containers) + self.mixin.spec.withVolumeClaimTemplates(volumeClaims) + self.mixin.spec.template.metadata.withLabels(podLabels),
mixin:: {
//
metadata:: {
@@ -4219,7 +4219,7 @@
// Namespace provides a scope for Names. Use of multiple namespaces is optional.
namespace:: {
local kind = {kind: "Namespace"},
- new(name):: apiVersion + kind + self.mixin.metadata.name(name),
+ new(name):: apiVersion + kind + self.mixin.metadata.withName(name),
mixin:: {
// Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
metadata:: { Thanks in advance! |
@AntonioMeireles I actually can't reproduce this issue. At the top of your |
The net effect of these changes is that something like this is now possible: