Skip to content

Commit ad7a9f3

Browse files
authored
Merge pull request #38 from SgtCoDFish/cleanup
Small cleanups of code
2 parents e113236 + 14c5cfa commit ad7a9f3

File tree

10 files changed

+27
-27
lines changed

10 files changed

+27
-27
lines changed

README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
# cert-manager release tooling
1+
# cert-manager Release Tooling
22

33
This repository contains release tooling for the cert-manager project.
44

5+
NB: The most up-to-date release process is documented on the [cert-manager website](https://cert-manager.io/docs/contributing/release-process/).
6+
If you're trying to do a cert-manager release, you should start on the website. The docs
7+
here are mostly intended for people developing cert-manager tooling.
8+
59
## cmrel
610

711
cmrel is the central hub for release managers interacting with the release
@@ -13,7 +17,7 @@ It has 3 primary functions:
1317
* Listing staged releases
1418
* Publishing a staged release
1519

16-
### Creating an official release
20+
### Creating an Official Release
1721

1822
> *WARNING*: following these steps exactly will push out a *public facing release*!
1923
> Please use this as an example *only*.
@@ -37,7 +41,7 @@ For example purposes, we'll:
3741
The `cmrel` tool provides a subcommand to start this process, `cmrel stage`.
3842
Full usage information for `cmrel stage`:
3943

40-
```
44+
```text
4145
Flags:
4246
--branch string The git branch to build the release from. If --git-ref is not specified, the HEAD of this branch will be looked up on GitHub. (default "master")
4347
--bucket string The name of the GCS bucket to stage the release to. (default "cert-manager-release")
@@ -61,7 +65,7 @@ to publish to.
6165

6266
We'll run `cmrel stage` below to start a GCB job to stage the release:
6367

64-
```
68+
```console
6569
$ cmrel stage \
6670
--branch release-0.14 \
6771
--release-version v0.14.0
@@ -75,7 +79,7 @@ follow along and view logs to track the build progress.
7579

7680
Once complete, `cmrel stage` should exit successfully.
7781

78-
#### Step 2 - listing staged builds
82+
#### Step 2 - Listing Staged Builds
7983

8084
After a build has been staged, it's important that you verify the release has
8185
been published to the bucket as expected.
@@ -85,7 +89,7 @@ staged to the release bucket.
8589

8690
Full usage information for `cmrel staged`:
8791

88-
```
92+
```text
8993
Flags:
9094
--bucket string The name of the GCS bucket containing the staged releases. (default "cert-manager-release")
9195
--git-ref string Optional specific git reference to list staged releases for - if specified, --release-version must also be specified.
@@ -96,7 +100,7 @@ Flags:
96100

97101
Running it will print a list of staged releases:
98102

99-
```
103+
```console
100104
$ cmrel staged
101105
...
102106
NAME VERSION DATE
@@ -110,7 +114,7 @@ that the correct revision of cert-manager has in fact been built.
110114
Once you have found the release you wish to stage in this list, make a note of
111115
the release's `name` and proceed to step 3!
112116

113-
#### Step 3 - publishing a staged release
117+
#### Step 3 - Publishing a Staged Release
114118

115119
Once a release has been staged into the release bucket and we've verified it
116120
has been built from the correct revision of cert-manager, we are now ready to
@@ -119,8 +123,7 @@ trigger the publishing stage of the release.
119123
In this step, the staged release is fetched from Google Cloud Storage,
120124
validated, and then pushed out to public facing locations.
121125

122-
```
123-
126+
```console
124127
$ cmrel publish \
125128
--release-name v0.14.0-f6da9c76877551ef32503b17189bb178501f59a7 \
126129
--nomock
@@ -140,15 +143,15 @@ If you are intending to publish to your own, private release buckets (i.e. to
140143
test this whole workflow, or for creating internal releases) you should be sure
141144
to set the following flags when calling `cmrel publish`:
142145

143-
```
146+
```text
144147
--published-image-repo='quay.io/mycompany' # prefix for images, e.g. 'quay.io/mycompany'
145148
--published-helm-chart-bucket='mycompany-helm-charts' # name of the GCS bucket where the built Helm chart should be stored
146149
--published-github-org='mycompany' # name of the GitHub org containing the repo that will be tagged at the end
147150
```
148151

149152
### Development
150153

151-
#### Creating development builds
154+
#### Creating Development Builds
152155

153156
By default the artifacts created during a release process are pushed to `cert-manager-release` bucket at `/stage/gcb/release` path.
154157
It is also possible to create a 'development' build by skipping the `--release-version` flag on `cmrel stage` command. This will result in the build artifacts being pushed to `cert-manager-release` bucket at `/stage/gcb/devel` path.

cmd/cmrel/cmd/gcb_stage.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"encoding/json"
2424
"fmt"
2525
"io"
26-
"io/ioutil"
2726
"log"
2827
"os"
2928
"os/exec"
@@ -298,7 +297,7 @@ func readBazelVersion(wd string) (string, error) {
298297
return "", err
299298
}
300299

301-
vBytes, err := ioutil.ReadFile(buildArtifactPath(wd, "version"))
300+
vBytes, err := os.ReadFile(buildArtifactPath(wd, "version"))
302301
if err != nil {
303302
return "", err
304303
}

cmd/cmrel/cmd/staged.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ staging release bucket.
4141

4242
var (
4343
stagedExample = fmt.Sprintf(`
44-
To staged a release of the 'master' branch to the default staging bucket, run:
44+
To staged a release of the 'master' branch to the default staging bucket, run:
4545
4646
%s %s --git-ref=master
4747

gcb/publish/cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ secrets:
2020
steps:
2121

2222
## Clone & checkout the cert-manager release repository
23-
- name: gcr.io/cloud-builders/go
23+
- name: gcr.io/cloud-builders/go:alpine-1.16
2424
dir: "go/src/github.com/cert-manager/release"
2525
entrypoint: sh
2626
args:

gcb/stage/cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ steps:
1313
git clone "${_CM_REPO}" . && git checkout "${_CM_REF}"
1414
1515
## Clone & checkout the cert-manager release repository
16-
- name: gcr.io/cloud-builders/go
16+
- name: gcr.io/cloud-builders/go:alpine-1.16
1717
dir: "go/src/github.com/cert-manager/release"
1818
entrypoint: sh
1919
args:

gcb/test/helm/cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# (Please do not remove this security notice.)
1212
steps:
1313

14-
- name: gcr.io/cloud-builders/go
14+
- name: gcr.io/cloud-builders/go:alpine-1.16
1515
dir: "go/src/github.com/cert-manager/release"
1616
entrypoint: sh
1717
secretEnv:

pkg/gcb/gcb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"context"
2121
"encoding/json"
2222
"fmt"
23-
"io/ioutil"
2423
"log"
24+
"os"
2525
"time"
2626

2727
"google.golang.org/api/cloudbuild/v1"
@@ -37,7 +37,7 @@ const (
3737
// LoadBuild will decode a cloudbuild.yaml file into a cloudbuild.Build
3838
// structure and return it.
3939
func LoadBuild(filename string) (*cloudbuild.Build, error) {
40-
f, err := ioutil.ReadFile(filename)
40+
f, err := os.ReadFile(filename)
4141
if err != nil {
4242
return nil, err
4343
}

pkg/release/helm/helm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package helm
33
import (
44
"context"
55
"fmt"
6-
"io/ioutil"
76
"log"
87
"net/http"
8+
"os"
99
"strings"
1010

1111
"github.com/google/go-github/v35/github"
@@ -182,7 +182,7 @@ func (o *gitHubRepositoryManager) createBranch(ctx context.Context, sourceName,
182182
// commitChartToBranch uploads a single Helm chart to the target branch.
183183
func (o *gitHubRepositoryManager) commitChartToBranch(ctx context.Context, branch string, chart manifests.Chart) error {
184184
chartFileName := chart.PackageFileName()
185-
chartContent, err := ioutil.ReadFile(chart.Path())
185+
chartContent, err := os.ReadFile(chart.Path())
186186
if err != nil {
187187
return errors.WithStack(err)
188188
}

pkg/release/tar/tarball.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"compress/gzip"
2222
"fmt"
2323
"io"
24-
"io/ioutil"
2524
"os"
2625
"path/filepath"
2726
)
@@ -118,7 +117,7 @@ func ReadSingleFile(filename string, r io.Reader) ([]byte, error) {
118117
if header.Typeflag == tar.TypeDir {
119118
return nil, fmt.Errorf("expected path %q to be a file, but it was a directory", filename)
120119
}
121-
return ioutil.ReadAll(tr)
120+
return io.ReadAll(tr)
122121
}
123122
return nil, fmt.Errorf("could not find file %q in tar input", filename)
124123
}

pkg/release/unpacker.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"encoding/hex"
2323
"fmt"
2424
"io"
25-
"io/ioutil"
2625
"log"
2726
"os"
2827
"path/filepath"
@@ -212,7 +211,7 @@ func manifestArtifactForStaged(s *Staged) (*StagedArtifact, error) {
212211
}
213212

214213
func extractStagedArtifactToTempDir(ctx context.Context, a *StagedArtifact) (string, error) {
215-
dest, err := ioutil.TempDir("", "extracted-artifact-")
214+
dest, err := os.MkdirTemp("", "extracted-artifact-")
216215
if err != nil {
217216
return "", err
218217
}
@@ -222,7 +221,7 @@ func extractStagedArtifactToTempDir(ctx context.Context, a *StagedArtifact) (str
222221

223222
func extractStagedArtifact(ctx context.Context, a *StagedArtifact, dest string) error {
224223
// download the file to disk first
225-
f, err := ioutil.TempFile("", "temp-artifact-")
224+
f, err := os.CreateTemp("", "temp-artifact-")
226225
if err != nil {
227226
return err
228227
}

0 commit comments

Comments
 (0)