-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved sinkbiding to v1, including types, default, conversion and webh… (
#4235) * moved sinkbiding to v1, including types, default, conversion and webhook: * fixed boilerplate * fixed nits * fixed nits
- Loading branch information
1 parent
42f7a15
commit b2387db
Showing
37 changed files
with
2,617 additions
and
12 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
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,43 @@ | ||
/* | ||
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 v1 | ||
|
||
import ( | ||
"context" | ||
|
||
"knative.dev/pkg/apis" | ||
) | ||
|
||
// sinkURIKey is used as the key for associating information | ||
// with a context.Context. | ||
type sinkURIKey struct{} | ||
|
||
// WithSinkURI notes on the context for binding that the resolved SinkURI | ||
// is the provided apis.URL. | ||
func WithSinkURI(ctx context.Context, uri *apis.URL) context.Context { | ||
return context.WithValue(ctx, sinkURIKey{}, uri) | ||
} | ||
|
||
// GetSinkURI accesses the apis.URL for the Sink URI that has been associated | ||
// with this context. | ||
func GetSinkURI(ctx context.Context) *apis.URL { | ||
value := ctx.Value(sinkURIKey{}) | ||
if value == nil { | ||
return nil | ||
} | ||
return value.(*apis.URL) | ||
} |
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,43 @@ | ||
/* | ||
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 v1 | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"knative.dev/pkg/apis" | ||
) | ||
|
||
func TestGetSinkURI(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
if uri := GetSinkURI(ctx); uri != nil { | ||
t.Errorf("GetSinkURI() = %v, wanted nil", uri) | ||
} | ||
|
||
want := &apis.URL{ | ||
Scheme: "https", | ||
Host: "knobots.io", | ||
Path: "/omg/a/path", | ||
} | ||
ctx = WithSinkURI(ctx, want) | ||
|
||
if got := GetSinkURI(ctx); got != want { | ||
t.Errorf("GetSinkURI() = %v, wanted %v", got, want) | ||
} | ||
} |
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 v1 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"knative.dev/pkg/apis" | ||
) | ||
|
||
// ConvertTo implements apis.Convertible | ||
func (source *SinkBinding) ConvertTo(ctx context.Context, sink apis.Convertible) error { | ||
return fmt.Errorf("v1 is the highest known version, got: %T", sink) | ||
} | ||
|
||
// ConvertFrom implements apis.Convertible | ||
func (sink *SinkBinding) ConvertFrom(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 v1 | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
) | ||
|
||
func TestSinkBindingConversionBadType(t *testing.T) { | ||
good, bad := &SinkBinding{}, &dummyObject{} | ||
|
||
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 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 v1 | ||
|
||
import ( | ||
"context" | ||
|
||
"knative.dev/pkg/apis" | ||
) | ||
|
||
// SetDefaults implements apis.Defaultable | ||
func (fb *SinkBinding) SetDefaults(ctx context.Context) { | ||
if fb.Spec.Subject.Namespace == "" { | ||
// Default the subject's namespace to our namespace. | ||
fb.Spec.Subject.Namespace = fb.Namespace | ||
} | ||
|
||
withNS := apis.WithinParent(ctx, fb.ObjectMeta) | ||
fb.Spec.Sink.SetDefaults(withNS) | ||
} |
Oops, something went wrong.