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 Jul 2, 2024
2 parents 27805af + beb71be commit dff4435
Show file tree
Hide file tree
Showing 18 changed files with 622 additions and 63 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"
8 changes: 3 additions & 5 deletions .github/workflows/kind-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,14 @@ 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
uses: ko-build/[email protected]

- name: Check out code onto GOPATH
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install KinD
run: |
Expand Down Expand Up @@ -112,7 +110,7 @@ jobs:
- name: Wait for things to be up
run: |
set -e
source ./vendor/knative.dev/hack/infra-library.sh
source "$(go run knative.dev/hack/cmd/script infra-library.sh)"
wait_until_pods_running ${SYSTEM_NAMESPACE}
- name: Run e2e Tests
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
9 changes: 2 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ 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
)

replace knative.dev/hack => github.com/cardil/knative-hack v0.0.0-20240627155243-4b5dad135546
replace knative.dev/hack => github.com/cardil/knative-hack v0.0.0-20240702091202-6535957027e0

require (
contrib.go.opencensus.io/exporter/ocagent v0.7.1-0.20200907061046-05415f1de66d // indirect
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
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/blendle/zapdriver v1.3.1 h1:C3dydBOWYRiOk+B8X9IVZ5IOe+7cl+tGOexN4QqHfpE=
github.com/blendle/zapdriver v1.3.1/go.mod h1:mdXfREi6u5MArG4j9fewC+FGnXaBR+T4Ox4J2u4eHCc=
github.com/cardil/knative-hack v0.0.0-20240627155243-4b5dad135546 h1:sbjR3wfWYfIEfJx1Th2rxdBDhUyzlHRDjFCkpnSP86M=
github.com/cardil/knative-hack v0.0.0-20240627155243-4b5dad135546/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
github.com/cardil/knative-hack v0.0.0-20240702091202-6535957027e0 h1:V9QHY1AQIUQnKPobPrVO7OZ49s69ocP40VpkHx57MCc=
github.com/cardil/knative-hack v0.0.0-20240702091202-6535957027e0/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/census-instrumentation/opencensus-proto v0.4.1 h1:iKLQ0xPNFxR/2hzXZMrBo8f1j86j5WHzznCCQxV/b8g=
github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw=
Expand Down 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
Loading

0 comments on commit dff4435

Please sign in to comment.