forked from jsonnet-libs/k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate libraries for CRDs (jsonnet-libs#31)
This is heavily based on https://github.com/xvzf/crd-libs. Big shout out to @xvzf for putting this together.
- Loading branch information
Showing
45 changed files
with
784 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ spec.json | |
vendor | ||
k8s | ||
.vscode/ | ||
gen/ | ||
gen/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
FROM bitnami/kubectl:1.21.1 as kubectl | ||
FROM rancher/k3s:v1.21.1-k3s1 as k3s | ||
FROM mikefarah/yq:4.9.3 as yq2 | ||
|
||
FROM golang:1.16.4 as base | ||
|
||
ENV GO111MODULE=on | ||
WORKDIR /app | ||
|
||
COPY go.mod . | ||
COPY go.sum . | ||
|
||
RUN go mod download | ||
|
||
COPY pkg pkg | ||
COPY main.go main.go | ||
|
||
FROM base AS builder | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o k8s-gen . | ||
|
||
FROM golang:1.15.2-alpine3.12 as docsonnet | ||
|
||
RUN apk add --no-cache git | ||
RUN go get github.com/jsonnet-libs/docsonnet | ||
RUN go install github.com/sh0rez/docsonnet | ||
|
||
FROM alpine:3.12 | ||
|
||
WORKDIR /app | ||
|
||
ENV KUBECONFIG=/app/kubeconfig/kube-config.yaml | ||
RUN chmod a+w /app | ||
|
||
COPY --from=kubectl /opt/bitnami/kubectl/bin/kubectl /usr/local/bin | ||
COPY --from=k3s /bin/k3s /usr/local/bin | ||
COPY --from=yq2 /usr/bin/yq /usr/local/bin/yq2 | ||
COPY --from=builder /app/k8s-gen /usr/local/bin | ||
COPY --from=docsonnet /go/bin/docsonnet /usr/local/bin | ||
# | ||
RUN apk add --no-cache bash curl | ||
|
||
COPY scripts . | ||
|
||
ENTRYPOINT ["./gen.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
.PHONY: configure build debug run test push push-image | ||
|
||
IMAGE_NAME ?= k8s-crds | ||
IMAGE_PREFIX ?= jsonnet-libs | ||
IMAGE_TAG ?= 0.0.1 | ||
|
||
INPUT_DIR ?= ${PWD}/libs/k8s-alpha | ||
OUTPUT_DIR ?= ${PWD}/gen | ||
|
||
ABS_INPUT_DIR := $(shell realpath $(INPUT_DIR)) | ||
JSONNET_FILE := $(ABS_INPUT_DIR)/config.jsonnet | ||
ABS_OUTPUT_DIR := $(shell realpath $(OUTPUT_DIR)) | ||
|
||
# Requires Go implementation of Jsonnet | ||
# Implementation of `-c` argument pending: https://github.com/google/jsonnet/issues/195 | ||
configure: | ||
jsonnet -c -m $(ABS_INPUT_DIR) -S $(JSONNET_FILE) | ||
|
||
build: | ||
docker build -t $(IMAGE_PREFIX)/$(IMAGE_NAME):$(IMAGE_TAG) . | ||
|
||
debug: configure build | ||
docker run --rm -ti \ | ||
--user $(shell id -u):$(shell id -g) \ | ||
-v $(ABS_INPUT_DIR):/config \ | ||
-v $(ABS_OUTPUT_DIR):/output \ | ||
--entrypoint /bin/bash \ | ||
$(IMAGE_PREFIX)/$(IMAGE_NAME):$(IMAGE_TAG) | ||
|
||
run: configure build | ||
docker run --rm -ti \ | ||
--user $(shell id -u):$(shell id -g) \ | ||
-v $(ABS_INPUT_DIR):/config \ | ||
-v $(ABS_OUTPUT_DIR):/output \ | ||
$(IMAGE_PREFIX)/$(IMAGE_NAME):$(IMAGE_TAG) /config /output | ||
|
||
test: build | ||
|
||
push: build test push-image | ||
|
||
push-image: | ||
docker push $(IMAGE_PREFIX)/$(IMAGE_NAME):$(IMAGE_TAG) | ||
docker push $(IMAGE_PREFIX)/$(IMAGE_NAME):latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
set -x | ||
|
||
rm -rf gen./ | ||
mkdir -p gen/ | ||
|
||
for dir in libs/*; do | ||
[ -d "$dir" ] && make run INPUT_DIR="$dir" OUTPUT_DIR=gen/ | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/jsonnet-libs/k8s | ||
|
||
go 1.13 | ||
go 1.16 | ||
|
||
require ( | ||
github.com/fatih/camelcase v1.0.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
permalink: / | ||
--- | ||
|
||
# Jsonnet library for %(name)s | ||
|
||
The Jsonnet Kubernetes library is a generated with | ||
[`k8s`](https://github.com/jsonnet-libs/k8s). | ||
|
||
%(pages)s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
local name = 'cert-manager'; | ||
local repository = 'github.com/jsonnet-libs/' + name + '-lib'; | ||
local specs = [ | ||
{ | ||
output: '1.3', | ||
openapi: 'http://localhost:8001/openapi/v2', | ||
prefix: '^io\\.cert-manager\\..*', | ||
crd: 'https://github.com/jetstack/cert-manager/releases/download/v1.3.1/cert-manager.crds.yaml', | ||
localName: 'cert_manager', | ||
repository: 'github.com/jsonnet-libs/cert-manager-lib', | ||
}, | ||
]; | ||
|
||
{ | ||
'config.yml': std.manifestYamlDoc({ | ||
repository: repository, | ||
specs: specs, | ||
}, true), | ||
|
||
'docs/README.md': (importstr 'README.md.tmpl') % { | ||
name: name, | ||
pages: std.join('\n', [ | ||
'- [%(output)s](%(output)s/README.md)' % spec | ||
for spec in specs | ||
]), | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"repository": "github.com/jsonnet-libs/cert-manager-lib" | ||
"specs": | ||
- "crd": "https://github.com/jetstack/cert-manager/releases/download/v1.3.1/cert-manager.crds.yaml" | ||
"localName": "cert_manager" | ||
"openapi": "http://localhost:8001/openapi/v2" | ||
"output": "1.3" | ||
"prefix": "^io\\.cert-manager\\..*" | ||
"repository": "github.com/jsonnet-libs/cert-manager-lib" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
permalink: / | ||
--- | ||
|
||
# Jsonnet library for cert-manager | ||
|
||
The Jsonnet Kubernetes library is a generated with | ||
[`k8s`](https://github.com/jsonnet-libs/k8s). | ||
|
||
- [1.3](1.3/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
permalink: / | ||
--- | ||
|
||
# Jsonnet library for %(name)s | ||
|
||
The Jsonnet Kubernetes library is a generated with | ||
[`k8s`](https://github.com/jsonnet-libs/k8s). | ||
|
||
%(pages)s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
local name = 'cnrm'; | ||
local repository = 'github.com/jsonnet-libs/' + name + '-lib'; | ||
local specs = [ | ||
{ | ||
output: '1.33', | ||
openapi: 'http://localhost:8001/openapi/v2', | ||
prefix: '^com\\.google\\.cloud\\.cnrm\\..*', | ||
crd: 'https://raw.githubusercontent.com/GoogleCloudPlatform/k8s-config-connector/1.33.0/install-bundles/install-bundle-workload-identity/crds.yaml', | ||
localName: 'cnrm', | ||
repository: 'github.com/jsonnet-libs/cnrm-lib', | ||
}, | ||
]; | ||
|
||
{ | ||
'config.yml': std.manifestYamlDoc({ | ||
repository: repository, | ||
specs: specs, | ||
}, true), | ||
|
||
'docs/README.md': (importstr 'README.md.tmpl') % { | ||
name: name, | ||
pages: std.join('\n', [ | ||
'- [%(output)s](%(output)s/README.md)' % spec | ||
for spec in specs | ||
]), | ||
}, | ||
} |
Oops, something went wrong.