k8s.io/kubernetes@v1.29.3/pkg/proxy/metaproxier/meta_proxier.go (about) 1 /* 2 Copyright 2019 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 metaproxier 18 19 import ( 20 v1 "k8s.io/api/core/v1" 21 discovery "k8s.io/api/discovery/v1" 22 "k8s.io/klog/v2" 23 "k8s.io/kubernetes/pkg/proxy" 24 "k8s.io/kubernetes/pkg/proxy/config" 25 ) 26 27 type metaProxier struct { 28 // actual, wrapped 29 ipv4Proxier proxy.Provider 30 // actual, wrapped 31 ipv6Proxier proxy.Provider 32 // TODO(imroc): implement node handler for meta proxier. 33 config.NoopNodeHandler 34 } 35 36 // NewMetaProxier returns a dual-stack "meta-proxier". Proxier API 37 // calls will be dispatched to the ProxyProvider instances depending 38 // on address family. 39 func NewMetaProxier(ipv4Proxier, ipv6Proxier proxy.Provider) proxy.Provider { 40 return proxy.Provider(&metaProxier{ 41 ipv4Proxier: ipv4Proxier, 42 ipv6Proxier: ipv6Proxier, 43 }) 44 } 45 46 // Sync immediately synchronizes the ProxyProvider's current state to 47 // proxy rules. 48 func (proxier *metaProxier) Sync() { 49 proxier.ipv4Proxier.Sync() 50 proxier.ipv6Proxier.Sync() 51 } 52 53 // SyncLoop runs periodic work. This is expected to run as a 54 // goroutine or as the main loop of the app. It does not return. 55 func (proxier *metaProxier) SyncLoop() { 56 go proxier.ipv6Proxier.SyncLoop() // Use go-routine here! 57 proxier.ipv4Proxier.SyncLoop() // never returns 58 } 59 60 // OnServiceAdd is called whenever creation of new service object is observed. 61 func (proxier *metaProxier) OnServiceAdd(service *v1.Service) { 62 proxier.ipv4Proxier.OnServiceAdd(service) 63 proxier.ipv6Proxier.OnServiceAdd(service) 64 } 65 66 // OnServiceUpdate is called whenever modification of an existing 67 // service object is observed. 68 func (proxier *metaProxier) OnServiceUpdate(oldService, service *v1.Service) { 69 proxier.ipv4Proxier.OnServiceUpdate(oldService, service) 70 proxier.ipv6Proxier.OnServiceUpdate(oldService, service) 71 } 72 73 // OnServiceDelete is called whenever deletion of an existing service 74 // object is observed. 75 func (proxier *metaProxier) OnServiceDelete(service *v1.Service) { 76 proxier.ipv4Proxier.OnServiceDelete(service) 77 proxier.ipv6Proxier.OnServiceDelete(service) 78 79 } 80 81 // OnServiceSynced is called once all the initial event handlers were 82 // called and the state is fully propagated to local cache. 83 func (proxier *metaProxier) OnServiceSynced() { 84 proxier.ipv4Proxier.OnServiceSynced() 85 proxier.ipv6Proxier.OnServiceSynced() 86 } 87 88 // OnEndpointSliceAdd is called whenever creation of a new endpoint slice object 89 // is observed. 90 func (proxier *metaProxier) OnEndpointSliceAdd(endpointSlice *discovery.EndpointSlice) { 91 switch endpointSlice.AddressType { 92 case discovery.AddressTypeIPv4: 93 proxier.ipv4Proxier.OnEndpointSliceAdd(endpointSlice) 94 case discovery.AddressTypeIPv6: 95 proxier.ipv6Proxier.OnEndpointSliceAdd(endpointSlice) 96 default: 97 klog.ErrorS(nil, "EndpointSlice address type not supported", "addressType", endpointSlice.AddressType) 98 } 99 } 100 101 // OnEndpointSliceUpdate is called whenever modification of an existing endpoint 102 // slice object is observed. 103 func (proxier *metaProxier) OnEndpointSliceUpdate(oldEndpointSlice, newEndpointSlice *discovery.EndpointSlice) { 104 switch newEndpointSlice.AddressType { 105 case discovery.AddressTypeIPv4: 106 proxier.ipv4Proxier.OnEndpointSliceUpdate(oldEndpointSlice, newEndpointSlice) 107 case discovery.AddressTypeIPv6: 108 proxier.ipv6Proxier.OnEndpointSliceUpdate(oldEndpointSlice, newEndpointSlice) 109 default: 110 klog.ErrorS(nil, "EndpointSlice address type not supported", "addressType", newEndpointSlice.AddressType) 111 } 112 } 113 114 // OnEndpointSliceDelete is called whenever deletion of an existing endpoint slice 115 // object is observed. 116 func (proxier *metaProxier) OnEndpointSliceDelete(endpointSlice *discovery.EndpointSlice) { 117 switch endpointSlice.AddressType { 118 case discovery.AddressTypeIPv4: 119 proxier.ipv4Proxier.OnEndpointSliceDelete(endpointSlice) 120 case discovery.AddressTypeIPv6: 121 proxier.ipv6Proxier.OnEndpointSliceDelete(endpointSlice) 122 default: 123 klog.ErrorS(nil, "EndpointSlice address type not supported", "addressType", endpointSlice.AddressType) 124 } 125 } 126 127 // OnEndpointSlicesSynced is called once all the initial event handlers were 128 // called and the state is fully propagated to local cache. 129 func (proxier *metaProxier) OnEndpointSlicesSynced() { 130 proxier.ipv4Proxier.OnEndpointSlicesSynced() 131 proxier.ipv6Proxier.OnEndpointSlicesSynced() 132 } 133 134 // OnNodeAdd is called whenever creation of new node object is observed. 135 func (proxier *metaProxier) OnNodeAdd(node *v1.Node) { 136 proxier.ipv4Proxier.OnNodeAdd(node) 137 proxier.ipv6Proxier.OnNodeAdd(node) 138 } 139 140 // OnNodeUpdate is called whenever modification of an existing 141 // node object is observed. 142 func (proxier *metaProxier) OnNodeUpdate(oldNode, node *v1.Node) { 143 proxier.ipv4Proxier.OnNodeUpdate(oldNode, node) 144 proxier.ipv6Proxier.OnNodeUpdate(oldNode, node) 145 } 146 147 // OnNodeDelete is called whenever deletion of an existing node 148 // object is observed. 149 func (proxier *metaProxier) OnNodeDelete(node *v1.Node) { 150 proxier.ipv4Proxier.OnNodeDelete(node) 151 proxier.ipv6Proxier.OnNodeDelete(node) 152 153 } 154 155 // OnNodeSynced is called once all the initial event handlers were 156 // called and the state is fully propagated to local cache. 157 func (proxier *metaProxier) OnNodeSynced() { 158 proxier.ipv4Proxier.OnNodeSynced() 159 proxier.ipv6Proxier.OnNodeSynced() 160 }