istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pilot/pkg/serviceregistry/instance.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 serviceregistry
    16  
    17  import (
    18  	"istio.io/istio/pilot/pkg/model"
    19  	"istio.io/istio/pilot/pkg/serviceregistry/provider"
    20  	"istio.io/istio/pkg/cluster"
    21  )
    22  
    23  // Instance of a service registry. A single service registry combines the capabilities of service discovery
    24  // and the controller for managing asynchronous events.
    25  type Instance interface {
    26  	model.Controller
    27  	model.ServiceDiscovery
    28  
    29  	// Provider backing this service registry (i.e. Kubernetes etc.)
    30  	Provider() provider.ID
    31  
    32  	// Cluster for which the service registry applies. Only needed for multicluster systems.
    33  	Cluster() cluster.ID
    34  }
    35  
    36  var _ Instance = &Simple{}
    37  
    38  type DiscoveryController interface {
    39  	model.Controller
    40  	model.ServiceDiscovery
    41  }
    42  
    43  // Simple Instance implementation, where fields are set individually.
    44  type Simple struct {
    45  	ProviderID provider.ID
    46  	ClusterID  cluster.ID
    47  
    48  	DiscoveryController
    49  }
    50  
    51  func (r Simple) Provider() provider.ID {
    52  	return r.ProviderID
    53  }
    54  
    55  func (r Simple) Cluster() cluster.ID {
    56  	return r.ClusterID
    57  }