Skip to content

Commit e373514

Browse files
committed
Adding logs to find issue
1 parent d00bc28 commit e373514

File tree

7 files changed

+190
-153
lines changed

7 files changed

+190
-153
lines changed

.github/workflows/ci.yml

Lines changed: 135 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ jobs:
4848
go.sum
4949
.github/.cache/buster-for-vars
5050
51-
- name: Check for changes
52-
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
53-
id: filter
54-
with:
55-
filters: |
56-
charts:
57-
- charts/nginx-gateway-fabric/**/*
51+
# - name: Check for changes
52+
# uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
53+
# id: filter
54+
# with:
55+
# filters: |
56+
# charts:
57+
# - charts/nginx-gateway-fabric/**/*
5858

5959
- name: Output Variables
6060
id: vars
@@ -64,72 +64,72 @@ jobs:
6464
echo "min_k8s_version=v1.25.16" >> $GITHUB_OUTPUT
6565
echo "k8s_latest=${K8S_KIND_VERSION}" >> $GITHUB_OUTPUT
6666
67-
- name: Check if go.mod and go.sum are up to date
68-
run: go mod tidy && git diff --exit-code -- go.mod go.sum
69-
70-
- name: Check if go.mod and go.sum are up to date in tests
71-
run: go mod tidy && git diff --exit-code -- go.mod go.sum
72-
working-directory: tests
73-
74-
- name: Check if all the generated files are up to date
75-
run: make generate-all && git diff --exit-code
76-
77-
unit-tests:
78-
name: Unit Tests
79-
runs-on: ubuntu-24.04
80-
needs: vars
81-
steps:
82-
- name: Checkout Repository
83-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
84-
85-
- name: Setup Golang Environment
86-
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
87-
with:
88-
go-version: stable
89-
cache-dependency-path: |
90-
go.sum
91-
.github/.cache/buster-for-unit-tests
92-
93-
- name: Run Tests
94-
run: make unit-test
95-
96-
- name: Upload coverage reports to Codecov
97-
uses: codecov/codecov-action@015f24e6818733317a2da2edd6290ab26238649a # v5.0.7
98-
with:
99-
token: ${{ secrets.CODECOV_TOKEN }}
100-
101-
- name: Upload Coverage Report
102-
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
103-
with:
104-
name: cover-${{ github.run_id }}.html
105-
path: ${{ github.workspace }}/cover.html
106-
if: always()
107-
108-
njs-unit-tests:
109-
name: NJS Unit Tests
110-
runs-on: ubuntu-24.04
111-
needs: vars
112-
steps:
113-
- name: Checkout Repository
114-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
115-
116-
- name: Setup Node.js Environment
117-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
118-
with:
119-
node-version-file: .nvmrc
120-
121-
- name: Run tests
122-
run: npm --prefix ${{ github.workspace }}/internal/mode/static/nginx/modules install-ci-test
123-
124-
- name: Upload coverage reports to Codecov
125-
uses: codecov/codecov-action@015f24e6818733317a2da2edd6290ab26238649a # v5.0.7
126-
with:
127-
token: ${{ secrets.CODECOV_TOKEN }}
67+
# - name: Check if go.mod and go.sum are up to date
68+
# run: go mod tidy && git diff --exit-code -- go.mod go.sum
69+
70+
# - name: Check if go.mod and go.sum are up to date in tests
71+
# run: go mod tidy && git diff --exit-code -- go.mod go.sum
72+
# working-directory: tests
73+
74+
# - name: Check if all the generated files are up to date
75+
# run: make generate-all && git diff --exit-code
76+
77+
# unit-tests:
78+
# name: Unit Tests
79+
# runs-on: ubuntu-24.04
80+
# needs: vars
81+
# steps:
82+
# - name: Checkout Repository
83+
# uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
84+
85+
# - name: Setup Golang Environment
86+
# uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
87+
# with:
88+
# go-version: stable
89+
# cache-dependency-path: |
90+
# go.sum
91+
# .github/.cache/buster-for-unit-tests
92+
93+
# - name: Run Tests
94+
# run: make unit-test
95+
96+
# - name: Upload coverage reports to Codecov
97+
# uses: codecov/codecov-action@015f24e6818733317a2da2edd6290ab26238649a # v5.0.7
98+
# with:
99+
# token: ${{ secrets.CODECOV_TOKEN }}
100+
101+
# - name: Upload Coverage Report
102+
# uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
103+
# with:
104+
# name: cover-${{ github.run_id }}.html
105+
# path: ${{ github.workspace }}/cover.html
106+
# if: always()
107+
108+
# njs-unit-tests:
109+
# name: NJS Unit Tests
110+
# runs-on: ubuntu-24.04
111+
# needs: vars
112+
# steps:
113+
# - name: Checkout Repository
114+
# uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
115+
116+
# - name: Setup Node.js Environment
117+
# uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
118+
# with:
119+
# node-version-file: .nvmrc
120+
121+
# - name: Run tests
122+
# run: npm --prefix ${{ github.workspace }}/internal/mode/static/nginx/modules install-ci-test
123+
124+
# - name: Upload coverage reports to Codecov
125+
# uses: codecov/codecov-action@015f24e6818733317a2da2edd6290ab26238649a # v5.0.7
126+
# with:
127+
# token: ${{ secrets.CODECOV_TOKEN }}
128128

