-
Notifications
You must be signed in to change notification settings - Fork 592
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
202 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
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 v1alpha1 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"knative.dev/eventing/pkg/apis/eventing/v1beta1" | ||
"knative.dev/pkg/apis" | ||
) | ||
|
||
// ConvertUp implements apis.Convertible. | ||
// Converts source (from v1alpha1.Trigger) into v1beta1.Trigger | ||
func (source *Trigger) ConvertUp(ctx context.Context, obj apis.Convertible) error { | ||
switch sink := obj.(type) { | ||
case *v1beta1.Trigger: | ||
sink.ObjectMeta = source.ObjectMeta | ||
sink.Spec.Broker = source.Spec.Broker | ||
sink.Spec.Subscriber = source.Spec.Subscriber | ||
if source.Spec.Filter != nil { | ||
sink.Spec.Filter = &v1beta1.TriggerFilter{} | ||
if source.Spec.Filter.Attributes != nil { | ||
for k, v := range *source.Spec.Filter.Attributes { | ||
sink.Spec.Filter.Attributes[k] = v | ||
} | ||
} | ||
if source.Spec.Filter.DeprecatedSourceAndType != nil { | ||
sink.Spec.Filter.Attributes["source"] = source.Spec.Filter.DeprecatedSourceAndType.Source | ||
sink.Spec.Filter.Attributes["type"] = source.Spec.Filter.DeprecatedSourceAndType.Type | ||
} | ||
} | ||
sink.Status.Status = source.Status.Status | ||
sink.Status.SubscriberURI = source.Status.SubscriberURI | ||
return nil | ||
default: | ||
return fmt.Errorf("Unknown conversion, got: %T", sink) | ||
|
||
} | ||
} | ||
|
||
// ConvertDown implements apis.Convertible. | ||
// Converts obj from v1beta1.Trigger into v1alpha1.Trigger | ||
func (sink *Trigger) ConvertDown(ctx context.Context, obj apis.Convertible) error { | ||
switch source := obj.(type) { | ||
case *v1beta1.Trigger: | ||
sink.ObjectMeta = source.ObjectMeta | ||
sink.Spec.Broker = source.Spec.Broker | ||
sink.Spec.Subscriber = source.Spec.Subscriber | ||
if source.Spec.Filter != nil { | ||
sink.Spec.Filter = &TriggerFilter{} | ||
tfa := TriggerFilterAttributes{} | ||
for k, v := range source.Spec.Filter.Attributes { | ||
tfa[k] = v | ||
} | ||
} | ||
|
||
sink.Status.Status = source.Status.Status | ||
sink.Status.SubscriberURI = source.Status.SubscriberURI | ||
return nil | ||
default: | ||
return fmt.Errorf("Unknown conversion, got: %T", source) | ||
} | ||
} |
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,44 @@ | ||
/* | ||
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 ( | ||
"knative.dev/pkg/apis" | ||
) | ||
|
||
var brokerCondSet = apis.NewLivingConditionSet(BrokerConditionAddressable) | ||
|
||
const ( | ||
BrokerConditionReady = apis.ConditionReady | ||
BrokerConditionAddressable apis.ConditionType = "Addressable" | ||
) | ||
|
||
// GetTopLevelCondition returns the top level Condition. | ||
func (bs *BrokerStatus) GetTopLevelCondition() *apis.Condition { | ||
return brokerCondSet.Manage(bs).GetTopLevelCondition() | ||
} | ||
|
||
// SetAddress makes this Broker addressable by setting the URI. It also | ||
// sets the BrokerConditionAddressable to true. | ||
func (bs *BrokerStatus) SetAddress(url *apis.URL) { | ||
bs.Address.URL = url | ||
if url != nil { | ||
brokerCondSet.Manage(bs).MarkTrue(BrokerConditionAddressable) | ||
} else { | ||
brokerCondSet.Manage(bs).MarkFalse(BrokerConditionAddressable, "nil URL", "URL is nil") | ||
} | ||
} |
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,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" | ||
) | ||
|
||
// ConvertUp implements apis.Convertible | ||
func (source *Trigger) ConvertUp(ctx context.Context, sink apis.Convertible) error { | ||
return fmt.Errorf("v1beta1 is the highest known version, got: %T", sink) | ||
} | ||
|
||
// ConvertDown implements apis.Convertible | ||
func (sink *Trigger) ConvertDown(ctx context.Context, source apis.Convertible) error { | ||
return fmt.Errorf("v1 is the highest known version, got: %T", source) | ||
} |
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,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 TestTriggerConversionBadType(t *testing.T) { | ||
good, bad := &Trigger{}, &Trigger{} | ||
|
||
if err := good.ConvertUp(context.Background(), bad); err == nil { | ||
t.Errorf("ConvertUp() = %#v, wanted error", bad) | ||
} | ||
|
||
if err := good.ConvertDown(context.Background(), bad); err == nil { | ||
t.Errorf("ConvertDown() = %#v, wanted error", good) | ||
} | ||
} |
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