From aba229d32e710f13bcae74e4df5e64f08245b619 Mon Sep 17 00:00:00 2001 From: Stav matityhau Date: Wed, 21 May 2025 15:26:07 +0300 Subject: [PATCH 1/9] Add CI workflow to test kor against live Kubernetes cluster --- .github/workflows/kor-ci.yaml | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/kor-ci.yaml diff --git a/.github/workflows/kor-ci.yaml b/.github/workflows/kor-ci.yaml new file mode 100644 index 00000000..f7a687a3 --- /dev/null +++ b/.github/workflows/kor-ci.yaml @@ -0,0 +1,55 @@ +name: Kor CI Test + +on: + pull_request: + branches: [main] + +jobs: + kor-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.23.2' + + - name: Install kind + run: | + curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64 + chmod +x ./kind + sudo mv ./kind /usr/local/bin/kind + + - name: Create Kind cluster + run: | + kind create cluster + kubectl cluster-info + + - name: Deploy resources (Deployment + Service) + run: | + kubectl create deployment nginx --image=nginx + kubectl expose deployment nginx --port=80 --target-port=80 + echo "=== Resources created ===" + kubectl get all + + - name: Build kor + run: | + go build -o kor ./cmd + + - name: Run kor all before deletion + run: | + echo "=== kor output BEFORE delete ===" + ./kor all + + - name: Run kor all --delete + run: | + echo "=== Running kor all --delete ===" + ./kor all --delete + + - name: Run kor all after deletion + run: | + echo "=== kor output AFTER delete ===" + ./kor all From 094f48e2cbb6b33c63c01ab51ca5fc15502cd102 Mon Sep 17 00:00:00 2001 From: Stav matityhau Date: Wed, 21 May 2025 15:26:26 +0300 Subject: [PATCH 2/9] Add CI workflow to test kor against live Kubernetes cluster --- .github/workflows/kor-ci.yaml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/kor-ci.yaml b/.github/workflows/kor-ci.yaml index f7a687a3..8736c84f 100644 --- a/.github/workflows/kor-ci.yaml +++ b/.github/workflows/kor-ci.yaml @@ -17,16 +17,8 @@ jobs: with: go-version: '1.23.2' - - name: Install kind - run: | - curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64 - chmod +x ./kind - sudo mv ./kind /usr/local/bin/kind - - - name: Create Kind cluster - run: | - kind create cluster - kubectl cluster-info + - name: Set up Kind + uses: helm/kind-action@v1.8.0 - name: Deploy resources (Deployment + Service) run: | From 7f4e8a565725e0fb4536512359988513c9330d7b Mon Sep 17 00:00:00 2001 From: Stav matityhau Date: Wed, 21 May 2025 15:45:39 +0300 Subject: [PATCH 3/9] Update the build kor task --- .github/workflows/kor-ci.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/kor-ci.yaml b/.github/workflows/kor-ci.yaml index 8736c84f..5a39b101 100644 --- a/.github/workflows/kor-ci.yaml +++ b/.github/workflows/kor-ci.yaml @@ -29,19 +29,19 @@ jobs: - name: Build kor run: | - go build -o kor ./cmd + go build -o kor main.go - name: Run kor all before deletion run: | echo "=== kor output BEFORE delete ===" - ./kor all + go run main.go all - name: Run kor all --delete run: | echo "=== Running kor all --delete ===" - ./kor all --delete + go run main.go all --delete - name: Run kor all after deletion run: | echo "=== kor output AFTER delete ===" - ./kor all + go run main.go all From 233a28f92e2b34ff494d40c5a4b823b845e95d4f Mon Sep 17 00:00:00 2001 From: Stav matityhau Date: Wed, 21 May 2025 16:11:26 +0300 Subject: [PATCH 4/9] Create the resource and added resource file --- .github/workflows/kor-ci.yaml | 5 ++--- k8s/example-resources.yaml | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 k8s/example-resources.yaml diff --git a/.github/workflows/kor-ci.yaml b/.github/workflows/kor-ci.yaml index 5a39b101..09e4ab2d 100644 --- a/.github/workflows/kor-ci.yaml +++ b/.github/workflows/kor-ci.yaml @@ -20,10 +20,9 @@ jobs: - name: Set up Kind uses: helm/kind-action@v1.8.0 - - name: Deploy resources (Deployment + Service) + - name: Deploy test resources from YAML run: | - kubectl create deployment nginx --image=nginx - kubectl expose deployment nginx --port=80 --target-port=80 + kubectl apply -f k8s/unused-demo.yaml echo "=== Resources created ===" kubectl get all diff --git a/k8s/example-resources.yaml b/k8s/example-resources.yaml new file mode 100644 index 00000000..624fe5ee --- /dev/null +++ b/k8s/example-resources.yaml @@ -0,0 +1,34 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx + labels: + app: nginx +spec: + replicas: 1 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: nginx +spec: + selector: + app: nginx + ports: + - protocol: TCP + port: 80 + targetPort: 80 + type: ClusterIP From 1e8f8f948bcc7c92143dd890ff48c1e74b7aa3fd Mon Sep 17 00:00:00 2001 From: Stav matityhau Date: Wed, 21 May 2025 16:28:19 +0300 Subject: [PATCH 5/9] Get the files from ci branch --- .github/workflows/kor-ci.yaml | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/kor-ci.yaml b/.github/workflows/kor-ci.yaml index 09e4ab2d..6ca4c744 100644 --- a/.github/workflows/kor-ci.yaml +++ b/.github/workflows/kor-ci.yaml @@ -9,15 +9,17 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout code + - name: Checkout code from PR branch uses: actions/checkout@v3 + with: + ref: ${{ github.head_ref }} - name: Set up Go uses: actions/setup-go@v4 with: go-version: '1.23.2' - - name: Set up Kind + - name: Set up Kind cluster uses: helm/kind-action@v1.8.0 - name: Deploy test resources from YAML @@ -26,10 +28,6 @@ jobs: echo "=== Resources created ===" kubectl get all - - name: Build kor - run: | - go build -o kor main.go - - name: Run kor all before deletion run: | echo "=== kor output BEFORE delete ===" @@ -44,3 +42,14 @@ jobs: run: | echo "=== kor output AFTER delete ===" go run main.go all + + - name: Verify no unused resources remain + run: | + REMAINING=$(go run main.go all | wc -l) + echo "Lines of output from kor all: $REMAINING" + if [ "$REMAINING" -gt 1 ]; then + echo "There are still unused resources after deletion" + exit 1 + else + echo "All unused resources successfully deleted" + fi From bed894a8bc00f5de3bd7bbd7a8c84f728eebe4d5 Mon Sep 17 00:00:00 2001 From: Stav matityhau Date: Wed, 21 May 2025 16:37:20 +0300 Subject: [PATCH 6/9] Remove unused k8s test resources --- k8s/example-resources.yaml | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 k8s/example-resources.yaml diff --git a/k8s/example-resources.yaml b/k8s/example-resources.yaml deleted file mode 100644 index 624fe5ee..00000000 --- a/k8s/example-resources.yaml +++ /dev/null @@ -1,34 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: nginx - labels: - app: nginx -spec: - replicas: 1 - selector: - matchLabels: - app: nginx - template: - metadata: - labels: - app: nginx - spec: - containers: - - name: nginx - image: nginx - ports: - - containerPort: 80 ---- -apiVersion: v1 -kind: Service -metadata: - name: nginx -spec: - selector: - app: nginx - ports: - - protocol: TCP - port: 80 - targetPort: 80 - type: ClusterIP From 93629a432591aa0c9cba31805c5d2211a90feb41 Mon Sep 17 00:00:00 2001 From: Stav matityhau Date: Wed, 21 May 2025 16:39:42 +0300 Subject: [PATCH 7/9] Add CI workflow: create Kind cluster, deploy test resources, and validate kor deletion --- .github/workflows/kor-ci.yaml | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/.github/workflows/kor-ci.yaml b/.github/workflows/kor-ci.yaml index 6ca4c744..291c2efb 100644 --- a/.github/workflows/kor-ci.yaml +++ b/.github/workflows/kor-ci.yaml @@ -9,10 +9,8 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout code from PR branch + - name: Checkout code uses: actions/checkout@v3 - with: - ref: ${{ github.head_ref }} - name: Set up Go uses: actions/setup-go@v4 @@ -22,9 +20,10 @@ jobs: - name: Set up Kind cluster uses: helm/kind-action@v1.8.0 - - name: Deploy test resources from YAML + - name: Deploy test resources via kubectl commands run: | - kubectl apply -f k8s/unused-demo.yaml + kubectl create deployment nginx --image=nginx + kubectl expose deployment nginx --port=80 --target-port=80 echo "=== Resources created ===" kubectl get all @@ -42,14 +41,3 @@ jobs: run: | echo "=== kor output AFTER delete ===" go run main.go all - - - name: Verify no unused resources remain - run: | - REMAINING=$(go run main.go all | wc -l) - echo "Lines of output from kor all: $REMAINING" - if [ "$REMAINING" -gt 1 ]; then - echo "There are still unused resources after deletion" - exit 1 - else - echo "All unused resources successfully deleted" - fi From a49d915316d7bf889e93cce1d3707dbc1f9e9721 Mon Sep 17 00:00:00 2001 From: Stav matityhau Date: Sun, 25 May 2025 14:43:34 +0300 Subject: [PATCH 8/9] Add basic CI to test kor all --delete against unused Kubernetes resources --- .github/workflows/kor-ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/kor-ci.yaml b/.github/workflows/kor-ci.yaml index 291c2efb..2bc1cded 100644 --- a/.github/workflows/kor-ci.yaml +++ b/.github/workflows/kor-ci.yaml @@ -22,7 +22,7 @@ jobs: - name: Deploy test resources via kubectl commands run: | - kubectl create deployment nginx --image=nginx + kubectl create deployment nginx --image=nginx --replicas=0 kubectl expose deployment nginx --port=80 --target-port=80 echo "=== Resources created ===" kubectl get all From 466f61ce3d21ba5353cc81772885a7381a065475 Mon Sep 17 00:00:00 2001 From: Stav matityhau Date: Sun, 25 May 2025 14:48:44 +0300 Subject: [PATCH 9/9] Add --no-interactive flag to kor all --delete --- .github/workflows/kor-ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/kor-ci.yaml b/.github/workflows/kor-ci.yaml index 2bc1cded..e05305d8 100644 --- a/.github/workflows/kor-ci.yaml +++ b/.github/workflows/kor-ci.yaml @@ -35,7 +35,7 @@ jobs: - name: Run kor all --delete run: | echo "=== Running kor all --delete ===" - go run main.go all --delete + go run main.go all --delete --no-interactive - name: Run kor all after deletion run: |