This repository has been archived by the owner on Jun 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Pubsub v1beta1 Conversions #784
Merged
knative-prow-robot
merged 15 commits into
google:master
from
Harwayne:pubsub-conversion
Apr 10, 2020
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ecfa618
Duck v1beta1 types.
Harwayne 433bf5f
hack/update-codegen.sh
Harwayne 8fb2110
v1beta1 for pubsub APIs.
Harwayne 3aa88e1
Initial work on PullSubscription conversion.
Harwayne d1cd222
Unit tests for PullSubscription conversion.
Harwayne 33665f5
Conversion for Topics.
Harwayne c95c61b
Add the conversion webhook.
Harwayne 77b9201
Update the Pubsub CRDs to allow v1beta1.
Harwayne d8d6097
Make the OpenAPI schemna's structural.
Harwayne 9d55a7a
Fix PullSubscription's OpenAPI schema by flusing out spec.secret and …
Harwayne e204849
bool -> boolean
Harwayne e3420b2
Fill in the structure of Topic's spec.secret.
Harwayne 66fb5d8
Add PullSubscription's spec.adapterType.
Harwayne a1dda4f
Merge branch 'master' into pubsub-conversion
Harwayne 6f86d4e
Merge branch 'master' into pubsub-conversion
Harwayne 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
174 changes: 174 additions & 0 deletions
174
pkg/apis/pubsub/v1alpha1/pullsubscription_conversion.go
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,174 @@ | ||
/* | ||
Copyright 2020 Google LLC | ||
|
||
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 v1alpha1 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" | ||
duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" | ||
"github.com/google/knative-gcp/pkg/apis/pubsub/v1beta1" | ||
"knative.dev/pkg/apis" | ||
) | ||
|
||
// ConvertTo implements apis.Convertible. | ||
// Converts source (from v1beta1.PullSubscription) into v1alpha1.PullSubscription. | ||
func (source *PullSubscription) ConvertTo(_ context.Context, to apis.Convertible) error { | ||
switch sink := to.(type) { | ||
case *v1beta1.PullSubscription: | ||
sink.ObjectMeta = source.ObjectMeta | ||
sink.Spec.PubSubSpec = convertToV1beta1PubSubSpec(source.Spec.PubSubSpec) | ||
sink.Spec.Topic = source.Spec.Topic | ||
sink.Spec.AckDeadline = source.Spec.AckDeadline | ||
sink.Spec.RetainAckedMessages = source.Spec.RetainAckedMessages | ||
sink.Spec.RetentionDuration = source.Spec.RetentionDuration | ||
sink.Spec.Transformer = source.Spec.Transformer | ||
if mode, err := convertToV1beta1ModeType(source.Spec.Mode); err != nil { | ||
return err | ||
} else { | ||
sink.Spec.Mode = mode | ||
} | ||
sink.Spec.AdapterType = source.Spec.AdapterType | ||
sink.Status.PubSubStatus = convertToV1beta1PubSubStatus(source.Status.PubSubStatus) | ||
sink.Status.TransformerURI = source.Status.TransformerURI | ||
sink.Status.SubscriptionID = source.Status.SubscriptionID | ||
return nil | ||
default: | ||
return fmt.Errorf("unknown conversion, got: %T", sink) | ||
|
||
} | ||
} | ||
|
||
// ConvertFrom implements apis.Convertible. | ||
// Converts obj from v1alpha1.PullSubscription into v1beta1.PullSubscription. | ||
func (sink *PullSubscription) ConvertFrom(_ context.Context, from apis.Convertible) error { | ||
switch source := from.(type) { | ||
case *v1beta1.PullSubscription: | ||
sink.ObjectMeta = source.ObjectMeta | ||
sink.Spec.PubSubSpec = convertFromV1beta1PubSubSpec(source.Spec.PubSubSpec) | ||
sink.Spec.Topic = source.Spec.Topic | ||
sink.Spec.AckDeadline = source.Spec.AckDeadline | ||
sink.Spec.RetainAckedMessages = source.Spec.RetainAckedMessages | ||
sink.Spec.RetentionDuration = source.Spec.RetentionDuration | ||
sink.Spec.Transformer = source.Spec.Transformer | ||
if mode, err := convertFromV1beta1ModeType(source.Spec.Mode); err != nil { | ||
return err | ||
} else { | ||
sink.Spec.Mode = mode | ||
} | ||
sink.Spec.AdapterType = source.Spec.AdapterType | ||
sink.Status.PubSubStatus = convertFromV1beta1PubSubStatus(source.Status.PubSubStatus) | ||
sink.Status.TransformerURI = source.Status.TransformerURI | ||
sink.Status.SubscriptionID = source.Status.SubscriptionID | ||
return nil | ||
default: | ||
return fmt.Errorf("unknown conversion, got: %T", source) | ||
} | ||
} | ||
|
||
func convertToV1beta1ModeType(from ModeType) (v1beta1.ModeType, error) { | ||
switch from { | ||
case ModeCloudEventsBinary: | ||
return v1beta1.ModeCloudEventsBinary, nil | ||
case ModeCloudEventsStructured: | ||
return v1beta1.ModeCloudEventsStructured, nil | ||
case ModePushCompatible: | ||
return v1beta1.ModePushCompatible, nil | ||
case "": | ||
return "", nil | ||
default: | ||
return "unknown", fmt.Errorf("unknown ModeType %v", from) | ||
} | ||
} | ||
|
||
func convertFromV1beta1ModeType(from v1beta1.ModeType) (ModeType, error) { | ||
switch from { | ||
case v1beta1.ModeCloudEventsBinary: | ||
return ModeCloudEventsBinary, nil | ||
case v1beta1.ModeCloudEventsStructured: | ||
return ModeCloudEventsStructured, nil | ||
case v1beta1.ModePushCompatible: | ||
return ModePushCompatible, nil | ||
case "": | ||
return "", nil | ||
default: | ||
return "unknown", fmt.Errorf("unknown ModeType %v", from) | ||
} | ||
} | ||
|
||
func convertToV1beta1PubSubSpec(from v1alpha1.PubSubSpec) duckv1beta1.PubSubSpec { | ||
to := duckv1beta1.PubSubSpec{} | ||
to.SourceSpec = from.SourceSpec | ||
to.IdentitySpec = convertToV1beta1IdentitySpec(from.IdentitySpec) | ||
to.Secret = from.Secret | ||
to.Project = from.Project | ||
return to | ||
} | ||
func convertFromV1beta1PubSubSpec(from duckv1beta1.PubSubSpec) v1alpha1.PubSubSpec { | ||
to := v1alpha1.PubSubSpec{} | ||
to.SourceSpec = from.SourceSpec | ||
to.IdentitySpec = convertFromV1beta1IdentitySpec(from.IdentitySpec) | ||
to.Secret = from.Secret | ||
to.Project = from.Project | ||
return to | ||
} | ||
|
||
func convertToV1beta1IdentitySpec(from v1alpha1.IdentitySpec) duckv1beta1.IdentitySpec { | ||
to := duckv1beta1.IdentitySpec{} | ||
to.GoogleServiceAccount = from.GoogleServiceAccount | ||
return to | ||
} | ||
func convertFromV1beta1IdentitySpec(from duckv1beta1.IdentitySpec) v1alpha1.IdentitySpec { | ||
to := v1alpha1.IdentitySpec{} | ||
to.GoogleServiceAccount = from.GoogleServiceAccount | ||
return to | ||
} | ||
|
||
func convertToV1beta1PubSubStatus(from v1alpha1.PubSubStatus) duckv1beta1.PubSubStatus { | ||
to := duckv1beta1.PubSubStatus{} | ||
to.IdentityStatus = convertToV1beta1IdentityStatus(from.IdentityStatus) | ||
to.SinkURI = from.SinkURI | ||
to.CloudEventAttributes = from.CloudEventAttributes | ||
to.ProjectID = from.ProjectID | ||
to.TopicID = from.TopicID | ||
to.SubscriptionID = from.SubscriptionID | ||
return to | ||
} | ||
func convertFromV1beta1PubSubStatus(from duckv1beta1.PubSubStatus) v1alpha1.PubSubStatus { | ||
to := v1alpha1.PubSubStatus{} | ||
to.IdentityStatus = convertFromV1beta1IdentityStatus(from.IdentityStatus) | ||
to.SinkURI = from.SinkURI | ||
to.CloudEventAttributes = from.CloudEventAttributes | ||
to.ProjectID = from.ProjectID | ||
to.TopicID = from.TopicID | ||
to.SubscriptionID = from.SubscriptionID | ||
return to | ||
} | ||
|
||
func convertToV1beta1IdentityStatus(from v1alpha1.IdentityStatus) duckv1beta1.IdentityStatus { | ||
to := duckv1beta1.IdentityStatus{} | ||
to.Status = from.Status | ||
to.ServiceAccountName = from.ServiceAccountName | ||
return to | ||
} | ||
func convertFromV1beta1IdentityStatus(from duckv1beta1.IdentityStatus) v1alpha1.IdentityStatus { | ||
to := v1alpha1.IdentityStatus{} | ||
to.Status = from.Status | ||
to.ServiceAccountName = from.ServiceAccountName | ||
return to | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: add a comment about the purpose of this argument, as in https://github.com/knative/eventing/blob/1e68f1cfe5bb4f8c67aca7b09b36b973cde278dc/cmd/webhook/main.go#L333
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#813