Skip to content

Commit

Permalink
Merge pull request #2280 from CecileRobertMichon/image-promote
Browse files Browse the repository at this point in the history
krel: make promote-images work for other k8s and k8s sigs projects
  • Loading branch information
k8s-ci-robot authored Oct 7, 2021
2 parents 6eea9b4 + 0e60afc commit 541a91a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
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

0 comments on commit 541a91a

Please sign in to comment.