istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pilot/pkg/bootstrap/config_compare.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 bootstrap 16 17 import ( 18 "strings" 19 20 gogoproto "github.com/gogo/protobuf/proto" // nolint: depguard 21 "google.golang.org/protobuf/proto" 22 23 "istio.io/istio/pkg/config" 24 ) 25 26 // needsPush checks whether the passed in config has same spec and hence push needs 27 // to be triggered. This is to avoid unnecessary pushes only when labels have changed 28 // for example. 29 func needsPush(prev config.Config, curr config.Config) bool { 30 if prev.GroupVersionKind != curr.GroupVersionKind { 31 // This should never happen. 32 return true 33 } 34 // If the config is not Istio, let us just push. 35 if !strings.HasSuffix(prev.GroupVersionKind.Group, "istio.io") { 36 return true 37 } 38 // If current/previous metadata has "*istio.io" label/annotation, just push 39 for label := range curr.Meta.Labels { 40 if strings.Contains(label, "istio.io") { 41 return true 42 } 43 } 44 for annotation := range curr.Meta.Annotations { 45 if strings.Contains(annotation, "istio.io") { 46 return true 47 } 48 } 49 for label := range prev.Meta.Labels { 50 if strings.Contains(label, "istio.io") { 51 return true 52 } 53 } 54 for annotation := range prev.Meta.Annotations { 55 if strings.Contains(annotation, "istio.io") { 56 return true 57 } 58 } 59 prevspecProto, okProtoP := prev.Spec.(proto.Message) 60 currspecProto, okProtoC := curr.Spec.(proto.Message) 61 if okProtoP && okProtoC { 62 return !proto.Equal(prevspecProto, currspecProto) 63 } 64 prevspecGogo, okGogoP := prev.Spec.(gogoproto.Message) 65 currspecGogo, okGogoC := curr.Spec.(gogoproto.Message) 66 if okGogoP && okGogoC { 67 return !gogoproto.Equal(prevspecGogo, currspecGogo) 68 } 69 return true 70 }