refact(deps): bump k8s and client-go deps to version v0.20.2 (#294)

Signed-off-by: prateekpandey14 <prateek.pandey@mayadata.io>
This commit is contained in:
Prateek Pandey 2021-03-31 16:43:42 +05:30 committed by GitHub
parent 533e17a9aa
commit b1aa6ab51a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2196 changed files with 306727 additions and 251810 deletions

View file

@ -29,9 +29,6 @@ import (
"strings"
flag "github.com/spf13/pflag"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/graph/topo"
"k8s.io/code-generator/pkg/util"
"k8s.io/gengo/args"
@ -279,7 +276,7 @@ func Run(g *Generator) {
cmd := exec.Command("protoc", append(args, path)...)
out, err := cmd.CombinedOutput()
if len(out) > 0 {
log.Printf(string(out))
log.Print(string(out))
}
if err != nil {
log.Println(strings.Join(cmd.Args, " "))
@ -300,7 +297,7 @@ func Run(g *Generator) {
cmd = exec.Command("goimports", "-w", outputPath)
out, err = cmd.CombinedOutput()
if len(out) > 0 {
log.Printf(string(out))
log.Print(string(out))
}
if err != nil {
log.Println(strings.Join(cmd.Args, " "))
@ -311,7 +308,7 @@ func Run(g *Generator) {
cmd = exec.Command("gofmt", "-s", "-w", outputPath)
out, err = cmd.CombinedOutput()
if len(out) > 0 {
log.Printf(string(out))
log.Print(string(out))
}
if err != nil {
log.Println(strings.Join(cmd.Args, " "))
@ -374,38 +371,73 @@ func deps(c *generator.Context, pkgs []*protobufPackage) map[string][]string {
return ret
}
// given a set of pkg->[]deps, return the order that ensures all deps are processed before the things that depend on them
func importOrder(deps map[string][]string) ([]string, error) {
nodes := map[string]graph.Node{}
names := map[int64]string{}
g := simple.NewDirectedGraph()
for pkg, imports := range deps {
for _, imp := range imports {
if _, found := nodes[pkg]; !found {
n := g.NewNode()
g.AddNode(n)
nodes[pkg] = n
names[n.ID()] = pkg
}
if _, found := nodes[imp]; !found {
n := g.NewNode()
g.AddNode(n)
nodes[imp] = n
names[n.ID()] = imp
}
g.SetEdge(g.NewEdge(nodes[imp], nodes[pkg]))
// add all nodes and edges
var remainingNodes = map[string]struct{}{}
var graph = map[edge]struct{}{}
for to, froms := range deps {
remainingNodes[to] = struct{}{}
for _, from := range froms {
remainingNodes[from] = struct{}{}
graph[edge{from: from, to: to}] = struct{}{}
}
}
ret := []string{}
sorted, err := topo.Sort(g)
if err != nil {
return nil, err
// find initial nodes without any dependencies
sorted := findAndRemoveNodesWithoutDependencies(remainingNodes, graph)
for i := 0; i < len(sorted); i++ {
node := sorted[i]
removeEdgesFrom(node, graph)
sorted = append(sorted, findAndRemoveNodesWithoutDependencies(remainingNodes, graph)...)
}
if len(remainingNodes) > 0 {
return nil, fmt.Errorf("cycle: remaining nodes: %#v, remaining edges: %#v", remainingNodes, graph)
}
for _, n := range sorted {
ret = append(ret, names[n.ID()])
fmt.Println("topological order", names[n.ID()])
fmt.Println("topological order", n)
}
return sorted, nil
}
// edge describes a from->to relationship in a graph
type edge struct {
from string
to string
}
// findAndRemoveNodesWithoutDependencies finds nodes in the given set which are not pointed to by any edges in the graph,
// removes them from the set of nodes, and returns them in sorted order
func findAndRemoveNodesWithoutDependencies(nodes map[string]struct{}, graph map[edge]struct{}) []string {
roots := []string{}
// iterate over all nodes as potential "to" nodes
for node := range nodes {
incoming := false
// iterate over all remaining edges
for edge := range graph {
// if there's any edge to the node we care about, it's not a root
if edge.to == node {
incoming = true
break
}
}
// if there are no incoming edges, remove from the set of remaining nodes and add to our results
if !incoming {
delete(nodes, node)
roots = append(roots, node)
}
}
sort.Strings(roots)
return roots
}
// removeEdgesFrom removes any edges from the graph where edge.from == node
func removeEdgesFrom(node string, graph map[edge]struct{}) {
for edge := range graph {
if edge.from == node {
delete(graph, edge)
}
}
return ret, nil
}
type positionOrder struct {

View file

@ -25,7 +25,7 @@ import (
"strconv"
"strings"
"k8s.io/klog"
"k8s.io/klog/v2"
"k8s.io/gengo/generator"
"k8s.io/gengo/namer"
@ -371,7 +371,7 @@ func (b bodyGen) doStruct(sw *generator.SnippetWriter) error {
`, b.t)
if len(options) > 0 {
sort.Sort(sort.StringSlice(options))
sort.Strings(options)
for _, s := range options {
fmt.Fprintf(out, " option %s;\n", s)
}
@ -399,7 +399,7 @@ func (b bodyGen) doStruct(sw *generator.SnippetWriter) error {
}
extras = append(extras, fmt.Sprintf("%s = %s", k, v))
}
sort.Sort(sort.StringSlice(extras))
sort.Strings(extras)
if len(extras) > 0 {
fmt.Fprintf(out, " [")
fmt.Fprint(out, strings.Join(extras, ", "))
@ -740,7 +740,7 @@ func formatProtoFile(source []byte) ([]byte, error) {
func assembleProtoFile(w io.Writer, f *generator.File) {
w.Write(f.Header)
fmt.Fprint(w, "syntax = 'proto2';\n\n")
fmt.Fprint(w, "syntax = \"proto2\";\n\n")
if len(f.PackageName) > 0 {
fmt.Fprintf(w, "package %s;\n\n", f.PackageName)

View file

@ -132,7 +132,7 @@ func rewriteOptionalMethods(decl ast.Decl, isOptional OptionalFunc) {
switch t.Name.Name {
case "Unmarshal":
ast.Walk(&optionalItemsVisitor{}, t.Body)
case "MarshalTo", "Size", "String":
case "MarshalTo", "Size", "String", "MarshalToSizedBuffer":
ast.Walk(&optionalItemsVisitor{}, t.Body)
fallthrough
case "Marshal":
@ -375,6 +375,21 @@ func RewriteTypesWithProtobufStructTags(name string, structTags map[string]map[s
})
}
func getFieldName(expr ast.Expr, structname string) (name string, err error) {
for {
switch t := expr.(type) {
case *ast.Ident:
return t.Name, nil
case *ast.SelectorExpr:
return t.Sel.Name, nil
case *ast.StarExpr:
expr = t.X
default:
return "", fmt.Errorf("unable to get name for tag from struct %q, field %#v", structname, t)
}
}
}
func updateStructTags(decl ast.Decl, structTags map[string]map[string]string, toCopy []string) []error {
var errs []error
t, ok := decl.(*ast.GenDecl)
@ -403,14 +418,11 @@ func updateStructTags(decl ast.Decl, structTags map[string]map[string]string, to
for i := range st.Fields.List {
f := st.Fields.List[i]
var name string
var err error
if len(f.Names) == 0 {
switch t := f.Type.(type) {
case *ast.Ident:
name = t.Name
case *ast.SelectorExpr:
name = t.Sel.Name
default:
errs = append(errs, fmt.Errorf("unable to get name for tag from struct %q, field %#v", spec.Name.Name, t))
name, err = getFieldName(f.Type, spec.Name.Name)
if err != nil {
errs = append(errs, err)
continue
}
} else {

View file

@ -18,7 +18,7 @@ package protobuf
import (
"k8s.io/gengo/types"
"k8s.io/klog"
"k8s.io/klog/v2"
)
// extractBoolTagOrDie gets the comment-tags for the key and asserts that, if