istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pilot/pkg/xds/pcds.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 discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3" 19 20 mesh "istio.io/api/mesh/v1alpha1" 21 "istio.io/istio/pilot/pkg/features" 22 "istio.io/istio/pilot/pkg/model" 23 tb "istio.io/istio/pilot/pkg/trustbundle" 24 "istio.io/istio/pilot/pkg/util/protoconv" 25 ) 26 27 // PcdsGenerator generates proxy configuration for proxies to consume 28 type PcdsGenerator struct { 29 TrustBundle *tb.TrustBundle 30 } 31 32 var _ model.XdsResourceGenerator = &PcdsGenerator{} 33 34 func pcdsNeedsPush(req *model.PushRequest) bool { 35 if !features.MultiRootMesh { 36 return false 37 } 38 39 if req == nil { 40 return true 41 } 42 43 if !req.Full { 44 return false 45 } 46 47 if len(req.ConfigsUpdated) == 0 { 48 // This needs to be better optimized 49 return true 50 } 51 52 return false 53 } 54 55 // Generate returns ProxyConfig protobuf containing TrustBundle for given proxy 56 func (e *PcdsGenerator) Generate(proxy *model.Proxy, w *model.WatchedResource, req *model.PushRequest) (model.Resources, model.XdsLogDetails, error) { 57 if !pcdsNeedsPush(req) { 58 return nil, model.DefaultXdsLogDetails, nil 59 } 60 if e.TrustBundle == nil { 61 return nil, model.DefaultXdsLogDetails, nil 62 } 63 // TODO: For now, only TrustBundle updates are pushed. Eventually, this should push entire Proxy Configuration 64 pc := &mesh.ProxyConfig{ 65 CaCertificatesPem: e.TrustBundle.GetTrustBundle(), 66 } 67 return model.Resources{&discovery.Resource{Resource: protoconv.MessageToAny(pc)}}, model.DefaultXdsLogDetails, nil 68 }