-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add persistent cache store backed by ConfigMap. Refactor mtping (#3451)
* add persistent store backed by configmap * adapter support watching configmap. Disabled by default * cleanup, add more tests * fix ut, and maybe it * Setting up informers in now an opt-in flag, for backward compatibility reason * more tests * changes from review and fix configmap label * filter resource-scoped pingsources (yeah still there) * really delete schedule * fix crash when configmap does not exist * add more tests * fix broken k8s event
- Loading branch information
1 parent
6caed6a
commit 1cbaa24
Showing
22 changed files
with
1,306 additions
and
563 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ rules: | |
- "endpoints" | ||
- "events" | ||
- "serviceaccounts" | ||
- "pods" | ||
verbs: &everything | ||
- "get" | ||
- "list" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
Copyright 2020 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. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package mtping | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
"knative.dev/eventing/pkg/apis/eventing" | ||
"knative.dev/eventing/pkg/apis/sources/v1alpha2" | ||
) | ||
|
||
type PingConfig struct { | ||
corev1.ObjectReference `json:",inline"` | ||
|
||
// Schedule is the cronjob schedule. Defaults to `* * * * *`. | ||
Schedule string `json:"schedule"` | ||
|
||
// JsonData is json encoded data used as the body of the event posted to | ||
// the sink. Default is empty. If set, datacontenttype will also be set | ||
// to "application/json". | ||
// +optional | ||
JsonData string `json:"jsonData,omitempty"` | ||
|
||
// Extensions specify what attribute are added or overridden on the | ||
// outbound event. Each `Extensions` key-value pair are set on the event as | ||
// an attribute extension independently. | ||
// +optional | ||
Extensions map[string]string `json:"extensions,omitempty"` | ||
|
||
// SinkURI is the current active sink URI that has been configured for the | ||
// Source. | ||
SinkURI string `json:"sinkUri,omitempty"` | ||
} | ||
|
||
type PingConfigs map[string]PingConfig | ||
|
||
// Project creates a PingConfig for the given source | ||
func Project(i interface{}) interface{} { | ||
obj := i.(*v1alpha2.PingSource) | ||
|
||
if scope, ok := obj.Annotations[eventing.ScopeAnnotationKey]; ok && scope != eventing.ScopeCluster { | ||
return nil | ||
} | ||
|
||
cfg := &PingConfig{ | ||
ObjectReference: corev1.ObjectReference{ | ||
Name: obj.Name, | ||
Namespace: obj.Namespace, | ||
UID: obj.UID, | ||
ResourceVersion: obj.ResourceVersion, | ||
}, | ||
Schedule: obj.Spec.Schedule, | ||
JsonData: obj.Spec.JsonData, | ||
SinkURI: obj.Status.SinkURI.String(), | ||
} | ||
if obj.Spec.CloudEventOverrides != nil { | ||
cfg.Extensions = obj.Spec.CloudEventOverrides.Extensions | ||
} | ||
return cfg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
Copyright 2020 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. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package mtping | ||
|
||
import ( | ||
"testing" | ||
|
||
"knative.dev/pkg/apis" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
duckv1 "knative.dev/pkg/apis/duck/v1" | ||
|
||
sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" | ||
) | ||
|
||
func TestProject(t *testing.T) { | ||
testCases := map[string]struct { | ||
source sourcesv1alpha2.PingSource | ||
expected PingConfig | ||
}{ | ||
"TestAddRunRemoveSchedule": { | ||
source: sourcesv1alpha2.PingSource{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-name", | ||
Namespace: "test-ns"}, | ||
|
||
Spec: sourcesv1alpha2.PingSourceSpec{ | ||
SourceSpec: duckv1.SourceSpec{ | ||
CloudEventOverrides: nil, | ||
}, | ||
Schedule: "* * * * ?", | ||
JsonData: "some data", | ||
}, | ||
Status: sourcesv1alpha2.PingSourceStatus{ | ||
duckv1.SourceStatus{ | ||
SinkURI: &apis.URL{ | ||
Host: "asink", | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: PingConfig{ | ||
ObjectReference: corev1.ObjectReference{ | ||
Name: "test-name", | ||
Namespace: "test-ns", | ||
}, | ||
Schedule: "* * * * ?", | ||
JsonData: "some data", | ||
SinkURI: "//asink", | ||
}}, | ||
"TestAddRunRemoveScheduleWithExtensionOverride": { | ||
source: sourcesv1alpha2.PingSource{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-name", | ||
Namespace: "test-ns"}, | ||
Spec: sourcesv1alpha2.PingSourceSpec{ | ||
SourceSpec: duckv1.SourceSpec{ | ||
Sink: duckv1.Destination{}, | ||
CloudEventOverrides: &duckv1.CloudEventOverrides{ | ||
Extensions: map[string]string{"1": "one", "2": "two"}, | ||
}, | ||
}, | ||
Schedule: "* * * * ?", | ||
JsonData: "some data", | ||
}, | ||
Status: sourcesv1alpha2.PingSourceStatus{ | ||
duckv1.SourceStatus{ | ||
SinkURI: &apis.URL{Host: "anothersink"}, | ||
}, | ||
}, | ||
}, | ||
expected: PingConfig{ | ||
ObjectReference: corev1.ObjectReference{ | ||
Name: "test-name", | ||
Namespace: "test-ns", | ||
}, | ||
Schedule: "* * * * ?", | ||
JsonData: "some data", | ||
Extensions: map[string]string{"1": "one", "2": "two"}, | ||
SinkURI: "//anothersink", | ||
}}, | ||
} | ||
for n, tc := range testCases { | ||
t.Run(n, func(t *testing.T) { | ||
got := Project(&tc.source) | ||
if diff := cmp.Diff(&tc.expected, got); diff != "" { | ||
t.Errorf("unexpected projection (-want, +got) = %v", diff) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.