Skip to content

Commit

Permalink
Remove auto vip allocation
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Dorosh <kevin.dorosh@solo.io>
  • Loading branch information
Kevin Dorosh committed Jul 6, 2023
1 parent 99b26b2 commit 37e605d
Show file tree
Hide file tree
Showing 15 changed files with 204 additions and 257 deletions.
16 changes: 0 additions & 16 deletions pilot/pkg/model/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"google.golang.org/protobuf/proto"

"istio.io/api/label"
networking "istio.io/api/networking/v1alpha3"
"istio.io/istio/pilot/pkg/features"
"istio.io/istio/pilot/pkg/serviceregistry/provider"
"istio.io/istio/pkg/cluster"
Expand Down Expand Up @@ -615,15 +614,6 @@ type ServiceAttributes struct {
// a namespace when the namespace is imported.
ExportTo map[visibility.Instance]bool

// The service entry (if any) name
ServiceEntryName string

// The service entry (if any) namespace
ServiceEntryNamespace string

// The service entry spec (if any) this service was derived from.
ServiceEntry *networking.ServiceEntry

// LabelSelectors are the labels used by the service to select workloads.
// Applicable to both Kubernetes and ServiceEntries.
LabelSelectors map[string]string
Expand Down Expand Up @@ -665,12 +655,6 @@ func (s *ServiceAttributes) DeepCopy() ServiceAttributes {
// nolint: govet
out := *s

if s.ServiceEntry != nil {
out.ServiceEntry = s.ServiceEntry.DeepCopy()
}
out.ServiceEntryName = s.ServiceEntryName
out.ServiceEntryNamespace = s.ServiceEntryNamespace

if s.Labels != nil {
out.Labels = make(map[string]string, len(s.Labels))
for k, v := range s.Labels {
Expand Down
2 changes: 1 addition & 1 deletion pilot/pkg/model/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ func TestFuzzServiceDeepCopy(t *testing.T) {
originalSvc := &Service{}
fuzzer.Fuzz(originalSvc)
copied := originalSvc.DeepCopy()
opts := []cmp.Option{cmp.AllowUnexported(), cmpopts.IgnoreFields(AddressMap{}, "mutex"), cmpopts.IgnoreFields(ServiceAttributes{}, "ServiceEntry")}
opts := []cmp.Option{cmp.AllowUnexported(), cmpopts.IgnoreFields(AddressMap{}, "mutex")}
if !cmp.Equal(originalSvc, copied, opts...) {
diff := cmp.Diff(originalSvc, copied, opts...)
t.Errorf("unexpected diff %v", diff)
Expand Down
37 changes: 26 additions & 11 deletions pilot/pkg/serviceregistry/kube/controller/ambientindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@ type AmbientIndex interface {
Waypoint(scope model.WaypointScope) []netip.Addr
CalculateUpdatedWorkloads(pods map[string]*v1.Pod, workloadEntries map[networkAddress]*apiv1alpha3.WorkloadEntry, c *Controller) map[model.ConfigKey]struct{}
HandleSelectedNamespace(ns string, pods []*v1.Pod, c *Controller)
// HandleServiceEntry updates ambient index served xds on any service entry create/update/delete
// or VIP re auto-allocation event.
//
// We handle service entry events using an externally called hook instead of a k8s informer
// because we need to support auto allocation of VIPs; calculating these IPs is an expensive
// operation and already batched elsewhere in the repo. Instead we just wait for those events
// and events propagated from another service entry controller and act on those.
HandleServiceEntry(svc *model.Service, event model.Event, c *Controller)
}

// AmbientIndexImpl maintains an index of ambient WorkloadInfo objects by various keys.
Expand All @@ -83,10 +75,10 @@ type AmbientIndexImpl struct {
// Map of Scope -> address
waypoints map[model.WaypointScope]*workloadapi.GatewayAddress

// map of service entry name/namespace to the derived service.
// map of service entry name/namespace to the service entry.
// used on pod updates to add VIPs to pods from service entries.
// also used on service entry updates to cleanup any old VIPs from pods/workloads maps.
servicesMap map[types.NamespacedName]*model.Service
servicesMap map[types.NamespacedName]*apiv1alpha3.ServiceEntry
}

func workloadToAddressInfo(w *workloadapi.Workload) *model.AddressInfo {
Expand Down Expand Up @@ -447,6 +439,29 @@ func (c *Controller) setupIndex() *AmbientIndexImpl {
}
})

// Handle ServiceEntries.
c.configController.RegisterEventHandler(gvk.ServiceEntry, func(_ config.Config, newCfg config.Config, ev model.Event) {
newSvcEntrySpec := serviceentry.ConvertServiceEntry(newCfg)
var newSvcEntry *apiv1alpha3.ServiceEntry
if newSvcEntrySpec != nil {
newSvcEntry = &apiv1alpha3.ServiceEntry{
ObjectMeta: newCfg.ToObjectMeta(),
Spec: *newSvcEntrySpec.DeepCopy(),
}
}

idx.mu.Lock()
defer idx.mu.Unlock()
updates := idx.handleServiceEntry(newSvcEntry, ev, c)
if len(updates) > 0 {
c.opts.XDSUpdater.ConfigUpdate(&model.PushRequest{
Full: false,
ConfigsUpdated: updates,
Reason: []model.TriggerReason{model.AmbientUpdate},
})
}
})

serviceHandler := cache.ResourceEventHandlerFuncs{
AddFunc: func(obj any) {
idx.mu.Lock()
Expand Down Expand Up @@ -492,7 +507,7 @@ func (c *Controller) setupIndex() *AmbientIndexImpl {
},
}

idx.servicesMap = make(map[types.NamespacedName]*model.Service)
idx.servicesMap = make(map[types.NamespacedName]*apiv1alpha3.ServiceEntry)
c.services.AddEventHandler(serviceHandler)
return &idx
}
Expand Down

0 comments on commit 37e605d

Please sign in to comment.