Save default namespace in the client.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
parent
d0f4cf0bde
commit
af7b7cdb02
25
client.go
25
client.go
@ -89,7 +89,9 @@ func New(address string, opts ...ClientOpt) (*Client, error) {
|
|||||||
copts.timeout = 10 * time.Second
|
copts.timeout = 10 * time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
c := &Client{}
|
c := &Client{
|
||||||
|
defaultns: copts.defaultns,
|
||||||
|
}
|
||||||
|
|
||||||
if copts.defaultRuntime != "" {
|
if copts.defaultRuntime != "" {
|
||||||
c.runtime = copts.defaultRuntime
|
c.runtime = copts.defaultRuntime
|
||||||
@ -142,9 +144,8 @@ func New(address string, opts ...ClientOpt) (*Client, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check namespace labels for default runtime
|
// check namespace labels for default runtime
|
||||||
if copts.defaultRuntime == "" && copts.defaultns != "" {
|
if copts.defaultRuntime == "" && c.defaultns != "" {
|
||||||
ctx := namespaces.WithNamespace(context.Background(), copts.defaultns)
|
if label, err := c.GetLabel(context.Background(), defaults.DefaultRuntimeNSLabel); err != nil {
|
||||||
if label, err := c.GetLabel(ctx, defaults.DefaultRuntimeNSLabel); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if label != "" {
|
} else if label != "" {
|
||||||
c.runtime = label
|
c.runtime = label
|
||||||
@ -164,14 +165,14 @@ func NewWithConn(conn *grpc.ClientConn, opts ...ClientOpt) (*Client, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
c := &Client{
|
c := &Client{
|
||||||
conn: conn,
|
defaultns: copts.defaultns,
|
||||||
runtime: fmt.Sprintf("%s.%s", plugin.RuntimePlugin, runtime.GOOS),
|
conn: conn,
|
||||||
|
runtime: fmt.Sprintf("%s.%s", plugin.RuntimePlugin, runtime.GOOS),
|
||||||
}
|
}
|
||||||
|
|
||||||
// check namespace labels for default runtime
|
// check namespace labels for default runtime
|
||||||
if copts.defaultRuntime == "" && copts.defaultns != "" {
|
if copts.defaultRuntime == "" && c.defaultns != "" {
|
||||||
ctx := namespaces.WithNamespace(context.Background(), copts.defaultns)
|
if label, err := c.GetLabel(context.Background(), defaults.DefaultRuntimeNSLabel); err != nil {
|
||||||
if label, err := c.GetLabel(ctx, defaults.DefaultRuntimeNSLabel); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if label != "" {
|
} else if label != "" {
|
||||||
c.runtime = label
|
c.runtime = label
|
||||||
@ -191,6 +192,7 @@ type Client struct {
|
|||||||
connMu sync.Mutex
|
connMu sync.Mutex
|
||||||
conn *grpc.ClientConn
|
conn *grpc.ClientConn
|
||||||
runtime string
|
runtime string
|
||||||
|
defaultns string
|
||||||
connector func() (*grpc.ClientConn, error)
|
connector func() (*grpc.ClientConn, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -497,7 +499,10 @@ func writeIndex(ctx context.Context, index *ocispec.Index, client *Client, ref s
|
|||||||
func (c *Client) GetLabel(ctx context.Context, label string) (string, error) {
|
func (c *Client) GetLabel(ctx context.Context, label string) (string, error) {
|
||||||
ns, err := namespaces.NamespaceRequired(ctx)
|
ns, err := namespaces.NamespaceRequired(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
if c.defaultns == "" {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
ns = c.defaultns
|
||||||
}
|
}
|
||||||
|
|
||||||
srv := c.NamespaceService()
|
srv := c.NamespaceService()
|
||||||
|
Loading…
Reference in New Issue
Block a user