istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pilot/pkg/xds/rds.go (about) 1 // Copyright Istio Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package xds 16 17 import ( 18 "istio.io/istio/pilot/pkg/model" 19 "istio.io/istio/pilot/pkg/networking/core" 20 "istio.io/istio/pkg/config/schema/kind" 21 "istio.io/istio/pkg/util/sets" 22 ) 23 24 type RdsGenerator struct { 25 ConfigGenerator core.ConfigGenerator 26 } 27 28 var _ model.XdsResourceGenerator = &RdsGenerator{} 29 30 // Map of all configs that do not impact RDS 31 var skippedRdsConfigs = sets.New[kind.Kind]( 32 kind.WorkloadEntry, 33 kind.WorkloadGroup, 34 kind.AuthorizationPolicy, 35 kind.RequestAuthentication, 36 kind.PeerAuthentication, 37 kind.Secret, 38 kind.WasmPlugin, 39 kind.Telemetry, 40 kind.ProxyConfig, 41 kind.DNSName, 42 ) 43 44 func rdsNeedsPush(req *model.PushRequest) bool { 45 if req == nil { 46 return true 47 } 48 if !req.Full { 49 // RDS only handles full push 50 return false 51 } 52 // If none set, we will always push 53 if len(req.ConfigsUpdated) == 0 { 54 return true 55 } 56 for config := range req.ConfigsUpdated { 57 if !skippedRdsConfigs.Contains(config.Kind) { 58 return true 59 } 60 } 61 return false 62 } 63 64 func (c RdsGenerator) Generate(proxy *model.Proxy, w *model.WatchedResource, req *model.PushRequest) (model.Resources, model.XdsLogDetails, error) { 65 if !rdsNeedsPush(req) { 66 return nil, model.DefaultXdsLogDetails, nil 67 } 68 resources, logDetails := c.ConfigGenerator.BuildHTTPRoutes(proxy, req, w.ResourceNames) 69 return resources, logDetails, nil 70 }