Skip to content

Commit

Permalink
Make kubeval hermetic
Browse files Browse the repository at this point in the history
  • Loading branch information
Mengqi Yu committed Apr 19, 2021
1 parent 69f7868 commit db461f8
Show file tree
Hide file tree
Showing 6 changed files with 95,951 additions and 50 deletions.
13 changes: 6 additions & 7 deletions examples/kubeval/simple/README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
# Kubeval
# kubeval: simple example

The `kubeval` KRM config function validates Kubernetes resources using kubeval.
Learn more on the [kubeval website].

This example invokes the kubeval function against Kubernetes v1.18.0.
This example invokes the kubeval function against the builtin Kubernetes
v1.19.8 schema.

## Function invocation

Get this example and try it out by running the following commands:

<!-- TODO: no --network. See: https://github.com/GoogleContainerTools/kpt/issues/1621 -->

```sh
kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/kubeval .
kpt fn run kubeval --network
kpt fn run kubeval
```

## Expected Results

This should give the following output:

```sh
[ERROR] Invalid type. Expected: [integer,null], given: string in object 'v1/ReplicationController//bob' in file example-config.yaml in field spec.replicas
[ERROR] Invalid type. Expected: [integer,null], given: string in object 'v1/ReplicationController//bob' in file resources.yaml in field spec.replicas
error: exit status 1
```

In the `example-config.yaml` file, replace the value of `spec.replicas`
In the `resources.yaml` file, replace the value of `spec.replicas`
with an integer to pass validation and rerun the command. This will return
success (no output).

Expand Down
3 changes: 0 additions & 3 deletions examples/kubeval/simple/fn-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ metadata:
config.k8s.io/function: |
container:
image: gcr.io/kpt-fn/kubeval:unstable
network: true
config.kubernetes.io/local-config: 'true'
data:
schema_location: https://kubernetesjsonschema.dev/
21 changes: 16 additions & 5 deletions functions/ts/kubeval/build/kubeval.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
FROM python:3.9-alpine3.12 as parser

RUN pip install --no-cache-dir openapi2jsonschema

COPY openapi.json /home/
COPY scripts/preprocess.py /home/

RUN python /home/preprocess.py /home/openapi.json | openapi2jsonschema --kubernetes --expanded --stand-alone -o /home/master-standalone file:///dev/stdin

FROM node:14.15-alpine3.12 as builder

ARG KUBEVAL_VERSION="0.15.0"
ARG KUBEVAL_VERSION="v0.16.1"
RUN apk add curl && \
curl -sSLf https://github.com/instrumenta/kubeval/releases/download/${KUBEVAL_VERSION}/kubeval-linux-amd64.tar.gz | \
tar xzf - -C /usr/local/bin
Expand All @@ -27,16 +36,18 @@ RUN npm run build && \

FROM node:14.15-alpine3.12

COPY --from=parser /home/master-standalone/ /home/master-standalone/

COPY --from=builder /home/node/app /home/node/app

COPY --from=builder /usr/local/bin /usr/local/bin

# Run as non-root user as a best-practices:
# https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md
USER node

WORKDIR /home/node/app

COPY --from=builder /home/node/app /home/node/app

COPY --from=builder /usr/local/bin /usr/local/bin

ENV PATH /usr/local/bin:$PATH

ENTRYPOINT ["node", "/home/node/app/dist/kubeval_run.js"]
Loading

0 comments on commit db461f8

Please sign in to comment.