-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add serializer to remove protobuf support (#51)
Signed-off-by: Vishal Choudhary <[email protected]>
- Loading branch information
1 parent
37729fb
commit 86b7b27
Showing
3 changed files
with
41 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package api | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/serializer" | ||
) | ||
|
||
type subsetNegotiatedSerializer struct { | ||
accepts []func(info runtime.SerializerInfo) bool | ||
runtime.NegotiatedSerializer | ||
} | ||
|
||
func (s subsetNegotiatedSerializer) SupportedMediaTypes() []runtime.SerializerInfo { | ||
base := s.NegotiatedSerializer.SupportedMediaTypes() | ||
var filtered []runtime.SerializerInfo | ||
for _, info := range base { | ||
for _, accept := range s.accepts { | ||
if accept(info) { | ||
filtered = append(filtered, info) | ||
break | ||
} | ||
} | ||
} | ||
return filtered | ||
} | ||
|
||
func NoProtobuf(info runtime.SerializerInfo) bool { | ||
return info.MediaType != runtime.ContentTypeProtobuf | ||
} | ||
|
||
func SubsetNegotiatedSerializer(codecs serializer.CodecFactory, accepts ...func(info runtime.SerializerInfo) bool) runtime.NegotiatedSerializer { | ||
return subsetNegotiatedSerializer{accepts, codecs} | ||
} | ||
|
||
func DefaultSubsetNegotiatedSerializer(codecs serializer.CodecFactory) runtime.NegotiatedSerializer { | ||
return SubsetNegotiatedSerializer(codecs, NoProtobuf) | ||
} |
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