mirror of https://github.com/kyverno/chainsaw.git
Compare commits
130 Commits
Author | SHA1 | Date |
---|---|---|
|
c923201c9f | |
|
79b6709e2d | |
|
787e5aa4b9 | |
|
c3e918eae1 | |
|
fcdd8da755 | |
|
c03f744625 | |
|
b602c7e3a4 | |
|
354baeb734 | |
|
210f67e40f | |
|
7b90b0c1b6 | |
|
6ff9d759f4 | |
|
bf1a17fd0e | |
|
d2caa8cdf5 | |
|
efa0fffa88 | |
|
80f988ee45 | |
|
d8598992a0 | |
|
b5b747053d | |
|
c975dcc68b | |
|
3c18804a4a | |
|
2ebca820bb | |
|
3c23435ab3 | |
|
fa007ee411 | |
|
bab727ee05 | |
|
77c12f7cd6 | |
|
5bccfa414c | |
|
809cbbcf9c | |
|
b71b2cd0ee | |
|
983cfa61de | |
|
53ea7ae4ee | |
|
dfe952c4b7 | |
|
72c0a05595 | |
|
ad8cfdcc88 | |
|
63dfbdc6d3 | |
|
7e78f4118b | |
|
02960c38cf | |
|
b8ad80b1d2 | |
|
4432b2d300 | |
|
d7f079f4d7 | |
|
76f2cd3338 | |
|
c505780e00 | |
|
3f46fff124 | |
|
23d9658a05 | |
|
c38526b194 | |
|
478efb086b | |
|
7994fce982 | |
|
1f4ec806e6 | |
|
eae65169ae | |
|
38eb74776b | |
|
8458e289d1 | |
|
d6e3e2cf70 | |
|
71cac61ed2 | |
|
de947f21dc | |
|
639647664a | |
|
baafd69f0b | |
|
0670f8dec3 | |
|
9250ed5326 | |
|
8b6858fa14 | |
|
fd3b4afccf | |
|
1fb3b0d055 | |
|
0d9649bfb3 | |
|
9223850b89 | |
|
496d4173fb | |
|
5ac242ceb7 | |
|
57a4201085 | |
|
019b877176 | |
|
d8d638129b | |
|
5b45636bc4 | |
|
b36344859b | |
|
60be808cda | |
|
bc982f8320 | |
|
93f14ebe5c | |
|
dda88e999b | |
|
939fe1833c | |
|
bd3e7cd395 | |
|
fd11837f57 | |
|
3abe1fced8 | |
|
38c69531ff | |
|
9b108553da | |
|
bc40b1f0f7 | |
|
9035ce6417 | |
|
b2b2ab6713 | |
|
9df3003deb | |
|
d8845f136e | |
|
f121618067 | |
|
9cef44342a | |
|
dac0712e93 | |
|
3f3276b668 | |
|
e3a0234d23 | |
|
19434ceb34 | |
|
90d2e2c8c6 | |
|
595060e332 | |
|
41b1966a91 | |
|
e44813dc4a | |
|
e0fe5946cf | |
|
8891bf31e1 | |
|
3078680efe | |
|
f9a9f9dd60 | |
|
461bddf61c | |
|
d7a79146d0 | |
|
e2c56a0ecb | |
|
8bb564ee84 | |
|
d281b6e618 | |
|
c818f77884 | |
|
ed5c7aacdc | |
|
3977046b0b | |
|
05ef5b10e7 | |
|
fe23bd0472 | |
|
aa0a7bb181 | |
|
2d80344c34 | |
|
58dbdbc308 | |
|
c68f42bb02 | |
|
0acd1bdb3e | |
|
366c1acf31 | |
|
fe419e9a63 | |
|
4a27d4f659 | |
|
b285ae4cbf | |
|
ef85df2772 | |
|
aa474dc4a7 | |
|
57be38138d | |
|
3efa453777 | |
|
e29a5e78dd | |
|
006ea0967c | |
|
b488897eb6 | |
|
86321cd75d | |
|
24c568610a | |
|
2314b2fca0 | |
|
aaadec5414 | |
|
88bfaf4d46 | |
|
6421092a10 | |
|
61b9b0a846 |
|
@ -902,7 +902,7 @@ spec:
|
|||
type: integer
|
||||
reportFormat:
|
||||
description: |-
|
||||
ReportFormat determines test report format (JSON|XML|JUNIT-TEST|JUNIT-STEP|JUNIT-OPERATION|nil) nil == no report.
|
||||
ReportFormat determines test report format (JSON, XML, JUNIT-TEST, JUNIT-STEP, JUNIT-OPERATION, nil) nil == no report.
|
||||
maps to report.Type, however we don't want generated.deepcopy to have reference to it.
|
||||
enum:
|
||||
- JSON
|
||||
|
@ -1899,7 +1899,8 @@ spec:
|
|||
properties:
|
||||
format:
|
||||
default: JSON
|
||||
description: ReportFormat determines test report format (JSON|XML|JUNIT-TEST|JUNIT-STEP|JUNIT-OPERATION).
|
||||
description: ReportFormat determines test report format (JSON,
|
||||
XML, JUNIT-TEST, JUNIT-STEP, JUNIT-OPERATION).
|
||||
enum:
|
||||
- JSON
|
||||
- XML
|
||||
|
|
|
@ -23,9 +23,9 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
- name: Ensure SHA pinned actions
|
||||
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@5d6ac37a4cef8b8df67f482a8e384987766f0213 # v3.0.17
|
||||
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@fc87bb5b5a97953d987372e74478de634726b3e5 # v3.0.25
|
||||
with:
|
||||
# slsa-github-generator requires using a semver tag for reusable workflows.
|
||||
# See: https://github.com/slsa-framework/slsa-github-generator#referencing-slsa-builders-and-generators
|
||||
|
|
|
@ -23,9 +23,9 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
|
||||
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
cache-dependency-path: go.sum
|
||||
|
|
|
@ -25,11 +25,11 @@ jobs:
|
|||
security-events: write
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Run Trivy vulnerability scanner in repo mode
|
||||
uses: aquasecurity/trivy-action@18f2510ee396bbf400402947b394f2dd8c87dbb0 # v0.29.0
|
||||
uses: aquasecurity/trivy-action@dc5a429b52fcf669ce959baa2c2dd26090d2a6c4 # v0.32.0
|
||||
with:
|
||||
scan-type: fs
|
||||
ignore-unfixed: false
|
||||
|
@ -42,7 +42,7 @@ jobs:
|
|||
env:
|
||||
TRIVY_DB_REPOSITORY: 'public.ecr.aws/aquasecurity/trivy-db:2'
|
||||
- name: Upload Trivy scan results to GitHub Security tab
|
||||
uses: github/codeql-action/upload-sarif@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
|
||||
uses: github/codeql-action/upload-sarif@df559355d593797519d70b90fc8edd5db049e7a2 # v3.29.5
|
||||
with:
|
||||
sarif_file: trivy-results.sarif
|
||||
category: code
|
||||
|
|
|
@ -20,9 +20,9 @@ jobs:
|
|||
contents: write
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
|
||||
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
cache-dependency-path: go.sum
|
||||
|
|
|
@ -23,9 +23,9 @@ jobs:
|
|||
version_extractor_regex: '^docs-v(.*)$'
|
||||
- name: Checkout
|
||||
if: ${{ steps.semver.outputs.prerelease == '' }}
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
|
||||
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
|
||||
if: ${{ steps.semver.outputs.prerelease == '' }}
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
|
|
|
@ -23,13 +23,13 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
|
||||
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
cache-dependency-path: go.sum
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v3.7.1
|
||||
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
|
||||
with:
|
||||
skip-cache: true
|
||||
|
|
|
@ -33,7 +33,7 @@ jobs:
|
|||
docker-images: true
|
||||
swap-storage: false
|
||||
- name: Checkout
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Fetch all tags
|
||||
|
@ -41,19 +41,19 @@ jobs:
|
|||
set -e
|
||||
git fetch --force --tags
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
|
||||
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
cache-dependency-path: go.sum
|
||||
- name: Install Cosign
|
||||
uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da # v3.7.0
|
||||
uses: sigstore/cosign-installer@d58896d6a1865668819e1d91763c7751a165e159 # v3.9.2
|
||||
- name: Install Syft
|
||||
uses: anchore/sbom-action/download-syft@55dc4ee22412511ee8c3142cbea40418e6cec693 # v0.17.8
|
||||
uses: anchore/sbom-action/download-syft@7b36ad622f042cab6f59a75c2ac24ccb256e9b45 # v0.20.4
|
||||
- name: Install Ko
|
||||
uses: ko-build/setup-ko@3aebd0597dc1e9d1a26bcfdb7cbeb19c131d3037 # v0.7
|
||||
uses: ko-build/setup-ko@d006021bd0c28d1ce33a07e7943d48b079944c8d # v0.9
|
||||
- name: Run GoReleaser
|
||||
id: goreleaser
|
||||
uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.1.0
|
||||
uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # v6.3.0
|
||||
with:
|
||||
distribution: goreleaser
|
||||
version: latest
|
||||
|
@ -61,14 +61,14 @@ jobs:
|
|||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Upload artifacts.json
|
||||
uses: svenstaro/upload-release-action@04733e069f2d7f7f0b4aebc4fbdbce8613b03ccd # 2.9.0
|
||||
uses: svenstaro/upload-release-action@81c65b7cd4de9b2570615ce3aad67a41de5b1a13 # 2.11.2
|
||||
with:
|
||||
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
file: dist/artifacts.json
|
||||
asset_name: artifacts.json
|
||||
tag: ${{ github.ref }}
|
||||
- name: Upload metadata.json
|
||||
uses: svenstaro/upload-release-action@04733e069f2d7f7f0b4aebc4fbdbce8613b03ccd # 2.9.0
|
||||
uses: svenstaro/upload-release-action@81c65b7cd4de9b2570615ce3aad67a41de5b1a13 # 2.11.2
|
||||
with:
|
||||
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
file: dist/metadata.json
|
||||
|
@ -102,7 +102,7 @@ jobs:
|
|||
actions: read
|
||||
id-token: write
|
||||
contents: write
|
||||
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.0.0
|
||||
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.1.0
|
||||
with:
|
||||
base64-subjects: "${{ needs.goreleaser.outputs.hashes }}"
|
||||
upload-assets: true
|
||||
|
@ -114,7 +114,7 @@ jobs:
|
|||
actions: read
|
||||
id-token: write
|
||||
packages: write
|
||||
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@v2.0.0
|
||||
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@v2.1.0
|
||||
with:
|
||||
image: ${{ needs.goreleaser.outputs.image }}
|
||||
digest: ${{ needs.goreleaser.outputs.digest }}
|
||||
|
|
|
@ -23,9 +23,9 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
|
||||
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
cache-dependency-path: go.sum
|
||||
|
@ -38,7 +38,7 @@ jobs:
|
|||
set -e
|
||||
make tests
|
||||
- name: Upload coverage
|
||||
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: coverage.out
|
||||
path: coverage.out
|
||||
|
@ -51,11 +51,11 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Download coverage
|
||||
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
|
||||
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
|
||||
with:
|
||||
name: coverage.out
|
||||
- name: Upload Report to Codecov
|
||||
uses: codecov/codecov-action@015f24e6818733317a2da2edd6290ab26238649a # v5.0.7
|
||||
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
|
||||
with:
|
||||
files: ./coverage.out
|
||||
fail_ci_if_error: true
|
||||
|
@ -67,9 +67,9 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
|
||||
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
cache-dependency-path: go.sum
|
||||
|
@ -86,9 +86,9 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
|
||||
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
cache-dependency-path: go.sum
|
||||
|
@ -101,14 +101,14 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
|
||||
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
cache-dependency-path: go.sum
|
||||
- name: Install ko
|
||||
uses: ko-build/setup-ko@3aebd0597dc1e9d1a26bcfdb7cbeb19c131d3037 #v0.7
|
||||
uses: ko-build/setup-ko@d006021bd0c28d1ce33a07e7943d48b079944c8d #v0.9
|
||||
- name: Create test cluster
|
||||
run: |
|
||||
set -e
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
version: "2"
|
||||
linters:
|
||||
enable:
|
||||
- asasalint
|
||||
|
@ -5,46 +6,49 @@ linters:
|
|||
- bidichk
|
||||
- bodyclose
|
||||
- containedctx
|
||||
- copyloopvar
|
||||
- decorder
|
||||
- dogsled
|
||||
- durationcheck
|
||||
- errcheck
|
||||
- errname
|
||||
- exportloopref
|
||||
- gci
|
||||
- gochecknoinits
|
||||
- gofmt
|
||||
- gofumpt
|
||||
- goimports
|
||||
- goprintffuncname
|
||||
- gosec
|
||||
- gosimple
|
||||
- govet
|
||||
- grouper
|
||||
- importas
|
||||
- ineffassign
|
||||
- makezero
|
||||
- misspell
|
||||
- noctx
|
||||
- nolintlint
|
||||
- nosprintfhostport
|
||||
# - paralleltest
|
||||
- staticcheck
|
||||
- tenv
|
||||
- thelper
|
||||
- tparallel
|
||||
- typecheck
|
||||
- unconvert
|
||||
- unused
|
||||
- usetesting
|
||||
- wastedassign
|
||||
- whitespace
|
||||
|
||||
run:
|
||||
timeout: 15m
|
||||
|
||||
output:
|
||||
sort-results: true
|
||||
|
||||
issues:
|
||||
exclude-files:
|
||||
- ".+\\.generated.go"
|
||||
exclusions:
|
||||
generated: lax
|
||||
presets:
|
||||
- comments
|
||||
- common-false-positives
|
||||
- legacy
|
||||
- std-error-handling
|
||||
paths:
|
||||
- .+\.generated.go
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
formatters:
|
||||
enable:
|
||||
- gci
|
||||
- gofmt
|
||||
- gofumpt
|
||||
- goimports
|
||||
exclusions:
|
||||
generated: lax
|
||||
paths:
|
||||
- .+\.generated.go
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
|
|
|
@ -19,3 +19,7 @@ Release notes for `TODO`.
|
|||
|
||||
## 🎸 Misc 🎸
|
||||
-->
|
||||
|
||||
## 💫 New features 💫
|
||||
|
||||
- Continue tests when an error happens when computing the test name
|
|
@ -1764,7 +1764,7 @@
|
|||
"minimum": 1
|
||||
},
|
||||
"reportFormat": {
|
||||
"description": "ReportFormat determines test report format (JSON|XML|JUNIT-TEST|JUNIT-STEP|JUNIT-OPERATION|nil) nil == no report.\nmaps to report.Type, however we don't want generated.deepcopy to have reference to it.",
|
||||
"description": "ReportFormat determines test report format (JSON, XML, JUNIT-TEST, JUNIT-STEP, JUNIT-OPERATION, nil) nil == no report.\nmaps to report.Type, however we don't want generated.deepcopy to have reference to it.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
|
@ -1885,7 +1885,6 @@
|
|||
"version": "v1alpha1"
|
||||
}
|
||||
],
|
||||
"x-kubernetes-selectable-fields": [],
|
||||
"additionalProperties": false,
|
||||
"$schema": "http://json-schema.org/schema#"
|
||||
}
|
|
@ -1841,7 +1841,7 @@
|
|||
],
|
||||
"properties": {
|
||||
"format": {
|
||||
"description": "ReportFormat determines test report format (JSON|XML|JUNIT-TEST|JUNIT-STEP|JUNIT-OPERATION).",
|
||||
"description": "ReportFormat determines test report format (JSON, XML, JUNIT-TEST, JUNIT-STEP, JUNIT-OPERATION).",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
|
@ -1973,7 +1973,6 @@
|
|||
"version": "v1alpha2"
|
||||
}
|
||||
],
|
||||
"x-kubernetes-selectable-fields": [],
|
||||
"additionalProperties": false,
|
||||
"$schema": "http://json-schema.org/schema#"
|
||||
}
|
|
@ -8049,7 +8049,6 @@
|
|||
"version": "v1alpha1"
|
||||
}
|
||||
],
|
||||
"x-kubernetes-selectable-fields": [],
|
||||
"additionalProperties": false,
|
||||
"$schema": "http://json-schema.org/schema#"
|
||||
}
|
|
@ -9892,7 +9892,6 @@
|
|||
"version": "v1alpha1"
|
||||
}
|
||||
],
|
||||
"x-kubernetes-selectable-fields": [],
|
||||
"additionalProperties": false,
|
||||
"$schema": "http://json-schema.org/schema#"
|
||||
}
|
45
Makefile
45
Makefile
|
@ -7,9 +7,6 @@
|
|||
GIT_SHA := $(shell git rev-parse HEAD)
|
||||
ORG ?= kyverno
|
||||
PACKAGE ?= github.com/$(ORG)/chainsaw
|
||||
GOPATH_SHIM := ${PWD}/.gopath
|
||||
PACKAGE_SHIM := $(GOPATH_SHIM)/src/$(PACKAGE)
|
||||
INPUT_DIRS := $(PACKAGE)/pkg/apis/v1alpha1,$(PACKAGE)/pkg/apis/v1alpha2
|
||||
CRDS_PATH := ${PWD}/.crds
|
||||
CLI_BIN := chainsaw
|
||||
CGO_ENABLED ?= 0
|
||||
|
@ -21,7 +18,7 @@ LD_FLAGS := "-s -w"
|
|||
endif
|
||||
KO_REGISTRY := ko.local
|
||||
KO_TAGS := $(GIT_SHA)
|
||||
KIND_IMAGE ?= kindest/node:v1.31.0
|
||||
KIND_IMAGE ?= kindest/node:v1.33.2
|
||||
|
||||
#########
|
||||
# TOOLS #
|
||||
|
@ -32,13 +29,13 @@ CONTROLLER_GEN := $(TOOLS_DIR)/controller-gen
|
|||
REGISTER_GEN := $(TOOLS_DIR)/register-gen
|
||||
DEEPCOPY_GEN := $(TOOLS_DIR)/deepcopy-gen
|
||||
CONVERSION_GEN := $(TOOLS_DIR)/conversion-gen
|
||||
CODE_GEN_VERSION := v0.28.0
|
||||
CODE_GEN_VERSION := v0.33.3
|
||||
REFERENCE_DOCS := $(TOOLS_DIR)/genref
|
||||
REFERENCE_DOCS_VERSION := latest
|
||||
KIND := $(TOOLS_DIR)/kind
|
||||
KIND_VERSION := v0.22.0
|
||||
KIND_VERSION := v0.29.0
|
||||
KO ?= $(TOOLS_DIR)/ko
|
||||
KO_VERSION ?= v0.15.1
|
||||
KO_VERSION ?= v0.18.0
|
||||
TOOLS := $(CONTROLLER_GEN) $(REGISTER_GEN) $(DEEPCOPY_GEN) $(CONVERSION_GEN) $(REFERENCE_DOCS) $(KIND) $(KO)
|
||||
PIP ?= "pip"
|
||||
ifeq ($(GOOS), darwin)
|
||||
|
@ -50,7 +47,7 @@ COMMA := ,
|
|||
|
||||
$(CONTROLLER_GEN):
|
||||
@echo Install controller-gen... >&2
|
||||
@cd ./hack/controller-gen && GOBIN=$(TOOLS_DIR) go install
|
||||
@cd ./hack/controller-gen && GOBIN=$(TOOLS_DIR) go install -buildvcs=false
|
||||
|
||||
$(REGISTER_GEN):
|
||||
@echo Install register-gen... >&2
|
||||
|
@ -89,54 +86,42 @@ clean-tools: ## Remove installed tools
|
|||
# CODEGEN #
|
||||
###########
|
||||
|
||||
$(GOPATH_SHIM):
|
||||
@echo Create gopath shim... >&2
|
||||
@mkdir -p $(GOPATH_SHIM)
|
||||
|
||||
.INTERMEDIATE: $(PACKAGE_SHIM)
|
||||
$(PACKAGE_SHIM): $(GOPATH_SHIM)
|
||||
@echo Create package shim... >&2
|
||||
@mkdir -p $(GOPATH_SHIM)/src/github.com/$(ORG) && ln -s -f ${PWD} $(PACKAGE_SHIM)
|
||||
|
||||
.PHONY: codegen-register
|
||||
codegen-register: ## Generate types registrations
|
||||
codegen-register: $(PACKAGE_SHIM)
|
||||
codegen-register: $(REGISTER_GEN)
|
||||
@echo Generate registration... >&2
|
||||
@GOPATH=$(GOPATH_SHIM) $(REGISTER_GEN) \
|
||||
@$(REGISTER_GEN) \
|
||||
--go-header-file=./hack/boilerplate.go.txt \
|
||||
--input-dirs=$(INPUT_DIRS)
|
||||
--output-file zz_generated.register.go \
|
||||
./pkg/apis/...
|
||||
|
||||
.PHONY: codegen-deepcopy
|
||||
codegen-deepcopy: ## Generate deep copy functions
|
||||
codegen-deepcopy: $(PACKAGE_SHIM)
|
||||
codegen-deepcopy: $(DEEPCOPY_GEN)
|
||||
@echo Generate deep copy functions... >&2
|
||||
@GOPATH=$(GOPATH_SHIM) $(DEEPCOPY_GEN) \
|
||||
@$(DEEPCOPY_GEN) \
|
||||
--go-header-file=./hack/boilerplate.go.txt \
|
||||
--input-dirs=$(INPUT_DIRS) \
|
||||
--output-file-base=zz_generated.deepcopy
|
||||
--output-file=zz_generated.deepcopy.go \
|
||||
./pkg/apis/...
|
||||
|
||||
.PHONY: codegen-conversion
|
||||
codegen-conversion: ## Generate conversion functions
|
||||
codegen-conversion: $(PACKAGE_SHIM)
|
||||
codegen-conversion: $(CONVERSION_GEN)
|
||||
@echo Generate conversion functions... >&2
|
||||
@GOPATH=$(GOPATH_SHIM) $(CONVERSION_GEN) \
|
||||
@$(CONVERSION_GEN) \
|
||||
--go-header-file=./hack/boilerplate.go.txt \
|
||||
--input-dirs=$(INPUT_DIRS) \
|
||||
--output-file-base=zz_generated.conversion
|
||||
--output-file=zz_generated.conversion.go \
|
||||
./pkg/apis/...
|
||||
|
||||
.PHONY: codegen-crds
|
||||
codegen-crds: ## Generate CRDs
|
||||
codegen-crds: $(PACKAGE_SHIM)
|
||||
codegen-crds: $(CONTROLLER_GEN)
|
||||
codegen-crds: codegen-deepcopy
|
||||
codegen-crds: codegen-register
|
||||
codegen-crds: codegen-conversion
|
||||
@echo Generate crds... >&2
|
||||
@rm -rf $(CRDS_PATH)
|
||||
@GOPATH=$(GOPATH_SHIM) $(CONTROLLER_GEN) paths=./pkg/apis/... crd:crdVersions=v1,ignoreUnexportedFields=true,generateEmbeddedObjectMeta=false output:dir=$(CRDS_PATH)
|
||||
@$(CONTROLLER_GEN) paths=./pkg/apis/... crd:crdVersions=v1,ignoreUnexportedFields=true,generateEmbeddedObjectMeta=false output:dir=$(CRDS_PATH)
|
||||
@echo Copy generated CRDs to embed in the CLI... >&2
|
||||
@rm -rf pkg/data/crds && mkdir -p pkg/data/crds
|
||||
@cp $(CRDS_PATH)/* pkg/data/crds
|
||||
|
|
|
@ -51,7 +51,7 @@ To attend our community meetings, join the [Chainsaw group](https://groups.googl
|
|||
You will then be sent a meeting invite and will have access to the agenda and meeting notes.
|
||||
Any member may suggest topics for discussion.
|
||||
|
||||
This is a public, weekly for Kyverno-Chainsaw maintainers to make announcements and provide project updates, and request input and feedback.
|
||||
This is a public, weekly meeting for Kyverno-Chainsaw maintainers to make announcements and provide project updates, and request input and feedback.
|
||||
This forum allows community members to raise agenda items of any sort, including but not limited to any PRs or issues on which they are working.
|
||||
|
||||
Weekly every Thursday at 2:00 PM UTC
|
||||
|
|
18
chainsaw.rb
18
chainsaw.rb
|
@ -5,20 +5,20 @@
|
|||
class Chainsaw < Formula
|
||||
desc "Declarative Kubernetes end-to-end testing."
|
||||
homepage "https://kyverno.github.io/chainsaw"
|
||||
version "0.2.11"
|
||||
version "0.2.12"
|
||||
|
||||
on_macos do
|
||||
on_intel do
|
||||
url "https://github.com/kyverno/chainsaw/releases/download/v0.2.11/chainsaw_darwin_amd64.tar.gz"
|
||||
sha256 "940362446fff7598395392ee7c2b1d306e4d6f27be9c29d65997ac8678dbb087"
|
||||
url "https://github.com/kyverno/chainsaw/releases/download/v0.2.12/chainsaw_darwin_amd64.tar.gz"
|
||||
sha256 "b49dba1214b32024567b1edc7653498a644fbef18111bcc3e1c46dc52e1d194e"
|
||||
|
||||
def install
|
||||
bin.install "chainsaw"
|
||||
end
|
||||
end
|
||||
on_arm do
|
||||
url "https://github.com/kyverno/chainsaw/releases/download/v0.2.11/chainsaw_darwin_arm64.tar.gz"
|
||||
sha256 "8669c23d25774f2a39749d9ee80c36219ab669c8251a3ed5d04fc9ec13a1af11"
|
||||
url "https://github.com/kyverno/chainsaw/releases/download/v0.2.12/chainsaw_darwin_arm64.tar.gz"
|
||||
sha256 "717a07fcc4d781fff967b287880fed1d8b1e6af9fbecc7650a714c467f296d33"
|
||||
|
||||
def install
|
||||
bin.install "chainsaw"
|
||||
|
@ -29,8 +29,8 @@ class Chainsaw < Formula
|
|||
on_linux do
|
||||
on_intel do
|
||||
if Hardware::CPU.is_64_bit?
|
||||
url "https://github.com/kyverno/chainsaw/releases/download/v0.2.11/chainsaw_linux_amd64.tar.gz"
|
||||
sha256 "0a91b6e2f7181300e99a91a80f69e6a7dc4bee9b4bda1d73fdce6f8d6ed1e486"
|
||||
url "https://github.com/kyverno/chainsaw/releases/download/v0.2.12/chainsaw_linux_amd64.tar.gz"
|
||||
sha256 "d6bfb17ba47af2db85edc0365288f92b5e1a4566f7ff130ec9b326f96856e209"
|
||||
|
||||
def install
|
||||
bin.install "chainsaw"
|
||||
|
@ -39,8 +39,8 @@ class Chainsaw < Formula
|
|||
end
|
||||
on_arm do
|
||||
if Hardware::CPU.is_64_bit?
|
||||
url "https://github.com/kyverno/chainsaw/releases/download/v0.2.11/chainsaw_linux_arm64.tar.gz"
|
||||
sha256 "3b2f109d70f2e3871ed95dac2c0bbd697aa5ef0f38636e158f6e7d745b96d504"
|
||||
url "https://github.com/kyverno/chainsaw/releases/download/v0.2.12/chainsaw_linux_arm64.tar.gz"
|
||||
sha256 "72a6273d6da16a04e29e0fae232631b084852d21ddf25f88ed3d3de480125d30"
|
||||
|
||||
def install
|
||||
bin.install "chainsaw"
|
||||
|
|
137
go.mod
137
go.mod
|
@ -1,41 +1,41 @@
|
|||
module github.com/kyverno/chainsaw
|
||||
|
||||
go 1.23.0
|
||||
go 1.24.2
|
||||
|
||||
require (
|
||||
github.com/Masterminds/sprig v2.22.0+incompatible
|
||||
github.com/dustinkirkland/golang-petname v0.0.0-20240428194347-eebcea082ee0
|
||||
github.com/evanphx/json-patch v5.9.0+incompatible
|
||||
github.com/evanphx/json-patch v5.9.11+incompatible
|
||||
github.com/fatih/color v1.18.0
|
||||
github.com/go-logr/logr v1.4.2
|
||||
github.com/google/cel-go v0.21.0
|
||||
github.com/go-logr/logr v1.4.3
|
||||
github.com/google/cel-go v0.23.2
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
||||
github.com/hashicorp/go-getter v1.7.6
|
||||
github.com/hashicorp/go-getter v1.7.8
|
||||
github.com/jmespath-community/go-jmespath v1.1.2-0.20240930152130-6eb5a346873f
|
||||
github.com/jstemmer/go-junit-report/v2 v2.1.0
|
||||
github.com/kudobuilder/kuttl v0.20.0
|
||||
github.com/kyverno/kyverno-json v0.0.4-0.20241008103124-b294ee72a2bf
|
||||
github.com/kyverno/pkg/ext v0.0.0-20240418121121-df8add26c55c
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2
|
||||
github.com/prometheus/common v0.60.1
|
||||
github.com/spf13/cobra v1.8.1
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/prometheus/common v0.65.0
|
||||
github.com/spf13/cobra v1.9.1
|
||||
github.com/spf13/pflag v1.0.7
|
||||
github.com/stretchr/testify v1.10.0
|
||||
github.com/xeipuuv/gojsonschema v1.2.0
|
||||
go.uber.org/multierr v1.11.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
k8s.io/api v0.31.3
|
||||
k8s.io/apimachinery v0.31.3
|
||||
k8s.io/apiserver v0.31.3
|
||||
k8s.io/client-go v0.31.3
|
||||
k8s.io/utils v0.0.0-20240921022957-49e7df575cb6
|
||||
sigs.k8s.io/controller-runtime v0.19.3
|
||||
sigs.k8s.io/kubectl-validate v0.0.5-0.20240827210056-ce13d95db263
|
||||
sigs.k8s.io/yaml v1.4.0
|
||||
k8s.io/api v0.33.3
|
||||
k8s.io/apimachinery v0.33.3
|
||||
k8s.io/apiserver v0.33.3
|
||||
k8s.io/client-go v0.33.3
|
||||
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397
|
||||
sigs.k8s.io/controller-runtime v0.21.0
|
||||
sigs.k8s.io/kubectl-validate v0.0.5-0.20241223122011-eb064d2f92d5
|
||||
sigs.k8s.io/yaml v1.6.0
|
||||
)
|
||||
|
||||
require (
|
||||
cel.dev/expr v0.16.1 // indirect
|
||||
cel.dev/expr v0.19.1 // indirect
|
||||
cloud.google.com/go v0.115.1 // indirect
|
||||
cloud.google.com/go/auth v0.9.7 // indirect
|
||||
cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect
|
||||
|
@ -51,44 +51,43 @@ require (
|
|||
github.com/Masterminds/semver v1.5.0 // indirect
|
||||
github.com/NYTimes/gziphandler v1.1.1 // indirect
|
||||
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
|
||||
github.com/aquilax/truncate v1.0.0 // indirect
|
||||
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
|
||||
github.com/aws/aws-sdk-go v1.55.5 // indirect
|
||||
github.com/aquilax/truncate v1.0.1 // indirect
|
||||
github.com/aws/aws-sdk-go v1.55.6 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
|
||||
github.com/blang/semver/v4 v4.0.0 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 // indirect
|
||||
github.com/cncf/xds/go v0.0.0-20250121191232-2f005788dc42 // indirect
|
||||
github.com/coreos/go-semver v0.3.1 // indirect
|
||||
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
|
||||
github.com/envoyproxy/go-control-plane v0.13.0 // indirect
|
||||
github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect
|
||||
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
|
||||
github.com/envoyproxy/go-control-plane/envoy v1.32.3 // indirect
|
||||
github.com/envoyproxy/go-control-plane/ratelimit v0.1.0 // indirect
|
||||
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
|
||||
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
|
||||
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.8.0 // indirect
|
||||
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.21.0 // indirect
|
||||
github.com/go-openapi/jsonreference v0.21.0 // indirect
|
||||
github.com/go-openapi/swag v0.23.0 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
github.com/google/gofuzz v1.2.0 // indirect
|
||||
github.com/google/btree v1.1.3 // indirect
|
||||
github.com/google/gnostic-models v0.6.9 // indirect
|
||||
github.com/google/go-cmp v0.7.0 // indirect
|
||||
github.com/google/s2a-go v0.1.8 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
|
||||
github.com/gopherjs/gopherjs v1.17.2 // indirect
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.1-0.20210315223345-82c243799c99 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0 // indirect
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||
github.com/hashicorp/go-safetemp v1.0.0 // indirect
|
||||
github.com/hashicorp/go-version v1.7.0 // indirect
|
||||
|
@ -99,7 +98,7 @@ require (
|
|||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/jtolds/gls v4.20.0+incompatible // indirect
|
||||
github.com/klauspost/compress v1.17.10 // indirect
|
||||
github.com/klauspost/compress v1.18.0 // indirect
|
||||
github.com/kylelemons/godebug v1.1.0 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
|
@ -111,12 +110,10 @@ require (
|
|||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/onsi/ginkgo/v2 v2.20.1 // indirect
|
||||
github.com/onsi/gomega v1.34.2 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
|
||||
github.com/prometheus/client_golang v1.20.4 // indirect
|
||||
github.com/prometheus/client_model v0.6.1 // indirect
|
||||
github.com/prometheus/client_golang v1.22.0 // indirect
|
||||
github.com/prometheus/client_model v0.6.2 // indirect
|
||||
github.com/prometheus/procfs v0.15.1 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/stoewer/go-strcase v1.3.0 // indirect
|
||||
|
@ -125,46 +122,48 @@ require (
|
|||
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
|
||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
|
||||
github.com/zach-klippenstein/goregen v0.0.0-20160303162051-795b5e3961ea // indirect
|
||||
go.etcd.io/etcd/api/v3 v3.5.15 // indirect
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.15 // indirect
|
||||
go.etcd.io/etcd/client/v3 v3.5.15 // indirect
|
||||
go.etcd.io/etcd/api/v3 v3.5.21 // indirect
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.21 // indirect
|
||||
go.etcd.io/etcd/client/v3 v3.5.21 // indirect
|
||||
go.opencensus.io v0.24.0 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
||||
go.opentelemetry.io/contrib/detectors/gcp v1.29.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.55.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 // indirect
|
||||
go.opentelemetry.io/otel v1.30.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.30.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.30.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.30.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.30.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.58.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 // indirect
|
||||
go.opentelemetry.io/otel v1.33.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.33.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.33.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.33.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk/metric v1.29.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.30.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.33.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.4.0 // indirect
|
||||
go.uber.org/zap v1.27.0 // indirect
|
||||
golang.org/x/crypto v0.28.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20241004190924-225e2abe05e6 // indirect
|
||||
golang.org/x/net v0.30.0 // indirect
|
||||
golang.org/x/oauth2 v0.23.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.26.0 // indirect
|
||||
golang.org/x/term v0.25.0 // indirect
|
||||
golang.org/x/text v0.19.0 // indirect
|
||||
golang.org/x/time v0.7.0 // indirect
|
||||
go.yaml.in/yaml/v2 v2.4.2 // indirect
|
||||
golang.org/x/crypto v0.38.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect
|
||||
golang.org/x/net v0.40.0 // indirect
|
||||
golang.org/x/oauth2 v0.30.0 // indirect
|
||||
golang.org/x/sync v0.14.0 // indirect
|
||||
golang.org/x/sys v0.33.0 // indirect
|
||||
golang.org/x/term v0.32.0 // indirect
|
||||
golang.org/x/text v0.25.0 // indirect
|
||||
golang.org/x/time v0.11.0 // indirect
|
||||
google.golang.org/api v0.199.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20241007155032-5fefd90f89a9 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
|
||||
google.golang.org/grpc v1.67.1 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect
|
||||
google.golang.org/grpc v1.68.1 // indirect
|
||||
google.golang.org/grpc/stats/opentelemetry v0.0.0-20240907200651-3ffb98b2c93a // indirect
|
||||
google.golang.org/protobuf v1.35.1 // indirect
|
||||
google.golang.org/protobuf v1.36.6 // indirect
|
||||
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
k8s.io/apiextensions-apiserver v0.31.3 // indirect
|
||||
k8s.io/component-base v0.31.3 // indirect
|
||||
k8s.io/apiextensions-apiserver v0.33.0 // indirect
|
||||
k8s.io/component-base v0.33.3 // indirect
|
||||
k8s.io/klog/v2 v2.130.1 // indirect
|
||||
k8s.io/kube-openapi v0.0.0-20240903163716-9e1beecbcb38 // indirect
|
||||
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 // indirect
|
||||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
|
||||
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
|
||||
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2 // indirect
|
||||
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
|
||||
sigs.k8s.io/randfill v1.0.0 // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
|
||||
)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
module github.com/kyverno/chainsaw/hack/controller-gen
|
||||
|
||||
go 1.22.0
|
||||
go 1.24.0
|
||||
|
||||
require (
|
||||
github.com/spf13/cobra v1.8.1
|
||||
k8s.io/apiextensions-apiserver v0.31.3
|
||||
sigs.k8s.io/controller-tools v0.16.5
|
||||
github.com/spf13/cobra v1.9.1
|
||||
k8s.io/apiextensions-apiserver v0.33.3
|
||||
sigs.k8s.io/controller-tools v0.17.2
|
||||
)
|
||||
|
||||
require (
|
||||
|
@ -13,25 +13,27 @@ require (
|
|||
github.com/go-logr/logr v1.4.2 // indirect
|
||||
github.com/gobuffalo/flect v1.0.3 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/google/gofuzz v1.2.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/kr/pretty v0.3.1 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/rogpeppe/go-internal v1.14.1 // indirect
|
||||
github.com/spf13/pflag v1.0.6 // indirect
|
||||
github.com/x448/float16 v0.8.4 // indirect
|
||||
golang.org/x/mod v0.21.0 // indirect
|
||||
golang.org/x/net v0.30.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/text v0.19.0 // indirect
|
||||
golang.org/x/tools v0.26.0 // indirect
|
||||
golang.org/x/mod v0.24.0 // indirect
|
||||
golang.org/x/net v0.38.0 // indirect
|
||||
golang.org/x/sync v0.12.0 // indirect
|
||||
golang.org/x/text v0.23.0 // indirect
|
||||
golang.org/x/tools v0.31.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
k8s.io/apimachinery v0.31.3 // indirect
|
||||
k8s.io/apimachinery v0.33.3 // indirect
|
||||
k8s.io/klog/v2 v2.130.1 // indirect
|
||||
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
|
||||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
|
||||
k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e // indirect
|
||||
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
|
||||
sigs.k8s.io/randfill v1.0.0 // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
|
||||
sigs.k8s.io/yaml v1.4.0 // indirect
|
||||
)
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
|
||||
|
@ -15,11 +14,9 @@ github.com/gobuffalo/flect v1.0.3/go.mod h1:A5msMlrHtLqh9umBSnvabjsMrCcCpAyzglnD
|
|||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
|
@ -42,18 +39,19 @@ github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
|||
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
|
||||
github.com/onsi/gomega v1.34.2 h1:pNCwDkzrsv7MS9kpaQvVb1aVLahQXyJ/Tv5oAZMI3i8=
|
||||
github.com/onsi/gomega v1.34.2/go.mod h1:v1xfxRgk0KIsG+QOdm7p8UosrOzPYRo60fd3B/1Dukc=
|
||||
github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8=
|
||||
github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY=
|
||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
|
||||
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
||||
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
|
||||
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
|
||||
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
|
||||
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
|
||||
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
|
@ -61,8 +59,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
|
|||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
|
||||
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
|
@ -72,34 +70,34 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
|
|||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
|
||||
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
|
||||
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
|
||||
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
|
||||
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
|
||||
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
|
||||
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
||||
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
|
||||
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
|
||||
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
|
||||
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
|
||||
golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU=
|
||||
golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
@ -111,25 +109,27 @@ gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
|
|||
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
k8s.io/apiextensions-apiserver v0.31.3 h1:+GFGj2qFiU7rGCsA5o+p/rul1OQIq6oYpQw4+u+nciE=
|
||||
k8s.io/apiextensions-apiserver v0.31.3/go.mod h1:2DSpFhUZZJmn/cr/RweH1cEVVbzFw9YBu4T+U3mf1e4=
|
||||
k8s.io/apimachinery v0.31.3 h1:6l0WhcYgasZ/wk9ktLq5vLaoXJJr5ts6lkaQzgeYPq4=
|
||||
k8s.io/apimachinery v0.31.3/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
|
||||
k8s.io/apiextensions-apiserver v0.33.3 h1:qmOcAHN6DjfD0v9kxL5udB27SRP6SG/MTopmge3MwEs=
|
||||
k8s.io/apiextensions-apiserver v0.33.3/go.mod h1:oROuctgo27mUsyp9+Obahos6CWcMISSAPzQ77CAQGz8=
|
||||
k8s.io/apimachinery v0.33.3 h1:4ZSrmNa0c/ZpZJhAgRdcsFcZOw1PQU1bALVQ0B3I5LA=
|
||||
k8s.io/apimachinery v0.33.3/go.mod h1:BHW0YOu7n22fFv/JkYOEfkUYNRN0fj0BlvMFWA7b+SM=
|
||||
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
|
||||
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
|
||||
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A=
|
||||
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
|
||||
sigs.k8s.io/controller-tools v0.16.5 h1:5k9FNRqziBPwqr17AMEPPV/En39ZBplLAdOwwQHruP4=
|
||||
sigs.k8s.io/controller-tools v0.16.5/go.mod h1:8vztuRVzs8IuuJqKqbXCSlXcw+lkAv/M2sTpg55qjMY=
|
||||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
|
||||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
|
||||
k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e h1:KqK5c/ghOm8xkHYhlodbp6i6+r+ChV2vuAuVRdFbLro=
|
||||
k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
|
||||
sigs.k8s.io/controller-tools v0.17.2 h1:jNFOKps8WnaRKZU2R+4vRCHnXyJanVmXBWqkuUPFyFg=
|
||||
sigs.k8s.io/controller-tools v0.17.2/go.mod h1:4q5tZG2JniS5M5bkiXY2/potOiXyhoZVw/U48vLkXk0=
|
||||
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7npUVDpVXUUOFfW6CgAqE=
|
||||
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg=
|
||||
sigs.k8s.io/randfill v0.0.0-20250304075658-069ef1bbf016/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY=
|
||||
sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU=
|
||||
sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY=
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 h1:IUA9nvMmnKWcj5jl84xn+T5MnlZKThmUW1TdblaLVAc=
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.6.0/go.mod h1:dDy58f92j70zLsuZVuUX5Wp9vtxXpaZnkPGWeqDfCps=
|
||||
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
|
||||
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
|
||||
|
|
|
@ -58,7 +58,7 @@ type ConfigurationSpec struct {
|
|||
// +kubebuilder:default:=Background
|
||||
DeletionPropagationPolicy metav1.DeletionPropagation `json:"deletionPropagationPolicy,omitempty"`
|
||||
|
||||
// ReportFormat determines test report format (JSON|XML|JUNIT-TEST|JUNIT-STEP|JUNIT-OPERATION|nil) nil == no report.
|
||||
// ReportFormat determines test report format (JSON, XML, JUNIT-TEST, JUNIT-STEP, JUNIT-OPERATION, nil) nil == no report.
|
||||
// maps to report.Type, however we don't want generated.deepcopy to have reference to it.
|
||||
// +optional
|
||||
// +kubebuilder:validation:Enum:=JSON;XML;JUNIT-TEST;JUNIT-STEP;JUNIT-OPERATION;
|
||||
|
|
|
@ -14,6 +14,11 @@ import (
|
|||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
const (
|
||||
EngineJP = v1alpha1.EngineJP
|
||||
EngineCEL = v1alpha1.EngineCEL
|
||||
)
|
||||
|
||||
var (
|
||||
identifier = regexp.MustCompile(`^(?:\w+|\(.+\))$`)
|
||||
NewAny = v1alpha1.NewAny
|
||||
|
@ -193,31 +198,6 @@ type DefaultTimeouts struct {
|
|||
Exec metav1.Duration `json:"exec"`
|
||||
}
|
||||
|
||||
func (t DefaultTimeouts) Combine(override *Timeouts) DefaultTimeouts {
|
||||
if override == nil {
|
||||
return t
|
||||
}
|
||||
if override.Apply != nil {
|
||||
t.Apply = *override.Apply
|
||||
}
|
||||
if override.Assert != nil {
|
||||
t.Assert = *override.Assert
|
||||
}
|
||||
if override.Error != nil {
|
||||
t.Error = *override.Error
|
||||
}
|
||||
if override.Delete != nil {
|
||||
t.Delete = *override.Delete
|
||||
}
|
||||
if override.Cleanup != nil {
|
||||
t.Cleanup = *override.Cleanup
|
||||
}
|
||||
if override.Exec != nil {
|
||||
t.Exec = *override.Exec
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// Timeouts contains timeouts per operation.
|
||||
type Timeouts struct {
|
||||
// Apply defines the timeout for the apply operation
|
||||
|
|
|
@ -2,10 +2,8 @@ package v1alpha1
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
func TestBinding_CheckName(t *testing.T) {
|
||||
|
@ -57,51 +55,3 @@ func TestBinding_CheckName(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimeouts_Combine(t *testing.T) {
|
||||
base := DefaultTimeouts{
|
||||
Apply: metav1.Duration{Duration: 1 * time.Minute},
|
||||
Assert: metav1.Duration{Duration: 1 * time.Minute},
|
||||
Cleanup: metav1.Duration{Duration: 1 * time.Minute},
|
||||
Delete: metav1.Duration{Duration: 1 * time.Minute},
|
||||
Error: metav1.Duration{Duration: 1 * time.Minute},
|
||||
Exec: metav1.Duration{Duration: 1 * time.Minute},
|
||||
}
|
||||
override := Timeouts{
|
||||
Apply: &metav1.Duration{Duration: 2 * time.Minute},
|
||||
Assert: &metav1.Duration{Duration: 2 * time.Minute},
|
||||
Cleanup: &metav1.Duration{Duration: 2 * time.Minute},
|
||||
Delete: &metav1.Duration{Duration: 2 * time.Minute},
|
||||
Error: &metav1.Duration{Duration: 2 * time.Minute},
|
||||
Exec: &metav1.Duration{Duration: 2 * time.Minute},
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
base DefaultTimeouts
|
||||
override *Timeouts
|
||||
want DefaultTimeouts
|
||||
}{{
|
||||
name: "nil",
|
||||
base: base,
|
||||
override: nil,
|
||||
want: base,
|
||||
}, {
|
||||
name: "override",
|
||||
base: base,
|
||||
override: &override,
|
||||
want: DefaultTimeouts{
|
||||
Apply: metav1.Duration{Duration: 2 * time.Minute},
|
||||
Assert: metav1.Duration{Duration: 2 * time.Minute},
|
||||
Cleanup: metav1.Duration{Duration: 2 * time.Minute},
|
||||
Delete: metav1.Duration{Duration: 2 * time.Minute},
|
||||
Error: metav1.Duration{Duration: 2 * time.Minute},
|
||||
Exec: metav1.Duration{Duration: 2 * time.Minute},
|
||||
},
|
||||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := tt.base.Combine(tt.override)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
//go:build !ignore_autogenerated
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright The Kubernetes Authors.
|
||||
|
||||
|
@ -20,8 +23,8 @@ package v1alpha1
|
|||
|
||||
import (
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
schema "k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
// GroupName specifies the group name used to register the objects.
|
||||
|
@ -43,7 +46,7 @@ var (
|
|||
// localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes.
|
||||
SchemeBuilder runtime.SchemeBuilder
|
||||
localSchemeBuilder = &SchemeBuilder
|
||||
// Depreciated: use Install instead
|
||||
// Deprecated: use Install instead
|
||||
AddToScheme = localSchemeBuilder.AddToScheme
|
||||
Install = localSchemeBuilder.AddToScheme
|
||||
)
|
||||
|
|
|
@ -107,7 +107,7 @@ const (
|
|||
|
||||
// ReportOptions contains the configuration used for reporting.
|
||||
type ReportOptions struct {
|
||||
// ReportFormat determines test report format (JSON|XML|JUNIT-TEST|JUNIT-STEP|JUNIT-OPERATION).
|
||||
// ReportFormat determines test report format (JSON, XML, JUNIT-TEST, JUNIT-STEP, JUNIT-OPERATION).
|
||||
// +optional
|
||||
// +kubebuilder:validation:Enum:=JSON;XML;JUNIT-TEST;JUNIT-STEP;JUNIT-OPERATION
|
||||
// +kubebuilder:default:="JSON"
|
||||
|
|
|
@ -5,6 +5,11 @@ import (
|
|||
_ "github.com/kyverno/kyverno-json/pkg/apis/policy/v1alpha1"
|
||||
)
|
||||
|
||||
const (
|
||||
EngineJP = v1alpha1.EngineJP
|
||||
EngineCEL = v1alpha1.EngineCEL
|
||||
)
|
||||
|
||||
type (
|
||||
Clusters = v1alpha1.Clusters
|
||||
Compiler = v1alpha1.Compiler
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
//go:build !ignore_autogenerated
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright The Kubernetes Authors.
|
||||
|
||||
|
@ -20,8 +23,8 @@ package v1alpha2
|
|||
|
||||
import (
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
schema "k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
// GroupName specifies the group name used to register the objects.
|
||||
|
@ -43,7 +46,7 @@ var (
|
|||
// localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes.
|
||||
SchemeBuilder runtime.SchemeBuilder
|
||||
localSchemeBuilder = &SchemeBuilder
|
||||
// Depreciated: use Install instead
|
||||
// Deprecated: use Install instead
|
||||
AddToScheme = localSchemeBuilder.AddToScheme
|
||||
Install = localSchemeBuilder.AddToScheme
|
||||
)
|
||||
|
|
|
@ -73,8 +73,11 @@ func (c *cleaner) Run(ctx context.Context, stepReport *model.StepReport) []error
|
|||
}
|
||||
|
||||
func (c *cleaner) delete(ctx context.Context, entry cleanupEntry) error {
|
||||
ctx, cancel := context.WithTimeout(ctx, c.timeout)
|
||||
defer cancel()
|
||||
if c.timeout != 0 {
|
||||
_ctx, cancel := context.WithTimeout(ctx, c.timeout)
|
||||
defer cancel()
|
||||
ctx = _ctx
|
||||
}
|
||||
if err := entry.client.Delete(ctx, entry.object, client.PropagationPolicy(c.propagation)); err != nil {
|
||||
if !kerrors.IsNotFound(err) {
|
||||
return err
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
tclient "github.com/kyverno/chainsaw/pkg/client/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
kerror "k8s.io/apimachinery/pkg/api/errors"
|
||||
|
@ -196,7 +197,7 @@ func Test_cleaner_Run(t *testing.T) {
|
|||
timeout: 1 * time.Second,
|
||||
entries: tt.entries,
|
||||
}
|
||||
got := c.Run(context.TODO(), nil)
|
||||
got := c.Run(context.TODO(), &model.StepReport{})
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -138,8 +138,12 @@ func runE(opts options, cmd *cobra.Command, client client.Client, namespacer nsp
|
|||
}
|
||||
|
||||
func assert(opts options, client client.Client, resource unstructured.Unstructured, namespacer nspacer.Namespacer) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), opts.timeout.Duration)
|
||||
defer cancel()
|
||||
ctx := context.Background()
|
||||
if opts.timeout.Duration != 0 {
|
||||
_ctx, cancel := context.WithTimeout(ctx, opts.timeout.Duration)
|
||||
defer cancel()
|
||||
ctx = _ctx
|
||||
}
|
||||
op := opassert.New(apis.DefaultCompilers, client, resource, namespacer, false)
|
||||
_, err := op.Exec(ctx, nil)
|
||||
return err
|
||||
|
|
|
@ -3,23 +3,30 @@ package assert
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
tclient "github.com/kyverno/chainsaw/pkg/client/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/commands/root"
|
||||
fakeNamespacer "github.com/kyverno/chainsaw/pkg/engine/namespacer/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/testing"
|
||||
"github.com/spf13/cobra"
|
||||
testify "github.com/stretchr/testify/assert"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
type errReader struct{}
|
||||
|
||||
func (e *errReader) Read(p []byte) (n int, err error) {
|
||||
return 0, errors.New("error reading from stdin")
|
||||
}
|
||||
|
||||
func Test_Execute(t *testing.T) {
|
||||
basePath := path.Join("..", "..", "..", "testdata", "commands", "assert")
|
||||
tests := []struct {
|
||||
|
@ -320,7 +327,7 @@ data:
|
|||
cmd.Args = cobra.RangeArgs(0, 1)
|
||||
cmd.SilenceUsage = true
|
||||
cmd.SetOut(bytes.NewBufferString(""))
|
||||
cmd.SetIn(&testing.ErrReader{})
|
||||
cmd.SetIn(&errReader{})
|
||||
return cmd
|
||||
},
|
||||
opts: options{
|
||||
|
|
|
@ -19,7 +19,7 @@ func websitePrepender(filename string) string {
|
|||
now := time.Now().Format(time.RFC3339)
|
||||
name := filepath.Base(filename)
|
||||
base := strings.TrimSuffix(name, path.Ext(name))
|
||||
return fmt.Sprintf(fmTemplate, now, strings.Replace(base, "_", " ", -1))
|
||||
return fmt.Sprintf(fmTemplate, now, strings.ReplaceAll(base, "_", " "))
|
||||
}
|
||||
|
||||
func websiteLinkHandler(filename string) string {
|
||||
|
|
|
@ -151,7 +151,7 @@ func processStep(stderr io.Writer, step *v1alpha1.TestStep, s discovery.Step, fo
|
|||
}
|
||||
}
|
||||
if !containsKuttlResources {
|
||||
step.TestStepSpec.Try = append(step.TestStepSpec.Try, v1alpha1.Operation{
|
||||
step.Try = append(step.Try, v1alpha1.Operation{
|
||||
Apply: &v1alpha1.Apply{
|
||||
ActionResourceRef: v1alpha1.ActionResourceRef{
|
||||
FileRef: v1alpha1.FileRef{
|
||||
|
@ -193,7 +193,7 @@ func processStep(stderr io.Writer, step *v1alpha1.TestStep, s discovery.Step, fo
|
|||
return err
|
||||
}
|
||||
}
|
||||
step.TestStepSpec.Try = append(step.TestStepSpec.Try, v1alpha1.Operation{
|
||||
step.Try = append(step.Try, v1alpha1.Operation{
|
||||
Apply: &v1alpha1.Apply{
|
||||
ActionResourceRef: v1alpha1.ActionResourceRef{
|
||||
FileRef: v1alpha1.FileRef{
|
||||
|
@ -218,7 +218,7 @@ func processStep(stderr io.Writer, step *v1alpha1.TestStep, s discovery.Step, fo
|
|||
}
|
||||
}
|
||||
if !containsKuttlResources {
|
||||
step.TestStepSpec.Try = append(step.TestStepSpec.Try, v1alpha1.Operation{
|
||||
step.Try = append(step.Try, v1alpha1.Operation{
|
||||
Assert: &v1alpha1.Assert{
|
||||
ActionCheckRef: v1alpha1.ActionCheckRef{
|
||||
FileRef: v1alpha1.FileRef{
|
||||
|
@ -254,7 +254,7 @@ func processStep(stderr io.Writer, step *v1alpha1.TestStep, s discovery.Step, fo
|
|||
return err
|
||||
}
|
||||
}
|
||||
step.TestStepSpec.Try = append(step.TestStepSpec.Try, v1alpha1.Operation{
|
||||
step.Try = append(step.Try, v1alpha1.Operation{
|
||||
Assert: &v1alpha1.Assert{
|
||||
ActionCheckRef: v1alpha1.ActionCheckRef{
|
||||
FileRef: v1alpha1.FileRef{
|
||||
|
@ -279,7 +279,7 @@ func processStep(stderr io.Writer, step *v1alpha1.TestStep, s discovery.Step, fo
|
|||
}
|
||||
}
|
||||
if !containsKuttlResources {
|
||||
step.TestStepSpec.Try = append(step.TestStepSpec.Try, v1alpha1.Operation{
|
||||
step.Try = append(step.Try, v1alpha1.Operation{
|
||||
Error: &v1alpha1.Error{
|
||||
ActionCheckRef: v1alpha1.ActionCheckRef{
|
||||
FileRef: v1alpha1.FileRef{
|
||||
|
@ -315,7 +315,7 @@ func processStep(stderr io.Writer, step *v1alpha1.TestStep, s discovery.Step, fo
|
|||
return err
|
||||
}
|
||||
}
|
||||
step.TestStepSpec.Try = append(step.TestStepSpec.Try, v1alpha1.Operation{
|
||||
step.Try = append(step.Try, v1alpha1.Operation{
|
||||
Error: &v1alpha1.Error{
|
||||
ActionCheckRef: v1alpha1.ActionCheckRef{
|
||||
FileRef: v1alpha1.FileRef{
|
||||
|
|
|
@ -12,8 +12,10 @@ import (
|
|||
"github.com/kyverno/chainsaw/pkg/discovery"
|
||||
"github.com/kyverno/chainsaw/pkg/loaders/config"
|
||||
"github.com/kyverno/chainsaw/pkg/loaders/values"
|
||||
"github.com/kyverno/chainsaw/pkg/report"
|
||||
"github.com/kyverno/chainsaw/pkg/runner"
|
||||
"github.com/kyverno/chainsaw/pkg/runner/failer"
|
||||
enginecontext "github.com/kyverno/chainsaw/pkg/runner/context"
|
||||
runnerflags "github.com/kyverno/chainsaw/pkg/runner/flags"
|
||||
flagutils "github.com/kyverno/chainsaw/pkg/utils/flag"
|
||||
fsutils "github.com/kyverno/chainsaw/pkg/utils/fs"
|
||||
restutils "github.com/kyverno/chainsaw/pkg/utils/rest"
|
||||
|
@ -75,26 +77,28 @@ func Command() *cobra.Command {
|
|||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
color.Init(options.noColor, true)
|
||||
clock := clock.RealClock{}
|
||||
out := cmd.OutOrStdout()
|
||||
fmt.Fprintf(out, "Version: %s\n", version.Version())
|
||||
stdOut := cmd.OutOrStdout()
|
||||
stdErr := cmd.ErrOrStderr()
|
||||
stdIn := cmd.InOrStdin()
|
||||
fmt.Fprintf(stdOut, "Version: %s\n", version.Version())
|
||||
var configuration v1alpha2.Configuration
|
||||
// if no config file was provided, give a chance to the default config name
|
||||
if options.config == "" {
|
||||
if _, err := os.Stat(config.DefaultFileName); err == nil {
|
||||
options.config = config.DefaultFileName
|
||||
fmt.Fprintf(out, "No configuration provided but found default file: %s\n", options.config)
|
||||
fmt.Fprintf(stdOut, "No configuration provided but found default file: %s\n", options.config)
|
||||
}
|
||||
}
|
||||
// try to load configuration file
|
||||
if options.config != "" {
|
||||
fmt.Fprintf(out, "Loading config (%s)...\n", options.config)
|
||||
fmt.Fprintf(stdOut, "Loading config (%s)...\n", options.config)
|
||||
config, err := config.Load(options.config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
configuration = *config
|
||||
} else {
|
||||
fmt.Fprintln(out, "Loading default configuration...")
|
||||
fmt.Fprintln(stdOut, "Loading default configuration...")
|
||||
config, err := config.DefaultConfiguration()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -225,63 +229,63 @@ func Command() *cobra.Command {
|
|||
if options.pauseOnFailure {
|
||||
configuration.Spec.Execution.Parallel = ptr.To(1)
|
||||
}
|
||||
fmt.Fprintf(out, "- Using test file: %s\n", configuration.Spec.Discovery.TestFile)
|
||||
fmt.Fprintf(out, "- TestDirs %v\n", options.testDirs)
|
||||
fmt.Fprintf(out, "- SkipDelete %v\n", configuration.Spec.Cleanup.SkipDelete)
|
||||
fmt.Fprintf(out, "- FailFast %v\n", configuration.Spec.Execution.FailFast)
|
||||
fmt.Fprintf(stdOut, "- Using test file: %s\n", configuration.Spec.Discovery.TestFile)
|
||||
fmt.Fprintf(stdOut, "- TestDirs %v\n", options.testDirs)
|
||||
fmt.Fprintf(stdOut, "- SkipDelete %v\n", configuration.Spec.Cleanup.SkipDelete)
|
||||
fmt.Fprintf(stdOut, "- FailFast %v\n", configuration.Spec.Execution.FailFast)
|
||||
if configuration.Spec.Report != nil {
|
||||
fmt.Fprintf(out, "- ReportFormat '%v'\n", configuration.Spec.Report.Format)
|
||||
fmt.Fprintf(out, "- ReportName '%v'\n", configuration.Spec.Report.Name)
|
||||
fmt.Fprintf(stdOut, "- ReportFormat '%v'\n", configuration.Spec.Report.Format)
|
||||
fmt.Fprintf(stdOut, "- ReportName '%v'\n", configuration.Spec.Report.Name)
|
||||
if configuration.Spec.Report.Path != "" {
|
||||
fmt.Fprintf(out, "- ReportPath '%v'\n", configuration.Spec.Report.Path)
|
||||
fmt.Fprintf(stdOut, "- ReportPath '%v'\n", configuration.Spec.Report.Path)
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(out, "- Namespace '%v'\n", configuration.Spec.Namespace.Name)
|
||||
fmt.Fprintf(out, "- FullName %v\n", configuration.Spec.Discovery.FullName)
|
||||
fmt.Fprintf(out, "- IncludeTestRegex '%v'\n", configuration.Spec.Discovery.IncludeTestRegex)
|
||||
fmt.Fprintf(out, "- ExcludeTestRegex '%v'\n", configuration.Spec.Discovery.ExcludeTestRegex)
|
||||
fmt.Fprintf(out, "- ApplyTimeout %v\n", configuration.Spec.Timeouts.Apply.Duration)
|
||||
fmt.Fprintf(out, "- AssertTimeout %v\n", configuration.Spec.Timeouts.Assert.Duration)
|
||||
fmt.Fprintf(out, "- CleanupTimeout %v\n", configuration.Spec.Timeouts.Cleanup.Duration)
|
||||
fmt.Fprintf(out, "- DeleteTimeout %v\n", configuration.Spec.Timeouts.Delete.Duration)
|
||||
fmt.Fprintf(out, "- ErrorTimeout %v\n", configuration.Spec.Timeouts.Error.Duration)
|
||||
fmt.Fprintf(out, "- ExecTimeout %v\n", configuration.Spec.Timeouts.Exec.Duration)
|
||||
fmt.Fprintf(out, "- DeletionPropagationPolicy %v\n", configuration.Spec.Deletion.Propagation)
|
||||
fmt.Fprintf(stdOut, "- Namespace '%v'\n", configuration.Spec.Namespace.Name)
|
||||
fmt.Fprintf(stdOut, "- FullName %v\n", configuration.Spec.Discovery.FullName)
|
||||
fmt.Fprintf(stdOut, "- IncludeTestRegex '%v'\n", configuration.Spec.Discovery.IncludeTestRegex)
|
||||
fmt.Fprintf(stdOut, "- ExcludeTestRegex '%v'\n", configuration.Spec.Discovery.ExcludeTestRegex)
|
||||
fmt.Fprintf(stdOut, "- ApplyTimeout %v\n", configuration.Spec.Timeouts.Apply.Duration)
|
||||
fmt.Fprintf(stdOut, "- AssertTimeout %v\n", configuration.Spec.Timeouts.Assert.Duration)
|
||||
fmt.Fprintf(stdOut, "- CleanupTimeout %v\n", configuration.Spec.Timeouts.Cleanup.Duration)
|
||||
fmt.Fprintf(stdOut, "- DeleteTimeout %v\n", configuration.Spec.Timeouts.Delete.Duration)
|
||||
fmt.Fprintf(stdOut, "- ErrorTimeout %v\n", configuration.Spec.Timeouts.Error.Duration)
|
||||
fmt.Fprintf(stdOut, "- ExecTimeout %v\n", configuration.Spec.Timeouts.Exec.Duration)
|
||||
fmt.Fprintf(stdOut, "- DeletionPropagationPolicy %v\n", configuration.Spec.Deletion.Propagation)
|
||||
if configuration.Spec.Execution.Parallel != nil && *configuration.Spec.Execution.Parallel > 0 {
|
||||
fmt.Fprintf(out, "- Parallel %d\n", *configuration.Spec.Execution.Parallel)
|
||||
fmt.Fprintf(stdOut, "- Parallel %d\n", *configuration.Spec.Execution.Parallel)
|
||||
}
|
||||
if configuration.Spec.Execution.RepeatCount != nil {
|
||||
fmt.Fprintf(out, "- RepeatCount %v\n", *configuration.Spec.Execution.RepeatCount)
|
||||
fmt.Fprintf(stdOut, "- RepeatCount %v\n", *configuration.Spec.Execution.RepeatCount)
|
||||
}
|
||||
if configuration.Spec.Execution.ForceTerminationGracePeriod != nil {
|
||||
fmt.Fprintf(out, "- ForceTerminationGracePeriod %v\n", configuration.Spec.Execution.ForceTerminationGracePeriod.Duration)
|
||||
fmt.Fprintf(stdOut, "- ForceTerminationGracePeriod %v\n", configuration.Spec.Execution.ForceTerminationGracePeriod.Duration)
|
||||
}
|
||||
if configuration.Spec.Cleanup.DelayBeforeCleanup != nil {
|
||||
fmt.Fprintf(out, "- DelayBeforeCleanup %v\n", configuration.Spec.Cleanup.DelayBeforeCleanup.Duration)
|
||||
fmt.Fprintf(stdOut, "- DelayBeforeCleanup %v\n", configuration.Spec.Cleanup.DelayBeforeCleanup.Duration)
|
||||
}
|
||||
if len(options.selector) != 0 {
|
||||
fmt.Fprintf(out, "- Selector %v\n", options.selector)
|
||||
fmt.Fprintf(stdOut, "- Selector %v\n", options.selector)
|
||||
}
|
||||
if len(options.values) != 0 {
|
||||
fmt.Fprintf(out, "- Values %v\n", options.values)
|
||||
fmt.Fprintf(stdOut, "- Values %v\n", options.values)
|
||||
}
|
||||
fmt.Fprintf(out, "- Template %v\n", configuration.Spec.Templating.Enabled)
|
||||
fmt.Fprintf(stdOut, "- Template %v\n", configuration.Spec.Templating.Enabled)
|
||||
if configuration.Spec.Templating.Compiler != nil {
|
||||
fmt.Fprintf(out, "- Default compiler %v\n", *configuration.Spec.Templating.Compiler)
|
||||
fmt.Fprintf(stdOut, "- Default compiler %v\n", *configuration.Spec.Templating.Compiler)
|
||||
}
|
||||
if len(configuration.Spec.Clusters) != 0 {
|
||||
fmt.Fprintf(out, "- Clusters %v\n", configuration.Spec.Clusters)
|
||||
fmt.Fprintf(stdOut, "- Clusters %v\n", configuration.Spec.Clusters)
|
||||
}
|
||||
if options.remarshal {
|
||||
fmt.Fprintf(out, "- Remarshal %v\n", options.remarshal)
|
||||
fmt.Fprintf(stdOut, "- Remarshal %v\n", options.remarshal)
|
||||
}
|
||||
fmt.Fprintf(out, "- NoCluster %v\n", options.noCluster)
|
||||
fmt.Fprintf(out, "- PauseOnFailure %v\n", options.pauseOnFailure)
|
||||
fmt.Fprintf(stdOut, "- NoCluster %v\n", options.noCluster)
|
||||
fmt.Fprintf(stdOut, "- PauseOnFailure %v\n", options.pauseOnFailure)
|
||||
if options.shardCount > 0 {
|
||||
fmt.Fprintf(out, "- Shard %v / %v\n", options.shardIndex, options.shardCount)
|
||||
fmt.Fprintf(stdOut, "- Shard %v / %v\n", options.shardIndex, options.shardCount)
|
||||
}
|
||||
// load tests
|
||||
fmt.Fprintln(out, "Loading tests...")
|
||||
fmt.Fprintln(stdOut, "Loading tests...")
|
||||
if err := fsutils.CheckFolders(options.testDirs...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -310,20 +314,20 @@ func Command() *cobra.Command {
|
|||
var testToRun []discovery.Test
|
||||
for _, test := range tests {
|
||||
if test.Err != nil {
|
||||
fmt.Fprintf(out, "- %s (%s) - (%s)\n", test.Test.Name, test.BasePath, test.Err)
|
||||
fmt.Fprintf(stdOut, "- %s (%s) - (%s)\n", test.Test.Name, test.BasePath, test.Err)
|
||||
} else {
|
||||
fmt.Fprintf(out, "- %s (%s)\n", test.Test.Name, test.BasePath)
|
||||
fmt.Fprintf(stdOut, "- %s (%s)\n", test.Test.Name, test.BasePath)
|
||||
testToRun = append(testToRun, test)
|
||||
}
|
||||
}
|
||||
// load values
|
||||
fmt.Fprintln(out, "Loading values...")
|
||||
fmt.Fprintln(stdOut, "Loading values...")
|
||||
values, err := values.Load(options.values...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// run tests
|
||||
fmt.Fprintln(out, "Running tests...")
|
||||
fmt.Fprintln(stdOut, "Running tests...")
|
||||
var restConfig *rest.Config
|
||||
if !options.noCluster {
|
||||
cfg, err := restutils.DefaultConfig(options.kubeConfigOverrides)
|
||||
|
@ -332,21 +336,44 @@ func Command() *cobra.Command {
|
|||
}
|
||||
restConfig = cfg
|
||||
}
|
||||
ctx := failer.IntoContext(context.Background(), failer.New(options.pauseOnFailure))
|
||||
summary, err := runner.Run(ctx, restConfig, clock, configuration.Spec, values, testToRun...)
|
||||
if summary != nil {
|
||||
fmt.Fprintln(out, "Tests Summary...")
|
||||
fmt.Fprintln(out, "- Passed tests", summary.Passed())
|
||||
fmt.Fprintln(out, "- Failed tests", summary.Failed())
|
||||
fmt.Fprintln(out, "- Skipped tests", summary.Skipped())
|
||||
var onFailure func()
|
||||
if options.pauseOnFailure {
|
||||
onFailure = func() {
|
||||
fmt.Fprintln(stdErr, "Failure detected, press ENTER to continue...")
|
||||
fmt.Fscanln(stdIn) //nolint:errcheck
|
||||
}
|
||||
}
|
||||
ctx := context.Background()
|
||||
tc, err := enginecontext.InitContext(configuration.Spec, restConfig, values)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
runner := runner.New(clock, onFailure)
|
||||
// setup flags
|
||||
if err := runnerflags.SetupFlags(configuration.Spec); err != nil {
|
||||
return err
|
||||
}
|
||||
err = runner.Run(ctx, configuration.Spec.Namespace, tc, testToRun...)
|
||||
fmt.Fprintln(stdOut, "Tests Summary...")
|
||||
fmt.Fprintln(stdOut, "- Passed tests", tc.Passed())
|
||||
fmt.Fprintln(stdOut, "- Failed tests", tc.Failed())
|
||||
fmt.Fprintln(stdOut, "- Skipped tests", tc.Skipped())
|
||||
// process report
|
||||
if err == nil {
|
||||
if configuration.Spec.Report != nil && configuration.Spec.Report.Format != "" {
|
||||
fmt.Fprintln(stdOut, "Saving report...")
|
||||
if err := report.Save(tc.Report, configuration.Spec.Report.Format, configuration.Spec.Report.Path, configuration.Spec.Report.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Fprintln(out, "Done with error.")
|
||||
} else if summary != nil && summary.Failed() > 0 {
|
||||
fmt.Fprintln(out, "Done with failures.")
|
||||
fmt.Fprintln(stdOut, "Done with error.")
|
||||
} else if tc.Failed() > 0 {
|
||||
fmt.Fprintln(stdOut, "Done with failures.")
|
||||
err = errors.New("some tests failed")
|
||||
} else {
|
||||
fmt.Fprintln(out, "Done.")
|
||||
fmt.Fprintln(stdOut, "Done.")
|
||||
}
|
||||
return err
|
||||
},
|
||||
|
@ -388,7 +415,7 @@ func Command() *cobra.Command {
|
|||
cmd.Flags().StringVar(&options.deletionPropagationPolicy, "deletion-propagation-policy", "Background", "The deletion propagation policy (Foreground|Background|Orphan)")
|
||||
// error options
|
||||
// reporting options
|
||||
cmd.Flags().StringVar(&options.reportFormat, "report-format", "", "Test report format (JSON|XML|JUNIT-TEST|JUNIT-STEP|JUNIT-OPERATION)")
|
||||
cmd.Flags().StringVar(&options.reportFormat, "report-format", "", "Test report format (JSON, XML, JUNIT-TEST, JUNIT-STEP, JUNIT-OPERATION)")
|
||||
cmd.Flags().StringVar(&options.reportName, "report-name", "chainsaw-report", "The name of the report to create")
|
||||
cmd.Flags().StringVar(&options.reportPath, "report-path", "", "The path of the report to create")
|
||||
// multi-cluster options
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func TestChainsawCommand(t *testing.T) {
|
||||
path := "../../../.temp"
|
||||
basePath := "../../../testdata/commands/test"
|
||||
tests := []struct {
|
||||
name string
|
||||
|
@ -116,6 +117,8 @@ func TestChainsawCommand(t *testing.T) {
|
|||
args: []string{
|
||||
"--config",
|
||||
filepath.Join(basePath, "config/config_all_fields.yaml"),
|
||||
"--report-path",
|
||||
path,
|
||||
},
|
||||
wantErr: false,
|
||||
out: filepath.Join(basePath, "config_all_fields.txt"),
|
||||
|
@ -135,6 +138,8 @@ func TestChainsawCommand(t *testing.T) {
|
|||
"--parallel=24",
|
||||
"--repeat-count=12",
|
||||
"--report-format=XML",
|
||||
"--report-path",
|
||||
path,
|
||||
"--report-name=foo",
|
||||
"--namespace=bar",
|
||||
"--full-name=true",
|
||||
|
|
|
@ -902,7 +902,7 @@ spec:
|
|||
type: integer
|
||||
reportFormat:
|
||||
description: |-
|
||||
ReportFormat determines test report format (JSON|XML|JUNIT-TEST|JUNIT-STEP|JUNIT-OPERATION|nil) nil == no report.
|
||||
ReportFormat determines test report format (JSON, XML, JUNIT-TEST, JUNIT-STEP, JUNIT-OPERATION, nil) nil == no report.
|
||||
maps to report.Type, however we don't want generated.deepcopy to have reference to it.
|
||||
enum:
|
||||
- JSON
|
||||
|
@ -1899,7 +1899,8 @@ spec:
|
|||
properties:
|
||||
format:
|
||||
default: JSON
|
||||
description: ReportFormat determines test report format (JSON|XML|JUNIT-TEST|JUNIT-STEP|JUNIT-OPERATION).
|
||||
description: ReportFormat determines test report format (JSON,
|
||||
XML, JUNIT-TEST, JUNIT-STEP, JUNIT-OPERATION).
|
||||
enum:
|
||||
- JSON
|
||||
- XML
|
||||
|
|
|
@ -1764,7 +1764,7 @@
|
|||
"minimum": 1
|
||||
},
|
||||
"reportFormat": {
|
||||
"description": "ReportFormat determines test report format (JSON|XML|JUNIT-TEST|JUNIT-STEP|JUNIT-OPERATION|nil) nil == no report.\nmaps to report.Type, however we don't want generated.deepcopy to have reference to it.",
|
||||
"description": "ReportFormat determines test report format (JSON, XML, JUNIT-TEST, JUNIT-STEP, JUNIT-OPERATION, nil) nil == no report.\nmaps to report.Type, however we don't want generated.deepcopy to have reference to it.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
|
@ -1885,7 +1885,6 @@
|
|||
"version": "v1alpha1"
|
||||
}
|
||||
],
|
||||
"x-kubernetes-selectable-fields": [],
|
||||
"additionalProperties": false,
|
||||
"$schema": "http://json-schema.org/schema#"
|
||||
}
|
|
@ -1841,7 +1841,7 @@
|
|||
],
|
||||
"properties": {
|
||||
"format": {
|
||||
"description": "ReportFormat determines test report format (JSON|XML|JUNIT-TEST|JUNIT-STEP|JUNIT-OPERATION).",
|
||||
"description": "ReportFormat determines test report format (JSON, XML, JUNIT-TEST, JUNIT-STEP, JUNIT-OPERATION).",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
|
@ -1973,7 +1973,6 @@
|
|||
"version": "v1alpha2"
|
||||
}
|
||||
],
|
||||
"x-kubernetes-selectable-fields": [],
|
||||
"additionalProperties": false,
|
||||
"$schema": "http://json-schema.org/schema#"
|
||||
}
|
|
@ -8049,7 +8049,6 @@
|
|||
"version": "v1alpha1"
|
||||
}
|
||||
],
|
||||
"x-kubernetes-selectable-fields": [],
|
||||
"additionalProperties": false,
|
||||
"$schema": "http://json-schema.org/schema#"
|
||||
}
|
|
@ -9892,7 +9892,6 @@
|
|||
"version": "v1alpha1"
|
||||
}
|
||||
],
|
||||
"x-kubernetes-selectable-fields": [],
|
||||
"additionalProperties": false,
|
||||
"$schema": "http://json-schema.org/schema#"
|
||||
}
|
|
@ -109,7 +109,7 @@ func LoadTest(fileName string, path string, remarshal bool) ([]Test, error) {
|
|||
Name: fmt.Sprintf("step-%s", key),
|
||||
}
|
||||
for _, file := range steps[key].OtherFiles {
|
||||
step.TestStepSpec.Try = append(step.TestStepSpec.Try, v1alpha1.Operation{
|
||||
step.Try = append(step.Try, v1alpha1.Operation{
|
||||
Apply: &v1alpha1.Apply{
|
||||
ActionResourceRef: v1alpha1.ActionResourceRef{
|
||||
FileRef: v1alpha1.FileRef{
|
||||
|
@ -120,7 +120,7 @@ func LoadTest(fileName string, path string, remarshal bool) ([]Test, error) {
|
|||
})
|
||||
}
|
||||
for _, file := range steps[key].AssertFiles {
|
||||
step.TestStepSpec.Try = append(step.TestStepSpec.Try, v1alpha1.Operation{
|
||||
step.Try = append(step.Try, v1alpha1.Operation{
|
||||
Assert: &v1alpha1.Assert{
|
||||
ActionCheckRef: v1alpha1.ActionCheckRef{
|
||||
FileRef: v1alpha1.FileRef{
|
||||
|
@ -131,7 +131,7 @@ func LoadTest(fileName string, path string, remarshal bool) ([]Test, error) {
|
|||
})
|
||||
}
|
||||
for _, file := range steps[key].ErrorFiles {
|
||||
step.TestStepSpec.Try = append(step.TestStepSpec.Try, v1alpha1.Operation{
|
||||
step.Try = append(step.Try, v1alpha1.Operation{
|
||||
Error: &v1alpha1.Error{
|
||||
ActionCheckRef: v1alpha1.ActionCheckRef{
|
||||
FileRef: v1alpha1.FileRef{
|
||||
|
|
|
@ -20,7 +20,7 @@ func checkBindingName(name string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func RegisterBinding(ctx context.Context, bindings apis.Bindings, name string, value any) apis.Bindings {
|
||||
func RegisterBinding(bindings apis.Bindings, name string, value any) apis.Bindings {
|
||||
return bindings.Register("$"+name, apis.NewBinding(value))
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ func TestRegisterBinding(t *testing.T) {
|
|||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
bindings := RegisterBinding(context.TODO(), tt.bindings, tt.bindingName, tt.value)
|
||||
bindings := RegisterBinding(tt.bindings, tt.bindingName, tt.value)
|
||||
assert.NotNil(t, bindings)
|
||||
got, err := bindings.Get("$" + tt.bindingName)
|
||||
assert.NoError(t, err)
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/pkg/ext/output/color"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
@ -94,15 +94,9 @@ func (c *runnerClient) RESTMapper() meta.RESTMapper {
|
|||
}
|
||||
|
||||
func (c *runnerClient) ok(ctx context.Context, op logging.Operation, obj client.Object) {
|
||||
logger := logging.FromContext(ctx)
|
||||
if logger != nil {
|
||||
logger.WithResource(obj).Log(op, logging.OkStatus, color.BoldGreen)
|
||||
}
|
||||
logging.Log(ctx, op, logging.OkStatus, obj, color.BoldGreen)
|
||||
}
|
||||
|
||||
func (c *runnerClient) error(ctx context.Context, op logging.Operation, obj client.Object, err error) {
|
||||
logger := logging.FromContext(ctx)
|
||||
if logger != nil {
|
||||
logger.WithResource(obj).Log(op, logging.WarnStatus, color.BoldYellow, logging.ErrSection(err))
|
||||
}
|
||||
logging.Log(ctx, op, logging.OkStatus, obj, color.BoldYellow, logging.ErrSection(err))
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@ import (
|
|||
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
tclient "github.com/kyverno/chainsaw/pkg/client/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
tlogging "github.com/kyverno/chainsaw/pkg/engine/logging/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/mocks"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
|
@ -48,7 +48,6 @@ func Test_runnerClient_Get(t *testing.T) {
|
|||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
logger func(t *testing.T) *tlogging.FakeLogger
|
||||
inner func(t *testing.T) *tclient.FakeClient
|
||||
args args
|
||||
wantErr bool
|
||||
|
@ -56,10 +55,6 @@ func Test_runnerClient_Get(t *testing.T) {
|
|||
loggerCalls int
|
||||
}{{
|
||||
name: "with error",
|
||||
logger: func(t *testing.T) *tlogging.FakeLogger {
|
||||
t.Helper()
|
||||
return &tlogging.FakeLogger{}
|
||||
},
|
||||
inner: func(t *testing.T) *tclient.FakeClient {
|
||||
t.Helper()
|
||||
return &tclient.FakeClient{
|
||||
|
@ -77,10 +72,6 @@ func Test_runnerClient_Get(t *testing.T) {
|
|||
innerCalls: 1,
|
||||
}, {
|
||||
name: "no error",
|
||||
logger: func(t *testing.T) *tlogging.FakeLogger {
|
||||
t.Helper()
|
||||
return &tlogging.FakeLogger{}
|
||||
},
|
||||
inner: func(t *testing.T) *tclient.FakeClient {
|
||||
t.Helper()
|
||||
return &tclient.FakeClient{
|
||||
|
@ -98,10 +89,6 @@ func Test_runnerClient_Get(t *testing.T) {
|
|||
innerCalls: 1,
|
||||
}, {
|
||||
name: "inner was called",
|
||||
logger: func(t *testing.T) *tlogging.FakeLogger {
|
||||
t.Helper()
|
||||
return &tlogging.FakeLogger{}
|
||||
},
|
||||
inner: func(t *testing.T) *tclient.FakeClient {
|
||||
t.Helper()
|
||||
return &tclient.FakeClient{
|
||||
|
@ -122,10 +109,6 @@ func Test_runnerClient_Get(t *testing.T) {
|
|||
innerCalls: 1,
|
||||
}, {
|
||||
name: "logger was not called",
|
||||
logger: func(t *testing.T) *tlogging.FakeLogger {
|
||||
t.Helper()
|
||||
return &tlogging.FakeLogger{}
|
||||
},
|
||||
inner: func(t *testing.T) *tclient.FakeClient {
|
||||
t.Helper()
|
||||
return &tclient.FakeClient{
|
||||
|
@ -147,12 +130,12 @@ func Test_runnerClient_Get(t *testing.T) {
|
|||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
mockLogger := tt.logger(t)
|
||||
logger := &mocks.Logger{}
|
||||
mockClient := tt.inner(t)
|
||||
c := &runnerClient{
|
||||
inner: mockClient,
|
||||
}
|
||||
ctx := logging.IntoContext(context.TODO(), mockLogger)
|
||||
ctx := logging.WithLogger(context.TODO(), logger)
|
||||
err := c.Get(ctx, tt.args.key, tt.args.obj, tt.args.opts...)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
|
@ -160,7 +143,7 @@ func Test_runnerClient_Get(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
}
|
||||
assert.Equal(t, tt.innerCalls, mockClient.NumCalls())
|
||||
assert.Equal(t, tt.loggerCalls, mockLogger.NumCalls())
|
||||
assert.Equal(t, tt.loggerCalls, logger.NumCalls())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -172,7 +155,6 @@ func Test_runnerClient_Create(t *testing.T) {
|
|||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
logger func(t *testing.T) *tlogging.FakeLogger
|
||||
inner func(t *testing.T) *tclient.FakeClient
|
||||
args args
|
||||
wantErr bool
|
||||
|
@ -180,10 +162,6 @@ func Test_runnerClient_Create(t *testing.T) {
|
|||
loggerCalls int
|
||||
}{{
|
||||
name: "with error",
|
||||
logger: func(t *testing.T) *tlogging.FakeLogger {
|
||||
t.Helper()
|
||||
return &tlogging.FakeLogger{}
|
||||
},
|
||||
inner: func(t *testing.T) *tclient.FakeClient {
|
||||
t.Helper()
|
||||
return &tclient.FakeClient{
|
||||
|
@ -197,14 +175,10 @@ func Test_runnerClient_Create(t *testing.T) {
|
|||
opts: nil,
|
||||
},
|
||||
wantErr: true,
|
||||
loggerCalls: 2,
|
||||
loggerCalls: 1,
|
||||
innerCalls: 1,
|
||||
}, {
|
||||
name: "no error",
|
||||
logger: func(t *testing.T) *tlogging.FakeLogger {
|
||||
t.Helper()
|
||||
return &tlogging.FakeLogger{}
|
||||
},
|
||||
inner: func(t *testing.T) *tclient.FakeClient {
|
||||
t.Helper()
|
||||
return &tclient.FakeClient{
|
||||
|
@ -218,17 +192,17 @@ func Test_runnerClient_Create(t *testing.T) {
|
|||
opts: nil,
|
||||
},
|
||||
wantErr: false,
|
||||
loggerCalls: 2,
|
||||
loggerCalls: 1,
|
||||
innerCalls: 1,
|
||||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
mockLogger := tt.logger(t)
|
||||
logger := &mocks.Logger{}
|
||||
mockClient := tt.inner(t)
|
||||
c := &runnerClient{
|
||||
inner: mockClient,
|
||||
}
|
||||
ctx := logging.IntoContext(context.TODO(), mockLogger)
|
||||
ctx := logging.WithLogger(context.TODO(), logger)
|
||||
err := c.Create(ctx, tt.args.obj, tt.args.opts...)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
|
@ -236,7 +210,7 @@ func Test_runnerClient_Create(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
}
|
||||
assert.Equal(t, tt.innerCalls, mockClient.NumCalls())
|
||||
assert.Equal(t, tt.loggerCalls, mockLogger.NumCalls())
|
||||
assert.Equal(t, tt.loggerCalls, logger.NumCalls())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -248,7 +222,6 @@ func Test_runnerClient_Update(t *testing.T) {
|
|||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
logger func(t *testing.T) *tlogging.FakeLogger
|
||||
inner func(t *testing.T) *tclient.FakeClient
|
||||
args args
|
||||
wantErr bool
|
||||
|
@ -256,10 +229,6 @@ func Test_runnerClient_Update(t *testing.T) {
|
|||
loggerCalls int
|
||||
}{{
|
||||
name: "with error",
|
||||
logger: func(t *testing.T) *tlogging.FakeLogger {
|
||||
t.Helper()
|
||||
return &tlogging.FakeLogger{}
|
||||
},
|
||||
inner: func(t *testing.T) *tclient.FakeClient {
|
||||
t.Helper()
|
||||
return &tclient.FakeClient{
|
||||
|
@ -273,14 +242,10 @@ func Test_runnerClient_Update(t *testing.T) {
|
|||
opts: nil,
|
||||
},
|
||||
wantErr: true,
|
||||
loggerCalls: 2,
|
||||
loggerCalls: 1,
|
||||
innerCalls: 1,
|
||||
}, {
|
||||
name: "no error",
|
||||
logger: func(t *testing.T) *tlogging.FakeLogger {
|
||||
t.Helper()
|
||||
return &tlogging.FakeLogger{}
|
||||
},
|
||||
inner: func(t *testing.T) *tclient.FakeClient {
|
||||
t.Helper()
|
||||
return &tclient.FakeClient{
|
||||
|
@ -294,17 +259,17 @@ func Test_runnerClient_Update(t *testing.T) {
|
|||
opts: nil,
|
||||
},
|
||||
wantErr: false,
|
||||
loggerCalls: 2,
|
||||
loggerCalls: 1,
|
||||
innerCalls: 1,
|
||||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
mockLogger := tt.logger(t)
|
||||
logger := &mocks.Logger{}
|
||||
mockClient := tt.inner(t)
|
||||
c := &runnerClient{
|
||||
inner: mockClient,
|
||||
}
|
||||
ctx := logging.IntoContext(context.TODO(), mockLogger)
|
||||
ctx := logging.WithLogger(context.TODO(), logger)
|
||||
err := c.Update(ctx, tt.args.obj, tt.args.opts...)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
|
@ -312,7 +277,7 @@ func Test_runnerClient_Update(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
}
|
||||
assert.Equal(t, tt.innerCalls, mockClient.NumCalls())
|
||||
assert.Equal(t, tt.loggerCalls, mockLogger.NumCalls())
|
||||
assert.Equal(t, tt.loggerCalls, logger.NumCalls())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -324,7 +289,6 @@ func Test_runnerClient_Delete(t *testing.T) {
|
|||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
logger func(t *testing.T) *tlogging.FakeLogger
|
||||
inner func(t *testing.T) *tclient.FakeClient
|
||||
args args
|
||||
wantErr bool
|
||||
|
@ -332,10 +296,6 @@ func Test_runnerClient_Delete(t *testing.T) {
|
|||
loggerCalls int
|
||||
}{{
|
||||
name: "with error",
|
||||
logger: func(t *testing.T) *tlogging.FakeLogger {
|
||||
t.Helper()
|
||||
return &tlogging.FakeLogger{}
|
||||
},
|
||||
inner: func(t *testing.T) *tclient.FakeClient {
|
||||
t.Helper()
|
||||
return &tclient.FakeClient{
|
||||
|
@ -349,14 +309,10 @@ func Test_runnerClient_Delete(t *testing.T) {
|
|||
opts: nil,
|
||||
},
|
||||
wantErr: true,
|
||||
loggerCalls: 2,
|
||||
loggerCalls: 1,
|
||||
innerCalls: 1,
|
||||
}, {
|
||||
name: "no error",
|
||||
logger: func(t *testing.T) *tlogging.FakeLogger {
|
||||
t.Helper()
|
||||
return &tlogging.FakeLogger{}
|
||||
},
|
||||
inner: func(t *testing.T) *tclient.FakeClient {
|
||||
t.Helper()
|
||||
return &tclient.FakeClient{
|
||||
|
@ -370,17 +326,17 @@ func Test_runnerClient_Delete(t *testing.T) {
|
|||
opts: nil,
|
||||
},
|
||||
wantErr: false,
|
||||
loggerCalls: 2,
|
||||
loggerCalls: 1,
|
||||
innerCalls: 1,
|
||||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
mockLogger := tt.logger(t)
|
||||
logger := &mocks.Logger{}
|
||||
mockClient := tt.inner(t)
|
||||
c := &runnerClient{
|
||||
inner: mockClient,
|
||||
}
|
||||
ctx := logging.IntoContext(context.TODO(), mockLogger)
|
||||
ctx := logging.WithLogger(context.TODO(), logger)
|
||||
err := c.Delete(ctx, tt.args.obj, tt.args.opts...)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
|
@ -388,7 +344,7 @@ func Test_runnerClient_Delete(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
}
|
||||
assert.Equal(t, tt.innerCalls, mockClient.NumCalls())
|
||||
assert.Equal(t, tt.loggerCalls, mockLogger.NumCalls())
|
||||
assert.Equal(t, tt.loggerCalls, logger.NumCalls())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -400,7 +356,6 @@ func Test_runnerClient_List(t *testing.T) {
|
|||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
logger func(t *testing.T) *tlogging.FakeLogger
|
||||
inner func(t *testing.T) *tclient.FakeClient
|
||||
args args
|
||||
wantErr bool
|
||||
|
@ -408,10 +363,6 @@ func Test_runnerClient_List(t *testing.T) {
|
|||
loggerCalls int
|
||||
}{{
|
||||
name: "with error",
|
||||
logger: func(t *testing.T) *tlogging.FakeLogger {
|
||||
t.Helper()
|
||||
return &tlogging.FakeLogger{}
|
||||
},
|
||||
inner: func(t *testing.T) *tclient.FakeClient {
|
||||
t.Helper()
|
||||
return &tclient.FakeClient{
|
||||
|
@ -429,10 +380,6 @@ func Test_runnerClient_List(t *testing.T) {
|
|||
innerCalls: 1,
|
||||
}, {
|
||||
name: "no error",
|
||||
logger: func(t *testing.T) *tlogging.FakeLogger {
|
||||
t.Helper()
|
||||
return &tlogging.FakeLogger{}
|
||||
},
|
||||
inner: func(t *testing.T) *tclient.FakeClient {
|
||||
t.Helper()
|
||||
return &tclient.FakeClient{
|
||||
|
@ -451,12 +398,12 @@ func Test_runnerClient_List(t *testing.T) {
|
|||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
mockLogger := tt.logger(t)
|
||||
logger := &mocks.Logger{}
|
||||
mockClient := tt.inner(t)
|
||||
c := &runnerClient{
|
||||
inner: mockClient,
|
||||
}
|
||||
ctx := logging.IntoContext(context.TODO(), mockLogger)
|
||||
ctx := logging.WithLogger(context.TODO(), logger)
|
||||
err := c.List(ctx, tt.args.obj, tt.args.opts...)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
|
@ -464,7 +411,7 @@ func Test_runnerClient_List(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
}
|
||||
assert.Equal(t, tt.innerCalls, mockClient.NumCalls())
|
||||
assert.Equal(t, tt.loggerCalls, mockLogger.NumCalls())
|
||||
assert.Equal(t, tt.loggerCalls, logger.NumCalls())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -477,7 +424,6 @@ func Test_runnerClient_Patch(t *testing.T) {
|
|||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
logger func(t *testing.T) *tlogging.FakeLogger
|
||||
inner func(t *testing.T) *tclient.FakeClient
|
||||
args args
|
||||
wantErr bool
|
||||
|
@ -485,10 +431,6 @@ func Test_runnerClient_Patch(t *testing.T) {
|
|||
loggerCalls int
|
||||
}{{
|
||||
name: "with error",
|
||||
logger: func(t *testing.T) *tlogging.FakeLogger {
|
||||
t.Helper()
|
||||
return &tlogging.FakeLogger{}
|
||||
},
|
||||
inner: func(t *testing.T) *tclient.FakeClient {
|
||||
t.Helper()
|
||||
return &tclient.FakeClient{
|
||||
|
@ -502,14 +444,10 @@ func Test_runnerClient_Patch(t *testing.T) {
|
|||
opts: nil,
|
||||
},
|
||||
wantErr: true,
|
||||
loggerCalls: 2,
|
||||
loggerCalls: 1,
|
||||
innerCalls: 1,
|
||||
}, {
|
||||
name: "no error",
|
||||
logger: func(t *testing.T) *tlogging.FakeLogger {
|
||||
t.Helper()
|
||||
return &tlogging.FakeLogger{}
|
||||
},
|
||||
inner: func(t *testing.T) *tclient.FakeClient {
|
||||
t.Helper()
|
||||
return &tclient.FakeClient{
|
||||
|
@ -523,17 +461,17 @@ func Test_runnerClient_Patch(t *testing.T) {
|
|||
opts: nil,
|
||||
},
|
||||
wantErr: false,
|
||||
loggerCalls: 2,
|
||||
loggerCalls: 1,
|
||||
innerCalls: 1,
|
||||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
mockLogger := tt.logger(t)
|
||||
logger := &mocks.Logger{}
|
||||
mockClient := tt.inner(t)
|
||||
c := &runnerClient{
|
||||
inner: mockClient,
|
||||
}
|
||||
ctx := logging.IntoContext(context.TODO(), mockLogger)
|
||||
ctx := logging.WithLogger(context.TODO(), logger)
|
||||
err := c.Patch(ctx, tt.args.obj, tt.args.patch, tt.args.opts...)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
|
@ -541,7 +479,7 @@ func Test_runnerClient_Patch(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
}
|
||||
assert.Equal(t, tt.innerCalls, mockClient.NumCalls())
|
||||
assert.Equal(t, tt.loggerCalls, mockLogger.NumCalls())
|
||||
assert.Equal(t, tt.loggerCalls, logger.NumCalls())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -552,7 +490,6 @@ func Test_runnerClient_IsObjectNamespaced(t *testing.T) {
|
|||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
logger func(t *testing.T) *tlogging.FakeLogger
|
||||
inner func(t *testing.T) *tclient.FakeClient
|
||||
args args
|
||||
want bool
|
||||
|
@ -560,10 +497,6 @@ func Test_runnerClient_IsObjectNamespaced(t *testing.T) {
|
|||
innerCalls int
|
||||
}{{
|
||||
name: "with error",
|
||||
logger: func(t *testing.T) *tlogging.FakeLogger {
|
||||
t.Helper()
|
||||
return &tlogging.FakeLogger{}
|
||||
},
|
||||
inner: func(t *testing.T) *tclient.FakeClient {
|
||||
t.Helper()
|
||||
return &tclient.FakeClient{
|
||||
|
@ -579,10 +512,6 @@ func Test_runnerClient_IsObjectNamespaced(t *testing.T) {
|
|||
innerCalls: 1,
|
||||
}, {
|
||||
name: "no error - false",
|
||||
logger: func(t *testing.T) *tlogging.FakeLogger {
|
||||
t.Helper()
|
||||
return &tlogging.FakeLogger{}
|
||||
},
|
||||
inner: func(t *testing.T) *tclient.FakeClient {
|
||||
t.Helper()
|
||||
return &tclient.FakeClient{
|
||||
|
@ -599,10 +528,6 @@ func Test_runnerClient_IsObjectNamespaced(t *testing.T) {
|
|||
innerCalls: 1,
|
||||
}, {
|
||||
name: "no error - true",
|
||||
logger: func(t *testing.T) *tlogging.FakeLogger {
|
||||
t.Helper()
|
||||
return &tlogging.FakeLogger{}
|
||||
},
|
||||
inner: func(t *testing.T) *tclient.FakeClient {
|
||||
t.Helper()
|
||||
return &tclient.FakeClient{
|
||||
|
|
|
@ -16,10 +16,10 @@ type fromConfig struct {
|
|||
config *rest.Config
|
||||
}
|
||||
|
||||
func NewClusterFromConfig(config *rest.Config) (Cluster, error) {
|
||||
func NewClusterFromConfig(config *rest.Config) Cluster {
|
||||
return &fromConfig{
|
||||
config: config,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *fromConfig) Config() (*rest.Config, error) {
|
||||
|
|
|
@ -9,10 +9,9 @@ import (
|
|||
|
||||
func TestNewClusterFromConfig(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
config *rest.Config
|
||||
want Cluster
|
||||
wantErr bool
|
||||
name string
|
||||
config *rest.Config
|
||||
want Cluster
|
||||
}{{
|
||||
name: "nil",
|
||||
want: &fromConfig{
|
||||
|
@ -27,17 +26,11 @@ func TestNewClusterFromConfig(t *testing.T) {
|
|||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := NewClusterFromConfig(tt.config)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, got)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.want, got)
|
||||
got, err := got.Config()
|
||||
assert.NoError(t, err)
|
||||
assert.Same(t, tt.config, got)
|
||||
}
|
||||
got := NewClusterFromConfig(tt.config)
|
||||
assert.Equal(t, tt.want, got)
|
||||
config, err := got.Config()
|
||||
assert.NoError(t, err)
|
||||
assert.Same(t, tt.config, config)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
package engine
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/kyverno/chainsaw/pkg/apis/v1alpha1"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/bindings"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/clusters"
|
||||
)
|
||||
|
||||
func WithBindings(ctx context.Context, tc Context, variables ...v1alpha1.Binding) (Context, error) {
|
||||
for _, variable := range variables {
|
||||
name, value, err := bindings.ResolveBinding(ctx, tc.Compilers(), tc.Bindings(), nil, variable)
|
||||
if err != nil {
|
||||
return tc, err
|
||||
}
|
||||
tc = tc.WithBinding(ctx, name, value)
|
||||
}
|
||||
return tc, nil
|
||||
}
|
||||
|
||||
func WithClusters(ctx context.Context, tc Context, basePath string, c map[string]v1alpha1.Cluster) Context {
|
||||
for name, cluster := range c {
|
||||
kubeconfig := filepath.Join(basePath, cluster.Kubeconfig)
|
||||
cluster := clusters.NewClusterFromKubeconfig(kubeconfig, cluster.Context)
|
||||
tc = tc.WithCluster(ctx, name, cluster)
|
||||
}
|
||||
return tc
|
||||
}
|
||||
|
||||
func WithCurrentCluster(ctx context.Context, tc Context, name string) (Context, error) {
|
||||
tc = tc.WithCurrentCluster(ctx, name)
|
||||
config, client, err := tc.CurrentClusterClient()
|
||||
if err != nil {
|
||||
return tc, err
|
||||
}
|
||||
tc = tc.WithBinding(ctx, "client", client)
|
||||
tc = tc.WithBinding(ctx, "config", config)
|
||||
return tc, nil
|
||||
}
|
||||
|
||||
func WithNamespace(ctx context.Context, tc Context, namespace string) Context {
|
||||
return tc.WithBinding(ctx, "namespace", namespace)
|
||||
}
|
||||
|
||||
func WithValues(ctx context.Context, tc Context, values any) Context {
|
||||
return tc.WithBinding(ctx, "values", values)
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
package context
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/kyverno/chainsaw/pkg/apis"
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
"github.com/kyverno/chainsaw/pkg/client/dryrun"
|
||||
apibindings "github.com/kyverno/chainsaw/pkg/engine/bindings"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/clusters"
|
||||
"github.com/kyverno/chainsaw/pkg/model"
|
||||
"github.com/kyverno/kyverno-json/pkg/core/compilers"
|
||||
"k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
type TestContext struct {
|
||||
*model.Summary
|
||||
*model.Report
|
||||
bindings apis.Bindings
|
||||
compilers compilers.Compilers
|
||||
cluster clusters.Cluster
|
||||
clusters clusters.Registry
|
||||
dryRun bool
|
||||
}
|
||||
|
||||
func MakeContext(bindings apis.Bindings, registry clusters.Registry) TestContext {
|
||||
return TestContext{
|
||||
Summary: &model.Summary{},
|
||||
Report: &model.Report{
|
||||
Name: "chainsaw-report",
|
||||
StartTime: time.Now(),
|
||||
},
|
||||
bindings: bindings,
|
||||
compilers: apis.DefaultCompilers,
|
||||
clusters: registry,
|
||||
cluster: nil,
|
||||
}
|
||||
}
|
||||
|
||||
func EmptyContext() TestContext {
|
||||
return MakeContext(apis.NewBindings(), clusters.NewRegistry(nil))
|
||||
}
|
||||
|
||||
func (tc *TestContext) Bindings() apis.Bindings {
|
||||
return tc.bindings
|
||||
}
|
||||
|
||||
func (tc *TestContext) Compilers() compilers.Compilers {
|
||||
return tc.compilers
|
||||
}
|
||||
|
||||
func (tc *TestContext) Cluster(name string) clusters.Cluster {
|
||||
return tc.clusters.Lookup(name)
|
||||
}
|
||||
|
||||
func (tc *TestContext) Clusters() clusters.Registry {
|
||||
return tc.clusters
|
||||
}
|
||||
|
||||
func (tc *TestContext) CurrentCluster() clusters.Cluster {
|
||||
return tc.cluster
|
||||
}
|
||||
|
||||
func (tc *TestContext) CurrentClusterClient() (*rest.Config, client.Client, error) {
|
||||
config, client, err := tc.clusters.Build(tc.cluster)
|
||||
if err == nil && client != nil && tc.DryRun() {
|
||||
client = dryrun.New(client)
|
||||
}
|
||||
return config, client, err
|
||||
}
|
||||
|
||||
func (tc *TestContext) DryRun() bool {
|
||||
return tc.dryRun
|
||||
}
|
||||
|
||||
func (tc TestContext) WithBinding(ctx context.Context, name string, value any) TestContext {
|
||||
tc.bindings = apibindings.RegisterBinding(ctx, tc.bindings, name, value)
|
||||
return tc
|
||||
}
|
||||
|
||||
func (tc TestContext) WithDefaultCompiler(name string) TestContext {
|
||||
tc.compilers = tc.compilers.WithDefaultCompiler(name)
|
||||
return tc
|
||||
}
|
||||
|
||||
func (tc TestContext) WithCluster(ctx context.Context, name string, cluster clusters.Cluster) TestContext {
|
||||
tc.clusters = tc.clusters.Register(name, cluster)
|
||||
return tc
|
||||
}
|
||||
|
||||
func (tc TestContext) WithCurrentCluster(ctx context.Context, name string) TestContext {
|
||||
tc.cluster = tc.Cluster(name)
|
||||
return tc
|
||||
}
|
||||
|
||||
func (tc TestContext) WithDryRun(ctx context.Context, dryRun bool) TestContext {
|
||||
tc.dryRun = dryRun
|
||||
return tc
|
||||
}
|
|
@ -13,6 +13,12 @@ import (
|
|||
"k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
// jpKubernetesResourceExists is a JMESPath function that checks if a Kubernetes resource type exists in the cluster.
|
||||
// Arguments:
|
||||
// - client: The Kubernetes client
|
||||
// - apiVersion: API version of the resource (e.g., "v1", "apps/v1")
|
||||
// - kind: Kind of the resource (e.g., "Pod", "Deployment")
|
||||
// Returns true if the resource type exists, false otherwise.
|
||||
func jpKubernetesResourceExists(arguments []any) (any, error) {
|
||||
var client client.Client
|
||||
var apiVersion, kind string
|
||||
|
@ -40,6 +46,14 @@ func jpKubernetesResourceExists(arguments []any) (any, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// jpKubernetesExists is a JMESPath function that checks if a specific Kubernetes resource exists in the cluster.
|
||||
// Arguments:
|
||||
// - client: The Kubernetes client
|
||||
// - apiVersion: API version of the resource (e.g., "v1", "apps/v1")
|
||||
// - kind: Kind of the resource (e.g., "Pod", "Deployment")
|
||||
// - namespace: Namespace of the resource
|
||||
// - name: Name of the resource
|
||||
// Returns true if the specific resource exists, false otherwise.
|
||||
func jpKubernetesExists(arguments []any) (any, error) {
|
||||
var apiVersion, kind string
|
||||
var key client.ObjectKey
|
||||
|
@ -72,6 +86,14 @@ func jpKubernetesExists(arguments []any) (any, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// jpKubernetesGet is a JMESPath function that retrieves a specific Kubernetes resource from the cluster.
|
||||
// Arguments:
|
||||
// - client: The Kubernetes client
|
||||
// - apiVersion: API version of the resource (e.g., "v1", "apps/v1")
|
||||
// - kind: Kind of the resource (e.g., "Pod", "Deployment")
|
||||
// - namespace: Namespace of the resource
|
||||
// - name: Name of the resource
|
||||
// Returns the resource as an unstructured object if found, error otherwise.
|
||||
func jpKubernetesGet(arguments []any) (any, error) {
|
||||
var apiVersion, kind string
|
||||
var key client.ObjectKey
|
||||
|
@ -100,6 +122,13 @@ func jpKubernetesGet(arguments []any) (any, error) {
|
|||
return obj.UnstructuredContent(), nil
|
||||
}
|
||||
|
||||
// jpKubernetesList is a JMESPath function that lists Kubernetes resources of a specific type from the cluster.
|
||||
// Arguments:
|
||||
// - client: The Kubernetes client
|
||||
// - apiVersion: API version of the resource (e.g., "v1", "apps/v1")
|
||||
// - kind: Kind of the resource (e.g., "Pod", "Deployment")
|
||||
// - namespace: (Optional) Namespace to filter resources by
|
||||
// Returns a list of resources as an unstructured object.
|
||||
func jpKubernetesList(arguments []any) (any, error) {
|
||||
var c client.Client
|
||||
var apiVersion, kind, namespace string
|
||||
|
@ -130,6 +159,10 @@ func jpKubernetesList(arguments []any) (any, error) {
|
|||
return list.UnstructuredContent(), nil
|
||||
}
|
||||
|
||||
// jpKubernetesServerVersion is a JMESPath function that retrieves the Kubernetes server version.
|
||||
// Arguments:
|
||||
// - config: The Kubernetes REST config
|
||||
// Returns the server version information.
|
||||
func jpKubernetesServerVersion(arguments []any) (any, error) {
|
||||
var config *rest.Config
|
||||
if err := getArg(arguments, 0, &config); err != nil {
|
||||
|
|
|
@ -5,14 +5,20 @@ import (
|
|||
"fmt"
|
||||
)
|
||||
|
||||
// stable is a utility function that returns the function name as-is.
|
||||
// Used for stable, non-experimental JMESPath functions.
|
||||
func stable(in string) string {
|
||||
return in
|
||||
}
|
||||
|
||||
// experimental is a utility function that prefixes the function name with "x_".
|
||||
// Used for experimental JMESPath functions that may change in future versions.
|
||||
func experimental(in string) string {
|
||||
return "x_" + in
|
||||
}
|
||||
|
||||
// getArgAt retrieves an argument at the specified index from the arguments slice.
|
||||
// Returns an error if the index is out of range.
|
||||
func getArgAt(arguments []any, index int) (any, error) {
|
||||
if index >= len(arguments) {
|
||||
return nil, fmt.Errorf("index out of range (%d / %d)", index, len(arguments))
|
||||
|
@ -20,6 +26,12 @@ func getArgAt(arguments []any, index int) (any, error) {
|
|||
return arguments[index], nil
|
||||
}
|
||||
|
||||
// getArg is a generic function that retrieves and type-asserts an argument at the specified index.
|
||||
// Arguments:
|
||||
// - arguments: The slice of arguments to retrieve from
|
||||
// - index: The index of the argument to retrieve
|
||||
// - out: A pointer to store the retrieved value
|
||||
// Returns an error if the index is out of range or if the type assertion fails.
|
||||
func getArg[T any](arguments []any, index int, out *T) error {
|
||||
arg, err := getArgAt(arguments, index)
|
||||
if err != nil {
|
||||
|
|
|
@ -39,18 +39,18 @@ func Wait(ctx context.Context, compilers compilers.Compilers, client client.Clie
|
|||
return "", nil, err
|
||||
}
|
||||
args := []string{"wait", resource}
|
||||
if collector.WaitFor.Deletion != nil {
|
||||
if collector.Deletion != nil {
|
||||
args = append(args, "--for=delete")
|
||||
} else if collector.WaitFor.Condition != nil {
|
||||
name, err := collector.WaitFor.Condition.Name.Value(ctx, compilers, tc)
|
||||
} else if collector.Condition != nil {
|
||||
name, err := collector.Condition.Name.Value(ctx, compilers, tc)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if name == "" {
|
||||
return "", nil, errors.New("a condition name must be specified for condition wait type")
|
||||
}
|
||||
if collector.WaitFor.Condition.Value != nil {
|
||||
value, err := collector.WaitFor.Condition.Value.Value(ctx, compilers, tc)
|
||||
if collector.Condition.Value != nil {
|
||||
value, err := collector.Condition.Value.Value(ctx, compilers, tc)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
@ -58,16 +58,16 @@ func Wait(ctx context.Context, compilers compilers.Compilers, client client.Clie
|
|||
} else {
|
||||
args = append(args, fmt.Sprintf("--for=condition=%s", name))
|
||||
}
|
||||
} else if collector.WaitFor.JsonPath != nil {
|
||||
path, err := collector.WaitFor.JsonPath.Path.Value(ctx, compilers, tc)
|
||||
} else if collector.JsonPath != nil {
|
||||
path, err := collector.JsonPath.Path.Value(ctx, compilers, tc)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if path == "" {
|
||||
return "", nil, errors.New("a path must be specified for jsonpath wait type")
|
||||
}
|
||||
if collector.WaitFor.JsonPath.Value != nil {
|
||||
value, err := collector.WaitFor.JsonPath.Value.Value(ctx, compilers, tc)
|
||||
if collector.JsonPath.Value != nil {
|
||||
value, err := collector.JsonPath.Value.Value(ctx, compilers, tc)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package logging
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type contextKey struct{}
|
||||
|
||||
func FromContext(ctx context.Context) Logger {
|
||||
if ctx != nil {
|
||||
if v, ok := ctx.Value(contextKey{}).(Logger); ok {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func IntoContext(ctx context.Context, logger Logger) context.Context {
|
||||
return context.WithValue(ctx, contextKey{}, logger)
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package logging
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
"github.com/kyverno/pkg/ext/output/color"
|
||||
"k8s.io/utils/clock"
|
||||
)
|
||||
|
||||
const eraser = "\b\b\b\b\b\b\b\b\b"
|
||||
|
||||
type logger struct {
|
||||
t TLogger
|
||||
clock clock.PassiveClock
|
||||
test string
|
||||
step string
|
||||
resource client.Object
|
||||
}
|
||||
|
||||
func NewLogger(t TLogger, clock clock.PassiveClock, test string, step string) Logger {
|
||||
t.Helper()
|
||||
return &logger{
|
||||
t: t,
|
||||
clock: clock,
|
||||
test: test,
|
||||
step: step,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *logger) Log(operation Operation, status Status, color *color.Color, args ...fmt.Stringer) {
|
||||
sprint := fmt.Sprint
|
||||
opLen := 9
|
||||
stLen := 5
|
||||
if color != nil {
|
||||
sprint = color.Sprint
|
||||
opLen += 14
|
||||
stLen += 14
|
||||
}
|
||||
a := make([]any, 0, len(args)+2)
|
||||
prefix := fmt.Sprintf("%s| %s | %s | %s | %-*s | %-*s |", eraser, l.clock.Now().Format("15:04:05"), sprint(l.test), sprint(l.step), opLen, sprint(operation), stLen, sprint(status))
|
||||
if l.resource != nil {
|
||||
gvk := l.resource.GetObjectKind().GroupVersionKind()
|
||||
key := client.Key(l.resource)
|
||||
prefix = fmt.Sprintf("%s %s/%s @ %s", prefix, gvk.GroupVersion(), gvk.Kind, client.Name(key))
|
||||
}
|
||||
a = append(a, prefix)
|
||||
for _, arg := range args {
|
||||
a = append(a, "\n")
|
||||
a = append(a, arg)
|
||||
}
|
||||
l.t.Log(fmt.Sprint(a...))
|
||||
}
|
||||
|
||||
func (l *logger) WithResource(resource client.Object) Logger {
|
||||
return &logger{
|
||||
t: l.t,
|
||||
clock: l.clock,
|
||||
test: l.test,
|
||||
step: l.step,
|
||||
resource: resource,
|
||||
}
|
||||
}
|
|
@ -1,157 +0,0 @@
|
|||
package logging
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
tlogging "github.com/kyverno/chainsaw/pkg/engine/logging/testing"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
tclock "k8s.io/utils/clock/testing"
|
||||
)
|
||||
|
||||
func TestNewLogger(t *testing.T) {
|
||||
fakeClock := tclock.NewFakePassiveClock(time.Now())
|
||||
testName := "testName"
|
||||
stepName := "stepName"
|
||||
logger, ok := NewLogger(t, fakeClock, testName, stepName).(*logger)
|
||||
|
||||
assert.True(t, ok, "Type assertion for *logger failed")
|
||||
|
||||
assert.Equal(t, t, logger.t)
|
||||
assert.Equal(t, fakeClock, logger.clock)
|
||||
assert.Equal(t, testName, logger.test)
|
||||
assert.Equal(t, stepName, logger.step)
|
||||
assert.Nil(t, logger.resource)
|
||||
}
|
||||
|
||||
type s string
|
||||
|
||||
func (v s) String() string { return string(v) }
|
||||
|
||||
func Test_logger_Log(t *testing.T) {
|
||||
fakeClock := tclock.NewFakePassiveClock(time.Now())
|
||||
mockT := &tlogging.FakeTLogger{}
|
||||
fakeLogger := NewLogger(mockT, fakeClock, "testName", "stepName").(*logger)
|
||||
disabled := color.New(color.FgBlue)
|
||||
disabled.DisableColor()
|
||||
enabled := color.New(color.FgBlue)
|
||||
enabled.EnableColor()
|
||||
testCases := []struct {
|
||||
name string
|
||||
resource client.Object
|
||||
operation string
|
||||
status string
|
||||
color *color.Color
|
||||
args []fmt.Stringer
|
||||
expectContains []string
|
||||
}{
|
||||
{
|
||||
name: "without resource",
|
||||
resource: nil,
|
||||
operation: "OPERATION",
|
||||
status: "STATUS",
|
||||
args: []fmt.Stringer{s("arg1"), s("arg2")},
|
||||
expectContains: []string{
|
||||
"testName", "stepName", "OPERATION", "arg1", "arg2",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "with color",
|
||||
resource: nil,
|
||||
operation: "OPERATION",
|
||||
status: "STATUS",
|
||||
color: enabled,
|
||||
args: []fmt.Stringer{s("arg1"), s("arg2")},
|
||||
expectContains: []string{
|
||||
"testName", "stepName", "OPERATION", "arg1", "arg2",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "with resource",
|
||||
resource: func() client.Object {
|
||||
var r unstructured.Unstructured
|
||||
r.SetName("testResource")
|
||||
r.SetNamespace("default")
|
||||
r.SetAPIVersion("testGroup/v1")
|
||||
r.SetKind("testKind")
|
||||
return &r
|
||||
}(),
|
||||
operation: "OPERATION",
|
||||
status: "STATUS",
|
||||
args: []fmt.Stringer{s("arg1"), s("arg2")},
|
||||
expectContains: []string{
|
||||
"testName", "stepName", "OPERATION", "default/testResource", "testGroup/v1/testKind", "arg1", "arg2",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range testCases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.resource != nil {
|
||||
fakeLogger = fakeLogger.WithResource(tt.resource).(*logger)
|
||||
}
|
||||
fakeLogger.Log(Operation(tt.operation), Status(tt.status), tt.color, tt.args...)
|
||||
for _, exp := range tt.expectContains {
|
||||
found := false
|
||||
for _, msg := range mockT.Messages {
|
||||
if strings.Contains(msg, exp) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.True(t, found, "Expected to find '%s' in logs, but didn't. Logs: %v", exp, mockT.Messages)
|
||||
}
|
||||
mockT.Messages = []string{}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_logger_WithResource(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
resource client.Object
|
||||
expectNil bool
|
||||
}{{
|
||||
name: "Valid Resource",
|
||||
resource: func() client.Object {
|
||||
var r unstructured.Unstructured
|
||||
r.SetName("testResource")
|
||||
return &r
|
||||
}(),
|
||||
expectNil: false,
|
||||
}, {
|
||||
name: "Nil Resource",
|
||||
resource: nil,
|
||||
expectNil: true,
|
||||
}}
|
||||
for _, tt := range testCases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
fakeClock := tclock.NewFakePassiveClock(time.Now())
|
||||
fakeLogger := logger{
|
||||
t: t,
|
||||
clock: fakeClock,
|
||||
test: "testName",
|
||||
step: "stepName",
|
||||
}
|
||||
|
||||
newLogger := fakeLogger.WithResource(tt.resource).(*logger)
|
||||
|
||||
if tt.expectNil {
|
||||
assert.Nil(t, newLogger.resource, "Expected resource to be nil in the logger")
|
||||
} else {
|
||||
assert.NotNil(t, newLogger.resource, "Expected resource to not be nil in the logger")
|
||||
assert.Equal(t, tt.resource, newLogger.resource, "Expected correct resource to be set in the logger")
|
||||
}
|
||||
|
||||
assert.Equal(t, fakeLogger.t, newLogger.t, "Expected testing.T to remain the same")
|
||||
assert.Equal(t, fakeLogger.clock, newLogger.clock, "Expected clock to remain the same")
|
||||
assert.Equal(t, fakeLogger.test, newLogger.test, "Expected test name to remain the same")
|
||||
assert.Equal(t, fakeLogger.step, newLogger.step, "Expected step name to remain the same")
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package logging
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/kyverno/pkg/ext/output/color"
|
||||
)
|
||||
|
||||
func Log(ctx context.Context, operation Operation, status Status, color *color.Color, args ...fmt.Stringer) {
|
||||
logger := FromContext(ctx)
|
||||
if logger != nil {
|
||||
logger.Log(operation, status, color, args...)
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package logging
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
tlogging "github.com/kyverno/chainsaw/pkg/engine/logging/testing"
|
||||
"github.com/kyverno/pkg/ext/output/color"
|
||||
tclock "k8s.io/utils/clock/testing"
|
||||
)
|
||||
|
||||
func TestLog(t *testing.T) {
|
||||
fakeClock := tclock.NewFakePassiveClock(time.Now())
|
||||
mockT := &tlogging.FakeTLogger{}
|
||||
fakeLogger := NewLogger(mockT, fakeClock, "testName", "stepName").(*logger)
|
||||
tests := []struct {
|
||||
name string
|
||||
ctx context.Context //nolint:containedctx
|
||||
operation string
|
||||
status string
|
||||
color *color.Color
|
||||
args []fmt.Stringer
|
||||
}{{
|
||||
name: "background",
|
||||
ctx: context.Background(),
|
||||
operation: "foo",
|
||||
status: "bar",
|
||||
color: nil,
|
||||
args: nil,
|
||||
}, {
|
||||
name: "nil",
|
||||
ctx: nil,
|
||||
operation: "foo",
|
||||
status: "bar",
|
||||
color: nil,
|
||||
args: nil,
|
||||
}, {
|
||||
name: "with logger",
|
||||
ctx: IntoContext(context.Background(), fakeLogger),
|
||||
operation: "foo",
|
||||
status: "bar",
|
||||
color: nil,
|
||||
args: nil,
|
||||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
Log(tt.ctx, Operation(tt.operation), Status(tt.status), tt.color, tt.args...)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package logging
|
||||
|
||||
import (
|
||||
tlogging "github.com/kyverno/chainsaw/pkg/engine/logging/testing"
|
||||
)
|
||||
|
||||
type (
|
||||
Logger = tlogging.Logger
|
||||
Operation = tlogging.Operation
|
||||
Status = tlogging.Status
|
||||
)
|
||||
|
||||
const (
|
||||
Apply Operation = "APPLY"
|
||||
Assert Operation = "ASSERT"
|
||||
Catch Operation = "CATCH"
|
||||
Cleanup Operation = "CLEANUP"
|
||||
Command Operation = "CMD"
|
||||
Create Operation = "CREATE"
|
||||
Delete Operation = "DELETE"
|
||||
Error Operation = "ERROR"
|
||||
Finally Operation = "FINALLY"
|
||||
Get Operation = "GET"
|
||||
Internal Operation = "INTERNAL"
|
||||
Patch Operation = "PATCH"
|
||||
Script Operation = "SCRIPT"
|
||||
Sleep Operation = "SLEEP"
|
||||
Stderr Operation = "STDERR"
|
||||
Stdout Operation = "STDOUT"
|
||||
Try Operation = "TRY"
|
||||
Update Operation = "UPDATE"
|
||||
)
|
||||
|
||||
const (
|
||||
BeginStatus Status = "BEGIN"
|
||||
DoneStatus Status = "DONE"
|
||||
EndStatus Status = "END"
|
||||
ErrorStatus Status = "ERROR"
|
||||
LogStatus Status = "LOG"
|
||||
OkStatus Status = "OK"
|
||||
RunStatus Status = "RUN"
|
||||
WarnStatus Status = "WARN"
|
||||
// DoneStatus Status = "✅"
|
||||
// ErrorStatus Status = "❌"
|
||||
// LogStatus Status = "📄"
|
||||
// OkStatus Status = "🟢"
|
||||
// RunStatus Status = "🚧"
|
||||
// WarnStatus Status = "🟡"
|
||||
)
|
|
@ -1,6 +0,0 @@
|
|||
package logging
|
||||
|
||||
type TLogger interface {
|
||||
Log(args ...any)
|
||||
Helper()
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package testing
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
)
|
||||
|
||||
// TODO: not thread safe
|
||||
type FakeLogger struct {
|
||||
Logs []string
|
||||
numCalls int
|
||||
}
|
||||
|
||||
func (f *FakeLogger) WithResource(resource client.Object) Logger {
|
||||
defer func() { f.numCalls++ }()
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *FakeLogger) Log(operation Operation, status Status, color *color.Color, args ...fmt.Stringer) {
|
||||
defer func() { f.numCalls++ }()
|
||||
message := fmt.Sprintf("%s: %s - %v", operation, status, args)
|
||||
f.Logs = append(f.Logs, message)
|
||||
}
|
||||
|
||||
func (f *FakeLogger) NumCalls() int {
|
||||
return f.numCalls
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package testing
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type FakeTLogger struct {
|
||||
Messages []string
|
||||
}
|
||||
|
||||
func (tl *FakeTLogger) Log(args ...any) {
|
||||
for _, arg := range args {
|
||||
tl.Messages = append(tl.Messages, fmt.Sprint(arg))
|
||||
}
|
||||
}
|
||||
|
||||
func (tl *FakeTLogger) Helper() {}
|
|
@ -1,18 +0,0 @@
|
|||
package testing
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
)
|
||||
|
||||
type (
|
||||
Operation string
|
||||
Status string
|
||||
)
|
||||
|
||||
type Logger interface {
|
||||
Log(Operation, Status, *color.Color, ...fmt.Stringer)
|
||||
WithResource(client.Object) Logger
|
||||
}
|
|
@ -9,12 +9,12 @@ import (
|
|||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
bindings "github.com/kyverno/chainsaw/pkg/engine/bindings"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/checks"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/namespacer"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations/internal"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/outputs"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/templating"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/kyverno-json/pkg/core/compilers"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
|
@ -61,9 +61,8 @@ func (o *operation) Exec(ctx context.Context, tc apis.Bindings) (_ outputs.Outpu
|
|||
tc = apis.NewBindings()
|
||||
}
|
||||
obj := o.base
|
||||
logger := internal.GetLogger(ctx, &obj)
|
||||
defer func() {
|
||||
internal.LogEnd(logger, logging.Apply, _err)
|
||||
internal.LogEnd(ctx, logging.Apply, &obj, _err)
|
||||
}()
|
||||
if o.template {
|
||||
template := v1alpha1.NewProjection(obj.UnstructuredContent())
|
||||
|
@ -76,7 +75,7 @@ func (o *operation) Exec(ctx context.Context, tc apis.Bindings) (_ outputs.Outpu
|
|||
if err := internal.ApplyNamespacer(o.namespacer, o.client, &obj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
internal.LogStart(logger, logging.Apply)
|
||||
internal.LogStart(ctx, logging.Apply, &obj)
|
||||
return o.execute(ctx, tc, obj)
|
||||
}
|
||||
|
||||
|
@ -132,9 +131,9 @@ func (o *operation) createResource(ctx context.Context, tc apis.Bindings, obj un
|
|||
|
||||
func (o *operation) handleCheck(ctx context.Context, tc apis.Bindings, obj unstructured.Unstructured, err error) (_outputs outputs.Outputs, _err error) {
|
||||
if err == nil {
|
||||
tc = bindings.RegisterBinding(ctx, tc, "error", nil)
|
||||
tc = bindings.RegisterBinding(tc, "error", nil)
|
||||
} else {
|
||||
tc = bindings.RegisterBinding(ctx, tc, "error", err.Error())
|
||||
tc = bindings.RegisterBinding(tc, "error", err.Error())
|
||||
}
|
||||
defer func(tc apis.Bindings) {
|
||||
if _err == nil {
|
||||
|
|
|
@ -10,8 +10,8 @@ import (
|
|||
"github.com/kyverno/chainsaw/pkg/apis/v1alpha1"
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
tclient "github.com/kyverno/chainsaw/pkg/client/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
tlogging "github.com/kyverno/chainsaw/pkg/engine/logging/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/mocks"
|
||||
"github.com/stretchr/testify/assert"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
|
@ -286,8 +286,8 @@ func Test_apply(t *testing.T) {
|
|||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
logger := &tlogging.FakeLogger{}
|
||||
ctx := logging.IntoContext(context.TODO(), logger)
|
||||
logger := &mocks.Logger{}
|
||||
ctx := logging.WithLogger(context.TODO(), logger)
|
||||
toCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
ctx = toCtx
|
||||
|
|
|
@ -8,13 +8,13 @@ import (
|
|||
"github.com/kyverno/chainsaw/pkg/apis/v1alpha1"
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/checks"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/namespacer"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations"
|
||||
operrors "github.com/kyverno/chainsaw/pkg/engine/operations/errors"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations/internal"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/outputs"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/templating"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/kyverno-json/pkg/core/compilers"
|
||||
"go.uber.org/multierr"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
|
@ -52,9 +52,8 @@ func (o *operation) Exec(ctx context.Context, bindings apis.Bindings) (_ outputs
|
|||
bindings = apis.NewBindings()
|
||||
}
|
||||
obj := o.base
|
||||
logger := internal.GetLogger(ctx, &obj)
|
||||
defer func() {
|
||||
internal.LogEnd(logger, logging.Assert, _err)
|
||||
internal.LogEnd(ctx, logging.Assert, &obj, _err)
|
||||
}()
|
||||
if o.template {
|
||||
if err := templating.ResourceRef(ctx, o.compilers, &obj, bindings); err != nil {
|
||||
|
@ -66,7 +65,7 @@ func (o *operation) Exec(ctx context.Context, bindings apis.Bindings) (_ outputs
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
internal.LogStart(logger, logging.Assert)
|
||||
internal.LogStart(ctx, logging.Assert, &obj)
|
||||
return nil, o.execute(ctx, bindings, obj)
|
||||
}
|
||||
|
||||
|
|
|
@ -9,11 +9,10 @@ import (
|
|||
"github.com/kyverno/chainsaw/pkg/apis"
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
tclient "github.com/kyverno/chainsaw/pkg/client/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
tlogging "github.com/kyverno/chainsaw/pkg/engine/logging/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/namespacer"
|
||||
tnamespacer "github.com/kyverno/chainsaw/pkg/engine/namespacer/testing"
|
||||
ttesting "github.com/kyverno/chainsaw/pkg/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/mocks"
|
||||
"github.com/stretchr/testify/assert"
|
||||
kerror "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
|
@ -282,7 +281,6 @@ func Test_operationAssert(t *testing.T) {
|
|||
},
|
||||
client: &tclient.FakeClient{
|
||||
ListFn: func(ctx context.Context, _ int, list client.ObjectList, opts ...client.ListOption) error {
|
||||
t := ttesting.FromContext(ctx)
|
||||
assert.Contains(t, opts, client.InNamespace("bar"))
|
||||
uList := list.(*unstructured.UnstructuredList)
|
||||
uList.Items = append(uList.Items, unstructured.Unstructured{
|
||||
|
@ -350,8 +348,8 @@ func Test_operationAssert(t *testing.T) {
|
|||
nspacer,
|
||||
false,
|
||||
)
|
||||
logger := &tlogging.FakeLogger{}
|
||||
outputs, err := operation.Exec(ttesting.IntoContext(logging.IntoContext(ctx, logger), t), nil)
|
||||
logger := &mocks.Logger{}
|
||||
outputs, err := operation.Exec(logging.WithLogger(ctx, logger), nil)
|
||||
assert.Nil(t, outputs)
|
||||
if tt.expectErr {
|
||||
assert.NotNil(t, err)
|
||||
|
|
|
@ -11,10 +11,10 @@ import (
|
|||
"github.com/kyverno/chainsaw/pkg/apis/v1alpha1"
|
||||
apibindings "github.com/kyverno/chainsaw/pkg/engine/bindings"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/checks"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations/internal"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/outputs"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
environment "github.com/kyverno/chainsaw/pkg/utils/env"
|
||||
restutils "github.com/kyverno/chainsaw/pkg/utils/rest"
|
||||
"github.com/kyverno/kyverno-json/pkg/core/compilers"
|
||||
|
@ -50,9 +50,8 @@ func (o *operation) Exec(ctx context.Context, bindings apis.Bindings) (_ outputs
|
|||
if bindings == nil {
|
||||
bindings = apis.NewBindings()
|
||||
}
|
||||
logger := internal.GetLogger(ctx, nil)
|
||||
defer func() {
|
||||
internal.LogEnd(logger, logging.Command, _err)
|
||||
internal.LogEnd(ctx, logging.Command, nil, _err)
|
||||
}()
|
||||
cmd, cancel, err := o.createCommand(ctx, bindings)
|
||||
if cancel != nil {
|
||||
|
@ -65,7 +64,7 @@ func (o *operation) Exec(ctx context.Context, bindings apis.Bindings) (_ outputs
|
|||
if !o.command.SkipCommandOutput {
|
||||
logOpts = append(logOpts, logging.Section("COMMAND", cmd.String()))
|
||||
}
|
||||
internal.LogStart(logger, logging.Command, logOpts...)
|
||||
internal.LogStart(ctx, logging.Command, nil, logOpts...)
|
||||
return o.execute(ctx, bindings, cmd)
|
||||
}
|
||||
|
||||
|
@ -86,8 +85,7 @@ func (o *operation) createCommand(ctx context.Context, bindings apis.Bindings) (
|
|||
cancel = func() {
|
||||
err := os.Remove(path)
|
||||
if err != nil {
|
||||
logger := internal.GetLogger(ctx, nil)
|
||||
logger.Log(logging.Script, logging.WarnStatus, color.BoldYellow, logging.ErrSection(err))
|
||||
logging.Log(ctx, logging.Script, logging.WarnStatus, nil, color.BoldYellow, logging.ErrSection(err))
|
||||
}
|
||||
}
|
||||
defer f.Close()
|
||||
|
@ -112,24 +110,23 @@ func (o *operation) createCommand(ctx context.Context, bindings apis.Bindings) (
|
|||
}
|
||||
|
||||
func (o *operation) execute(ctx context.Context, bindings apis.Bindings, cmd *exec.Cmd) (_outputs outputs.Outputs, _err error) {
|
||||
logger := logging.FromContext(ctx)
|
||||
var output internal.CommandOutput
|
||||
if !o.command.SkipLogOutput {
|
||||
defer func() {
|
||||
if sections := output.Sections(); len(sections) != 0 {
|
||||
logger.Log(logging.Command, logging.LogStatus, color.BoldFgCyan, sections...)
|
||||
logging.Log(ctx, logging.Command, logging.LogStatus, nil, color.BoldFgCyan, sections...)
|
||||
}
|
||||
}()
|
||||
}
|
||||
cmd.Stdout = &output.Stdout
|
||||
cmd.Stderr = &output.Stderr
|
||||
err := cmd.Run()
|
||||
bindings = apibindings.RegisterBinding(ctx, bindings, "stdout", output.Out())
|
||||
bindings = apibindings.RegisterBinding(ctx, bindings, "stderr", output.Err())
|
||||
bindings = apibindings.RegisterBinding(bindings, "stdout", output.Out())
|
||||
bindings = apibindings.RegisterBinding(bindings, "stderr", output.Err())
|
||||
if err == nil {
|
||||
bindings = apibindings.RegisterBinding(ctx, bindings, "error", nil)
|
||||
bindings = apibindings.RegisterBinding(bindings, "error", nil)
|
||||
} else {
|
||||
bindings = apibindings.RegisterBinding(ctx, bindings, "error", err.Error())
|
||||
bindings = apibindings.RegisterBinding(bindings, "error", err.Error())
|
||||
}
|
||||
defer func(bindings apis.Bindings) {
|
||||
if _err == nil {
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
|
||||
"github.com/kyverno/chainsaw/pkg/apis"
|
||||
"github.com/kyverno/chainsaw/pkg/apis/v1alpha1"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
tlogging "github.com/kyverno/chainsaw/pkg/engine/logging/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/mocks"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/utils/ptr"
|
||||
)
|
||||
|
@ -134,7 +134,7 @@ func Test_operationCommand(t *testing.T) {
|
|||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ctx := logging.IntoContext(context.TODO(), &tlogging.FakeLogger{})
|
||||
ctx := logging.WithLogger(context.TODO(), &mocks.Logger{})
|
||||
operation := New(
|
||||
apis.DefaultCompilers,
|
||||
tt.command,
|
||||
|
|
|
@ -10,12 +10,12 @@ import (
|
|||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
apibindings "github.com/kyverno/chainsaw/pkg/engine/bindings"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/checks"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/namespacer"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations/internal"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/outputs"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/templating"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/kyverno-json/pkg/core/compilers"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
|
@ -60,9 +60,8 @@ func (o *operation) Exec(ctx context.Context, bindings apis.Bindings) (_ outputs
|
|||
bindings = apis.NewBindings()
|
||||
}
|
||||
obj := o.base
|
||||
logger := internal.GetLogger(ctx, &obj)
|
||||
defer func() {
|
||||
internal.LogEnd(logger, logging.Create, _err)
|
||||
internal.LogEnd(ctx, logging.Create, &obj, _err)
|
||||
}()
|
||||
if o.template {
|
||||
template := v1alpha1.NewProjection(obj.UnstructuredContent())
|
||||
|
@ -75,7 +74,7 @@ func (o *operation) Exec(ctx context.Context, bindings apis.Bindings) (_ outputs
|
|||
if err := internal.ApplyNamespacer(o.namespacer, o.client, &obj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
internal.LogStart(logger, logging.Create)
|
||||
internal.LogStart(ctx, logging.Create, &obj)
|
||||
return o.execute(ctx, bindings, obj)
|
||||
}
|
||||
|
||||
|
@ -120,9 +119,9 @@ func (o *operation) createResource(ctx context.Context, bindings apis.Bindings,
|
|||
|
||||
func (o *operation) handleCheck(ctx context.Context, bindings apis.Bindings, obj unstructured.Unstructured, err error) (_outputs outputs.Outputs, _err error) {
|
||||
if err == nil {
|
||||
bindings = apibindings.RegisterBinding(ctx, bindings, "error", nil)
|
||||
bindings = apibindings.RegisterBinding(bindings, "error", nil)
|
||||
} else {
|
||||
bindings = apibindings.RegisterBinding(ctx, bindings, "error", err.Error())
|
||||
bindings = apibindings.RegisterBinding(bindings, "error", err.Error())
|
||||
}
|
||||
defer func(bindings apis.Bindings) {
|
||||
if _err == nil {
|
||||
|
|
|
@ -11,8 +11,8 @@ import (
|
|||
"github.com/kyverno/chainsaw/pkg/cleanup/cleaner"
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
tclient "github.com/kyverno/chainsaw/pkg/client/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
tlogging "github.com/kyverno/chainsaw/pkg/engine/logging/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/mocks"
|
||||
"github.com/stretchr/testify/assert"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
|
@ -213,8 +213,8 @@ func Test_create(t *testing.T) {
|
|||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
logger := &tlogging.FakeLogger{}
|
||||
ctx := logging.IntoContext(context.TODO(), logger)
|
||||
logger := &mocks.Logger{}
|
||||
ctx := logging.WithLogger(context.TODO(), logger)
|
||||
toCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
ctx = toCtx
|
||||
|
|
|
@ -8,12 +8,12 @@ import (
|
|||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
apibindings "github.com/kyverno/chainsaw/pkg/engine/bindings"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/checks"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/namespacer"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations/internal"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/outputs"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/templating"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/kyverno-json/pkg/core/compilers"
|
||||
"go.uber.org/multierr"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
|
@ -57,9 +57,8 @@ func (o *operation) Exec(ctx context.Context, bindings apis.Bindings) (_ outputs
|
|||
bindings = apis.NewBindings()
|
||||
}
|
||||
obj := o.base
|
||||
logger := internal.GetLogger(ctx, &obj)
|
||||
defer func() {
|
||||
internal.LogEnd(logger, logging.Delete, _err)
|
||||
internal.LogEnd(ctx, logging.Delete, &obj, _err)
|
||||
}()
|
||||
if o.template {
|
||||
template := v1alpha1.NewProjection(obj.UnstructuredContent())
|
||||
|
@ -72,7 +71,7 @@ func (o *operation) Exec(ctx context.Context, bindings apis.Bindings) (_ outputs
|
|||
if err := internal.ApplyNamespacer(o.namespacer, o.client, &obj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
internal.LogStart(logger, logging.Delete)
|
||||
internal.LogStart(ctx, logging.Delete, &obj)
|
||||
return nil, o.execute(ctx, bindings, obj)
|
||||
}
|
||||
|
||||
|
@ -145,9 +144,9 @@ func (o *operation) waitForDeletion(ctx context.Context, resource unstructured.U
|
|||
|
||||
func (o *operation) handleCheck(ctx context.Context, bindings apis.Bindings, resource unstructured.Unstructured, err error) error {
|
||||
if err == nil {
|
||||
bindings = apibindings.RegisterBinding(ctx, bindings, "error", nil)
|
||||
bindings = apibindings.RegisterBinding(bindings, "error", nil)
|
||||
} else {
|
||||
bindings = apibindings.RegisterBinding(ctx, bindings, "error", err.Error())
|
||||
bindings = apibindings.RegisterBinding(bindings, "error", err.Error())
|
||||
}
|
||||
if matched, err := checks.Expect(ctx, o.compilers, resource, bindings, o.expect...); matched {
|
||||
return err
|
||||
|
|
|
@ -10,10 +10,9 @@ import (
|
|||
"github.com/kyverno/chainsaw/pkg/apis/v1alpha1"
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
tclient "github.com/kyverno/chainsaw/pkg/client/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
tlogging "github.com/kyverno/chainsaw/pkg/engine/logging/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/namespacer"
|
||||
ttesting "github.com/kyverno/chainsaw/pkg/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/mocks"
|
||||
"github.com/stretchr/testify/assert"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
@ -112,7 +111,6 @@ func Test_operationDelete(t *testing.T) {
|
|||
object: pod,
|
||||
client: &tclient.FakeClient{
|
||||
GetFn: func(ctx context.Context, call int, key client.ObjectKey, obj client.Object, _ ...client.GetOption) error {
|
||||
t := ttesting.FromContext(ctx)
|
||||
assert.Equal(t, "bar", key.Namespace)
|
||||
if call == 0 {
|
||||
return nil
|
||||
|
@ -120,7 +118,6 @@ func Test_operationDelete(t *testing.T) {
|
|||
return kerrors.NewNotFound(obj.GetObjectKind().GroupVersionKind().GroupVersion().WithResource("pod").GroupResource(), key.Name)
|
||||
},
|
||||
DeleteFn: func(ctx context.Context, call int, obj client.Object, _ ...client.DeleteOption) error {
|
||||
t := ttesting.FromContext(ctx)
|
||||
assert.Equal(t, "bar", obj.GetNamespace())
|
||||
return nil
|
||||
},
|
||||
|
@ -144,7 +141,6 @@ func Test_operationDelete(t *testing.T) {
|
|||
return kerrors.NewNotFound(obj.GetObjectKind().GroupVersionKind().GroupVersion().WithResource("pod").GroupResource(), key.Name)
|
||||
},
|
||||
DeleteFn: func(ctx context.Context, call int, obj client.Object, _ ...client.DeleteOption) error {
|
||||
t := ttesting.FromContext(ctx)
|
||||
assert.Equal(t, 1, call)
|
||||
return errors.New("dummy error")
|
||||
},
|
||||
|
@ -176,8 +172,8 @@ func Test_operationDelete(t *testing.T) {
|
|||
metav1.DeletePropagationForeground,
|
||||
tt.expect...,
|
||||
)
|
||||
logger := &tlogging.FakeLogger{}
|
||||
outputs, err := operation.Exec(ttesting.IntoContext(logging.IntoContext(ctx, logger), t), nil)
|
||||
logger := &mocks.Logger{}
|
||||
outputs, err := operation.Exec(logging.WithLogger(ctx, logger), nil)
|
||||
assert.Nil(t, outputs)
|
||||
if tt.expectedErr != nil {
|
||||
assert.EqualError(t, err, tt.expectedErr.Error())
|
||||
|
|
|
@ -8,12 +8,12 @@ import (
|
|||
"github.com/kyverno/chainsaw/pkg/apis/v1alpha1"
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/checks"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/namespacer"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations/internal"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/outputs"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/templating"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/kyverno-json/pkg/core/compilers"
|
||||
"go.uber.org/multierr"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
|
@ -51,9 +51,8 @@ func (o *operation) Exec(ctx context.Context, bindings apis.Bindings) (_ outputs
|
|||
bindings = apis.NewBindings()
|
||||
}
|
||||
obj := o.base
|
||||
logger := internal.GetLogger(ctx, &obj)
|
||||
defer func() {
|
||||
internal.LogEnd(logger, logging.Error, _err)
|
||||
internal.LogEnd(ctx, logging.Error, &obj, _err)
|
||||
}()
|
||||
if o.template {
|
||||
if err := templating.ResourceRef(ctx, o.compilers, &obj, bindings); err != nil {
|
||||
|
@ -65,7 +64,7 @@ func (o *operation) Exec(ctx context.Context, bindings apis.Bindings) (_ outputs
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
internal.LogStart(logger, logging.Error)
|
||||
internal.LogStart(ctx, logging.Error, &obj)
|
||||
return nil, o.execute(ctx, bindings, obj)
|
||||
}
|
||||
|
||||
|
|
|
@ -10,11 +10,10 @@ import (
|
|||
"github.com/kyverno/chainsaw/pkg/apis"
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
tclient "github.com/kyverno/chainsaw/pkg/client/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
tlogging "github.com/kyverno/chainsaw/pkg/engine/logging/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/namespacer"
|
||||
tnamespacer "github.com/kyverno/chainsaw/pkg/engine/namespacer/testing"
|
||||
ttesting "github.com/kyverno/chainsaw/pkg/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/mocks"
|
||||
"github.com/stretchr/testify/assert"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
|
@ -160,7 +159,6 @@ func Test_operationError(t *testing.T) {
|
|||
},
|
||||
client: &tclient.FakeClient{
|
||||
ListFn: func(ctx context.Context, _ int, list client.ObjectList, opts ...client.ListOption) error {
|
||||
t := ttesting.FromContext(ctx)
|
||||
assert.Contains(t, opts, client.InNamespace("bar"))
|
||||
uList := list.(*unstructured.UnstructuredList)
|
||||
uList.Items = nil
|
||||
|
@ -217,8 +215,8 @@ func Test_operationError(t *testing.T) {
|
|||
nspacer,
|
||||
false,
|
||||
)
|
||||
logger := &tlogging.FakeLogger{}
|
||||
outputs, err := operation.Exec(ttesting.IntoContext(logging.IntoContext(ctx, logger), t), nil)
|
||||
logger := &mocks.Logger{}
|
||||
outputs, err := operation.Exec(logging.WithLogger(ctx, logger), nil)
|
||||
assert.Nil(t, outputs)
|
||||
if tt.expectedErr != nil {
|
||||
assert.EqualError(t, err, tt.expectedErr.Error())
|
||||
|
|
|
@ -0,0 +1,195 @@
|
|||
package errors
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/kyverno/chainsaw/pkg/apis"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
)
|
||||
|
||||
func TestResourceError(t *testing.T) {
|
||||
// Create test objects
|
||||
expected := unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "test-config",
|
||||
"namespace": "default",
|
||||
},
|
||||
"data": map[string]interface{}{
|
||||
"key1": "expected-value",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
actual := unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "test-config",
|
||||
"namespace": "default",
|
||||
},
|
||||
"data": map[string]interface{}{
|
||||
"key1": "actual-value",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Create field error list
|
||||
errorList := field.ErrorList{
|
||||
field.Invalid(field.NewPath("data", "key1"), "actual-value", "expected 'expected-value'"),
|
||||
}
|
||||
|
||||
// Test creating a ResourceError
|
||||
err := ResourceError(
|
||||
apis.DefaultCompilers,
|
||||
expected,
|
||||
actual,
|
||||
false,
|
||||
apis.NewBindings(),
|
||||
errorList,
|
||||
)
|
||||
|
||||
// Verify the error is of the correct type
|
||||
_, ok := err.(resourceError)
|
||||
assert.True(t, ok, "Expected error to be of type resourceError")
|
||||
|
||||
// Verify the error message contains the expected information
|
||||
errMsg := err.Error()
|
||||
|
||||
// Should include resource identification
|
||||
assert.Contains(t, errMsg, "v1/ConfigMap/default/test-config")
|
||||
|
||||
// Should include field errors
|
||||
assert.Contains(t, errMsg, "data.key1")
|
||||
assert.Contains(t, errMsg, "expected 'expected-value'")
|
||||
assert.Contains(t, errMsg, "actual-value")
|
||||
|
||||
// Should include diff information
|
||||
assert.Contains(t, errMsg, "key1:")
|
||||
}
|
||||
|
||||
func TestResourceErrorWithTemplating(t *testing.T) {
|
||||
// Create test objects
|
||||
expected := unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "test-config",
|
||||
"namespace": "default",
|
||||
},
|
||||
"data": map[string]interface{}{
|
||||
"key1": "{{ .value }}", // Template value
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
actual := unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "test-config",
|
||||
"namespace": "default",
|
||||
},
|
||||
"data": map[string]interface{}{
|
||||
"key1": "wrong-value",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Create bindings for templating
|
||||
bindings := apis.NewBindings().Register("value", apis.NewBinding("template-value"))
|
||||
|
||||
// Test creating a ResourceError with templating
|
||||
err := ResourceError(
|
||||
apis.DefaultCompilers,
|
||||
expected,
|
||||
actual,
|
||||
true, // Enable templating
|
||||
bindings,
|
||||
field.ErrorList{},
|
||||
)
|
||||
|
||||
// Verify the error message contains templated values
|
||||
errMsg := err.Error()
|
||||
|
||||
// Should include resource identification
|
||||
assert.Contains(t, errMsg, "v1/ConfigMap/default/test-config")
|
||||
|
||||
// We need to check for the template or value in diff, not always both
|
||||
// Either the template was successfully rendered (contains template-value)
|
||||
// Or it shows the raw template (contains {{ .value }})
|
||||
if !assert.True(t,
|
||||
(contains(errMsg, "template-value") || contains(errMsg, "{{ .value }}")),
|
||||
"Error message should contain either the template expression or the template value") {
|
||||
// Print the actual error message for debugging
|
||||
t.Logf("Actual error message: %s", errMsg)
|
||||
}
|
||||
|
||||
assert.Contains(t, errMsg, "wrong-value")
|
||||
}
|
||||
|
||||
func TestResourceErrorWithInvalidTemplate(t *testing.T) {
|
||||
// Create test objects with invalid template
|
||||
expected := unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "test-config",
|
||||
"namespace": "default",
|
||||
},
|
||||
"data": map[string]interface{}{
|
||||
"key1": "{{ .undefinedValue }}", // Undefined value in template
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
actual := unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "test-config",
|
||||
"namespace": "default",
|
||||
},
|
||||
"data": map[string]interface{}{
|
||||
"key1": "some-value",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Test creating a ResourceError with invalid templating
|
||||
err := ResourceError(
|
||||
apis.DefaultCompilers,
|
||||
expected,
|
||||
actual,
|
||||
true, // Enable templating
|
||||
apis.NewBindings(), // Empty bindings, so .undefinedValue is not defined
|
||||
field.ErrorList{},
|
||||
)
|
||||
|
||||
// Verify the error message contains relevant info
|
||||
errMsg := err.Error()
|
||||
t.Logf("Error message: %s", errMsg)
|
||||
|
||||
// Should include resource identification
|
||||
assert.Contains(t, errMsg, "v1/ConfigMap/default/test-config")
|
||||
|
||||
// Should include the template expression
|
||||
assert.Contains(t, errMsg, "{{ .undefinedValue }}")
|
||||
|
||||
// Might contain an error about the template (but not guaranteed by the implementation)
|
||||
// So we don't assert on this anymore
|
||||
}
|
||||
|
||||
// Helper function to check if a string contains another string
|
||||
func contains(s, substr string) bool {
|
||||
return assert.Contains(&testing.T{}, s, substr)
|
||||
}
|
|
@ -5,7 +5,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
)
|
||||
|
||||
type CommandOutput struct {
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
|
|
@ -5,35 +5,18 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/pkg/ext/output/color"
|
||||
)
|
||||
|
||||
func GetLogger(ctx context.Context, obj client.Object) logging.Logger {
|
||||
logger := logging.FromContext(ctx)
|
||||
if logger == nil {
|
||||
return logger
|
||||
}
|
||||
if obj != nil {
|
||||
if obj.GetObjectKind().GroupVersionKind().Kind == "" {
|
||||
return logger
|
||||
}
|
||||
}
|
||||
return logger.WithResource(obj)
|
||||
func LogStart(ctx context.Context, op logging.Operation, obj client.Object, args ...fmt.Stringer) {
|
||||
logging.Log(ctx, op, logging.RunStatus, obj, color.BoldFgCyan, args...)
|
||||
}
|
||||
|
||||
func LogStart(logger logging.Logger, op logging.Operation, args ...fmt.Stringer) {
|
||||
if logger != nil {
|
||||
logger.Log(op, logging.RunStatus, color.BoldFgCyan, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func LogEnd(logger logging.Logger, op logging.Operation, err error) {
|
||||
if logger != nil {
|
||||
if err != nil {
|
||||
logger.Log(op, logging.ErrorStatus, color.BoldRed, logging.ErrSection(err))
|
||||
} else {
|
||||
logger.Log(op, logging.DoneStatus, color.BoldGreen)
|
||||
}
|
||||
func LogEnd(ctx context.Context, op logging.Operation, obj client.Object, err error) {
|
||||
if err != nil {
|
||||
logging.Log(ctx, op, logging.ErrorStatus, obj, color.BoldRed, logging.ErrSection(err))
|
||||
} else {
|
||||
logging.Log(ctx, op, logging.DoneStatus, obj, color.BoldGreen)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,69 +5,45 @@ import (
|
|||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
tlogging "github.com/kyverno/chainsaw/pkg/engine/logging/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/mocks"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
func TestGetLogger(t *testing.T) {
|
||||
assert.Nil(t, GetLogger(context.TODO(), nil))
|
||||
{
|
||||
logger := &tlogging.FakeLogger{}
|
||||
ctx := logging.IntoContext(context.TODO(), logger)
|
||||
assert.NotNil(t, GetLogger(ctx, nil))
|
||||
}
|
||||
{
|
||||
logger := &tlogging.FakeLogger{}
|
||||
ctx := logging.IntoContext(context.TODO(), logger)
|
||||
obj := unstructured.Unstructured{}
|
||||
obj.SetAPIVersion("foo/v1")
|
||||
obj.SetKind("bar")
|
||||
obj.SetName("hello")
|
||||
obj.SetNamespace("chainsaw")
|
||||
l := GetLogger(ctx, &obj)
|
||||
l.Log("aaa", "bbb", nil)
|
||||
assert.Equal(t, []string{"aaa: bbb - []"}, logger.Logs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogStart(t *testing.T) {
|
||||
logger := &tlogging.FakeLogger{}
|
||||
ctx := logging.IntoContext(context.TODO(), logger)
|
||||
logger := &mocks.Logger{}
|
||||
ctx := logging.WithLogger(context.TODO(), logger)
|
||||
obj := unstructured.Unstructured{}
|
||||
obj.SetAPIVersion("foo/v1")
|
||||
obj.SetKind("bar")
|
||||
obj.SetName("hello")
|
||||
obj.SetNamespace("chainsaw")
|
||||
l := GetLogger(ctx, &obj)
|
||||
LogStart(l, "aaa")
|
||||
LogStart(ctx, "aaa", &obj)
|
||||
assert.Equal(t, []string{"aaa: RUN - []"}, logger.Logs)
|
||||
}
|
||||
|
||||
func TestLogEnd(t *testing.T) {
|
||||
{
|
||||
logger := &tlogging.FakeLogger{}
|
||||
ctx := logging.IntoContext(context.TODO(), logger)
|
||||
logger := &mocks.Logger{}
|
||||
ctx := logging.WithLogger(context.TODO(), logger)
|
||||
obj := unstructured.Unstructured{}
|
||||
obj.SetAPIVersion("foo/v1")
|
||||
obj.SetKind("bar")
|
||||
obj.SetName("hello")
|
||||
obj.SetNamespace("chainsaw")
|
||||
l := GetLogger(ctx, &obj)
|
||||
LogEnd(l, "aaa", nil)
|
||||
LogEnd(ctx, "aaa", &obj, nil)
|
||||
assert.Equal(t, []string{"aaa: DONE - []"}, logger.Logs)
|
||||
}
|
||||
{
|
||||
logger := &tlogging.FakeLogger{}
|
||||
ctx := logging.IntoContext(context.TODO(), logger)
|
||||
logger := &mocks.Logger{}
|
||||
ctx := logging.WithLogger(context.TODO(), logger)
|
||||
obj := unstructured.Unstructured{}
|
||||
obj.SetAPIVersion("foo/v1")
|
||||
obj.SetKind("bar")
|
||||
obj.SetName("hello")
|
||||
obj.SetNamespace("chainsaw")
|
||||
l := GetLogger(ctx, &obj)
|
||||
LogEnd(l, "aaa", errors.New("some error"))
|
||||
LogEnd(ctx, "aaa", &obj, errors.New("some error"))
|
||||
assert.Equal(t, []string{"aaa: ERROR - [=== ERROR\nsome error]"}, logger.Logs)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@ import (
|
|||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
apibindings "github.com/kyverno/chainsaw/pkg/engine/bindings"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/checks"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/namespacer"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations/internal"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/outputs"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/templating"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/kyverno-json/pkg/core/compilers"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
|
@ -56,9 +56,8 @@ func (o *operation) Exec(ctx context.Context, bindings apis.Bindings) (_ outputs
|
|||
bindings = apis.NewBindings()
|
||||
}
|
||||
obj := o.base
|
||||
logger := internal.GetLogger(ctx, &obj)
|
||||
defer func() {
|
||||
internal.LogEnd(logger, logging.Patch, _err)
|
||||
internal.LogEnd(ctx, logging.Patch, &obj, _err)
|
||||
}()
|
||||
if o.template {
|
||||
template := v1alpha1.NewProjection(obj.UnstructuredContent())
|
||||
|
@ -71,7 +70,7 @@ func (o *operation) Exec(ctx context.Context, bindings apis.Bindings) (_ outputs
|
|||
if err := internal.ApplyNamespacer(o.namespacer, o.client, &obj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
internal.LogStart(logger, logging.Patch)
|
||||
internal.LogStart(ctx, logging.Patch, &obj)
|
||||
return o.execute(ctx, bindings, obj)
|
||||
}
|
||||
|
||||
|
@ -116,9 +115,9 @@ func (o *operation) updateResource(ctx context.Context, bindings apis.Bindings,
|
|||
|
||||
func (o *operation) handleCheck(ctx context.Context, bindings apis.Bindings, obj unstructured.Unstructured, err error) (_outputs outputs.Outputs, _err error) {
|
||||
if err == nil {
|
||||
bindings = apibindings.RegisterBinding(ctx, bindings, "error", nil)
|
||||
bindings = apibindings.RegisterBinding(bindings, "error", nil)
|
||||
} else {
|
||||
bindings = apibindings.RegisterBinding(ctx, bindings, "error", err.Error())
|
||||
bindings = apibindings.RegisterBinding(bindings, "error", err.Error())
|
||||
}
|
||||
defer func(bindings apis.Bindings) {
|
||||
if _err == nil {
|
||||
|
|
|
@ -10,8 +10,8 @@ import (
|
|||
"github.com/kyverno/chainsaw/pkg/apis/v1alpha1"
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
tclient "github.com/kyverno/chainsaw/pkg/client/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
tlogging "github.com/kyverno/chainsaw/pkg/engine/logging/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/mocks"
|
||||
"github.com/stretchr/testify/assert"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
|
@ -203,8 +203,8 @@ func Test_create(t *testing.T) {
|
|||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
logger := &tlogging.FakeLogger{}
|
||||
ctx := logging.IntoContext(context.TODO(), logger)
|
||||
logger := &mocks.Logger{}
|
||||
ctx := logging.WithLogger(context.TODO(), logger)
|
||||
toCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
|
||||
defer cancel()
|
||||
ctx = toCtx
|
||||
|
|
|
@ -11,10 +11,10 @@ import (
|
|||
"github.com/kyverno/chainsaw/pkg/apis/v1alpha1"
|
||||
apibindings "github.com/kyverno/chainsaw/pkg/engine/bindings"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/checks"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations/internal"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/outputs"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
restutils "github.com/kyverno/chainsaw/pkg/utils/rest"
|
||||
"github.com/kyverno/kyverno-json/pkg/core/compilers"
|
||||
"github.com/kyverno/pkg/ext/output/color"
|
||||
|
@ -49,9 +49,8 @@ func (o *operation) Exec(ctx context.Context, bindings apis.Bindings) (_ outputs
|
|||
if bindings == nil {
|
||||
bindings = apis.NewBindings()
|
||||
}
|
||||
logger := internal.GetLogger(ctx, nil)
|
||||
defer func() {
|
||||
internal.LogEnd(logger, logging.Script, _err)
|
||||
internal.LogEnd(ctx, logging.Script, nil, _err)
|
||||
}()
|
||||
cmd, cancel, _err := o.createCommand(ctx, bindings)
|
||||
if cancel != nil {
|
||||
|
@ -64,7 +63,7 @@ func (o *operation) Exec(ctx context.Context, bindings apis.Bindings) (_ outputs
|
|||
if !o.script.SkipCommandOutput {
|
||||
logOpts = append(logOpts, logging.Section("COMMAND", cmd.String()))
|
||||
}
|
||||
internal.LogStart(logger, logging.Command, logOpts...)
|
||||
internal.LogStart(ctx, logging.Command, nil, logOpts...)
|
||||
return o.execute(ctx, bindings, cmd)
|
||||
}
|
||||
|
||||
|
@ -85,8 +84,7 @@ func (o *operation) createCommand(ctx context.Context, bindings apis.Bindings) (
|
|||
cancel = func() {
|
||||
err := os.Remove(path)
|
||||
if err != nil {
|
||||
logger := internal.GetLogger(ctx, nil)
|
||||
logger.Log(logging.Script, logging.WarnStatus, color.BoldYellow, logging.ErrSection(err))
|
||||
logging.Log(ctx, logging.Script, logging.WarnStatus, nil, color.BoldYellow, logging.ErrSection(err))
|
||||
}
|
||||
}
|
||||
defer f.Close()
|
||||
|
@ -110,24 +108,23 @@ func (o *operation) createCommand(ctx context.Context, bindings apis.Bindings) (
|
|||
}
|
||||
|
||||
func (o *operation) execute(ctx context.Context, bindings apis.Bindings, cmd *exec.Cmd) (_outputs outputs.Outputs, _err error) {
|
||||
logger := internal.GetLogger(ctx, nil)
|
||||
var output internal.CommandOutput
|
||||
if !o.script.SkipLogOutput {
|
||||
defer func() {
|
||||
if sections := output.Sections(); len(sections) != 0 {
|
||||
logger.Log(logging.Script, logging.LogStatus, color.BoldFgCyan, sections...)
|
||||
logging.Log(ctx, logging.Script, logging.LogStatus, nil, color.BoldFgCyan, sections...)
|
||||
}
|
||||
}()
|
||||
}
|
||||
cmd.Stdout = &output.Stdout
|
||||
cmd.Stderr = &output.Stderr
|
||||
err := cmd.Run()
|
||||
bindings = apibindings.RegisterBinding(ctx, bindings, "stdout", output.Out())
|
||||
bindings = apibindings.RegisterBinding(ctx, bindings, "stderr", output.Err())
|
||||
bindings = apibindings.RegisterBinding(bindings, "stdout", output.Out())
|
||||
bindings = apibindings.RegisterBinding(bindings, "stderr", output.Err())
|
||||
if err == nil {
|
||||
bindings = apibindings.RegisterBinding(ctx, bindings, "error", nil)
|
||||
bindings = apibindings.RegisterBinding(bindings, "error", nil)
|
||||
} else {
|
||||
bindings = apibindings.RegisterBinding(ctx, bindings, "error", err.Error())
|
||||
bindings = apibindings.RegisterBinding(bindings, "error", err.Error())
|
||||
}
|
||||
defer func(bindings apis.Bindings) {
|
||||
if _err == nil {
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
|
||||
"github.com/kyverno/chainsaw/pkg/apis"
|
||||
"github.com/kyverno/chainsaw/pkg/apis/v1alpha1"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
tlogging "github.com/kyverno/chainsaw/pkg/engine/logging/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/mocks"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/utils/ptr"
|
||||
)
|
||||
|
@ -126,7 +126,7 @@ func Test_operationScript(t *testing.T) {
|
|||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ctx := logging.IntoContext(context.TODO(), &tlogging.FakeLogger{})
|
||||
ctx := logging.WithLogger(context.TODO(), &mocks.Logger{})
|
||||
operation := New(
|
||||
apis.DefaultCompilers,
|
||||
tt.script,
|
||||
|
|
|
@ -5,33 +5,31 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/kyverno/chainsaw/pkg/apis"
|
||||
"github.com/kyverno/chainsaw/pkg/apis/v1alpha1"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations/internal"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/outputs"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
)
|
||||
|
||||
type operation struct {
|
||||
duration v1alpha1.Sleep
|
||||
duration time.Duration
|
||||
}
|
||||
|
||||
func New(duration v1alpha1.Sleep) operations.Operation {
|
||||
func New(duration time.Duration) operations.Operation {
|
||||
return &operation{
|
||||
duration: duration,
|
||||
}
|
||||
}
|
||||
|
||||
func (o *operation) Exec(ctx context.Context, _ apis.Bindings) (_ outputs.Outputs, _err error) {
|
||||
logger := internal.GetLogger(ctx, nil)
|
||||
defer func() {
|
||||
internal.LogEnd(logger, logging.Sleep, _err)
|
||||
internal.LogEnd(ctx, logging.Sleep, nil, _err)
|
||||
}()
|
||||
internal.LogStart(logger, logging.Sleep)
|
||||
internal.LogStart(ctx, logging.Sleep, nil)
|
||||
return nil, o.execute()
|
||||
}
|
||||
|
||||
func (o *operation) execute() error {
|
||||
time.Sleep(o.duration.Duration.Duration)
|
||||
time.Sleep(o.duration)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -5,28 +5,22 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/kyverno/chainsaw/pkg/apis/v1alpha1"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
tlogging "github.com/kyverno/chainsaw/pkg/engine/logging/testing"
|
||||
ttesting "github.com/kyverno/chainsaw/pkg/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/mocks"
|
||||
"github.com/stretchr/testify/assert"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
func Test_operation_Exec(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
sleep v1alpha1.Sleep
|
||||
sleep time.Duration
|
||||
expectedLogs []string
|
||||
}{{
|
||||
name: "zero",
|
||||
sleep: v1alpha1.Sleep{},
|
||||
expectedLogs: []string{"SLEEP: RUN - []", "SLEEP: DONE - []"},
|
||||
}, {
|
||||
name: "1s",
|
||||
sleep: v1alpha1.Sleep{
|
||||
Duration: metav1.Duration{Duration: time.Second},
|
||||
},
|
||||
name: "1s",
|
||||
sleep: time.Second,
|
||||
expectedLogs: []string{"SLEEP: RUN - []", "SLEEP: DONE - []"},
|
||||
}}
|
||||
for _, tt := range tests {
|
||||
|
@ -36,8 +30,8 @@ func Test_operation_Exec(t *testing.T) {
|
|||
operation := New(
|
||||
tt.sleep,
|
||||
)
|
||||
logger := &tlogging.FakeLogger{}
|
||||
outputs, err := operation.Exec(ttesting.IntoContext(logging.IntoContext(ctx, logger), t), nil)
|
||||
logger := &mocks.Logger{}
|
||||
outputs, err := operation.Exec(logging.WithLogger(ctx, logger), nil)
|
||||
assert.Nil(t, outputs)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.expectedLogs, logger.Logs)
|
||||
|
|
|
@ -9,20 +9,18 @@ import (
|
|||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
apibindings "github.com/kyverno/chainsaw/pkg/engine/bindings"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/checks"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/namespacer"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/operations/internal"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/outputs"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/templating"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/kyverno-json/pkg/core/compilers"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
)
|
||||
|
||||
const op = logging.Update
|
||||
|
||||
type operation struct {
|
||||
compilers compilers.Compilers
|
||||
client client.Client
|
||||
|
@ -58,9 +56,8 @@ func (o *operation) Exec(ctx context.Context, bindings apis.Bindings) (_ outputs
|
|||
bindings = apis.NewBindings()
|
||||
}
|
||||
obj := o.base
|
||||
logger := internal.GetLogger(ctx, &obj)
|
||||
defer func() {
|
||||
internal.LogEnd(logger, op, _err)
|
||||
internal.LogEnd(ctx, logging.Update, &obj, _err)
|
||||
}()
|
||||
if o.template {
|
||||
template := v1alpha1.NewProjection(obj.UnstructuredContent())
|
||||
|
@ -73,7 +70,7 @@ func (o *operation) Exec(ctx context.Context, bindings apis.Bindings) (_ outputs
|
|||
if err := internal.ApplyNamespacer(o.namespacer, o.client, &obj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
internal.LogStart(logger, op)
|
||||
internal.LogStart(ctx, logging.Update, &obj)
|
||||
return o.execute(ctx, bindings, obj)
|
||||
}
|
||||
|
||||
|
@ -116,9 +113,9 @@ func (o *operation) updateResource(ctx context.Context, bindings apis.Bindings,
|
|||
|
||||
func (o *operation) handleCheck(ctx context.Context, bindings apis.Bindings, obj unstructured.Unstructured, err error) (_outputs outputs.Outputs, _err error) {
|
||||
if err == nil {
|
||||
bindings = apibindings.RegisterBinding(ctx, bindings, "error", nil)
|
||||
bindings = apibindings.RegisterBinding(bindings, "error", nil)
|
||||
} else {
|
||||
bindings = apibindings.RegisterBinding(ctx, bindings, "error", err.Error())
|
||||
bindings = apibindings.RegisterBinding(bindings, "error", err.Error())
|
||||
}
|
||||
defer func(bindings apis.Bindings) {
|
||||
if _err == nil {
|
||||
|
|
|
@ -10,8 +10,8 @@ import (
|
|||
"github.com/kyverno/chainsaw/pkg/apis/v1alpha1"
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
tclient "github.com/kyverno/chainsaw/pkg/client/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/logging"
|
||||
tlogging "github.com/kyverno/chainsaw/pkg/engine/logging/testing"
|
||||
"github.com/kyverno/chainsaw/pkg/logging"
|
||||
"github.com/kyverno/chainsaw/pkg/mocks"
|
||||
"github.com/stretchr/testify/assert"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
|
@ -179,8 +179,8 @@ func Test_update(t *testing.T) {
|
|||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
logger := &tlogging.FakeLogger{}
|
||||
ctx := logging.IntoContext(context.TODO(), logger)
|
||||
logger := &mocks.Logger{}
|
||||
ctx := logging.WithLogger(context.TODO(), logger)
|
||||
toCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
ctx = toCtx
|
||||
|
|
|
@ -26,7 +26,7 @@ func Process(ctx context.Context, compilers compilers.Compilers, tc apis.Binding
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tc = bindings.RegisterBinding(ctx, tc, name, value)
|
||||
tc = bindings.RegisterBinding(tc, name, value)
|
||||
if results == nil {
|
||||
results = Outputs{}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package engine
|
||||
|
||||
import (
|
||||
"github.com/kyverno/chainsaw/pkg/engine/context"
|
||||
"github.com/kyverno/chainsaw/pkg/engine/namespacer"
|
||||
)
|
||||
|
||||
type (
|
||||
Context = context.TestContext
|
||||
Namespacer = namespacer.Namespacer
|
||||
)
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package logging
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type sinkKey struct{}
|
||||
|
||||
type loggerKey struct{}
|
||||
|
||||
func WithSink(ctx context.Context, sink Sink) context.Context {
|
||||
return context.WithValue(ctx, sinkKey{}, sink)
|
||||
}
|
||||
|
||||
func getSink(ctx context.Context) Sink {
|
||||
if ctx != nil {
|
||||
if v, ok := ctx.Value(sinkKey{}).(Sink); ok {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func WithLogger(ctx context.Context, logger Logger) context.Context {
|
||||
return context.WithValue(ctx, loggerKey{}, logger)
|
||||
}
|
||||
|
||||
func getLogger(ctx context.Context) Logger {
|
||||
if ctx != nil {
|
||||
if v, ok := ctx.Value(loggerKey{}).(Logger); ok {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package logging
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestWithSink(t *testing.T) {
|
||||
var f SinkFunc = func(string, string, Operation, Status, client.Object, *color.Color, ...fmt.Stringer) {
|
||||
}
|
||||
ctx := context.Background()
|
||||
assert.NotNil(t, ctx)
|
||||
ctx = WithSink(ctx, f)
|
||||
assert.NotNil(t, ctx)
|
||||
}
|
||||
|
||||
func Test_getSink(t *testing.T) {
|
||||
var f SinkFunc = func(string, string, Operation, Status, client.Object, *color.Color, ...fmt.Stringer) {
|
||||
}
|
||||
ctx := context.Background()
|
||||
assert.NotNil(t, ctx)
|
||||
assert.Nil(t, getSink(ctx))
|
||||
ctx = WithSink(ctx, f)
|
||||
assert.NotNil(t, ctx)
|
||||
assert.NotNil(t, getSink(ctx))
|
||||
}
|
||||
|
||||
func TestWithLogger(t *testing.T) {
|
||||
var f LoggerFunc = func(context.Context, Operation, Status, client.Object, *color.Color, ...fmt.Stringer) {
|
||||
}
|
||||
ctx := context.Background()
|
||||
assert.NotNil(t, ctx)
|
||||
ctx = WithLogger(ctx, f)
|
||||
assert.NotNil(t, ctx)
|
||||
}
|
||||
|
||||
func Test_getLogger(t *testing.T) {
|
||||
var f LoggerFunc = func(context.Context, Operation, Status, client.Object, *color.Color, ...fmt.Stringer) {
|
||||
}
|
||||
ctx := context.Background()
|
||||
assert.NotNil(t, ctx)
|
||||
assert.Nil(t, getLogger(ctx))
|
||||
ctx = WithLogger(ctx, f)
|
||||
assert.NotNil(t, ctx)
|
||||
assert.NotNil(t, getLogger(ctx))
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package logging
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
)
|
||||
|
||||
func Log(ctx context.Context, operation Operation, status Status, obj client.Object, color *color.Color, args ...fmt.Stringer) {
|
||||
if logger := getLogger(ctx); logger != nil {
|
||||
logger.Log(ctx, operation, status, obj, color, args...)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package logging
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
func TestLog(t *testing.T) {
|
||||
called := false
|
||||
_operation := Create
|
||||
_status := BeginStatus
|
||||
_obj := &unstructured.Unstructured{}
|
||||
_color := color.New(color.FgBlue)
|
||||
_args := []fmt.Stringer{Section("arg1"), Section("arg2")}
|
||||
var f LoggerFunc = func(_ context.Context, operation Operation, status Status, obj client.Object, color *color.Color, args ...fmt.Stringer) {
|
||||
assert.Equal(t, _operation, operation)
|
||||
assert.Equal(t, _status, status)
|
||||
assert.Equal(t, _obj, obj)
|
||||
assert.Equal(t, _color, color)
|
||||
assert.Equal(t, _args, args)
|
||||
called = true
|
||||
}
|
||||
ctx := context.Background()
|
||||
assert.NotNil(t, ctx)
|
||||
assert.Nil(t, getLogger(ctx))
|
||||
Log(ctx, _operation, _status, _obj, _color, _args...)
|
||||
assert.False(t, called)
|
||||
ctx = WithLogger(ctx, f)
|
||||
Log(ctx, _operation, _status, _obj, _color, _args...)
|
||||
assert.True(t, called)
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package logging
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
)
|
||||
|
||||
type Logger interface {
|
||||
Log(context.Context, Operation, Status, client.Object, *color.Color, ...fmt.Stringer)
|
||||
}
|
||||
|
||||
type LoggerFunc func(context.Context, Operation, Status, client.Object, *color.Color, ...fmt.Stringer)
|
||||
|
||||
func (f LoggerFunc) Log(ctx context.Context, operation Operation, status Status, obj client.Object, color *color.Color, args ...fmt.Stringer) {
|
||||
f(ctx, operation, status, obj, color, args...)
|
||||
}
|
||||
|
||||
func NewLogger(test string, step string) LoggerFunc {
|
||||
return func(ctx context.Context, operation Operation, status Status, obj client.Object, color *color.Color, args ...fmt.Stringer) {
|
||||
if sink := getSink(ctx); sink != nil {
|
||||
sink.Log(test, step, operation, status, obj, color, args...)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package logging
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/kyverno/chainsaw/pkg/client"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
func TestLoggerFunc_Log(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
test string
|
||||
step string
|
||||
operation Operation
|
||||
status Status
|
||||
obj client.Object
|
||||
color *color.Color
|
||||
args []fmt.Stringer
|
||||
}{{
|
||||
test: "test",
|
||||
step: "step",
|
||||
operation: Create,
|
||||
status: BeginStatus,
|
||||
obj: &unstructured.Unstructured{},
|
||||
color: color.New(color.FgBlue),
|
||||
args: []fmt.Stringer{Section("arg1"), Section("arg2")},
|
||||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
called := false
|
||||
var f SinkFunc = func(test, step string, operation Operation, status Status, obj client.Object, color *color.Color, args ...fmt.Stringer) {
|
||||
assert.Equal(t, tt.test, test)
|
||||
assert.Equal(t, tt.step, step)
|
||||
assert.Equal(t, tt.operation, operation)
|
||||
assert.Equal(t, tt.status, status)
|
||||
assert.Equal(t, tt.obj, obj)
|
||||
assert.Equal(t, tt.color, color)
|
||||
assert.Equal(t, tt.args, args)
|
||||
called = true
|
||||
}
|
||||
ctx := context.Background()
|
||||
ctx = WithSink(ctx, f)
|
||||
logger := NewLogger(tt.test, tt.step)
|
||||
logger.Log(ctx, tt.operation, tt.status, tt.obj, tt.color, tt.args...)
|
||||
assert.True(t, called)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package logging
|
||||
|
||||
type Operation string
|
||||
|
||||
const (
|
||||
Apply Operation = "APPLY"
|
||||
Assert Operation = "ASSERT"
|
||||
Catch Operation = "CATCH"
|
||||
Cleanup Operation = "CLEANUP"
|
||||
Command Operation = "CMD"
|
||||
Create Operation = "CREATE"
|
||||
Delete Operation = "DELETE"
|
||||
Error Operation = "ERROR"
|
||||
Finally Operation = "FINALLY"
|
||||
Get Operation = "GET"
|
||||
Internal Operation = "INTERNAL"
|
||||
Patch Operation = "PATCH"
|
||||
Script Operation = "SCRIPT"
|
||||
Sleep Operation = "SLEEP"
|
||||
Stderr Operation = "STDERR"
|
||||
Stdout Operation = "STDOUT"
|
||||
Try Operation = "TRY"
|
||||
Update Operation = "UPDATE"
|
||||
)
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue