Skip to content

Commit 4af39ae

Browse files
committed
copy cert-manager code and add makefile & release logic
Signed-off-by: Tim Ramlot <[email protected]>
1 parent 5029f03 commit 4af39ae

File tree

144 files changed

+14604
-1
lines changed

Some content is hidden

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

144 files changed

+14604
-1
lines changed

.github/dependabot.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# 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.
3+
4+
# Update Go dependencies and GitHub Actions dependencies weekly.
5+
version: 2
6+
updates:
7+
- package-ecosystem: gomod
8+
directory: /
9+
schedule:
10+
interval: weekly
11+
groups:
12+
all:
13+
patterns: ["*"]
14+
- package-ecosystem: github-actions
15+
directory: /
16+
schedule:
17+
interval: weekly
18+
groups:
19+
all:
20+
patterns: ["*"]
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
2+
# Edit https://github.com/cert-manager/makefile-modules/blob/main/modules/repository-base/base/.github/workflows/make-self-upgrade.yaml instead.
3+
4+
name: make-self-upgrade
5+
concurrency: make-self-upgrade
6+
on:
7+
workflow_dispatch: {}
8+
schedule:
9+
- cron: '0 0 * * *'
10+
11+
jobs:
12+
build_images:
13+
runs-on: ubuntu-latest
14+
15+
permissions:
16+
contents: write
17+
pull-requests: write
18+
19+
steps:
20+
- name: Fail if branch is not main
21+
if: github.ref != 'refs/heads/main'
22+
run: |
23+
echo "This workflow should not be run on a branch other than main."
24+
exit 1
25+
26+
- uses: actions/checkout@v4
27+
28+
- id: go-version
29+
run: |
30+
make print-go-version >> "$GITHUB_OUTPUT"
31+
32+
- uses: actions/setup-go@v5
33+
with:
34+
go-version: ${{ steps.go-version.outputs.result }}
35+
36+
- run: |
37+
git checkout -B "self-upgrade"
38+
39+
- run: |
40+
make -j upgrade-klone
41+
make -j generate
42+
43+
- id: is-up-to-date
44+
shell: bash
45+
run: |
46+
git_status=$(git status -s)
47+
is_up_to_date="true"
48+
if [ -n "$git_status" ]; then
49+
is_up_to_date="false"
50+
echo "The following changes will be committed:"
51+
echo "$git_status"
52+
fi
53+
echo "result=$is_up_to_date" >> "$GITHUB_OUTPUT"
54+
55+
- if: ${{ steps.is-up-to-date.outputs.result != 'true' }}
56+
run: |
57+
git config --global user.name "jetstack-bot"
58+
git config --global user.email "[email protected]"
59+
git add -A && git commit -m "BOT: run 'make upgrade-klone' and 'make generate'" --signoff
60+
git push -f origin self-upgrade
61+
62+
- if: ${{ steps.is-up-to-date.outputs.result != 'true' }}
63+
uses: actions/github-script@v7
64+
with:
65+
script: |
66+
const { repo, owner } = context.repo;
67+
const pulls = await github.rest.pulls.list({
68+
owner: owner,
69+
repo: repo,
70+
head: owner + ':self-upgrade',
71+
base: 'main',
72+
state: 'open',
73+
});
74+
75+
if (pulls.data.length < 1) {
76+
await github.rest.pulls.create({
77+
title: '[CI] Merge self-upgrade into main',
78+
owner: owner,
79+
repo: repo,
80+
head: 'self-upgrade',
81+
base: 'main',
82+
body: [
83+
'This PR is auto-generated to bump the Makefile modules.',
84+
].join('\n'),
85+
});
86+
}