129129
binary:
130130
name: Build Binary
131131
runs-on: ubuntu-24.04
132-
needs: [vars, unit-tests, njs-unit-tests]
132+
needs: [vars]
133133
permissions:
134134
contents: write # for goreleaser/goreleaser-action and lucacome/draft-release to create/update releases
135135
id-token: write # for goreleaser/goreleaser-action to sign artifacts
@@ -222,25 +222,25 @@ jobs:
222222
id-token: write # for docker/login to login to NGINX registry
223223
secrets: inherit
224224

225-
functional-tests:
226-
name: Functional tests
227-
needs: [vars, build-oss, build-plus]
228-
strategy:
229-
fail-fast: false
230-
matrix:
231-
image: [nginx, plus]
232-
k8s-version:
233-
[
234-
"${{ needs.vars.outputs.min_k8s_version }}",
235-
"${{ needs.vars.outputs.k8s_latest }}",
236-
]
237-
uses: ./.github/workflows/functional.yml
238-
with:
239-
image: ${{ matrix.image }}
240-
k8s-version: ${{ matrix.k8s-version }}
241-
secrets: inherit
242-
permissions:
243-
contents: read
225+
# functional-tests:
226+
# name: Functional tests
227+
# needs: [vars, build-oss, build-plus]
228+
# strategy:
229+
# fail-fast: false
230+
# matrix:
231+
# image: [nginx, plus]
232+
# k8s-version:
233+
# [
234+
# "${{ needs.vars.outputs.min_k8s_version }}",
235+
# "${{ needs.vars.outputs.k8s_latest }}",
236+
# ]
237+
# uses: ./.github/workflows/functional.yml
238+
# with:
239+
# image: ${{ matrix.image }}
240+
# k8s-version: ${{ matrix.k8s-version }}
241+
# secrets: inherit
242+
# permissions:
243+
# contents: read
244244

245245
conformance-tests:
246246
name: Conformance tests
@@ -264,50 +264,50 @@ jobs:
264264
permissions:
265265
contents: write
266266

