-
Notifications
You must be signed in to change notification settings - Fork 628
Bringing ContainerSource back #2824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f7452f4
adding ContainerSource back
nachocano 4b58a56
remove omitempty
34635cc
lint
nachocano ae484d8
Merge remote-tracking branch 'upstream/master' into container-sinkbin…
nachocano 4e0b58e
using sinkbinding, all UTs broken
nachocano 9ce16df
fixing some UTs
nachocano 34a76f1
Merge remote-tracking branch 'upstream/master' into container-sinkbin…
nachocano 9ee9fa0
update
nachocano ead139e
update codegen
aa1f14f
moving to v1alpha2
nachocano 9e1bd55
update code gen
1dcc641
moving to v1alpha2
nachocano 29a0eaf
update codegen
d5f7995
one more try
nachocano 7668afd
fixing e2e
nachocano c8df7d9
lint
nachocano a0a0ae7
fix e2e
nachocano 73fdde6
comment
nachocano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
| core/resources/containersource.yaml | ||
|
nachocano marked this conversation as resolved.
|
||
This file contains hidden or 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,62 @@ | ||
| # 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. | ||
|
|
||
| apiVersion: apiextensions.k8s.io/v1beta1 | ||
| kind: CustomResourceDefinition | ||
| metadata: | ||
| labels: | ||
| eventing.knative.dev/release: devel | ||
| eventing.knative.dev/source: "true" | ||
| duck.knative.dev/source: "true" | ||
| knative.dev/crd-install: "true" | ||
| name: containersources.sources.knative.dev | ||
| spec: | ||
| group: sources.knative.dev | ||
| names: | ||
| categories: | ||
| - all | ||
| - knative | ||
| - eventing | ||
| - sources | ||
| kind: ContainerSource | ||
| plural: containersources | ||
| scope: Namespaced | ||
| subresources: | ||
| status: {} | ||
| preserveUnknownFields: false | ||
| validation: | ||
| openAPIV3Schema: | ||
| type: object | ||
| # this is a work around so we don't need to flesh out the | ||
| # schema for each version at this time | ||
| # | ||
| # see issue: https://github.com/knative/serving/issues/912 | ||
| x-kubernetes-preserve-unknown-fields: true | ||
| additionalPrinterColumns: | ||
| - name: Ready | ||
| type: string | ||
| JSONPath: ".status.conditions[?(@.type==\"Ready\")].status" | ||
| - name: Reason | ||
| type: string | ||
| JSONPath: ".status.conditions[?(@.type=='Ready')].reason" | ||
| - name: Sink | ||
| type: string | ||
| JSONPath: ".status.sinkUri" | ||
| - name: Age | ||
| type: date | ||
| JSONPath: .metadata.creationTimestamp | ||
| versions: | ||
| - name: v1alpha2 | ||
| served: true | ||
| storage: true |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,42 @@ | ||
| /* | ||
| 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 v1alpha2 | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| "knative.dev/pkg/apis" | ||
| ) | ||
|
|
||
| func (s *ContainerSource) SetDefaults(ctx context.Context) { | ||
| withName := apis.WithinParent(ctx, s.ObjectMeta) | ||
| s.Spec.SetDefaults(withName) | ||
| } | ||
|
|
||
| func (ss *ContainerSourceSpec) SetDefaults(ctx context.Context) { | ||
| containers := make([]corev1.Container, 0, len(ss.Template.Spec.Containers)) | ||
| for i, c := range ss.Template.Spec.Containers { | ||
| // If the Container specified has no name, then default to "<source_name>_<i>". | ||
| if c.Name == "" { | ||
| c.Name = fmt.Sprintf("%s-%d", apis.ParentMeta(ctx).Name, i) | ||
| } | ||
| containers = append(containers, c) | ||
| } | ||
| ss.Template.Spec.Containers = containers | ||
| } |
This file contains hidden or 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,114 @@ | ||
| /* | ||
| 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 v1alpha2 | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/google/go-cmp/cmp" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| func TestContainerSourceDefaults(t *testing.T) { | ||
| testCases := map[string]struct { | ||
| initial ContainerSource | ||
| expected ContainerSource | ||
| }{ | ||
| "no container name": { | ||
| initial: ContainerSource{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "test-name", | ||
| Namespace: "test-namespace", | ||
| }, | ||
| Spec: ContainerSourceSpec{ | ||
| Template: corev1.PodTemplateSpec{ | ||
| Spec: corev1.PodSpec{ | ||
| Containers: []corev1.Container{{ | ||
| Image: "test-image", | ||
| }}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| expected: ContainerSource{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "test-name", | ||
| Namespace: "test-namespace", | ||
| }, | ||
| Spec: ContainerSourceSpec{ | ||
| Template: corev1.PodTemplateSpec{ | ||
| Spec: corev1.PodSpec{ | ||
| Containers: []corev1.Container{{ | ||
| Name: "test-name-0", | ||
| Image: "test-image", | ||
| }}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| "one with ontainer name one without": { | ||
| initial: ContainerSource{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "test-name", | ||
| Namespace: "test-namespace", | ||
| }, | ||
| Spec: ContainerSourceSpec{ | ||
| Template: corev1.PodTemplateSpec{ | ||
| Spec: corev1.PodSpec{ | ||
| Containers: []corev1.Container{{ | ||
| Name: "test-container", | ||
| Image: "test-image", | ||
| }, { | ||
| Image: "test-another-image", | ||
| }}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| expected: ContainerSource{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "test-name", | ||
| Namespace: "test-namespace", | ||
| }, | ||
| Spec: ContainerSourceSpec{ | ||
| Template: corev1.PodTemplateSpec{ | ||
| Spec: corev1.PodSpec{ | ||
| Containers: []corev1.Container{{ | ||
| Name: "test-container", | ||
| Image: "test-image", | ||
| }, { | ||
| Name: "test-name-1", | ||
| Image: "test-another-image", | ||
| }}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| for n, tc := range testCases { | ||
| t.Run(n, func(t *testing.T) { | ||
| tc.initial.SetDefaults(context.Background()) | ||
| if diff := cmp.Diff(tc.expected, tc.initial); diff != "" { | ||
| t.Fatalf("Unexpected defaults (-want, +got): %s", diff) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or 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,92 @@ | ||
| /* | ||
| 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 v1alpha2 | ||
|
|
||
| import ( | ||
| appsv1 "k8s.io/api/apps/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| "knative.dev/eventing/pkg/apis/duck" | ||
| "knative.dev/pkg/apis" | ||
| ) | ||
|
|
||
| const ( | ||
| // ContainerSourceConditionReady has status True when the ContainerSource is ready to send events. | ||
| ContainerSourceConditionReady = apis.ConditionReady | ||
|
|
||
| // ContainerSourceConditionSinkBindingReady has status True when the ContainerSource's SinkBinding is ready. | ||
| ContainerSourceConditionSinkBindingReady apis.ConditionType = "SinkBindingReady" | ||
|
|
||
| // ContainerSourceConditionReceiveAdapterReady has status True when the ContainerSource's ReceiveAdapter is ready. | ||
| ContainerSourceConditionReceiveAdapterReady apis.ConditionType = "ReceiveAdapterReady" | ||
| ) | ||
|
|
||
| var containerCondSet = apis.NewLivingConditionSet( | ||
| ContainerSourceConditionSinkBindingReady, | ||
| ContainerSourceConditionReceiveAdapterReady, | ||
| ) | ||
|
|
||
| // GetCondition returns the condition currently associated with the given type, or nil. | ||
| func (s *ContainerSourceStatus) GetCondition(t apis.ConditionType) *apis.Condition { | ||
| return containerCondSet.Manage(s).GetCondition(t) | ||
| } | ||
|
|
||
| // IsReady returns true if the resource is ready overall. | ||
| func (s *ContainerSourceStatus) IsReady() bool { | ||
| return containerCondSet.Manage(s).IsHappy() | ||
| } | ||
|
|
||
| // InitializeConditions sets relevant unset conditions to Unknown state. | ||
| func (s *ContainerSourceStatus) InitializeConditions() { | ||
| containerCondSet.Manage(s).InitializeConditions() | ||
| } | ||
|
|
||
| // PropagateSinkBindingStatus uses the availability of the provided Deployment to determine if | ||
| // ContainerSourceConditionSinkBindingReady should be marked as true, false or unknown. | ||
| func (s *ContainerSourceStatus) PropagateSinkBindingStatus(status *SinkBindingStatus) { | ||
| // Do not copy conditions nor observedGeneration | ||
| conditions := s.Conditions | ||
| observedGeneration := s.ObservedGeneration | ||
| s.SourceStatus = status.SourceStatus | ||
| s.Conditions = conditions | ||
| s.ObservedGeneration = observedGeneration | ||
|
|
||
| cond := status.GetCondition(apis.ConditionReady) | ||
| switch { | ||
| case cond == nil: | ||
| containerCondSet.Manage(s).MarkUnknown(ContainerSourceConditionSinkBindingReady, "", "") | ||
| case cond.Status == corev1.ConditionTrue: | ||
| containerCondSet.Manage(s).MarkTrue(ContainerSourceConditionSinkBindingReady) | ||
| case cond.Status == corev1.ConditionFalse: | ||
| containerCondSet.Manage(s).MarkFalse(ContainerSourceConditionSinkBindingReady, cond.Reason, cond.Message) | ||
| case cond.Status == corev1.ConditionUnknown: | ||
| containerCondSet.Manage(s).MarkUnknown(ContainerSourceConditionSinkBindingReady, cond.Reason, cond.Message) | ||
| default: | ||
| containerCondSet.Manage(s).MarkUnknown(ContainerSourceConditionSinkBindingReady, cond.Reason, cond.Message) | ||
| } | ||
| } | ||
|
|
||
| // PropagateReceiveAdapterStatus uses the availability of the provided Deployment to determine if | ||
| // ContainerSourceConditionReceiveAdapterReady should be marked as true or false. | ||
| func (s *ContainerSourceStatus) PropagateReceiveAdapterStatus(d *appsv1.Deployment) { | ||
| if duck.DeploymentIsAvailable(&d.Status, false) { | ||
| containerCondSet.Manage(s).MarkTrue(ContainerSourceConditionReceiveAdapterReady) | ||
| } else { | ||
| // I don't know how to propagate the status well, so just give the name of the Deployment | ||
| // for now. | ||
| containerCondSet.Manage(s).MarkFalse(ContainerSourceConditionReceiveAdapterReady, "DeploymentUnavailable", "The Deployment '%s' is unavailable.", d.Name) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.