Skip to content

Commit

Permalink
upgrade to latest dependencies (#1505)
Browse files Browse the repository at this point in the history
bumping knative.dev/eventing-kafka 3237bed...396ee08:
  > 396ee08 Wait for topic readiness after creation (# 986)
bumping knative.dev/pkg 22c0eba...5708c4c:
  > 5708c4c codegen - support multiple annotation keys (# 2350)

Signed-off-by: Knative Automation <automation@knative.team>
  • Loading branch information
knative-automation authored Nov 18, 2021
1 parent 77934d5 commit 7f6a1c8
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 52 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ require (
k8s.io/client-go v0.21.4
k8s.io/utils v0.0.0-20210111153108-fddb29f9d009
knative.dev/eventing v0.27.1-0.20211117135535-e7452e66b37c
knative.dev/eventing-kafka v0.27.1-0.20211117082433-3237bedea284
knative.dev/eventing-kafka v0.27.1-0.20211117151034-396ee08d5fc9
knative.dev/hack v0.0.0-20211117134436-69a2295d54ce
knative.dev/pkg v0.0.0-20211117133034-22c0eba0cacf
knative.dev/pkg v0.0.0-20211117215328-5708c4c44232
knative.dev/reconciler-test v0.0.0-20211112132636-ae9e2e21972f
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1329,8 +1329,8 @@ knative.dev/control-protocol v0.0.0-20211115173555-0910714d1183/go.mod h1:h/Ac2W
knative.dev/eventing v0.27.1-0.20211115154555-d5201e7b4c2e/go.mod h1:eJGGW9Rbrq585P2Ppc0a+nDLfJzGXe/R8eMXcNwUKlI=
knative.dev/eventing v0.27.1-0.20211117135535-e7452e66b37c h1:m1WFpIweDVlMXm6829Vp5NI2ajSLd9rFlOAZ98RZNo4=
knative.dev/eventing v0.27.1-0.20211117135535-e7452e66b37c/go.mod h1:wfjYgRZX2jlPewfsSGrX2OuOdwbx+n7jryLEz7Dak8k=
knative.dev/eventing-kafka v0.27.1-0.20211117082433-3237bedea284 h1:Jm8m7WDYmo7nqOanv+CsY2UPUK1WtFsGwuCnZFjEEcY=
knative.dev/eventing-kafka v0.27.1-0.20211117082433-3237bedea284/go.mod h1:pewzUwhWpTybd+lBFbu9ntB1xF8wDIbCQ32SAiRcYpM=
knative.dev/eventing-kafka v0.27.1-0.20211117151034-396ee08d5fc9 h1:sdcphuUe82U8ApX4J5t5qkyZnyA8jgEPbiXI6eVu5mA=
knative.dev/eventing-kafka v0.27.1-0.20211117151034-396ee08d5fc9/go.mod h1:pewzUwhWpTybd+lBFbu9ntB1xF8wDIbCQ32SAiRcYpM=
knative.dev/hack v0.0.0-20211101195839-11d193bf617b/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
knative.dev/hack v0.0.0-20211108170701-96aac1c30be3/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
knative.dev/hack v0.0.0-20211112192837-128cf0150a69/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
Expand All @@ -1341,8 +1341,8 @@ knative.dev/pkg v0.0.0-20211101212339-96c0204a70dc/go.mod h1:SkfDk9bWIiNZD7XtILG
knative.dev/pkg v0.0.0-20211111114938-0b0c3390a475/go.mod h1:plYIuKk6WNC9LyiG/9xBnOBYuxO0Ro6xN0z7iXWVUtk=
knative.dev/pkg v0.0.0-20211115071955-517ef0292b53/go.mod h1:VqUp1KWJqpTDNoiSI/heaX3uMdubImslJE2tBkP+Bbw=
knative.dev/pkg v0.0.0-20211117100634-54071addcdb8/go.mod h1:VqUp1KWJqpTDNoiSI/heaX3uMdubImslJE2tBkP+Bbw=
knative.dev/pkg v0.0.0-20211117133034-22c0eba0cacf h1:8hLmIbMv9lvpLwjuaVH/rEJ9fKrThEWViyzYZcBPNNc=
knative.dev/pkg v0.0.0-20211117133034-22c0eba0cacf/go.mod h1:VqUp1KWJqpTDNoiSI/heaX3uMdubImslJE2tBkP+Bbw=
knative.dev/pkg v0.0.0-20211117215328-5708c4c44232 h1:mye0h0gL0sI2YraL1X5FjyfQZoYVaaaRemTJq+uw+/8=
knative.dev/pkg v0.0.0-20211117215328-5708c4c44232/go.mod h1:VqUp1KWJqpTDNoiSI/heaX3uMdubImslJE2tBkP+Bbw=
knative.dev/reconciler-test v0.0.0-20211112132636-ae9e2e21972f h1:bSdsp5av09LqSF4iXo8LCCDEENJ+JEbzzdgHBoJdf2w=
knative.dev/reconciler-test v0.0.0-20211112132636-ae9e2e21972f/go.mod h1:gTsbLk496j/M9xqMpx/liyCQ0X3bwDpRtcs2Zzws364=
modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw=
Expand Down
42 changes: 42 additions & 0 deletions vendor/knative.dev/eventing-kafka/test/e2e/helpers/kafka_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ package helpers
import (
"context"
"fmt"
"log"
"strings"
"time"

"github.com/google/uuid"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"

"github.com/davecgh/go-spew/spew"
appsv1 "k8s.io/api/apps/v1"
Expand All @@ -31,6 +34,7 @@ import (
apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/wait"
testlib "knative.dev/eventing/test/lib"
Expand Down Expand Up @@ -241,6 +245,11 @@ func MustCreateTopic(client *testlib.Client, clusterName, clusterNamespace, topi
}

client.Tracker.Add(topicGVR.Group, topicGVR.Version, topicGVR.Resource, clusterNamespace, topicName)

// Wait for the topic to be ready
if err := WaitForTopicReady(context.Background(), client, clusterNamespace, topicName, topicGVR); err != nil {
client.T.Fatalf("Error while creating the topic %s: %v", topicName, err)
}
}

//CheckKafkaSourceState waits for specified kafka source resource state
Expand Down Expand Up @@ -287,3 +296,36 @@ func CheckRADeployment(ctx context.Context, c *testlib.Client, name string, inSt
}
return nil
}

func WaitForTopicReady(ctx context.Context, client *testlib.Client, namespace, name string, gvr schema.GroupVersionResource) error {
like := &duckv1.KResource{}
return wait.PollImmediate(interval, timeout, func() (bool, error) {
us, err := client.Dynamic.Resource(gvr).Namespace(namespace).Get(ctx, name, metav1.GetOptions{})
if err != nil {
if apierrs.IsNotFound(err) {
log.Println(namespace, name, "not found", err)
// keep polling
return false, nil
}
return false, err
}
obj := like.DeepCopy()
if err = runtime.DefaultUnstructuredConverter.FromUnstructured(us.Object, obj); err != nil {
log.Fatalf("Error DefaultUnstructured.Dynamiconverter. %v", err)
}
obj.ResourceVersion = gvr.Version
obj.APIVersion = gvr.GroupVersion().String()

// First see if the resource has conditions.
if len(obj.Status.Conditions) == 0 {
return false, nil // keep polling
}

ready := obj.Status.GetCondition(apis.ConditionReady)
if ready != nil && ready.Status == corev1.ConditionTrue {
return true, nil
}

return false, nil
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,55 +19,74 @@ import "strings"

// Adapted from the k8s.io comment parser https://github.com/kubernetes/gengo/blob/master/types/comments.go

// CommentsTags maps marker prefixes to a set of tags containing keys and values
type CommentTags map[string]CommentTag

// CommentTags maps keys to a list of values
type CommentTag map[string][]string

// ExtractCommentTags parses comments for lines of the form:
//
// 'marker' + ':' "key=value,key2=value2".
// "marker" + "prefix" + ':' + "key=value,key2=value2".
//
// Values are optional; empty map is the default. A tag can be specified more than
// In the following example the marker is '+' and the prefix is 'foo':
// +foo:key=value1,key2=value2,key=value3
//
// Values are optional; empty map is the default. A tag can be specified more than
// one time and all values are returned. If the resulting map has an entry for
// a key, the value (a slice) is guaranteed to have at least 1 element.
//
// Example: if you pass "+" for 'marker', and the following lines are in
// the comments:
// +foo:key=value1,key2=value2
// +foo:key=value1,key2=value2,key=value3
// +bar
//
// Then this function will return:
// map[string]map[string]string{"foo":{"key":value1","key2":"value2"}, "bar": nil}
// map[string]map[string]string{
// "foo":{
// "key": []string{"value1", "value3"},
// "key2": []string{"value2"}
// },
// "bar": {},
// }
//
// Users are not expected to repeat values.
func ExtractCommentTags(marker string, lines []string) map[string]map[string]string {
out := map[string]map[string]string{}
func ExtractCommentTags(marker string, lines []string) CommentTags {
out := CommentTags{}

for _, line := range lines {
line = strings.TrimSpace(line)
if len(line) == 0 || !strings.HasPrefix(line, marker) {
continue
}

options := strings.SplitN(line[len(marker):], ":", 2)
prefix := options[0]

if len(options) == 2 {
vals := strings.Split(options[1], ",")

opts := out[options[0]]
opts := out[prefix]
if opts == nil {
opts = make(map[string]string, len(vals))
opts = make(CommentTag, len(vals))
out[prefix] = opts
}

for _, pair := range vals {
if kv := strings.SplitN(pair, "=", 2); len(kv) == 2 {
opts[kv[0]] = kv[1]
} else if kv[0] != "" {
opts[kv[0]] = ""
kv := strings.SplitN(pair, "=", 2)
if len(kv) == 1 && kv[0] == "" {
continue
}
if _, ok := opts[kv[0]]; !ok {
opts[kv[0]] = []string{}
}
if len(kv) == 2 {
opts[kv[0]] = append(opts[kv[0]], kv[1])
}
}
if len(opts) == 0 {
out[options[0]] = nil
} else {
out[options[0]] = opts
}
} else if len(options) == 1 && options[0] != "" {
if _, has := out[options[0]]; !has {
out[options[0]] = nil
if _, has := out[prefix]; !has {
out[prefix] = CommentTag{}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,29 +193,36 @@ func MustParseClientGenTags(lines []string) Tags {
return ret
}

func extractCommentTags(t *types.Type) map[string]map[string]string {
func extractCommentTags(t *types.Type) CommentTags {
comments := append(append([]string{}, t.SecondClosestCommentLines...), t.CommentLines...)
return ExtractCommentTags("+", comments)
}

func extractReconcilerClassTag(tags map[string]map[string]string) (string, bool) {
func extractReconcilerClassesTag(tags CommentTags) ([]string, bool) {
vals, ok := tags["genreconciler"]
if !ok {
return "", false
return nil, false
}
classname, has := vals["class"]
return classname, has
classnames, has := vals["class"]
if has && len(classnames) == 0 {
return nil, false
}
return classnames, has
}

func isKRShaped(tags map[string]map[string]string) bool {
func isKRShaped(tags CommentTags) bool {
vals, has := tags["genreconciler"]
if !has {
return false
}
return vals["krshapedlogic"] != "false"
stringVals, has := vals["krshapedlogic"]
if !has || len(vals) == 0 {
return true // Default is true
}
return stringVals[0] != "false"
}

func isNonNamespaced(tags map[string]map[string]string) bool {
func isNonNamespaced(tags CommentTags) bool {
vals, has := tags["genclient"]
if !has {
return false
Expand All @@ -224,7 +231,7 @@ func isNonNamespaced(tags map[string]map[string]string) bool {
return has
}

func stubs(tags map[string]map[string]string) bool {
func stubs(tags CommentTags) bool {
vals, has := tags["genreconciler"]
if !has {
return false
Expand Down Expand Up @@ -545,7 +552,7 @@ func reconcilerPackages(basePackage string, groupPkgName string, gv clientgentyp
// Fix for golang iterator bug.
t := t
extracted := extractCommentTags(t)
reconcilerClass, hasReconcilerClass := extractReconcilerClassTag(extracted)
reconcilerClasses, hasReconcilerClass := extractReconcilerClassesTag(extracted)
nonNamespaced := isNonNamespaced(extracted)
isKRShaped := isKRShaped(extracted)
stubs := stubs(extracted)
Expand Down Expand Up @@ -573,7 +580,7 @@ func reconcilerPackages(basePackage string, groupPkgName string, gv clientgentyp
clientPkg: clientPackagePath,
informerPackagePath: informerPackagePath,
schemePkg: filepath.Join(customArgs.VersionedClientSetPackage, "scheme"),
reconcilerClass: reconcilerClass,
reconcilerClasses: reconcilerClasses,
hasReconcilerClass: hasReconcilerClass,
hasStatus: hasStatus(t),
})
Expand Down Expand Up @@ -602,7 +609,7 @@ func reconcilerPackages(basePackage string, groupPkgName string, gv clientgentyp
outputPackage: filepath.Join(packagePath, "stub"),
imports: generator.NewImportTracker(),
informerPackagePath: informerPackagePath,
reconcilerClass: reconcilerClass,
reconcilerClasses: reconcilerClasses,
hasReconcilerClass: hasReconcilerClass,
})
return generators
Expand Down Expand Up @@ -633,7 +640,7 @@ func reconcilerPackages(basePackage string, groupPkgName string, gv clientgentyp
listerPkg: listerPackagePath,
groupGoName: groupGoName,
groupVersion: gv,
reconcilerClass: reconcilerClass,
reconcilerClasses: reconcilerClasses,
hasReconcilerClass: hasReconcilerClass,
nonNamespaced: nonNamespaced,
isKRShaped: isKRShaped,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type reconcilerControllerGenerator struct {
schemePkg string
informerPackagePath string

reconcilerClass string
reconcilerClasses []string
hasReconcilerClass bool
hasStatus bool
}
Expand Down Expand Up @@ -69,7 +69,7 @@ func (g *reconcilerControllerGenerator) GenerateType(c *generator.Context, t *ty
m := map[string]interface{}{
"type": t,
"group": g.groupName,
"class": g.reconcilerClass,
"classes": g.reconcilerClasses,
"hasClass": g.hasReconcilerClass,
"hasStatus": g.hasStatus,
"controllerImpl": c.Universe.Type(types.Name{
Expand Down Expand Up @@ -195,12 +195,24 @@ var reconcilerControllerNewImpl = `
const (
defaultControllerAgentName = "{{.type|lowercaseSingular}}-controller"
defaultFinalizerName = "{{.type|allLowercasePlural}}.{{.group}}"
{{if .hasClass}}
{{if .hasClass }}
// ClassAnnotationKey points to the annotation for the class of this resource.
ClassAnnotationKey = "{{ .class }}"
{{if gt (.classes | len) 1 }}// Deprecated: Use ClassAnnotationKeys given multiple keys exist
{{end -}}
ClassAnnotationKey = "{{ index .classes 0 }}"
{{end}}
)
{{if gt (.classes | len) 1 }}
var (
// ClassAnnotationKeys points to the annotation for the class of this resource.
ClassAnnotationKeys = []string{
{{range $class := .classes}}"{{$class}}",
{{end}}
}
)
{{end}}
// NewImpl returns a {{.controllerImpl|raw}} that handles queuing and feeding work from
// the queue through an implementation of {{.controllerReconciler|raw}}, delegating to
// the provided Interface and optional Finalizer methods. OptionsFn is used to return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type reconcilerControllerStubGenerator struct {

reconcilerPkg string
informerPackagePath string
reconcilerClass string
reconcilerClasses []string
hasReconcilerClass bool
}

Expand Down Expand Up @@ -64,7 +64,7 @@ func (g *reconcilerControllerStubGenerator) GenerateType(c *generator.Context, t

m := map[string]interface{}{
"type": t,
"class": g.reconcilerClass,
"classes": g.reconcilerClasses,
"hasClass": g.hasReconcilerClass,
"informerGet": c.Universe.Function(types.Name{
Package: g.informerPackagePath,
Expand All @@ -91,10 +91,18 @@ func (g *reconcilerControllerStubGenerator) GenerateType(c *generator.Context, t
Package: g.reconcilerPkg,
Name: "ClassAnnotationKey",
}),
"classAnnotationKeys": c.Universe.Variable(types.Name{
Package: g.reconcilerPkg,
Name: "ClassAnnotationKeys",
}),
"annotationFilterFunc": c.Universe.Function(types.Name{
Package: "knative.dev/pkg/reconciler",
Name: "AnnotationFilterFunc",
}),
"orFilterFunc": c.Universe.Function(types.Name{
Package: "knative.dev/pkg/reconciler",
Name: "Or",
}),
"filterHandler": c.Universe.Type(types.Name{
Package: "k8s.io/client-go/tools/cache",
Name: "FilteringResourceEventHandler",
Expand All @@ -120,7 +128,17 @@ func NewController(
{{if .hasClass}}
classValue := "default" // TODO: update this to the appropriate value.
{{if len .classes | eq 1 }}
classFilter := {{.annotationFilterFunc|raw}}({{.classAnnotationKey|raw}}, classValue, false /*allowUnset*/)
{{else if gt (len .classes) 1 }}
filterFuncs := make([]func(interface{}) bool, 0, len({{.classAnnotationKeys|raw}}))
for _, key := range {{.classAnnotationKeys|raw}} {
filterFuncs = append(filterFuncs, {{.annotationFilterFunc|raw}}(key, classValue, false /*allowUnset*/))
}
classFilter := {{.orFilterFunc|raw}}(filterFuncs...)
{{end}}
{{end}}
// TODO: setup additional informers here.
Expand Down
Loading

0 comments on commit 7f6a1c8

Please sign in to comment.