From b68464fdac734283b2817543352ad2957fa19ced Mon Sep 17 00:00:00 2001
From: Alex Clemmer <clemmer.alexander@gmail.com>
Date: Mon, 20 Nov 2017 16:44:42 -0800
Subject: [PATCH] Update ksonnet-lib vendored dependency

---
 .../ksonnet-gen/jsonnet/rewrite.go            |   8 +
 .../ksonnet-lib/ksonnet-gen/ksonnet/emit.go   |  61 ++++--
 .../ksonnet-gen/kubeversion/data.go           | 188 +++++++++++++++---
 vendor/vendor.json                            |  22 +-
 4 files changed, 230 insertions(+), 49 deletions(-)

diff --git a/vendor/github.com/ksonnet/ksonnet-lib/ksonnet-gen/jsonnet/rewrite.go b/vendor/github.com/ksonnet/ksonnet-lib/ksonnet-gen/jsonnet/rewrite.go
index 65aa5e96..4e53a314 100644
--- a/vendor/github.com/ksonnet/ksonnet-lib/ksonnet-gen/jsonnet/rewrite.go
+++ b/vendor/github.com/ksonnet/ksonnet-lib/ksonnet-gen/jsonnet/rewrite.go
@@ -35,6 +35,14 @@ type FuncParam string
 // Kubernetes version. For example, `fooAPI` becomes `fooApi`.
 type Identifier string
 
+func (id Identifier) ToSetterID() Identifier {
+	return Identifier("with" + strings.Title(string(id)))
+}
+
+func (id Identifier) ToMixinID() Identifier {
+	return Identifier("with" + strings.Title(string(id)) + "Mixin")
+}
+
 // RewriteAsFieldKey takes a `PropertyName` and converts it to a valid
 // Jsonnet field name. For example, if the `PropertyName` has a value
 // of `"error"`, then this would generate an invalid object, `{error:
diff --git a/vendor/github.com/ksonnet/ksonnet-lib/ksonnet-gen/ksonnet/emit.go b/vendor/github.com/ksonnet/ksonnet-lib/ksonnet-gen/ksonnet/emit.go
index 2b0b98c3..f421f374 100644
--- a/vendor/github.com/ksonnet/ksonnet-lib/ksonnet-gen/ksonnet/emit.go
+++ b/vendor/github.com/ksonnet/ksonnet-lib/ksonnet-gen/ksonnet/emit.go
@@ -601,8 +601,10 @@ func (ao *apiObject) emitConstructor(
 					"Attempted to create constructor, but property '%s' does not exist",
 					param.ID)
 			}
