-
Notifications
You must be signed in to change notification settings - Fork 630
Pingsource v1beta1 #3607
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
knative-prow-robot
merged 4 commits into
knative:master
from
lionelvillard:pingsource-v1beta1
Jul 28, 2020
Merged
Pingsource v1beta1 #3607
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| 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 v1beta1 | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "knative.dev/pkg/apis" | ||
| ) | ||
|
|
||
| // ConvertTo implements apis.Convertible | ||
| func (source *PingSource) ConvertTo(ctx context.Context, sink apis.Convertible) error { | ||
| return fmt.Errorf("v1beta1 is the highest known version, got: %T", sink) | ||
| } | ||
|
|
||
| // ConvertFrom implements apis.Convertible | ||
| func (sink *PingSource) ConvertFrom(ctx context.Context, source apis.Convertible) error { | ||
| return fmt.Errorf("v1beta1 is the highest known version, got: %T", source) | ||
| } |
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,34 @@ | ||
| /* | ||
| 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 v1beta1 | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestPingSourceConversionBadType(t *testing.T) { | ||
| good, bad := &PingSource{}, &PingSource{} | ||
|
|
||
| if err := good.ConvertTo(context.Background(), bad); err == nil { | ||
| t.Errorf("ConvertTo() = %#v, wanted error", bad) | ||
| } | ||
|
|
||
| if err := good.ConvertFrom(context.Background(), bad); err == nil { | ||
| t.Errorf("ConvertFrom() = %#v, wanted error", good) | ||
| } | ||
| } |
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,35 @@ | ||
| /* | ||
| 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 v1beta1 | ||
|
|
||
| import ( | ||
| "context" | ||
| ) | ||
|
|
||
| const ( | ||
| defaultSchedule = "* * * * *" | ||
| ) | ||
|
|
||
| func (s *PingSource) SetDefaults(ctx context.Context) { | ||
| s.Spec.SetDefaults(ctx) | ||
| } | ||
|
|
||
| func (ss *PingSourceSpec) SetDefaults(ctx context.Context) { | ||
| if ss.Schedule == "" { | ||
| ss.Schedule = defaultSchedule | ||
| } | ||
| } |
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,67 @@ | ||
| /* | ||
| 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 v1beta1 | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/google/go-cmp/cmp" | ||
| ) | ||
|
|
||
| func TestPingSourceSetDefaults(t *testing.T) { | ||
| testCases := map[string]struct { | ||
| initial PingSource | ||
| expected PingSource | ||
| }{ | ||
| "nil": { | ||
| expected: PingSource{ | ||
| Spec: PingSourceSpec{ | ||
| Schedule: defaultSchedule, | ||
| }, | ||
| }, | ||
| }, | ||
| "empty": { | ||
| initial: PingSource{}, | ||
| expected: PingSource{ | ||
| Spec: PingSourceSpec{ | ||
| Schedule: defaultSchedule, | ||
| }, | ||
| }, | ||
| }, | ||
| "with schedule": { | ||
| initial: PingSource{ | ||
| Spec: PingSourceSpec{ | ||
| Schedule: "1 2 3 4 5", | ||
| }, | ||
| }, | ||
| expected: PingSource{ | ||
| Spec: PingSourceSpec{ | ||
| Schedule: "1 2 3 4 5", | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| for n, tc := range testCases { | ||
| t.Run(n, func(t *testing.T) { | ||
| tc.initial.SetDefaults(context.TODO()) | ||
| 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,117 @@ | ||
| /* | ||
| 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 v1beta1 | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| appsv1 "k8s.io/api/apps/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| "k8s.io/apimachinery/pkg/runtime/schema" | ||
| "knative.dev/pkg/apis" | ||
| ) | ||
|
|
||
| const ( | ||
| // PingSourceConditionReady has status True when the PingSource is ready to send events. | ||
| PingSourceConditionReady = apis.ConditionReady | ||
|
|
||
| // PingSourceConditionSinkProvided has status True when the PingSource has been configured with a sink target. | ||
| PingSourceConditionSinkProvided apis.ConditionType = "SinkProvided" | ||
|
|
||
| // PingSourceConditionDeployed has status True when the PingSource has had it's receive adapter deployment created. | ||
| PingSourceConditionDeployed apis.ConditionType = "Deployed" | ||
| ) | ||
|
|
||
| var PingSourceCondSet = apis.NewLivingConditionSet( | ||
| PingSourceConditionSinkProvided, | ||
| PingSourceConditionDeployed) | ||
|
|
||
| // GetConditionSet retrieves the condition set for this resource. Implements the KRShaped interface. | ||
| func (*PingSource) GetConditionSet() apis.ConditionSet { | ||
| return PingSourceCondSet | ||
| } | ||
|
|
||
| // PingSourceSource returns the PingSource CloudEvent source. | ||
| func PingSourceSource(namespace, name string) string { | ||
| return fmt.Sprintf("/apis/v1/namespaces/%s/pingsources/%s", namespace, name) | ||
| } | ||
|
|
||
| // GetUntypedSpec returns the spec of the PingSource. | ||
| func (s *PingSource) GetUntypedSpec() interface{} { | ||
| return s.Spec | ||
| } | ||
|
|
||
| // GetGroupVersionKind returns the GroupVersionKind. | ||
| func (s *PingSource) GetGroupVersionKind() schema.GroupVersionKind { | ||
| return SchemeGroupVersion.WithKind("PingSource") | ||
| } | ||
|
|
||
| // GetCondition returns the condition currently associated with the given type, or nil. | ||
| func (s *PingSourceStatus) GetCondition(t apis.ConditionType) *apis.Condition { | ||
| return PingSourceCondSet.Manage(s).GetCondition(t) | ||
| } | ||
|
|
||
| // GetTopLevelCondition returns the top level Condition. | ||
| func (ps *PingSourceStatus) GetTopLevelCondition() *apis.Condition { | ||
| return PingSourceCondSet.Manage(ps).GetTopLevelCondition() | ||
| } | ||
|
|
||
| // IsReady returns true if the resource is ready overall. | ||
| func (s *PingSourceStatus) IsReady() bool { | ||
| return PingSourceCondSet.Manage(s).IsHappy() | ||
| } | ||
|
|
||
| // InitializeConditions sets relevant unset conditions to Unknown state. | ||
| func (s *PingSourceStatus) InitializeConditions() { | ||
| PingSourceCondSet.Manage(s).InitializeConditions() | ||
| } | ||
|
|
||
| // MarkSink sets the condition that the source has a sink configured. | ||
| func (s *PingSourceStatus) MarkSink(uri *apis.URL) { | ||
| s.SinkURI = uri | ||
| if uri != nil { | ||
| PingSourceCondSet.Manage(s).MarkTrue(PingSourceConditionSinkProvided) | ||
| } else { | ||
| PingSourceCondSet.Manage(s).MarkFalse(PingSourceConditionSinkProvided, "SinkEmpty", "Sink has resolved to empty.") | ||
| } | ||
| } | ||
|
|
||
| // MarkNoSink sets the condition that the source does not have a sink configured. | ||
| func (s *PingSourceStatus) MarkNoSink(reason, messageFormat string, messageA ...interface{}) { | ||
| PingSourceCondSet.Manage(s).MarkFalse(PingSourceConditionSinkProvided, reason, messageFormat, messageA...) | ||
| } | ||
|
|
||
| // PropagateDeploymentAvailability uses the availability of the provided Deployment to determine if | ||
| // PingSourceConditionDeployed should be marked as true or false. | ||
| func (s *PingSourceStatus) PropagateDeploymentAvailability(d *appsv1.Deployment) { | ||
| deploymentAvailableFound := false | ||
| for _, cond := range d.Status.Conditions { | ||
| if cond.Type == appsv1.DeploymentAvailable { | ||
| deploymentAvailableFound = true | ||
| if cond.Status == corev1.ConditionTrue { | ||
| PingSourceCondSet.Manage(s).MarkTrue(PingSourceConditionDeployed) | ||
| } else if cond.Status == corev1.ConditionFalse { | ||
| PingSourceCondSet.Manage(s).MarkFalse(PingSourceConditionDeployed, cond.Reason, cond.Message) | ||
| } else if cond.Status == corev1.ConditionUnknown { | ||
| PingSourceCondSet.Manage(s).MarkUnknown(PingSourceConditionDeployed, cond.Reason, cond.Message) | ||
| } | ||
| } | ||
| } | ||
| if !deploymentAvailableFound { | ||
| PingSourceCondSet.Manage(s).MarkUnknown(PingSourceConditionDeployed, "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.