├── .gitignore ├── 1.13 ├── _hidden.libsonnet ├── admissionregistration.libsonnet ├── apiextensions.libsonnet ├── apiregistration.libsonnet ├── apps.libsonnet ├── auditregistration.libsonnet ├── authentication.libsonnet ├── authorization.libsonnet ├── autoscaling.libsonnet ├── batch.libsonnet ├── certificates.libsonnet ├── coordination.libsonnet ├── core.libsonnet ├── events.libsonnet ├── extensions.libsonnet ├── k.libsonnet ├── k8s.libsonnet ├── meta.libsonnet ├── networking.libsonnet ├── policy.libsonnet ├── rbac.libsonnet ├── scheduling.libsonnet ├── settings.libsonnet └── storage.libsonnet ├── 1.14 ├── _hidden.libsonnet ├── admissionregistration.libsonnet ├── apiextensions.libsonnet ├── apiregistration.libsonnet ├── apps.libsonnet ├── auditregistration.libsonnet ├── authentication.libsonnet ├── authorization.libsonnet ├── autoscaling.libsonnet ├── batch.libsonnet ├── certificates.libsonnet ├── coordination.libsonnet ├── core.libsonnet ├── events.libsonnet ├── extensions.libsonnet ├── k.libsonnet ├── k8s.libsonnet ├── meta.libsonnet ├── networking.libsonnet ├── node.libsonnet ├── policy.libsonnet ├── rbac.libsonnet ├── scheduling.libsonnet ├── settings.libsonnet └── storage.libsonnet ├── 1.15 ├── _hidden.libsonnet ├── admissionregistration.libsonnet ├── apiextensions.libsonnet ├── apiregistration.libsonnet ├── apps.libsonnet ├── auditregistration.libsonnet ├── authentication.libsonnet ├── authorization.libsonnet ├── autoscaling.libsonnet ├── batch.libsonnet ├── certificates.libsonnet ├── coordination.libsonnet ├── core.libsonnet ├── events.libsonnet ├── extensions.libsonnet ├── k.libsonnet ├── k8s.libsonnet ├── meta.libsonnet ├── networking.libsonnet ├── node.libsonnet ├── policy.libsonnet ├── rbac.libsonnet ├── scheduling.libsonnet ├── settings.libsonnet └── storage.libsonnet ├── 1.16 ├── _hidden.libsonnet ├── admissionregistration.libsonnet ├── apiextensions.libsonnet ├── apiregistration.libsonnet ├── apps.libsonnet ├── auditregistration.libsonnet ├── authentication.libsonnet ├── authorization.libsonnet ├── autoscaling.libsonnet ├── batch.libsonnet ├── certificates.libsonnet ├── coordination.libsonnet ├── core.libsonnet ├── discovery.libsonnet ├── events.libsonnet ├── extensions.libsonnet ├── k.libsonnet ├── k8s.libsonnet ├── meta.libsonnet ├── networking.libsonnet ├── node.libsonnet ├── policy.libsonnet ├── rbac.libsonnet ├── scheduling.libsonnet ├── settings.libsonnet └── storage.libsonnet ├── 1.17 ├── _hidden.libsonnet ├── admissionregistration.libsonnet ├── apiextensions.libsonnet ├── apiregistration.libsonnet ├── apps.libsonnet ├── auditregistration.libsonnet ├── authentication.libsonnet ├── authorization.libsonnet ├── autoscaling.libsonnet ├── batch.libsonnet ├── certificates.libsonnet ├── coordination.libsonnet ├── core.libsonnet ├── discovery.libsonnet ├── events.libsonnet ├── extensions.libsonnet ├── flowcontrol.libsonnet ├── k.libsonnet ├── k8s.libsonnet ├── meta.libsonnet ├── networking.libsonnet ├── node.libsonnet ├── policy.libsonnet ├── rbac.libsonnet ├── scheduling.libsonnet ├── settings.libsonnet └── storage.libsonnet ├── 1.18 ├── _hidden.libsonnet ├── admissionregistration.libsonnet ├── apiextensions.libsonnet ├── apiregistration.libsonnet ├── apps.libsonnet ├── auditregistration.libsonnet ├── authentication.libsonnet ├── authorization.libsonnet ├── autoscaling.libsonnet ├── batch.libsonnet ├── certificates.libsonnet ├── coordination.libsonnet ├── core.libsonnet ├── discovery.libsonnet ├── events.libsonnet ├── extensions.libsonnet ├── flowcontrol.libsonnet ├── k.libsonnet ├── k8s.libsonnet ├── meta.libsonnet ├── networking.libsonnet ├── node.libsonnet ├── policy.libsonnet ├── rbac.libsonnet ├── scheduling.libsonnet ├── settings.libsonnet └── storage.libsonnet ├── CODE-OF-CONDUCT.md ├── LICENSE ├── Makefile ├── README.md ├── gen.go ├── gen ├── README.md ├── astext │ ├── astext.go │ ├── astext_test.go │ └── extensions.go ├── ksonnet │ ├── api_object.go │ ├── api_object_test.go │ ├── catalog.go │ ├── catalog_test.go │ ├── component.go │ ├── component_test.go │ ├── constructors.go │ ├── constructors_test.go │ ├── custom_constructor.go │ ├── description.go │ ├── description_test.go │ ├── document.go │ ├── document_integration_test.go │ ├── document_test.go │ ├── extension.go │ ├── extension_test.go │ ├── field.go │ ├── field_test.go │ ├── group.go │ ├── group_test.go │ ├── ksonnet.go │ ├── object.go │ ├── object_test.go │ ├── paths.go │ ├── paths_test.go │ ├── properties.go │ ├── properties_test.go │ ├── renderer.go │ ├── renderer_test.go │ ├── strings.go │ ├── strings_test.go │ ├── testdata │ │ ├── component.json │ │ ├── component.libsonnet │ │ ├── constructor.libsonnet │ │ ├── generated_k.libsonnet │ │ ├── invalid_definition.json │ │ ├── invalid_ref.json │ │ ├── k.libsonnet │ │ └── swagger-1.8.json │ ├── type.go │ ├── type_test.go │ ├── util.go │ ├── version.go │ └── version_test.go ├── kubespec │ ├── importer.go │ ├── importer_test.go │ ├── new.go │ ├── parsing.go │ ├── parsing_test.go │ ├── swagger.go │ └── testdata │ │ ├── deployment.json │ │ └── invalid.json ├── log │ └── log.go ├── main.go ├── nodemaker │ ├── nodemaker.go │ └── nodemaker_test.go └── printer │ ├── doc.go │ ├── printer.go │ ├── printer_test.go │ └── testdata │ ├── apply_brace │ ├── apply_with_index │ ├── apply_with_multiple_arguments │ ├── apply_with_number │ ├── array │ ├── array_comp │ ├── block_string │ ├── boolean │ ├── chained_apply │ ├── conditional │ ├── conditional_no_false │ ├── declarations │ ├── dollar │ ├── field_id_keywords │ ├── field_with_string_key │ ├── function │ ├── function_with_args │ ├── function_with_no_args │ ├── function_with_optional_args_ast │ ├── function_with_optional_args_astext │ ├── importstr │ ├── index │ ├── index_quote_name │ ├── index_quote_name_2 │ ├── index_with_index │ ├── literal │ ├── literal_with_newline │ ├── literal_with_single_quote │ ├── local │ ├── local_function_with_args │ ├── local_with_function │ ├── local_with_multiline_function │ ├── multi_line_comments │ ├── nil_node │ ├── null │ ├── object │ ├── object_comp │ ├── object_field_trailing_comma │ ├── object_field_with_comment │ ├── object_field_with_local │ ├── object_mixin │ ├── object_mixin_with_string_index │ ├── object_with_hidden_field │ ├── object_with_nested_object │ ├── self_apply │ ├── super_index │ ├── trimmed_whitespace_in_tests │ └── upstream │ ├── array.jsonnet │ ├── array_index1.jsonnet │ ├── array_index2.jsonnet │ ├── array_index3.jsonnet │ ├── array_index4.jsonnet │ ├── array_out_of_bounds.jsonnet │ ├── array_out_of_bounds2.jsonnet │ ├── array_out_of_bounds3.jsonnet │ ├── array_out_of_bounds4.jsonnet │ ├── array_plus_bad.jsonnet │ ├── arrcomp.jsonnet │ ├── arrcomp2.jsonnet │ ├── arrcomp3.jsonnet │ ├── arrcomp4.jsonnet │ ├── arrcomp5.jsonnet │ ├── arrcomp6.jsonnet │ ├── arrcomp7.jsonnet │ ├── arrcomp_if.jsonnet │ ├── arrcomp_if2.jsonnet │ ├── arrcomp_if3.jsonnet │ ├── arrcomp_if4.jsonnet │ ├── arrcomp_if5.jsonnet │ ├── arrcomp_if6.jsonnet │ ├── arrcomp_if7.jsonnet │ ├── assert.jsonnet │ ├── assert2.jsonnet │ ├── assert3.jsonnet │ ├── assert_equal.jsonnet │ ├── assert_equal2.jsonnet │ ├── assert_equal3.jsonnet │ ├── assert_failed.jsonnet │ ├── assert_failed_custom.jsonnet │ ├── binaryNot.jsonnet │ ├── binaryNot2.jsonnet │ ├── bitwise_and.jsonnet │ ├── bitwise_and2.jsonnet │ ├── bitwise_and3.jsonnet │ ├── bitwise_and4.jsonnet │ ├── bitwise_and5.jsonnet │ ├── bitwise_and6.jsonnet │ ├── bitwise_or.jsonnet │ ├── bitwise_or10.jsonnet │ ├── bitwise_or2.jsonnet │ ├── bitwise_or3.jsonnet │ ├── bitwise_or4.jsonnet │ ├── bitwise_or5.jsonnet │ ├── bitwise_or6.jsonnet │ ├── bitwise_or7.jsonnet │ ├── bitwise_or8.jsonnet │ ├── bitwise_or9.jsonnet │ ├── bitwise_shift.jsonnet │ ├── bitwise_shift2.jsonnet │ ├── bitwise_shift3.jsonnet │ ├── bitwise_shift4.jsonnet │ ├── bitwise_xor.jsonnet │ ├── bitwise_xor2.jsonnet │ ├── bitwise_xor3.jsonnet │ ├── bitwise_xor4.jsonnet │ ├── bitwise_xor5.jsonnet │ ├── bitwise_xor6.jsonnet │ ├── bitwise_xor7.jsonnet │ ├── bitwise_xor8.jsonnet │ ├── bitwise_xor9.jsonnet │ ├── boolean_literal.jsonnet │ ├── builtinChar.jsonnet │ ├── builtinChar2.jsonnet │ ├── builtinChar3.jsonnet │ ├── builtinChar4.jsonnet │ ├── builtinChar5.jsonnet │ ├── builtinChar6.jsonnet │ ├── builtinChar7.jsonnet │ ├── builtinObjectFieldsEx.jsonnet │ ├── builtinObjectFieldsExWithHidden.jsonnet │ ├── builtinObjectHasEx.jsonnet │ ├── builtin_acos.jsonnet │ ├── builtin_asin.jsonnet │ ├── builtin_atan.jsonnet │ ├── builtin_ceil.jsonnet │ ├── builtin_cos.jsonnet │ ├── builtin_exp.jsonnet │ ├── builtin_exp2.jsonnet │ ├── builtin_exp3.jsonnet │ ├── builtin_exp4.jsonnet │ ├── builtin_exp5.jsonnet │ ├── builtin_exp6.jsonnet │ ├── builtin_exp7.jsonnet │ ├── builtin_exp8.jsonnet │ ├── builtin_floor.jsonnet │ ├── builtin_log.jsonnet │ ├── builtin_log2.jsonnet │ ├── builtin_log3.jsonnet │ ├── builtin_log4.jsonnet │ ├── builtin_log5.jsonnet │ ├── builtin_log6.jsonnet │ ├── builtin_log7.jsonnet │ ├── builtin_log8.jsonnet │ ├── builtin_sin.jsonnet │ ├── builtin_sqrt.jsonnet │ ├── builtin_sqrt2.jsonnet │ ├── builtin_tan.jsonnet │ ├── div1.jsonnet │ ├── div2.jsonnet │ ├── div3.jsonnet │ ├── div4.jsonnet │ ├── empty_array.jsonnet │ ├── empty_object.jsonnet │ ├── equals.jsonnet │ ├── error.jsonnet │ ├── error_from_array.jsonnet │ ├── error_function_fail.jsonnet │ ├── escaped_fields.jsonnet │ ├── extvar_code.jsonnet │ ├── extvar_error.jsonnet │ ├── extvar_hermetic.jsonnet │ ├── extvar_mutually_recursive.jsonnet │ ├── extvar_not_a_string.jsonnet │ ├── extvar_self_recursive.jsonnet │ ├── extvar_static_error.jsonnet │ ├── extvar_string.jsonnet │ ├── extvar_unknown.jsonnet │ ├── function_call.jsonnet │ ├── function_capturing.jsonnet │ ├── function_in_object.jsonnet │ ├── function_manifested.jsonnet │ ├── function_no_params.jsonnet │ ├── function_plus_string.jsonnet │ ├── function_too_many_params.jsonnet │ ├── function_with_argument.jsonnet │ ├── greater.jsonnet │ ├── greaterEq.jsonnet │ ├── greaterEq2.jsonnet │ ├── holding │ ├── argcapture_builtin_call.jsonnet │ ├── assert_equal5.jsonnet │ ├── assert_equal6.jsonnet │ ├── call_number.jsonnet │ ├── double_thunk.jsonnet │ ├── escaped_single_quote.jsonnet │ ├── false.jsonnet │ ├── fieldname_not_string.jsonnet │ ├── filled_thunk.jsonnet │ ├── method_call.jsonnet │ ├── missing_super.jsonnet │ ├── nonexistent_import.jsonnet │ ├── nonexistent_import_crazy.jsonnet │ ├── proto_object_comp.jsonnet │ ├── self.jsonnet │ ├── stackbug-regression-test.jsonnet │ ├── static_error_eof.jsonnet │ ├── std.codepoint2.jsonnet │ ├── std.toString7.jsonnet │ ├── string2.jsonnet │ ├── too_many_arguments.jsonnet │ ├── unicode.jsonnet │ ├── unicode2.jsonnet │ ├── variable.jsonnet │ ├── variable_not_visible.jsonnet │ └── verbatim_string.jsonnet │ ├── ifthen_false.jsonnet │ ├── ifthenelse_false.jsonnet │ ├── ifthenelse_true.jsonnet │ ├── import.jsonnet │ ├── import2.jsonnet │ ├── import3.jsonnet │ ├── import4.jsonnet │ ├── import_various_literals.jsonnet │ ├── in.jsonnet │ ├── in2.jsonnet │ ├── in3.jsonnet │ ├── in4.jsonnet │ ├── insuper.jsonnet │ ├── insuper2.jsonnet │ ├── insuper4.jsonnet │ ├── lazy.jsonnet │ ├── lazy_operator1.jsonnet │ ├── lazy_operator2.jsonnet │ ├── less.jsonnet │ ├── lessEq.jsonnet │ ├── lessEq2.jsonnet │ ├── local1.jsonnet │ ├── local_within_nested_object.jsonnet │ ├── modulo.jsonnet │ ├── modulo2.jsonnet │ ├── modulo3.jsonnet │ ├── modulo4.jsonnet │ ├── modulo5.jsonnet │ ├── modulo6.jsonnet │ ├── modulo7.jsonnet │ ├── mult.jsonnet │ ├── mult2.jsonnet │ ├── mult3.jsonnet │ ├── native1.jsonnet │ ├── native2.jsonnet │ ├── native4.jsonnet │ ├── native5.jsonnet │ ├── native6.jsonnet │ ├── native7.jsonnet │ ├── native_error.jsonnet │ ├── native_nonexistent.jsonnet │ ├── number_divided_by_string.jsonnet │ ├── number_times_string.jsonnet │ ├── numeric_literal.jsonnet │ ├── object.jsonnet │ ├── object2.jsonnet │ ├── object3.jsonnet │ ├── object_comp.jsonnet │ ├── object_comp_binary.jsonnet │ ├── object_comp_dollar.jsonnet │ ├── object_comp_err_elem.jsonnet │ ├── object_comp_err_index.jsonnet │ ├── object_comp_if.jsonnet │ ├── object_comp_int_index.jsonnet │ ├── object_comp_local.jsonnet │ ├── object_comp_super.jsonnet │ ├── object_field1.jsonnet │ ├── object_hidden.jsonnet │ ├── object_local.jsonnet │ ├── object_local_self_super.jsonnet │ ├── object_plus_bad.jsonnet │ ├── object_sum.jsonnet │ ├── object_sum2.jsonnet │ ├── object_sum3.jsonnet │ ├── object_super.jsonnet │ ├── object_super_deep.jsonnet │ ├── object_super_within.jsonnet │ ├── optional_args.jsonnet │ ├── optional_args10.jsonnet │ ├── optional_args11.jsonnet │ ├── optional_args12.jsonnet │ ├── optional_args13.jsonnet │ ├── optional_args14.jsonnet │ ├── optional_args15.jsonnet │ ├── optional_args16.jsonnet │ ├── optional_args17.jsonnet │ ├── optional_args18.jsonnet │ ├── optional_args19.jsonnet │ ├── optional_args2.jsonnet │ ├── optional_args20.jsonnet │ ├── optional_args21.jsonnet │ ├── optional_args22.jsonnet │ ├── optional_args3.jsonnet │ ├── optional_args4.jsonnet │ ├── optional_args5.jsonnet │ ├── optional_args6.jsonnet │ ├── optional_args7.jsonnet │ ├── optional_args8.jsonnet │ ├── optional_args9.jsonnet │ ├── or.jsonnet │ ├── or2.jsonnet │ ├── or3.jsonnet │ ├── or4.jsonnet │ ├── or5.jsonnet │ ├── or6.jsonnet │ ├── percent_format_float.jsonnet │ ├── percent_format_str.jsonnet │ ├── percent_format_str2.jsonnet │ ├── percent_format_str3.jsonnet │ ├── percent_format_str4.jsonnet │ ├── percent_format_str5.jsonnet │ ├── percent_format_str6.jsonnet │ ├── percent_format_str7.jsonnet │ ├── percent_format_str8.jsonnet │ ├── percent_mod_int.jsonnet │ ├── percent_mod_int2.jsonnet │ ├── percent_mod_int3.jsonnet │ ├── percent_mod_int4.jsonnet │ ├── percent_mod_int5.jsonnet │ ├── percent_mod_int6.jsonnet │ ├── plus.jsonnet │ ├── plus2.jsonnet │ ├── plus3.jsonnet │ ├── plus4.jsonnet │ ├── plus5.jsonnet │ ├── plus6.jsonnet │ ├── plus7.jsonnet │ ├── plus9.jsonnet │ ├── pow.jsonnet │ ├── pow2.jsonnet │ ├── pow3.jsonnet │ ├── pow4.jsonnet │ ├── pow5.jsonnet │ ├── pow8.jsonnet │ ├── pow9.jsonnet │ ├── recursive_local.jsonnet │ ├── recursive_thunk.jsonnet │ ├── simple_arith1.jsonnet │ ├── simple_arith2.jsonnet │ ├── simple_arith3.jsonnet │ ├── simple_arith_string.jsonnet │ ├── simple_arith_string2.jsonnet │ ├── simple_arith_string3.jsonnet │ ├── simple_arith_string_empty.jsonnet │ ├── slice.jsonnet │ ├── slice3.jsonnet │ ├── slice4.jsonnet │ ├── slice5.jsonnet │ ├── slice7.jsonnet │ ├── std.codepoint.jsonnet │ ├── std.codepoint3.jsonnet │ ├── std.codepoint4.jsonnet │ ├── std.codepoint5.jsonnet │ ├── std.codepoint6.jsonnet │ ├── std.codepoint7.jsonnet │ ├── std.codepoint8.jsonnet │ ├── std.exponent.jsonnet │ ├── std.exponent2.jsonnet │ ├── std.exponent3.jsonnet │ ├── std.exponent4.jsonnet │ ├── std.exponent5.jsonnet │ ├── std.exponent6.jsonnet │ ├── std.exponent7.jsonnet │ ├── std.filter.jsonnet │ ├── std.filter2.jsonnet │ ├── std.filter3.jsonnet │ ├── std.filter4.jsonnet │ ├── std.filter5.jsonnet │ ├── std.filter6.jsonnet │ ├── std.filter7.jsonnet │ ├── std.filter8.jsonnet │ ├── std.filter_swapped_args.jsonnet │ ├── std.flatmap.jsonnet │ ├── std.flatmap2.jsonnet │ ├── std.flatmap3.jsonnet │ ├── std.flatmap4.jsonnet │ ├── std.flatmap5.jsonnet │ ├── std.join.jsonnet │ ├── std.join2.jsonnet │ ├── std.join3.jsonnet │ ├── std.join4.jsonnet │ ├── std.join5.jsonnet │ ├── std.join6.jsonnet │ ├── std.join7.jsonnet │ ├── std.join8.jsonnet │ ├── std.jsonnet │ ├── std.makeArray.jsonnet │ ├── std.makeArrayNamed.jsonnet │ ├── std.makeArrayNamed2.jsonnet │ ├── std.makeArrayNamed3.jsonnet │ ├── std.makeArrayNamed4.jsonnet │ ├── std.makeArray_bad.jsonnet │ ├── std.makeArray_bad2.jsonnet │ ├── std.makeArray_noninteger.jsonnet │ ├── std.makeArray_noninteger_big.jsonnet │ ├── std.makeArray_recursive.jsonnet │ ├── std.makeArray_recursive_evalutation_order_matters.jsonnet │ ├── std.mantissa.jsonnet │ ├── std.mantissa2.jsonnet │ ├── std.mantissa3.jsonnet │ ├── std.mantissa4.jsonnet │ ├── std.mantissa5.jsonnet │ ├── std.mantissa6.jsonnet │ ├── std.mantissa7.jsonnet │ ├── std.md5.jsonnet │ ├── std.md5_2.jsonnet │ ├── std.md5_3.jsonnet │ ├── std.md5_4.jsonnet │ ├── std.md5_5.jsonnet │ ├── std.md5_6.jsonnet │ ├── std.mod_int.jsonnet │ ├── std.mod_string.jsonnet │ ├── std.modulo.jsonnet │ ├── std.modulo2.jsonnet │ ├── std.modulo3.jsonnet │ ├── std.primitiveEquals.jsonnet │ ├── std.primitiveEquals10.jsonnet │ ├── std.primitiveEquals11.jsonnet │ ├── std.primitiveEquals12.jsonnet │ ├── std.primitiveEquals13.jsonnet │ ├── std.primitiveEquals14.jsonnet │ ├── std.primitiveEquals15.jsonnet │ ├── std.primitiveEquals16.jsonnet │ ├── std.primitiveEquals17.jsonnet │ ├── std.primitiveEquals18.jsonnet │ ├── std.primitiveEquals19.jsonnet │ ├── std.primitiveEquals2.jsonnet │ ├── std.primitiveEquals20.jsonnet │ ├── std.primitiveEquals21.jsonnet │ ├── std.primitiveEquals3.jsonnet │ ├── std.primitiveEquals4.jsonnet │ ├── std.primitiveEquals5.jsonnet │ ├── std.primitiveEquals6.jsonnet │ ├── std.primitiveEquals7.jsonnet │ ├── std.primitiveEquals8.jsonnet │ ├── std.primitiveEquals9.jsonnet │ ├── std.slice.jsonnet │ ├── std.thisFile.jsonnet │ ├── std.thisFile2.jsonnet │ ├── std.toString.jsonnet │ ├── std.toString2.jsonnet │ ├── std.toString3.jsonnet │ ├── std.toString4.jsonnet │ ├── std.toString5.jsonnet │ ├── std.toString6.jsonnet │ ├── std.toString8.jsonnet │ ├── std_in_local.jsonnet │ ├── std_substr.jsonnet │ ├── strReplace.jsonnet │ ├── strReplace2.jsonnet │ ├── strReplace3.jsonnet │ ├── string.jsonnet │ ├── string_comparison1.jsonnet │ ├── string_comparison2.jsonnet │ ├── string_comparison3.jsonnet │ ├── string_comparison4.jsonnet │ ├── string_comparison5.jsonnet │ ├── string_comparison6.jsonnet │ ├── string_comparison7.jsonnet │ ├── string_divided_by_number.jsonnet │ ├── string_index.jsonnet │ ├── string_index2.jsonnet │ ├── string_index_negative.jsonnet │ ├── string_index_out_of_bounds.jsonnet │ ├── string_minus_number.jsonnet │ ├── string_plus_function.jsonnet │ ├── string_times_number.jsonnet │ ├── string_to_bool.jsonnet │ ├── supersugar.jsonnet │ ├── supersugar2.jsonnet │ ├── supersugar3.jsonnet │ ├── supersugar5.jsonnet │ ├── supersugar6.jsonnet │ ├── supersugar7.jsonnet │ ├── supersugar8.jsonnet │ ├── tailstrict.jsonnet │ ├── tailstrict2.jsonnet │ ├── tailstrict3.jsonnet │ ├── tailstrict4.jsonnet │ ├── tailstrict5.jsonnet │ ├── true.jsonnet │ ├── type_array.jsonnet │ ├── type_builtin_function.jsonnet │ ├── type_error.jsonnet │ ├── type_function.jsonnet │ ├── type_number.jsonnet │ ├── type_object.jsonnet │ ├── type_string.jsonnet │ ├── unary_minus.jsonnet │ ├── unary_minus2.jsonnet │ ├── unary_minus3.jsonnet │ ├── unary_minus4.jsonnet │ └── use_object.jsonnet ├── go.mod ├── go.sum └── versions.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | 26 | # Output of the go coverage tool, specifically when used with LiteIDE 27 | *.out 28 | 29 | # External packages folder 30 | vendor/ 31 | tmp/ 32 | 33 | # Project-specific working space 34 | /charts/ 35 | 36 | #stray unwanted in fork 37 | .DS_Store 38 | 39 | /ksonnet-gen/ksonnet-gen 40 | 41 | .vscode 42 | -------------------------------------------------------------------------------- /1.13/k8s.libsonnet: -------------------------------------------------------------------------------- 1 | { 2 | __ksonnet: { 3 | "k8s.io": { 4 | checksum: '4f27287e82c6f4304dbf99f1c68dab12c1c5b540658296057d47aea068e1ccd9', 5 | generator: { 6 | vendor: 'github.com/kube-jsonnet/k', 7 | version: '21598b7-dirty', 8 | }, 9 | maintainer: 'kube-jsonnet', 10 | version: '1.13.0', 11 | }, 12 | }, 13 | _hidden:: (import '_hidden.libsonnet'), 14 | admissionregistration:: (import 'admissionregistration.libsonnet'), 15 | apiextensions:: (import 'apiextensions.libsonnet'), 16 | apiregistration:: (import 'apiregistration.libsonnet'), 17 | apps:: (import 'apps.libsonnet'), 18 | auditregistration:: (import 'auditregistration.libsonnet'), 19 | authentication:: (import 'authentication.libsonnet'), 20 | authorization:: (import 'authorization.libsonnet'), 21 | autoscaling:: (import 'autoscaling.libsonnet'), 22 | batch:: (import 'batch.libsonnet'), 23 | certificates:: (import 'certificates.libsonnet'), 24 | coordination:: (import 'coordination.libsonnet'), 25 | core:: (import 'core.libsonnet'), 26 | events:: (import 'events.libsonnet'), 27 | extensions:: (import 'extensions.libsonnet'), 28 | meta:: (import 'meta.libsonnet'), 29 | networking:: (import 'networking.libsonnet'), 30 | policy:: (import 'policy.libsonnet'), 31 | rbac:: (import 'rbac.libsonnet'), 32 | scheduling:: (import 'scheduling.libsonnet'), 33 | settings:: (import 'settings.libsonnet'), 34 | storage:: (import 'storage.libsonnet'), 35 | } -------------------------------------------------------------------------------- /1.13/meta.libsonnet: -------------------------------------------------------------------------------- 1 | { 2 | local hidden = (import '_hidden.libsonnet'), 3 | v1:: { 4 | local apiVersion = { apiVersion: 'storage.k8s.io/v1' }, 5 | // Patch is provided to give a concrete name and type to the Kubernetes PATCH request body. 6 | storageClass:: { 7 | local kind = { kind: 'StorageClass' }, 8 | new():: apiVersion + kind, 9 | mixin:: {}, 10 | }, 11 | }, 12 | } -------------------------------------------------------------------------------- /1.14/k8s.libsonnet: -------------------------------------------------------------------------------- 1 | { 2 | __ksonnet: { 3 | "k8s.io": { 4 | checksum: 'b923088253256b1ed1631fb8f32328d08984583a7f31c58c1a2d95926f71f204', 5 | generator: { 6 | vendor: 'github.com/kube-jsonnet/k', 7 | version: '21598b7-dirty', 8 | }, 9 | maintainer: 'kube-jsonnet', 10 | version: '1.14.0', 11 | }, 12 | }, 13 | _hidden:: (import '_hidden.libsonnet'), 14 | admissionregistration:: (import 'admissionregistration.libsonnet'), 15 | apiextensions:: (import 'apiextensions.libsonnet'), 16 | apiregistration:: (import 'apiregistration.libsonnet'), 17 | apps:: (import 'apps.libsonnet'), 18 | auditregistration:: (import 'auditregistration.libsonnet'), 19 | authentication:: (import 'authentication.libsonnet'), 20 | authorization:: (import 'authorization.libsonnet'), 21 | autoscaling:: (import 'autoscaling.libsonnet'), 22 | batch:: (import 'batch.libsonnet'), 23 | certificates:: (import 'certificates.libsonnet'), 24 | coordination:: (import 'coordination.libsonnet'), 25 | core:: (import 'core.libsonnet'), 26 | events:: (import 'events.libsonnet'), 27 | extensions:: (import 'extensions.libsonnet'), 28 | meta:: (import 'meta.libsonnet'), 29 | networking:: (import 'networking.libsonnet'), 30 | node:: (import 'node.libsonnet'), 31 | policy:: (import 'policy.libsonnet'), 32 | rbac:: (import 'rbac.libsonnet'), 33 | scheduling:: (import 'scheduling.libsonnet'), 34 | settings:: (import 'settings.libsonnet'), 35 | storage:: (import 'storage.libsonnet'), 36 | } -------------------------------------------------------------------------------- /1.14/meta.libsonnet: -------------------------------------------------------------------------------- 1 | { 2 | local hidden = (import '_hidden.libsonnet'), 3 | v1beta1:: { 4 | local apiVersion = { apiVersion: 'rbac.authorization.k8s.io/v1beta1' }, 5 | // Patch is provided to give a concrete name and type to the Kubernetes PATCH request body. 6 | clusterRole:: { 7 | local kind = { kind: 'ClusterRole' }, 8 | new():: apiVersion + kind, 9 | mixin:: {}, 10 | }, 11 | }, 12 | } -------------------------------------------------------------------------------- /1.15/k8s.libsonnet: -------------------------------------------------------------------------------- 1 | { 2 | __ksonnet: { 3 | "k8s.io": { 4 | checksum: '47a333fef11294e8bdfeca48a74e67fb438f3ffa427856d3c443d1af2cf77ad4', 5 | generator: { 6 | vendor: 'github.com/kube-jsonnet/k', 7 | version: '21598b7-dirty', 8 | }, 9 | maintainer: 'kube-jsonnet', 10 | version: '1.15.0', 11 | }, 12 | }, 13 | _hidden:: (import '_hidden.libsonnet'), 14 | admissionregistration:: (import 'admissionregistration.libsonnet'), 15 | apiextensions:: (import 'apiextensions.libsonnet'), 16 | apiregistration:: (import 'apiregistration.libsonnet'), 17 | apps:: (import 'apps.libsonnet'), 18 | auditregistration:: (import 'auditregistration.libsonnet'), 19 | authentication:: (import 'authentication.libsonnet'), 20 | authorization:: (import 'authorization.libsonnet'), 21 | autoscaling:: (import 'autoscaling.libsonnet'), 22 | batch:: (import 'batch.libsonnet'), 23 | certificates:: (import 'certificates.libsonnet'), 24 | coordination:: (import 'coordination.libsonnet'), 25 | core:: (import 'core.libsonnet'), 26 | events:: (import 'events.libsonnet'), 27 | extensions:: (import 'extensions.libsonnet'), 28 | meta:: (import 'meta.libsonnet'), 29 | networking:: (import 'networking.libsonnet'), 30 | node:: (import 'node.libsonnet'), 31 | policy:: (import 'policy.libsonnet'), 32 | rbac:: (import 'rbac.libsonnet'), 33 | scheduling:: (import 'scheduling.libsonnet'), 34 | settings:: (import 'settings.libsonnet'), 35 | storage:: (import 'storage.libsonnet'), 36 | } -------------------------------------------------------------------------------- /1.15/meta.libsonnet: -------------------------------------------------------------------------------- 1 | { 2 | local hidden = (import '_hidden.libsonnet'), 3 | v1beta1:: { 4 | local apiVersion = { apiVersion: 'batch/v1beta1' }, 5 | // Patch is provided to give a concrete name and type to the Kubernetes PATCH request body. 6 | cronJob:: { 7 | local kind = { kind: 'CronJob' }, 8 | new():: apiVersion + kind, 9 | mixin:: {}, 10 | }, 11 | }, 12 | } -------------------------------------------------------------------------------- /1.16/k8s.libsonnet: -------------------------------------------------------------------------------- 1 | { 2 | __ksonnet: { 3 | "k8s.io": { 4 | checksum: '83a26ef6141a68fb7dcb8a189c899aec55d71dbed6765b5e057cbba6e145301b', 5 | generator: { 6 | vendor: 'github.com/kube-jsonnet/k', 7 | version: '21598b7-dirty', 8 | }, 9 | maintainer: 'kube-jsonnet', 10 | version: '1.16.0', 11 | }, 12 | }, 13 | _hidden:: (import '_hidden.libsonnet'), 14 | admissionregistration:: (import 'admissionregistration.libsonnet'), 15 | apiextensions:: (import 'apiextensions.libsonnet'), 16 | apiregistration:: (import 'apiregistration.libsonnet'), 17 | apps:: (import 'apps.libsonnet'), 18 | auditregistration:: (import 'auditregistration.libsonnet'), 19 | authentication:: (import 'authentication.libsonnet'), 20 | authorization:: (import 'authorization.libsonnet'), 21 | autoscaling:: (import 'autoscaling.libsonnet'), 22 | batch:: (import 'batch.libsonnet'), 23 | certificates:: (import 'certificates.libsonnet'), 24 | coordination:: (import 'coordination.libsonnet'), 25 | core:: (import 'core.libsonnet'), 26 | discovery:: (import 'discovery.libsonnet'), 27 | events:: (import 'events.libsonnet'), 28 | extensions:: (import 'extensions.libsonnet'), 29 | meta:: (import 'meta.libsonnet'), 30 | networking:: (import 'networking.libsonnet'), 31 | node:: (import 'node.libsonnet'), 32 | policy:: (import 'policy.libsonnet'), 33 | rbac:: (import 'rbac.libsonnet'), 34 | scheduling:: (import 'scheduling.libsonnet'), 35 | settings:: (import 'settings.libsonnet'), 36 | storage:: (import 'storage.libsonnet'), 37 | } -------------------------------------------------------------------------------- /1.16/meta.libsonnet: -------------------------------------------------------------------------------- 1 | { 2 | local hidden = (import '_hidden.libsonnet'), 3 | v1:: { 4 | local apiVersion = { apiVersion: 'v1' }, 5 | // Patch is provided to give a concrete name and type to the Kubernetes PATCH request body. 6 | resourceQuota:: { 7 | local kind = { kind: 'ResourceQuota' }, 8 | new():: apiVersion + kind, 9 | mixin:: {}, 10 | }, 11 | }, 12 | } -------------------------------------------------------------------------------- /1.17/k8s.libsonnet: -------------------------------------------------------------------------------- 1 | { 2 | __ksonnet: { 3 | "k8s.io": { 4 | checksum: '135115c7795ce7e1eceeef34301a1f82fc9972314627261b90bf8913e26d92fa', 5 | generator: { 6 | vendor: 'github.com/kube-jsonnet/k', 7 | version: '21598b7-dirty', 8 | }, 9 | maintainer: 'kube-jsonnet', 10 | version: '1.17.0', 11 | }, 12 | }, 13 | _hidden:: (import '_hidden.libsonnet'), 14 | admissionregistration:: (import 'admissionregistration.libsonnet'), 15 | apiextensions:: (import 'apiextensions.libsonnet'), 16 | apiregistration:: (import 'apiregistration.libsonnet'), 17 | apps:: (import 'apps.libsonnet'), 18 | auditregistration:: (import 'auditregistration.libsonnet'), 19 | authentication:: (import 'authentication.libsonnet'), 20 | authorization:: (import 'authorization.libsonnet'), 21 | autoscaling:: (import 'autoscaling.libsonnet'), 22 | batch:: (import 'batch.libsonnet'), 23 | certificates:: (import 'certificates.libsonnet'), 24 | coordination:: (import 'coordination.libsonnet'), 25 | core:: (import 'core.libsonnet'), 26 | discovery:: (import 'discovery.libsonnet'), 27 | events:: (import 'events.libsonnet'), 28 | extensions:: (import 'extensions.libsonnet'), 29 | flowcontrol:: (import 'flowcontrol.libsonnet'), 30 | meta:: (import 'meta.libsonnet'), 31 | networking:: (import 'networking.libsonnet'), 32 | node:: (import 'node.libsonnet'), 33 | policy:: (import 'policy.libsonnet'), 34 | rbac:: (import 'rbac.libsonnet'), 35 | scheduling:: (import 'scheduling.libsonnet'), 36 | settings:: (import 'settings.libsonnet'), 37 | storage:: (import 'storage.libsonnet'), 38 | } -------------------------------------------------------------------------------- /1.17/meta.libsonnet: -------------------------------------------------------------------------------- 1 | { 2 | local hidden = (import '_hidden.libsonnet'), 3 | v1beta2:: { 4 | local apiVersion = { apiVersion: 'apps/v1beta2' }, 5 | // Patch is provided to give a concrete name and type to the Kubernetes PATCH request body. 6 | statefulSet:: { 7 | local kind = { kind: 'StatefulSet' }, 8 | new():: apiVersion + kind, 9 | mixin:: {}, 10 | }, 11 | }, 12 | } -------------------------------------------------------------------------------- /1.18/k.libsonnet: -------------------------------------------------------------------------------- 1 | local k8s = (import 'k8s.libsonnet'); 2 | local fn = { 3 | mapContainers(f):: { 4 | local podContainers = super.spec.template.spec.containers, 5 | spec+: { 6 | template+: { 7 | spec+: { 8 | containers: std.map(f, podContainers), 9 | }, 10 | }, 11 | }, 12 | }, 13 | mapContainersWithName(names, f):: 14 | local nameSet = if std.type(names) == 'array' then std.set(names) else std.set([names]); 15 | local inNameSet(name) = std.length(std.setInter(nameSet, std.set([name]))) > 0; 16 | 17 | self.mapContainers(function(c) if std.objectHas(c, 'name') && inNameSet(c.name) then f(c) else c), 18 | }; 19 | 20 | k8s + { 21 | apps:: k8s.apps + { 22 | v1:: k8s.apps.v1 + { 23 | daemonSet:: k8s.apps.v1.daemonSet + { 24 | mapContainers(f):: fn.mapContainers(f), 25 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 26 | }, 27 | deployment:: k8s.apps.v1.deployment + { 28 | mapContainers(f):: fn.mapContainers(f), 29 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 30 | }, 31 | replicaSet:: k8s.apps.v1.replicaSet + { 32 | mapContainers(f):: fn.mapContainers(f), 33 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 34 | }, 35 | statefulSet:: k8s.apps.v1.statefulSet + { 36 | mapContainers(f):: fn.mapContainers(f), 37 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 38 | }, 39 | }, 40 | }, 41 | batch:: k8s.batch + { 42 | v1:: k8s.batch.v1 + { 43 | job:: k8s.batch.v1.job + { 44 | mapContainers(f):: fn.mapContainers(f), 45 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 46 | }, 47 | }, 48 | v1beta1:: k8s.batch.v1beta1 + { 49 | cronJob:: k8s.batch.v1beta1.cronJob + { 50 | mapContainers(f):: fn.mapContainers(f), 51 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 52 | }, 53 | }, 54 | v2alpha1:: k8s.batch.v2alpha1 + { 55 | cronJob:: k8s.batch.v2alpha1.cronJob + { 56 | mapContainers(f):: fn.mapContainers(f), 57 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 58 | }, 59 | }, 60 | }, 61 | core:: k8s.core + { 62 | v1:: k8s.core.v1 + { 63 | list:: { 64 | new(items):: { 65 | apiVersion: 'v1', 66 | } + { 67 | kind: 'List', 68 | } + self.items(items), 69 | items(items):: if std.type(items) == 'array' then { items+: items } else { items+: [items] }, 70 | }, 71 | pod:: k8s.core.v1.pod + { 72 | mapContainers(f):: fn.mapContainers(f), 73 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 74 | }, 75 | podTemplate:: k8s.core.v1.podTemplate + { 76 | mapContainers(f):: fn.mapContainers(f), 77 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 78 | }, 79 | replicationController:: k8s.core.v1.replicationController + { 80 | mapContainers(f):: fn.mapContainers(f), 81 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 82 | }, 83 | }, 84 | }, 85 | } -------------------------------------------------------------------------------- /1.18/k8s.libsonnet: -------------------------------------------------------------------------------- 1 | { 2 | __ksonnet: { 3 | "k8s.io": { 4 | checksum: 'c16b4744603a5a9941c6c656ffea9abe857f6b39b02d8620504530b7906d7838', 5 | generator: { 6 | vendor: 'github.com/kube-jsonnet/k', 7 | version: '21598b7-dirty', 8 | }, 9 | maintainer: 'kube-jsonnet', 10 | version: '1.18.0', 11 | }, 12 | }, 13 | _hidden:: (import '_hidden.libsonnet'), 14 | admissionregistration:: (import 'admissionregistration.libsonnet'), 15 | apiextensions:: (import 'apiextensions.libsonnet'), 16 | apiregistration:: (import 'apiregistration.libsonnet'), 17 | apps:: (import 'apps.libsonnet'), 18 | auditregistration:: (import 'auditregistration.libsonnet'), 19 | authentication:: (import 'authentication.libsonnet'), 20 | authorization:: (import 'authorization.libsonnet'), 21 | autoscaling:: (import 'autoscaling.libsonnet'), 22 | batch:: (import 'batch.libsonnet'), 23 | certificates:: (import 'certificates.libsonnet'), 24 | coordination:: (import 'coordination.libsonnet'), 25 | core:: (import 'core.libsonnet'), 26 | discovery:: (import 'discovery.libsonnet'), 27 | events:: (import 'events.libsonnet'), 28 | extensions:: (import 'extensions.libsonnet'), 29 | flowcontrol:: (import 'flowcontrol.libsonnet'), 30 | meta:: (import 'meta.libsonnet'), 31 | networking:: (import 'networking.libsonnet'), 32 | node:: (import 'node.libsonnet'), 33 | policy:: (import 'policy.libsonnet'), 34 | rbac:: (import 'rbac.libsonnet'), 35 | scheduling:: (import 'scheduling.libsonnet'), 36 | settings:: (import 'settings.libsonnet'), 37 | storage:: (import 'storage.libsonnet'), 38 | } -------------------------------------------------------------------------------- /1.18/meta.libsonnet: -------------------------------------------------------------------------------- 1 | { 2 | local hidden = (import '_hidden.libsonnet'), 3 | v1:: { 4 | local apiVersion = { apiVersion: 'v1' }, 5 | // Patch is provided to give a concrete name and type to the Kubernetes PATCH request body. 6 | pod:: { 7 | local kind = { kind: 'Pod' }, 8 | new():: apiVersion + kind, 9 | mixin:: {}, 10 | }, 11 | }, 12 | } -------------------------------------------------------------------------------- /CODE-OF-CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## kube-jsonnet Community Code of Conduct 2 | 3 | kube-jsonnet follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md). 4 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .DEFAULT_GOAL: gen 2 | 3 | .PHONY: clean gen 4 | clean: 5 | rm -r 1.* || true 6 | 7 | gen: clean 8 | go run ./gen.go 9 | 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # !!! THIS REPOSITORY HAS BEEN DEPRECATED IN FAVOR OF [k8s-alpha](https://github.com/jsonnet-libs/k8s-alpha)!!! 2 | 3 | # `k.libsonnet`: The Kubernetes library for Jsonnet 4 | 5 | Generated from Kubernetes' `swagger.json`, this project provides an always 6 | up-to-date library for quick, flexible and concise creation of 7 | Kubernetes objects using Jsonnet. 8 | 9 | ## Install 10 | 11 | Use jsonnet-bundler to add this library to your `vendor/` folder: 12 | 13 | ```bash 14 | $ jb install github.com/kube-jsonnet/k/1.16 15 | ``` 16 | 17 | > You might need to pick another cluster version than `1.16`, use `kubectl version` to check that. 18 | 19 | ## Usage: 20 | 21 | ```jsonnet 22 | // import the library 23 | (import "github.com/kube-jsonnet/k/1.16/k.libsonnet") + 24 | { 25 | // create an example deployment 26 | deployment: $.apps.v1.deployment.new(name="grafana", replicas=1, containers=[ 27 | $.core.v1.container.new(name="grafana", image="grafana/grafana") 28 | ]) 29 | } 30 | ``` 31 | 32 | For more examples, check https://x.tanka.dev 33 | 34 | ## Versioning 35 | 36 | In the context of this project, there are two different versions: 37 | 38 | 1. **Kubernetes target**: Equals the Kubernetes version, the library is generated 39 | for. For each Kubernetes major release that is supported, a subdirectory 40 | exists in this repo, containing a matching library. 41 | 2. **Library version**: Independent from the targeted Kubernetes version, this 42 | repository is frequently released (`git tag`). This version resembles 43 | enhancements to the generator, etc. 44 | 45 | At any time, `master` can be considered stable, tags are just for historic reference. 46 | 47 | ### Support policy 48 | 49 | We support at least three major versions including the current one, perhaps more 50 | when reasonable. 51 | 52 | As soon as a version is not maintained anymore, its respective subdirectory is 53 | removed from the tree. If you still need it, consider using the previous tag of 54 | this project that still includes it. 55 | 56 | # License 57 | 58 | Licensed Apache 2.0, see [`LICENSE`](LICENSE). 59 | -------------------------------------------------------------------------------- /gen.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "fmt" 7 | "io/ioutil" 8 | "log" 9 | "os" 10 | "os/exec" 11 | "strings" 12 | ) 13 | 14 | const LDFLAGS = `-ldflags=-X main.Version=%s` 15 | 16 | func main() { 17 | log.SetFlags(0) 18 | 19 | data, err := ioutil.ReadFile("versions.json") 20 | if err != nil { 21 | log.Fatalln(err) 22 | } 23 | 24 | vs := make(map[string]string) 25 | json.Unmarshal(data, &vs) 26 | 27 | if err := sh("go", "build", "-o=kgen", fmt.Sprintf(LDFLAGS, version()), "./gen"); err != nil { 28 | log.Fatalln("Building generator") 29 | } 30 | defer os.Remove("kgen") 31 | 32 | for v, swag := range vs { 33 | log.Println(v) 34 | if err := sh("./kgen", "-version="+v, "-dir="+v, swag); err != nil { 35 | log.Fatalf("Generating %s: %v", v, err) 36 | } 37 | } 38 | } 39 | 40 | func sh(c string, args ...string) error { 41 | cmd := exec.Command(c, args...) 42 | cmd.Stdout = os.Stdout 43 | cmd.Stderr = os.Stderr 44 | 45 | return cmd.Run() 46 | } 47 | 48 | func version() string { 49 | cmd := exec.Command("git", "describe", "--tags", "--dirty", "--always") 50 | buf := bytes.Buffer{} 51 | cmd.Stdout = &buf 52 | cmd.Stderr = os.Stderr 53 | if err := cmd.Run(); err != nil { 54 | log.Fatalln(err) 55 | } 56 | 57 | return strings.TrimSuffix(buf.String(), "\n") 58 | } 59 | -------------------------------------------------------------------------------- /gen/README.md: -------------------------------------------------------------------------------- 1 | # `gen`: Library generator 2 | 3 | This folder contains the generator, responsible for transforming the 4 | `swagger.json` into the Jsonnet library. 5 | 6 | ## Building 7 | 8 | This project uses `go.mod`, so make sure to be outside of `$GOPATH`. 9 | 10 | ```bash 11 | $ go build . 12 | ``` 13 | 14 | ## Usage 15 | 16 | From the project root: 17 | 18 | ```bash 19 | $ go run ./gen -dir=1.14 https://raw.githubusercontent.com/kubernetes/kubernetes/release-1.14/api/openapi-spec/swagger.json 20 | ``` 21 | -------------------------------------------------------------------------------- /gen/astext/astext.go: -------------------------------------------------------------------------------- 1 | package astext 2 | 3 | import ( 4 | "regexp" 5 | 6 | "github.com/google/go-jsonnet/ast" 7 | "github.com/pkg/errors" 8 | ) 9 | 10 | // ObjectFields is a slice of ObjectField. 11 | type ObjectFields []ObjectField 12 | 13 | // ObjectField wraps ast.ObjectField and adds commenting and the ability to 14 | // be printed on one line. 15 | type ObjectField struct { 16 | ast.ObjectField 17 | 18 | // Comment is a comment for the object field. 19 | Comment *Comment 20 | 21 | // Oneline prints this field on a single line. 22 | Oneline bool 23 | } 24 | 25 | // Object wraps ast.Object and adds the ability to be printed on one line. 26 | type Object struct { 27 | ast.Object 28 | 29 | Fields []ObjectField 30 | 31 | // Oneline prints this field on a single line. 32 | Oneline bool 33 | } 34 | 35 | var ( 36 | // reFieldStr matches a field id that should be enclosed in quotes. 37 | reFieldStr = regexp.MustCompile(`^([_A-Za-z0-9\.]?[A-Za-z0-9\-_\.]+(\.[A-Za-z0-9\-_]+)*)?$`) 38 | // reField matches a field id. 39 | reField = regexp.MustCompile(`^[_A-Za-z]+[_A-Za-z0-9]*$`) 40 | ) 41 | 42 | // CreateField creates an ObjectField with a name. If the name matches `reFieldStr`, it will 43 | // create an ObjectField with Kind `ObjectFieldStr`. If not, it will create an identifier 44 | // and set the ObjectField kind to `ObjectFieldId`. 45 | func CreateField(name string) (*ObjectField, error) { 46 | of := ObjectField{ObjectField: ast.ObjectField{}} 47 | if reField.MatchString(name) { 48 | id := ast.Identifier(name) 49 | of.Kind = ast.ObjectFieldID 50 | of.Id = &id 51 | } else if reFieldStr.MatchString(name) { 52 | of.Expr1 = &ast.LiteralString{ 53 | Value: name, 54 | Kind: ast.StringDouble, 55 | } 56 | of.Kind = ast.ObjectFieldStr 57 | } else { 58 | return nil, errors.Errorf("invalid field name %q", name) 59 | } 60 | 61 | return &of, nil 62 | } 63 | -------------------------------------------------------------------------------- /gen/astext/astext_test.go: -------------------------------------------------------------------------------- 1 | package astext 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/google/go-jsonnet/ast" 7 | "github.com/stretchr/testify/require" 8 | ) 9 | 10 | func TestCreateField(t *testing.T) { 11 | id := ast.Identifier("name") 12 | uID := ast.Identifier("underscore_name") 13 | leadingID := ast.Identifier("__leading") 14 | 15 | cases := []struct { 16 | name string 17 | isErr bool 18 | expected *ObjectField 19 | }{ 20 | { 21 | name: "name", 22 | expected: &ObjectField{ 23 | ObjectField: ast.ObjectField{ 24 | Kind: ast.ObjectFieldID, Id: &id}}, 25 | }, 26 | { 27 | name: "underscore_name", 28 | expected: &ObjectField{ 29 | ObjectField: ast.ObjectField{ 30 | Kind: ast.ObjectFieldID, Id: &uID}}, 31 | }, 32 | { 33 | name: "underscore_field-", 34 | expected: &ObjectField{ 35 | ObjectField: ast.ObjectField{ 36 | Kind: ast.ObjectFieldStr, 37 | Expr1: &ast.LiteralString{ 38 | Value: "underscore_field-", 39 | Kind: ast.StringDouble, 40 | }}}, 41 | }, 42 | { 43 | name: "dashed-name", 44 | expected: &ObjectField{ 45 | ObjectField: ast.ObjectField{ 46 | Kind: ast.ObjectFieldStr, 47 | Expr1: &ast.LiteralString{ 48 | Value: "dashed-name", 49 | Kind: ast.StringDouble, 50 | }}}, 51 | }, 52 | { 53 | name: "__leading", 54 | expected: &ObjectField{ 55 | ObjectField: ast.ObjectField{ 56 | Kind: ast.ObjectFieldID, 57 | Id: &leadingID, 58 | }}, 59 | }, 60 | { 61 | name: "dot.name", 62 | expected: &ObjectField{ 63 | ObjectField: ast.ObjectField{ 64 | Kind: ast.ObjectFieldStr, 65 | Expr1: &ast.LiteralString{ 66 | Value: "dot.name", 67 | Kind: ast.StringDouble, 68 | }}}, 69 | }, 70 | { 71 | name: ".", 72 | expected: &ObjectField{ 73 | ObjectField: ast.ObjectField{ 74 | Kind: ast.ObjectFieldStr, 75 | Expr1: &ast.LiteralString{ 76 | Value: ".", 77 | Kind: ast.StringDouble, 78 | }}}, 79 | }, 80 | { 81 | name: "9p", 82 | expected: &ObjectField{ 83 | ObjectField: ast.ObjectField{ 84 | Kind: ast.ObjectFieldStr, 85 | Expr1: &ast.LiteralString{ 86 | Value: "9p", 87 | Kind: ast.StringDouble, 88 | }}}, 89 | }, 90 | { 91 | name: "invalid$", 92 | isErr: true, 93 | }, 94 | } 95 | 96 | for _, tc := range cases { 97 | t.Run(tc.name, func(t *testing.T) { 98 | got, err := CreateField(tc.name) 99 | if tc.isErr { 100 | require.Error(t, err) 101 | } else { 102 | require.NoError(t, err) 103 | require.Equal(t, tc.expected, got) 104 | } 105 | }) 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /gen/astext/extensions.go: -------------------------------------------------------------------------------- 1 | package astext 2 | 3 | // extensions for ast that could live upstream 4 | 5 | // Comment is a comment. 6 | type Comment struct { 7 | Text string // represents a single line comment 8 | } 9 | -------------------------------------------------------------------------------- /gen/ksonnet/api_object.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "github.com/pkg/errors" 5 | 6 | nm "github.com/kube-jsonnet/k/gen/nodemaker" 7 | ) 8 | 9 | // APIObject is an API object. 10 | type APIObject struct { 11 | resource Object 12 | renderFieldsFn renderFieldsFn 13 | } 14 | 15 | // NewAPIObject creates an instance of APIObject. 16 | func NewAPIObject(resource Object) *APIObject { 17 | ao := &APIObject{ 18 | resource: resource, 19 | renderFieldsFn: renderFields, 20 | } 21 | 22 | return ao 23 | } 24 | 25 | // Kind is the kind of api object this is. 26 | func (a *APIObject) Kind() string { 27 | return FormatKind(a.resource.Kind()) 28 | } 29 | 30 | // Description is the description of this API object. 31 | func (a *APIObject) Description() string { 32 | return a.resource.Description() 33 | } 34 | 35 | // Node returns an AST node for this api object. 36 | func (a *APIObject) Node(catalog *Catalog) (*nm.Object, error) { 37 | return apiObjectNode(catalog, a) 38 | } 39 | 40 | func (a *APIObject) initNode(catalog *Catalog) (*nm.Object, error) { 41 | o := nm.NewObject() 42 | 43 | if a.resource.IsType() { 44 | kindObject := nm.OnelineObject() 45 | kind := a.resource.Kind() 46 | kindObject.Set(nm.InheritedKey("kind"), nm.NewStringDouble(kind)) 47 | o.Set(nm.LocalKey("kind"), kindObject) 48 | 49 | ctorBase := []nm.Noder{ 50 | nm.NewVar("apiVersion"), 51 | nm.NewVar("kind"), 52 | } 53 | 54 | a.setConstructors(o, ctorBase, objectConstructor()) 55 | } else { 56 | a.setConstructors(o, nil, nm.OnelineObject()) 57 | } 58 | 59 | return o, nil 60 | } 61 | 62 | func (a *APIObject) setConstructors(parent *nm.Object, ctorBase []nm.Noder, defaultCtorBody nm.Noder) error { 63 | desc := makeDescriptor(a.resource.Codebase(), a.resource.Group(), a.resource.Kind()) 64 | ctors := locateConstructors(desc) 65 | 66 | if len(ctors) > 0 { 67 | for _, ctor := range ctors { 68 | key, err := ctor.Key() 69 | if err != nil { 70 | return errors.Wrap(err, "generate constructor key") 71 | } 72 | 73 | parent.Set(key, ctor.Body(ctorBase...)) 74 | } 75 | return nil 76 | } 77 | 78 | parent.Set(nm.FunctionKey("new", []string{}), defaultCtorBody) 79 | return nil 80 | 81 | } 82 | 83 | func objectConstructor() *nm.Binary { 84 | return nm.NewBinary(nm.NewVar("apiVersion"), nm.NewVar("kind"), nm.BopPlus) 85 | } 86 | 87 | func apiObjectNode(catalog *Catalog, a *APIObject) (*nm.Object, error) { 88 | if catalog == nil { 89 | return nil, errors.New("catalog is nil") 90 | } 91 | 92 | o, err := a.initNode(catalog) 93 | if err != nil { 94 | return nil, err 95 | } 96 | if err := a.renderFieldsFn(catalog, o, "", a.resource.Properties()); err != nil { 97 | return nil, err 98 | } 99 | return o, nil 100 | } 101 | -------------------------------------------------------------------------------- /gen/ksonnet/api_object_test.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/pkg/errors" 7 | "github.com/stretchr/testify/require" 8 | 9 | nm "github.com/kube-jsonnet/k/gen/nodemaker" 10 | ) 11 | 12 | func TestAPIObject_Kind(t *testing.T) { 13 | c1 := Component{Group: "group2", Version: "v1", Kind: "Deployment"} 14 | o1 := NewType("alpha", "desc", "codebase", "group", c1, nil) 15 | ao := NewAPIObject(&o1) 16 | 17 | require.Equal(t, "deployment", ao.Kind()) 18 | } 19 | 20 | func TestAPIObject_Description(t *testing.T) { 21 | c1 := Component{Group: "group2", Version: "v1", Kind: "Deployment"} 22 | o1 := NewType("alpha", "desc", "codebase", "group", c1, nil) 23 | ao := NewAPIObject(&o1) 24 | 25 | require.Equal(t, "desc", ao.Description()) 26 | } 27 | 28 | func TestAPIObject_Node_with_type(t *testing.T) { 29 | c := initCatalog(t, "swagger-1.8.json") 30 | 31 | t1 := NewField("io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta", "desc", "apimachinery", "group", "ver", "Kind", nil) 32 | ao := NewAPIObject(t1) 33 | 34 | n, err := ao.Node(c) 35 | require.NoError(t, err) 36 | 37 | _, ok := n.Get("kind").(*nm.Object) 38 | require.False(t, ok) 39 | 40 | require.NotNil(t, n.Get("new")) 41 | } 42 | 43 | func TestAPIObject_Node_with_field(t *testing.T) { 44 | c := initCatalog(t, "swagger-1.8.json") 45 | 46 | c1 := Component{Group: "group2", Version: "v1", Kind: "Deployment"} 47 | 48 | o1 := NewType("io.k8s.codebase.pkg.api.version.kind", "desc", "codebase", "group", c1, nil) 49 | ao := NewAPIObject(&o1) 50 | 51 | n, err := ao.Node(c) 52 | require.NoError(t, err) 53 | 54 | kindo, ok := n.Get("kind").(*nm.Object) 55 | require.True(t, ok) 56 | require.IsType(t, nm.NewObject(), kindo) 57 | 58 | kind, ok := kindo.Get("kind").(*nm.StringDouble) 59 | require.True(t, ok) 60 | require.Equal(t, nm.NewStringDouble("Deployment"), kind) 61 | 62 | require.NotNil(t, n.Get("new")) 63 | } 64 | 65 | func TestAPIObject_Node_with_nil_catalog(t *testing.T) { 66 | c1 := Component{Group: "group2", Version: "v1", Kind: "Deployment"} 67 | o1 := NewType("alpha", "desc", "codebase", "group", c1, nil) 68 | ao := NewAPIObject(&o1) 69 | 70 | _, err := ao.Node(nil) 71 | require.Error(t, err) 72 | } 73 | 74 | func TestAPIObject_Node_fails_when_renderer_fails(t *testing.T) { 75 | c := initCatalog(t, "swagger-1.8.json") 76 | 77 | c1 := Component{Group: "group2", Version: "v1", Kind: "Deployment"} 78 | o1 := NewType("alpha", "desc", "codebase", "group", c1, nil) 79 | ao := NewAPIObject(&o1) 80 | 81 | ao.renderFieldsFn = func(typeLookup, *nm.Object, string, map[string]Property) error { 82 | return errors.New("failed") 83 | } 84 | 85 | _, err := ao.Node(c) 86 | require.Error(t, err) 87 | } 88 | -------------------------------------------------------------------------------- /gen/ksonnet/component.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/go-openapi/spec" 7 | "github.com/pkg/errors" 8 | ) 9 | 10 | const ( 11 | extensionGroupVersionKind = "x-kubernetes-group-version-kind" 12 | ) 13 | 14 | // Component is resource information provided in the k8s swagger schema 15 | // which contains the group, kind, and version for a definition. 16 | type Component struct { 17 | Group string 18 | Kind string 19 | Version string 20 | } 21 | 22 | // NewComponent extracts component information from a schema. 23 | func NewComponent(s spec.Schema) (*Component, error) { 24 | re := componentExtractor{schema: s} 25 | group := re.extract("group") 26 | kind := re.extract("kind") 27 | version := re.extract("version") 28 | 29 | if re.err != nil { 30 | return nil, re.err 31 | } 32 | 33 | return &Component{ 34 | Group: group, 35 | Kind: kind, 36 | Version: version, 37 | }, nil 38 | } 39 | 40 | func (c *Component) String() string { 41 | group := c.Group 42 | if group == "" { 43 | group = "core" 44 | } 45 | 46 | return fmt.Sprintf("%s.%s.%s", group, c.Version, c.Kind) 47 | } 48 | 49 | type componentExtractor struct { 50 | err error 51 | schema spec.Schema 52 | } 53 | 54 | func (re *componentExtractor) extract(key string) string { 55 | if re.err != nil { 56 | return "" 57 | } 58 | 59 | i, ok := re.schema.Extensions[extensionGroupVersionKind] 60 | if !ok { 61 | re.err = errors.New("no group/kind/version extension") 62 | return "" 63 | } 64 | 65 | s, ok := i.([]interface{}) 66 | if ok { 67 | m, ok := s[0].(map[string]interface{}) 68 | if ok { 69 | str, ok := m[key].(string) 70 | if ok { 71 | return str 72 | } 73 | } 74 | } 75 | 76 | return "" 77 | } 78 | -------------------------------------------------------------------------------- /gen/ksonnet/component_test.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "path/filepath" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/require" 8 | 9 | "github.com/kube-jsonnet/k/gen/kubespec" 10 | ) 11 | 12 | func testdata(name string) string { 13 | return filepath.Join("testdata", name) 14 | } 15 | 16 | func TestComponent(t *testing.T) { 17 | cases := []struct { 18 | name string 19 | expected *Component 20 | isErr bool 21 | }{ 22 | { 23 | name: "io.k8s.api.apps.v1beta2.Deployment", 24 | expected: &Component{ 25 | Group: "apps", 26 | Version: "v1beta2", 27 | Kind: "Deployment", 28 | }, 29 | }, 30 | { 31 | name: "io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta", 32 | isErr: true, 33 | }, 34 | { 35 | name: "missing", 36 | isErr: true, 37 | }, 38 | } 39 | 40 | for _, tc := range cases { 41 | t.Run(tc.name, func(t *testing.T) { 42 | apiSpec, _, err := kubespec.Import(testdata("swagger-1.8.json")) 43 | require.NoError(t, err) 44 | 45 | schema := apiSpec.Definitions[tc.name] 46 | 47 | c, err := NewComponent(schema) 48 | if tc.isErr { 49 | require.Error(t, err) 50 | 51 | } else { 52 | require.NoError(t, err) 53 | require.Equal(t, tc.expected, c) 54 | } 55 | 56 | }) 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /gen/ksonnet/constructors.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "regexp" 5 | "sort" 6 | 7 | "github.com/google/go-jsonnet/ast" 8 | "github.com/pkg/errors" 9 | 10 | nm "github.com/kube-jsonnet/k/gen/nodemaker" 11 | ) 12 | 13 | var ( 14 | // reCtorSetter is a regex that matches function names. It'll successfully 15 | // match `withName`, `foo.withName`, and `foo.bar.withName`. 16 | reCtorSetter = regexp.MustCompile(`((^.*?)\.)*(with\w+|mixinInstance)$`) 17 | ) 18 | 19 | func matchCtorSetter(in string) (string, string, error) { 20 | match := reCtorSetter.FindAllStringSubmatch(in, -1) 21 | if len(match) == 0 { 22 | return "", "", errors.New("no match") 23 | } 24 | 25 | cur := match[0] 26 | if cur[1] == "" { 27 | return "self", cur[3], nil 28 | } 29 | 30 | return "self." + cur[2], cur[3], nil 31 | } 32 | 33 | type constructor struct { 34 | name string 35 | params []constructorParam 36 | } 37 | 38 | func newConstructor(name string, params ...constructorParam) *constructor { 39 | return &constructor{ 40 | name: name, 41 | params: params, 42 | } 43 | } 44 | 45 | // Key creates an object key for the constructor. 46 | func (c *constructor) Key() (nm.Key, error) { 47 | var args []nm.OptionalArg 48 | 49 | for _, param := range c.params { 50 | option, err := param.Option() 51 | if err != nil { 52 | return nm.Key{}, errors.Wrap(err, "unable to create key from param") 53 | } 54 | 55 | args = append(args, option) 56 | } 57 | 58 | key := nm.FunctionKey(c.name, []string{}, nm.KeyOptNamedParams(args...)) 59 | return key, nil 60 | } 61 | 62 | func (c *constructor) Body(baseNodes ...nm.Noder) nm.Noder { 63 | var items []nm.Noder 64 | for _, node := range baseNodes { 65 | items = append(items, node) 66 | } 67 | 68 | // collection functions so they can be de-duplicated. 69 | funs := make(map[string][]argRef) 70 | for _, param := range c.params { 71 | path, fn, err := matchCtorSetter(param.function) 72 | if err != nil { 73 | // TODO should we handle this error? 74 | continue 75 | } 76 | 77 | if _, ok := funs[path]; !ok { 78 | funs[path] = make([]argRef, 0) 79 | } 80 | 81 | funs[path] = append(funs[path], argRef{name: param.name, fn: fn}) 82 | } 83 | 84 | var funNames []string 85 | for funName := range funs { 86 | funNames = append(funNames, funName) 87 | } 88 | sort.Strings(funNames) 89 | 90 | for _, funName := range funNames { 91 | 92 | call := nm.NewCall(funName) 93 | 94 | var curApply *ctorApply 95 | var addedCall bool 96 | 97 | ars := funs[funName] 98 | sort.Slice(ars, func(i, j int) bool { 99 | return ars[i].fn < ars[j].fn 100 | }) 101 | 102 | for _, ar := range ars { 103 | indexID := ast.Identifier(ar.fn) 104 | index := &ast.Index{Id: &indexID} 105 | if !addedCall { 106 | index.Target = call.Node() 107 | addedCall = true 108 | } else { 109 | index.Target = curApply.Node() 110 | } 111 | 112 | arg := &ast.Var{Id: ast.Identifier(ar.name)} 113 | apply := ast.Apply{ 114 | Arguments: ast.Arguments{Positional: ast.Nodes{arg}}, 115 | Target: index, 116 | } 117 | 118 | curApply = &ctorApply{Apply: apply} 119 | } 120 | 121 | items = append(items, curApply) 122 | } 123 | 124 | return nm.Combine(items...) 125 | } 126 | 127 | type ctorApply struct { 128 | ast.Apply 129 | } 130 | 131 | func (ca *ctorApply) Node() ast.Node { 132 | return &ca.Apply 133 | } 134 | 135 | type argRef struct { 136 | name string 137 | fn string 138 | } 139 | 140 | type constructorParam struct { 141 | name string 142 | function string 143 | defaultValue interface{} 144 | } 145 | 146 | func newConstructorParam(name, function string, defaultValue interface{}) *constructorParam { 147 | if defaultValue == nil { 148 | defaultValue = "" 149 | } 150 | 151 | return &constructorParam{ 152 | name: name, 153 | function: function, 154 | defaultValue: defaultValue, 155 | } 156 | } 157 | 158 | func (cp *constructorParam) Option() (nm.OptionalArg, error) { 159 | var node nm.Noder 160 | 161 | var err error 162 | 163 | switch t := cp.defaultValue.(type) { 164 | case string: 165 | node = nm.NewStringDouble(t) 166 | case map[string]interface{}: 167 | node, err = nm.KVFromMap(t) 168 | if err != nil { 169 | return nm.OptionalArg{}, errors.Wrap(err, "invalid parameter") 170 | } 171 | case []string: 172 | var items []nm.Noder 173 | for _, item := range t { 174 | items = append(items, nm.NewStringDouble(item)) 175 | } 176 | node = nm.NewArray(items) 177 | case float64: 178 | node = nm.NewFloat(t) 179 | case int: 180 | node = nm.NewInt(t) 181 | case bool: 182 | node = nm.NewBoolean(t) 183 | default: 184 | return nm.OptionalArg{}, errors.Errorf("unable to use type %T in param", t) 185 | } 186 | 187 | return nm.OptionalArg{Name: cp.name, Default: node}, nil 188 | } 189 | -------------------------------------------------------------------------------- /gen/ksonnet/constructors_test.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "bytes" 5 | "io/ioutil" 6 | "strings" 7 | "testing" 8 | 9 | "github.com/stretchr/testify/assert" 10 | "github.com/stretchr/testify/require" 11 | 12 | nm "github.com/kube-jsonnet/k/gen/nodemaker" 13 | "github.com/kube-jsonnet/k/gen/printer" 14 | ) 15 | 16 | func Test_matchCtorSetter(t *testing.T) { 17 | cases := []struct { 18 | name string 19 | in string 20 | path string 21 | fn string 22 | isErr bool 23 | }{ 24 | { 25 | name: "with no path", 26 | in: "withName", 27 | fn: "withName", 28 | path: "self", 29 | }, 30 | { 31 | name: "with a path", 32 | in: "foo.bar.baz.withName", 33 | path: "self.foo.bar.baz", 34 | fn: "withName", 35 | }, 36 | { 37 | name: "unrecognized", 38 | in: "invalid", 39 | isErr: true, 40 | }, 41 | } 42 | 43 | for _, tc := range cases { 44 | t.Run(tc.name, func(t *testing.T) { 45 | path, fn, err := matchCtorSetter(tc.in) 46 | if tc.isErr { 47 | require.Error(t, err) 48 | } else { 49 | assert.Equal(t, tc.path, path) 50 | assert.Equal(t, tc.fn, fn) 51 | } 52 | }) 53 | } 54 | } 55 | 56 | func Test_constructor(t *testing.T) { 57 | obj := map[string]interface{}{ 58 | "key": "val", 59 | } 60 | 61 | array := []string{"val"} 62 | 63 | params := []constructorParam{ 64 | *newConstructorParam("name", "withName", nil), 65 | *newConstructorParam("nestedName", "foo.bar.baz.withName", nil), 66 | *newConstructorParam("nestedItem", "foo.bar.baz.withItem", nil), 67 | *newConstructorParam("str", "withStr", "val"), 68 | *newConstructorParam("obj", "withObj", obj), 69 | *newConstructorParam("array", "withArray", array), 70 | *newConstructorParam("other", "other.withArray", nil), 71 | *newConstructorParam("foo", "last.path.withFoo", nil), 72 | } 73 | 74 | c := newConstructor("new", params...) 75 | 76 | o := nm.NewObject() 77 | 78 | ctorBase := []nm.Noder{ 79 | nm.NewVar("apiVersion"), 80 | nm.NewVar("kind"), 81 | } 82 | 83 | key, err := c.Key() 84 | require.NoError(t, err) 85 | o.Set(key, c.Body(ctorBase...)) 86 | 87 | var buf bytes.Buffer 88 | err = printer.Fprint(&buf, o.Node()) 89 | require.NoError(t, err) 90 | 91 | testData, err := ioutil.ReadFile("testdata/constructor.libsonnet") 92 | require.NoError(t, err) 93 | 94 | got := strings.TrimSpace(buf.String()) 95 | expected := strings.TrimSpace(string(testData)) 96 | assert.Equal(t, expected, got) 97 | } 98 | 99 | func Test_constructorParam(t *testing.T) { 100 | obj, err := nm.KVFromMap(map[string]interface{}{"alpha": "beta"}) 101 | require.NoError(t, err) 102 | 103 | cases := []struct { 104 | name string 105 | cp *constructorParam 106 | option nm.OptionalArg 107 | isOptErr bool 108 | }{ 109 | { 110 | name: "local property", 111 | cp: newConstructorParam("name", "withName", nil), 112 | option: nm.OptionalArg{Name: "name", Default: nm.NewStringDouble("")}, 113 | }, 114 | { 115 | name: "nested property", 116 | cp: newConstructorParam("name", "foo.bar.baz.withName", nil), 117 | option: nm.OptionalArg{Name: "name", Default: nm.NewStringDouble("")}, 118 | }, 119 | { 120 | name: "string", 121 | cp: newConstructorParam("name", "withName", "name"), 122 | option: nm.OptionalArg{Name: "name", Default: nm.NewStringDouble("name")}, 123 | }, 124 | { 125 | name: "map[string]interface{}", 126 | cp: newConstructorParam("name", "withName", map[string]interface{}{"alpha": "beta"}), 127 | option: nm.OptionalArg{Name: "name", Default: obj}, 128 | }, 129 | { 130 | name: "invalid item in map[string]interface{}", 131 | cp: newConstructorParam("name", "withName", map[string]interface{}{"alpha": []int{1}}), 132 | isOptErr: true, 133 | }, 134 | { 135 | name: "array of strings", 136 | cp: newConstructorParam("name", "withName", []string{"one", "two"}), 137 | option: nm.OptionalArg{Name: "name", 138 | Default: nm.NewArray([]nm.Noder{nm.NewStringDouble("one"), nm.NewStringDouble("two")})}, 139 | }, 140 | { 141 | name: "float64", 142 | cp: newConstructorParam("name", "withName", 1.0), 143 | option: nm.OptionalArg{Name: "name", Default: nm.NewFloat(1.0)}, 144 | }, 145 | { 146 | name: "int", 147 | cp: newConstructorParam("name", "withName", 1), 148 | option: nm.OptionalArg{Name: "name", Default: nm.NewInt(1)}, 149 | }, 150 | { 151 | name: "bool", 152 | cp: newConstructorParam("name", "withName", true), 153 | option: nm.OptionalArg{Name: "name", Default: nm.NewBoolean(true)}, 154 | }, 155 | { 156 | name: "unknown type", 157 | cp: newConstructorParam("name", "withName", []int{1}), 158 | isOptErr: true, 159 | }, 160 | } 161 | 162 | for _, tc := range cases { 163 | t.Run(tc.name, func(t *testing.T) { 164 | option, err := tc.cp.Option() 165 | if tc.isOptErr { 166 | require.Error(t, err) 167 | } else { 168 | require.NoError(t, err) 169 | assert.Equal(t, tc.option, option) 170 | } 171 | }) 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /gen/ksonnet/description.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "fmt" 5 | "regexp" 6 | ) 7 | 8 | const ( 9 | groupCore = "core" 10 | ) 11 | 12 | var ( 13 | reNames = []*regexp.Regexp{ 14 | // Core API, pre-1.8 Kubernetes OR non-Kubernetes codebase APIs 15 | regexp.MustCompile(`io\.k8s\.(?P\S+)\.pkg\.api\.(?P\S+)\.(?P\S+)`), 16 | // Core API, 1.8+ Kubernetes 17 | regexp.MustCompile(`io\.k8s\.api\.(?Pcore)\.(?P\S+)\.(?P\S+)`), 18 | // Other APIs, pre-1.8 Kubernetes OR non-Kubernetes codebase APIs 19 | regexp.MustCompile(`io\.k8s\.(?P\S+)\.pkg\.(?Papis)\.(?P\S+)\.(?P\S+)\.(?P\S+)`), 20 | // Other APIs, 1.8+ Kubernetes 21 | regexp.MustCompile(`io\.k8s\.api\.(?P\S+)\.(?P\S+)\.(?P\S+)`), 22 | // Util packageType 23 | regexp.MustCompile(`io\.k8s\.(?P\S+)\.pkg\.(?Putil)\.(?P\S+)\.(?P\S+)`), 24 | // Version packageType 25 | regexp.MustCompile(`io\.k8s\.(?P\S+)\.pkg\.(?Pversion)\.(?P\S+)`), 26 | // Runtime packageType 27 | regexp.MustCompile(`io\.k8s\.(?P\S+)\.pkg\.(?Pruntime)\.(?P\S+)`), 28 | } 29 | ) 30 | 31 | // UnknownDefinitionError is an error signifying an unknown definition. 32 | type UnknownDefinitionError struct { 33 | name string 34 | } 35 | 36 | var _ error = (*UnknownDefinitionError)(nil) 37 | 38 | // NewUnknownDefinitionError creates an instance of UnknownDefinitionError. 39 | func NewUnknownDefinitionError(name string) *UnknownDefinitionError { 40 | return &UnknownDefinitionError{ 41 | name: name, 42 | } 43 | } 44 | 45 | func (e *UnknownDefinitionError) Error() string { 46 | return fmt.Sprintf("%q is not a known definition name", e.name) 47 | } 48 | 49 | // Description is a description of a Kubernetes definition name. 50 | type Description struct { 51 | Name string 52 | Version string 53 | Kind string 54 | Group string 55 | Codebase string 56 | } 57 | 58 | // Validate validates the Description. A description is valid if it has a version. 59 | func (d *Description) Validate() error { 60 | if d.Version == "" { 61 | return fmt.Errorf("version is nil for %q", d.Name) 62 | } 63 | 64 | return nil 65 | } 66 | 67 | // ParseDescription takes a definition name and returns a Description. 68 | func ParseDescription(name string) (*Description, error) { 69 | for _, r := range reNames { 70 | if match := r.FindStringSubmatch(name); len(match) > 0 { 71 | 72 | result := make(map[string]string) 73 | for i, name := range r.SubexpNames() { 74 | if i != 0 { 75 | result[name] = match[i] 76 | } 77 | } 78 | 79 | codebase := result["codebase"] 80 | if codebase == "" { 81 | codebase = "api" 82 | } 83 | 84 | d := &Description{ 85 | Name: name, 86 | Version: result["version"], 87 | Kind: result["kind"], 88 | Group: result["group"], 89 | Codebase: codebase, 90 | } 91 | 92 | return d, nil 93 | } 94 | } 95 | 96 | return nil, &UnknownDefinitionError{name: name} 97 | } 98 | -------------------------------------------------------------------------------- /gen/ksonnet/description_test.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/require" 7 | ) 8 | 9 | func Test_UnknownDefinitionError(t *testing.T) { 10 | err := NewUnknownDefinitionError("name") 11 | require.Equal(t, `"name" is not a known definition name`, err.Error()) 12 | } 13 | 14 | func Test_Description_Validate(t *testing.T) { 15 | cases := []struct { 16 | name string 17 | description Description 18 | isErr bool 19 | }{ 20 | { 21 | name: "with version", 22 | description: Description{Version: "version"}, 23 | }, 24 | { 25 | name: "with out version", 26 | description: Description{}, 27 | isErr: true, 28 | }, 29 | } 30 | 31 | for _, tc := range cases { 32 | t.Run(tc.name, func(t *testing.T) { 33 | err := tc.description.Validate() 34 | if tc.isErr { 35 | require.Error(t, err) 36 | } else { 37 | require.NoError(t, err) 38 | } 39 | }) 40 | } 41 | } 42 | 43 | func Test_ParseDescription(t *testing.T) { 44 | cases := []struct { 45 | name string 46 | description Description 47 | err error 48 | }{ 49 | { 50 | name: "foo.bar", 51 | err: NewUnknownDefinitionError("foo.bar"), 52 | }, 53 | { 54 | name: "io.k8s.apimachinery.pkg.version.Info", 55 | description: Description{ 56 | Name: "io.k8s.apimachinery.pkg.version.Info", 57 | Kind: "Info", 58 | Codebase: "apimachinery", 59 | }, 60 | }, 61 | { 62 | name: "io.k8s.apimachinery.pkg.apis.meta.v1.Status", 63 | description: Description{ 64 | Name: "io.k8s.apimachinery.pkg.apis.meta.v1.Status", 65 | Kind: "Status", 66 | Version: "v1", 67 | Group: "meta", 68 | Codebase: "apimachinery", 69 | }, 70 | }, 71 | { 72 | name: "io.k8s.api.admissionregistration.v1alpha1.AdmissionHookClientConfig", 73 | description: Description{ 74 | Name: "io.k8s.api.admissionregistration.v1alpha1.AdmissionHookClientConfig", 75 | Version: "v1alpha1", 76 | Kind: "AdmissionHookClientConfig", 77 | Group: "admissionregistration", 78 | Codebase: "api", 79 | }, 80 | }, 81 | { 82 | name: "io.k8s.codebase.pkg.api.version.kind", 83 | description: Description{ 84 | Name: "io.k8s.codebase.pkg.api.version.kind", 85 | Version: "version", 86 | Kind: "kind", 87 | Codebase: "codebase", 88 | }, 89 | }, 90 | } 91 | 92 | for _, tc := range cases { 93 | t.Run(tc.name, func(t *testing.T) { 94 | d, err := ParseDescription(tc.name) 95 | if tc.err == nil { 96 | require.NoError(t, err) 97 | require.Equal(t, tc.description, *d) 98 | } else { 99 | require.Error(t, err) 100 | } 101 | }) 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /gen/ksonnet/document_integration_test.go: -------------------------------------------------------------------------------- 1 | package ksonnet_test 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | "io/ioutil" 7 | "os" 8 | "os/exec" 9 | "path/filepath" 10 | "testing" 11 | 12 | "github.com/stretchr/testify/require" 13 | 14 | "github.com/kube-jsonnet/k/gen/ksonnet" 15 | ) 16 | 17 | func testdata(name string) string { 18 | return filepath.Join("testdata", name) 19 | } 20 | 21 | func TestDocument_Integration(t *testing.T) { 22 | dir, err := ioutil.TempDir("", "document") 23 | require.NoError(t, err) 24 | 25 | defer os.RemoveAll(dir) 26 | 27 | lib := genDoc(t, "testdata/swagger-1.8.json") 28 | 29 | k8sPath := filepath.Join(dir, "k8s.libsonnet") 30 | writeFile(t, k8sPath, lib.K8s) 31 | verifyJsonnet(t, dir, "k8s.libsonnet") 32 | 33 | ksPath := filepath.Join(dir, "k.libsonnet") 34 | writeFile(t, ksPath, lib.Extensions) 35 | verifyJsonnet(t, dir, "k.libsonnet") 36 | 37 | compPath := filepath.Join(dir, "component.libsonnet") 38 | copyFile(t, testdata("component.libsonnet"), compPath) 39 | 40 | cmd := exec.Command(jsonnetCmd(), "component.libsonnet") 41 | cmd.Dir = dir 42 | 43 | out, err := cmd.CombinedOutput() 44 | if err != nil { 45 | t.Fatal(string(out)) 46 | } 47 | 48 | expected, err := ioutil.ReadFile(testdata("component.json")) 49 | require.NoError(t, err) 50 | 51 | require.Equal(t, string(expected), string(out)) 52 | } 53 | 54 | func jsonnetCmd() string { 55 | bin := os.Getenv("JSONNET_BIN") 56 | if bin == "" { 57 | bin = "jsonnet" 58 | } 59 | 60 | return bin 61 | } 62 | 63 | func verifyJsonnet(t *testing.T, dir, fileName string) { 64 | cmd := exec.Command(jsonnetCmd(), "fmt", fileName) 65 | cmd.Dir = dir 66 | 67 | var b bytes.Buffer 68 | cmd.Stderr = &b 69 | 70 | err := cmd.Run() 71 | if err != nil { 72 | t.Fatalf("%s verification failed: %v", fileName, b.String()) 73 | } 74 | } 75 | 76 | func genDoc(t *testing.T, input string) *ksonnet.Lib { 77 | lib, err := ksonnet.GenerateLib(input) 78 | require.NoError(t, err) 79 | 80 | return lib 81 | } 82 | 83 | func writeFile(t *testing.T, name string, content []byte) { 84 | err := ioutil.WriteFile(name, content, 0600) 85 | require.NoError(t, err) 86 | } 87 | 88 | func copyFile(t *testing.T, src, dest string) { 89 | from, err := os.Open(src) 90 | require.NoError(t, err) 91 | defer from.Close() 92 | 93 | to, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE, 0666) 94 | require.NoError(t, err) 95 | defer to.Close() 96 | 97 | _, err = io.Copy(to, from) 98 | require.NoError(t, err) 99 | } 100 | -------------------------------------------------------------------------------- /gen/ksonnet/extension_test.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "io/ioutil" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/require" 8 | 9 | "github.com/kube-jsonnet/k/gen/printer" 10 | ) 11 | 12 | func TestExtension_Output(t *testing.T) { 13 | c := initCatalog(t, "swagger-1.8.json") 14 | 15 | e := NewExtension(c) 16 | 17 | node, err := e.Node() 18 | require.NoError(t, err) 19 | 20 | require.NoError(t, printer.Fprint(ioutil.Discard, node.Node())) 21 | } 22 | -------------------------------------------------------------------------------- /gen/ksonnet/field.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | // Field is a Kubernetes field. 4 | type Field struct { 5 | kind string 6 | description string 7 | properties map[string]Property 8 | version string 9 | group string 10 | codebase string 11 | identifier string 12 | } 13 | 14 | var _ Object = (*Field)(nil) 15 | 16 | // NewField creates an instance of Field. 17 | func NewField(id, desc, codebase, group, ver, kind string, props map[string]Property) *Field { 18 | return &Field{ 19 | identifier: id, 20 | description: desc, 21 | group: group, 22 | codebase: codebase, 23 | version: ver, 24 | kind: kind, 25 | properties: props, 26 | } 27 | } 28 | 29 | // Kind is the kind for this field. 30 | func (f *Field) Kind() string { 31 | return f.kind 32 | } 33 | 34 | // Version is the version for this field. 35 | func (f *Field) Version() string { 36 | return f.version 37 | } 38 | 39 | // Codebase is the codebase for this field. 40 | func (f *Field) Codebase() string { 41 | return f.codebase 42 | } 43 | 44 | // Group is the group for this field. 45 | func (f *Field) Group() string { 46 | if f.group == "" { 47 | return "core" 48 | } 49 | 50 | return f.group 51 | } 52 | 53 | // QualifiedGroup is the group for this field. 54 | func (f *Field) QualifiedGroup() string { 55 | return f.Group() 56 | } 57 | 58 | // Description is the description for this field. 59 | func (f *Field) Description() string { 60 | return f.description 61 | } 62 | 63 | // Identifier is the identifier for this field. 64 | func (f *Field) Identifier() string { 65 | return f.identifier 66 | } 67 | 68 | // IsType returns if this item is a type. It always returns false. 69 | func (f *Field) IsType() bool { 70 | return false 71 | } 72 | 73 | // Properties are the properties for this field. 74 | func (f *Field) Properties() map[string]Property { 75 | return f.properties 76 | } 77 | -------------------------------------------------------------------------------- /gen/ksonnet/field_test.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | ) 8 | 9 | func TestField(t *testing.T) { 10 | props := make(map[string]Property) 11 | props["foo"] = NewLiteralField("name", "integer", "desc", "ref") 12 | 13 | ty := NewField("id", "desc", "codebase", "group", "ver", "kind", props) 14 | 15 | assert.Equal(t, "id", ty.Identifier()) 16 | assert.Equal(t, "desc", ty.Description()) 17 | assert.Equal(t, "codebase", ty.Codebase()) 18 | assert.Equal(t, "group", ty.Group()) 19 | assert.Equal(t, "group", ty.QualifiedGroup()) 20 | assert.Equal(t, "ver", ty.Version()) 21 | assert.Equal(t, "kind", ty.Kind()) 22 | assert.False(t, ty.IsType()) 23 | 24 | assert.Len(t, ty.Properties(), 1) 25 | } 26 | 27 | func TestField_no_group(t *testing.T) { 28 | props := make(map[string]Property) 29 | props["foo"] = NewLiteralField("name", "integer", "desc", "ref") 30 | 31 | ty := NewField("id", "desc", "codebase", "", "ver", "kind", props) 32 | 33 | assert.Equal(t, "core", ty.Group()) 34 | assert.Equal(t, "core", ty.QualifiedGroup()) 35 | } 36 | -------------------------------------------------------------------------------- /gen/ksonnet/group.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "sort" 5 | 6 | nm "github.com/kube-jsonnet/k/gen/nodemaker" 7 | ) 8 | 9 | // Group is group of definitions. 10 | type Group struct { 11 | versions map[string]*Version 12 | name string 13 | } 14 | 15 | // NewGroup creates an instance of Group. 16 | func NewGroup(name string) *Group { 17 | return &Group{ 18 | versions: make(map[string]*Version), 19 | name: name, 20 | } 21 | } 22 | 23 | // Name is the name of the group. 24 | func (g *Group) Name() string { 25 | return g.name 26 | } 27 | 28 | // Versions returns the versions available for this group. 29 | func (g *Group) Versions() []Version { 30 | var names []string 31 | for name := range g.versions { 32 | names = append(names, name) 33 | } 34 | 35 | sort.Strings(names) 36 | 37 | var versions []Version 38 | for _, name := range names { 39 | versions = append(versions, *g.versions[name]) 40 | } 41 | 42 | return versions 43 | } 44 | 45 | // AddResource adds a resource to a version. 46 | func (g *Group) AddResource(r Object) { 47 | name := r.Version() 48 | if name == "" { 49 | return 50 | } 51 | 52 | v, ok := g.versions[name] 53 | if !ok { 54 | v = NewVersion(name, r.QualifiedGroup()) 55 | g.versions[name] = v 56 | } 57 | 58 | v.AddResource(r) 59 | } 60 | 61 | // Node returns an ast node for this group. 62 | func (g *Group) Node() *nm.Object { 63 | return nm.NewObject() 64 | } 65 | -------------------------------------------------------------------------------- /gen/ksonnet/group_test.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/require" 7 | 8 | nm "github.com/kube-jsonnet/k/gen/nodemaker" 9 | ) 10 | 11 | func TestGroup_Name(t *testing.T) { 12 | g := NewGroup("groupName") 13 | require.Equal(t, "groupName", g.Name()) 14 | } 15 | 16 | func TestGroup_Node(t *testing.T) { 17 | g := NewGroup("groupName") 18 | versions := nm.NewObject() 19 | 20 | require.Equal(t, versions, g.Node()) 21 | } 22 | 23 | func TestGroup_Versions(t *testing.T) { 24 | g := NewGroup("groupName") 25 | g.versions = map[string]*Version{ 26 | "v1": {}, 27 | "v2": {}, 28 | } 29 | 30 | require.Len(t, g.Versions(), 2) 31 | } 32 | 33 | func TestGroup_AddResource(t *testing.T) { 34 | c1 := Component{Group: "group2", Version: "v1", Kind: "kind"} 35 | o1 := NewType("alpha", "desc", "codebase", "group", c1, nil) 36 | 37 | g := NewGroup("groupName") 38 | g.AddResource(&o1) 39 | 40 | require.Len(t, g.Versions(), 1) 41 | 42 | c2 := Component{Group: "group2", Version: "", Kind: "kind"} 43 | o2 := NewType("beta", "desc", "codebase", "group", c2, nil) 44 | g.AddResource(&o2) 45 | 46 | require.Len(t, g.Versions(), 1) 47 | } 48 | -------------------------------------------------------------------------------- /gen/ksonnet/ksonnet.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "bytes" 5 | "regexp" 6 | 7 | "github.com/pkg/errors" 8 | 9 | "github.com/kube-jsonnet/k/gen/kubespec" 10 | "github.com/kube-jsonnet/k/gen/printer" 11 | ) 12 | 13 | // Lib is a ksonnet lib. 14 | type Lib struct { 15 | K8s map[string][]byte 16 | Extensions []byte 17 | Version string 18 | } 19 | 20 | type GenOpts struct { 21 | Metadata 22 | 23 | // OpenAPI (swagger.json) spec of the API 24 | OpenAPI string 25 | 26 | // Optional regexp to only generate specific apiGroups 27 | Target *regexp.Regexp 28 | 29 | // Name of the generated library (e.g. Kubernetes, cert-manager, etc) 30 | Name string 31 | // Version of the targeted software (e.g. 1.17, 0.1, etc.) 32 | Version string 33 | // Maintainer of the generated library 34 | Maintainer string 35 | } 36 | 37 | // Metadata holds meta information about the generator used for the build 38 | type Metadata struct { 39 | // Vendor of this build 40 | Vendor string 41 | 42 | // Version of the generator 43 | Version string 44 | } 45 | 46 | // GenerateLib generates ksonnet lib. 47 | func GenerateLib(opts GenOpts) (*Lib, error) { 48 | apiSpec, checksum, err := kubespec.Import(opts.OpenAPI) 49 | if err != nil { 50 | return nil, errors.Wrap(err, "import Kubernetes spec") 51 | } 52 | 53 | c, err := NewCatalog(apiSpec, opts.Name, 54 | CatalogOptChecksum(checksum), 55 | CatalogOptVersion(opts.Version), 56 | CatalogOptMaintainer(opts.Maintainer), 57 | ) 58 | 59 | if err != nil { 60 | return nil, errors.Wrap(err, "create ksonnet catalog") 61 | } 62 | 63 | k8s, err := createK8s(c, opts.Metadata) 64 | if err != nil { 65 | return nil, errors.Wrap(err, "create k8s.libsonnet") 66 | } 67 | 68 | k, err := createK(c) 69 | if err != nil { 70 | return nil, errors.Wrap(err, "create k.libsonnet") 71 | } 72 | 73 | lib := &Lib{ 74 | K8s: k8s, 75 | Extensions: k, 76 | Version: c.apiVersion.String(), 77 | } 78 | 79 | return lib, nil 80 | } 81 | 82 | func createK8s(c *Catalog, meta Metadata) (map[string][]byte, error) { 83 | doc, err := NewDocument(c) 84 | if err != nil { 85 | return nil, errors.Wrapf(err, "create document") 86 | } 87 | 88 | nodes, err := doc.Nodes(meta) 89 | if err != nil { 90 | return nil, errors.Wrapf(err, "build document node") 91 | } 92 | 93 | out := make(map[string][]byte) 94 | for name, n := range nodes { 95 | var buf bytes.Buffer 96 | if err := printer.Fprint(&buf, n.Node()); err != nil { 97 | return nil, errors.Wrap(err, "print AST") 98 | } 99 | 100 | out[name] = buf.Bytes() 101 | } 102 | 103 | return out, nil 104 | } 105 | 106 | func createK(c *Catalog) ([]byte, error) { 107 | e := NewExtension(c) 108 | 109 | node, err := e.Node() 110 | if err != nil { 111 | return nil, errors.Wrapf(err, "build extension node") 112 | } 113 | 114 | var buf bytes.Buffer 115 | 116 | if err := printer.Fprint(&buf, node.Node()); err != nil { 117 | return nil, errors.Wrap(err, "print AST") 118 | } 119 | 120 | return buf.Bytes(), nil 121 | } 122 | -------------------------------------------------------------------------------- /gen/ksonnet/object.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | // Object is an object that can be turned into a node by APIObject. 4 | type Object interface { 5 | Kind() string 6 | Description() string 7 | IsType() bool 8 | Properties() map[string]Property 9 | Version() string 10 | Group() string 11 | Codebase() string 12 | QualifiedGroup() string 13 | Identifier() string 14 | } 15 | 16 | // Property is a field in a resource 17 | type Property interface { 18 | Description() string 19 | Name() string 20 | Ref() string 21 | } 22 | 23 | // LiteralField is a literal field. (e.g. string, number, int, array) 24 | type LiteralField struct { 25 | name string 26 | fieldType string 27 | description string 28 | ref string 29 | } 30 | 31 | var _ Property = (*LiteralField)(nil) 32 | 33 | // NewLiteralField creates an instance of LiteralField. 34 | func NewLiteralField(name, fieldType, description, ref string) *LiteralField { 35 | return &LiteralField{ 36 | name: name, 37 | fieldType: fieldType, 38 | description: description, 39 | ref: ref, 40 | } 41 | } 42 | 43 | // FieldType returns the field type of the LiteralField. 44 | func (f *LiteralField) FieldType() string { 45 | return f.fieldType 46 | } 47 | 48 | // Name returns the name of the LiteralField. 49 | func (f *LiteralField) Name() string { 50 | return f.name 51 | } 52 | 53 | // Description returns the description of the LiteralField. 54 | func (f *LiteralField) Description() string { 55 | return f.description 56 | } 57 | 58 | // Ref returns the ref of the LiteralField. 59 | func (f *LiteralField) Ref() string { 60 | return f.ref 61 | } 62 | 63 | // ReferenceField is a reference field. 64 | type ReferenceField struct { 65 | name string 66 | description string 67 | ref string 68 | } 69 | 70 | var _ Property = (*ReferenceField)(nil) 71 | 72 | // NewReferenceField creates an instance of ReferenceField. 73 | func NewReferenceField(name, description, ref string) *ReferenceField { 74 | return &ReferenceField{ 75 | name: name, 76 | description: description, 77 | ref: ref, 78 | } 79 | } 80 | 81 | // Name returns the name of the ReferenceField. 82 | func (f *ReferenceField) Name() string { 83 | return f.name 84 | } 85 | 86 | // Description returns the description of the ReferenceField. 87 | func (f *ReferenceField) Description() string { 88 | return f.description 89 | } 90 | 91 | // Ref returns the defintion this ReferenceField represents. 92 | func (f *ReferenceField) Ref() string { 93 | return f.ref 94 | } 95 | -------------------------------------------------------------------------------- /gen/ksonnet/object_test.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | ) 8 | 9 | func TestLiteralField(t *testing.T) { 10 | f := NewLiteralField("name", "string", "desc", "ref") 11 | 12 | assert.Equal(t, "name", f.Name()) 13 | assert.Equal(t, "string", f.FieldType()) 14 | assert.Equal(t, "desc", f.Description()) 15 | assert.Equal(t, "ref", f.Ref()) 16 | } 17 | 18 | func TestReferenceField(t *testing.T) { 19 | f := NewReferenceField("name", "desc", "ref") 20 | 21 | assert.Equal(t, "name", f.Name()) 22 | assert.Equal(t, "desc", f.Description()) 23 | assert.Equal(t, "ref", f.Ref()) 24 | } 25 | -------------------------------------------------------------------------------- /gen/ksonnet/paths.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "github.com/go-openapi/spec" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | func parsePaths(apiSpec *spec.Swagger) (map[string]Component, error) { 9 | m := make(map[string]Component) 10 | 11 | if apiSpec.Paths == nil { 12 | return nil, errors.New("api spec has zero paths") 13 | } 14 | paths := apiSpec.Paths.Paths 15 | for _, pathItem := range paths { 16 | verbs := []*spec.Operation{pathItem.Post, pathItem.Patch, pathItem.Put} 17 | for _, verb := range verbs { 18 | if verb == nil { 19 | continue 20 | } 21 | 22 | var body spec.Parameter 23 | var hasBody bool 24 | for _, param := range verb.Parameters { 25 | if param.Name == "body" { 26 | body = param // shallow copy 27 | hasBody = true 28 | break 29 | } 30 | } 31 | 32 | if !hasBody { 33 | continue 34 | } 35 | 36 | if body.Schema == nil { 37 | return nil, errors.Errorf("invalid body parameter - missing required field: schema") 38 | } 39 | ref := extractRef(*body.Schema) 40 | 41 | component, exists, err := pathExtensionComponent(verb.Extensions) 42 | if err != nil { 43 | return nil, errors.Wrapf(err, "extract component for %s", ref) 44 | } 45 | 46 | if exists { 47 | m[ref] = component 48 | } 49 | 50 | } 51 | } 52 | 53 | return m, nil 54 | } 55 | 56 | // pathExtensionComponent generates a component from a method tpe extension 57 | func pathExtensionComponent(extensions spec.Extensions) (Component, bool, error) { 58 | for x, v := range extensions { 59 | if x == extensionGroupVersionKind { 60 | gvk, ok := v.(map[string]interface{}) 61 | if !ok { 62 | return Component{}, false, errors.New("gvk extension was invalid") 63 | } 64 | 65 | component := Component{ 66 | Group: gvk["group"].(string), 67 | Version: gvk["version"].(string), 68 | Kind: gvk["kind"].(string), 69 | } 70 | return component, true, nil 71 | } 72 | } 73 | 74 | return Component{}, false, nil 75 | } 76 | -------------------------------------------------------------------------------- /gen/ksonnet/paths_test.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | "github.com/stretchr/testify/require" 8 | ) 9 | 10 | func Test_parsePaths(t *testing.T) { 11 | c := initCatalog(t, "swagger-1.8.json") 12 | 13 | m, err := parsePaths(c.apiSpec) 14 | require.NoError(t, err) 15 | require.NotNil(t, m) 16 | 17 | expected := Component{ 18 | Group: "rbac.authorization.k8s.io", 19 | Version: "v1alpha1", 20 | Kind: "ClusterRoleBinding", 21 | } 22 | 23 | assert.Equal(t, expected, m["io.k8s.api.rbac.v1alpha1.ClusterRoleBinding"]) 24 | } 25 | -------------------------------------------------------------------------------- /gen/ksonnet/properties.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/go-openapi/spec" 7 | "github.com/pkg/errors" 8 | ) 9 | 10 | var ( 11 | recursiveRefs = []string{ 12 | "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.JSONSchemaProps", 13 | "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaProps", 14 | } 15 | ) 16 | 17 | func extractProperties(c *Catalog, properties map[string]spec.Schema, required []string) (map[string]Property, error) { 18 | if c == nil { 19 | return nil, errors.New("catalog is nil") 20 | } 21 | 22 | out := make(map[string]Property) 23 | 24 | for name, schema := range properties { 25 | if isSkippedProperty(name, schema) { 26 | if !stringInSlice(name, required) { 27 | continue 28 | } 29 | } 30 | 31 | ref := extractRef(schema) 32 | 33 | if ref != "" && stringInSlice(ref, recursiveRefs) { 34 | out[name] = NewLiteralField(name, "object", schema.Description, ref) 35 | continue 36 | } 37 | 38 | // literal 39 | if t := schema.Type; len(t) == 1 { 40 | out[name] = buildLiteralField(t[0], name, schema) 41 | continue 42 | } 43 | 44 | ifr, err := c.isFormatRef(ref) 45 | if err != nil { 46 | return nil, errors.Wrap(err, "check for format ref") 47 | } 48 | 49 | if ifr { 50 | // don't have to check for existence here because isFormatRef does the same thing 51 | formatSchema := c.apiSpec.Definitions[ref] 52 | out[name] = buildLiteralField(fieldType(formatSchema), name, schema) 53 | continue 54 | } 55 | 56 | // must be a mixin 57 | f := NewReferenceField(name, schema.Description, ref) 58 | out[name] = f 59 | } 60 | 61 | return out, nil 62 | } 63 | 64 | func buildLiteralField(fieldType, name string, schema spec.Schema) *LiteralField { 65 | var itemRef string 66 | if schema.Items != nil && schema.Items.Schema != nil { 67 | itemRef = extractRef(*schema.Items.Schema) 68 | } 69 | 70 | return NewLiteralField(name, fieldType, schema.Description, itemRef) 71 | } 72 | 73 | func isSkippedProperty(name string, schema spec.Schema) bool { 74 | if stringInSlice(name, blockedPropertyNames) { 75 | return true 76 | } 77 | 78 | if strings.Contains(strings.ToLower(schema.Description), "read-only") && name != "readOnly" { 79 | return true 80 | } 81 | 82 | ref := extractRef(schema) 83 | if stringInSlice(ref, blockedReferences) { 84 | return true 85 | } 86 | 87 | return false 88 | } 89 | 90 | func fieldType(schema spec.Schema) string { 91 | if t := schema.Type; len(t) == 1 { 92 | return t[0] 93 | } 94 | 95 | return "" 96 | } 97 | -------------------------------------------------------------------------------- /gen/ksonnet/strings.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "bytes" 5 | "strings" 6 | "unicode" 7 | ) 8 | 9 | var ( 10 | jsonnetKeywords = []string{"assert", "else", "error", "false", "for", "function", "if", 11 | "import", "importstr", "in", "null", "tailstrict", "then", "self", "super", 12 | "true"} 13 | ) 14 | 15 | // camelCase converts a string to camel case. 16 | func camelCase(in string) string { 17 | out := "" 18 | 19 | for i, r := range in { 20 | if i == 0 { 21 | out += strings.ToLower(string(r)) 22 | continue 23 | } 24 | 25 | out += string(r) 26 | 27 | } 28 | 29 | return out 30 | } 31 | 32 | // kebabToCamelCase converts a kebab-string to camelCase 33 | func kebabToCamelCase(kebab string) (camelCase string) { 34 | isToUpper := false 35 | for _, runeValue := range kebab { 36 | if isToUpper { 37 | camelCase += strings.ToUpper(string(runeValue)) 38 | isToUpper = false 39 | } else { 40 | if runeValue == '-' { 41 | isToUpper = true 42 | } else { 43 | camelCase += string(runeValue) 44 | } 45 | } 46 | } 47 | return 48 | } 49 | 50 | // stringInSlice returns true if the string is in the slice. 51 | func stringInSlice(a string, list []string) bool { 52 | for _, b := range list { 53 | if b == a { 54 | return true 55 | } 56 | } 57 | return false 58 | } 59 | 60 | // capitalizer adjusts the case of terms found in a string. 61 | func toLower(b byte) byte { 62 | return byte(unicode.ToLower(rune(b))) 63 | } 64 | 65 | func isUpper(b byte) bool { 66 | return unicode.IsUpper(rune(b)) 67 | } 68 | 69 | // capitalize adjusts the case of terms found in a string. It will convert `HTTPHeader` into 70 | // `HttpHeader`. 71 | func capitalize(in string) string { 72 | l := len(in) - 1 73 | 74 | if l == 0 { 75 | // nothing to do when there is a one character strings 76 | return in 77 | } 78 | 79 | var b bytes.Buffer 80 | b.WriteByte(in[0]) 81 | 82 | for i := 1; i <= l; i++ { 83 | if isUpper(in[i-1]) { 84 | if i < l { 85 | if isUpper(in[i+1]) || (isUpper(in[i]) && i+1 == l) { 86 | b.WriteByte(toLower(in[i])) 87 | } else { 88 | b.WriteByte(in[i]) 89 | } 90 | } else if i == l && isUpper(in[i]) { 91 | b.WriteByte(toLower(in[i])) 92 | } else { 93 | b.WriteByte(in[i]) 94 | } 95 | } else { 96 | b.WriteByte(in[i]) 97 | } 98 | } 99 | 100 | return b.String() 101 | } 102 | 103 | // FormatKind formats a string in kind format. i.e camel case with jsonnet keywords massaged. 104 | func FormatKind(s string) string { 105 | if strings.ToLower(s) == "local" { 106 | return "localStorage" 107 | } 108 | 109 | if strings.HasPrefix(s, "$") { 110 | s = "dollar" + strings.Title(strings.TrimPrefix(s, "$")) 111 | return s 112 | } 113 | s = capitalize(s) 114 | s = camelCase(s) 115 | s = kebabToCamelCase(s) 116 | 117 | if stringInSlice(s, jsonnetKeywords) { 118 | s = s + "Param" 119 | } 120 | 121 | return s 122 | } 123 | -------------------------------------------------------------------------------- /gen/ksonnet/testdata/component.json: -------------------------------------------------------------------------------- 1 | { 2 | "apiVersion": "v1", 3 | "items": [ 4 | { 5 | "apiVersion": "apps/v1beta2", 6 | "kind": "Deployment", 7 | "metadata": { 8 | "name": "appName" 9 | }, 10 | "spec": { 11 | "replicas": 2, 12 | "template": { 13 | "metadata": { 14 | "labels": { 15 | "app": "customName" 16 | } 17 | }, 18 | "spec": { 19 | "containers": [ 20 | { 21 | "image": "nginx:latest", 22 | "name": "appName", 23 | "ports": [ 24 | { 25 | "containerPort": 80 26 | } 27 | ] 28 | } 29 | ] 30 | } 31 | } 32 | } 33 | } 34 | ], 35 | "kind": "List" 36 | } 37 | -------------------------------------------------------------------------------- /gen/ksonnet/testdata/component.libsonnet: -------------------------------------------------------------------------------- 1 | local k = import 'k.libsonnet'; 2 | 3 | local params = { 4 | version: 'v1beta2', 5 | name: 'appName', 6 | replicas: 3, 7 | containerPort: 80, 8 | image: 'nginx:latest', 9 | labels: { app: 'customName' }, 10 | }; 11 | 12 | // defining the deployment version as a variable means you potentially have the ability to 13 | // set versions in params. It also means a single prototype can support multiple versions of a 14 | // resource. 15 | local deploymentVersion = params.version; 16 | 17 | // container creates a container object 18 | local container = function(version, name, image, containerPort) 19 | // create a local variable with our resource 20 | local deployment = k.apps[deploymentVersion].deployment; 21 | 22 | local containersType = deployment.mixin.spec.template.spec.containersType; 23 | local portsType = containersType.portsType; 24 | 25 | local port = portsType.withContainerPort(containerPort); 26 | 27 | containersType 28 | .withName(name) 29 | .withImage(image) 30 | .withPorts(port); 31 | 32 | 33 | // createDeployment is our function for creating a deployment 34 | local createDeployment = function(version, name, containers, podLabels={}, replicas=1) 35 | // create a local variable with our resource 36 | local deployment = k.apps[version].deployment; 37 | 38 | local labels = { app: name } + podLabels; 39 | local metadata = deployment.mixin.metadata.withName(name); 40 | local spec = deployment.mixin.spec.withReplicas(replicas); 41 | local templateSpec = spec.template.spec.withContainers(containers); 42 | local templateMetadata = spec.template.metadata.withLabels(labels); 43 | 44 | deployment 45 | .new() 46 | + metadata 47 | + spec 48 | + templateSpec 49 | + templateMetadata; 50 | 51 | 52 | local containers = [ 53 | container(deploymentVersion, params.name, params.image, params.containerPort), 54 | ]; 55 | 56 | // The createDeployment function allows authors to generate the objects they would like rather 57 | // than being confined to what is generated in ksonnet-lib. 58 | local appDeployment = createDeployment( 59 | deploymentVersion, 60 | params.name, 61 | containers, 62 | podLabels=params.labels, 63 | replicas=2 64 | ); 65 | 66 | k.core.v1.list.new([appDeployment]) 67 | -------------------------------------------------------------------------------- /gen/ksonnet/testdata/constructor.libsonnet: -------------------------------------------------------------------------------- 1 | { 2 | new(name='', nestedName='', nestedItem='', str='val', obj={ key: 'val' }, array=['val'], other='', foo=''):: apiVersion + kind + self.withArray(array).withName(name).withObj(obj).withStr(str) + self.foo.bar.baz.withItem(nestedItem).withName(nestedName) + self.last.path.withFoo(foo) + self.other.withArray(other), 3 | } 4 | -------------------------------------------------------------------------------- /gen/ksonnet/testdata/generated_k.libsonnet: -------------------------------------------------------------------------------- 1 | local k8s = import 'k8s.libsonnet'; 2 | local fn = { 3 | mapContainers(f):: { 4 | local podContainers = super.spec.template.spec.containers, 5 | spec+: { 6 | template+: { 7 | spec+: { 8 | containers: std.map(f, podContainers), 9 | }, 10 | }, 11 | }, 12 | }, 13 | mapContainersWithName(names, f):: 14 | local nameSet = if std.type(names) == 'array' then std.set(names) else std.set([names]); 15 | local inNameSet(name) = std.length(std.setInter(nameSet, std.set([name]))) > 0; 16 | 17 | self.mapContainers(function(c) if std.objectHas(c, 'name') && inNameSet(c.name) then f(c) else c), 18 | }; 19 | 20 | k8s { 21 | apps:: k8s.apps { 22 | v1beta1:: k8s.apps.v1beta1 { 23 | deployment:: k8s.apps.v1beta1.deployment { 24 | mapContainers(f):: fn.mapContainers(f), 25 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 26 | }, 27 | statefulSet:: k8s.apps.v1beta1.statefulSet { 28 | mapContainers(f):: fn.mapContainers(f), 29 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 30 | }, 31 | }, 32 | v1beta2:: k8s.apps.v1beta2 { 33 | daemonSet:: k8s.apps.v1beta2.daemonSet { 34 | mapContainers(f):: fn.mapContainers(f), 35 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 36 | }, 37 | deployment:: k8s.apps.v1beta2.deployment { 38 | mapContainers(f):: fn.mapContainers(f), 39 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 40 | }, 41 | replicaSet:: k8s.apps.v1beta2.replicaSet { 42 | mapContainers(f):: fn.mapContainers(f), 43 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 44 | }, 45 | statefulSet:: k8s.apps.v1beta2.statefulSet { 46 | mapContainers(f):: fn.mapContainers(f), 47 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 48 | }, 49 | }, 50 | }, 51 | batch:: k8s.batch { 52 | v1:: k8s.batch.v1 { 53 | job:: k8s.batch.v1.job { 54 | mapContainers(f):: fn.mapContainers(f), 55 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 56 | }, 57 | }, 58 | v1beta1:: k8s.batch.v1beta1 { 59 | cronJob:: k8s.batch.v1beta1.cronJob { 60 | mapContainers(f):: fn.mapContainers(f), 61 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 62 | }, 63 | }, 64 | v2alpha1:: k8s.batch.v2alpha1 { 65 | cronJob:: k8s.batch.v2alpha1.cronJob { 66 | mapContainers(f):: fn.mapContainers(f), 67 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 68 | }, 69 | }, 70 | }, 71 | core:: k8s.core { 72 | v1:: k8s.core.v1 { 73 | list:: { 74 | new(items):: { 75 | apiVersion: 'v1', 76 | } + { 77 | kind: 'List', 78 | } + self.items(items), 79 | items(items):: if std.type(items) == 'array' then { items+: items } else { items+: [items] }, 80 | }, 81 | pod:: k8s.core.v1.pod { 82 | mapContainers(f):: fn.mapContainers(f), 83 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 84 | }, 85 | podTemplate:: k8s.core.v1.podTemplate { 86 | mapContainers(f):: fn.mapContainers(f), 87 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 88 | }, 89 | replicationController:: k8s.core.v1.replicationController { 90 | mapContainers(f):: fn.mapContainers(f), 91 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 92 | }, 93 | }, 94 | }, 95 | extensions:: k8s.extensions { 96 | v1beta1:: k8s.extensions.v1beta1 { 97 | daemonSet:: k8s.extensions.v1beta1.daemonSet { 98 | mapContainers(f):: fn.mapContainers(f), 99 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 100 | }, 101 | deployment:: k8s.extensions.v1beta1.deployment { 102 | mapContainers(f):: fn.mapContainers(f), 103 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 104 | }, 105 | replicaSet:: k8s.extensions.v1beta1.replicaSet { 106 | mapContainers(f):: fn.mapContainers(f), 107 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 108 | }, 109 | }, 110 | }, 111 | } 112 | -------------------------------------------------------------------------------- /gen/ksonnet/testdata/invalid_definition.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "v1.8.0" 5 | }, 6 | "paths": { 7 | "/invalid": {} 8 | }, 9 | "definitions": { 10 | "invalid": {} 11 | } 12 | } -------------------------------------------------------------------------------- /gen/ksonnet/testdata/invalid_ref.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "v1.8.0" 5 | }, 6 | "paths": { 7 | "/invalid": {} 8 | }, 9 | "definitions": { 10 | "io.k8s.api.apps.v1beta2.RollingUpdateDeployment": { 11 | "description": "Spec to control the desired behavior of rolling update.", 12 | "properties": { 13 | "maxSurge": { 14 | "description": "The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to 25%. Example: when this is set to 30%, the new RC can be scaled up immediately when the rolling update starts, such that the total number of old and new pods do not exceed 130% of desired pods. Once old pods have been killed, new RC can be scaled up further, ensuring that total number of pods running at any time during the update is atmost 130% of desired pods.", 15 | "$ref": "#/definitions/io.k8s.apimachinery.pkg.util.intstr.IntOrString" 16 | }, 17 | "maxUnavailable": { 18 | "description": "The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to 25%. Example: when this is set to 30%, the old RC can be scaled down to 70% of desired pods immediately when the rolling update starts. Once new pods are ready, old RC can be scaled down further, followed by scaling up the new RC, ensuring that the total number of pods available at all times during the update is at least 70% of desired pods.", 19 | "$ref": "#/definitions/io.k8s.apimachinery.pkg.util.intstr.IntOrString" 20 | } 21 | } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /gen/ksonnet/testdata/k.libsonnet: -------------------------------------------------------------------------------- 1 | local k8s = import 'k8s.libsonnet'; 2 | local fn = { 3 | mapContainers(f):: { 4 | local podContainers = super.spec.template.spec.containers, 5 | spec+: { 6 | template+: { 7 | spec+: { 8 | containers: std.map(f, podContainers), 9 | }, 10 | }, 11 | }, 12 | }, 13 | mapContainersWithName(names, f):: 14 | local nameSet = if std.type(names) == 'array' then std.set(names) else std.set([names]); 15 | local inNameSet(name) = std.length(std.setInter(nameSet, std.set([name]))) > 0; 16 | 17 | self.mapContainers(function(c) if std.objectHas(c, 'name') && inNameSet(c.name) then f(c) else c), 18 | }; 19 | 20 | k8s { 21 | apps:: k8s.apps { 22 | v1beta1:: k8s.apps.v1beta1 { 23 | deployment:: k8s.apps.v1beta1.deployment { 24 | mapContainers(f):: fn.mapContainers(f), 25 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 26 | }, 27 | statefulSet:: k8s.apps.v1beta1.statefulSet { 28 | mapContainers(f):: fn.mapContainers(f), 29 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 30 | }, 31 | }, 32 | v1beta2:: k8s.apps.v1beta2 { 33 | daemonSet:: k8s.apps.v1beta2.daemonSet { 34 | mapContainers(f):: fn.mapContainers(f), 35 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 36 | }, 37 | deployment:: k8s.apps.v1beta2.deployment { 38 | mapContainers(f):: fn.mapContainers(f), 39 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 40 | }, 41 | replicaSet:: k8s.apps.v1beta2.replicaSet { 42 | mapContainers(f):: fn.mapContainers(f), 43 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 44 | }, 45 | statefulSet:: k8s.apps.v1beta2.statefulSet { 46 | mapContainers(f):: fn.mapContainers(f), 47 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 48 | }, 49 | }, 50 | }, 51 | batch:: k8s.batch { 52 | v1:: k8s.batch.v1 { 53 | job:: k8s.batch.v1.job { 54 | mapContainers(f):: fn.mapContainers(f), 55 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 56 | }, 57 | }, 58 | v1beta1:: k8s.batch.v1beta1 { 59 | cronJob:: k8s.batch.v1beta1.cronJob { 60 | mapContainers(f):: fn.mapContainers(f), 61 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 62 | }, 63 | }, 64 | v2alpha1:: k8s.batch.v2alpha1 { 65 | cronJob:: k8s.batch.v2alpha1.cronJob { 66 | mapContainers(f):: fn.mapContainers(f), 67 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 68 | }, 69 | }, 70 | }, 71 | core:: k8s.core { 72 | v1:: k8s.core.v1 { 73 | list:: { 74 | new(items):: { 75 | apiVersion: 'v1', 76 | } + { 77 | kind: 'List', 78 | } + self.items(items), 79 | items(items):: if std.type(items) == 'array' then { items+: items } else { items+: [items] }, 80 | }, 81 | pod:: k8s.core.v1.pod { 82 | mapContainers(f):: fn.mapContainers(f), 83 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 84 | }, 85 | podTemplate:: k8s.core.v1.podTemplate { 86 | mapContainers(f):: fn.mapContainers(f), 87 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 88 | }, 89 | replicationController:: k8s.core.v1.replicationController { 90 | mapContainers(f):: fn.mapContainers(f), 91 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 92 | }, 93 | }, 94 | }, 95 | extensions:: k8s.extensions { 96 | v1beta1:: k8s.extensions.v1beta1 { 97 | daemonSet:: k8s.extensions.v1beta1.daemonSet { 98 | mapContainers(f):: fn.mapContainers(f), 99 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 100 | }, 101 | deployment:: k8s.extensions.v1beta1.deployment { 102 | mapContainers(f):: fn.mapContainers(f), 103 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 104 | }, 105 | replicaSet:: k8s.extensions.v1beta1.replicaSet { 106 | mapContainers(f):: fn.mapContainers(f), 107 | mapContainersWithName(names, f):: fn.mapContainersWithName(names, f), 108 | }, 109 | }, 110 | }, 111 | } 112 | -------------------------------------------------------------------------------- /gen/ksonnet/type.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | // Type is a Kubernetes kind. 4 | type Type struct { 5 | description string 6 | properties map[string]Property 7 | component Component 8 | group string 9 | codebase string 10 | identifier string 11 | } 12 | 13 | var _ Object = (*Type)(nil) 14 | 15 | // NewType creates an instance of Type. 16 | func NewType(identifier, description, codebase, group string, component Component, props map[string]Property) Type { 17 | return Type{ 18 | description: description, 19 | group: group, 20 | codebase: codebase, 21 | component: component, 22 | properties: props, 23 | identifier: identifier, 24 | } 25 | } 26 | 27 | // Kind is the kind for this type 28 | func (t *Type) Kind() string { 29 | return t.component.Kind 30 | } 31 | 32 | // Version is the version for this type 33 | func (t *Type) Version() string { 34 | return t.component.Version 35 | } 36 | 37 | // Codebase is the codebase for this field. 38 | func (t *Type) Codebase() string { 39 | return t.codebase 40 | } 41 | 42 | // Group is the group for this type 43 | func (t *Type) Group() string { 44 | if t.group == "" { 45 | return "core" 46 | } 47 | 48 | return t.group 49 | } 50 | 51 | // QualifiedGroup is the group for this type 52 | func (t *Type) QualifiedGroup() string { 53 | return t.component.Group 54 | } 55 | 56 | // Description is description for this type 57 | func (t *Type) Description() string { 58 | return t.description 59 | } 60 | 61 | // Identifier is identifier for this type 62 | func (t *Type) Identifier() string { 63 | return t.identifier 64 | } 65 | 66 | // IsType returns if this item is a type. It always returns true. 67 | func (t *Type) IsType() bool { 68 | return true 69 | } 70 | 71 | // Properties are the properties for this type. 72 | func (t *Type) Properties() map[string]Property { 73 | return t.properties 74 | } 75 | -------------------------------------------------------------------------------- /gen/ksonnet/type_test.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | ) 8 | 9 | func TestType(t *testing.T) { 10 | props := make(map[string]Property) 11 | props["foo"] = NewLiteralField("name", "integer", "desc", "ref") 12 | 13 | c := Component{ 14 | Group: "group2", 15 | Version: "ver", 16 | Kind: "kind", 17 | } 18 | 19 | r := NewType("id", "desc", "codebase", "group1", c, props) 20 | 21 | assert.Equal(t, "id", r.Identifier()) 22 | assert.Equal(t, "desc", r.Description()) 23 | assert.Equal(t, "group1", r.Group()) 24 | assert.Equal(t, "ver", r.Version()) 25 | assert.Equal(t, "kind", r.Kind()) 26 | assert.Equal(t, "group2", r.QualifiedGroup()) 27 | assert.True(t, r.IsType()) 28 | 29 | assert.Len(t, r.Properties(), 1) 30 | } 31 | 32 | func TestType_no_group(t *testing.T) { 33 | props := make(map[string]Property) 34 | props["foo"] = NewLiteralField("name", "integer", "desc", "ref") 35 | 36 | c := Component{ 37 | Group: "group2", 38 | Version: "ver", 39 | Kind: "kind", 40 | } 41 | 42 | r := NewType("id", "desc", "codebase", "", c, props) 43 | 44 | assert.Equal(t, "core", r.Group()) 45 | assert.Equal(t, "group2", r.QualifiedGroup()) 46 | 47 | } 48 | -------------------------------------------------------------------------------- /gen/ksonnet/util.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "github.com/kube-jsonnet/k/gen/kubespec" 5 | ) 6 | 7 | var ( 8 | specialProperties = map[kubespec.PropertyName]kubespec.PropertyName{ 9 | "apiVersion": "apiVersion", 10 | "kind": "kind", 11 | } 12 | 13 | specialPropertiesList []string 14 | ) 15 | 16 | func init() { 17 | for k := range specialProperties { 18 | specialPropertiesList = append(specialPropertiesList, string(k)) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /gen/ksonnet/version.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "fmt" 5 | "sort" 6 | 7 | "github.com/google/go-jsonnet/ast" 8 | 9 | nm "github.com/kube-jsonnet/k/gen/nodemaker" 10 | ) 11 | 12 | // Version is an API version. 13 | type Version struct { 14 | name string 15 | group string 16 | 17 | resources []*APIObject 18 | } 19 | 20 | // NewVersion creates an instance of Version. 21 | func NewVersion(name, group string) *Version { 22 | v := &Version{ 23 | name: name, 24 | group: group, 25 | resources: make([]*APIObject, 0), 26 | } 27 | 28 | return v 29 | } 30 | 31 | // APIObjects returns a slice of APIObjects sorted by name. 32 | func (v *Version) APIObjects() []APIObject { 33 | var objects []APIObject 34 | for _, resource := range v.resources { 35 | objects = append(objects, *resource) 36 | } 37 | 38 | sort.Slice(objects, func(i, j int) bool { 39 | return objects[i].Kind() < objects[j].Kind() 40 | }) 41 | 42 | return objects 43 | } 44 | 45 | // Name is the name of the version. 46 | func (v *Version) Name() string { 47 | return v.name 48 | } 49 | 50 | // AddResource adds a resource to the version. 51 | func (v *Version) AddResource(resource Object) { 52 | ao := NewAPIObject(resource) 53 | v.resources = append(v.resources, ao) 54 | } 55 | 56 | // APIVersion returns the version. 57 | func (v *Version) APIVersion() string { 58 | if v.group == "core" || v.group == "" { 59 | return v.name 60 | } 61 | return fmt.Sprintf("%s/%s", v.group, v.name) 62 | } 63 | 64 | // Node returns an ast node for this version. 65 | func (v *Version) Node() *nm.Object { 66 | o := nm.NewObject() 67 | 68 | avo := nm.OnelineObject() 69 | avo.Set( 70 | nm.NewKey( 71 | "apiVersion", 72 | nm.KeyOptCategory(ast.ObjectFieldID), 73 | nm.KeyOptVisibility(ast.ObjectFieldInherit)), 74 | nm.NewStringDouble(v.APIVersion())) 75 | 76 | o.Set(nm.LocalKey("apiVersion"), avo) 77 | 78 | return o 79 | } 80 | -------------------------------------------------------------------------------- /gen/ksonnet/version_test.go: -------------------------------------------------------------------------------- 1 | package ksonnet 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/require" 7 | 8 | nm "github.com/kube-jsonnet/k/gen/nodemaker" 9 | ) 10 | 11 | func TestVersion_Name(t *testing.T) { 12 | v := NewVersion("v1", "groupName") 13 | require.Equal(t, "v1", v.Name()) 14 | } 15 | 16 | func TestVersion_APIVersion(t *testing.T) { 17 | cases := []struct { 18 | name string 19 | groupName string 20 | expected string 21 | }{ 22 | { 23 | name: "groupName group", 24 | groupName: "groupName", 25 | expected: "groupName/v1", 26 | }, 27 | { 28 | name: "core group", 29 | groupName: "core", 30 | expected: "v1", 31 | }, 32 | { 33 | name: "empty group", 34 | groupName: "", 35 | expected: "v1", 36 | }, 37 | } 38 | 39 | for _, tc := range cases { 40 | t.Run(tc.name, func(t *testing.T) { 41 | v := NewVersion("v1", tc.groupName) 42 | require.Equal(t, tc.expected, v.APIVersion()) 43 | }) 44 | } 45 | } 46 | 47 | func TestVersion_AddResource(t *testing.T) { 48 | v := NewVersion("v1", "groupName") 49 | 50 | c1 := Component{Group: "group2", Version: "v1", Kind: "kind1"} 51 | o1 := NewType("alpha", "desc", "codebase", "group", c1, nil) 52 | v.AddResource(&o1) 53 | 54 | c2 := Component{Group: "group2", Version: "v1", Kind: "kind2"} 55 | o2 := NewType("beta", "desc", "codebase", "group", c2, nil) 56 | v.AddResource(&o2) 57 | 58 | require.Len(t, v.APIObjects(), 2) 59 | } 60 | 61 | func TestVersion_Node(t *testing.T) { 62 | v := NewVersion("v1", "groupName") 63 | 64 | n := v.Node() 65 | require.NotNil(t, n) 66 | 67 | av, ok := n.Get("apiVersion").(*nm.Object) 68 | require.True(t, ok) 69 | 70 | vStr, ok := av.Get("apiVersion").(*nm.StringDouble) 71 | require.True(t, ok) 72 | 73 | require.Equal(t, nm.NewStringDouble(v.APIVersion()), vStr) 74 | } 75 | -------------------------------------------------------------------------------- /gen/kubespec/importer.go: -------------------------------------------------------------------------------- 1 | package kubespec 2 | 3 | import ( 4 | "crypto/sha256" 5 | "encoding/json" 6 | "fmt" 7 | 8 | "github.com/go-openapi/spec" 9 | "github.com/go-openapi/swag" 10 | "github.com/pkg/errors" 11 | ) 12 | 13 | // Import imports an OpenAPI swagger schema. 14 | func Import(path string) (*spec.Swagger, string, error) { 15 | b, err := swag.LoadFromFileOrHTTP(path) 16 | if err != nil { 17 | return nil, "", errors.Wrap(err, "load schema from path") 18 | } 19 | 20 | h := sha256.New() 21 | h.Write(b) 22 | 23 | checksum := fmt.Sprintf("%x", h.Sum(nil)) 24 | 25 | spec, err := CreateAPISpec(b) 26 | if err != nil { 27 | return nil, "", err 28 | } 29 | 30 | return spec, checksum, nil 31 | } 32 | 33 | // CreateAPISpec a swagger file into a *spec.Swagger. 34 | func CreateAPISpec(b []byte) (*spec.Swagger, error) { 35 | var apiSpec spec.Swagger 36 | if err := json.Unmarshal(b, &apiSpec); err != nil { 37 | return nil, errors.Wrap(err, "parse swagger JSON") 38 | } 39 | 40 | return &apiSpec, nil 41 | } 42 | -------------------------------------------------------------------------------- /gen/kubespec/importer_test.go: -------------------------------------------------------------------------------- 1 | package kubespec_test 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "net/http/httptest" 7 | "path/filepath" 8 | "testing" 9 | 10 | "github.com/kube-jsonnet/k/gen/kubespec" 11 | 12 | "github.com/stretchr/testify/require" 13 | ) 14 | 15 | func testdata(name string) string { 16 | return filepath.Join("testdata", name) 17 | } 18 | 19 | func TestImporter_Import(t *testing.T) { 20 | cases := []struct { 21 | name string 22 | location string 23 | checksum string 24 | isErr bool 25 | }{ 26 | { 27 | name: "missing file", 28 | location: "missing.json", 29 | isErr: true, 30 | }, 31 | { 32 | name: "invalid file", 33 | location: testdata("invalid.json"), 34 | isErr: true, 35 | }, 36 | { 37 | name: "valid file", 38 | location: testdata("deployment.json"), 39 | checksum: "0958866ac95c381dc661136396c73456038854df20b06688332a91a463857135", 40 | }, 41 | } 42 | 43 | for _, tc := range cases { 44 | t.Run(tc.name, func(t *testing.T) { 45 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 46 | t.Logf("path = %s", r.URL.Path) 47 | if r.URL.Path != "/swagger.json" { 48 | http.NotFound(w, r) 49 | return 50 | } 51 | 52 | fmt.Fprintln(w, `{"swagger": "2.0", "info": {"title": "Kubernetes"}}`) 53 | })) 54 | defer ts.Close() 55 | 56 | apiSpec, checksum, err := kubespec.Import(tc.location) 57 | if tc.isErr { 58 | require.Error(t, err) 59 | } else { 60 | require.NoError(t, err) 61 | require.NotNil(t, apiSpec) 62 | require.Equal(t, tc.checksum, checksum) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /gen/kubespec/new.go: -------------------------------------------------------------------------------- 1 | package kubespec 2 | 3 | import ( 4 | "fmt" 5 | "regexp" 6 | ) 7 | 8 | var ( 9 | regexes = []*regexp.Regexp{ 10 | // Core API, pre-1.8 Kubernetes OR non-Kubernetes codebase APIs 11 | regexp.MustCompile(`io\.k8s\.(?P\S+)\.pkg\.api\.(?P\S+)\.(?P\S+)`), 12 | // Core API, 1.8+ Kubernetes 13 | regexp.MustCompile(`io\.k8s\.api\.(?Pcore)\.(?P\S+)\.(?P\S+)`), 14 | // Other APIs, pre-1.8 Kubernetes OR non-Kubernetes codebase APIs 15 | regexp.MustCompile(`io\.k8s\.(?P\S+)\.pkg\.(?Papis)\.(?P\S+)\.(?P\S+)\.(?P\S+)`), 16 | // Other APIs, 1.8+ Kubernetes 17 | regexp.MustCompile(`io\.k8s\.api\.(?P\S+)\.(?P\S+)\.(?P\S+)`), 18 | // Util packageType 19 | regexp.MustCompile(`io\.k8s\.(?P\S+)\.pkg\.(?Putil)\.(?P\S+)\.(?P\S+)`), 20 | // Version packageType 21 | regexp.MustCompile(`io\.k8s\.(?P\S+)\.pkg\.(?Pversion)\.(?P\S+)`), 22 | // Runtime packageType 23 | regexp.MustCompile(`io\.k8s\.(?P\S+)\.pkg\.(?Pruntime)\.(?P\S+)`), 24 | } 25 | ) 26 | 27 | var ( 28 | packageTypeMap = map[string]Package{ 29 | "core": Core, 30 | "apis": APIs, 31 | "util": Util, 32 | "runtime": Runtime, 33 | "version": Version, 34 | } 35 | ) 36 | 37 | type description struct { 38 | name string 39 | codebase string 40 | version string 41 | kind ObjectKind 42 | packageType Package 43 | group string 44 | } 45 | 46 | func (d *description) Validate() error { 47 | if d.version == "" { 48 | return fmt.Errorf("version is nil for %q", d.name) 49 | } 50 | 51 | return nil 52 | } 53 | 54 | func describeDefinition(name string) (*description, error) { 55 | for _, r := range regexes { 56 | if match := r.FindStringSubmatch(name); len(match) > 0 { 57 | 58 | result := make(map[string]string) 59 | for i, name := range r.SubexpNames() { 60 | if i != 0 { 61 | result[name] = match[i] 62 | } 63 | } 64 | 65 | // Hacky heuristics to fix missing fields 66 | if result["codebase"] == "" { 67 | result["codebase"] = "kubernetes" 68 | } 69 | if result["packageType"] == "" && result["group"] == "" { 70 | result["packageType"] = "core" 71 | } 72 | if result["packageType"] == "" && result["group"] != "" { 73 | result["packageType"] = "apis" 74 | } 75 | 76 | d := &description{ 77 | name: name, 78 | codebase: result["codebase"], 79 | version: result["version"], 80 | kind: ObjectKind(result["kind"]), 81 | packageType: packageTypeMap[result["packageType"]], 82 | group: result["group"], 83 | } 84 | 85 | return d, nil 86 | } 87 | } 88 | 89 | return nil, fmt.Errorf("unknown definition %q", name) 90 | } 91 | -------------------------------------------------------------------------------- /gen/kubespec/testdata/invalid.json: -------------------------------------------------------------------------------- 1 | ////// invalid -------------------------------------------------------------------------------- /gen/log/log.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | import "log" 4 | 5 | func init() { 6 | log.SetFlags(0) 7 | } 8 | 9 | var Debug = false 10 | 11 | func Println(args ...interface{}) { 12 | log.Println(args...) 13 | } 14 | 15 | func Printf(s string, args ...interface{}) { 16 | log.Printf(s, args...) 17 | } 18 | 19 | func Fatalln(args ...interface{}) { 20 | log.Fatalln(args...) 21 | } 22 | 23 | func Fatalf(s string, args ...interface{}) { 24 | log.Fatalf(s, args...) 25 | } 26 | 27 | func Debugln(args ...interface{}) { 28 | if Debug { 29 | log.Println(args...) 30 | } 31 | } 32 | 33 | func Debugf(s string, args ...interface{}) { 34 | if Debug { 35 | log.Printf(s, args...) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /gen/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "io/ioutil" 7 | "os" 8 | "path/filepath" 9 | "regexp" 10 | 11 | "github.com/pkg/errors" 12 | 13 | "github.com/pkg/profile" 14 | 15 | "github.com/kube-jsonnet/k/gen/ksonnet" 16 | "github.com/kube-jsonnet/k/gen/log" 17 | ) 18 | 19 | var ( 20 | Version = "dev" 21 | Vendor = "github.com/kube-jsonnet/k" 22 | ) 23 | 24 | const ( 25 | k8s = "k8s.libsonnet" 26 | k = "k.libsonnet" 27 | ) 28 | 29 | func main() { 30 | outputDir := flag.String("dir", ".", "output directory") 31 | target := flag.String("target", "", " regex pattern to filter apiGroup") 32 | 33 | name := flag.String("name", "k8s.io", "name of the generated library") 34 | maintainer := flag.String("maintainer", "kube-jsonnet", "maintainer of the generated library") 35 | version := flag.String("version", "", " version of the generated library (defaults to specified in swagger.json)") 36 | 37 | pprof := flag.Bool("pprof", false, "Profile execution") 38 | verbose := flag.Bool("v", false, "debug logging") 39 | 40 | flag.Usage = func() { 41 | fmt.Println("gen transforms a Kubernetes swagger.json into a Jsonnet library") 42 | fmt.Println("\nUsage:") 43 | fmt.Println(" ", filepath.Base(os.Args[0]), "[flags] ") 44 | fmt.Println("\nFlags:") 45 | flag.PrintDefaults() 46 | } 47 | flag.Parse() 48 | 49 | log.Debug = *verbose 50 | if *pprof { 51 | defer profile.Start(profile.MemProfile).Stop() 52 | } 53 | 54 | if len(flag.Args()) == 0 { 55 | flag.Usage() 56 | os.Exit(0) 57 | } 58 | 59 | if err := gen(ksonnet.GenOpts{ 60 | OpenAPI: flag.Arg(0), 61 | Target: regexp.MustCompile(*target), 62 | Name: *name, 63 | Version: *version, 64 | Maintainer: *maintainer, 65 | Metadata: ksonnet.Metadata{ 66 | Version: Version, 67 | Vendor: Vendor, 68 | }, 69 | }, *outputDir); err != nil { 70 | log.Fatalln(err) 71 | } 72 | 73 | } 74 | 75 | func gen(opts ksonnet.GenOpts, dir string) error { 76 | lib, err := ksonnet.GenerateLib(opts) 77 | if err != nil { 78 | return err 79 | } 80 | 81 | if err := os.MkdirAll(dir, os.ModePerm); err != nil { 82 | return err 83 | } 84 | 85 | for name, data := range lib.K8s { 86 | if err := writeFile(filepath.Join(dir, name+".libsonnet"), data); err != nil { 87 | return fmt.Errorf("k8s.libsonnet: %w", err) 88 | } 89 | } 90 | 91 | if err := writeFile(filepath.Join(dir, k), lib.Extensions); err != nil { 92 | return fmt.Errorf("k.libsonnet: %w", err) 93 | } 94 | return nil 95 | } 96 | 97 | func writeFile(path string, b []byte) error { 98 | err := ioutil.WriteFile(path, b, 0644) 99 | return errors.Wrapf(err, "write %q", path) 100 | } 101 | -------------------------------------------------------------------------------- /gen/printer/doc.go: -------------------------------------------------------------------------------- 1 | // Package printer implements printing of jsonnet AST nodes. 2 | package printer 3 | -------------------------------------------------------------------------------- /gen/printer/testdata/apply_brace: -------------------------------------------------------------------------------- 1 | params {} 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/apply_with_index: -------------------------------------------------------------------------------- 1 | alpha.beta.charlie('arg1') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/apply_with_multiple_arguments: -------------------------------------------------------------------------------- 1 | self(a, b) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/apply_with_number: -------------------------------------------------------------------------------- 1 | function() 1 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/array: -------------------------------------------------------------------------------- 1 | [foo, self, 'string'] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/array_comp: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | kind: kind, 4 | qty: 4 / 3, 5 | } 6 | for kind in ['Honey Syrup', 'Lemon Juice', 'Farmers Gin'] 7 | ] 8 | -------------------------------------------------------------------------------- /gen/printer/testdata/block_string: -------------------------------------------------------------------------------- 1 | ||| 2 | text 3 | ||| -------------------------------------------------------------------------------- /gen/printer/testdata/boolean: -------------------------------------------------------------------------------- 1 | { 2 | isTrue: true, 3 | isFalse: false, 4 | } 5 | -------------------------------------------------------------------------------- /gen/printer/testdata/chained_apply: -------------------------------------------------------------------------------- 1 | di.withFoo(foo).withBar(bar) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/conditional: -------------------------------------------------------------------------------- 1 | if std.type(foo) == 'array' then { foo: foo } else { foo: [foo] } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/conditional_no_false: -------------------------------------------------------------------------------- 1 | if std.type(foo) == 'array' then { foo: foo } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/declarations: -------------------------------------------------------------------------------- 1 | local a = import 'a'; 2 | local b = 'b'; 3 | local c = deployment.new(); 4 | 5 | {} 6 | -------------------------------------------------------------------------------- /gen/printer/testdata/dollar: -------------------------------------------------------------------------------- 1 | $ 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/field_id_keywords: -------------------------------------------------------------------------------- 1 | { 2 | 'error': 'value', 3 | 'local': 'value', 4 | unquoteme: 'value', 5 | 'but-not-me': 'value', 6 | 'nor:me': 'value', 7 | } 8 | -------------------------------------------------------------------------------- /gen/printer/testdata/field_with_string_key: -------------------------------------------------------------------------------- 1 | { 2 | key:: value, 3 | } 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/function: -------------------------------------------------------------------------------- 1 | function() {} 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/function_with_args: -------------------------------------------------------------------------------- 1 | { 2 | foo(one, two):: myVar + 2, 3 | } 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/function_with_no_args: -------------------------------------------------------------------------------- 1 | { 2 | foo():: 1 + 2, 3 | } 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/function_with_optional_args_ast: -------------------------------------------------------------------------------- 1 | { 2 | alpha(one, two, opt1=1):: myVar + 2, 3 | beta(one, two, opt1={ foo: 1 }):: myVar + 2, 4 | } 5 | -------------------------------------------------------------------------------- /gen/printer/testdata/function_with_optional_args_astext: -------------------------------------------------------------------------------- 1 | { 2 | alpha(one, two, opt1=1):: myVar + 2, 3 | beta(one, two, opt1={ foo: 1 }):: myVar + 2, 4 | } 5 | -------------------------------------------------------------------------------- /gen/printer/testdata/importstr: -------------------------------------------------------------------------------- 1 | importstr 'file.txt' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/index: -------------------------------------------------------------------------------- 1 | { 2 | foo:: foo.bar.baz, 3 | } 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/index_quote_name: -------------------------------------------------------------------------------- 1 | { 2 | foo:: foo['bar-dashed']['baz-dashed'], 3 | } 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/index_quote_name_2: -------------------------------------------------------------------------------- 1 | std.extVar('__ksonnet/params').components['my-service'] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/index_with_index: -------------------------------------------------------------------------------- 1 | { 2 | foo:: foo.bar.baz, 3 | } 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/literal: -------------------------------------------------------------------------------- 1 | { 2 | foo: 'value', 3 | } 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/literal_with_newline: -------------------------------------------------------------------------------- 1 | { 2 | foo: 'value1\nvalue2', 3 | } 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/literal_with_single_quote: -------------------------------------------------------------------------------- 1 | { 2 | foo: 'value1', 3 | } 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/local: -------------------------------------------------------------------------------- 1 | { 2 | local bar = {}, 3 | } 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/local_function_with_args: -------------------------------------------------------------------------------- 1 | { 2 | local foo(one, two) = myVar + 2, 3 | } 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/local_with_function: -------------------------------------------------------------------------------- 1 | local foo() = 'a'; 2 | 3 | {} 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/local_with_multiline_function: -------------------------------------------------------------------------------- 1 | local foo() = 2 | local a = { a: 'a' }; 3 | local b = { b: 'b' }; 4 | 5 | a + b; 6 | 7 | {} 8 | -------------------------------------------------------------------------------- /gen/printer/testdata/multi_line_comments: -------------------------------------------------------------------------------- 1 | { 2 | // line 1 3 | // 4 | // line 3 5 | // line 4 6 | local bar = {}, 7 | } 8 | -------------------------------------------------------------------------------- /gen/printer/testdata/nil_node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kube-jsonnet/k/6ed7b817024f60319ac424a5119844f29b291230/gen/printer/testdata/nil_node -------------------------------------------------------------------------------- /gen/printer/testdata/null: -------------------------------------------------------------------------------- 1 | null 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/object: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/object_comp: -------------------------------------------------------------------------------- 1 | { 2 | field: { 3 | [x]: envParams.components[x] + globals 4 | for x in std.objectFields(envParams.components) 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /gen/printer/testdata/object_field_trailing_comma: -------------------------------------------------------------------------------- 1 | { 2 | // a comment 3 | foo: 'value', 4 | } 5 | -------------------------------------------------------------------------------- /gen/printer/testdata/object_field_with_comment: -------------------------------------------------------------------------------- 1 | { 2 | // a comment 3 | foo: 'value', 4 | } 5 | -------------------------------------------------------------------------------- /gen/printer/testdata/object_field_with_local: -------------------------------------------------------------------------------- 1 | { 2 | fn():: 3 | local foo = 'a'; 4 | 5 | {}, 6 | } 7 | -------------------------------------------------------------------------------- /gen/printer/testdata/object_mixin: -------------------------------------------------------------------------------- 1 | { 2 | foo+:: {}, 3 | } 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/object_mixin_with_string_index: -------------------------------------------------------------------------------- 1 | { 2 | id+: {}, 3 | } 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/object_with_hidden_field: -------------------------------------------------------------------------------- 1 | { 2 | foo:: {}, 3 | bar:: {}, 4 | } 5 | -------------------------------------------------------------------------------- /gen/printer/testdata/object_with_nested_object: -------------------------------------------------------------------------------- 1 | { 2 | foo:: { 3 | bar:: {}, 4 | }, 5 | } 6 | -------------------------------------------------------------------------------- /gen/printer/testdata/self_apply: -------------------------------------------------------------------------------- 1 | self() 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/super_index: -------------------------------------------------------------------------------- 1 | super.metadata 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/trimmed_whitespace_in_tests: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/array.jsonnet: -------------------------------------------------------------------------------- 1 | [1, 2, 1 + 2] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/array_index1.jsonnet: -------------------------------------------------------------------------------- 1 | [1][0] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/array_index2.jsonnet: -------------------------------------------------------------------------------- 1 | [1, 2, 3][0] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/array_index3.jsonnet: -------------------------------------------------------------------------------- 1 | [1, 2, 3][1] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/array_index4.jsonnet: -------------------------------------------------------------------------------- 1 | [1, 2, 3][2] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/array_out_of_bounds.jsonnet: -------------------------------------------------------------------------------- 1 | [][0] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/array_out_of_bounds2.jsonnet: -------------------------------------------------------------------------------- 1 | [1, 2, 3][3] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/array_out_of_bounds3.jsonnet: -------------------------------------------------------------------------------- 1 | [][-1] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/array_out_of_bounds4.jsonnet: -------------------------------------------------------------------------------- 1 | [1, 2, 3][42] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/array_plus_bad.jsonnet: -------------------------------------------------------------------------------- 1 | [] + 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/arrcomp.jsonnet: -------------------------------------------------------------------------------- 1 | [ 2 | x 3 | for x in [] 4 | ] 5 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/arrcomp2.jsonnet: -------------------------------------------------------------------------------- 1 | [ 2 | x 3 | for x in [1, 2, 3] 4 | ] 5 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/arrcomp3.jsonnet: -------------------------------------------------------------------------------- 1 | [ 2 | [var, var2] 3 | for var in [1, 2, 3] 4 | for var2 in ['a', 'b', 'c'] 5 | ] 6 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/arrcomp4.jsonnet: -------------------------------------------------------------------------------- 1 | [ 2 | y 3 | for x in [1, 2, 3] 4 | for y in [x + 1] 5 | ] 6 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/arrcomp5.jsonnet: -------------------------------------------------------------------------------- 1 | [ 2 | y 3 | for y in [x + 1] 4 | for x in [1, 2, 3] 5 | ] 6 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/arrcomp6.jsonnet: -------------------------------------------------------------------------------- 1 | [ 2 | [x, y, z] 3 | for x in [1] 4 | for y in [2] 5 | for z in [3] 6 | ] 7 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/arrcomp7.jsonnet: -------------------------------------------------------------------------------- 1 | [ 2 | [a1, a2, a3, a4, a5, a6, a7, a8] 3 | for a1 in [1, 2] 4 | for a2 in [3, 4] 5 | for a3 in [5, 6] 6 | for a4 in [7, 8] 7 | for a5 in [9, 10] 8 | for a6 in [11, 12] 9 | for a7 in [13, 14] 10 | if a7 % 2 == 1 11 | if a4 % 2 == 0 12 | if a2 % 2 == 0 13 | if a1 % 2 == 1 14 | for a8 in [15, 16] 15 | ] 16 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/arrcomp_if.jsonnet: -------------------------------------------------------------------------------- 1 | [ 2 | x 3 | for x in [1, 2, 3, 4, 5] 4 | if x > 3 5 | ] 6 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/arrcomp_if2.jsonnet: -------------------------------------------------------------------------------- 1 | [ 2 | [x, y] 3 | for x in [1, 2, 3, 4, 5] 4 | for y in [1, 2, 3, 4, 5] 5 | if x > 3 6 | if y < 4 7 | ] 8 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/arrcomp_if3.jsonnet: -------------------------------------------------------------------------------- 1 | [ 2 | [x, y] 3 | for x in [1, 2, 3, 4, 5] 4 | if x < 3 5 | for y in [1, 2, 3, 4, 5] 6 | if y > 2 7 | ] 8 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/arrcomp_if4.jsonnet: -------------------------------------------------------------------------------- 1 | [ 2 | [x, y] 3 | for x in [1, 2, 3, 4, 5] 4 | if y == 3 5 | for y in [1, 2, 3, 4, 5] 6 | ] 7 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/arrcomp_if5.jsonnet: -------------------------------------------------------------------------------- 1 | [ 2 | x 3 | for x in [] 4 | if error 'x' 5 | ] 6 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/arrcomp_if6.jsonnet: -------------------------------------------------------------------------------- 1 | [ 2 | x 3 | for x in [1] 4 | if error 'x' 5 | ] 6 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/arrcomp_if7.jsonnet: -------------------------------------------------------------------------------- 1 | [ 2 | x 3 | for x in [1, 2, 3] 4 | if 42 5 | ] 6 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/assert.jsonnet: -------------------------------------------------------------------------------- 1 | assert true; true 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/assert2.jsonnet: -------------------------------------------------------------------------------- 1 | assert 42 == 42; true 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/assert3.jsonnet: -------------------------------------------------------------------------------- 1 | assert 42 != 42; 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/assert_equal.jsonnet: -------------------------------------------------------------------------------- 1 | std.assertEqual([], []) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/assert_equal2.jsonnet: -------------------------------------------------------------------------------- 1 | std.assertEqual({}, {}) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/assert_equal3.jsonnet: -------------------------------------------------------------------------------- 1 | std.assertEqual({ x:: 42 }, {}) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/assert_failed.jsonnet: -------------------------------------------------------------------------------- 1 | assert false; true 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/assert_failed_custom.jsonnet: -------------------------------------------------------------------------------- 1 | assert false : 'Custom Message'; true 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/binaryNot.jsonnet: -------------------------------------------------------------------------------- 1 | ~12345 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/binaryNot2.jsonnet: -------------------------------------------------------------------------------- 1 | ~'xxx' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_and.jsonnet: -------------------------------------------------------------------------------- 1 | 0 & 0 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_and2.jsonnet: -------------------------------------------------------------------------------- 1 | 1337 & 0 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_and3.jsonnet: -------------------------------------------------------------------------------- 1 | 1e30 & 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_and4.jsonnet: -------------------------------------------------------------------------------- 1 | 1 & error 'x' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_and5.jsonnet: -------------------------------------------------------------------------------- 1 | -1337 & 1337 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_and6.jsonnet: -------------------------------------------------------------------------------- 1 | -42 & 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_or.jsonnet: -------------------------------------------------------------------------------- 1 | 0 | 0 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_or10.jsonnet: -------------------------------------------------------------------------------- 1 | 'xxx' | 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_or2.jsonnet: -------------------------------------------------------------------------------- 1 | 0 | 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_or3.jsonnet: -------------------------------------------------------------------------------- 1 | 42 | 0 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_or4.jsonnet: -------------------------------------------------------------------------------- 1 | 42 | 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_or5.jsonnet: -------------------------------------------------------------------------------- 1 | 1337 | 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_or6.jsonnet: -------------------------------------------------------------------------------- 1 | 1 | 2 | 3 | 4 | 5 | 6 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_or7.jsonnet: -------------------------------------------------------------------------------- 1 | 1 | 2 | 4 | 8 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_or8.jsonnet: -------------------------------------------------------------------------------- 1 | -42 | 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_or9.jsonnet: -------------------------------------------------------------------------------- 1 | (1 << 62) | 1 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_shift.jsonnet: -------------------------------------------------------------------------------- 1 | 1 << 10 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_shift2.jsonnet: -------------------------------------------------------------------------------- 1 | 1024 >> 10 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_shift3.jsonnet: -------------------------------------------------------------------------------- 1 | 1 << 20 >> 20 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_shift4.jsonnet: -------------------------------------------------------------------------------- 1 | 10000 >> (-10) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_xor.jsonnet: -------------------------------------------------------------------------------- 1 | 0 ^ 0 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_xor2.jsonnet: -------------------------------------------------------------------------------- 1 | 0 ^ 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_xor3.jsonnet: -------------------------------------------------------------------------------- 1 | 42 ^ 0 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_xor4.jsonnet: -------------------------------------------------------------------------------- 1 | 42 ^ 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_xor5.jsonnet: -------------------------------------------------------------------------------- 1 | 42 ^ 7 ^ 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_xor6.jsonnet: -------------------------------------------------------------------------------- 1 | 1 ^ 1 ^ 1 ^ 1 ^ 1 ^ 1 ^ 1 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_xor7.jsonnet: -------------------------------------------------------------------------------- 1 | 1 ^ error 'x' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_xor8.jsonnet: -------------------------------------------------------------------------------- 1 | 42 ^ 1 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/bitwise_xor9.jsonnet: -------------------------------------------------------------------------------- 1 | 42 ^ 2 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/boolean_literal.jsonnet: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtinChar.jsonnet: -------------------------------------------------------------------------------- 1 | std.char(65) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtinChar2.jsonnet: -------------------------------------------------------------------------------- 1 | std.char(0) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtinChar3.jsonnet: -------------------------------------------------------------------------------- 1 | std.char(-1) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtinChar4.jsonnet: -------------------------------------------------------------------------------- 1 | std.char(42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtinChar5.jsonnet: -------------------------------------------------------------------------------- 1 | std.char(1114112) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtinChar6.jsonnet: -------------------------------------------------------------------------------- 1 | std.char(1114111) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtinChar7.jsonnet: -------------------------------------------------------------------------------- 1 | std.char('xxx') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtinObjectFieldsEx.jsonnet: -------------------------------------------------------------------------------- 1 | std.objectFieldsEx({ 2 | x: 1, 3 | y:: 1, 4 | z::: 2, 5 | }, false) 6 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtinObjectFieldsExWithHidden.jsonnet: -------------------------------------------------------------------------------- 1 | std.objectFieldsEx({ 2 | x: 1, 3 | y:: 1, 4 | z::: 2, 5 | }, true) 6 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtinObjectHasEx.jsonnet: -------------------------------------------------------------------------------- 1 | std.objectHasEx({ x: 1, y:: 1, z::: 2 }, 'x', false) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_acos.jsonnet: -------------------------------------------------------------------------------- 1 | std.acos(1) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_asin.jsonnet: -------------------------------------------------------------------------------- 1 | std.asin(1) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_atan.jsonnet: -------------------------------------------------------------------------------- 1 | std.atan(1) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_ceil.jsonnet: -------------------------------------------------------------------------------- 1 | std.ceil(2.5) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_cos.jsonnet: -------------------------------------------------------------------------------- 1 | std.cos(1) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_exp.jsonnet: -------------------------------------------------------------------------------- 1 | std.exp(12) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_exp2.jsonnet: -------------------------------------------------------------------------------- 1 | std.exp(0) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_exp3.jsonnet: -------------------------------------------------------------------------------- 1 | std.exp(1000) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_exp4.jsonnet: -------------------------------------------------------------------------------- 1 | std.exp(100) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_exp5.jsonnet: -------------------------------------------------------------------------------- 1 | std.exp(100000000000000000000) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_exp6.jsonnet: -------------------------------------------------------------------------------- 1 | std.exp(-2) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_exp7.jsonnet: -------------------------------------------------------------------------------- 1 | std.exp(-100000000000000000) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_exp8.jsonnet: -------------------------------------------------------------------------------- 1 | std.exp(3.14) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_floor.jsonnet: -------------------------------------------------------------------------------- 1 | std.floor(2.5) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_log.jsonnet: -------------------------------------------------------------------------------- 1 | std.log(42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_log2.jsonnet: -------------------------------------------------------------------------------- 1 | std.log(std.exp(100)) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_log3.jsonnet: -------------------------------------------------------------------------------- 1 | std.log(100000000000000000000000000000000000) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_log4.jsonnet: -------------------------------------------------------------------------------- 1 | std.log(3.14) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_log5.jsonnet: -------------------------------------------------------------------------------- 1 | std.log(0) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_log6.jsonnet: -------------------------------------------------------------------------------- 1 | std.log(0.0000000000000001) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_log7.jsonnet: -------------------------------------------------------------------------------- 1 | std.log(-1) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_log8.jsonnet: -------------------------------------------------------------------------------- 1 | std.log(-1000000000000) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_sin.jsonnet: -------------------------------------------------------------------------------- 1 | std.sin(1) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_sqrt.jsonnet: -------------------------------------------------------------------------------- 1 | std.sqrt(4) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_sqrt2.jsonnet: -------------------------------------------------------------------------------- 1 | std.sqrt('cookie') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/builtin_tan.jsonnet: -------------------------------------------------------------------------------- 1 | std.tan(1) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/div1.jsonnet: -------------------------------------------------------------------------------- 1 | 2 / 2 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/div2.jsonnet: -------------------------------------------------------------------------------- 1 | 1337 / 2 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/div3.jsonnet: -------------------------------------------------------------------------------- 1 | 1 / 1e30 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/div4.jsonnet: -------------------------------------------------------------------------------- 1 | 1 / (1e-160) / (1e-160) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/empty_array.jsonnet: -------------------------------------------------------------------------------- 1 | [] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/empty_object.jsonnet: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/equals.jsonnet: -------------------------------------------------------------------------------- 1 | 42 == 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/error.jsonnet: -------------------------------------------------------------------------------- 1 | error '42' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/error_from_array.jsonnet: -------------------------------------------------------------------------------- 1 | [error 'xxx'][0] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/error_function_fail.jsonnet: -------------------------------------------------------------------------------- 1 | error (function(x) 42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/escaped_fields.jsonnet: -------------------------------------------------------------------------------- 1 | { 2 | '"': null, 3 | "'": null, 4 | ||| 5 | 1234 6 | 1234 7 | |||: null, 8 | } 9 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/extvar_code.jsonnet: -------------------------------------------------------------------------------- 1 | std.extVar('codeVar') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/extvar_error.jsonnet: -------------------------------------------------------------------------------- 1 | std.extVar('errorVar') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/extvar_hermetic.jsonnet: -------------------------------------------------------------------------------- 1 | local x = 42; 2 | 3 | std.extVar('UndeclaredX') 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/extvar_mutually_recursive.jsonnet: -------------------------------------------------------------------------------- 1 | std.extVar('mutuallyRecursiveVar1') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/extvar_not_a_string.jsonnet: -------------------------------------------------------------------------------- 1 | std.extVar(42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/extvar_self_recursive.jsonnet: -------------------------------------------------------------------------------- 1 | std.extVar('selfRecursiveVar') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/extvar_static_error.jsonnet: -------------------------------------------------------------------------------- 1 | std.extVar('staticErrorVar') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/extvar_string.jsonnet: -------------------------------------------------------------------------------- 1 | std.extVar('stringVar') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/extvar_unknown.jsonnet: -------------------------------------------------------------------------------- 1 | std.extVar('UNKNOWN') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/function_call.jsonnet: -------------------------------------------------------------------------------- 1 | (function() 42)() 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/function_capturing.jsonnet: -------------------------------------------------------------------------------- 1 | local y = 17; 2 | 3 | (function(x) y)(42) 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/function_in_object.jsonnet: -------------------------------------------------------------------------------- 1 | local r = { f: function(x) 42 }; 2 | 3 | r.f(null) 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/function_manifested.jsonnet: -------------------------------------------------------------------------------- 1 | { 2 | f(x): 3, 3 | } 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/function_no_params.jsonnet: -------------------------------------------------------------------------------- 1 | function() 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/function_plus_string.jsonnet: -------------------------------------------------------------------------------- 1 | (function() 42) + 'xxx' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/function_too_many_params.jsonnet: -------------------------------------------------------------------------------- 1 | function(x) 3 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/function_with_argument.jsonnet: -------------------------------------------------------------------------------- 1 | (function(x) x)(42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/greater.jsonnet: -------------------------------------------------------------------------------- 1 | if 1 > 2 then error 'x' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/greaterEq.jsonnet: -------------------------------------------------------------------------------- 1 | if 1 >= 2 then error 'x' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/greaterEq2.jsonnet: -------------------------------------------------------------------------------- 1 | if 1 >= 1 then 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/argcapture_builtin_call.jsonnet: -------------------------------------------------------------------------------- 1 | local r = { f(x): local a = x; std.length(a) }; r.f([1, 2, 3]) -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/assert_equal5.jsonnet: -------------------------------------------------------------------------------- 1 | std.assertEqual("\n ", "\n") 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/assert_equal6.jsonnet: -------------------------------------------------------------------------------- 1 | std.assertEqual("\u001b[31m", "") 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/call_number.jsonnet: -------------------------------------------------------------------------------- 1 | 42() -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/double_thunk.jsonnet: -------------------------------------------------------------------------------- 1 | local x = local y = error "xxx"; y; x 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/escaped_single_quote.jsonnet: -------------------------------------------------------------------------------- 1 | "\\'" -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/false.jsonnet: -------------------------------------------------------------------------------- 1 | false 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/fieldname_not_string.jsonnet: -------------------------------------------------------------------------------- 1 | { [1234]: 42 } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/filled_thunk.jsonnet: -------------------------------------------------------------------------------- 1 | local x = [1, 2, 3]; x[1] + x[1] -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/method_call.jsonnet: -------------------------------------------------------------------------------- 1 | local r = {f(a): 42};r.f(null) -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/missing_super.jsonnet: -------------------------------------------------------------------------------- 1 | { x: super.x } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/nonexistent_import.jsonnet: -------------------------------------------------------------------------------- 1 | importstr 'no chance a file with this name exists' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/nonexistent_import_crazy.jsonnet: -------------------------------------------------------------------------------- 1 | importstr "ąęółńśćźż \" \' \n\n\t\t" 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/proto_object_comp.jsonnet: -------------------------------------------------------------------------------- 1 | [{[v]: v} for v in ["x", "y", "z"]] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/self.jsonnet: -------------------------------------------------------------------------------- 1 | {x: self.y, y: 42}.x -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/stackbug-regression-test.jsonnet: -------------------------------------------------------------------------------- 1 | local xxx=0; xxx==0 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/static_error_eof.jsonnet: -------------------------------------------------------------------------------- 1 | local x = 5 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/std.codepoint2.jsonnet: -------------------------------------------------------------------------------- 1 | std.codepoint("\u0000") 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/std.toString7.jsonnet: -------------------------------------------------------------------------------- 1 | std.toString([{ 2 | a: [42, 42, { 3 | }], 4 | ["b"]: 1337 5 | }, 42, "text", 42]) 6 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/string2.jsonnet: -------------------------------------------------------------------------------- 1 | "\"xxx\"" 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/too_many_arguments.jsonnet: -------------------------------------------------------------------------------- 1 | (function(x, y, z) 42)(1, 2, 3, 4) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/unicode.jsonnet: -------------------------------------------------------------------------------- 1 | "\u263A" -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/unicode2.jsonnet: -------------------------------------------------------------------------------- 1 | "\u263a" -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/variable.jsonnet: -------------------------------------------------------------------------------- 1 | local x = 2; 2 | 3 | x -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/variable_not_visible.jsonnet: -------------------------------------------------------------------------------- 1 | local x1 = local nested = 42; 2 | 3 | nested, x2 = nested; x2 -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/holding/verbatim_string.jsonnet: -------------------------------------------------------------------------------- 1 | @"blah ☺" -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/ifthen_false.jsonnet: -------------------------------------------------------------------------------- 1 | if true then 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/ifthenelse_false.jsonnet: -------------------------------------------------------------------------------- 1 | if false then error 'no way' else 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/ifthenelse_true.jsonnet: -------------------------------------------------------------------------------- 1 | if true then 42 else error 'no way' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/import.jsonnet: -------------------------------------------------------------------------------- 1 | import 'true.jsonnet' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/import2.jsonnet: -------------------------------------------------------------------------------- 1 | import 'false.jsonnet' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/import3.jsonnet: -------------------------------------------------------------------------------- 1 | importstr 'true.jsonnet' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/import4.jsonnet: -------------------------------------------------------------------------------- 1 | importstr 'false.jsonnet' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/import_various_literals.jsonnet: -------------------------------------------------------------------------------- 1 | [ 2 | import 'true.jsonnet', 3 | import 'true.jsonnet', 4 | import @"true.jsonnet", 5 | import @'true.jsonnet', 6 | ] 7 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/in.jsonnet: -------------------------------------------------------------------------------- 1 | 'x' in { x: 42 } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/in2.jsonnet: -------------------------------------------------------------------------------- 1 | 'x' in {} 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/in3.jsonnet: -------------------------------------------------------------------------------- 1 | 'x' in { x: 42, y: 42 } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/in4.jsonnet: -------------------------------------------------------------------------------- 1 | 'x' in { assert false } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/insuper.jsonnet: -------------------------------------------------------------------------------- 1 | { 2 | x: 42, 3 | } { 4 | assert 'x' in super, 5 | } 6 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/insuper2.jsonnet: -------------------------------------------------------------------------------- 1 | {} { x: 'x' in super } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/insuper4.jsonnet: -------------------------------------------------------------------------------- 1 | 'x' in super 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/lazy.jsonnet: -------------------------------------------------------------------------------- 1 | local x = { x: error 'blah' }, f(x) = 42, z = x.x; 2 | 3 | f(x.x) 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/lazy_operator1.jsonnet: -------------------------------------------------------------------------------- 1 | false && error "shouldn't happen" 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/lazy_operator2.jsonnet: -------------------------------------------------------------------------------- 1 | true && error 'should happen' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/less.jsonnet: -------------------------------------------------------------------------------- 1 | if 2 < 1 then error 'x' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/lessEq.jsonnet: -------------------------------------------------------------------------------- 1 | if 2 <= 1 then error 'x' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/lessEq2.jsonnet: -------------------------------------------------------------------------------- 1 | if 2 <= 2 then 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/local1.jsonnet: -------------------------------------------------------------------------------- 1 | local params = std.extVar('__ksonnet/params'); 2 | local globals = import 'globals.libsonnet'; 3 | local envParams = params { 4 | components+: { 5 | guestbook+: { 6 | name: 'guestbook-dev', 7 | }, 8 | }, 9 | }; 10 | 11 | { 12 | components: { 13 | [x]: envParams.components[x] + globals 14 | for x in std.objectFields(envParams.components) 15 | }, 16 | } 17 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/local_within_nested_object.jsonnet: -------------------------------------------------------------------------------- 1 | local a = 42; 2 | 3 | { x: { x: a } }.x.x 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/modulo.jsonnet: -------------------------------------------------------------------------------- 1 | std.modulo(16, 3) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/modulo2.jsonnet: -------------------------------------------------------------------------------- 1 | std.modulo(42, 3) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/modulo3.jsonnet: -------------------------------------------------------------------------------- 1 | std.modulo(16, -3) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/modulo4.jsonnet: -------------------------------------------------------------------------------- 1 | std.modulo(-16, 3) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/modulo5.jsonnet: -------------------------------------------------------------------------------- 1 | std.modulo(-16, -3) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/modulo6.jsonnet: -------------------------------------------------------------------------------- 1 | std.modulo(15.5, 1) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/modulo7.jsonnet: -------------------------------------------------------------------------------- 1 | std.modulo(42, 2.5) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/mult.jsonnet: -------------------------------------------------------------------------------- 1 | 2 * 2 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/mult2.jsonnet: -------------------------------------------------------------------------------- 1 | 2 * (-2) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/mult3.jsonnet: -------------------------------------------------------------------------------- 1 | 42 * 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/native1.jsonnet: -------------------------------------------------------------------------------- 1 | std.native('jsonToString')('test') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/native2.jsonnet: -------------------------------------------------------------------------------- 1 | std.native('jsonToString')({}) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/native4.jsonnet: -------------------------------------------------------------------------------- 1 | std.native('jsonToString')(error 'xxx') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/native5.jsonnet: -------------------------------------------------------------------------------- 1 | std.native('jsonToString')(function() 42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/native6.jsonnet: -------------------------------------------------------------------------------- 1 | std.native('jsonToString')(x={}) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/native7.jsonnet: -------------------------------------------------------------------------------- 1 | std.native('jsonToString')(y={}) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/native_error.jsonnet: -------------------------------------------------------------------------------- 1 | std.native('nativeError')() 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/native_nonexistent.jsonnet: -------------------------------------------------------------------------------- 1 | std.native('blah') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/number_divided_by_string.jsonnet: -------------------------------------------------------------------------------- 1 | 42 / 'xxx' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/number_times_string.jsonnet: -------------------------------------------------------------------------------- 1 | 42 * 'xxx' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/numeric_literal.jsonnet: -------------------------------------------------------------------------------- 1 | 100 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object.jsonnet: -------------------------------------------------------------------------------- 1 | { x: 1 + 1 } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object2.jsonnet: -------------------------------------------------------------------------------- 1 | { 2 | global: { 3 | restart: false, 4 | }, 5 | components: { 6 | 'guestbook-ui': { 7 | containerPort: 80, 8 | image: 'gcr.io/heptio-images/ks-guestbook-demo:0.2', 9 | name: 'guestbook-ui', 10 | replicas: 5, 11 | servicePort: 80, 12 | type: 'NodePort', 13 | }, 14 | }, 15 | } 16 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object3.jsonnet: -------------------------------------------------------------------------------- 1 | local params = import '../../components/params.libsonnet'; 2 | 3 | params { 4 | components+: { 5 | guestbook+: { 6 | name: 'guestbook-dev', 7 | }, 8 | }, 9 | } 10 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_comp.jsonnet: -------------------------------------------------------------------------------- 1 | { 2 | [x]: 42 3 | for x in ['a', 'b', 'c'] 4 | } 5 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_comp_binary.jsonnet: -------------------------------------------------------------------------------- 1 | local o = { 2 | a: 'a', 3 | b: 'b', 4 | }; 5 | 6 | { 7 | ['pre-' + key]: o[key] 8 | for key in std.objectFields(o) 9 | } -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_comp_dollar.jsonnet: -------------------------------------------------------------------------------- 1 | { 2 | [x]: if x == 'a' then 42 else $.a + 1 3 | for x in ['a', 'b', 'c'] 4 | } 5 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_comp_err_elem.jsonnet: -------------------------------------------------------------------------------- 1 | { 2 | ['x']: error 'xxx' 3 | for x in [1] 4 | } 5 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_comp_err_index.jsonnet: -------------------------------------------------------------------------------- 1 | { 2 | [error 'xxx']: 42 3 | for x in [1] 4 | } 5 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_comp_if.jsonnet: -------------------------------------------------------------------------------- 1 | { 2 | [x]: 42 3 | for x in ['a', 'b', 'bb', 'c'] 4 | if x[0] == 'b' 5 | } 6 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_comp_int_index.jsonnet: -------------------------------------------------------------------------------- 1 | { 2 | [x]: x 3 | for x in [1, 2, 3] 4 | } 5 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_comp_local.jsonnet: -------------------------------------------------------------------------------- 1 | local domain = '.example.org'; 2 | local services = ['one', 'two']; 3 | local computedServices = [ 4 | local serviceName = service; 5 | local serviceUrl = service + domain; 6 | 7 | { [serviceName]: serviceUrl } 8 | for service in services 9 | ]; 10 | 11 | std.prune(computedServices) -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_comp_super.jsonnet: -------------------------------------------------------------------------------- 1 | { x: 1, y: 2, z: 3 } + 2 | { 3 | [v]: [super.x, v] 4 | for v in ['x', 'y', 'z'] 5 | } + 6 | { 7 | [v]: self.q + v 8 | for v in ['a', 'b', 'c'] 9 | } + 10 | { q: 42 } 11 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_field1.jsonnet: -------------------------------------------------------------------------------- 1 | local command = 'command'; 2 | 3 | { 4 | [if command != 'null' then 'command']: [command], 5 | } -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_hidden.jsonnet: -------------------------------------------------------------------------------- 1 | local progressive = { f1: 1, f2:: 2, f3::: 3 }; 2 | local all_inherit = { f1: 4, f2: 5, f3: 6 }; 3 | local all_hidden = { f1:: 7, f2:: 8, f3:: 9 }; 4 | local all_visible = { f1::: 10, f2::: 11, f3::: 12 }; 5 | 6 | [ 7 | progressive, 8 | all_inherit, 9 | all_hidden, 10 | all_visible, 11 | progressive + all_inherit, 12 | progressive + all_hidden, 13 | progressive + all_visible, 14 | all_hidden + all_visible, 15 | all_visible + all_hidden, 16 | all_hidden + all_inherit, 17 | all_visible + all_inherit, 18 | all_inherit + all_inherit, 19 | all_inherit + progressive, 20 | all_visible + progressive, 21 | all_hidden + progressive, 22 | progressive + (all_hidden + all_inherit), 23 | ] 24 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_local.jsonnet: -------------------------------------------------------------------------------- 1 | { local foo(bar) = bar, baz: foo(42) } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_local_self_super.jsonnet: -------------------------------------------------------------------------------- 1 | { local x = self, y:: x, z: 42, foo: 'xxx' } { local x = super.y, foo: x.z, bar: x.foo, baz: super.foo } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_plus_bad.jsonnet: -------------------------------------------------------------------------------- 1 | {} + 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_sum.jsonnet: -------------------------------------------------------------------------------- 1 | {} + {} 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_sum2.jsonnet: -------------------------------------------------------------------------------- 1 | { a: 1 } + { a: 2 } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_sum3.jsonnet: -------------------------------------------------------------------------------- 1 | { a: 1 } + { b: 2 } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_super.jsonnet: -------------------------------------------------------------------------------- 1 | { a: 1 } + { a: 2, b: super.a } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_super_deep.jsonnet: -------------------------------------------------------------------------------- 1 | { a: 1 } + {} + { a: 2, b: super.a } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/object_super_within.jsonnet: -------------------------------------------------------------------------------- 1 | { a: 42, d: 1 } + { c: super.d, d: 42 } + { a: 2, b: super.c, d: 42 } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args.jsonnet: -------------------------------------------------------------------------------- 1 | local foo(x=42) = x; 2 | 3 | foo() 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args10.jsonnet: -------------------------------------------------------------------------------- 1 | (function(x, y) x)(y=1, x=2) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args11.jsonnet: -------------------------------------------------------------------------------- 1 | (function(x, y) 42)(42, x=42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args12.jsonnet: -------------------------------------------------------------------------------- 1 | (function(x=42, y=42) 42)(y=42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args13.jsonnet: -------------------------------------------------------------------------------- 1 | (function(x, y) 42)(x=42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args14.jsonnet: -------------------------------------------------------------------------------- 1 | (function(a=b, b=a) 42)() 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args15.jsonnet: -------------------------------------------------------------------------------- 1 | { g: 42, f(a=self.g): a }.f() 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args16.jsonnet: -------------------------------------------------------------------------------- 1 | (function(x=17) x)(42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args17.jsonnet: -------------------------------------------------------------------------------- 1 | (function(x, y=42) x + y)(y=1, x=2) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args18.jsonnet: -------------------------------------------------------------------------------- 1 | (function(a1=1, a2=a1 + 1, a3=a2 + 1, a4=a3 + 1) [a1, a2, a3, a4])(a1=42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args19.jsonnet: -------------------------------------------------------------------------------- 1 | (function(a1=a2 + 1, a2=a3 + 1, a3=a4 + 1, a4=1) [a1, a2, a3, a4])(a4=42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args2.jsonnet: -------------------------------------------------------------------------------- 1 | local x = 1; 2 | local foo(x=2, y=3, z=x) = { 3 | x: x, 4 | y: y, 5 | z: z, 6 | }; 7 | local x = 4; 8 | 9 | foo(y=x) 10 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args20.jsonnet: -------------------------------------------------------------------------------- 1 | (function(x, a1=[x, a2[1] + 1], a2=[a1[0] + 1, a3[1] + 1], a3=[a2[0] + 1, a4[1] + 1], a4=[a3[0] + 1, a4[0] + 1]) [a1, a2, a3, a4])(x=42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args21.jsonnet: -------------------------------------------------------------------------------- 1 | local foo(x=2, z=x) = x; 2 | 3 | foo() 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args22.jsonnet: -------------------------------------------------------------------------------- 1 | local foo(x) = local bar(y=x) = [x, y]; 2 | 3 | bar; 4 | 5 | [foo(42)(), foo(42)(17)] 6 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args3.jsonnet: -------------------------------------------------------------------------------- 1 | local x = 1; 2 | local foo(x=2, y=3, z=x) = { 3 | x: x, 4 | y: y, 5 | z: z, 6 | }; 7 | 8 | foo(y=x) 9 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args4.jsonnet: -------------------------------------------------------------------------------- 1 | local x = 1; 2 | local foo(x=2, y=3, z=x) = { 3 | x: x, 4 | y: y, 5 | z: z, 6 | }; 7 | local x = 4; 8 | 9 | foo(x=5, y=x) 10 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args5.jsonnet: -------------------------------------------------------------------------------- 1 | local foo(x, y=x) = y; 2 | 3 | foo(42) 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args6.jsonnet: -------------------------------------------------------------------------------- 1 | local foo(x, y=x) = y; 2 | 3 | foo(x=42) 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args7.jsonnet: -------------------------------------------------------------------------------- 1 | local foo(x) = x; 2 | 3 | foo(x=42) 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args8.jsonnet: -------------------------------------------------------------------------------- 1 | local foo(x=42) = x; 2 | 3 | foo(y=17) 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/optional_args9.jsonnet: -------------------------------------------------------------------------------- 1 | (function(x) x)(42, x=42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/or.jsonnet: -------------------------------------------------------------------------------- 1 | false || false 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/or2.jsonnet: -------------------------------------------------------------------------------- 1 | false || true 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/or3.jsonnet: -------------------------------------------------------------------------------- 1 | true || error 'xxx' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/or4.jsonnet: -------------------------------------------------------------------------------- 1 | false || error 'xxx' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/or5.jsonnet: -------------------------------------------------------------------------------- 1 | 'xxx' || true 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/or6.jsonnet: -------------------------------------------------------------------------------- 1 | false || 'xxx' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/percent_format_float.jsonnet: -------------------------------------------------------------------------------- 1 | '%f' % 0 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/percent_format_str.jsonnet: -------------------------------------------------------------------------------- 1 | 'x %s' % ['y'] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/percent_format_str2.jsonnet: -------------------------------------------------------------------------------- 1 | 'x %s' % 'y' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/percent_format_str3.jsonnet: -------------------------------------------------------------------------------- 1 | 'x %s %s' % ['y', 'z'] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/percent_format_str4.jsonnet: -------------------------------------------------------------------------------- 1 | 'x %s' % ['y', 'z'] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/percent_format_str5.jsonnet: -------------------------------------------------------------------------------- 1 | 'x %s %s' % ['y'] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/percent_format_str6.jsonnet: -------------------------------------------------------------------------------- 1 | 'x %s %s' % 'y' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/percent_format_str7.jsonnet: -------------------------------------------------------------------------------- 1 | 'x %d' % ['y'] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/percent_format_str8.jsonnet: -------------------------------------------------------------------------------- 1 | 'x %(a)s %(b)s' % { a: 'y', b: 'z' } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/percent_mod_int.jsonnet: -------------------------------------------------------------------------------- 1 | 42 % 5 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/percent_mod_int2.jsonnet: -------------------------------------------------------------------------------- 1 | 42 % -5 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/percent_mod_int3.jsonnet: -------------------------------------------------------------------------------- 1 | -42 % 5 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/percent_mod_int4.jsonnet: -------------------------------------------------------------------------------- 1 | -42 % -5 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/percent_mod_int5.jsonnet: -------------------------------------------------------------------------------- 1 | 42 % 0 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/percent_mod_int6.jsonnet: -------------------------------------------------------------------------------- 1 | 0 % 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/plus.jsonnet: -------------------------------------------------------------------------------- 1 | 1 + 2 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/plus2.jsonnet: -------------------------------------------------------------------------------- 1 | 'a' + 'b' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/plus3.jsonnet: -------------------------------------------------------------------------------- 1 | [1, 2, 3] + [4, 5, 6] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/plus4.jsonnet: -------------------------------------------------------------------------------- 1 | { a: 1, b: 2 } + { a: 3, c: 4 } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/plus5.jsonnet: -------------------------------------------------------------------------------- 1 | 42 + function() 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/plus6.jsonnet: -------------------------------------------------------------------------------- 1 | 'a' + 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/plus7.jsonnet: -------------------------------------------------------------------------------- 1 | 42 + 'a' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/plus9.jsonnet: -------------------------------------------------------------------------------- 1 | 'a' + [1, 2, 3] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/pow.jsonnet: -------------------------------------------------------------------------------- 1 | std.pow(2, 10) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/pow2.jsonnet: -------------------------------------------------------------------------------- 1 | std.pow(10, 2) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/pow3.jsonnet: -------------------------------------------------------------------------------- 1 | std.pow(-1, 3) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/pow4.jsonnet: -------------------------------------------------------------------------------- 1 | std.pow(-1, 0.2) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/pow5.jsonnet: -------------------------------------------------------------------------------- 1 | std.pow(2, 0.2) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/pow8.jsonnet: -------------------------------------------------------------------------------- 1 | std.pow('xxx', 42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/pow9.jsonnet: -------------------------------------------------------------------------------- 1 | std.pow(42, 'xxx') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/recursive_local.jsonnet: -------------------------------------------------------------------------------- 1 | local f(x) = if x == 0 then 0 else 1 + f(x - 1); 2 | 3 | f(5) 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/recursive_thunk.jsonnet: -------------------------------------------------------------------------------- 1 | local bar(th, x) = if x == 0 then error 'xxx' else th; 2 | local foo(x) = bar(foo(x - 1), x - 1); 3 | 4 | foo(3) 5 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/simple_arith1.jsonnet: -------------------------------------------------------------------------------- 1 | 3 + 3 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/simple_arith2.jsonnet: -------------------------------------------------------------------------------- 1 | 3 + 3 + 3 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/simple_arith3.jsonnet: -------------------------------------------------------------------------------- 1 | (3 + 3) + (3 + 3) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/simple_arith_string.jsonnet: -------------------------------------------------------------------------------- 1 | 'aaa' + 'bbb' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/simple_arith_string2.jsonnet: -------------------------------------------------------------------------------- 1 | 'aaa' + '' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/simple_arith_string3.jsonnet: -------------------------------------------------------------------------------- 1 | '' + 'bbb' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/simple_arith_string_empty.jsonnet: -------------------------------------------------------------------------------- 1 | '' + '' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/slice.jsonnet: -------------------------------------------------------------------------------- 1 | [1, 2, 3, 4][1:4:2] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/slice3.jsonnet: -------------------------------------------------------------------------------- 1 | [1, 2, 3, 4][1:2] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/slice4.jsonnet: -------------------------------------------------------------------------------- 1 | [1, 2, 3, 4][:3] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/slice5.jsonnet: -------------------------------------------------------------------------------- 1 | [1, 2, 3, 4][1:] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/slice7.jsonnet: -------------------------------------------------------------------------------- 1 | [1, 2, 3, 4][::2] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.codepoint.jsonnet: -------------------------------------------------------------------------------- 1 | std.codepoint('A') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.codepoint3.jsonnet: -------------------------------------------------------------------------------- 1 | std.codepoint('aa') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.codepoint4.jsonnet: -------------------------------------------------------------------------------- 1 | std.codepoint('ą') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.codepoint5.jsonnet: -------------------------------------------------------------------------------- 1 | std.codepoint('台') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.codepoint6.jsonnet: -------------------------------------------------------------------------------- 1 | std.codepoint('') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.codepoint7.jsonnet: -------------------------------------------------------------------------------- 1 | std.codepoint('ą') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.codepoint8.jsonnet: -------------------------------------------------------------------------------- 1 | std.codepoint(42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.exponent.jsonnet: -------------------------------------------------------------------------------- 1 | std.exponent(0) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.exponent2.jsonnet: -------------------------------------------------------------------------------- 1 | std.exponent(42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.exponent3.jsonnet: -------------------------------------------------------------------------------- 1 | std.exponent(1e30) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.exponent4.jsonnet: -------------------------------------------------------------------------------- 1 | std.exponent(1 << 30) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.exponent5.jsonnet: -------------------------------------------------------------------------------- 1 | std.exponent(42 << 30) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.exponent6.jsonnet: -------------------------------------------------------------------------------- 1 | std.exponent(42 / (1 << 30)) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.exponent7.jsonnet: -------------------------------------------------------------------------------- 1 | std.exponent(-42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.filter.jsonnet: -------------------------------------------------------------------------------- 1 | std.filter(function(n) std.mod(n, 2) == 1, [1, 2, 3, 4, 5]) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.filter2.jsonnet: -------------------------------------------------------------------------------- 1 | std.filter(error 'x', []) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.filter3.jsonnet: -------------------------------------------------------------------------------- 1 | std.filter(function(n) error 'xxx', []) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.filter4.jsonnet: -------------------------------------------------------------------------------- 1 | std.filter(42, []) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.filter5.jsonnet: -------------------------------------------------------------------------------- 1 | std.filter(function(n) 42, 42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.filter6.jsonnet: -------------------------------------------------------------------------------- 1 | std.filter(42, '42') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.filter7.jsonnet: -------------------------------------------------------------------------------- 1 | std.filter(function(n) false, [error 'xxx']) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.filter8.jsonnet: -------------------------------------------------------------------------------- 1 | std.filter([42], function(i) 'xxx') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.filter_swapped_args.jsonnet: -------------------------------------------------------------------------------- 1 | std.filter([1, 2, 3], function(n) true) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.flatmap.jsonnet: -------------------------------------------------------------------------------- 1 | std.flatMap(function(x) [], [1, 2, 3]) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.flatmap2.jsonnet: -------------------------------------------------------------------------------- 1 | std.flatMap(function(x) [1, 2, 3], ['a', 2, 3, 4, 5]) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.flatmap3.jsonnet: -------------------------------------------------------------------------------- 1 | std.flatMap(function(x) error 'never happens', []) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.flatmap4.jsonnet: -------------------------------------------------------------------------------- 1 | std.flatMap(function(x) [x, x], [1, 2, 3, 4, 5]) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.flatmap5.jsonnet: -------------------------------------------------------------------------------- 1 | local failWith(x) = error x; 2 | 3 | std.type(std.flatMap(failWith, ['a', 'b', 'c'])) 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.join.jsonnet: -------------------------------------------------------------------------------- 1 | std.join([], []) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.join2.jsonnet: -------------------------------------------------------------------------------- 1 | std.join([42], []) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.join3.jsonnet: -------------------------------------------------------------------------------- 1 | std.join([42], [[1]]) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.join4.jsonnet: -------------------------------------------------------------------------------- 1 | std.join([42], [[1], [2]]) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.join5.jsonnet: -------------------------------------------------------------------------------- 1 | std.join([42], [[1], [2], [3]]) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.join6.jsonnet: -------------------------------------------------------------------------------- 1 | std.join('xxx', ['aa', 'bb']) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.join7.jsonnet: -------------------------------------------------------------------------------- 1 | std.join('aa', [[1], [2]]) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.join8.jsonnet: -------------------------------------------------------------------------------- 1 | std.join([3, 4], [[1, 2], '56']) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.jsonnet: -------------------------------------------------------------------------------- 1 | std.length('x') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.makeArray.jsonnet: -------------------------------------------------------------------------------- 1 | std.makeArray(5, function(x) 42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.makeArrayNamed.jsonnet: -------------------------------------------------------------------------------- 1 | std.makeArray(sz=5, func=function(i) i) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.makeArrayNamed2.jsonnet: -------------------------------------------------------------------------------- 1 | std.makeArray(func=function(i) i, sz=5) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.makeArrayNamed3.jsonnet: -------------------------------------------------------------------------------- 1 | std.makeArray(blahblah=5, blahblahblah=function(i) i) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.makeArrayNamed4.jsonnet: -------------------------------------------------------------------------------- 1 | std.makeArray(3, func=function(i) i) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.makeArray_bad.jsonnet: -------------------------------------------------------------------------------- 1 | std.makeArray('xxx', function(i) i) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.makeArray_bad2.jsonnet: -------------------------------------------------------------------------------- 1 | std.makeArray(42, 'xxx') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.makeArray_noninteger.jsonnet: -------------------------------------------------------------------------------- 1 | std.makeArray(2.5, function(i) i) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.makeArray_noninteger_big.jsonnet: -------------------------------------------------------------------------------- 1 | std.makeArray(1e100, error "shouldn't happen") 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.makeArray_recursive.jsonnet: -------------------------------------------------------------------------------- 1 | local arr = [0] + std.makeArray(2000, function(i) arr[i] + 1); 2 | 3 | arr 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.makeArray_recursive_evalutation_order_matters.jsonnet: -------------------------------------------------------------------------------- 1 | local arr = [0] + std.makeArray(2000, function(i) arr[i] + 1); 2 | 3 | arr[500] 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.mantissa.jsonnet: -------------------------------------------------------------------------------- 1 | std.mantissa(0) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.mantissa2.jsonnet: -------------------------------------------------------------------------------- 1 | std.mantissa(42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.mantissa3.jsonnet: -------------------------------------------------------------------------------- 1 | std.mantissa(0.42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.mantissa4.jsonnet: -------------------------------------------------------------------------------- 1 | std.mantissa(1e100) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.mantissa5.jsonnet: -------------------------------------------------------------------------------- 1 | std.mantissa(42 << 30) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.mantissa6.jsonnet: -------------------------------------------------------------------------------- 1 | std.mantissa(42 / (1 << 30)) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.mantissa7.jsonnet: -------------------------------------------------------------------------------- 1 | std.mantissa(-42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.md5.jsonnet: -------------------------------------------------------------------------------- 1 | std.md5('xxx') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.md5_2.jsonnet: -------------------------------------------------------------------------------- 1 | std.md5('') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.md5_3.jsonnet: -------------------------------------------------------------------------------- 1 | std.md5('a') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.md5_4.jsonnet: -------------------------------------------------------------------------------- 1 | std.md5('message digest') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.md5_5.jsonnet: -------------------------------------------------------------------------------- 1 | std.md5('ą') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.md5_6.jsonnet: -------------------------------------------------------------------------------- 1 | std.md5(42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.mod_int.jsonnet: -------------------------------------------------------------------------------- 1 | std.mod(42, 5) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.mod_string.jsonnet: -------------------------------------------------------------------------------- 1 | std.mod('abcd %s %03d', ['xxx', 42]) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.modulo.jsonnet: -------------------------------------------------------------------------------- 1 | std.modulo(42, 5) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.modulo2.jsonnet: -------------------------------------------------------------------------------- 1 | std.modulo('xxx', 42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.modulo3.jsonnet: -------------------------------------------------------------------------------- 1 | std.modulo('xxx', 42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals(1, 1) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals10.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals(error 'x', 42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals11.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals(3.14, 3.14) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals12.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals(3.14, 3.15) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals13.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals([], []) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals14.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals(42, {}) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals15.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals({}, 42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals16.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals([], 42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals17.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals(42, []) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals18.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals(null, null) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals19.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals(true, true) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals2.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals(1, 2) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals20.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals(true, 'xxx') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals21.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals('xxx', 42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals3.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals('xxx', 'xxx') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals4.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals('xxx', 'xxy') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals5.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals(1, 'x') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals6.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals({}, {}) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals7.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals(function() 42, function() 42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals8.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals(42, function() 42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.primitiveEquals9.jsonnet: -------------------------------------------------------------------------------- 1 | std.primitiveEquals(42, error 'x') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.slice.jsonnet: -------------------------------------------------------------------------------- 1 | std.slice([1, 2, 3, 4], 1, 4, 2) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.thisFile.jsonnet: -------------------------------------------------------------------------------- 1 | std.thisFile 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.thisFile2.jsonnet: -------------------------------------------------------------------------------- 1 | import 'std.thisFile.jsonnet' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.toString.jsonnet: -------------------------------------------------------------------------------- 1 | std.toString('xxx') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.toString2.jsonnet: -------------------------------------------------------------------------------- 1 | std.toString(2) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.toString3.jsonnet: -------------------------------------------------------------------------------- 1 | std.toString({}) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.toString4.jsonnet: -------------------------------------------------------------------------------- 1 | std.toString([]) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.toString5.jsonnet: -------------------------------------------------------------------------------- 1 | std.toString(error 'x') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.toString6.jsonnet: -------------------------------------------------------------------------------- 1 | std.toString({ x: [{ y: [] }] }) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std.toString8.jsonnet: -------------------------------------------------------------------------------- 1 | std.toString(a=42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std_in_local.jsonnet: -------------------------------------------------------------------------------- 1 | local x = std.length('x'); 2 | 3 | x 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/std_substr.jsonnet: -------------------------------------------------------------------------------- 1 | std.substr('abcd', 1, 2) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/strReplace.jsonnet: -------------------------------------------------------------------------------- 1 | local n = 10000; 2 | local text = std.join('', std.makeArray(n, function(x) 'ab')); 3 | 4 | std.strReplace(text, 'a', 'b') 5 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/strReplace2.jsonnet: -------------------------------------------------------------------------------- 1 | std.strReplace('test test test', 'test', '__') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/strReplace3.jsonnet: -------------------------------------------------------------------------------- 1 | std.strReplace('test', '', 'blah') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/string.jsonnet: -------------------------------------------------------------------------------- 1 | 'xxx' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/string_comparison1.jsonnet: -------------------------------------------------------------------------------- 1 | 'a' < 'b' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/string_comparison2.jsonnet: -------------------------------------------------------------------------------- 1 | 'a' > 'b' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/string_comparison3.jsonnet: -------------------------------------------------------------------------------- 1 | 'a' == 'b' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/string_comparison4.jsonnet: -------------------------------------------------------------------------------- 1 | 'a' < 'aa' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/string_comparison5.jsonnet: -------------------------------------------------------------------------------- 1 | 'aa' < 'a' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/string_comparison6.jsonnet: -------------------------------------------------------------------------------- 1 | 'ą' < 'ć' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/string_comparison7.jsonnet: -------------------------------------------------------------------------------- 1 | 'ą' < 'z' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/string_divided_by_number.jsonnet: -------------------------------------------------------------------------------- 1 | 'xxx' / 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/string_index.jsonnet: -------------------------------------------------------------------------------- 1 | 'abcd'[0] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/string_index2.jsonnet: -------------------------------------------------------------------------------- 1 | 'abcd'[3] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/string_index_negative.jsonnet: -------------------------------------------------------------------------------- 1 | 'abcd'[-1] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/string_index_out_of_bounds.jsonnet: -------------------------------------------------------------------------------- 1 | 'abcd'[4] 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/string_minus_number.jsonnet: -------------------------------------------------------------------------------- 1 | 'x' - 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/string_plus_function.jsonnet: -------------------------------------------------------------------------------- 1 | 'xxx' + (function() 42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/string_times_number.jsonnet: -------------------------------------------------------------------------------- 1 | 'x' * 42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/string_to_bool.jsonnet: -------------------------------------------------------------------------------- 1 | local stringToBool(s) = if s == 'true' then true else if s == 'false' then false else error 'invalid boolean: ' + std.manifestJson(s); 2 | 3 | [stringToBool('false'), stringToBool('true')] 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/supersugar.jsonnet: -------------------------------------------------------------------------------- 1 | { x: { a: 1 } } { x+: { b: 2 } } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/supersugar2.jsonnet: -------------------------------------------------------------------------------- 1 | { x: +1 } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/supersugar3.jsonnet: -------------------------------------------------------------------------------- 1 | { assert self.x } { x+: true } 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/supersugar5.jsonnet: -------------------------------------------------------------------------------- 1 | ({} { x+: function(x) x }).x(42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/supersugar6.jsonnet: -------------------------------------------------------------------------------- 1 | { 2 | x: 'hello, ', 3 | } { 4 | x+: 'world', 5 | } 6 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/supersugar7.jsonnet: -------------------------------------------------------------------------------- 1 | { 2 | x: [1, 2, 3], 3 | } { 4 | x+: [4, 5, 6], 5 | } 6 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/supersugar8.jsonnet: -------------------------------------------------------------------------------- 1 | { 2 | assert self.x, 3 | } { 4 | x+: false, 5 | } 6 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/tailstrict.jsonnet: -------------------------------------------------------------------------------- 1 | local arr = [function(x) x] + std.makeArray(600, function(i) (function(x) arr[i](x + 1) tailstrict)); 2 | 3 | arr[600](42) 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/tailstrict2.jsonnet: -------------------------------------------------------------------------------- 1 | local e(x) = (error x); 2 | 3 | (function(x) e(x))('xxx') tailstrict 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/tailstrict3.jsonnet: -------------------------------------------------------------------------------- 1 | local foo(x, y=error 'xxx') = x; 2 | 3 | foo(42) tailstrict 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/tailstrict4.jsonnet: -------------------------------------------------------------------------------- 1 | local foo(x, y=error 'xxx') = x; 2 | 3 | foo(42, y=5) tailstrict 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/tailstrict5.jsonnet: -------------------------------------------------------------------------------- 1 | local sum(x, v) = if x <= 0 then v else sum(x - 1, x + v) tailstrict; 2 | 3 | sum(1000, 0) 4 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/true.jsonnet: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/type_array.jsonnet: -------------------------------------------------------------------------------- 1 | std.type([error 'x']) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/type_builtin_function.jsonnet: -------------------------------------------------------------------------------- 1 | std.type(std.type) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/type_error.jsonnet: -------------------------------------------------------------------------------- 1 | std.type(error 'xxx') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/type_function.jsonnet: -------------------------------------------------------------------------------- 1 | std.type(function() {}) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/type_number.jsonnet: -------------------------------------------------------------------------------- 1 | std.type(42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/type_object.jsonnet: -------------------------------------------------------------------------------- 1 | std.type({ x: error 'x' }) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/type_string.jsonnet: -------------------------------------------------------------------------------- 1 | std.type('xxx') 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/unary_minus.jsonnet: -------------------------------------------------------------------------------- 1 | -42 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/unary_minus2.jsonnet: -------------------------------------------------------------------------------- 1 | -(-42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/unary_minus3.jsonnet: -------------------------------------------------------------------------------- 1 | -(42) 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/unary_minus4.jsonnet: -------------------------------------------------------------------------------- 1 | -'xxx' 2 | -------------------------------------------------------------------------------- /gen/printer/testdata/upstream/use_object.jsonnet: -------------------------------------------------------------------------------- 1 | { a: 1 }.a 2 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/kube-jsonnet/k 2 | 3 | go 1.13 4 | 5 | require ( 6 | github.com/blang/semver v3.5.1+incompatible 7 | github.com/go-openapi/spec v0.19.6 8 | github.com/go-openapi/swag v0.19.7 9 | github.com/google/go-jsonnet v0.13.0 10 | github.com/pkg/errors v0.9.1 11 | github.com/pkg/profile v1.4.0 12 | github.com/stretchr/testify v1.3.0 13 | ) 14 | -------------------------------------------------------------------------------- /versions.json: -------------------------------------------------------------------------------- 1 | { 2 | "1.13": "https://raw.githubusercontent.com/kubernetes/kubernetes/release-1.13/api/openapi-spec/swagger.json", 3 | "1.14": "https://raw.githubusercontent.com/kubernetes/kubernetes/release-1.14/api/openapi-spec/swagger.json", 4 | "1.15": "https://raw.githubusercontent.com/kubernetes/kubernetes/release-1.15/api/openapi-spec/swagger.json", 5 | "1.16": "https://raw.githubusercontent.com/kubernetes/kubernetes/release-1.16/api/openapi-spec/swagger.json", 6 | "1.17": "https://raw.githubusercontent.com/kubernetes/kubernetes/release-1.17/api/openapi-spec/swagger.json", 7 | "1.18": "https://raw.githubusercontent.com/kubernetes/kubernetes/release-1.18/api/openapi-spec/swagger.json" 8 | } 9 | --------------------------------------------------------------------------------