Skip to content

Commit 2043d80

Browse files
committed
Adding logs to find issue
1 parent 9fb7b33 commit 2043d80

File tree

5 files changed

+170
-120
lines changed

5 files changed

+170
-120
lines changed

.github/workflows/ci.yml

Lines changed: 118 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -74,62 +74,62 @@ jobs:
7474
- name: Check if all the generated files are up to date
7575
run: make generate-all && git diff --exit-code
7676

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@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0
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@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0
126-
with:
127-
token: ${{ secrets.CODECOV_TOKEN }}
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@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0
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@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0
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

internal/mode/static/handler.go

Lines changed: 46 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.
@@ -263,6 +267,11 @@ func (h *eventHandlerImpl) updateStatuses(ctx context.Context, logger logr.Logge
263267

264268
h.cfg.statusUpdater.UpdateGroup(ctx, groupAllExceptGateways, reqs...)
265269

270+
logs, err := h.GetPodLogs()
271+
if err != nil {
272+
logger.Error(err, "getting logs")
273+
}
274+
266275
// We put Gateway status updates separately from the rest of the statuses because we want to be able
267276
// to update them separately from the rest of the graph whenever the public IP of NGF changes.
268277
gwReqs := status.PrepareGatewayRequests(
@@ -271,10 +280,45 @@ func (h *eventHandlerImpl) updateStatuses(ctx context.Context, logger logr.Logge
271280
transitionTime,
272281
gwAddresses,
273282
h.latestReloadResult,
283+
logs,
274284
)
275285
h.cfg.statusUpdater.UpdateGroup(ctx, groupGateways, gwReqs...)
276286
}
277287

288+
func (h *eventHandlerImpl) GetPodLogs() (string, error) {
289+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
290+
defer cancel()
291+
292+
namespace := h.cfg.gatewayPodConfig.Namespace
293+
name := h.cfg.gatewayPodConfig.Name
294+
opts := &v1.PodLogOptions{
295+
Container: "nginx",
296+
TailLines: helpers.GetPointer(int64(20)),
297+
}
298+
299+
clientGoClient, err := kubernetes.NewForConfig(h.cfg.k8sConfig)
300+
if err != nil {
301+
return err.Error(), err
302+
}
303+
304+
req := clientGoClient.CoreV1().Pods(namespace).GetLogs(name, opts)
305+
306+
logs, err := req.Stream(ctx)
307+
if err != nil {
308+
return fmt.Sprintf("error getting logs from Pod: %v", err),
309+
fmt.Errorf("error getting logs from Pod: %w", err)
310+
}
311+
defer logs.Close()
312+
313+
buf := new(bytes.Buffer)
314+
if _, err := buf.ReadFrom(logs); err != nil {
315+
return fmt.Sprintf("error reading logs from Pod: %v", err),
316+
fmt.Errorf("error reading logs from Pod: %w", err)
317+
}
318+
319+
return buf.String(), nil
320+
}
321+
278322
func (h *eventHandlerImpl) parseAndCaptureEvent(ctx context.Context, logger logr.Logger, event interface{}) {
279323
switch e := event.(type) {
280324
case *events.UpsertEvent:
@@ -610,6 +654,7 @@ func (h *eventHandlerImpl) nginxGatewayServiceUpsert(ctx context.Context, logger
610654
transitionTime,
611655
gwAddresses,
612656
h.latestReloadResult,
657+
"",
613658
)
614659
h.cfg.statusUpdater.UpdateGroup(ctx, groupGateways, gatewayStatuses...)
615660
}
@@ -636,6 +681,7 @@ func (h *eventHandlerImpl) nginxGatewayServiceDelete(
636681
transitionTime,
637682
gwAddresses,
638683
h.latestReloadResult,
684+
"",
639685
)
640686
h.cfg.statusUpdater.UpdateGroup(ctx, groupGateways, gatewayStatuses...)
641687
}

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,

internal/mode/static/status/prepare_requests.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,12 @@ func PrepareGatewayRequests(
215215
transitionTime metav1.Time,
216216
gwAddresses []v1.GatewayStatusAddress,
217217
nginxReloadRes NginxReloadResult,
218+
logs string,
218219
) []frameworkStatus.UpdateRequest {
219220
reqs := make([]frameworkStatus.UpdateRequest, 0, 1+len(ignoredGateways))
220221

221222
if gateway != nil {
222-
reqs = append(reqs, prepareGatewayRequest(gateway, transitionTime, gwAddresses, nginxReloadRes))
223+
reqs = append(reqs, prepareGatewayRequest(gateway, transitionTime, gwAddresses, nginxReloadRes, logs))
223224
}
224225

225226
for nsname, gw := range ignoredGateways {
@@ -241,6 +242,7 @@ func prepareGatewayRequest(
241242
transitionTime metav1.Time,
242243
gwAddresses []v1.GatewayStatusAddress,
243244
nginxReloadRes NginxReloadResult,
245+
logs string,
244246
) frameworkStatus.UpdateRequest {
245247
if !gateway.Valid {
246248
conds := conditions.ConvertConditions(
@@ -302,7 +304,7 @@ func prepareGatewayRequest(
302304
if nginxReloadRes.Error != nil {
303305
gwConds = append(
304306
gwConds,
305-
staticConds.NewGatewayNotProgrammedInvalid(staticConds.GatewayMessageFailedNginxReload),
307+
staticConds.NewGatewayNotProgrammedInvalid(staticConds.GatewayMessageFailedNginxReload+logs),
306308
)
307309
}
308310

0 commit comments

Comments
 (0)