...

Source file src/k8s.io/kubernetes/test/e2e_node/util_sampledevice.go

Documentation: k8s.io/kubernetes/test/e2e_node

     1  /*
     2  Copyright 2023 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 e2enode
    18  
    19  import (
    20  	v1 "k8s.io/api/core/v1"
    21  )
    22  
    23  const (
    24  	// SampleDevicePluginDSYAML is the path of the daemonset template of the sample device plugin. // TODO: Parametrize it by making it a feature in TestFramework.
    25  	SampleDevicePluginDSYAML                    = "test/e2e/testing-manifests/sample-device-plugin/sample-device-plugin.yaml"
    26  	SampleDevicePluginControlRegistrationDSYAML = "test/e2e/testing-manifests/sample-device-plugin/sample-device-plugin-control-registration.yaml"
    27  
    28  	// SampleDevicePluginName is the name of the device plugin pod
    29  	SampleDevicePluginName = "sample-device-plugin"
    30  
    31  	// SampleDeviceResourceName is the name of the resource provided by the sample device plugin
    32  	SampleDeviceResourceName = "example.com/resource"
    33  
    34  	SampleDeviceEnvVarNamePluginSockDir = "PLUGIN_SOCK_DIR"
    35  )
    36  
    37  // CountSampleDeviceCapacity returns the number of devices of SampleDeviceResourceName advertised by a node capacity
    38  func CountSampleDeviceCapacity(node *v1.Node) int64 {
    39  	val, ok := node.Status.Capacity[v1.ResourceName(SampleDeviceResourceName)]
    40  	if !ok {
    41  		return 0
    42  	}
    43  	return val.Value()
    44  }
    45  
    46  // CountSampleDeviceAllocatable returns the number of devices of SampleDeviceResourceName advertised by a node allocatable
    47  func CountSampleDeviceAllocatable(node *v1.Node) int64 {
    48  	val, ok := node.Status.Allocatable[v1.ResourceName(SampleDeviceResourceName)]
    49  	if !ok {
    50  		return 0
    51  	}
    52  	return val.Value()
    53  }
    54  

View as plain text