istio
51 строка · 1.5 Кб
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
15package serviceentry
16
17import (
18"k8s.io/apimachinery/pkg/types"
19
20networking "istio.io/api/networking/v1alpha3"
21"istio.io/istio/pkg/config"
22"istio.io/istio/pkg/config/labels"
23)
24
25func getWorkloadServiceEntries(ses []config.Config, wle *networking.WorkloadEntry) map[types.NamespacedName]*config.Config {
26out := make(map[types.NamespacedName]*config.Config)
27for i, cfg := range ses {
28se := cfg.Spec.(*networking.ServiceEntry)
29if se.WorkloadSelector != nil && labels.Instance(se.WorkloadSelector.Labels).Match(wle.Labels) {
30out[cfg.NamespacedName()] = &ses[i]
31}
32}
33
34return out
35}
36
37// returns a set of objects that are in `old` but not in `curr`
38// For example:
39// old = {a1, a2, a3}
40// curr = {a1, a2, a4, a5}
41// difference(old, curr) = {a3}
42func difference(old, curr map[types.NamespacedName]*config.Config) []types.NamespacedName {
43var out []types.NamespacedName
44for key := range old {
45if _, ok := curr[key]; !ok {
46out = append(out, key)
47}
48}
49
50return out
51}
52