Skip to content

Commit 06df991

Browse files
authored
Merge pull request #7038 from Priyankasaggu11929/add-kep-automation-in-sig-template
auto generate list of KEPs in annual-report/sig_report go template
2 parents 5b887a6 + 27ddce7 commit 06df991

File tree

4 files changed

+184
-25
lines changed

4 files changed

+184
-25
lines changed

generator/annual-report/sig_report.tmpl

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,16 @@
1414
-
1515
-
1616

17-
3. KEP work in {{lastYear}} (1.x, 1.y, 1.z):
17+
{{$releases := getReleases}}
18+
3. KEP work in {{lastYear}} (v{{$releases.Latest}}, v{{$releases.LatestMinusOne}}, v{{$releases.LatestMinusTwo}}):
19+
{{$owingsig := .Dir}}
20+
{{- range $stage, $keps := filterKEPs $owingsig $releases}}
21+
{{ $stage }}:
22+
{{- range $keps}}
23+
- [{{.Number}} - {{.Title}}](https://github.com/kubernetes/enhancements/tree/master/keps/{{.OwningSIG}}/{{.Name}}) - {{.LatestMilestone -}}
24+
{{ end}}
25+
{{- end}}
1826

19-
<!--
20-
In future, this will be generated from kubernetes/enhancements kep.yaml files
21-
1. with SIG as owning-sig or in participating-sigs
22-
2. listing 1.x, 1.y, or 1.z in milestones or in latest-milestone
23-
-->
24-
25-
- Stable
26-
- [$kep-number - $title](https://git.k8s.io/community/$link/README.md) - $milestone.stable
27-
- [$kep-number - $title](https://git.k8s.io/community/$link/README.md) - $milestone.stable
28-
- Beta
29-
- [$kep-number - $title](https://git.k8s.io/community/$link/README.md) - $milestone.beta
30-
- [$kep-number - $title](https://git.k8s.io/community/$link/README.md) - $milestone.beta
31-
- Alpha
32-
- [$kep-number - $title](https://git.k8s.io/community/$link/README.md) - $milestone.alpha
33-
- [$kep-number - $title](https://git.k8s.io/community/$link/README.md) - $milestone.alpha
34-
- Pre-alpha
35-
- [$kep-number - $title](https://git.k8s.io/community/$link/README.md)
3627

3728
## Project health
3829

generator/app.go

Lines changed: 115 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"context"
21+
"encoding/json"
2022
"fmt"
2123
"io/ioutil"
2224
"log"
25+
"net/http"
2326
"net/url"
2427
"os"
2528
"path/filepath"
@@ -29,6 +32,10 @@ import (
2932
"text/template"
3033
"time"
3134

35+
"k8s.io/enhancements/api"
36+
37+
"github.com/google/go-github/v32/github"
38+
3239
yaml "gopkg.in/yaml.v3"
3340
)
3441

@@ -55,13 +62,101 @@ const (
5562

5663
regexRawGitHubURL = "https://raw.githubusercontent.com/(?P<org>[^/]+)/(?P<repo>[^/]+)/(?P<branch>[^/]+)/(?P<path>.*)"
5764
regexGitHubURL = "https://github.com/(?P<org>[^/]+)/(?P<repo>[^/]+)/(blob|tree)/(?P<branch>[^/]+)/(?P<path>.*)"
65+
66+
// For KEPs automation
67+
kepURL = "https://storage.googleapis.com/k8s-keps/keps.json"
5868
)
5969

6070
var (
6171
baseGeneratorDir = ""
6272
templateDir = "generator"
73+
releases = Releases{}
74+
cachedKEPs = []api.Proposal{}
6375
)
6476

77+
// KEP represents an individual KEP holding its metadata information.
78+
type KEP struct {
79+
Name string `json:"name"`
80+
Title string `json:"title"`
81+
KepNumber string `json:"kepNumber"`
82+
OwningSig string `json:"owningSig"`
83+
Stage string `json:"stage"`
84+
LatestMilestone string `json:"latestMilestone"`
85+
}
86+
87+
type Releases struct {
88+
Latest string
89+
LatestMinusOne string
90+
LatestMinusTwo string
91+
}
92+
93+
// TODO: improve as suggested in https://github.com/kubernetes/community/pull/7038#discussion_r1069456087
94+
func getLastThreeK8sReleases() (Releases, error) {
95+
ctx := context.Background()
96+
client := github.NewClient(nil)
97+
98+
releases, _, err := client.Repositories.ListReleases(ctx, "kubernetes", "kubernetes", nil)
99+
if err != nil {
100+
return Releases{}, err
101+
}
102+
var result Releases
103+
result.Latest = strings.Split(strings.TrimPrefix(*releases[0].TagName, "v"), ".")[0] + "." + strings.Split(strings.TrimPrefix(*releases[0].TagName, "v"), ".")[1]
104+
result.LatestMinusOne = strings.Split(strings.TrimPrefix(*releases[1].TagName, "v"), ".")[0] + "." + strings.Split(strings.TrimPrefix(*releases[1].TagName, "v"), ".")[1]
105+
result.LatestMinusTwo = strings.Split(strings.TrimPrefix(*releases[2].TagName, "v"), ".")[0] + "." + strings.Split(strings.TrimPrefix(*releases[2].TagName, "v"), ".")[1]
106+
return result, nil
107+
}
108+
109+
func getReleases() Releases {
110+
return releases
111+
}
112+
113+
func fetchKEPs() error {
114+
url, err := url.Parse(kepURL)
115+
if err != nil {
116+
return fmt.Errorf("Error parsing url: %v", err)
117+
}
118+
119+
req, err := http.NewRequest("GET", url.String(), nil)
120+
if err != nil {
121+
return fmt.Errorf("Error creating request: %v", err)
122+
}
123+
124+
client := &http.Client{}
125+
resp, err := client.Do(req)
126+
if err != nil {
127+
return fmt.Errorf("Error fetching KEPs: %v", err)
128+
}
129+
defer resp.Body.Close()
130+
131+
body, err := ioutil.ReadAll(resp.Body)
132+
if err != nil {
133+
return fmt.Errorf("Error reading KEPs body: %v", err)
134+
}
135+
136+
err = json.Unmarshal(body, &cachedKEPs)
137+
if err != nil {
138+
return fmt.Errorf("Error unmarshalling KEPs: %v", err)
139+
}
140+
return nil
141+
}
142+
143+
func filterKEPs(owningSig string, releases Releases) (map[api.Stage][]api.Proposal, error) {
144+
kepsByStage := make(map[api.Stage][]api.Proposal)
145+
for _, kep := range cachedKEPs {
146+
if kep.OwningSIG == owningSig {
147+
for _, stage := range api.ValidStages {
148+
if kep.Stage == stage && (strings.HasSuffix(kep.LatestMilestone, releases.Latest) ||
149+
strings.HasSuffix(kep.LatestMilestone, releases.LatestMinusOne) ||
150+
strings.HasSuffix(kep.LatestMilestone, releases.LatestMinusTwo)) {
151+
kepsByStage[stage] = append(kepsByStage[stage], kep)
152+
}
153+
}
154+
}
155+
}
156+
157+
return kepsByStage, nil
158+
}
159+
65160
// FoldedString is a string that will be serialized in FoldedStyle by go-yaml
66161
type FoldedString string
67162

@@ -169,7 +264,8 @@ type Group struct {
169264
Leadership LeadershipGroup `yaml:"leadership"`
170265
Meetings []Meeting
171266
Contact Contact
172-
Subprojects []Subproject `yaml:",omitempty"`
267+
Subprojects []Subproject `yaml:",omitempty"`
268+
KEPs map[string][]api.Proposal `yaml:",omitempty"`
173269
}
174270

175271
type WGName string
@@ -436,6 +532,8 @@ var funcMap = template.FuncMap{
436532
"now": time.Now,
437533
"lastYear": lastYear,
438534
"toUpper": strings.ToUpper,
535+
"filterKEPs": filterKEPs,
536+
"getReleases": getReleases,
439537
}
440538

441539
// lastYear returns the last year as a string
@@ -456,8 +554,9 @@ func githubURL(url string) string {
456554
}
457555

458556
// orgRepoPath converts either
459-
// - a regular GitHub url of form https://github.com/org/repo/blob/branch/path/to/file
460-
// - a raw GitHub url of form https://raw.githubusercontent.com/org/repo/branch/path/to/file
557+
// - a regular GitHub url of form https://github.com/org/repo/blob/branch/path/to/file
558+
// - a raw GitHub url of form https://raw.githubusercontent.com/org/repo/branch/path/to/file
559+
//
461560
// to a string of form 'org/repo/path/to/file'
462561
func orgRepoPath(url string) string {
463562
for _, regex := range []string{regexRawGitHubURL, regexGitHubURL} {
@@ -686,10 +785,22 @@ func writeYaml(data interface{}, path string) error {
686785
}
687786

688787
func main() {
788+
789+
// Fetch KEPs and cache them in the keps variable
790+
err := fetchKEPs()
791+
if err != nil {
792+
log.Fatal(err)
793+
}
794+
795+
releases, err = getLastThreeK8sReleases()
796+
if err != nil {
797+
log.Fatal(err)
798+
}
799+
689800
yamlPath := filepath.Join(baseGeneratorDir, sigsYamlFile)
690801
var ctx Context
691802

692-
err := readYaml(yamlPath, &ctx)
803+
err = readYaml(yamlPath, &ctx)
693804
if err != nil {
694805
log.Fatal(err)
695806
}

go.mod

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,18 @@ go 1.18
44

55
require (
66
github.com/client9/misspell v0.3.4
7-
gopkg.in/yaml.v3 v3.0.0-20190409140830-cdc409dda467
7+
github.com/google/go-github/v32 v32.1.0
8+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
9+
k8s.io/enhancements v0.0.0-20230113204613-7f681415a001
10+
)
11+
12+
require (
13+
github.com/go-playground/locales v0.13.0 // indirect
14+
github.com/go-playground/universal-translator v0.17.0 // indirect
15+
github.com/go-playground/validator/v10 v10.4.1 // indirect
16+
github.com/google/go-querystring v1.0.0 // indirect
17+
github.com/leodido/go-urn v1.2.1 // indirect
18+
github.com/pkg/errors v0.9.1 // indirect
19+
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 // indirect
20+
golang.org/x/sys v0.0.0-20210112080510-489259a85091 // indirect
821
)

go.sum

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,50 @@
11
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
22
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
3+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5+
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
6+
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
7+
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
8+
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
9+
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
10+
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
11+
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
12+
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
13+
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
14+
github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II=
15+
github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI=
16+
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
17+
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
18+
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
19+
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
20+
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
21+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
22+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
23+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
24+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
25+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
26+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
27+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
28+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
29+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
30+
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
31+
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 h1:hb9wdF1z5waM+dSIICn1l0DkLVDT3hqhhQsDNUmHPRE=
32+
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
33+
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
34+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
35+
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
36+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
37+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
38+
golang.org/x/sys v0.0.0-20210112080510-489259a85091 h1:DMyOG0U+gKfu8JZzg2UQe9MeaC1X+xQWlAKcRnjxjCw=
39+
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
40+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
41+
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
42+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
43+
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
344
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
445
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5-
gopkg.in/yaml.v3 v3.0.0-20190409140830-cdc409dda467 h1:w3VhdSYz2sIVz54Ta/eDCCfCQ4fQkDgRxMACggArIUw=
6-
gopkg.in/yaml.v3 v3.0.0-20190409140830-cdc409dda467/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
46+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
47+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
48+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
49+
k8s.io/enhancements v0.0.0-20230113204613-7f681415a001 h1:WIc9tKwNWdlFwmEMzK8rX5DVpxmKQPo8LA0yyKroxxs=
50+
k8s.io/enhancements v0.0.0-20230113204613-7f681415a001/go.mod h1:VTK7nLkF9+GUWaHX08TT7CYf8tZSY8rChiH8GFwPYy8=

0 commit comments

Comments
 (0)