This repository was archived by the owner on Feb 14, 2022. It is now read-only.
File tree 2 files changed +45
-0
lines changed
2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ package apiserver
2
2
3
3
import (
4
4
"net/http"
5
+ "reflect"
6
+ "unsafe"
5
7
6
8
"github.com/docker/compose-on-kubernetes/api/compose/v1alpha3"
7
9
"github.com/docker/compose-on-kubernetes/api/compose/v1beta1"
@@ -53,6 +55,25 @@ func init() {
53
55
if err := conversions .RegisterV1beta2Conversions (Scheme ); err != nil {
54
56
panic (err )
55
57
}
58
+ // We do not support protobuf serialization as the `Stack` struct has
59
+ // fields with unsupported types (e.g.: map[string]*string). This causes
60
+ // issues like https://github.com/docker/compose-on-kubernetes/issues/150.
61
+ // The workaround is to remove protobuf from the advertised supported codecs.
62
+ removeProtobufMediaType (& Codecs )
63
+ }
64
+
65
+ // removeProtobufMediaType removes protobuf from the list of accepted media
66
+ // types for the given CodecFactory.
67
+ func removeProtobufMediaType (c * serializer.CodecFactory ) {
68
+ codecsPtr := reflect .Indirect (reflect .ValueOf (c ))
69
+ accepts := codecsPtr .FieldByName ("accepts" )
70
+ acceptsPtr := (* []runtime.SerializerInfo )(unsafe .Pointer (accepts .UnsafeAddr ()))
71
+ for i , v := range * acceptsPtr {
72
+ if v .MediaType == runtime .ContentTypeProtobuf {
73
+ * acceptsPtr = append ((* acceptsPtr )[0 :i ], (* acceptsPtr )[i + 1 :]... )
74
+ break
75
+ }
76
+ }
56
77
}
57
78
58
79
// Config is the API server config
Original file line number Diff line number Diff line change 1
1
package apiserver
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/stretchr/testify/assert"
7
+ "k8s.io/apimachinery/pkg/runtime"
8
+ "k8s.io/apimachinery/pkg/runtime/serializer"
9
+ )
10
+
11
+ func supportsProtobufCodec (c serializer.CodecFactory ) bool {
12
+ for _ , v := range c .SupportedMediaTypes () {
13
+ if v .MediaType == runtime .ContentTypeProtobuf {
14
+ return true
15
+ }
16
+ }
17
+ return false
18
+ }
19
+
20
+ func TestRemoveProtobuf (t * testing.T ) {
21
+ codecs := serializer .NewCodecFactory (Scheme )
22
+ assert .True (t , supportsProtobufCodec (codecs ))
23
+ removeProtobufMediaType (& codecs )
24
+ assert .False (t , supportsProtobufCodec (codecs ))
25
+ }
You can’t perform that action at this time.
0 commit comments