From a39fd0f7c2d3b292d3fd8f80bd95099da8e6f60e Mon Sep 17 00:00:00 2001 From: siddhantprateek Date: Sun, 25 Feb 2024 11:03:03 +0530 Subject: [PATCH 1/4] chore: add GitHub Actions workflow for manifest validation The commit adds a new GitHub Actions workflow file named "Manifest Validation". This workflow is triggered on push and pull requests to the master branch. The workflow runs on an Ubuntu environment and consists of a single job named "validation". The job performs the following steps: 1. Checks out the repository using the actions/checkout@v2 action. 2. Validates Kubernetes YAML files using the kubeval tool. The files to be validated are specified as "definition" and "resources". 3. The validation is performed using the makocchi-git/actions-k8s-manifests-validate-kubeval@v1.0.1 action. 4. The GitHub token is passed to the action using the secrets.GITHUB_TOKEN. --- .github/FUNDING.yml | 1 + .github/workflows/yaml-validator.yml | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/yaml-validator.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..e826a46 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: siddhantprateek \ No newline at end of file diff --git a/.github/workflows/yaml-validator.yml b/.github/workflows/yaml-validator.yml new file mode 100644 index 0000000..23a1bc3 --- /dev/null +++ b/.github/workflows/yaml-validator.yml @@ -0,0 +1,19 @@ +name: Manifest Validation + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + validation: + runs-on: ubuntu-latest + steps: + - name: Checkout to Repository + uses: actions/checkout@v2 + - name: Kubernetes yaml validation by kubeval + uses: makocchi-git/actions-k8s-manifests-validate-kubeval@v1.0.1 + with: + files: difinition,resources + token: ${{ secrets.GITHUB_TOKEN }} From 72596ed8cb643cfe97015a024fd365de18f5904e Mon Sep 17 00:00:00 2001 From: siddhantprateek Date: Sun, 25 Feb 2024 11:03:19 +0530 Subject: [PATCH 2/4] feat: add custom hotel booking resource definition Adds a new resource definition for a custom hotel booking in the hotels.com/v1 API version. The resource is named "custom-hotel-booking" and has the following specifications: - guestfrom: US - guestName: Anderson - days: 21 --- resources/hotelbooking.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 resources/hotelbooking.yml diff --git a/resources/hotelbooking.yml b/resources/hotelbooking.yml new file mode 100644 index 0000000..4e0687f --- /dev/null +++ b/resources/hotelbooking.yml @@ -0,0 +1,8 @@ +apiVersion: hotels.com/v1 +kind: HotelBooking +metadata: + name: custom-hotel-booking +spec: + guestfrom: US + guestName: Anderson + days: 21 \ No newline at end of file From ff9bc42a173472c1002307907d4c7c9660e3f83c Mon Sep 17 00:00:00 2001 From: siddhantprateek Date: Sun, 25 Feb 2024 11:03:30 +0530 Subject: [PATCH 3/4] feat: add CustomResourceDefinition for HotelBooking Adds a CustomResourceDefinition (CRD) for HotelBooking to the Kubernetes cluster. This CRD defines a new resource type called "hotelbooking.hotels.com" with the following specifications: - Scope: Namespaced - Group: hotels.com - Names: - Kind: HotelBooking - Singular: hotelbooking - Plural: hotelbookings - Short Names: hb - Versions: - Name: v1 - Served: true - Storage: true - Schema: - Type: Object - Properties: - Spec: - Type: object - Properties: - guestfrom: - Type: string - guestName: - Type: string - days: - Type: integer - Minimum: 1 - Maximum: 90 --- definition/custom-definition.yml | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 definition/custom-definition.yml diff --git a/definition/custom-definition.yml b/definition/custom-definition.yml new file mode 100644 index 0000000..e1f2d76 --- /dev/null +++ b/definition/custom-definition.yml @@ -0,0 +1,35 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: hotelbooking.hotels.com +spec: + scope: Namespaced + group: hotels.com + names: + kind: HotelBooking + singular: hotelbooking + plural: hotelbookings + shortNames: + - hb + versions: + - name: v1 + served: true + storage: true + + schema: + openAPIV3Schema: + type: Object + properties: + spec: + type: object + properties: + guestfrom: + type: string + guestName: + type: string + days: + type: integer + minimum: 1 + maximum: 90 + + From 51e9d15b263ae3d1b21a2a3a361596e11bf01278 Mon Sep 17 00:00:00 2001 From: siddhantprateek Date: Sun, 25 Feb 2024 11:03:36 +0530 Subject: [PATCH 4/4] docs: add setup instructions for k8s-crds - Added requirements section to specify the need for Kubernetes (minikube) - Added setup instructions for creating custom resource definition and custom resources using kubectl apply command --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4290680..cefa805 100644 --- a/README.md +++ b/README.md @@ -1 +1,17 @@ -# k8s-crds \ No newline at end of file +# k8s-crds + +Requirements: +- `Kubernetes` (minikube) + + +## Setting up + +- Create custom resource defination +```bash +kubectl apply -f definition/custom-definition.yml +``` + +- Create custom resource +```bash +kubectl apply -f resources/* +``` \ No newline at end of file