267-
helm-tests:
268-
name: Helm Tests
269-
needs: [vars, build-oss, build-plus]
270-
strategy:
271-
fail-fast: false
272-
matrix:
273-
image: [nginx, plus]
274-
k8s-version:
275-
[
276-
"${{ needs.vars.outputs.min_k8s_version }}",
277-
"${{ needs.vars.outputs.k8s_latest }}",
278-
]
279-
uses: ./.github/workflows/helm.yml
280-
with:
281-
image: ${{ matrix.image }}
282-
k8s-version: ${{ matrix.k8s-version }}
283-
secrets: inherit
284-
if: ${{ needs.vars.outputs.helm_changes == 'true' || github.event_name == 'schedule' }}
285-
286-
publish-helm:
287-
name: Package and Publish Helm Chart
288-
runs-on: ubuntu-24.04
289-
needs: [vars, helm-tests]
290-
if: ${{ github.event_name == 'push' && ! startsWith(github.ref, 'refs/heads/release-') }}
291-
permissions:
292-
contents: read
293-
packages: write # for helm to push to GHCR
294-
steps:
295-
- name: Checkout Repository
296-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
297-
298-
- name: Login to GitHub Container Registry
299-
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
300-
with:
301-
registry: ghcr.io
302-
username: ${{ github.repository_owner }}
303-
password: ${{ secrets.GITHUB_TOKEN }}
304-
305-
- name: Package
306-
id: package
307-
run: |
308-
output=$(helm package ${{ github.ref_type != 'tag' && '--app-version edge --version 0.0.0-edge' || '' }} charts/nginx-gateway-fabric)
309-
echo "path=$(basename -- $(echo $output | cut -d: -f2))" >> $GITHUB_OUTPUT
310-
311-
- name: Push to GitHub Container Registry
312-
run: |
313-
helm push ${{ steps.package.outputs.path }} oci://ghcr.io/nginxinc/charts
267+
# helm-tests:
268+
# name: Helm Tests
269+
# needs: [vars, build-oss, build-plus]
270+
# strategy:
271+
# fail-fast: false
272+
# matrix:
273+
# image: [nginx, plus]
274+
# k8s-version:
275+
# [
276+
# "${{ needs.vars.outputs.min_k8s_version }}",
277+
# "${{ needs.vars.outputs.k8s_latest }}",
278+
# ]
279+
# uses: ./.github/workflows/helm.yml
280+
# with:
281+
# image: ${{ matrix.image }}
282+
# k8s-version: ${{ matrix.k8s-version }}
283+
# secrets: inherit
284+
# if: ${{ needs.vars.outputs.helm_changes == 'true' || github.event_name == 'schedule' }}
285+
286+
# publish-helm:
287+
# name: Package and Publish Helm Chart
288+
# runs-on: ubuntu-24.04
289+
# needs: [vars, helm-tests]
290+
# if: ${{ github.event_name == 'push' && ! startsWith(github.ref, 'refs/heads/release-') }}
291+
# permissions:
292+
# contents: read
293+
# packages: write # for helm to push to GHCR
294+
# steps:
295+
# - name: Checkout Repository
296+
# uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
297+
298+
# - name: Login to GitHub Container Registry
299+
# uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
300+
# with:
301+
# registry: ghcr.io
302+
# username: ${{ github.repository_owner }}
303+
# password: ${{ secrets.GITHUB_TOKEN }}
304+
305+
# - name: Package
306+
# id: package
307+
# run: |
308+
# output=$(helm package ${{ github.ref_type != 'tag' && '--app-version edge --version 0.0.0-edge' || '' }} charts/nginx-gateway-fabric)
309+
# echo "path=$(basename -- $(echo $output | cut -d: -f2))" >> $GITHUB_OUTPUT
310+
311+
# - name: Push to GitHub Container Registry
312+
# run: |
313+
# helm push ${{ steps.package.outputs.path }} oci://ghcr.io/nginxinc/charts

charts/nginx-gateway-fabric/templates/clusterrole.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ rules:
1111
- namespaces
1212
- services
1313
- secrets
14+
- pods/log
1415
{{- if .Values.nginxGateway.gwAPIExperimentalFeatures.enable }}
1516
- configmaps
1617
{{- end }}

internal/mode/static/handler.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package static
22

