From 214cce1cc9f8179742af691f777934a8742732d1 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Wed, 8 Mar 2023 12:54:34 +0100 Subject: [PATCH] initial commit --- .drone.yml | 64 ++++++++++++++++++++++++++++++++++++++ .gitignore | 1 + LICENSE | 21 +++++++++++++ Makefile | 27 ++++++++++++++++ README.md | 20 ++++++++++++ generate.sh | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 221 insertions(+) create mode 100644 .drone.yml create mode 100755 .gitignore create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100755 generate.sh diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..6c956c0 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,64 @@ +--- +kind: pipeline +name: build + +platform: + os: linux + arch: amd64 + +steps: + - name: generate + image: thegeeklab/alpine-tools + commands: + - curl -SsfL -o /usr/local/bin/openapi2jsonschema "https://raw.githubusercontent.com/yannh/kubeconform/master/scripts/openapi2jsonschema.py" + - chmod +x /usr/local/bin/openapi2jsonschema + - make + +trigger: + ref: + - refs/heads/main + - refs/tags/** + - refs/pull/** + +--- +kind: pipeline +name: notifications + +platform: + os: linux + arch: amd64 + +steps: + - name: matrix + image: thegeeklab/drone-matrix + settings: + homeserver: + from_secret: matrix_homeserver + password: + from_secret: matrix_password + roomid: + from_secret: matrix_roomid + template: "Status: **{{ .Build.Status }}**
Build: [{{ .Repo.Owner }}/{{ .Repo.Name }}]({{ .Build.Link }}){{ if .Build.Branch }} ({{ .Build.Branch }}){{ end }} by {{ .Commit.Author }}
Message: {{ .Commit.Message.Title }}" + username: + from_secret: matrix_username + when: + status: + - success + - failure + +trigger: + ref: + - refs/heads/main + - refs/tags/** + status: + - success + - failure + +depends_on: + - build + +--- +kind: signature +hmac: a72cd768ef5389dc4d62333cf26ec47c9a7b14a3d244fa76c15ca73887cd1296 + +... diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..9b1c8b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/dist diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3812eb4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Robert Kaussow + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..02f7e33 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +CWD ?= $(shell pwd) + +.EXPORT_ALL_VARIABLES: +DIST := $(CWD)/dist +TMP_CRD_DIR := $(HOME)/.crds-catalog +DIST_DIRS := $(DIST) $(TMP_CRD_DIR) + +# renovate: datasource=github-releases depName=projectcalico/calico +CALICO_VERSION := v3.25.0 +# renovate: datasource=github-releases depName=fluxcd/flux2 +FLUXCD_VERSION := v0.40.0 +# renovate: datasource=github-releases depName=cert-manager/cert-manager +CERTMANAGER_VERSION := v1.11.0 +# renovate: datasource=github-releases depName=cloudnative-pg/cloudnative-pg +CNPG_VERSION := v1.19.0 + +.PHONY: all +all: clean generate + +.PHONY: clean +clean: + @rm -rf $(DIST_DIRS) + +.PHONY: generate +generate: + @mkdir -p $(DIST) + @./generate.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..73436f8 --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# crds-catalog + +[![Build Status](https://img.shields.io/drone/build/infra/crds-catalog?logo=drone&server=https%3A%2F%2Fdrone.rknet.org)](https://drone.rknet.org/infra/crds-catalog) +[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?label=license)](LICENSE) + +This repository to aggregatepopular Kubernetes CRDs (CustomResourceDefinition) in JSON schema format. These schemas can be used by various tools such as Datree, Kubeconform and Kubeval to perform validation on custom (and native) Kuberentes resources. Running Kubernetes schema validation checks helps apply the "shift-left approach" on machines without giving them access to your cluster (e.g. locally or on CI). + +The project is inspired by [Datree's CRDs-catalog](https://github.com/datreeio/CRDs-catalog) and was created to manage CRDs required for my own Kubernetes deployments. + +## Usage + +### Kubeconform + +```Shell +kubeconform -schema-location default -schema-location 'https://gitea.rknet.org/infra/crds-catalog/raw/branch/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json' [MANIFEST] +``` + +## License + +This project is licensed under the MIT License - see the [LICENSE](https://github.com/ansible/galaxy/blob/main/LICENSE) file for details. diff --git a/generate.sh b/generate.sh new file mode 100755 index 0000000..96cf35a --- /dev/null +++ b/generate.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash +set -eo pipefail +shopt -s globstar + +default_openapi_handler() { + printf "Processing %s ...\n" $API + mkdir -p "${WORKDIR}" + curl -SsfL -o "${WORKDIR}/${NAME}.crds.yaml" "${SOURCE}" + ( + cd "$WORKDIR" + openapi2jsonschema "${NAME}.crds.yaml" >/dev/null + ) + + TARGET_DIR="$DIST/$API" + mkdir -p "$TARGET_DIR" + + for FILE in "${WORKDIR}"/*.json; do + FILENAME=$(basename "$FILE") + + mv "$FILE" "$TARGET_DIR/$FILENAME" + done +} + +## Calico +API=projectcalico.org +WORKDIR="${TMP_CRD_DIR}/calico" +SOURCE=" " + +printf "Processing %s ...\n" $API +mkdir -p "${WORKDIR}" +curl -SsfL -o "${WORKDIR}/calico.crds.yaml" "${SOURCE}" +( + cd "$WORKDIR" + openapi2jsonschema "calico.crds.yaml" >/dev/null +) + +TARGET_DIR="$DIST/$API" +mkdir -p "$TARGET_DIR" + +for FILE in "${WORKDIR}"/*.json; do + FILENAME=$(basename "$FILE") + + mv "$FILE" "$TARGET_DIR/${FILENAME//_v1/_v3}" +done + +## Flux2 +API=toolkit.fluxcd.io +WORKDIR="${TMP_CRD_DIR}/flux" +SOURCE="https://github.com/fluxcd/flux2/releases/download/${FLUXCD_VERSION}/crd-schemas.tar.gz" + +printf "Processing %s ...\n" $API +mkdir -p "${WORKDIR}" +curl -SsfL "${SOURCE}" | tar xz -C "${WORKDIR}" + +for FILE in "${WORKDIR}"/*.json; do + FILENAME=$(basename "$FILE") + PREFIX="${FILENAME%%\-*}" + MIDDLE="${FILENAME#*-}" + SUFFIX="${MIDDLE#*-}" + MIDDLE="${MIDDLE%%\-*}" + + TARGET_DIR="$DIST/$MIDDLE.$API" + TARGET_NAME="$TARGET_DIR/$PREFIX""_""$SUFFIX" + + mkdir -p "$TARGET_DIR" + mv "$FILE" "$TARGET_NAME" +done + +## Cloudnative-PG +API=postgresql.cnpg.io +NAME=cnpg +WORKDIR="${TMP_CRD_DIR}/$NAME" +SOURCE="https://github.com/cloudnative-pg/cloudnative-pg/releases/download/${CNPG_VERSION}/cnpg-${CNPG_VERSION##v}.yaml" +default_openapi_handler + +## Cert-Manager +API=cert-manager.io +NAME=cert-manager +WORKDIR="${TMP_CRD_DIR}/$NAME" +SOURCE="https://github.com/cert-manager/cert-manager/releases/download/${CERTMANAGER_VERSION}/cert-manager.crds.yaml" +default_openapi_handler + +## Minio +API=minio.min.io +NAME=minio +WORKDIR="${TMP_CRD_DIR}/$NAME" +SOURCE="https://raw.githubusercontent.com/minio/operator/v4.5.8/resources/base/crds/minio.min.io_tenants.yaml" +default_openapi_handler