github.com/kubewharf/katalyst-core@v0.5.3/cmd/katalyst-agent/app/options/qrm/network_plugin.go (about) 1 /* 2 Copyright 2022 The Katalyst 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 qrm 18 19 import ( 20 cliflag "k8s.io/component-base/cli/flag" 21 22 "github.com/kubewharf/katalyst-api/pkg/consts" 23 qrmconfig "github.com/kubewharf/katalyst-core/pkg/config/agent/qrm" 24 ) 25 26 type NetworkOptions struct { 27 PolicyName string 28 NetClass NetClassOptions 29 ReservedBandwidth uint32 30 EgressCapacityRate float32 31 IngressCapacityRate float32 32 SkipNetworkStateCorruption bool 33 PodLevelNetClassAnnoKey string 34 PodLevelNetAttributesAnnoKeys string 35 IPv4ResourceAllocationAnnotationKey string 36 IPv6ResourceAllocationAnnotationKey string 37 NetNSPathResourceAllocationAnnotationKey string 38 NetInterfaceNameResourceAllocationAnnotationKey string 39 NetClassIDResourceAllocationAnnotationKey string 40 NetBandwidthResourceAllocationAnnotationKey string 41 } 42 43 type NetClassOptions struct { 44 // ReclaimedCores is the network class id for reclaimed_cores 45 ReclaimedCores uint32 46 // SharedCores is the network class id for shared_cores 47 SharedCores uint32 48 // DedicatedCores is the network class id for dedicated_cores 49 DedicatedCores uint32 50 // SystemCores is the network class id for system_cores 51 SystemCores uint32 52 } 53 54 func NewNetworkOptions() *NetworkOptions { 55 return &NetworkOptions{ 56 PolicyName: "static", 57 PodLevelNetClassAnnoKey: consts.PodAnnotationNetClassKey, 58 ReservedBandwidth: 0, 59 EgressCapacityRate: 0.94, 60 IngressCapacityRate: 0.9, 61 SkipNetworkStateCorruption: false, 62 PodLevelNetAttributesAnnoKeys: "", 63 IPv4ResourceAllocationAnnotationKey: "qrm.katalyst.kubewharf.io/inet_addr", 64 IPv6ResourceAllocationAnnotationKey: "qrm.katalyst.kubewharf.io/inet_addr_ipv6", 65 NetNSPathResourceAllocationAnnotationKey: "qrm.katalyst.kubewharf.io/netns_path", 66 NetInterfaceNameResourceAllocationAnnotationKey: "qrm.katalyst.kubewharf.io/nic_name", 67 NetClassIDResourceAllocationAnnotationKey: "qrm.katalyst.kubewharf.io/netcls_id", 68 NetBandwidthResourceAllocationAnnotationKey: "qrm.katalyst.kubewharf.io/net_bandwidth", 69 } 70 } 71 72 func (o *NetworkOptions) AddFlags(fss *cliflag.NamedFlagSets) { 73 fs := fss.FlagSet("network_resource_plugin") 74 75 fs.StringVar(&o.PolicyName, "network-resource-plugin-policy", 76 o.PolicyName, "The policy network resource plugin should use") 77 fs.Uint32Var(&o.NetClass.ReclaimedCores, "network-resource-plugin-class-id-reclaimed-cores", 78 o.NetClass.ReclaimedCores, "net class id for reclaimed_cores") 79 fs.Uint32Var(&o.NetClass.SharedCores, "network-resource-plugin-class-id-shared-cores", 80 o.NetClass.SharedCores, "net class id for shared_cores") 81 fs.Uint32Var(&o.NetClass.DedicatedCores, "network-resource-plugin-class-id-dedicated-cores", 82 o.NetClass.DedicatedCores, "net class id for dedicated_cores") 83 fs.Uint32Var(&o.NetClass.SystemCores, "network-resource-plugin-class-id-system-cores", 84 o.NetClass.SystemCores, "net class id for system_cores") 85 fs.Uint32Var(&o.ReservedBandwidth, "network-resource-plugin-reserved-bandwidth", 86 o.ReservedBandwidth, "reserved bandwidth for business-critical jobs") 87 fs.Float32Var(&o.EgressCapacityRate, "network-resource-plugin-egress-capacity-rate", 88 o.EgressCapacityRate, "ratio of available egress capacity to egress line speed") 89 fs.Float32Var(&o.IngressCapacityRate, "network-resource-plugin-ingress-capacity-rate", 90 o.IngressCapacityRate, "ratio of available ingress capacity to ingress line speed") 91 fs.BoolVar(&o.SkipNetworkStateCorruption, "skip-network-state-corruption", 92 o.SkipNetworkStateCorruption, "if set true, we will skip network state corruption") 93 fs.StringVar(&o.PodLevelNetClassAnnoKey, "network-resource-plugin-net-class-annotation-key", 94 o.PodLevelNetClassAnnoKey, "The annotation key of pod-level net class") 95 fs.StringVar(&o.PodLevelNetAttributesAnnoKeys, "network-resource-plugin-net-attributes-keys", 96 o.PodLevelNetAttributesAnnoKeys, "The annotation keys of pod-level network attributes, separated by commas") 97 fs.StringVar(&o.IPv4ResourceAllocationAnnotationKey, "network-resource-plugin-ipv4-allocation-anno-key", 98 o.IPv4ResourceAllocationAnnotationKey, "The annotation key of allocated ipv4 address for the container, which is ready by runtime") 99 fs.StringVar(&o.IPv6ResourceAllocationAnnotationKey, "network-resource-plugin-ipv6-allocation-anno-key", 100 o.IPv6ResourceAllocationAnnotationKey, "The annotation key of allocated ipv6 address for the container, which is ready by runtime") 101 fs.StringVar(&o.NetNSPathResourceAllocationAnnotationKey, "network-resource-plugin-ns-path-allocation-anno-key", 102 o.NetNSPathResourceAllocationAnnotationKey, "The annotation key of allocated ns path for the container, which is ready by runtime") 103 fs.StringVar(&o.NetInterfaceNameResourceAllocationAnnotationKey, "network-resource-plugin-nic-name-allocation-anno-key", 104 o.NetInterfaceNameResourceAllocationAnnotationKey, "The annotation key of allocated nic name the container, which is ready by runtime") 105 fs.StringVar(&o.NetClassIDResourceAllocationAnnotationKey, "network-resource-plugin-class-id-allocation-anno-key", 106 o.NetClassIDResourceAllocationAnnotationKey, "The annotation key of allocated netcls id for the container, which is ready by runtime") 107 fs.StringVar(&o.NetBandwidthResourceAllocationAnnotationKey, "network-resource-plugin-bandwidth-allocation-anno-key", 108 o.NetBandwidthResourceAllocationAnnotationKey, "The annotation key of allocated bandwidth for the container, which is ready by runtime") 109 } 110 111 func (o *NetworkOptions) ApplyTo(conf *qrmconfig.NetworkQRMPluginConfig) error { 112 conf.PolicyName = o.PolicyName 113 conf.NetClass.ReclaimedCores = o.NetClass.ReclaimedCores 114 conf.NetClass.SharedCores = o.NetClass.SharedCores 115 conf.NetClass.DedicatedCores = o.NetClass.DedicatedCores 116 conf.NetClass.SystemCores = o.NetClass.SystemCores 117 conf.ReservedBandwidth = o.ReservedBandwidth 118 conf.EgressCapacityRate = o.EgressCapacityRate 119 conf.IngressCapacityRate = o.IngressCapacityRate 120 conf.SkipNetworkStateCorruption = o.SkipNetworkStateCorruption 121 conf.PodLevelNetClassAnnoKey = o.PodLevelNetClassAnnoKey 122 conf.PodLevelNetAttributesAnnoKeys = o.PodLevelNetAttributesAnnoKeys 123 conf.IPv4ResourceAllocationAnnotationKey = o.IPv4ResourceAllocationAnnotationKey 124 conf.IPv6ResourceAllocationAnnotationKey = o.IPv6ResourceAllocationAnnotationKey 125 conf.NetNSPathResourceAllocationAnnotationKey = o.NetNSPathResourceAllocationAnnotationKey 126 conf.NetInterfaceNameResourceAllocationAnnotationKey = o.NetInterfaceNameResourceAllocationAnnotationKey 127 conf.NetClassIDResourceAllocationAnnotationKey = o.NetClassIDResourceAllocationAnnotationKey 128 conf.NetBandwidthResourceAllocationAnnotationKey = o.NetBandwidthResourceAllocationAnnotationKey 129 130 return nil 131 }