-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move list of allowed ResourceTemplate types to its own package
This will help reduce the number of places we keep track of the list of types that Triggers can create especially as we add the v1beta1 types. Partially addresses #494 and part of the work needed for #1067
- Loading branch information
1 parent
7e52b44
commit a23ac4f
Showing
4 changed files
with
70 additions
and
8 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,30 @@ | ||
package config | ||
|
||
import ( | ||
pipelinev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" | ||
pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/serializer" | ||
utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
) | ||
|
||
var Decoder runtime.Decoder | ||
|
||
// TODO(dibyom): We should have a way of configuring this instead of an init function? | ||
func init() { | ||
scheme := runtime.NewScheme() | ||
utilruntime.Must(pipelinev1alpha1.AddToScheme(scheme)) | ||
utilruntime.Must(pipelinev1beta1.AddToScheme(scheme)) | ||
codec := serializer.NewCodecFactory(scheme) | ||
Decoder = codec.UniversalDecoder( | ||
pipelinev1alpha1.SchemeGroupVersion, | ||
pipelinev1beta1.SchemeGroupVersion, | ||
) | ||
} | ||
|
||
// EnsureAllowedType returns nil if the resourceTemplate has an apiVersion | ||
// and kind field set to one of the allowed ones. | ||
func EnsureAllowedType(rt runtime.RawExtension) error { | ||
_, err := runtime.Decode(Decoder, rt.Raw) | ||
return err | ||
} |
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