summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKubernetes Prow Robot <k8s-ci-robot@users.noreply.github.com>2023-01-15 23:38:50 -0800
committerGitHub <noreply@github.com>2023-01-15 23:38:50 -0800
commit06df99149cecf84431dca5259a56757393ea8268 (patch)
tree4cfdbdfa01ea2ed56f1e13bea50b84ae78900559
parent5b887a65cf81061146d9532f1938e8239184d397 (diff)
parent27ddce709366b6cc08c88f5e657d7cced0b0a8f5 (diff)
Merge pull request #7038 from Priyankasaggu11929/add-kep-automation-in-sig-template
auto generate list of KEPs in annual-report/sig_report go template
-rw-r--r--generator/annual-report/sig_report.tmpl27
-rw-r--r--generator/app.go119
-rw-r--r--go.mod15
-rw-r--r--go.sum48
4 files changed, 184 insertions, 25 deletions
diff --git a/generator/annual-report/sig_report.tmpl b/generator/annual-report/sig_report.tmpl
index d018622a..475ab145 100644
--- a/generator/annual-report/sig_report.tmpl
+++ b/generator/annual-report/sig_report.tmpl
@@ -14,25 +14,16 @@
-
-
-3. KEP work in {{lastYear}} (1.x, 1.y, 1.z):
+{{$releases := getReleases}}
+3. KEP work in {{lastYear}} (v{{$releases.Latest}}, v{{$releases.LatestMinusOne}}, v{{$releases.LatestMinusTwo}}):
+{{$owingsig := .Dir}}
+{{- range $stage, $keps := filterKEPs $owingsig $releases}}
+ {{ $stage }}:
+ {{- range $keps}}
+ - [{{.Number}} - {{.Title}}](https://github.com/kubernetes/enhancements/tree/master/keps/{{.OwningSIG}}/{{.Name}}) - {{.LatestMilestone -}}
+ {{ end}}
+{{- end}}
-<!--
-In future, this will be generated from kubernetes/enhancements kep.yaml files
-1. with SIG as owning-sig or in participating-sigs
-2. listing 1.x, 1.y, or 1.z in milestones or in latest-milestone
--->
-
- - Stable
- - [$kep-number - $title](https://git.k8s.io/community/$link/README.md) - $milestone.stable
- - [$kep-number - $title](https://git.k8s.io/community/$link/README.md) - $milestone.stable
- - Beta
- - [$kep-number - $title](https://git.k8s.io/community/$link/README.md) - $milestone.beta
- - [$kep-number - $title](https://git.k8s.io/community/$link/README.md) - $milestone.beta
- - Alpha
- - [$kep-number - $title](https://git.k8s.io/community/$link/README.md) - $milestone.alpha
- - [$kep-number - $title](https://git.k8s.io/community/$link/README.md) - $milestone.alpha
- - Pre-alpha
- - [$kep-number - $title](https://git.k8s.io/community/$link/README.md)
## Project health
diff --git a/generator/app.go b/generator/app.go
index 0e67ec1d..6d631343 100644
--- a/generator/app.go
+++ b/generator/app.go
@@ -17,9 +17,12 @@ limitations under the License.
package main
import (
+ "context"
+ "encoding/json"
"fmt"
"io/ioutil"
"log"
+ "net/http"
"net/url"
"os"
"path/filepath"
@@ -29,6 +32,10 @@ import (
"text/template"
"time"
+ "k8s.io/enhancements/api"
+
+ "github.com/google/go-github/v32/github"
+
yaml "gopkg.in/yaml.v3"
)
@@ -55,13 +62,101 @@ const (
regexRawGitHubURL = "https://raw.githubusercontent.com/(?P<org>[^/]+)/(?P<repo>[^/]+)/(?P<branch>[^/]+)/(?P<path>.*)"
regexGitHubURL = "https://github.com/(?P<org>[^/]+)/(?P<repo>[^/]+)/(blob|tree)/(?P<branch>[^/]+)/(?P<path>.*)"
+
+ // For KEPs automation
+ kepURL = "https://storage.googleapis.com/k8s-keps/keps.json"
)
var (
baseGeneratorDir = ""
templateDir = "generator"
+ releases = Releases{}
+ cachedKEPs = []api.Proposal{}
)
+// KEP represents an individual KEP holding its metadata information.
+type KEP struct {
+ Name string `json:"name"`
+ Title string `json:"title"`
+ KepNumber string `json:"kepNumber"`
+ OwningSig string `json:"owningSig"`
+ Stage string `json:"stage"`
+ LatestMilestone string `json:"latestMilestone"`
+}
+
+type Releases struct {
+ Latest string
+ LatestMinusOne string
+ LatestMinusTwo string
+}
+
+// TODO: improve as suggested in https://github.com/kubernetes/community/pull/7038#discussion_r1069456087
+func getLastThreeK8sReleases() (Releases, error) {
+ ctx := context.Background()
+ client := github.NewClient(nil)
+
+ releases, _, err := client.Repositories.ListReleases(ctx, "kubernetes", "kubernetes", nil)
+ if err != nil {
+ return Releases{}, err
+ }
+ var result Releases
+ result.Latest = strings.Split(strings.TrimPrefix(*releases[0].TagName, "v"), ".")[0] + "." + strings.Split(strings.TrimPrefix(*releases[0].TagName, "v"), ".")[1]
+ result.LatestMinusOne = strings.Split(strings.TrimPrefix(*releases[1].TagName, "v"), ".")[0] + "." + strings.Split(strings.TrimPrefix(*releases[1].TagName, "v"), ".")[1]
+ result.LatestMinusTwo = strings.Split(strings.TrimPrefix(*releases[2].TagName, "v"), ".")[0] + "." + strings.Split(strings.TrimPrefix(*releases[2].TagName, "v"), ".")[1]
+ return result, nil
+}
+
+func getReleases() Releases {
+ return releases
+}
+
+func fetchKEPs() error {
+ url, err := url.Parse(kepURL)
+ if err != nil {
+ return fmt.Errorf("Error parsing url: %v", err)
+ }
+
+ req, err := http.NewRequest("GET", url.String(), nil)
+ if err != nil {
+ return fmt.Errorf("Error creating request: %v", err)
+ }
+
+ client := &http.Client{}
+ resp, err := client.Do(req)
+ if err != nil {
+ return fmt.Errorf("Error fetching KEPs: %v", err)
+ }
+ defer resp.Body.Close()
+
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ return fmt.Errorf("Error reading KEPs body: %v", err)
+ }
+
+ err = json.Unmarshal(body, &cachedKEPs)
+ if err != nil {
+ return fmt.Errorf("Error unmarshalling KEPs: %v", err)
+ }
+ return nil
+}
+
+func filterKEPs(owningSig string, releases Releases) (map[api.Stage][]api.Proposal, error) {
+ kepsByStage := make(map[api.Stage][]api.Proposal)
+ for _, kep := range cachedKEPs {
+ if kep.OwningSIG == owningSig {
+ for _, stage := range api.ValidStages {
+ if kep.Stage == stage && (strings.HasSuffix(kep.LatestMilestone, releases.Latest) ||
+ strings.HasSuffix(kep.LatestMilestone, releases.LatestMinusOne) ||
+ strings.HasSuffix(kep.LatestMilestone, releases.LatestMinusTwo)) {
+ kepsByStage[stage] = append(kepsByStage[stage], kep)
+ }
+ }
+ }
+ }
+
+ return kepsByStage, nil
+}
+
// FoldedString is a string that will be serialized in FoldedStyle by go-yaml
type FoldedString string
@@ -169,7 +264,8 @@ type Group struct {
Leadership LeadershipGroup `yaml:"leadership"`
Meetings []Meeting
Contact Contact
- Subprojects []Subproject `yaml:",omitempty"`
+ Subprojects []Subproject `yaml:",omitempty"`
+ KEPs map[string][]api.Proposal `yaml:",omitempty"`
}
type WGName string
@@ -436,6 +532,8 @@ var funcMap = template.FuncMap{
"now": time.Now,
"lastYear": lastYear,
"toUpper": strings.ToUpper,
+ "filterKEPs": filterKEPs,
+ "getReleases": getReleases,
}
// lastYear returns the last year as a string
@@ -456,8 +554,9 @@ func githubURL(url string) string {
}
// orgRepoPath converts either
-// - a regular GitHub url of form https://github.com/org/repo/blob/branch/path/to/file
-// - a raw GitHub url of form https://raw.githubusercontent.com/org/repo/branch/path/to/file
+// - a regular GitHub url of form https://github.com/org/repo/blob/branch/path/to/file
+// - a raw GitHub url of form https://raw.githubusercontent.com/org/repo/branch/path/to/file
+//
// to a string of form 'org/repo/path/to/file'
func orgRepoPath(url string) string {
for _, regex := range []string{regexRawGitHubURL, regexGitHubURL} {
@@ -686,10 +785,22 @@ func writeYaml(data interface{}, path string) error {
}
func main() {
+
+ // Fetch KEPs and cache them in the keps variable
+ err := fetchKEPs()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ releases, err = getLastThreeK8sReleases()
+ if err != nil {
+ log.Fatal(err)
+ }
+
yamlPath := filepath.Join(baseGeneratorDir, sigsYamlFile)
var ctx Context
- err := readYaml(yamlPath, &ctx)
+ err = readYaml(yamlPath, &ctx)
if err != nil {
log.Fatal(err)
}
diff --git a/go.mod b/go.mod
index be491393..a333b394 100644
--- a/go.mod
+++ b/go.mod
@@ -4,5 +4,18 @@ go 1.18
require (
github.com/client9/misspell v0.3.4
- gopkg.in/yaml.v3 v3.0.0-20190409140830-cdc409dda467
+ github.com/google/go-github/v32 v32.1.0
+ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
+ k8s.io/enhancements v0.0.0-20230113204613-7f681415a001
+)
+
+require (
+ github.com/go-playground/locales v0.13.0 // indirect
+ github.com/go-playground/universal-translator v0.17.0 // indirect
+ github.com/go-playground/validator/v10 v10.4.1 // indirect
+ github.com/google/go-querystring v1.0.0 // indirect
+ github.com/leodido/go-urn v1.2.1 // indirect
+ github.com/pkg/errors v0.9.1 // indirect
+ golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 // indirect
+ golang.org/x/sys v0.0.0-20210112080510-489259a85091 // indirect
)
diff --git a/go.sum b/go.sum
index 5e75d209..94985373 100644
--- a/go.sum
+++ b/go.sum
@@ -1,6 +1,50 @@
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
+github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
+github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
+github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
+github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
+github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
+github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
+github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
+github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II=
+github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI=
+github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
+github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
+github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
+github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
+github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
+github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
+github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
+github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
+golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 h1:hb9wdF1z5waM+dSIICn1l0DkLVDT3hqhhQsDNUmHPRE=
+golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
+golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210112080510-489259a85091 h1:DMyOG0U+gKfu8JZzg2UQe9MeaC1X+xQWlAKcRnjxjCw=
+golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v3 v3.0.0-20190409140830-cdc409dda467 h1:w3VhdSYz2sIVz54Ta/eDCCfCQ4fQkDgRxMACggArIUw=
-gopkg.in/yaml.v3 v3.0.0-20190409140830-cdc409dda467/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+k8s.io/enhancements v0.0.0-20230113204613-7f681415a001 h1:WIc9tKwNWdlFwmEMzK8rX5DVpxmKQPo8LA0yyKroxxs=
+k8s.io/enhancements v0.0.0-20230113204613-7f681415a001/go.mod h1:VTK7nLkF9+GUWaHX08TT7CYf8tZSY8rChiH8GFwPYy8=