Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

krel: make promote-images work for other k8s and k8s sigs projects #2280

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions cmd/krel/cmd/promote-images.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ const (
// promoteCommand is the krel subcommand to promote conainer images
var imagePromoteCommand = &cobra.Command{
Use: "promote-images",
Short: "Starts an image promotion for a tag of kubernetes images",
Short: "Starts an image promotion for a tag of kubernetes or kubernetes-sigs images",
Long: `krel promote

The 'promote' subcommand of krel updates the image promoter manifests
ans creates a PR in kubernetes/k8s.io`,
and creates a PR in kubernetes/k8s.io`,
SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -57,8 +57,10 @@ ans creates a PR in kubernetes/k8s.io`,
}

type promoteOptions struct {
project string
userFork string
tags []string
reviewers string
interactiveMode bool
}

Expand Down Expand Up @@ -93,6 +95,13 @@ func (o *promoteOptions) Validate() error {
var promoteOpts = &promoteOptions{}

func init() {
imagePromoteCommand.PersistentFlags().StringVar(
&promoteOpts.project,
"project",
release.Kubernetes,
"the name of the project to promote images for",
)

imagePromoteCommand.PersistentFlags().StringSliceVarP(
&promoteOpts.tags,
"tag",
Expand All @@ -108,6 +117,13 @@ func init() {
"the user's fork of kubernetes/k8s.io",
)

imagePromoteCommand.PersistentFlags().StringVar(
&promoteOpts.reviewers,
"reviewers",
"@kubernetes/release-engineering",
"the list of GitHub users or teams to assign to the PR",
)

imagePromoteCommand.PersistentFlags().BoolVarP(
&promoteOpts.interactiveMode,
"interactive",
Expand All @@ -134,7 +150,7 @@ func runPromote(opts *promoteOptions) error {
ctx := context.Background()

// Validate options
branchname := opts.tags[0] + promotionBranchSuffix
branchname := opts.project + "-" + opts.tags[0] + promotionBranchSuffix

// Get the github org and repo from the fork slug
userForkOrg, userForkRepo, err := git.ParseRepoSlug(opts.userFork)
Expand Down Expand Up @@ -173,7 +189,7 @@ func runPromote(opts *promoteOptions) error {
imagesListPath := filepath.Join(
release.GCRIOPathProd,
"images",
filepath.Base(release.GCRIOPathStaging),
filepath.Base(release.GCRIOPathStagingPrefix)+opts.project,
"images.yaml",
)

Expand All @@ -194,7 +210,7 @@ func runPromote(opts *promoteOptions) error {
opt := reg.GrowManifestOptions{}
if err := opt.Populate(
filepath.Join(repo.Dir(), release.GCRIOPathProd),
release.GCRIOPathStaging, "", "", tag); err != nil {
release.GCRIOPathStagingPrefix+opts.project, "", "", tag); err != nil {
return errors.Wrapf(err, "populating image promoter options for tag %s", tag)
}

Expand Down Expand Up @@ -252,7 +268,7 @@ func runPromote(opts *promoteOptions) error {
return errors.Wrap(err, "adding image manifest to staging area")
}

commitMessage := "releng: Image promotion for " + strings.Join(opts.tags, " / ")
commitMessage := "releng: Image promotion for " + opts.project + " " + strings.Join(opts.tags, " / ")

// Commit files
logrus.Debug("Creating commit")
Expand All @@ -273,9 +289,9 @@ func runPromote(opts *promoteOptions) error {
return nil
}

prBody := fmt.Sprintf("Image promotion for Kubernetes %s\n", strings.Join(opts.tags, " / "))
prBody := fmt.Sprintf("Image promotion for %s %s\n", opts.project, strings.Join(opts.tags, " / "))
prBody += "This is an automated PR generated from `krel The Kubernetes Release Toolbox`\n\n"
prBody += "/hold\ncc: @kubernetes/release-engineering\n"
prBody += fmt.Sprintf("/hold\ncc: %s\n", opts.reviewers)

// Create the Pull Request
if mustRun(opts, "Create pull request?") {
Expand Down
2 changes: 1 addition & 1 deletion docs/krel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ krel has several subcommands that perform various tasks during the release lifec
| cve | Add and edit CVE information |
| [ff](ff.md) | Fast forward a Kubernetes release branch |
| history | Run history to build a list of commands that ran when cutting a specific Kubernetes release |
| promote-images | Starts an image promotion for a tag of kubernetes images |
| promote-images | Starts an image promotion for a tag of kubernetes or kubernetes-sigs images |
| [push](push.md) | Push Kubernetes release artifacts to Google Cloud Storage (GCS) |
| release | Release a staged Kubernetes version |
| [release-notes](release-notes.md) | The subcommand of choice for the Release Notes subteam of SIG Release |
Expand Down
8 changes: 7 additions & 1 deletion pkg/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ const (

KubernetesTar = "kubernetes.tar.gz"

// name of the kubernetes project
Kubernetes = "kubernetes"

// Staged source code tarball of Kubernetes
SourcesTar = "src.tar.gz"

Expand Down Expand Up @@ -107,8 +110,11 @@ const (
// Production registry root URL
GCRIOPathProd = "k8s.gcr.io"

// Staging registry root URL prefix
GCRIOPathStagingPrefix = "gcr.io/k8s-staging-"

// Staging registry root URL
GCRIOPathStaging = "gcr.io/k8s-staging-kubernetes"
GCRIOPathStaging = GCRIOPathStagingPrefix + Kubernetes

// Mock staging registry root URL
GCRIOPathMock = GCRIOPathStaging + "/mock"
Expand Down