Skip to content

Commit

Permalink
Update jsonnet autoformat script (#286)
Browse files Browse the repository at this point in the history
* Update jsonnet autoformat script

Enforce consistent string quote styling
and comment styling

* Autoformat jsonnet files using autoformat_jsonnet.sh
  • Loading branch information
Ankush Agarwal authored and jlewi committed Feb 26, 2018
1 parent 9960ba9 commit f9d9401
Show file tree
Hide file tree
Showing 21 changed files with 111 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local params = std.extVar("__ksonnet/params").components.workflows;

local k = import 'k.libsonnet';
local workflows = import 'workflows.libsonnet';
local k = import "k.libsonnet";
local workflows = import "workflows.libsonnet";
local namespace = params.namespace;
local serving_image = params.serving_image;
local testing_image = params.testing_image;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
{
name: "SERVING_IMAGE",
value: serving_image + ":" + name,
}
},
],
[{
name: "dind",
Expand Down
2 changes: 1 addition & 1 deletion kubeflow/argo/prototypes/argo.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// TODO(https://github.com/ksonnet/ksonnet/issues/222): We have to add namespace as an explicit parameter
// because ksonnet doesn't support inheriting it from the environment yet.

local k = import 'k.libsonnet';
local k = import "k.libsonnet";
local argo = import "kubeflow/argo/argo.libsonnet";

std.prune(k.core.v1.list.new(argo.parts(params.namespace).all))
12 changes: 6 additions & 6 deletions kubeflow/core/iap.libsonnet
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
parts(namespace):: {
local k = import 'k.libsonnet',
local k = import "k.libsonnet",

// We split the components into two protoypes.
// 1. Prototype contains the ingress and servcie
Expand Down Expand Up @@ -186,7 +186,7 @@
stat_prefix: "ingress_http",
access_log: [
{
format: "ACCESS [%START_TIME%] \"%REQ(:METHOD)% %REQ(X-ENVOY-ORIGINAL-PATH?:PATH)% %PROTOCOL%\" %RESPONSE_CODE% %RESPONSE_FLAGS% %BYTES_RECEIVED% %BYTES_SENT% %DURATION% %RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)% \"%REQ(X-FORWARDED-FOR)%\" \"%REQ(USER-AGENT)%\" \"%REQ(X-REQUEST-ID)%\" \"%REQ(:AUTHORITY)%\" \"%UPSTREAM_HOST%\"\n",
format: 'ACCESS [%START_TIME%] "%REQ(:METHOD)% %REQ(X-ENVOY-ORIGINAL-PATH?:PATH)% %PROTOCOL%" %RESPONSE_CODE% %RESPONSE_FLAGS% %BYTES_RECEIVED% %BYTES_SENT% %DURATION% %RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)% "%REQ(X-FORWARDED-FOR)%" "%REQ(USER-AGENT)%" "%REQ(X-REQUEST-ID)%" "%REQ(:AUTHORITY)%" "%UPSTREAM_HOST%"\n',
path: "/dev/fd/1",
},
],
Expand Down Expand Up @@ -393,7 +393,7 @@
stat_prefix: "ingress_http",
access_log: [
{
format: "ACCESS [%START_TIME%] \"%REQ(:METHOD)% %REQ(X-ENVOY-ORIGINAL-PATH?:PATH)% %PROTOCOL%\" %RESPONSE_CODE% %RESPONSE_FLAGS% %BYTES_RECEIVED% %BYTES_SENT% %DURATION% %RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)% \"%REQ(X-FORWARDED-FOR)%\" \"%REQ(USER-AGENT)%\" \"%REQ(X-REQUEST-ID)%\" \"%REQ(:AUTHORITY)%\" \"%UPSTREAM_HOST%\"\n",
format: 'ACCESS [%START_TIME%] "%REQ(:METHOD)% %REQ(X-ENVOY-ORIGINAL-PATH?:PATH)% %PROTOCOL%" %RESPONSE_CODE% %RESPONSE_FLAGS% %BYTES_RECEIVED% %BYTES_SENT% %DURATION% %RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)% "%REQ(X-FORWARDED-FOR)%" "%REQ(USER-AGENT)%" "%REQ(X-REQUEST-ID)%" "%REQ(:AUTHORITY)%" "%UPSTREAM_HOST%"\n',
path: "/dev/fd/1",
},
],
Expand Down Expand Up @@ -600,9 +600,9 @@
paths: [
{
backend: {
# Due to https://github.com/kubernetes/contrib/blob/master/ingress/controllers/gce/examples/health_checks/README.md#limitations
# Keep port the servicePort the same as the port we are targetting on the backend so that servicePort will be the same as targetPort for the purpose of
# health checking.
// Due to https://github.com/kubernetes/contrib/blob/master/ingress/controllers/gce/examples/health_checks/README.md#limitations
// Keep port the servicePort the same as the port we are targetting on the backend so that servicePort will be the same as targetPort for the purpose of
// health checking.
serviceName: "envoy",
servicePort: healthEnvoyPort,
},
Expand Down
8 changes: 4 additions & 4 deletions kubeflow/core/jupyterhub.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

authenticatorOptions:: {

### Authenticator Options
//## Authenticator Options
local kubeConfigDummyAuthenticator = "c.JupyterHub.authenticator_class = 'dummyauthenticator.DummyAuthenticator'",

# This configuration allows us to use the id provided by IAP.
// This configuration allows us to use the id provided by IAP.
local kubeConfigIAPAuthenticator = @"c.JupyterHub.authenticator_class ='jhub_remote_user_authenticator.remote_user_auth.RemoteUserAuthenticator'
c.RemoteUserAuthenticator.header_name = 'x-goog-authenticated-user-email'",

Expand All @@ -50,7 +50,7 @@ c.RemoteUserAuthenticator.header_name = 'x-goog-authenticated-user-email'",

local volumeMounts = std.map(function(v)
{
mountPath: '/mnt/' + v,
mountPath: "/mnt/" + v,
name: v,
}, volumeClaims),

Expand Down Expand Up @@ -96,7 +96,7 @@ c.RemoteUserAuthenticator.header_name = 'x-goog-authenticated-user-email'",

local volumeMounts = std.map(function(v)
{
mountPath: '/mnt/' + v,
mountPath: "/mnt/" + v,
name: v,
}, volumeClaims),

Expand Down
2 changes: 1 addition & 1 deletion kubeflow/core/prototypes/all.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// @optionalParam jupyterHubImage string gcr.io/kubeflow/jupyterhub-k8s:1.0.1 The image to use for JupyterHub.
// @optionalParam jupyterHubAuthenticator string null The authenticator to use

local k = import 'k.libsonnet';
local k = import "k.libsonnet";
local all = import "kubeflow/core/all.libsonnet";

std.prune(k.core.v1.list.new(all.parts(params).all))
14 changes: 7 additions & 7 deletions kubeflow/core/prototypes/iap-envoy.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
// TODO(https://github.com/ksonnet/ksonnet/issues/222): We have to add namespace as an explicit parameter
// because ksonnet doesn't support inheriting it from the environment yet.

local k = import 'k.libsonnet';
local k = import "k.libsonnet";
local iap = import "kubeflow/core/iap.libsonnet";
local util = import "kubeflow/core/util.libsonnet";

local name = import 'param://name';
local namespace = import 'param://namespace';
local name = import "param://name";
local namespace = import "param://namespace";

local envoyImage = import 'param://envoyImage';
local audiencesParam = import 'param://audiences';
local audiences = std.split(audiencesParam, ',');
local disableJwtCheckingParam = import 'param://disableJwtChecking';
local envoyImage = import "param://envoyImage";
local audiencesParam = import "param://audiences";
local audiences = std.split(audiencesParam, ",");
local disableJwtCheckingParam = import "param://disableJwtChecking";
local disableJwtChecking = util.toBool(disableJwtCheckingParam);

iap.parts(namespace).envoy(envoyImage, audiences, disableJwtChecking)
10 changes: 5 additions & 5 deletions kubeflow/core/prototypes/iap-ingress.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
// TODO(https://github.com/ksonnet/ksonnet/issues/222): We have to add namespace as an explicit parameter
// because ksonnet doesn't support inheriting it from the environment yet.

local k = import 'k.libsonnet';
local k = import "k.libsonnet";
local iap = import "kubeflow/core/iap.libsonnet";

local name = import 'param://name';
local namespace = import 'param://namespace';
local secretName = import 'param://secretName';
local ipName = import 'param://ipName';
local name = import "param://name";
local namespace = import "param://namespace";
local secretName = import "param://secretName";
local ipName = import "param://ipName";

iap.parts(namespace).ingressParts(secretName, ipName)
2 changes: 1 addition & 1 deletion kubeflow/core/tests/util_test.jsonnet
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local util = import '../util.libsonnet';
local util = import "../util.libsonnet";

std.assertEqual(util.upper("True"), "TRUE") &&
std.assertEqual(util.upper("TrUe"), "TRUE") &&
Expand Down
18 changes: 9 additions & 9 deletions kubeflow/seldon/core.libsonnet
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
local k = import 'k.libsonnet';
local k = import "k.libsonnet";
local deployment = k.extensions.v1beta1.deployment;
local container = k.apps.v1beta1.deployment.mixin.spec.template.spec.containersType;
local service = k.core.v1.service.mixin;
local serviceAccountMixin = k.core.v1.serviceAccount.mixin;
local clusterRoleBindingMixin = k.rbac.v1beta1.clusterRoleBinding.mixin;
local clusterRoleBinding = k.rbac.v1beta1.clusterRoleBinding;
local serviceAccount = k.core.v1.serviceAccount;
local baseApife = import 'json/apife-deployment.json';
local apifeService = import 'json/apife-service.json';
local operatorDeployment = import 'json/operator-deployment.json';
local redisDeployment = import 'json/redis-deployment.json';
local redisService = import 'json/redis-service.json';
local rbacServiceAccount = import 'json/rbac-service-account.json';
local rbacClusterRoleBinding = import 'json/rbac-cluster-binding.json';
local crdDefn = import 'crd.libsonnet';
local baseApife = import "json/apife-deployment.json";
local apifeService = import "json/apife-service.json";
local operatorDeployment = import "json/operator-deployment.json";
local redisDeployment = import "json/redis-deployment.json";
local redisService = import "json/redis-service.json";
local rbacServiceAccount = import "json/rbac-service-account.json";
local rbacClusterRoleBinding = import "json/rbac-cluster-binding.json";
local crdDefn = import "crd.libsonnet";

{
parts(namespace):: {
Expand Down
4 changes: 2 additions & 2 deletions kubeflow/seldon/crd.libsonnet
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local k = import 'k.libsonnet';
local podTemplateValidation = import 'json/pod-template-spec-validation.json';
local k = import "k.libsonnet";
local podTemplateValidation = import "json/pod-template-spec-validation.json";

{
crd()::
Expand Down
22 changes: 11 additions & 11 deletions kubeflow/seldon/prototypes/core.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@
// TODO(https://github.com/ksonnet/ksonnet/issues/222): We have to add namespace as an explicit parameter
// because ksonnet doesn't support inheriting it from the environment yet.

local k = import 'k.libsonnet';
local k = import "k.libsonnet";
local core = import "kubeflow/seldon/core.libsonnet";

local name = import 'param://name';
local namespace = import 'param://namespace';
local withRbac = import 'param://withRbac';
local withApife = import 'param://withApife';
local name = import "param://name";
local namespace = import "param://namespace";
local withRbac = import "param://withRbac";
local withApife = import "param://withApife";

// APIFE
local apifeImage = import 'param://apifeImage';
local apifeServiceType = import 'param://apifeServiceType';
local apifeImage = import "param://apifeImage";
local apifeServiceType = import "param://apifeServiceType";

// Cluster Manager (The CRD Operator)
local operatorImage = import 'param://operatorImage';
local operatorSpringOptsParam = import 'param://operatorSpringOpts';
local operatorImage = import "param://operatorImage";
local operatorSpringOptsParam = import "param://operatorSpringOpts";
local operatorSpringOpts = if operatorSpringOptsParam != "null" then operatorSpringOptsParam else "";
local operatorJavaOptsParam = import 'param://operatorJavaOpts';
local operatorJavaOptsParam = import "param://operatorJavaOpts";
local operatorJavaOpts = if operatorJavaOptsParam != "null" then operatorJavaOptsParam else "";

// Engine
local engineImage = import 'param://engineImage';
local engineImage = import "param://engineImage";

// APIFE
local apife = [
Expand Down
32 changes: 16 additions & 16 deletions kubeflow/tf-job/prototypes/tf-cnn-benchmarks.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
// TODO(https://github.com/ksonnet/ksonnet/issues/222): We have to add namespace as an explicit parameter
// because ksonnet doesn't support inheriting it from the environment yet.

local k = import 'k.libsonnet';
local k = import "k.libsonnet";
local deployment = k.extensions.v1beta1.deployment;
local container = deployment.mixin.spec.template.spec.containersType;
local podTemplate = k.extensions.v1beta1.podTemplate;

local tfJob = import 'kubeflow/tf-job/tf-job.libsonnet';
local tfJob = import "kubeflow/tf-job/tf-job.libsonnet";

local name = import 'param://name';
local namespace = import 'param://namespace';
local name = import "param://name";
local namespace = import "param://namespace";

local numGpus = import 'param://num_gpus';
local batchSize = import 'param://batch_size';
local model = import 'param://model';
local numGpus = import "param://num_gpus";
local batchSize = import "param://batch_size";
local model = import "param://model";

local args = [
"python",
Expand All @@ -42,10 +42,10 @@ local args = [
"--flush_stdout=true",
] +
if numGpus == 0 then
# We need to set num_gpus=1 even if not using GPUs because otherwise the devie list
# is empty because of this code
# https://github.com/tensorflow/benchmarks/blob/master/scripts/tf_cnn_benchmarks/benchmark_cnn.py#L775
# We won't actually use GPUs because based on other flags no ops will be assigned to GPus.
// We need to set num_gpus=1 even if not using GPUs because otherwise the devie list
// is empty because of this code
// https://github.com/tensorflow/benchmarks/blob/master/scripts/tf_cnn_benchmarks/benchmark_cnn.py#L775
// We won't actually use GPUs because based on other flags no ops will be assigned to GPus.
[
"--num_gpus=1",
"--local_parameter_device=cpu",
Expand All @@ -58,11 +58,11 @@ local args = [
]
;

local image = import 'param://image';
local imageGpu = import 'param://image_gpu';
local numPs = import 'param://num_ps';
local numWorkers = import 'param://num_workers';
local numGpus = import 'param://num_gpus';
local image = import "param://image";
local imageGpu = import "param://image_gpu";
local numPs = import "param://num_ps";
local numWorkers = import "param://num_workers";
local numGpus = import "param://num_gpus";

local workerSpec = if numGpus > 0 then
tfJob.parts.tfJobReplica("WORKER", numWorkers, args, imageGpu, numGpus)
Expand Down
26 changes: 13 additions & 13 deletions kubeflow/tf-job/prototypes/tf-job.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@
// TODO(https://github.com/ksonnet/ksonnet/issues/222): We have to add namespace as an explicit parameter
// because ksonnet doesn't support inheriting it from the environment yet.

local k = import 'k.libsonnet';
local tfJob = import 'kubeflow/tf-job/tf-job.libsonnet';
local k = import "k.libsonnet";
local tfJob = import "kubeflow/tf-job/tf-job.libsonnet";

local name = import 'param://name';
local namespace = import 'param://namespace';
local name = import "param://name";
local namespace = import "param://namespace";

local argsParam = import 'param://args';
local argsParam = import "param://args";
local args =
if argsParam == "null" then
[]
else
std.split(argsParam, ',');

local image = import 'param://image';
local imageGpu = import 'param://image_gpu';
local numMasters = import 'param://num_masters';
local numPs = import 'param://num_ps';
local numWorkers = import 'param://num_workers';
local numGpus = import 'param://num_gpus';
std.split(argsParam, ",");

local image = import "param://image";
local imageGpu = import "param://image_gpu";
local numMasters = import "param://num_masters";
local numPs = import "param://num_ps";
local numWorkers = import "param://num_workers";
local numGpus = import "param://num_gpus";

local workerSpec = if numGpus > 0 then
tfJob.parts.tfJobReplica("WORKER", numWorkers, args, imageGpu, numGpus)
Expand Down
2 changes: 1 addition & 1 deletion kubeflow/tf-job/tf-job.libsonnet
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local k = import 'k.libsonnet';
local k = import "k.libsonnet";

{
parts:: {
Expand Down
14 changes: 7 additions & 7 deletions kubeflow/tf-serving/prototypes/tf-serving-all-features.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
// TODO(https://github.com/ksonnet/ksonnet/issues/222): We have to add namespace as an explicit parameter
// because ksonnet doesn't support inheriting it from the environment yet.

local k = import 'k.libsonnet';
local tfServing = import 'kubeflow/tf-serving/tf-serving.libsonnet';
local k = import "k.libsonnet";
local tfServing = import "kubeflow/tf-serving/tf-serving.libsonnet";

local name = import 'param://name';
local namespace = import 'param://namespace';
local modelPath = import 'param://model_path';
local modelServerImage = import 'param://model_server_image';
local httpProxyImage = import 'param://http_proxy_image';
local name = import "param://name";
local namespace = import "param://namespace";
local modelPath = import "param://model_path";
local modelServerImage = import "param://model_server_image";
local httpProxyImage = import "param://http_proxy_image";

std.prune(k.core.v1.list.new([
tfServing.parts.deployment.modelServer(name, namespace, modelPath, modelServerImage, httpProxyImage),
Expand Down
2 changes: 1 addition & 1 deletion kubeflow/tf-serving/tf-serving.libsonnet
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local k = import 'k.libsonnet';
local k = import "k.libsonnet";
local deployment = k.extensions.v1beta1.deployment;
local container = deployment.mixin.spec.template.spec.containersType;
local storageClass = k.storage.v1beta1.storageClass;
Expand Down
11 changes: 9 additions & 2 deletions scripts/autoformat_jsonnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@
# Script to autoformat libsonnet files.
# Assumes jsonnet is on the path.
set -ex
find ./ -name "*.libsonnet" -exec jsonnet fmt {} -i --indent 2 ";"
find ./ -name "*.jsonnet" -exec jsonnet fmt {} -i --indent 2 ";"

# 2 spaces vertical indentation
# Use double quotes for strings
# Use // for comments
find -E $(pwd) -iregex ".*\.(libsonnet|jsonnet)$" -exec \
jsonnet fmt {} -i \
--string-style d \
--comment-style s \
--indent 2 ";"
4 changes: 2 additions & 2 deletions testing/workflows/components/workflows.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local params = std.extVar("__ksonnet/params").components.workflows;

local k = import 'k.libsonnet';
local workflows = import 'workflows.libsonnet';
local k = import "k.libsonnet";
local workflows = import "workflows.libsonnet";
local namespace = params.namespace;

// TODO(jlewi): Can we make name default so some random unique value?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ c.KubeSpawner.pvc_name_template = 'claim-{username}{servername}'

local volumeMounts = std.map(function(v)
{
mountPath: '/mnt/' + v,
mountPath: "/mnt/" + v,
name: v,
}, volumeClaims),

Expand Down

0 comments on commit f9d9401

Please sign in to comment.