Skip to content

Commit 7712ec3

Browse files
committed
Consider all SHA's of a reference, including manifests
1 parent a193a71 commit 7712ec3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1796
-630
lines changed

.github/workflows/build-test.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ jobs:
1919
steps:
2020
- name: Checkout code
2121
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
22+
2223
- name: Setup Golang
2324
uses: actions/setup-go@v5
2425
with:
2526
go-version-file: go.mod
27+
2628
- name: Run golangci-lint
2729
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
2830
with:
@@ -34,6 +36,10 @@ jobs:
3436
runs-on: ubuntu-latest
3537
name: Run govulncheck
3638
steps:
39+
# We only need to checkout as govuln does the go setup...
40+
- name: Checkout code
41+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
42+
3743
- id: govulncheck
3844
uses: golang/govulncheck-action@v1
3945
with:
@@ -45,8 +51,9 @@ jobs:
4551
runs-on: ubuntu-latest
4652
steps:
4753
- name: Checkout code
48-
uses: actions/checkout@v4 # v3.5.3
49-
- name: Setup Go
54+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
55+
56+
- name: Setup Golang
5057
uses: actions/setup-go@v5
5158
with:
5259
go-version-file: go.mod
@@ -88,6 +95,7 @@ jobs:
8895
steps:
8996
- name: Checkout code
9097
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
98+
9199
- name: Set up QEMU
92100
uses: docker/setup-qemu-action@v3
93101

@@ -106,6 +114,9 @@ jobs:
106114
tags: quay.io/jetstack/version-checker:${{github.sha}}
107115
cache-from: type=gha
108116
cache-to: type=gha,mode=max
117+
attests: |-
118+
type=sbom,generator=image
119+
type=provenance,mode=max
109120
110121
- name: Run Trivy vulnerability scanner
111122
uses: aquasecurity/trivy-action@0.30.0

.github/workflows/helm-docs.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ on:
44
workflow_call:
55
push:
66
paths:
7-
- '!*.md'
8-
- 'deploy/charts/version-checker/**'
7+
- "!*.md"
8+
- "deploy/charts/version-checker/**"
99
branches:
1010
- main
1111

.github/workflows/helm-test.yaml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ name: Test Helm Chart
22
on:
33
pull_request:
44
paths:
5-
- '!*.md'
6-
- 'deploy/charts/version-checker/**'
5+
- "!*.md"
6+
- "deploy/charts/version-checker/**"
77
branches:
8-
- 'main'
8+
- "main"
99

1010
concurrency:
1111
group: ${{ github.workflow }}-${{ github.ref }}
@@ -14,14 +14,19 @@ concurrency:
1414
jobs:
1515
lint:
1616
permissions:
17-
contents: read # for actions/checkout to fetch code
18-
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
17+
contents: read # for actions/checkout to fetch code
18+
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
1919
name: Lint Helm Chart
2020
runs-on: ubuntu-latest
2121
steps:
2222
- name: Checkout code
2323
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
2424

25+
- name: Setup Golang
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version-file: go.mod
29+
2530
- uses: azure/setup-helm@v4
2631

2732
- run: helm lint deploy/charts/version-checker
@@ -33,9 +38,12 @@ jobs:
3338
- name: Checkout code
3439
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
3540

36-
- uses: azure/setup-helm@v4
41+
- name: Setup Golang
42+
uses: actions/setup-go@v5
3743
with:
38-
token: ${{ github.token }}
44+
go-version-file: go.mod
45+
46+
- uses: azure/setup-helm@v4
3947

4048
- name: Install helm Plugins
4149
run: |
@@ -57,7 +65,9 @@ jobs:
5765
steps:
5866
- name: Checkout code
5967
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
68+
6069
- name: Install Kyverno CLI
6170
uses: kyverno/action-install-cli@v0.2.0
62-
- uses: azure/setup-helm@v4
63-
- run: kyverno apply -p https://github.com/kyverno/policies/pod-security/restricted --git-branch main --resource <(helm template deploy/charts/version-checker/)
71+
72+
- run: |-
73+
kyverno apply -p https://github.com/kyverno/policies/pod-security/restricted --git-branch main --resource <(helm template deploy/charts/version-checker/)