.github/workflows/release.yaml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: release
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
7+
env:
8+
VERSION: ${{ github.ref_name }}
9+
10+
jobs:
11+
build_images:
12+
runs-on: ubuntu-latest
13+
14+
permissions:
15+
contents: write # needed to write releases
16+
packages: write # needed for push images
17+
id-token: write # needed for keyless signing
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- id: go-version
23+
run: |
24+
make print-go-version >> "$GITHUB_OUTPUT"
25+
26+
- uses: docker/login-action@v3
27+
with:
28+
registry: ghcr.io
29+
username: ${{ github.actor }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- uses: actions/setup-go@v5
33+
with:
34+
go-version: ${{ steps.go-version.outputs.result }}
35+
36+
- env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
run: make release

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/_bin

.goreleaser.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Our Makefile will automatically add additional settings
2+
# to this builds array (environment variables, flags, ...)
3+
builds:
4+
- id: cmctl
5+
- id: kubectl_cert-manager
6+
7+
# config the checksum filename
8+
# https://goreleaser.com/customization/checksum
9+
checksum:
10+
name_template: 'checksums.txt'
11+
12+
# creates SBOMs of all archives and the source tarball using syft
13+
# https://goreleaser.com/customization/sbom
14+
sboms:
15+
- artifacts: binary
16+
documents:
17+
- "{{ .ArtifactName }}{{ .ArtifactExt }}.spdx.sbom"
18+
19+
# signs the checksum file
20+
# all files (including the sboms) are included in the checksum, so we don't need to sign each one if we don't want to
21+
# https://goreleaser.com/customization/sign
22+
signs:
23+
- cmd: cosign
24+
signature: "${artifact}.cosign.bundle"
25+
env:
26+
- COSIGN_EXPERIMENTAL=1
27+
args:
28+
- sign-blob
29+
- '--bundle=${signature}'
30+
- '${artifact}'
31+
- "--yes" # needed on cosign 2.0.0+
32+
artifacts: checksum
33+
output: true
34+
35+
archives:
36+
- name_template: "{{ .Binary }}_{{ .Os }}_{{ .Arch }}"
37+
format: binary
38+
39+
release:
40+
draft: true
41+
make_latest: false

Makefile

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Copyright 2023 The cert-manager Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
16+
# Edit https://github.com/cert-manager/makefile-modules/blob/main/modules/repository-base/base/Makefile instead.
17+
18+
# NOTE FOR DEVELOPERS: "How do the Makefiles work and how can I extend them?"
19+
#
20+
# Shared Makefile logic lives in the make/_shared/ directory. The source of truth for these files
21+
# lies outside of this repository, eg. in the cert-manager/makefile-modules repository.
22+
#
23+
# Logic specific to this repository must be defined in the make/00_mod.mk and make/02_mod.mk files:
24+
# - The make/00_mod.mk file is included first and contains variable definitions needed by
25+
# the shared Makefile logic.
26+
# - The make/02_mod.mk file is included later, it can make use of most of the shared targets
27+
# defined in the make/_shared/ directory (all targets defined in 00_mod.mk and 01_mod.mk).
28+
# This file should be used to define targets specific to this repository.
29+
30+
##################################
31+
32+
MAKEFLAGS += --warn-undefined-variables --no-builtin-rules
33+
SHELL := /usr/bin/env bash
34+
.SHELLFLAGS := -uo pipefail -c
35+
.DEFAULT_GOAL := help
36+
.DELETE_ON_ERROR:
37+
.SUFFIXES:
38+
FORCE:
39+
40+
noop: # do nothing
41+
42+
##################################
43+
# Host OS and architecture setup #
44+
##################################
45+
46+
# The reason we don't use "go env GOOS" or "go env GOARCH" is that the "go"
47+
# binary may not be available in the PATH yet when the Makefiles are
48+
# evaluated. HOST_OS and HOST_ARCH only support Linux, *BSD and macOS (M1
49+
# and Intel).
50+
HOST_OS ?= $(shell uname -s | tr A-Z a-z)
51+
HOST_ARCH ?= $(shell uname -m)
52+
ifeq (x86_64, $(HOST_ARCH))
53+
HOST_ARCH = amd64
54+
endif
55+
56+
##################################
57+
# Git and versioning information #
58+
##################################
59+
60+
VERSION ?= $(shell git describe --tags --always --match='v*' --abbrev=14 --dirty)
61+
IS_PRERELEASE := $(shell git describe --tags --always --match='v*' --abbrev=0 | grep -q '-' && echo true || echo false)
62+
GITCOMMIT := $(shell git rev-parse HEAD)
63+
GITEPOCH := $(shell git show -s --format=%ct HEAD)
64+
65+
##################################
66+
# Global variables and dirs #
67+
##################################
68+
69+
bin_dir := _bin
70+
71+
# The ARTIFACTS environment variable is set by the CI system to a directory
72+
# where artifacts should be placed. These artifacts are then uploaded to a
73+
# storage bucket by the CI system (https://docs.prow.k8s.io/docs/components/pod-utilities/).
74+
# An example of such an artifact is a jUnit XML file containing test results.
75+
# If the ARTIFACTS environment variable is not set, we default to a local
76+
# directory in the _bin directory.
77+
ARTIFACTS ?= $(bin_dir)/artifacts
78+
79+
$(bin_dir) $(ARTIFACTS) $(bin_dir)/scratch:
80+
mkdir -p $@
81+
82+
.PHONY: clean
83+
## Clean all temporary files
84+
## @category [shared] Tools
85+
clean:
86+
rm -rf $(bin_dir)
87+
88+
##################################
89+
# Include all the Makefiles #
90+
##################################
91+
92+
-include make/00_mod.mk
93+
-include make/_shared/*/00_mod.mk
94+
-include make/_shared/*/01_mod.mk
95+
-include make/02_mod.mk
96+
-include make/_shared/*/02_mod.mk

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# ctl
1+
# cmctl

cmd/cmd.go

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
Copyright 2020 The cert-manager Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package cmd
18+
19+
import (
20+
"context"
21+
"fmt"
22+
"io"
23+
24+
"github.com/spf13/cobra"
25+
"github.com/spf13/pflag"
26+
"k8s.io/cli-runtime/pkg/genericclioptions"
27+
"k8s.io/component-base/logs"
28+
29+
logf "github.com/cert-manager/cert-manager/pkg/logs"
30+
"github.com/cert-manager/cmctl/pkg/build"
31+
"github.com/cert-manager/cmctl/pkg/build/commands"
32+
)
33+
34+
func NewCertManagerCtlCommand(ctx context.Context, in io.Reader, out, err io.Writer) *cobra.Command {
35+
ctx = logf.NewContext(ctx, logf.Log)
36+
37+
logOptions := logs.NewOptions()
38+
39+
cmds := &cobra.Command{
40+
Use: build.Name(),
41+
Short: "cert-manager CLI tool to manage and configure cert-manager resources",
42+
Long: build.WithTemplate(`
43+
{{.BuildName}} is a CLI tool manage and configure cert-manager resources for Kubernetes`),
44+
CompletionOptions: cobra.CompletionOptions{
45+
DisableDefaultCmd: true,
46+
},
47+
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
48+
return logf.ValidateAndApply(logOptions)
49+
},
50+
SilenceErrors: true, // Errors are already logged when calling cmd.Execute()
51+
}
52+
cmds.SetUsageTemplate(usageTemplate())
53+
54+
{
55+
var logFlags pflag.FlagSet
56+
logf.AddFlagsNonDeprecated(logOptions, &logFlags)
57+
58+
logFlags.VisitAll(func(f *pflag.Flag) {
59+
switch f.Name {
60+
case "v":
61+
// "cmctl check api" already had a "v" flag that did not require any value, for
62+
// backwards compatibility we allow the "v" logging flag to be set without a value
63+
// and default to "2" (which will result in the same behaviour as before).
64+
f.NoOptDefVal = "2"
65+
cmds.PersistentFlags().AddFlag(f)
66+
default:
67+
cmds.PersistentFlags().AddFlag(f)
68+
}
69+
})
70+
}
71+
72+
ioStreams := genericclioptions.IOStreams{In: in, Out: out, ErrOut: err}
73+
for _, registerCmd := range commands.Commands() {
74+
cmds.AddCommand(registerCmd(ctx, ioStreams))
75+
}
76+
77+
return cmds
78+
}
79+
80+
func usageTemplate() string {
81+
return fmt.Sprintf(`Usage:{{if .Runnable}} %s {{end}}{{if .HasAvailableSubCommands}} %s [command]{{end}}{{if gt (len .Aliases) 0}}
82+
83+
Aliases:
84+
{{.NameAndAliases}}{{end}}{{if .HasExample}}
85+
86+
Examples:
87+
{{.Example}}{{end}}{{if .HasAvailableSubCommands}}
88+
89+
Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}}
90+
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}
91+
92+
Flags:
93+
{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}
94+
95+
Global Flags:
96+
{{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}}
97+
98+
Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}}
99+
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}}
100+
101+
Use "%s [command] --help" for more information about a command.{{end}}
102+
`, build.Name(), build.Name(), build.Name())
103+
}

0 commit comments

Comments
 (0)