@@ -89,7 +89,9 @@ func New(address string, opts ...ClientOpt) (*Client, error) {
8989 copts .timeout = 10 * time .Second
9090 }
9191
92- c := & Client {}
92+ c := & Client {
93+ defaultns : copts .defaultns ,
94+ }
9395
9496 if copts .defaultRuntime != "" {
9597 c .runtime = copts .defaultRuntime
@@ -142,9 +144,8 @@ func New(address string, opts ...ClientOpt) (*Client, error) {
142144 }
143145
144146 // check namespace labels for default runtime
145- if copts .defaultRuntime == "" && copts .defaultns != "" {
146- ctx := namespaces .WithNamespace (context .Background (), copts .defaultns )
147- if label , err := c .GetLabel (ctx , defaults .DefaultRuntimeNSLabel ); err != nil {
147+ if copts .defaultRuntime == "" && c .defaultns != "" {
148+ if label , err := c .GetLabel (context .Background (), defaults .DefaultRuntimeNSLabel ); err != nil {
148149 return nil , err
149150 } else if label != "" {
150151 c .runtime = label
@@ -164,14 +165,14 @@ func NewWithConn(conn *grpc.ClientConn, opts ...ClientOpt) (*Client, error) {
164165 }
165166 }
166167 c := & Client {
167- conn : conn ,
168- runtime : fmt .Sprintf ("%s.%s" , plugin .RuntimePlugin , runtime .GOOS ),
168+ defaultns : copts .defaultns ,
169+ conn : conn ,
170+ runtime : fmt .Sprintf ("%s.%s" , plugin .RuntimePlugin , runtime .GOOS ),
169171 }
170172
171173 // check namespace labels for default runtime
172- if copts .defaultRuntime == "" && copts .defaultns != "" {
173- ctx := namespaces .WithNamespace (context .Background (), copts .defaultns )
174- if label , err := c .GetLabel (ctx , defaults .DefaultRuntimeNSLabel ); err != nil {
174+ if copts .defaultRuntime == "" && c .defaultns != "" {
175+ if label , err := c .GetLabel (context .Background (), defaults .DefaultRuntimeNSLabel ); err != nil {
175176 return nil , err
176177 } else if label != "" {
177178 c .runtime = label
@@ -191,6 +192,7 @@ type Client struct {
191192 connMu sync.Mutex
192193 conn * grpc.ClientConn
193194 runtime string
195+ defaultns string
194196 connector func () (* grpc.ClientConn , error )
195197}
196198
@@ -497,7 +499,10 @@ func writeIndex(ctx context.Context, index *ocispec.Index, client *Client, ref s
497499func (c * Client ) GetLabel (ctx context.Context , label string ) (string , error ) {
498500 ns , err := namespaces .NamespaceRequired (ctx )
499501 if err != nil {
500- return "" , err
502+ if c .defaultns == "" {
503+ return "" , err
504+ }
505+ ns = c .defaultns
501506 }
502507
503508 srv := c .NamespaceService ()
0 commit comments