...

Source file src/k8s.io/kubernetes/pkg/kubelet/apis/podresources/client.go

Documentation: k8s.io/kubernetes/pkg/kubelet/apis/podresources

     1  /*
     2  Copyright 2018 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package podresources
    18  
    19  import (
    20  	"context"
    21  	"fmt"
    22  	"time"
    23  
    24  	"google.golang.org/grpc"
    25  	"google.golang.org/grpc/credentials/insecure"
    26  
    27  	"k8s.io/kubelet/pkg/apis/podresources/v1"
    28  	"k8s.io/kubelet/pkg/apis/podresources/v1alpha1"
    29  	"k8s.io/kubernetes/pkg/kubelet/util"
    30  )
    31  
    32  // Note: Consumers of the pod resources API should not be importing this package.
    33  // They should copy paste the function in their project.
    34  
    35  // GetV1alpha1Client returns a client for the PodResourcesLister grpc service
    36  // Note: This is deprecated
    37  func GetV1alpha1Client(socket string, connectionTimeout time.Duration, maxMsgSize int) (v1alpha1.PodResourcesListerClient, *grpc.ClientConn, error) {
    38  	addr, dialer, err := util.GetAddressAndDialer(socket)
    39  	if err != nil {
    40  		return nil, nil, err
    41  	}
    42  	ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout)
    43  	defer cancel()
    44  
    45  	conn, err := grpc.DialContext(ctx, addr,
    46  		grpc.WithTransportCredentials(insecure.NewCredentials()),
    47  		grpc.WithContextDialer(dialer),
    48  		grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)))
    49  	if err != nil {
    50  		return nil, nil, fmt.Errorf("error dialing socket %s: %v", socket, err)
    51  	}
    52  	return v1alpha1.NewPodResourcesListerClient(conn), conn, nil
    53  }
    54  
    55  // GetV1Client returns a client for the PodResourcesLister grpc service
    56  func GetV1Client(socket string, connectionTimeout time.Duration, maxMsgSize int) (v1.PodResourcesListerClient, *grpc.ClientConn, error) {
    57  	addr, dialer, err := util.GetAddressAndDialer(socket)
    58  	if err != nil {
    59  		return nil, nil, err
    60  	}
    61  	ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout)
    62  	defer cancel()
    63  
    64  	conn, err := grpc.DialContext(ctx, addr,
    65  		grpc.WithTransportCredentials(insecure.NewCredentials()),
    66  		grpc.WithContextDialer(dialer),
    67  		grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)))
    68  	if err != nil {
    69  		return nil, nil, fmt.Errorf("error dialing socket %s: %v", socket, err)
    70  	}
    71  	return v1.NewPodResourcesListerClient(conn), conn, nil
    72  }
    73  

View as plain text