Coder Social home page Coder Social logo

ksonnet / ksonnet-lib Goto Github PK

View Code? Open in Web Editor NEW
444.0 444.0 83.0 2.48 MB

Codegen for Kubernetes-API-compatible Jsonnet libraries

Home Page: https://ksonnet.io

License: Apache License 2.0

Go 3.43% JSONiq 0.03% Shell 0.01% Dockerfile 0.02% Jsonnet 96.51%

ksonnet-lib's Introduction

ksonnet

The team behind ksonnet is stepping back from the project. As a result, work on ksonnet will end and the GitHub repositories will be archived. You can read more about our decision here.

Official Site

Build Status Go Report Card

ksonnet is a framework for writing, sharing, and deploying Kubernetes application manifests. With its CLI, you can generate a complete application from scratch in only a few commands, or manage a complex system at scale.

Specifically, ksonnet allows you to:

  • Reuse common manifest patterns (within your app or from external libraries)
  • Customize manifests directly with powerful object concatenation syntax
  • Deploy app manifests to multiple environments
  • Diff across environments to compare two running versions of your app
  • Track the entire state of your app configuration in version controllable files

All of this results in a more iterative process for developing manifests, one that can be supplemented by continuous integration (CI).

Install

The ksonnet CLI, ks, can be installed in three different ways. Choose the method that best matches your setup:

Homebrew on macOS

If you are using Homebrew on macOS, you can install ks with the following command:

brew install ksonnet/tap/ks

Download a prebuilt binary for your OS

See the releases page to download the latest released binary.

Build a docker image

A docker image can be built and used similarly to our manual build as seen here

Manually build and install

You can download and manually build from source by following these instructions.

Run through an example

Here we provide some commands that show some basic ksonnet features in action. You can run these commands to deploy and update a basic web app UI, via a Kubernetes Service and Deployment. This app is shown below:

guestbook screenshot

Note that we will not be implementing the entire app in this example, so the buttons will not work!

Minimal explanation is provided here, and only basic ksonnet features are shown---this is intended to be a quick demonstration. If you are interested in learning more, see Additional Documentation.

Prerequisites

  • You should have access to an up-and-running Kubernetes cluster โ€” supported versions are 1.7 (default) and 1.8 (beta).

    If you do not have a cluster, choose a setup solution from the official Kubernetes docs.

  • You should have kubectl installed. If not, follow the instructions for installing via Homebrew (MacOS) or building the binary (Linux).

  • Your $KUBECONFIG should specify a valid kubeconfig file, which points at the cluster you want to use for this demonstration.

Commands

Start by creating your app directory. If you are running Kubernetes 1.8.x, you'll need to add --api-spec=version:v1.8.0 to the end of the following command:

# The ks-example app directory is created at the current path, and the
# app itself references your current cluster using $KUBECONFIG
ks init ks-example

You can copy and paste the commands below to deploy the web app UI:

# 'ks' commands should be run within a ksonnet app directory
cd ks-example

# Autogenerate a basic manifest
ks generate deployed-service guestbook-ui \
  --image gcr.io/heptio-images/ks-guestbook-demo:0.1 \
  --type ClusterIP

# Deploy your manifest to your cluster
ks apply default

Now there should be a Deployment and Service running on your cluster! Try accessing the guestbook-ui service in your browser. (How you do this may depend on your cluster setup).

If you are unsure what to do, we suggest using kubectl proxy.
# Set up an API proxy so that you can access the 'guestbook-ui' service locally
kubectl proxy > /dev/null &
PROXY_PID=$!
QUICKSTART_NAMESPACE=$(kubectl get svc guestbook-ui -o jsonpath="{.metadata.namespace}")
GUESTBOOK_SERVICE_URL=http://localhost:8001/api/v1/proxy/namespaces/$QUICKSTART_NAMESPACE/services/guestbook-ui
open $GUESTBOOK_SERVICE_URL

