forked from kubernetes/test-infra
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
code_freeze_maintainers_team
option to milestone
prow plugin
The new option allows to set a specific team (like the release-team-leads) to be milestone maintainer when code freeze is in place. For that we extend the milestone plugin to be able to validate codefreeze based on the tide configuration of the repository. Ref: - kubernetes/sig-release#2386 PRs for code freeze updates: - kubernetes#31164 - kubernetes#29259 Signed-off-by: Sascha Grunert <[email protected]>
- Loading branch information
1 parent
0562862
commit 5248cb0
Showing
7 changed files
with
476 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
prow/plugins/milestone/codefreezechecker/codefreezechecker.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package codefreezechecker | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/sirupsen/logrus" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
"k8s.io/test-infra/prow/config" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
const defaultConfigFile = "config/prow/config.yaml" | ||
|
||
var defaultBranches = []string{"master", "main"} | ||
|
||
// CodeFreezeChecker is the main structure of checking if we're in Code Freeze. | ||
type CodeFreezeChecker struct { | ||
impl impl | ||
} | ||
|
||
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate | ||
//counterfeiter:generate . impl | ||
type impl interface { | ||
ReadFile(name string) ([]byte, error) | ||
YAMLUnmarshal(y []byte) (*config.Config, error) | ||
} | ||
|
||
// New creates a new CodeFreezeChecker instance. | ||
func New() *CodeFreezeChecker { | ||
return &CodeFreezeChecker{ | ||
impl: &defaultImpl{}, | ||
} | ||
} | ||
|
||
// InCodeFreeze returns true if we're in Code Freeze: | ||
// https://github.com/kubernetes/sig-release/blob/2d8a1cc/releases/release_phases.md#code-freeze | ||
// This is being checked if the prow tide configuration has milestone restrictions applied like: | ||
// https://github.com/kubernetes/test-infra/pull/31164/files | ||
// It errors in case of any issue. | ||
func (c *CodeFreezeChecker) InCodeFreeze(org, repo string) (bool, error) { | ||
configData, err := c.impl.ReadFile(defaultConfigFile) | ||
if err != nil { | ||
return false, fmt.Errorf("read config file %s: %w", defaultConfigFile, err) | ||
} | ||
|
||
prowConfig, err := c.impl.YAMLUnmarshal(configData) | ||
if err != nil { | ||
return false, fmt.Errorf("unmarshal prow config: %w", err) | ||
} | ||
|
||
orgRepo := config.OrgRepo{Org: org, Repo: repo} | ||
queries := prowConfig.Tide.Queries.QueryMap().ForRepo(orgRepo) | ||
|
||
for _, query := range queries { | ||
if query.Milestone == "" { | ||
continue | ||
} | ||
|
||
includedBranches := sets.New(query.IncludedBranches...) | ||
releaseBranchFromMilestone := fmt.Sprintf("release-%s", strings.TrimPrefix(query.Milestone, "v")) | ||
|
||
if includedBranches.Has(releaseBranchFromMilestone) && includedBranches.HasAny(defaultBranches...) { | ||
logrus.Infof("Found code freeze for milestone %s", query.Milestone) | ||
return true, nil | ||
} | ||
} | ||
|
||
return false, nil | ||
} | ||
|
||
type defaultImpl struct{} | ||
|
||
func (*defaultImpl) ReadFile(name string) ([]byte, error) { | ||
return os.ReadFile(name) | ||
} | ||
|
||
func (*defaultImpl) YAMLUnmarshal(y []byte) (*config.Config, error) { | ||
prowConfig := &config.Config{} | ||
if err := yaml.Unmarshal(y, prowConfig); err != nil { | ||
return nil, err | ||
} | ||
return prowConfig, nil | ||
} |
79 changes: 79 additions & 0 deletions
79
prow/plugins/milestone/codefreezechecker/codefreezechecker_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package codefreezechecker | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"k8s.io/test-infra/prow/config" | ||
"k8s.io/test-infra/prow/plugins/milestone/codefreezechecker/codefreezecheckerfakes" | ||
) | ||
|
||
func TestInCodeFreeze(t *testing.T) { | ||
const ( | ||
testOrg = "org" | ||
testRepo = "repo" | ||
testMilestone = "v1.29" | ||
testReleaseBranch = "release-1.29" | ||
) | ||
t.Parallel() | ||
for _, tc := range []struct { | ||
name string | ||
prepare func(*codefreezecheckerfakes.FakeImpl) | ||
assert func(bool, error) | ||
}{ | ||
{ | ||
name: "success in code freez", | ||
prepare: func(mock *codefreezecheckerfakes.FakeImpl) { | ||
mock.YAMLUnmarshalReturns(&config.Config{ | ||
ProwConfig: config.ProwConfig{ | ||
Tide: config.Tide{ | ||
TideGitHubConfig: config.TideGitHubConfig{ | ||
Queries: config.TideQueries{ | ||
{ | ||
Milestone: testMilestone, | ||
Orgs: []string{testOrg}, | ||
Repos: []string{testRepo}, | ||
IncludedBranches: []string{testReleaseBranch, defaultBranches[0]}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, nil) | ||
}, | ||
assert: func(res bool, err error) { | ||
assert.True(t, res) | ||
assert.NoError(t, err) | ||
}, | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
mock := &codefreezecheckerfakes.FakeImpl{} | ||
tc.prepare(mock) | ||
|
||
sut := New() | ||
sut.impl = mock | ||
|
||
res, err := sut.InCodeFreeze(testOrg, testRepo) | ||
|
||
tc.assert(res, err) | ||
}) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
prow/plugins/milestone/codefreezechecker/codefreezecheckerfakes/fake_checker.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.