.github/workflows/release.yaml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@ jobs:
1515
prepare-release:
1616
# Don't push back to a tag!
1717
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
18-
name: Prepair release
18+
name: Prepare release
1919
runs-on: ubuntu-latest
2020
permissions:
2121
pull-requests: write
2222
contents: write
2323
steps:
24-
- uses: actions/checkout@v4
24+
- name: Checkout code
25+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
26+
- name: Setup Golang
27+
uses: actions/setup-go@v5
2528
with:
26-
fetch-depth: 0
29+
go-version-file: go.mod
30+
2731
- uses: bhowell2/github-substring-action@1.0.2
2832
id: release_number
2933
with:
@@ -113,10 +117,8 @@ jobs:
113117
helm-release:
114118
runs-on: ubuntu-latest
115119
steps:
116-
# Checkout our Repo
117-
- uses: actions/checkout@v4
118-
with:
119-
path: version-checker
120+
- name: Checkout code
121+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
120122

121123
- name: checkout jetstack-charts
122124
uses: actions/checkout@v4
@@ -134,6 +136,9 @@ jobs:
134136
run: |
135137
helm package version-checker/deploy/charts/version-checker -d jetstack-charts/charts/
136138
139+
- name: Login to Quay.io
140+
run: echo "${{ secrets.QUAY_ROBOT_TOKEN }}" | helm registry login quay.io -u ${{ secrets.QUAY_USERNAME }} --password-stdin
141+
137142
- name: Creating PR
138143
if: startsWith(github.ref, 'refs/tags/')
139144
uses: peter-evans/create-pull-request@v7
@@ -149,10 +154,16 @@ jobs:
149154
base: main
150155
draft: ${{ !startsWith(github.ref, 'refs/tags/') }}
151156

157+
- name: Push to Quay
158+
run: |-
159+
helm push jetstack-charts/charts/version-checker-${{ github.ref_name }}.tgz oci://quay.io/quay.io/jetstack/version-checker/chart
160+
152161
docker-release:
153162
runs-on: ubuntu-latest
154163
steps:
155-
- uses: actions/checkout@v4
164+
- name: Checkout code
165+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
166+
156167
- name: Set up QEMU
157168
uses: docker/setup-qemu-action@v3
158169

@@ -185,8 +196,6 @@ jobs:
185196
contents: write
186197
runs-on: ubuntu-latest
187198
steps:
188-
- uses: actions/checkout@v4
189-
190199
- name: Create Release / Change Logs
191200
uses: softprops/action-gh-release@v2
192201
with:

cmd/app/app.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func NewCommand(ctx context.Context) *cobra.Command {
5959
return fmt.Errorf("failed to build kubernetes rest config: %s", err)
6060
}
6161

62-
log.Infof("flag --test-all-containers=%t %s", opts.DefaultTestAll, defaultTestAllInfoMsg)
62+
log.Warnf("flag --test-all-containers=%t %s", opts.DefaultTestAll, defaultTestAllInfoMsg)
6363

