@@ -36,10 +36,9 @@ type namespaceKey struct{}
3636// WithNamespace sets a given namespace on the context
3737func WithNamespace (ctx context.Context , namespace string ) context.Context {
3838 ctx = context .WithValue (ctx , namespaceKey {}, namespace ) // set our key for namespace
39-
40- // also store on the grpc headers so it gets picked up by any clients that
39+ // also store on the grpc and ttrpc headers so it gets picked up by any clients that
4140 // are using this.
42- return withGRPCNamespaceHeader (ctx , namespace )
41+ return withTTRPCNamespaceHeader ( withGRPCNamespaceHeader (ctx , namespace ) , namespace )
4342}
4443
4544// NamespaceFromEnv uses the namespace defined in CONTAINERD_NAMESPACE or
@@ -58,9 +57,10 @@ func NamespaceFromEnv(ctx context.Context) context.Context {
5857func Namespace (ctx context.Context ) (string , bool ) {
5958 namespace , ok := ctx .Value (namespaceKey {}).(string )
6059 if ! ok {
61- return fromGRPCHeader (ctx )
60+ if namespace , ok = fromGRPCHeader (ctx ); ! ok {
61+ return fromTTRPCHeader (ctx )
62+ }
6263 }
63-
6464 return namespace , ok
6565}
6666
@@ -70,10 +70,8 @@ func NamespaceRequired(ctx context.Context) (string, error) {
7070 if ! ok || namespace == "" {
7171 return "" , errors .Wrapf (errdefs .ErrFailedPrecondition , "namespace is required" )
7272 }
73-
7473 if err := Validate (namespace ); err != nil {
7574 return "" , errors .Wrap (err , "namespace validation" )
7675 }
77-
7876 return namespace , nil
7977}
0 commit comments