Skip to content
Snippets Groups Projects
Commit b68464fd authored by Alex Clemmer's avatar Alex Clemmer
Browse files

Update ksonnet-lib vendored dependency

parent 57079c8e
No related branches found
No related tags found
No related merge requests found
...@@ -35,6 +35,14 @@ type FuncParam string ...@@ -35,6 +35,14 @@ type FuncParam string
// Kubernetes version. For example, `fooAPI` becomes `fooApi`. // Kubernetes version. For example, `fooAPI` becomes `fooApi`.
type Identifier string 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 // RewriteAsFieldKey takes a `PropertyName` and converts it to a valid
// Jsonnet field name. For example, if the `PropertyName` has a value // Jsonnet field name. For example, if the `PropertyName` has a value
// of `"error"`, then this would generate an invalid object, `{error: // of `"error"`, then this would generate an invalid object, `{error:
......
...@@ -601,8 +601,10 @@ func (ao *apiObject) emitConstructor( ...@@ -601,8 +601,10 @@ func (ao *apiObject) emitConstructor(
"Attempted to create constructor, but property '%s' does not exist", "Attempted to create constructor, but property '%s' does not exist",
param.ID) param.ID)
} }
k8sVersion := ao.root().spec.Info.Version
propMethodName := jsonnet.RewriteAsIdentifier(k8sVersion, prop.name).ToSetterID()
setters = append( setters = append(
setters, fmt.Sprintf("self.%s(%s)", prop.name, param.ID)) setters, fmt.Sprintf("self.%s(%s)", propMethodName, param.ID))
} else { } else {
// TODO(hausdorff): We may want to verify this relative path // TODO(hausdorff): We may want to verify this relative path
// exists. // exists.
...@@ -788,10 +790,12 @@ func (p *property) emitHelper( ...@@ -788,10 +790,12 @@ func (p *property) emitHelper(
p.comments.emit(m) p.comments.emit(m)
k8sVersion := p.root().spec.Info.Version 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) paramName := jsonnet.RewriteAsFuncParam(k8sVersion, p.name)
fieldName := jsonnet.RewriteAsFieldKey(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) { if isMixinRef(p.ref) {
parsedRefPath := p.ref.Name().Parse() parsedRefPath := p.ref.Name().Parse()
...@@ -804,21 +808,41 @@ func (p *property) emitHelper( ...@@ -804,21 +808,41 @@ func (p *property) emitHelper(
} else { } else {
body = fmt.Sprintf("%s({%s: %s})", *parentMixinName, fieldName, paramName) 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) m.writeLine(line)
} else if p.schemaType != nil { } else if p.schemaType != nil {
paramType := *p.schemaType 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 { switch paramType {
case "array": case "array":
emitMixin = true
if parentMixinName == nil { 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]}", "if std.type(%s) == \"array\" then {%s+: %s} else {%s+: [%s]}",
paramName, fieldName, paramName, fieldName, paramName, paramName, fieldName, paramName, fieldName, paramName,
) )
} else { } 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]})", "if std.type(%s) == \"array\" then %s({%s+: %s}) else %s({%s+: [%s]})",
paramName, *parentMixinName, fieldName, paramName, *parentMixinName, paramName, *parentMixinName, fieldName, paramName, *parentMixinName,
fieldName, paramName, fieldName, paramName,
...@@ -826,22 +850,35 @@ func (p *property) emitHelper( ...@@ -826,22 +850,35 @@ func (p *property) emitHelper(
} }
case "integer", "string", "boolean": case "integer", "string", "boolean":
if parentMixinName == nil { if parentMixinName == nil {
body = fmt.Sprintf("{%s: %s}", fieldName, paramName) setterBody = fmt.Sprintf("{%s: %s}", fieldName, paramName)
} else { } else {
body = fmt.Sprintf("%s({%s: %s})", *parentMixinName, fieldName, paramName) setterBody = fmt.Sprintf("%s({%s: %s})", *parentMixinName, fieldName, paramName)
} }
case "object": case "object":
emitMixin = true
if parentMixinName == nil { 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 { } 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: default:
log.Panicf("Unrecognized type '%s'", paramType) 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) m.writeLine(line)
if emitMixin {
p.comments.emit(m)
line = fmt.Sprintf("%s self + %s,", mixinSignature, mixinBody)
m.writeLine(line)
}
} else { } else {
log.Panicf("Neither a type nor a ref") log.Panicf("Neither a type nor a ref")
} }
......
...@@ -72,6 +72,74 @@ var versions = map[string]versionData{ ...@@ -72,6 +72,74 @@ var versions = map[string]versionData{
"local": "localStorage", "local": "localStorage",
}, },
constructorSpecs: map[string][]CustomConstructorSpec{ 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{ "io.k8s.kubernetes.pkg.api.v1.Container": []CustomConstructorSpec{
newConstructor("new", newParam("name"), newParam("image")), newConstructor("new", newParam("name"), newParam("image")),
}, },
...@@ -79,28 +147,64 @@ var versions = map[string]versionData{ ...@@ -79,28 +147,64 @@ var versions = map[string]versionData{
newConstructor("new", newParam("containerPort")), newConstructor("new", newParam("containerPort")),
newConstructor("newNamed", newParam("name"), newParam("containerPort")), newConstructor("newNamed", newParam("name"), newParam("containerPort")),
}, },
"io.k8s.kubernetes.pkg.api.v1.EndpointsList": objectList,
"io.k8s.kubernetes.pkg.api.v1.EnvVar": []CustomConstructorSpec{ "io.k8s.kubernetes.pkg.api.v1.EnvVar": []CustomConstructorSpec{
newConstructor("new", newParam("name"), newParam("value")), newConstructor("new", newParam("name"), newParam("value")),
newConstructor( newConstructor(
"fromSecretRef", "fromSecretRef",
newParam("name"), newParam("name"),
newParamNestedRef("secretRefName", "mixin.valueFrom.secretKeyRef.name"), newParamNestedRef("secretRefName", "mixin.valueFrom.secretKeyRef.withName"),
newParamNestedRef("secretRefKey", "mixin.valueFrom.secretKeyRef.key")), newParamNestedRef("secretRefKey", "mixin.valueFrom.secretKeyRef.withKey")),
newConstructor( newConstructor(
"fromFieldPath", "fromFieldPath",
newParam("name"), 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{ "io.k8s.kubernetes.pkg.api.v1.KeyToPath": []CustomConstructorSpec{
newConstructor("new", newParam("key"), newParam("path")), 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{ "io.k8s.kubernetes.pkg.api.v1.Service": []CustomConstructorSpec{
newConstructor( newConstructor(
"new", "new",
newParamNestedRef("name", "mixin.metadata.name"), newParamNestedRef("name", "mixin.metadata.withName"),
newParamNestedRef("selector", "mixin.spec.selector"), newParamNestedRef("selector", "mixin.spec.withSelector"),
newParamNestedRef("ports", "mixin.spec.ports")), 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{ "io.k8s.kubernetes.pkg.api.v1.ServicePort": []CustomConstructorSpec{
newConstructor("new", newParam("port"), newParam("targetPort")), newConstructor("new", newParam("port"), newParam("targetPort")),
newConstructor("newNamed", newParam("name"), newParam("port"), newParam("targetPort")), newConstructor("newNamed", newParam("name"), newParam("port"), newParam("targetPort")),
...@@ -109,8 +213,8 @@ var versions = map[string]versionData{ ...@@ -109,8 +213,8 @@ var versions = map[string]versionData{
newConstructor( newConstructor(
"fromConfigMap", "fromConfigMap",
newParam("name"), newParam("name"),
newParamNestedRef("configMapName", "mixin.configMap.name"), newParamNestedRef("configMapName", "mixin.configMap.withName"),
newParamNestedRef("configMapItems", "mixin.configMap.items")), newParamNestedRef("configMapItems", "mixin.configMap.withItems")),
newConstructor( newConstructor(
"fromEmptyDir", "fromEmptyDir",
newParam("name"), newParam("name"),
...@@ -118,32 +222,21 @@ var versions = map[string]versionData{ ...@@ -118,32 +222,21 @@ var versions = map[string]versionData{
newConstructor( newConstructor(
"fromPersistentVolumeClaim", "fromPersistentVolumeClaim",
newParam("name"), newParam("name"),
newParamNestedRef("claimName", "mixin.persistentVolumeClaim.claimName")), newParamNestedRef("claimName", "mixin.persistentVolumeClaim.withClaimName")),
newConstructor( newConstructor(
"fromHostPath", "fromHostPath",
newParam("name"), 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{ "io.k8s.kubernetes.pkg.api.v1.VolumeMount": []CustomConstructorSpec{
newConstructor("new", newParam("name"), newParam("mountPath"), newParamWithDefault("readOnly", "false")), 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{ propertyBlacklist: map[string]propertySet{
// Metadata fields. // Metadata fields.
"io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta": newPropertySet( "io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta": newPropertySet(
...@@ -336,3 +429,46 @@ k8s + { ...@@ -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}")),
}
...@@ -257,28 +257,28 @@ ...@@ -257,28 +257,28 @@
"revisionTime": "2017-03-14T01:17:55Z" "revisionTime": "2017-03-14T01:17:55Z"
}, },
{ {
"checksumSHA1": "wX+GmcWpMzCIcxR9YtN1FCM9BEE=", "checksumSHA1": "ia91LEEbuaR5os39J+5MzEi1xnY=",
"path": "github.com/ksonnet/ksonnet-lib/ksonnet-gen/jsonnet", "path": "github.com/ksonnet/ksonnet-lib/ksonnet-gen/jsonnet",
"revision": "b27d2d7778c12c3d762d24c1b9fd4c41da6c73c7", "revision": "46d8bb9e605dc3d3977e2e2054e921ed32dd699f",
"revisionTime": "2017-09-10T05:18:39Z" "revisionTime": "2017-11-21T00:39:10Z"
}, },
{ {
"checksumSHA1": "zJx/j+IS6qd0P5h2m8WEQEtrACU=", "checksumSHA1": "ZQxcZOI8LKx+lAZ9MAW1yb579zo=",
"path": "github.com/ksonnet/ksonnet-lib/ksonnet-gen/ksonnet", "path": "github.com/ksonnet/ksonnet-lib/ksonnet-gen/ksonnet",
"revision": "b27d2d7778c12c3d762d24c1b9fd4c41da6c73c7", "revision": "46d8bb9e605dc3d3977e2e2054e921ed32dd699f",
"revisionTime": "2017-09-10T05:18:39Z" "revisionTime": "2017-11-21T00:39:10Z"
}, },
{ {
"checksumSHA1": "BiiHRiYpSOb+vHiP6h/A9lRotEY=", "checksumSHA1": "BiiHRiYpSOb+vHiP6h/A9lRotEY=",
"path": "github.com/ksonnet/ksonnet-lib/ksonnet-gen/kubespec", "path": "github.com/ksonnet/ksonnet-lib/ksonnet-gen/kubespec",
"revision": "b27d2d7778c12c3d762d24c1b9fd4c41da6c73c7", "revision": "46d8bb9e605dc3d3977e2e2054e921ed32dd699f",
"revisionTime": "2017-09-10T05:18:39Z" "revisionTime": "2017-11-21T00:39:10Z"
}, },
{ {
"checksumSHA1": "lr+Bx7/N2KHk9dOrsWfLYBPjbdQ=", "checksumSHA1": "hEIHBY6IrJscUYUlgFPCHuW4yBs=",
"path": "github.com/ksonnet/ksonnet-lib/ksonnet-gen/kubeversion", "path": "github.com/ksonnet/ksonnet-lib/ksonnet-gen/kubeversion",
"revision": "b27d2d7778c12c3d762d24c1b9fd4c41da6c73c7", "revision": "46d8bb9e605dc3d3977e2e2054e921ed32dd699f",
"revisionTime": "2017-09-10T05:18:39Z" "revisionTime": "2017-11-21T00:39:10Z"
}, },
{ {
"checksumSHA1": "T8soMJArSZrYnhmdpAnq1bVxQ6Q=", "checksumSHA1": "T8soMJArSZrYnhmdpAnq1bVxQ6Q=",
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment