Detect support for protobuf array ref on server on frontend return call

Signed-off-by: Edgar Lee <edgarl@netflix.com>
v0.7
Edgar Lee 2020-01-14 16:45:37 -08:00
parent 359574093b
commit d81832cf6c
3 changed files with 38 additions and 10 deletions

View File

@ -105,6 +105,7 @@ func (c *grpcClient) Run(ctx context.Context, f client.BuildFunc) (retError erro
Metadata: res.Metadata,
}
if res.Refs != nil {
if c.caps.Supports(pb.CapProtoRefArray) == nil {
m := map[string]*pb.Ref{}
for k, r := range res.Refs {
id, err := convertRef(r)
@ -115,12 +116,28 @@ func (c *grpcClient) Run(ctx context.Context, f client.BuildFunc) (retError erro
m[k] = pb.NewRef(id)
}
pbRes.Result = &pb.Result_Refs{Refs: &pb.RefMap{Refs: m}}
} else {
m := map[string]string{}
for k, r := range res.Refs {
id, err := convertRef(r)
if err != nil {
retError = err
continue
}
m[k] = id
}
pbRes.Result = &pb.Result_RefsDeprecated{RefsDeprecated: &pb.RefMapDeprecated{Refs: m}}
}
} else {
id, err := convertRef(res.Ref)
if err != nil {
retError = err
} else {
if c.caps.Supports(pb.CapProtoRefArray) == nil {
pbRes.Result = &pb.Result_Ref{Ref: pb.NewRef(id)}
} else {
pbRes.Result = &pb.Result_RefDeprecated{RefDeprecated: id}
}
}
}
if retError == nil {

View File

@ -19,6 +19,11 @@ const (
CapReadDir apicaps.CapID = "readdir"
CapStatFile apicaps.CapID = "statfile"
CapImportCaches apicaps.CapID = "importcaches"
// CapProtoRefArray is a capability to return arrays of refs instead of single
// refs. This capability is only for the wire format change and shouldn't be
// used in frontends for feature detection.
CapProtoRefArray apicaps.CapID = "proto.refarray"
)
func init() {
@ -92,4 +97,11 @@ func init() {
Enabled: true,
Status: apicaps.CapStatusExperimental,
})
Caps.Init(apicaps.Cap{
ID: CapProtoRefArray,
Name: "wire format ref arrays",
Enabled: true,
Status: apicaps.CapStatusExperimental,
})
}

View File

@ -288,5 +288,4 @@ func init() {
Enabled: true,
Status: apicaps.CapStatusExperimental,
})
}