Skip to content

Commit

Permalink
ci(kubernetes-ci): install CRDs before linting manifests
Browse files Browse the repository at this point in the history
Signed-off-by: Siddhesh Mhadnak <[email protected]>
  • Loading branch information
sid-maddy committed Nov 26, 2023
1 parent fb0c82e commit ae6dcae
Show file tree
Hide file tree
Showing 9 changed files with 4,807 additions and 29 deletions.
43 changes: 38 additions & 5 deletions .github/workflows/kubernetes-ci.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: CI - Kubernetes

on:
Expand All @@ -6,24 +7,56 @@ on:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash

jobs:
lint:
name: Lint manifests

strategy:
fail-fast: false
matrix:
kubernetes-version:
- 1.27.2

runs-on: ubuntu-22.04
env:
KUBECONFIG: /home/runner/.kube/config
steps:
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Find manifests
id: manifests
shell: bash
run: |
echo "manifests<<EOF" >> $GITHUB_OUTPUT
python3 scripts/find_manifests.py >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo 'manifests<<EOF' >> "${GITHUB_OUTPUT}"
python3 scripts/python/find_manifests.py >> "${GITHUB_OUTPUT}"
echo 'EOF' >> "${GITHUB_OUTPUT}"
- name: Setup minikube
uses: medyagh/setup-minikube@96f4d627064f720ae7a9eb1116e590f9f1287867
with:
driver: docker
cpus: 2
memory: 2g

minikube-version: 1.32.0
kubernetes-version: ${{ matrix.kubernetes-version }}
timeout-minutes: 3

- name: Install CRDs
run: |
python3 -m pip install -r scripts/python/requirements.txt
python3 scripts/python/install_crds.py
- name: Lint manifests
uses: sid-maddy/k8s-lint@897009c442e242ea782988ddcc4c9dded9af86ba
uses: sid-maddy/k8s-lint@7c783e6819f2aab071f7dddc2387d0500a42cf2f
with:
lint-type: dry-run
manifests: ${{ steps.manifests.outputs.manifests }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ secrets.yaml

# Helm
kubernetes/chart/charts/*.tgz

# Python
.venv/
4,486 changes: 4,486 additions & 0 deletions kubernetes/crds/cert-manager.crds.yaml

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions scripts/bootstrap-vps.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#!/bin/bash
#!/usr/bin/env bash
# shellcheck shell=bash
# Script to bootstrap a new VPS with the necessary users and groups
set -e

groupadd vipyrsec

useradd --create-home --home-dir /home/shenanigansd --shell /bin/bash --groups sudo,vipyrsec --user-group shenanigansd
echo "shenanigansd:shadow" | chpasswd
echo 'shenanigansd:shadow' | chpasswd
mkdir /home/shenanigansd/.ssh
echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN+zdYNAzevMYs2uTKWmhW6lLtWWe24PHcVSo10MYX0W azuread\bradleyreynolds@5CD042JKKK" >/home/shenanigansd/.ssh/authorized_keys
echo 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN+zdYNAzevMYs2uTKWmhW6lLtWWe24PHcVSo10MYX0W azuread\bradleyreynolds@5CD042JKKK' >/home/shenanigansd/.ssh/authorized_keys
chown -R shenanigansd:shenanigansd /home/shenanigansd/.ssh
chmod 700 /home/shenanigansd/.ssh
chmod 600 /home/shenanigansd/.ssh/authorized_keys

useradd --create-home --home-dir /home/rem --shell /bin/bash --groups sudo,vipyrsec --user-group rem
echo "rem:shadow" | chpasswd
echo 'rem:shadow' | chpasswd
mkdir /home/rem/.ssh
echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICxt8Y50hNh192jUbOuhyah3bVUG0mUUXdo3dWe9uzHZ 44jmn@Syrup" >/home/rem/.ssh/authorized_keys
echo 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICxt8Y50hNh192jUbOuhyah3bVUG0mUUXdo3dWe9uzHZ 44jmn@Syrup' >/home/rem/.ssh/authorized_keys
chown -R rem:rem /home/rem/.ssh
chmod 700 /home/rem/.ssh
chmod 600 /home/rem/.ssh/authorized_keys
Expand Down
19 changes: 0 additions & 19 deletions scripts/find_manifests.py

This file was deleted.

24 changes: 24 additions & 0 deletions scripts/python/find_manifests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3
"""Search for Kubernetes manifests in the kubernetes/manifests/ directory."""

from __future__ import annotations

from pathlib import Path


def main() -> None:
"""Search for Kubernetes manifests in the kubernetes/manifests/ directory."""
manifests_dir = Path(__file__).parents[2] / "kubernetes/manifests"

for path in manifests_dir.rglob("*.yaml"):
if (
# Ignore manifests that start with _
not path.name.startswith("_")
# Path is likely a Kubernetes manifest
and "apiVersion:" in path.read_text()
):
print(path)


if __name__ == "__main__":
main()
26 changes: 26 additions & 0 deletions scripts/python/install_crds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python3
"""Install Kubernetes CRDs."""

from __future__ import annotations

from pathlib import PurePath

from kubernetes import client, config, utils


def main() -> None:
"""Install Kubernetes CRDs."""
config.load_kube_config()
api_client = client.ApiClient()

crd_dir = PurePath(__file__).parents[2] / "kubernetes/crds"

try:
utils.create_from_directory(api_client, yaml_dir=crd_dir, verbose=True)
except utils.FailToCreateError:
print("Failed to create some CRDs")
raise


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions scripts/python/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kubernetes==27.*
Loading

0 comments on commit ae6dcae

Please sign in to comment.