+			k8sVersion := ao.root().spec.Info.Version
+			propMethodName := jsonnet.RewriteAsIdentifier(k8sVersion, prop.name).ToSetterID()
 			setters = append(
-				setters, fmt.Sprintf("self.%s(%s)", prop.name, param.ID))
+				setters, fmt.Sprintf("self.%s(%s)", propMethodName, param.ID))
 		} else {
 			// TODO(hausdorff): We may want to verify this relative path
 			// exists.
@@ -788,10 +790,12 @@ func (p *property) emitHelper(
 	p.comments.emit(m)
 
 	k8sVersion := p.root().spec.Info.Version
-	functionName := jsonnet.RewriteAsIdentifier(k8sVersion, p.name)
+	setterFunctionName := jsonnet.RewriteAsIdentifier(k8sVersion, p.name).ToSetterID()
+	mixinFunctionName := jsonnet.RewriteAsIdentifier(k8sVersion, p.name).ToMixinID()
 	paramName := jsonnet.RewriteAsFuncParam(k8sVersion, p.name)
 	fieldName := jsonnet.RewriteAsFieldKey(p.name)
-	signature := fmt.Sprintf("%s(%s)::", functionName, paramName)
+	setterSignature := fmt.Sprintf("%s(%s)::", setterFunctionName, paramName)
+	mixinSignature := fmt.Sprintf("%s(%s)::", mixinFunctionName, paramName)
 
 	if isMixinRef(p.ref) {
 		parsedRefPath := p.ref.Name().Parse()
@@ -804,21 +808,41 @@ func (p *property) emitHelper(
 		} else {
 			body = fmt.Sprintf("%s({%s: %s})", *parentMixinName, fieldName, paramName)
 		}
-		line := fmt.Sprintf("%s %s,", signature, body)
+		line := fmt.Sprintf("%s %s,", setterSignature, body)
 		m.writeLine(line)
 	} else if p.schemaType != nil {
 		paramType := *p.schemaType
 
-		var body string
+		//
+		// Generate both setter and mixin functions for some property. For
+		// example, we emit both `metadata.setAnnotations({foo: "bar"})`
+		// (which replaces a set of annotations with given object) and
+		// `metadata.mixinAnnotations({foo: "bar"})` (which replaces only
+		// the `foo` key, if it exists.)
+		//
+
+		var setterBody string
+		var mixinBody string
+		emitMixin := false
 		switch paramType {
 		case "array":
+			emitMixin = true
 			if parentMixinName == nil {
-				body = fmt.Sprintf(
+				setterBody = fmt.Sprintf(
+					"if std.type(%s) == \"array\" then {%s: %s} else {%s: [%s]}",
+					paramName, fieldName, paramName, fieldName, paramName,
+				)
+				mixinBody = fmt.Sprintf(
 					"if std.type(%s) == \"array\" then {%s+: %s} else {%s+: [%s]}",
 					paramName, fieldName, paramName, fieldName, paramName,
 				)
 			} else {
-				body = fmt.Sprintf(
+				setterBody = fmt.Sprintf(
+					"if std.type(%s) == \"array\" then %s({%s: %s}) else %s({%s: [%s]})",
+					paramName, *parentMixinName, fieldName, paramName, *parentMixinName,
+					fieldName, paramName,
+				)
+				mixinBody = fmt.Sprintf(
 					"if std.type(%s) == \"array\" then %s({%s+: %s}) else %s({%s+: [%s]})",
 					paramName, *parentMixinName, fieldName, paramName, *parentMixinName,
 					fieldName, paramName,
@@ -826,22 +850,35 @@ func (p *property) emitHelper(
 			}
 		case "integer", "string", "boolean":
 			if parentMixinName == nil {
-				body = fmt.Sprintf("{%s: %s}", fieldName, paramName)
+				setterBody = fmt.Sprintf("{%s: %s}", fieldName, paramName)
 			} else {
-				body = fmt.Sprintf("%s({%s: %s})", *parentMixinName, fieldName, paramName)
+				setterBody = fmt.Sprintf("%s({%s: %s})", *parentMixinName, fieldName, paramName)
 			}
 		case "object":
+			emitMixin = true
 			if parentMixinName == nil {
-				body = fmt.Sprintf("{%s+: %s}", fieldName, paramName)
+				setterBody = fmt.Sprintf("{%s: %s}", fieldName, paramName)
+				mixinBody = fmt.Sprintf("{%s+: %s}", fieldName, paramName)
 			} else {
-				body = fmt.Sprintf("%s({%s+: %s})", *parentMixinName, fieldName, paramName)
+				setterBody = fmt.Sprintf("%s({%s: %s})", *parentMixinName, fieldName, paramName)
+				mixinBody = fmt.Sprintf("%s({%s+: %s})", *parentMixinName, fieldName, paramName)
 			}
 		default:
 			log.Panicf("Unrecognized type '%s'", paramType)
 		}
 
-		line := fmt.Sprintf("%s %s,", signature, body)
+		//
+		// Emit.
+		//
+
+		line := fmt.Sprintf("%s self + %s,", setterSignature, setterBody)
 		m.writeLine(line)
+
+		if emitMixin {
+			p.comments.emit(m)
+			line = fmt.Sprintf("%s self + %s,", mixinSignature, mixinBody)
+			m.writeLine(line)
+		}
 	} else {
 		log.Panicf("Neither a type nor a ref")
 	}
diff --git a/vendor/github.com/ksonnet/ksonnet-lib/ksonnet-gen/kubeversion/data.go b/vendor/github.com/ksonnet/ksonnet-lib/ksonnet-gen/kubeversion/data.go
index bd90e066..c3be9669 100644
--- a/vendor/github.com/ksonnet/ksonnet-lib/ksonnet-gen/kubeversion/data.go
+++ b/vendor/github.com/ksonnet/ksonnet-lib/ksonnet-gen/kubeversion/data.go
@@ -72,6 +72,74 @@ var versions = map[string]versionData{
 			"local": "localStorage",
 		},
 		constructorSpecs: map[string][]CustomConstructorSpec{
+			//
+			// Apps namespace.
+			//
+			"io.k8s.kubernetes.pkg.apis.apps.v1beta1.Deployment":         v1beta1Deployment,
+			"io.k8s.kubernetes.pkg.apis.apps.v1beta1.DeploymentList":     objectList,
+			"io.k8s.kubernetes.pkg.apis.apps.v1beta1.DeploymentRollback": v1beta1DeploymentRollback,
+			"io.k8s.kubernetes.pkg.apis.apps.v1beta1.Scale":              v1beta1Scale,
+			"io.k8s.kubernetes.pkg.apis.apps.v1beta1.StatefulSet":        v1beta1StatefulSet,
+			"io.k8s.kubernetes.pkg.apis.apps.v1beta1.StatefulSetList":    objectList,
+
+			//
+			// Extensions namespace.
+			//
+
+			"io.k8s.kubernetes.pkg.apis.extensions.v1beta1.Deployment":         v1beta1Deployment,
+			"io.k8s.kubernetes.pkg.apis.extensions.v1beta1.DeploymentList":     objectList,
+			"io.k8s.kubernetes.pkg.apis.extensions.v1beta1.DeploymentRollback": v1beta1DeploymentRollback,
+			"io.k8s.kubernetes.pkg.apis.extensions.v1beta1.Scale":              v1beta1Scale,
+			"io.k8s.kubernetes.pkg.apis.extensions.v1beta1.StatefulSet":        v1beta1StatefulSet,
+			"io.k8s.kubernetes.pkg.apis.extensions.v1beta1.StatefulSetList":    objectList,
+
+			//
+			// Authentication namespace.
+			//
+
+			"io.k8s.kubernetes.pkg.apis.authentication.v1.TokenReview": []CustomConstructorSpec{
+				newConstructor(
+					"new",
+					newParamNestedRef("token", "mixin.spec.withToken")),
+			},
+			"io.k8s.kubernetes.pkg.apis.authentication.v1beta1.TokenReview": []CustomConstructorSpec{
+				newConstructor(
+					"new",
+					newParamNestedRef("token", "mixin.spec.withToken")),
+			},
+
+			//
+			// Autoscaling namespace.
+			//
+
+			"io.k8s.kubernetes.pkg.apis.autoscaling.v1.HorizontalPodAutoscalerList":       objectList,
+			"io.k8s.kubernetes.pkg.apis.autoscaling.v1.Scale":                             v1beta1Scale,
+			"io.k8s.kubernetes.pkg.apis.autoscaling.v2alpha1.HorizontalPodAutoscalerList": objectList,
+
+			//
+			// Batch namespace.
+			//
+
+			"io.k8s.kubernetes.pkg.apis.batch.v1.JobList":           objectList,
+			"io.k8s.kubernetes.pkg.apis.batch.v2alpha1.CronJobList": objectList,
+
+			//
+			// Certificates namespace.
+			//
+
+			"io.k8s.kubernetes.pkg.apis.certificates.v1beta1.CertificateSigningRequestList": objectList,
+
+			//
+			// Core namespace.
+			//
+
+			"io.k8s.kubernetes.pkg.api.v1.ConfigMap": []CustomConstructorSpec{
+				newConstructor(
+					"new",
+					newParamNestedRef("name", "mixin.metadata.withName"),
+					newParam("data")),
+			},
+			"io.k8s.kubernetes.pkg.api.v1.ConfigMapList": objectList,
 			"io.k8s.kubernetes.pkg.api.v1.Container": []CustomConstructorSpec{
 				newConstructor("new", newParam("name"), newParam("image")),
 			},
@@ -79,28 +147,64 @@ var versions = map[string]versionData{
 				newConstructor("new", newParam("containerPort")),
 				newConstructor("newNamed", newParam("name"), newParam("containerPort")),
 			},
+			"io.k8s.kubernetes.pkg.api.v1.EndpointsList": objectList,
 			"io.k8s.kubernetes.pkg.api.v1.EnvVar": []CustomConstructorSpec{
 				newConstructor("new", newParam("name"), newParam("value")),
 				newConstructor(
 					"fromSecretRef",
 					newParam("name"),
-					newParamNestedRef("secretRefName", "mixin.valueFrom.secretKeyRef.name"),
-					newParamNestedRef("secretRefKey", "mixin.valueFrom.secretKeyRef.key")),
+					newParamNestedRef("secretRefName", "mixin.valueFrom.secretKeyRef.withName"),
+					newParamNestedRef("secretRefKey", "mixin.valueFrom.secretKeyRef.withKey")),
 				newConstructor(
 					"fromFieldPath",
 					newParam("name"),
-					newParamNestedRef("fieldPath", "mixin.valueFrom.fieldRef.fieldPath")),
+					newParamNestedRef("fieldPath", "mixin.valueFrom.fieldRef.withFieldPath")),
 			},
+			"io.k8s.kubernetes.pkg.api.v1.EventList": objectList,
 			"io.k8s.kubernetes.pkg.api.v1.KeyToPath": []CustomConstructorSpec{
 				newConstructor("new", newParam("key"), newParam("path")),
 			},
+			"io.k8s.kubernetes.pkg.api.v1.LimitRangeList": objectList,
+			"io.k8s.kubernetes.pkg.api.v1.Namespace": []CustomConstructorSpec{
+				newConstructor(
+					"new",
+					newParamNestedRef("name", "mixin.metadata.withName")),
+			},
+			"io.k8s.kubernetes.pkg.api.v1.NamespaceList":             objectList,
+			"io.k8s.kubernetes.pkg.api.v1.NodeList":                  objectList,
+			"io.k8s.kubernetes.pkg.api.v1.PersistentVolumeClaimList": objectList,
+			"io.k8s.kubernetes.pkg.api.v1.PersistentVolumeList":      objectList,
+			"io.k8s.kubernetes.pkg.api.v1.PodList":                   objectList,
+			"io.k8s.kubernetes.pkg.api.v1.PodTemplateList":           objectList,
+			"io.k8s.kubernetes.pkg.api.v1.ReplicationControllerList": objectList,
+			"io.k8s.kubernetes.pkg.api.v1.ResourceQuotaList":         objectList,
+			"io.k8s.kubernetes.pkg.api.v1.Secret": []CustomConstructorSpec{
+				newConstructor(
+					"new",
+					newParamNestedRef("name", "mixin.metadata.withName"),
+					newParam("data"),
+					newParamWithDefault("type", "\"Opaque\"")),
+				newConstructor(
+					"fromString",
+					newParamNestedRef("name", "mixin.metadata.withName"),
+					newParam("stringData"),
+					newParamWithDefault("type", "\"Opaque\"")),
+			},
+			"io.k8s.kubernetes.pkg.api.v1.SecretList": objectList,
 			"io.k8s.kubernetes.pkg.api.v1.Service": []CustomConstructorSpec{
 				newConstructor(
 					"new",
-					newParamNestedRef("name", "mixin.metadata.name"),
-					newParamNestedRef("selector", "mixin.spec.selector"),
-					newParamNestedRef("ports", "mixin.spec.ports")),
+					newParamNestedRef("name", "mixin.metadata.withName"),
+					newParamNestedRef("selector", "mixin.spec.withSelector"),
+					newParamNestedRef("ports", "mixin.spec.withPorts")),
+			},
+			"io.k8s.kubernetes.pkg.api.v1.ServiceAccount": []CustomConstructorSpec{
+				newConstructor(
+					"new",
+					newParamNestedRef("name", "mixin.metadata.withName")),
 			},
+			"io.k8s.kubernetes.pkg.api.v1.ServiceAccountList": objectList,
+			"io.k8s.kubernetes.pkg.api.v1.ServiceList":        objectList,
 			"io.k8s.kubernetes.pkg.api.v1.ServicePort": []CustomConstructorSpec{
 				newConstructor("new", newParam("port"), newParam("targetPort")),
 				newConstructor("newNamed", newParam("name"), newParam("port"), newParam("targetPort")),
@@ -109,8 +213,8 @@ var versions = map[string]versionData{
 				newConstructor(
 					"fromConfigMap",
 					newParam("name"),
-					newParamNestedRef("configMapName", "mixin.configMap.name"),
-					newParamNestedRef("configMapItems", "mixin.configMap.items")),
+					newParamNestedRef("configMapName", "mixin.configMap.withName"),
+					newParamNestedRef("configMapItems", "mixin.configMap.withItems")),
 				newConstructor(
 					"fromEmptyDir",
 					newParam("name"),
@@ -118,32 +222,21 @@ var versions = map[string]versionData{
 				newConstructor(
 					"fromPersistentVolumeClaim",
 					newParam("name"),
-					newParamNestedRef("claimName", "mixin.persistentVolumeClaim.claimName")),
+					newParamNestedRef("claimName", "mixin.persistentVolumeClaim.withClaimName")),
 				newConstructor(
 					"fromHostPath",
 					newParam("name"),
-					newParamNestedRef("hostPath", "mixin.hostPath.path")),
+					newParamNestedRef("hostPath", "mixin.hostPath.withPath")),
+				newConstructor(
+					"fromSecret",
+					newParam("name"),
+					newParamNestedRef("secretName", "mixin.secret.withSecretName")),
 			},
 			"io.k8s.kubernetes.pkg.api.v1.VolumeMount": []CustomConstructorSpec{
 				newConstructor("new", newParam("name"), newParam("mountPath"), newParamWithDefault("readOnly", "false")),
 			},
-			"io.k8s.kubernetes.pkg.apis.apps.v1beta1.Deployment": []CustomConstructorSpec{
-				newConstructor(
-					"new",
-					newParamNestedRef("name", "mixin.metadata.name"),
-					newParamNestedRef("replicas", "mixin.spec.replicas"),
-					newParamNestedRef("containers", "mixin.spec.template.spec.containers"),
-					newParamNestedRefDefault("podLabels", "mixin.spec.template.metadata.labels", "{}")),
-			},
-			"io.k8s.kubernetes.pkg.apis.extensions.v1beta1.Deployment": []CustomConstructorSpec{
-				newConstructor(
-					"new",
-					newParamNestedRef("name", "mixin.metadata.name"),
-					newParamNestedRef("replicas", "mixin.spec.replicas"),
-					newParamNestedRef("containers", "mixin.spec.template.spec.containers"),
-					newParamNestedRefDefault("podLabels", "mixin.spec.template.metadata.labels", "{}")),
-			},
 		},
+
 		propertyBlacklist: map[string]propertySet{
 			// Metadata fields.
 			"io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta": newPropertySet(
@@ -336,3 +429,46 @@ k8s + {
 `,
 	},
 }
+
+//-----------------------------------------------------------------------------
+// Utility specs, for duplicated objects.
+//-----------------------------------------------------------------------------
+
+var objectList = []CustomConstructorSpec{
+	newConstructor(
+		"new",
+		newParam("items")),
+}
+var v1beta1Deployment = []CustomConstructorSpec{
+	newConstructor(
+		"new",
+		newParamNestedRef("name", "mixin.metadata.withName"),
+		newParamNestedRef("replicas", "mixin.spec.withReplicas"),
+		newParamNestedRef("containers", "mixin.spec.template.spec.withContainers"),
+		newParamNestedRefDefault(
+			"podLabels",
+			"mixin.spec.template.metadata.withLabels",
+			"{app: name}")),
+}
+var v1beta1DeploymentRollback = []CustomConstructorSpec{
+	newConstructor(
+		"new",
+		newParam("name")),
+}
+var v1beta1Scale = []CustomConstructorSpec{
+	newConstructor(
+		"new",
+		newParamNestedRef("replicas", "mixin.spec.withReplicas")),
+}
+var v1beta1StatefulSet = []CustomConstructorSpec{
+	newConstructor(
+		"new",
+		newParamNestedRef("name", "mixin.metadata.withName"),
+		newParamNestedRef("replicas", "mixin.spec.withReplicas"),
+		newParamNestedRef("containers", "mixin.spec.template.spec.withContainers"),
+		newParamNestedRef("volumeClaims", "mixin.spec.withVolumeClaimTemplates"),
+		newParamNestedRefDefault(
+			"podLabels",
+			"mixin.spec.template.metadata.withLabels",
+			"{app: name}")),
+}
diff --git a/vendor/vendor.json b/vendor/vendor.json
index d66167f0..a4ee18e6 100644
--- a/vendor/vendor.json
+++ b/vendor/vendor.json
@@ -257,28 +257,28 @@
 			"revisionTime": "2017-03-14T01:17:55Z"
 		},
 		{
-			"checksumSHA1": "wX+GmcWpMzCIcxR9YtN1FCM9BEE=",
+			"checksumSHA1": "ia91LEEbuaR5os39J+5MzEi1xnY=",
 			"path": "github.com/ksonnet/ksonnet-lib/ksonnet-gen/jsonnet",
-			"revision": "b27d2d7778c12c3d762d24c1b9fd4c41da6c73c7",
-			"revisionTime": "2017-09-10T05:18:39Z"
+			"revision": "46d8bb9e605dc3d3977e2e2054e921ed32dd699f",
+			"revisionTime": "2017-11-21T00:39:10Z"
 		},
 		{
-			"checksumSHA1": "zJx/j+IS6qd0P5h2m8WEQEtrACU=",
+			"checksumSHA1": "ZQxcZOI8LKx+lAZ9MAW1yb579zo=",
 			"path": "github.com/ksonnet/ksonnet-lib/ksonnet-gen/ksonnet",
-			"revision": "b27d2d7778c12c3d762d24c1b9fd4c41da6c73c7",
-			"revisionTime": "2017-09-10T05:18:39Z"
+			"revision": "46d8bb9e605dc3d3977e2e2054e921ed32dd699f",
+			"revisionTime": "2017-11-21T00:39:10Z"
 		},
 		{
 			"checksumSHA1": "BiiHRiYpSOb+vHiP6h/A9lRotEY=",
 			"path": "github.com/ksonnet/ksonnet-lib/ksonnet-gen/kubespec",
-			"revision": "b27d2d7778c12c3d762d24c1b9fd4c41da6c73c7",
-			"revisionTime": "2017-09-10T05:18:39Z"
+			"revision": "46d8bb9e605dc3d3977e2e2054e921ed32dd699f",
+			"revisionTime": "2017-11-21T00:39:10Z"
 		},
 		{
-			"checksumSHA1": "lr+Bx7/N2KHk9dOrsWfLYBPjbdQ=",
+			"checksumSHA1": "hEIHBY6IrJscUYUlgFPCHuW4yBs=",
 			"path": "github.com/ksonnet/ksonnet-lib/ksonnet-gen/kubeversion",
-			"revision": "b27d2d7778c12c3d762d24c1b9fd4c41da6c73c7",
-			"revisionTime": "2017-09-10T05:18:39Z"
+			"revision": "46d8bb9e605dc3d3977e2e2054e921ed32dd699f",
+			"revisionTime": "2017-11-21T00:39:10Z"
 		},
 		{
 			"checksumSHA1": "T8soMJArSZrYnhmdpAnq1bVxQ6Q=",
-- 
GitLab