Skip to content

Commit 3aad628

Browse files
authored
Nonstandard sa name (#37)
* klone upgrade Signed-off-by: Abhijeet V <[email protected]> * upgraded dependencies Signed-off-by: Abhijeet V <[email protected]> * fallback to non-standard service account name Signed-off-by: Abhijeet V <[email protected]> --------- Signed-off-by: Abhijeet V <[email protected]>
1 parent 8faf860 commit 3aad628

Some content is hidden

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

49 files changed

+1265
-1316
lines changed

.github/dependabot.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
2-
# Edit https://github.com/cert-manager/makefile-modules/blob/main/modules/repository-base/base/.github/dependabot.yaml instead.
2+
# Edit https://github.com/cert-manager/makefile-modules/blob/main/modules/repository-base/base-dependabot/.github/dependabot.yaml instead.
33

4-
# Update Go dependencies and GitHub Actions dependencies weekly.
4+
# Update Go dependencies and GitHub Actions dependencies daily.
55
version: 2
66
updates:
77
- package-ecosystem: gomod
88
directory: /
99
schedule:
10-
interval: weekly
10+
interval: daily
1111
groups:
1212
all:
1313
patterns: ["*"]
1414
- package-ecosystem: github-actions
1515
directory: /
1616
schedule:
17-
interval: weekly
17+
interval: daily
1818
groups:
1919
all:
2020
patterns: ["*"]

.github/workflows/make-self-upgrade.yaml

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,49 @@ name: make-self-upgrade
55
concurrency: make-self-upgrade
66
on:
77
workflow_dispatch: {}
8-
# schedule:
9-
# - cron: '0 0 * * *'
8+
# schedule:
9+
# - cron: '0 0 * * *'
10+
11+
permissions:
12+
contents: read
1013

1114
jobs:
12-
build_images:
15+
self_upgrade:
1316
runs-on: ubuntu-latest
1417

18+
if: github.repository_owner == 'AthenZ'
19+
1520
permissions:
1621
contents: write
1722
pull-requests: write
23+
24+
env:
25+
SOURCE_BRANCH: "${{ github.ref_name }}"
26+
SELF_UPGRADE_BRANCH: "self-upgrade-${{ github.ref_name }}"
1827

1928
steps:
20-
- name: Fail if branch is not main
21-
if: github.ref != 'refs/heads/main'
29+
- name: Fail if branch is not head of branch.
30+
if: ${{ !startsWith(github.ref, 'refs/heads/') && env.SOURCE_BRANCH != '' && env.SELF_UPGRADE_BRANCH != '' }}
2231
run: |
23-
echo "This workflow should not be run on a branch other than main."
32+
echo "This workflow should not be run on a non-branch-head."
2433
exit 1
2534
26-
- uses: actions/checkout@v4
35+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
36+
# Adding `fetch-depth: 0` makes sure tags are also fetched. We need
37+
# the tags so `git describe` returns a valid version.
38+
# see https://github.com/actions/checkout/issues/701 for extra info about this option
39+
with: { fetch-depth: 0 }
2740

2841
- id: go-version
2942
run: |
3043
make print-go-version >> "$GITHUB_OUTPUT"
3144
32-
- uses: actions/setup-go@v5
45+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
3346
with:
3447
go-version: ${{ steps.go-version.outputs.result }}
3548

3649
- run: |
37-
git checkout -B "self-upgrade"
50+
git checkout -B "$SELF_UPGRADE_BRANCH"
3851
3952
- run: |
4053
make -j upgrade-klone
@@ -57,30 +70,36 @@ jobs:
5770
git config --global user.name "athenz-bot"
5871
git config --global user.email "[email protected]"
5972
git add -A && git commit -m "BOT: run 'make upgrade-klone' and 'make generate'" --signoff
60-
git push -f origin self-upgrade
73+
git push -f origin "$SELF_UPGRADE_BRANCH"
6174
6275
- if: ${{ steps.is-up-to-date.outputs.result != 'true' }}
63-
uses: actions/github-script@v7
76+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
6477
with:
6578
script: |
6679
const { repo, owner } = context.repo;
6780
const pulls = await github.rest.pulls.list({
6881
owner: owner,
6982
repo: repo,
70-
head: owner + ':self-upgrade',
71-
base: 'main',
83+
head: owner + ':' + process.env.SELF_UPGRADE_BRANCH,
84+
base: process.env.SOURCE_BRANCH,
7285
state: 'open',
7386
});
7487
7588
if (pulls.data.length < 1) {
76-
await github.rest.pulls.create({
77-
title: '[CI] Merge self-upgrade into main',
89+
const result = await github.rest.pulls.create({
90+
title: '[CI] Merge ' + process.env.SELF_UPGRADE_BRANCH + ' into ' + process.env.SOURCE_BRANCH,
7891
owner: owner,
7992
repo: repo,
80-
head: 'self-upgrade',
81-
base: 'main',
93+
head: process.env.SELF_UPGRADE_BRANCH,
94+
base: process.env.SOURCE_BRANCH,
8295
body: [
8396
'This PR is auto-generated to bump the Makefile modules.',
8497
].join('\n'),
8598
});
99+
await github.rest.issues.addLabels({
100+
owner,
101+
repo,
102+
issue_number: result.data.number,
103+
labels: ['skip-review']
104+
});
86105
}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ _bin
2727
_certs
2828
.vscode
2929

30-
scratch.txt
30+
scratch.txt
31+
.idea/

.golangci.yaml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
version: "2"
2+
linters:
3+
default: none
4+
exclusions:
5+
generated: lax
6+
presets: [comments, common-false-positives, legacy, std-error-handling]
7+
paths: [third_party, builtin$, examples$]
8+
warn-unused: true
9+
settings:
10+
staticcheck:
11+
checks: ["all", "-ST1000", "-ST1001", "-ST1003", "-ST1005", "-ST1012", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-QF1001", "-QF1003", "-QF1008"]
12+
enable:
13+
- asasalint
14+
- asciicheck
15+
- bidichk
16+
- bodyclose
17+
- canonicalheader
18+
- contextcheck
19+
- copyloopvar
20+
- decorder
21+
- dogsled
22+
- dupword
23+
- durationcheck
24+
- errcheck
25+
- errchkjson
26+
- errname
27+
- exhaustive
28+
- exptostd
29+
- forbidigo
30+
- ginkgolinter
31+
- gocheckcompilerdirectives
32+
- gochecksumtype
33+
- gocritic
34+
- goheader
35+
- goprintffuncname
36+
- gosec
37+
- gosmopolitan
38+
- govet
39+
- grouper
40+
- importas
41+
- ineffassign
42+
- interfacebloat
43+
- intrange
44+
- loggercheck
45+
- makezero
46+
- mirror
47+
- misspell
48+
- musttag
49+
- nakedret
50+
- nilerr
51+
- nilnil
52+
- noctx
53+
- nosprintfhostport
54+
- predeclared
55+
- promlinter
56+
- protogetter
57+
- reassign
58+
- sloglint
59+
- staticcheck
60+
- tagalign
61+
- testableexamples
62+
- unconvert
63+
- unparam
64+
- unused
65+
- usestdlibvars
66+
- usetesting
67+
- wastedassign
68+
formatters:
69+
enable: [gci, gofmt]
70+
settings:
71+
gci:
72+
sections:
73+
- standard # Standard section: captures all standard packages.
74+
- default # Default section: contains all imports that could not be matched to another section type.
75+
- prefix(github.com/AthenZ/athenz-issuer) # Custom section: groups all imports with the specified Prefix.
76+
- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
77+
- dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
78+
exclusions:
79+
generated: lax
80+
paths: [third_party, builtin$, examples$]

Makefile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The Athenz Authors.
1+
# Copyright 2023 The cert-manager Authors.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@
3030
##################################
3131

3232
# Some modules build their dependencies from variables, we want these to be
33-
# evalutated at the last possible moment. For this we use second expansion to
33+
# evaluated at the last possible moment. For this we use second expansion to
3434
# re-evaluate the generate and verify targets a second time.
3535
#
3636
# See https://www.gnu.org/software/make/manual/html_node/Secondary-Expansion.html
@@ -48,6 +48,10 @@ FORCE:
4848

4949
noop: # do nothing
5050

51+
# Set empty value for MAKECMDGOALS to prevent the "warning: undefined variable 'MAKECMDGOALS'"
52+
# warning from happening when running make without arguments
53+
MAKECMDGOALS ?=
54+
5155
##################################
5256
# Host OS and architecture setup #
5357
##################################
@@ -56,8 +60,10 @@ noop: # do nothing
5660
# binary may not be available in the PATH yet when the Makefiles are
5761
# evaluated. HOST_OS and HOST_ARCH only support Linux, *BSD and macOS (M1
5862
# and Intel).
59-
HOST_OS ?= $(shell uname -s | tr A-Z a-z)
60-
HOST_ARCH ?= $(shell uname -m)
63+
host_os := $(shell uname -s | tr A-Z a-z)
64+
host_arch := $(shell uname -m)
65+
HOST_OS ?= $(host_os)
66+
HOST_ARCH ?= $(host_arch)
6167

6268
ifeq (x86_64, $(HOST_ARCH))
6369
HOST_ARCH = amd64
@@ -70,7 +76,8 @@ endif
7076
# Git and versioning information #
7177
##################################
7278

73-
VERSION ?= $(shell git describe --tags --always --match='v*' --abbrev=14 --dirty)
79+
git_version := $(shell git describe --tags --always --match='v*' --abbrev=14 --dirty)
80+
VERSION ?= $(git_version)
7481
IS_PRERELEASE := $(shell git describe --tags --always --match='v*' --abbrev=0 | grep -q '-' && echo true || echo false)
7582
GITCOMMIT := $(shell git rev-parse HEAD)
7683
GITEPOCH := $(shell git show -s --format=%ct HEAD)

controller/signer.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ func (s *Signer) Check(ctx context.Context, issuerObject v1alpha1.Issuer) error
102102
}
103103
// create zts client
104104
tr := &http.Transport{
105-
TLSClientConfig: &tls.Config{},
106-
Proxy: http.ProxyFromEnvironment,
105+
TLSClientConfig: &tls.Config{},
106+
Proxy: http.ProxyFromEnvironment,
107107
DisableKeepAlives: true,
108108
}
109109

@@ -215,7 +215,13 @@ func getServiceAccountTokenFromAPIServer(namespaceName string, ctx context.Conte
215215

216216
sa, err := clientset.CoreV1().ServiceAccounts(namespaceName).Get(ctx, spiffeSA, metav1.GetOptions{})
217217
if err != nil {
218-
return "", fmt.Errorf("failed to get service account: %w", err)
218+
// try with a fallback service account name
219+
_, fallbackSA := issuerutil.ExtractDomainServiceFromServiceAccount(spiffeSA)
220+
sa, err = clientset.CoreV1().ServiceAccounts(namespaceName).Get(ctx, fallbackSA, metav1.GetOptions{})
221+
if err != nil {
222+
// if we still can't find the service account, return an error
223+
return "", fmt.Errorf("failed to get service account %s or %s in namespace %s: %w", spiffeSA, fallbackSA, namespaceName, err)
224+
}
219225
}
220226

221227
tr := &authenticationv1.TokenRequest{

deploy/charts/athenz-issuer/templates/crd-cert-manager.athenz.io_athenzclusterissuers.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ spec:
136136
storage: true
137137
subresources:
138138
status: {}
139-
{{- end }}
139+
{{- end }}

deploy/charts/athenz-issuer/templates/crd-cert-manager.athenz.io_athenzissuers.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ spec:
136136
storage: true
137137
subresources:
138138
status: {}
139-
{{- end }}
139+
{{- end }}

0 commit comments

Comments
 (0)