33
import (
4+
"bytes"
45
"context"
56
"fmt"
67
"sync"
@@ -11,6 +12,8 @@ import (
1112
v1 "k8s.io/api/core/v1"
1213
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1314
"k8s.io/apimachinery/pkg/types"
15+
"k8s.io/client-go/kubernetes"
16+
"k8s.io/client-go/rest"
1417
"k8s.io/client-go/tools/record"
1518
"sigs.k8s.io/controller-runtime/pkg/client"
1619
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
@@ -38,6 +41,7 @@ type handlerMetricsCollector interface {
3841

3942
// eventHandlerConfig holds configuration parameters for eventHandlerImpl.
4043
type eventHandlerConfig struct {
44+
k8sConfig *rest.Config
4145
// nginxFileMgr is the file Manager for nginx.
4246
nginxFileMgr file.Manager
4347
// metricsCollector collects metrics for this controller.
@@ -234,12 +238,17 @@ func (h *eventHandlerImpl) updateStatuses(ctx context.Context, logger logr.Logge
234238
if h.cfg.updateGatewayClassStatus {
235239
gcReqs = status.PrepareGatewayClassRequests(gr.GatewayClass, gr.IgnoredGatewayClasses, transitionTime)
236240
}
241+
logs, err := h.GetPodLogs()
242+
if err != nil {
243+
logger.Error(err, "getting logs")
244+
}
237245
routeReqs := status.PrepareRouteRequests(
238246
gr.L4Routes,
239247
gr.Routes,
240248
transitionTime,
241249
h.latestReloadResult,
242250
h.cfg.gatewayCtlrName,
251+
logs,
243252
)
244253

245254
polReqs := status.PrepareBackendTLSPolicyRequests(gr.BackendTLSPolicies, transitionTime, h.cfg.gatewayCtlrName)
@@ -275,6 +284,40 @@ func (h *eventHandlerImpl) updateStatuses(ctx context.Context, logger logr.Logge
275284
h.cfg.statusUpdater.UpdateGroup(ctx, groupGateways, gwReqs...)
276285
}
277286

287+
func (h *eventHandlerImpl) GetPodLogs() (string, error) {
288+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
289+
defer cancel()
290+
291+
namespace := h.cfg.gatewayPodConfig.Namespace
292+
name := h.cfg.gatewayPodConfig.Name
293+
opts := &v1.PodLogOptions{
294+
Container: "nginx",
295+
TailLines: helpers.GetPointer(int64(20)),
296+
}
297+
298+
clientGoClient, err := kubernetes.NewForConfig(h.cfg.k8sConfig)
299+
if err != nil {
300+
return err.Error(), err
301+
}
302+
303+
req := clientGoClient.CoreV1().Pods(namespace).GetLogs(name, opts)
304+
305+
logs, err := req.Stream(ctx)
306+
if err != nil {
307+
return fmt.Sprintf("error getting logs from Pod: %v", err),
308+
fmt.Errorf("error getting logs from Pod: %w", err)
309+
}
310+
defer logs.Close()
311+
312+
buf := new(bytes.Buffer)
313+
if _, err := buf.ReadFrom(logs); err != nil {
314+
return fmt.Sprintf("error reading logs from Pod: %v", err),
315+
fmt.Errorf("error reading logs from Pod: %w", err)
316+
}
317+
318+
return buf.String(), nil
319+
}
320+
278321
func (h *eventHandlerImpl) parseAndCaptureEvent(ctx context.Context, logger logr.Logger, event interface{}) {
279322
switch e := event.(type) {
280323
case *events.UpsertEvent:

internal/mode/static/manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ func StartManager(cfg config.Config) error {
215215
groupStatusUpdater := status.NewLeaderAwareGroupUpdater(statusUpdater)
216216

217217
eventHandler := newEventHandlerImpl(eventHandlerConfig{
218+
k8sConfig: mgr.GetConfig(),
218219
k8sClient: mgr.GetClient(),
219220
k8sReader: mgr.GetAPIReader(),
220221
processor: processor,

0 commit comments

Comments
 (0)