6464
mgr, err := ctrl.NewManager(restConfig, ctrl.Options{
6565
LeaderElection: false,
@@ -115,6 +115,7 @@ func NewCommand(ctx context.Context) *cobra.Command {
115115
client,
116116
mgr.GetClient(),
117117
log,
118+
opts.RequeueDuration,
118119
opts.DefaultTestAll,
119120
)
120121

cmd/app/options.go

Lines changed: 74 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,26 @@ var (
6464

6565
// Options is a struct to hold options for the version-checker.
6666
type Options struct {
67+
kubeConfigFlags *genericclioptions.ConfigFlags
68+
69+
Client client.Options
6770
MetricsServingAddress string
68-
DefaultTestAll bool
69-
CacheTimeout time.Duration
7071
LogLevel string
7172

72-
PprofBindAddress string
73+
PprofBindAddress string
74+
selfhosted selfhosted.Options
75+
76+
CacheTimeout time.Duration
77+
RequeueDuration time.Duration
7378
GracefulShutdownTimeout time.Duration
7479
CacheSyncPeriod time.Duration
7580

76-
kubeConfigFlags *genericclioptions.ConfigFlags
77-
selfhosted selfhosted.Options
81+
DefaultTestAll bool
82+
}
7883

79-
Client client.Options
84+
type envMatcher struct {
85+
re *regexp.Regexp
86+
action func(matches []string, value string)
8087
}
8188

8289
func (o *Options) addFlags(cmd *cobra.Command) {
@@ -124,6 +131,10 @@ func (o *Options) addAppFlags(fs *pflag.FlagSet) {
124131
"The time for an image version in the cache to be considered fresh. Images "+
125132
"will be rechecked after this interval.")
126133

134+
fs.DurationVarP(&o.RequeueDuration,
135+
"requeue-duration", "r", time.Hour,
136+
"The time a pod will be re-checked for new versions/tags")
137+
127138
fs.StringVarP(&o.LogLevel,
128139
"log-level", "v", "info",
129140
"Log level (debug, info, warn, error, fatal, panic).")
@@ -358,56 +369,81 @@ func (o *Options) assignSelfhosted(envs []string) {
358369
}
359370

360371
initOptions := func(name string) {
372+
if name == "" {
373+
panic("Not meant to be empty!")
374+
}
361375
if o.Client.Selfhosted[name] == nil {
362376
o.Client.Selfhosted[name] = new(selfhosted.Options)
363377
}
364378
}
365379

366-
regexActions := map[*regexp.Regexp]func(matches []string, value string){
367-
selfhostedHostReg: func(matches []string, value string) {
368-
initOptions(matches[1])
369-
o.Client.Selfhosted[matches[1]].Host = value
380+
// Go maps iterate in random order - Using a slice to consistency
381+
regexActions := []envMatcher{
382+
{
383+
re: selfhostedTokenPath,
384+
action: func(matches []string, value string) {
385+
initOptions(matches[1])
386+
o.Client.Selfhosted[matches[1]].TokenPath = value
387+
},
370388
},
371-
selfhostedUsernameReg: func(matches []string, value string) {
372-
initOptions(matches[1])
373-
o.Client.Selfhosted[matches[1]].Username = value
389+
{
390+
re: selfhostedTokenReg,
391+
action: func(matches []string, value string) {
392+
initOptions(matches[1])
393+
o.Client.Selfhosted[matches[1]].Bearer = value
394+
},
374395
},
375-
selfhostedPasswordReg: func(matches []string, value string) {
376-
initOptions(matches[1])
377-
o.Client.Selfhosted[matches[1]].Password = value
396+
// All your other patterns (host, username, password, insecure, capath...)
397+
{
398+
re: selfhostedHostReg,
399+
action: func(matches []string, value string) {
400+
initOptions(matches[1])
401+
o.Client.Selfhosted[matches[1]].Host = value
402+
},
378403
},
379-
selfhostedTokenPath: func(matches []string, value string) {
380-
initOptions(matches[1])
381-
o.Client.Selfhosted[matches[1]].TokenPath = value
404+
{
405+
re: selfhostedUsernameReg,
406+
action: func(matches []string, value string) {
407+
initOptions(matches[1])
408+
o.Client.Selfhosted[matches[1]].Username = value
409+
},
382410
},
383-
selfhostedTokenReg: func(matches []string, value string) {
384-
initOptions(matches[1])
385-
o.Client.Selfhosted[matches[1]].Bearer = value
411+
{
412+
re: selfhostedPasswordReg,
413+
action: func(matches []string, value string) {
414+
initOptions(matches[1])
415+
o.Client.Selfhosted[matches[1]].Password = value
416+
},
386417
},
387-
selfhostedInsecureReg: func(matches []string, value string) {
388-
initOptions(matches[1])
389-
if val, err := strconv.ParseBool(value); err == nil {
390-
o.Client.Selfhosted[matches[1]].Insecure = val
391-
}
418+
{
419+
re: selfhostedInsecureReg,
420+
action: func(matches []string, value string) {
421+
initOptions(matches[1])
422+
if b, err := strconv.ParseBool(value); err == nil {
423+
o.Client.Selfhosted[matches[1]].Insecure = b
424+
}
425+
},
392426
},
393-
selfhostedCAPath: func(matches []string, value string) {
394-
initOptions(matches[1])
395-
o.Client.Selfhosted[matches[1]].CAPath = value
427+
{
428+
re: selfhostedCAPath,
429+
action: func(matches []string, value string) {
430+
initOptions(matches[1])
431+
o.Client.Selfhosted[matches[1]].CAPath = value
432+
},
396433
},
397434
}
398435

399436
for _, env := range envs {
400-
pair := strings.SplitN(env, "=", 2)
401-
if len(pair) != 2 || len(pair[1]) == 0 {
437+
parts := strings.SplitN(env, "=", 2)
438+
if len(parts) != 2 || parts[1] == "" {
402439
continue
403440
}
441+
key := strings.ToUpper(parts[0])
442+
val := parts[1]
404443

405-
key := strings.ToUpper(pair[0])
406-
value := pair[1]
407-
408-
for regex, action := range regexActions {
409-
if matches := regex.FindStringSubmatch(key); len(matches) == 2 {
410-
action(matches, value)
444+
for _, p := range regexActions {
445+
if match := p.re.FindStringSubmatch(key); len(match) == 2 {
446+
p.action(match, val)
411447
break
412448
}
413449
}

0 commit comments

Comments
 (0)