(Remember, the buttons won't work in this example.)

Now let's try upgrading the container image to a new version:

# Bump the container image to a different version
ks param set guestbook-ui image gcr.io/heptio-images/ks-guestbook-demo:0.2

# View updated param values
ks param list

# Update your cluster with your latest changes
ks apply default

Check out the webpage again in your browser (force-refresh to update the javascript). Notice that it looks different! Clean up:

# Teardown
ks delete default

# There should be no guestbook service left running
kubectl get svc guestbook-ui

(If you ended up copying and pasting the kubectl proxy code above, make sure to clean up that process with kill -9 $PROXY_PID).

Now, even though you've made modifications to the Guestbook app and removed it from your cluster, ksonnet still tracks all your manifests locally:

# View all expanded manifests (YAML)
ks show default

If you're still wondering how ksonnet differs from existing tools, the tutorial shows you how to use other ksonnet features to implement the rest of the Guestbook app (and yes, the buttons will work!).

Additional documentation

ksonnet is a feature-rich framework. To learn more about how to integrate it into your workflow, check out the resources below:

  • Tutorial - What can I build with ksonnet and why? This finishes the Guestbook app from the example above.

  • Interactive tour of ksonnet - How do ks commands work under the hood?

  • CLI Reference - What ksonnet commands are available, and how do I use them?

  • Concept Reference - What do all these special ksonnet terms mean (e.g. prototypes) ?

  • Design Docs - What are the detailed design specs, and what's next on the feature roadmap?

Troubleshooting

If you encounter any problems that the documentation does not address, file an issue.

Contributing

Thanks for taking the time to join our community and start contributing!

Before you start

  • Please familiarize yourself with the Code of Conduct before contributing.
  • Read the contribution guidelines in CONTRIBUTING.md.
  • There is a mailing list or the #ksonnet channel on Slack if you want to interact with other members of the community.

Pull requests

  • We welcome pull requests. Feel free to dig through the issues and jump in.

Changelog

See the list of releases to find out about feature changes.

ksonnet-lib's People

Contributors

anguslees avatar bradamant3 avatar bryanl avatar glindstedt avatar hausdorff avatar jbeda avatar jessicayuen avatar jlewi avatar kstewart avatar metalmatze avatar shomron avatar skriss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ksonnet-lib's Issues

ksonnet-lib not handling intorstring correctly

Using the beta2 generated api I was expecting something like this to work:

local esProxyStrategy = 
    strategy.new() +
    strategy.rollingUpdate.maxSurge(2);

But it did not and @hausdorff told me that it was because the ksonnet-lib was not handling Kubernetes' intorstring type correctly.

Support Openshift

Hi,

Would be great to support OpenShift in ksonnet-gen.
openshift.json

go run main.go openshift.json out
Failed to parse definition name 'com.github.openshift.origin.pkg.authorization.apis.authorization.v1.RoleBindingRestrictionSpec'
exit status 1

ksonnet-gen seems not work properly or I am missing something

So, I tried ksonnet-gen with k8s 1.6.0 and 1.7.0-beta.0 tags and they both didn't work. Here below is what I did:

// with k8s v1.6.0 tag
$ ksonnet-gen ~/workspace/gocode/kubernetes/src/k8s.io/kubernetes/api/openapi-spec/swagger.json .
Unrecognized Kubernetes version 'v1.6.0'

// with k8s v1.7.0-beta.0
$ ksonnet-gen ~/workspace/gocode/kubernetes/src/k8s.io/kubernetes/api/openapi-spec/swagger.json .
Failed to emit ref mixin:
Can't make API object from name with nil version in path: 'io.k8s.apimachinery.pkg.runtime.RawExtension'

cc/ @hausdorff

"containers" should be an array and not a dictionary

While using jsonnet Jsonnet commandline interpreter v0.9.3 built-in locally on my Ubuntu 16.04 LTS machine, I noticed that jsonnet plus ksonnet yield invalid JSON:

$ git clone https://github.com/ksonnet/ksonnet-lib
$ cd ksonnet-lib/examples/readme/
$ jsonnet hello-nginx.jsonnet > json
$ kubectl create -f json
error: error validating "json": error validating data: [found invalid field hostMappings for v1.PodSpec, expected type array, for field spec.template.spec.containers, got map]; if you choose to ignore these errors, turn validation off with --validate=false

Don't emit empty objects

Sometimes you'll see stuff like containerPort.mixin which is empty. It would be better to simply not emit it.

Tutorial template draft: needs new examples

This snippet is a stripped down version of the old tutorial, with examples removed. Would probably be good to develop some more complex examples (to demonstrate the value proposition better). (This could be an effort post-initial release.)
(template is provided in raw markdown here and in attached text file because GH doesn't support attaching markdown files :-( )
TUTORIAL_template.txt

Tutorial

The ksonnet readme
shows you how to create a default
deployment.json file that lets you deploy an nginx container
to an existing Kubernetes cluster. This tutorial shows you how to:

  • Modify the deployment using ksonnet definitions
  • Define other Kubernetes objects
  • Work with mixins to develop complex configurations

Prerequisites

This tutorial assumes that you have performed the following
tasks. For details, see the readme.

  • Installed Jsonnet
  • Cloned the ksonnet repository locally
  • Installed and configured the VisualStudio Code extension
    (optional)
  • Created a test Kubernetes cluster

NOTE: All import paths are relative to the root of the
ksonnet* repository.

Modify the default deployment

ksonnet lets you configure or modify any Kubernetes object.

For example, to customize the default <> deployment, you can write:

// TODO: provide ksonnet example

Save the file as customDeploy.libsonnet
and run:

jsonnet customDeploy.libsonnet
kubectl apply -f deployment.json

(here we seem to be looking at YAML we get from running
kubectl get deployment <appName> -o yaml but in other examples
we're looking at JSON generated from ksonnet. Figure out, fix.)
And the generated YAML looks like this. You can see the new <>
and <> fields:

# TODO: provide example

Define other Kubernetes objects

ksonnet lets you define any Kubernetes object. For example,
you can define a container:

// TODO: update ksonnet example; container is probably a good one
// consider whether nginx is the right one for deployment 
// (issue also in previous example)

Save this snippet as container.libsonnet, and run:

jsonnet container.libsonnet

The JSON output looks like this:

TODO: fix up to be consistent with YAML vs JSON
across tutorial examples

(EXAMPLE)

You can include a liveness probe with your container:

// TODO: ksonnet example. Is liveness probe appropriate here?

Save the file again -- container.libsonnet --
and run:

jsonnet container.libsonnet

(As above, YAML or JSON?)
The JSON output now looks like this:

(EXAMPLE)

Now you can define a pod that runs this container:

// TODO: ksonnet example

Save the file as pod.libsonnet, and run the following commands
to deploy the pod to your cluster:

jsonnet pod.libsonnet // create pod.json
kubectl apply -f pod.json // apply pod definition to cluster

Work with mixins

You've seen how to modify the default deployment by writing
mixins to add custom fields.
As the Jsonnet tutorial explains in more detail, mixins provide
dynamic inheritance, at runtime instead of compile time. This
approach means that different team members can define the
Kubernetes objects that they need. You can then mix them into
your master definition without having to copy all the details.

For example, you could write the following code to define a
container for your application:

// TODO: ksonnet example

And your teammate could write the following code to define
the VolumeMounts:

//TODO: ksonnet example

Then, you write a deployment definition for the container that
adds the VolumeMounts for logging using mixins:

//TODO: ksonnet example with mixins

OS X runtime error when running `ks init guestbook`

OS Version: OS X High Sierra
Shell: Bash 3.2
K8s version: 1.8, minikube

Tying to follow: https://ksonnet-next-site.i.heptio.com/docs/tutorial#1-initialize-your-app-commands

bash-3.2$ kubectl get namespaces
NAME          STATUS    AGE
default       Active    1h
ks-dev        Active    9m
kube-public   Active    1h
kube-system   Active    1h

export GOPATH=/Users/ruben/go

INFO  Using context 'ks-dev'
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x1b805ce]

goroutine 1 [running]:
github.com/ksonnet/ksonnet/cmd.resolveContext(0xc420553ca8, 0xc420399800, 0x7, 0x7ffeefbffb54, 0x6, 0x0, 0x0)
    /Users/ruben/go/src/github.com/ksonnet/ksonnet/cmd/root.go:161 +0x3be
github.com/ksonnet/ksonnet/cmd.glob..func9(0x2528a00, 0xc42046eed0, 0x1, 0x3, 0x0, 0x0)
    /Users/ruben/go/src/github.com/ksonnet/ksonnet/cmd/init.go:68 +0x237
github.com/ksonnet/ksonnet/vendor/github.com/spf13/cobra.(*Command).execute(0x2528a00, 0xc42046ed80, 0x3, 0x3, 0x2528a00, 0xc42046ed80)
    /Users/ruben/go/src/github.com/ksonnet/ksonnet/vendor/github.com/spf13/cobra/command.go:656 +0x3f8
github.com/ksonnet/ksonnet/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0x252b260, 0x10067ac, 0xc42006c058, 0x0)
    /Users/ruben/go/src/github.com/ksonnet/ksonnet/vendor/github.com/spf13/cobra/command.go:735 +0x339
github.com/ksonnet/ksonnet/vendor/github.com/spf13/cobra.(*Command).Execute(0x252b260, 0x0, 0x1e76419)
    /Users/ruben/go/src/github.com/ksonnet/ksonnet/vendor/github.com/spf13/cobra/command.go:694 +0x2b
main.main()
    /Users/ruben/go/src/github.com/ksonnet/ksonnet/main.go:33 +0x5b

Can't set deployment namespace with simple ".withNamespace" mixin

When using deployment object, somehow the mixins get confused, so the top level ".withNamespace" sets it for the pod template, and not the deployment:

Repro:

local appDeployment = deployment
.new(
"heptio-server",
4,
serverContainer,
params.labels)
.withNamespace("heptio-svc");

Expected: deployment within given namespace.

Result: Sets the namespace in the pod spec.

Workaround:

The workaround is a bit hard to discover, but this works:

local appDeployment = deployment
.new(
"heptio-server",
params.replicas,
serverContainer,
myparams.labels)+
deployment.mixin.metadata.withNamespace("heptio-svc");

Dunno how to declare labels

People would like to add some labels (probably it's required) to deployment and/or service. Need to have a clear way to do that with ksonnet. Here below I have this error:

$ cat nginx-deployment.jsonnet
local k = import "../../ksonnet.beta.1/k.libsonnet";
local container = k.core.v1.container;
local deployment = k.apps.v1beta1.deployment;
local prune = k.util.prune;
local label = {app: "nginx"};

// Create nginx container with container port 80 open.
local nginxContainer =
  container.default("nginx", "nginx:1.13.0") +
  container.helpers.namedPort("http", 80);

// Create default `Deployment` object from nginx container.
prune(deployment.default(
  "nginx-deployment", nginxContainer) +
  deployment.mixin.spec.replicas(5) +
  deployment.mixin.spec.labels(label)
  )

$ jsonnet  nginx-deployment.jsonnet
RUNTIME ERROR: Field does not exist: labels
	nginx-svc.jsonnet:16:3-30	thunk <thing>
	../../ksonnet.beta.1/util.libsonnet:4:17-21	
	../../ksonnet.beta.1/util.libsonnet:4:8-22	thunk <a>
	../../ksonnet.beta.1/util.libsonnet:4:8-33	function <anonymous>
	../../ksonnet.beta.1/util.libsonnet:4:8-33	function <prune>
	nginx-svc.jsonnet:(13:1)-(17:3)	

A good example of using beta.2

I am looking for a good example to start writing my manifests using beta.2 at master branch. example/readme/hello-nginx.jsonnet is still beta.1 and some demo* files at sigapp branch don't work for master branch.

References to missing hidden.core.v1.persistentVolumeClaim

There are several references in k8s.libsonnet to the field hidden.core.v1.persistentVolumeClaim which does not exist. However there is a field in core.v1.persistentVolumeClaim which seems to fit the bill. I assume it was moved but the references weren't updated for some reason.

doc command

Going further than #64 it's annoying to read the k8s.libsonnet file. I'd like to have something like the following:

$ k8s doc -f ../lib/k8s.libsonnet core.v1.container 
container(name string, image string)
  // Arguments to the entrypoint. The docker image's CMD is used if this is not provided. Variable references $(VAR_NAME) are expanded using the container's environment. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell
  withArgs(args []string)
  withArgs(args string)
  
  // Arguments to the entrypoint. The docker image's CMD is used if this is not provided. Variable references $(VAR_NAME) are expanded using the container's environment. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell
  withCommand(command []string)
  withCommand(command string)
...

Perhaps the doc comments could be shortened or excluded unless you drilled down on that specific method.

$ k8s doc -f ../lib/k8s.libsonnet core.v1.container.withArgs
// Arguments to the entrypoint. The docker image's CMD is used if this is not provided. Variable references $(VAR_NAME) are expanded using the container's environment. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell

withArgs(args []string)
withArgs(args string)

Autogen casing is a bit weird

I'm seeing things like aPIVersion which I expect is some "downcase first letter" rule that wasn't expecting an acronym.

I don't know if this actually matters though. Feel free to close.

eventual issue with current head and beta.3

Hi all,

opening separate issue per @hausdorff request here. My original observation here is repasted bellow for simplicity

--
as of now it looks that current head is busted (for beta.3)

actually @hausdorff example above won't work at all ...

for it to behave, unless I'm missing something, it seems one has to manually patch ksonnet.beta.3/k8s.libsonnet along, at least, in those three places ...

diff --git a/ksonnet.beta.3/k8s.libsonnet b/ksonnet.beta.3/k8s.libsonnet
index 3b1bb7d..7cb3f16 100644
--- a/ksonnet.beta.3/k8s.libsonnet
+++ b/ksonnet.beta.3/k8s.libsonnet
@@ -348,7 +348,7 @@
       // Deployment enables declarative updates for Pods and ReplicaSets.
       deployment:: {
         local kind = {kind: "Deployment"},
-        new(name, replicas, containers, podLabels={app: name}):: apiVersion + kind + self.mixin.metadata.name(name) + self.mixin.spec.replicas(replicas) + self.mixin.spec.template.spec.containers(containers) + self.mixin.spec.template.metadata.labels(podLabels),
+        new(name, replicas, containers, podLabels={app: name}):: apiVersion + kind + self.mixin.metadata.withName(name) + self.mixin.spec.withReplicas(replicas) + self.mixin.spec.template.spec.withContainers(containers) + self.mixin.spec.template.metadata.withLabels(podLabels),
         mixin:: {
           // Standard object metadata.
           metadata:: {
@@ -865,7 +865,7 @@
       // The StatefulSet guarantees that a given network identity will always map to the same storage identity.
       statefulSet:: {
         local kind = {kind: "StatefulSet"},
-        new(name, replicas, containers, volumeClaims, podLabels={app: name}):: apiVersion + kind + self.mixin.metadata.name(name) + self.mixin.spec.replicas(replicas) + self.mixin.spec.template.spec.containers(containers) + self.mixin.spec.volumeClaimTemplates(volumeClaims) + self.mixin.spec.template.metadata.labels(podLabels),
+        new(name, replicas, containers, volumeClaims, podLabels={app: name}):: apiVersion + kind + self.mixin.metadata.withName(name) + self.mixin.spec.withReplicas(replicas) + self.mixin.spec.template.spec.withContainers(containers) + self.mixin.spec.withVolumeClaimTemplates(volumeClaims) + self.mixin.spec.template.metadata.withLabels(podLabels),
         mixin:: {
           //
           metadata:: {
@@ -4219,7 +4219,7 @@
       // Namespace provides a scope for Names. Use of multiple namespaces is optional.
       namespace:: {
         local kind = {kind: "Namespace"},
-        new(name):: apiVersion + kind + self.mixin.metadata.name(name),
+        new(name):: apiVersion + kind + self.mixin.metadata.withName(name),
         mixin:: {
           // Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
           metadata:: {

--
this is straight from tip. top of ksonnet.beta.3/k8s.libsonnet is

// AUTOGENERATED from the Kubernetes OpenAPI specification. DO NOT MODIFY.
// Kubernetes version: v1.7.0
// SHA of ksonnet-lib HEAD: 01423af3a22bb65ad77244563fa175d76458b012
// SHA of Kubernetes HEAD OpenAPI spec is generated from: d3ada0119e776222f11ec7945e6d860061339aad

@hausdorff fwiw this is on top of plain HEAD with just #81 applied (besides patch above). (host platform is macOS). Anything else I can do to help debug this ?

and thanks in advance!

Pay down the code debt from #90

We have a few open issues that are not urgent, but important to discuss, in #90. We merged to make the release window.

We need to come back, discuss, and fix them.

Kubernetes 1.8 and 1.6

I think we should enlarge the scope of the project and somehow support k8s 1.8 and 1.6

related to #70

Logical redux of Node+Pod affinity+anti-affinity

As of today affinity and anti-affinity specification are very explicit, and lengthy to specify.

Node Affinity Examples:
https://github.com/kubernetes/kubernetes/blob/master/plugin/pkg/scheduler/algorithm/priorities/node_affinity_test.go

Inter-Pod Affinity Examples:
https://github.com/kubernetes/kubernetes/blob/master/plugin/pkg/scheduler/algorithm/priorities/interpod_affinity_test.go

imo ~90% users can typically understand affinity in terms of "groupby" and "spreadby".

groupby (type(pod,node), key=value)

  • pod.groupby(node, rack=rack1)
  • pod.spreadby(pod, type=highiops)

There is more to this, but hopefully the gist is there.

VS Code Jsonnet Preview failed

local params = std.extVar("__ksonnet/params").components["teamcity-server-instance"];
local k = import "k.libsonnet";
local deployment = k.apps.v1beta1.deployment;
local container = k.apps.v1beta1.deployment.mixin.spec.template.spec.containersType;
local containerPort = container.portsType;
local service = k.core.v1.service;
local servicePort = k.core.v1.service.mixin.spec.portsType;

local targetPort = params.containerPort;
local nodePort = params.nodePort;
local labels = {app: params.name};

VS Code Jsonnet Preview:

RUNTIME ERROR: Undefined external variable: __ksonnet/params
	/Users/liaogang/Desktop/Anonym/CI/teamcity/components/teamcity-server-instance.jsonnet:1:16-45	thunk 
	/Users/liaogang/Desktop/Anonym/CI/teamcity/components/teamcity-server-instance.jsonnet:15:5-10	thunk 
	/Users/liaogang/ksonnet-lib/ksonnet.beta.3/k8s.libsonnet:8747:87-90	thunk 
	/Users/liaogang/ksonnet-lib/ksonnet.beta.3/k8s.libsonnet:8820:60-63	object 
	/Users/liaogang/ksonnet-lib/ksonnet.beta.3/k8s.libsonnet:8751:47-67	object 
	/Users/liaogang/Desktop/Anonym/CI/teamcity/components/teamcity-server-instance.jsonnet:31:21-30	thunk 
	/Users/liaogang/ksonnet-lib/ksonnet.beta.3/k.libsonnet:60:59-73	object 
	During manifestation	

Some labels keys are dropped from deployment meta to replica set

It appears that some keys from map labels which are using deployment.mixin.metadata.labels get dropped for it's child replicaset.

Example:

local k = import "ksonnet.beta.2/k.libsonnet";

local container = k.extensions.v1beta1.deployment.mixin.spec.template.spec.containersType;
local containerPort = container.portsType;
local deployment = k.extensions.v1beta1.deployment;

local containerImage = "nginx";
local containerTag = "1.13.7-alpine";

local staticHttp =
  local targetPort = 80;
  container.new(containerImage, containerTag) +
  container.ports(containerPort.newNamed("http", targetPort));

{
  defaultConfig:: {
    limits: {memory: "200Mi", cpu: "100m"},
    labels: {tier: "web", example: "ok", aardvark: "ok"},
  },

  deployment(app, labels, limits)::
    local comboLabels = std.mergePatch(self.defaultConfig.labels, {amazing: app});

    deployment.new("nginx", 3, staticHttp, self.defaultConfig) +
      deployment.mixin.metadata.labels(comboLabels) + {testing: comboLabels},
}.deployment('awesome', {}, {})

Output:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    aardvark: ok
    amazing: awesome
    example: ok
    tier: web
  name: nginx
spec:
  replicas: 3
  template:
    metadata:
      labels:
        labels:
          aardvark: ok
          example: ok
          tier: web
        limits:
          cpu: 100m
          memory: 200Mi
    spec:
      containers:
        - image: 1.13.7-alpine
          name: nginx
          ports:
            - containerPort: 80
              name: http
testing:
  aardvark: ok
  amazing: awesome
  example: ok
  tier: web

Notice: the amazing key is dropped from the replicaset labels.

I'm still digging into why this is happening, but it appears to be with the library.

Both jsonnet and go-jsonnet are producing the same incorrect output.

Field does not exist: ports

I am trying a simple nginx service and getting the below error:

$ cat nginx-svc.jsonnet

local k = import "../../ksonnet.beta.1/k.libsonnet";
local srv = k.core.v1.service;

srv.default("nginx") +
srv.mixin.spec.ports("80")

$ jsonnet nginx-svc.jsonnet
RUNTIME ERROR: Field does not exist: ports
		object <mixin>
	../../ksonnet.beta.1/core.v1.libsonnet:3379:31-44	object <anonymous>
	During manifestation

Consistent contructor

Rather than have multiple parameters in the constructors, prefer to have a single (or no param) constructor.

Currently the constructors take a variable number of parameters, and it's hard to know what's required. For example:

Deployment - new(name, replicas, containers, podLabels={app: name})
Service - new(name, selector, ports)

Some of these params are text, some are other objects. It's unclear from the definition. To make it more confusing, there's also builder methods like "withContainers", which presumably provide same functionality.

Suggestion:

Have a consistent constructor (single name param for named objects, else no param constructor):

local mydep = deployment.new("frontend")
.withReplicas(2)
.withContainers(...);

Official Docker image

I'd like to use ksonnet on deployment, while I don't want to install neither jsonnet nor ksonnet. Instead I want to use the official Docker image containing ksonnet (and jsonnet) as a command. Of course it's easy to create such an image by myself. But the official image is preferable to my own ones, I think.

Found invalid field hostMappings for v1.PodSpec

I've been trying to use ksonnet-lib with Kubernetes 1.6.2 but there's no way I can get Kubernetes to accept the JSON code generated from the example file hello-nginx.jsonnet:

$ jsonnet --version
Jsonnet commandline interpreter v0.9.3
$ git clone https://github.com/ksonnet/ksonnet-lib
$ cd ksonnet-lib/examples/
$ jsonnet hello-nginx.jsonnet > hello-nginx.json
$ kubectl create -f hello-nginx.json
error: error validating "hello-nginx.json": error validating data: found invalid field hostMappings for v1.PodSpec; if you choose to ignore these errors, turn validation off with --validate=false

Autogen `core.v1.list`

Currently this is not included as part of the OpenAPI JSON spec for the Kubernetes API, so we'll have to generate it manually.

io.k8s.kubernetes.pkg.api.v1.LocalVolumeSource confuses Jsonnet

Hi,

I'm using ksonnet-gen in https://github.com/amir/iron_jsonnet to generate k8s.libsonnet. The library gets generated successfully but Kubernetes resource io.k8s.kubernetes.pkg.api.v1.LocalVolumeSource gets translated to local:: which confuses Jsonnet. Looking at the k8s.libsonnet in ksonnet.beta.2 I don't see that resource but I can't find how it's been renamed/removed. Is there a manual step involved after generating the library?

I'm using sed in my project to replace it but before contributing a fix I wanted to make sure it's something you've encountered before too.

document constructors

Instead of having to read the code I'd love to see a page of what constructors ksonnet provides.

A list of constructors that could be better

  • authorization.v1.LocalSubjectAccessReview
  • authorization.v1.SelfSubjectAccessReview
  • authorization.v1.SubjectAccessReview
  • autoscaling.v1.HorizontalPodAutoscaler
  • autoscaling.v2alpha1.horizontalPodAutoscaler
  • batch.v1.Job
  • batch.v2alpha1.CronJob
  • certificates.v1beta1.CertificateSigningRequest
  • core.v1.Endpoints
  • core.v1.Event
  • core.v1.LimitRange
  • core.v1.Node
  • core.v1.PersistentVolume
  • core.v1.PersistentVolumeClaim
  • core.v1.Pod
  • core.v1.PodTemplate
  • core.v1.ReplicationController
  • core.v1.ResourceQuota
  • core.v1.Secret
  • policy.*
  • rbac.*
  • settings.*
  • storage.*

Things in cluster

[docs] Incompatible links between README and tutorial on the official website

The links between the main README and the tutorial doc are broken. I'm not 100% sure how to fix this, given that we don't want to break either the Github repo linking or the website linking. (Currently the Github linking works but the website doesn't).

Specifically: the tutorial link in http://ksonnet.heptio.com/docs/core-packages/ksonnet-lib.html#mixins and the readme link in http://ksonnet.heptio.com/docs/tutorial.html don't work.

Reimplement common k8s strings

There are a lot of expected strings that float around in k8s configurations.

Implement them as constants in this library (IfNotPresent, RollingUpdate, etc).

Optionally include validation.

group in `apiVersion` is not emitted correctly in all cases

apiVersion usually takes the form group/version. In the future, group will be a domain, rather than a single word (as old groups are).

We currently don't handle this correctly. We need to get the real group out of the fields that look like this:

    "x-kubernetes-group-version-kind": [
     {
      "Group": "rbac.authorization.k8s.io",
      "Version": "v1alpha1",
      "Kind": "ClusterRole"
     }
    ]

ksonnet seems to penalize breaking up large objects

Let's say I have this deployment:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: my-sample-deployment

This translates nicely when I make it one object like so:

deployment.new() +
deployment.mixin.metadata.name("my-sample-deployment")

But if I define my metadata first:

local metadata = deployment.mixin.metadataType;
local sampleDeploymentMetadata = metadata.new() +
    metadata.name("my-sample-deployment");

I now only seem to have an awkward object to attach to the deployment like so:

deployment.new() +
{
    "metadata": sampleDeploymentMetadata,
}

What do you think about supporting this kind of API:

deployment.new() +
deployment.mixin.metadata(sampleDeploymentMetadata);

Alternatively tell me what I've missed :)

note: you may be wondering about this code

deployment.new() +
sampleDeploymentMetadata

Well, this code yields:

apiVersion: extensions/v1beta1
kind: Deployment
name: my-sample-deployment

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.