Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into chore/vendorless
Browse files Browse the repository at this point in the history
  • Loading branch information
cardil committed Jun 28, 2024
2 parents 27805af + beb71be commit 89de356
Show file tree
Hide file tree
Showing 20 changed files with 670 additions and 58 deletions.
8 changes: 8 additions & 0 deletions .github/.dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Set update schedule for GitHub Actions
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"
4 changes: 1 addition & 3 deletions .github/workflows/kind-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ jobs:

steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21.x
uses: knative/actions/setup-go@main

# Install the latest release of ko
- name: Install ko
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/knative-downstream.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ jobs:
GOPATH: ${{ github.workspace }}
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21.x
uses: knative/actions/setup-go@main
- name: Install Dependencies
run: |
go install github.com/google/go-licenses@latest
Expand Down
2 changes: 2 additions & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"knative.dev/eventing/pkg/apis/sinks"
"knative.dev/eventing/pkg/auth"
"knative.dev/eventing/pkg/eventingtls"
"knative.dev/eventing/pkg/reconciler/eventpolicy"
"knative.dev/eventing/pkg/reconciler/jobsink"

"knative.dev/eventing/pkg/reconciler/apiserversource"
Expand Down Expand Up @@ -93,6 +94,7 @@ func main() {

// Eventing
eventtype.NewController,
eventpolicy.NewController,

// Flows
parallel.NewController,
Expand Down
7 changes: 1 addition & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ require (
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
knative.dev/hack v0.0.0-20240607132042-09143140a254
knative.dev/hack/schema v0.0.0-20240607132042-09143140a254
knative.dev/pkg v0.0.0-20240621201938-fc0720b7a660
knative.dev/pkg v0.0.0-20240626134149-3f6a546ac3a4
knative.dev/reconciler-test v0.0.0-20240618170853-5bf0b86114f8
sigs.k8s.io/yaml v1.4.0
)
Expand Down Expand Up @@ -123,8 +123,3 @@ require (
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)

replace (
github.com/dgrijalva/jwt-go => github.com/form3tech-oss/jwt-go v0.0.0-20210511163231-5b2d2b5f6c34
github.com/miekg/dns v1.0.14 => github.com/miekg/dns v1.1.25
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@ k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCf
k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
knative.dev/hack/schema v0.0.0-20240607132042-09143140a254 h1:b9hFHGtxx0Kpm4EEjSD72lL0jms91To3OEVBTbqfOYI=
knative.dev/hack/schema v0.0.0-20240607132042-09143140a254/go.mod h1:3pWwBLnTZSM9psSgCAvhKOHIPTzqfEMlWRpDu6IYhK0=
knative.dev/pkg v0.0.0-20240621201938-fc0720b7a660 h1:SYPUGNPA/egS+u6oa6q1kN3Ec+z+we/hPrWie7qhLUg=
knative.dev/pkg v0.0.0-20240621201938-fc0720b7a660/go.mod h1:Wikg4u73T6vk9TctrxZt60VXzqmGEQIx0iKfk1+9o4c=
knative.dev/pkg v0.0.0-20240626134149-3f6a546ac3a4 h1:slPKf3UKdBFZlz+hFy+KXzTgY9yOePLzRuEhKzgc5a4=
knative.dev/pkg v0.0.0-20240626134149-3f6a546ac3a4/go.mod h1:Wikg4u73T6vk9TctrxZt60VXzqmGEQIx0iKfk1+9o4c=
knative.dev/reconciler-test v0.0.0-20240618170853-5bf0b86114f8 h1:A+rsitEiTX3GudM51g7zUMza+Ripj+boncmlJ2jZp50=
knative.dev/reconciler-test v0.0.0-20240618170853-5bf0b86114f8/go.mod h1:2uUx3U6kdIzgJgMGgrGmdDdcFrFiex/DjuI2gM7Tte8=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
Expand Down
44 changes: 33 additions & 11 deletions pkg/apis/eventing/v1alpha1/eventpolicy_lifecycle.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Knative Authors
Copyright 2024 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -20,10 +20,12 @@ import (
"knative.dev/pkg/apis"
)

var eventPolicyCondSet = apis.NewLivingConditionSet()
var eventPolicyCondSet = apis.NewLivingConditionSet(EventPolicyConditionAuthenticationEnabled, EventPolicyConditionSubjectsResolved)

const (
EventPolicyConditionReady = apis.ConditionReady
EventPolicyConditionReady = apis.ConditionReady
EventPolicyConditionAuthenticationEnabled apis.ConditionType = "AuthenticationEnabled"
EventPolicyConditionSubjectsResolved apis.ConditionType = "SubjectsResolved"
)

// GetConditionSet retrieves the condition set for this resource. Implements the KRShaped interface.
Expand All @@ -32,21 +34,41 @@ func (*EventPolicy) GetConditionSet() apis.ConditionSet {
}

// GetCondition returns the condition currently associated with the given type, or nil.
func (et *EventPolicyStatus) GetCondition(t apis.ConditionType) *apis.Condition {
return eventPolicyCondSet.Manage(et).GetCondition(t)
func (ep *EventPolicyStatus) GetCondition(t apis.ConditionType) *apis.Condition {
return eventPolicyCondSet.Manage(ep).GetCondition(t)
}

// IsReady returns true if the resource is ready overall.
func (et *EventPolicyStatus) IsReady() bool {
return et.GetTopLevelCondition().IsTrue()
func (ep *EventPolicyStatus) IsReady() bool {
return ep.GetTopLevelCondition().IsTrue()
}

// GetTopLevelCondition returns the top level Condition.
func (et *EventPolicyStatus) GetTopLevelCondition() *apis.Condition {
return eventPolicyCondSet.Manage(et).GetTopLevelCondition()
func (ep *EventPolicyStatus) GetTopLevelCondition() *apis.Condition {
return eventPolicyCondSet.Manage(ep).GetTopLevelCondition()
}

// InitializeConditions sets relevant unset conditions to Unknown state.
func (et *EventPolicyStatus) InitializeConditions() {
eventPolicyCondSet.Manage(et).InitializeConditions()
func (ep *EventPolicyStatus) InitializeConditions() {
eventPolicyCondSet.Manage(ep).InitializeConditions()
}

// MarkOIDCAuthenticationEnabled sets EventPolicyConditionAuthenticationEnabled condition to true.
func (ep *EventPolicyStatus) MarkOIDCAuthenticationEnabled() {
eventPolicyCondSet.Manage(ep).MarkTrue(EventPolicyConditionAuthenticationEnabled)
}

// MarkOIDCAuthenticationDisabled sets EventPolicyConditionAuthenticationEnabled condition to false.
func (ep *EventPolicyStatus) MarkOIDCAuthenticationDisabled(reason, messageFormat string, messageA ...interface{}) {
eventPolicyCondSet.Manage(ep).MarkFalse(EventPolicyConditionAuthenticationEnabled, reason, messageFormat, messageA...)
}

// MarkSubjectsResolved sets EventPolicyConditionSubjectsResolved condition to true.
func (ep *EventPolicyStatus) MarkSubjectsResolvedSucceeded() {
eventPolicyCondSet.Manage(ep).MarkTrue(EventPolicyConditionSubjectsResolved)
}

// MarkSubjectsNotResolved sets EventPolicyConditionSubjectsResolved condition to false.
func (ep *EventPolicyStatus) MarkSubjectsResolvedFailed(reason, messageFormat string, messageA ...interface{}) {
eventPolicyCondSet.Manage(ep).MarkFalse(EventPolicyConditionSubjectsResolved, reason, messageFormat, messageA...)
}
121 changes: 110 additions & 11 deletions pkg/apis/eventing/v1alpha1/eventpolicy_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ func TestEventPolicyGetConditionSet(t *testing.T) {
func TestEventPolicyGetCondition(t *testing.T) {
tests := []struct {
name string
ets *EventPolicyStatus
eps *EventPolicyStatus
condQuery apis.ConditionType
want *apis.Condition
}{{
name: "single condition",
ets: &EventPolicyStatus{
eps: &EventPolicyStatus{
Status: duckv1.Status{
Conditions: []apis.Condition{
eventPolicyConditionReady,
Expand All @@ -67,7 +67,7 @@ func TestEventPolicyGetCondition(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := test.ets.GetCondition(test.condQuery)
got := test.eps.GetCondition(test.condQuery)
if diff := cmp.Diff(test.want, got); diff != "" {
t.Error("unexpected condition (-want, +got) =", diff)
}
Expand All @@ -78,18 +78,27 @@ func TestEventPolicyGetCondition(t *testing.T) {
func TestEventPolicyInitializeConditions(t *testing.T) {
tests := []struct {
name string
ets *EventPolicyStatus
eps *EventPolicyStatus
want *EventPolicyStatus
}{
{
name: "empty",
ets: &EventPolicyStatus{},
eps: &EventPolicyStatus{},
want: &EventPolicyStatus{
Status: duckv1.Status{
Conditions: []apis.Condition{{
Type: EventPolicyConditionReady,
Status: corev1.ConditionUnknown,
},
Conditions: []apis.Condition{
{
Type: EventPolicyConditionAuthenticationEnabled,
Status: corev1.ConditionUnknown,
},
{
Type: EventPolicyConditionReady,
Status: corev1.ConditionUnknown,
},
{
Type: EventPolicyConditionSubjectsResolved,
Status: corev1.ConditionUnknown,
},
},
},
},
Expand All @@ -98,10 +107,100 @@ func TestEventPolicyInitializeConditions(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
test.ets.InitializeConditions()
if diff := cmp.Diff(test.want, test.ets, ignoreAllButTypeAndStatus); diff != "" {
test.eps.InitializeConditions()
if diff := cmp.Diff(test.want, test.eps, ignoreAllButTypeAndStatus); diff != "" {
t.Error("unexpected conditions (-want, +got) =", diff)
}
})
}
}

func TestEventPolicyReadyCondition(t *testing.T) {
tests := []struct {
name string
eps *EventPolicyStatus
markOIDCAuthenticationEnabled bool
markSubjectsResolvedSucceeded bool
wantReady bool
}{
{
name: "Initially everything is Unknown, Auth&SubjectsResolved marked as true, EP should become Ready",
eps: &EventPolicyStatus{
Status: duckv1.Status{
Conditions: []apis.Condition{
{Type: EventPolicyConditionReady, Status: corev1.ConditionUnknown},
{Type: EventPolicyConditionAuthenticationEnabled, Status: corev1.ConditionUnknown},
{Type: EventPolicyConditionSubjectsResolved, Status: corev1.ConditionUnknown},
},
},
},
markOIDCAuthenticationEnabled: true,
markSubjectsResolvedSucceeded: true,
wantReady: true,
},
{
name: "Initially everything is True, Auth&SubjectsResolved stay true, EP should stay Ready",
eps: &EventPolicyStatus{
Status: duckv1.Status{
Conditions: []apis.Condition{
{Type: EventPolicyConditionReady, Status: corev1.ConditionTrue},
{Type: EventPolicyConditionAuthenticationEnabled, Status: corev1.ConditionTrue},
{Type: EventPolicyConditionSubjectsResolved, Status: corev1.ConditionTrue},
},
},
},
markOIDCAuthenticationEnabled: true,
markSubjectsResolvedSucceeded: true,
wantReady: true,
},
{
name: "Initially everything is True, then AuthenticationEnabled marked as False, EP should become NotReady",
eps: &EventPolicyStatus{
Status: duckv1.Status{
Conditions: []apis.Condition{
{Type: EventPolicyConditionReady, Status: corev1.ConditionTrue},
{Type: EventPolicyConditionAuthenticationEnabled, Status: corev1.ConditionTrue},
{Type: EventPolicyConditionSubjectsResolved, Status: corev1.ConditionTrue},
},
},
},
markOIDCAuthenticationEnabled: false,
markSubjectsResolvedSucceeded: true,
wantReady: false,
},
{
name: "Initially everything is True, then SubjectsResolved marked as False, EP should become NotReady",
eps: &EventPolicyStatus{
Status: duckv1.Status{
Conditions: []apis.Condition{
{Type: EventPolicyConditionReady, Status: corev1.ConditionTrue},
{Type: EventPolicyConditionAuthenticationEnabled, Status: corev1.ConditionTrue},
{Type: EventPolicyConditionSubjectsResolved, Status: corev1.ConditionTrue},
},
},
},
markOIDCAuthenticationEnabled: true,
markSubjectsResolvedSucceeded: false,
wantReady: false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if test.markOIDCAuthenticationEnabled {
test.eps.MarkOIDCAuthenticationEnabled()
} else {
test.eps.MarkOIDCAuthenticationDisabled("OIDCAuthenticationDisabled", "")
}
if test.markSubjectsResolvedSucceeded {
test.eps.MarkSubjectsResolvedSucceeded()
} else {
test.eps.MarkSubjectsResolvedFailed("SubjectsNotResolved", "")
}
ep := EventPolicy{Status: *test.eps}
got := ep.GetConditionSet().Manage(test.eps).IsHappy()
if test.wantReady != got {
t.Errorf("unexpected readiness: want %v, got %v", test.wantReady, got)
}
})
}
}
9 changes: 5 additions & 4 deletions pkg/apis/eventing/v1beta2/eventtype_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestEventTypeDefaults(t *testing.T) {
Spec: EventTypeSpec{},
},
},
"broker empty": {
"default broker reference": {
initial: EventType{
Spec: EventTypeSpec{
Type: "test-type",
Expand Down Expand Up @@ -76,9 +76,10 @@ func TestEventTypeDefaults(t *testing.T) {
},
expected: EventType{
Spec: EventTypeSpec{
Type: "test-type",
Source: testSource,
Schema: testSchema,
Reference: nil,
Type: "test-type",
Source: testSource,
Schema: testSchema,
},
},
},
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/eventing/v1beta3/eventtype_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestEventTypeDefaults(t *testing.T) {
Spec: EventTypeSpec{},
},
},
"broker empty": {
"default broker reference": {
initial: EventType{
Spec: EventTypeSpec{
Reference: &duckv1.KReference{
Expand Down Expand Up @@ -115,6 +115,7 @@ func TestEventTypeDefaults(t *testing.T) {
},
expected: EventType{
Spec: EventTypeSpec{
Reference: nil,
Attributes: []EventAttributeDefinition{
{
Value: "test-type",
Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/feature/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package feature

import (
"fmt"
"log"
"strings"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -186,7 +187,8 @@ func NewFlagsConfigFromMap(data map[string]string) (Flags, error) {
} else if strings.Contains(k, NodeSelectorLabel) {
flags[sanitizedKey] = Flag(v)
} else {
return flags, fmt.Errorf("cannot parse the feature flag '%s' = '%s'", k, v)
flags[k] = Flag(v)
log.Printf("Warning: unknown feature flag value %q=%q\n", k, v)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/channel/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func TestReconcile(t *testing.T) {
WithInMemoryChannelDLSUnknown(),
WithInMemoryChannelEventPoliciesReady()),
NewEventPolicy(unreadyEventPolicyName, testNS,
WithUnreadyEventPolicyCondition,
WithUnreadyEventPolicyCondition("", ""),
WithEventPolicyToRef(channelV1GVK, channelName),
),
NewEventPolicy(fmt.Sprintf("%s-%s", unreadyEventPolicyName, channelName), testNS,
Expand Down Expand Up @@ -453,7 +453,7 @@ func TestReconcile(t *testing.T) {
WithEventPolicyToRef(channelV1GVK, channelName),
),
NewEventPolicy(unreadyEventPolicyName, testNS,
WithUnreadyEventPolicyCondition,
WithUnreadyEventPolicyCondition("", ""),
WithEventPolicyToRef(channelV1GVK, channelName),
),
NewEventPolicy(fmt.Sprintf("%s-%s", readyEventPolicyName, channelName), testNS,
Expand Down
Loading

0 comments on commit 89de356

Please sign in to comment.