istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pilot/pkg/networking/core/configgen.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 core
    16  
    17  import (
    18  	core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
    19  	listener "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
    20  	discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
    21  
    22  	meshconfig "istio.io/api/mesh/v1alpha1"
    23  	"istio.io/istio/pilot/pkg/model"
    24  	dnsProto "istio.io/istio/pkg/dns/proto"
    25  )
    26  
    27  // ConfigGenerator represents the interfaces to be implemented by code that generates xDS responses
    28  type ConfigGenerator interface {
    29  	// BuildListeners returns the list of inbound/outbound listeners for the given proxy. This is the LDS output
    30  	// Internally, the computation will be optimized to ensure that listeners are computed only
    31  	// once and shared across multiple invocations of this function.
    32  	BuildListeners(node *model.Proxy, push *model.PushContext) []*listener.Listener
    33  
    34  	// BuildClusters returns the list of clusters for the given proxy. This is the CDS output
    35  	BuildClusters(node *model.Proxy, req *model.PushRequest) ([]*discovery.Resource, model.XdsLogDetails)
    36  
    37  	// BuildDeltaClusters returns both a list of resources that need to be pushed for a given proxy and a list of resources
    38  	// that have been deleted and should be removed from a given proxy. This is Delta CDS output.
    39  	BuildDeltaClusters(proxy *model.Proxy, updates *model.PushRequest,
    40  		watched *model.WatchedResource) ([]*discovery.Resource, []string, model.XdsLogDetails, bool)
    41  
    42  	// BuildHTTPRoutes returns the list of HTTP routes for the given proxy. This is the RDS output
    43  	BuildHTTPRoutes(node *model.Proxy, req *model.PushRequest, routeNames []string) ([]*discovery.Resource, model.XdsLogDetails)
    44  
    45  	// BuildNameTable returns list of hostnames and the associated IPs
    46  	BuildNameTable(node *model.Proxy, push *model.PushContext) *dnsProto.NameTable
    47  
    48  	// BuildExtensionConfiguration returns the list of extension configuration for the given proxy and list of names. This is the ECDS output.
    49  	BuildExtensionConfiguration(node *model.Proxy, push *model.PushContext, extensionConfigNames []string,
    50  		pullSecrets map[string][]byte) []*core.TypedExtensionConfig
    51  
    52  	// MeshConfigChanged is invoked when mesh config is changed, giving a chance to rebuild any cached config.
    53  	MeshConfigChanged(mesh *meshconfig.MeshConfig)
    54  }
    55  
    56  type ConfigGeneratorImpl struct {
    57  	Cache model.XdsCache
    58  }
    59  
    60  func NewConfigGenerator(cache model.XdsCache) *ConfigGeneratorImpl {
    61  	return &ConfigGeneratorImpl{
    62  		Cache: cache,
    63  	}
    64  }
    65  
    66  // MeshConfigChanged is called when mesh config is changed.
    67  func (configgen *ConfigGeneratorImpl) MeshConfigChanged(_ *meshconfig.MeshConfig) {
    68  	accessLogBuilder.reset()
    69  }