Skip to content

Commit 6ee1358

Browse files
committed
Update sync diff options to avoid common loops with k8s components
As DevWorkspaces can define Kubernetes objects in components, it's necessary to improve the checks we do to determine if an object on the cluster needs to be updated. This is especially an issue in the case of defaulted fields in objects, as comparing in a straightforward way will mean the object has to be updated every single time. Signed-off-by: Angel Misevski <[email protected]>
1 parent bb0a743 commit 6ee1358

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pkg/provision/sync/diff.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
2222
"github.com/google/go-cmp/cmp"
23+
"github.com/google/go-cmp/cmp/cmpopts"
2324
routev1 "github.com/openshift/api/route/v1"
2425
appsv1 "k8s.io/api/apps/v1"
2526
batchv1 "k8s.io/api/batch/v1"
@@ -137,10 +138,11 @@ func serviceDiffFunc(spec, cluster crclient.Object) (delete, update bool) {
137138
}
138139
sort.Slice(specCopy.Spec.Ports, servicePortSorter(specCopy.Spec.Ports))
139140
sort.Slice(clusterCopy.Spec.Ports, servicePortSorter(clusterCopy.Spec.Ports))
140-
if !cmp.Equal(specCopy.Spec.Ports, clusterCopy.Spec.Ports) {
141+
if !cmp.Equal(specCopy.Spec.Ports, clusterCopy.Spec.Ports, cmp.Options{cmpopts.IgnoreFields(corev1.ServicePort{}, "Protocol")}) {
141142
return false, true
142143
}
143-
return false, specCopy.Spec.Type != clusterCopy.Spec.Type
144+
typeMatches := specCopy.Spec.Type == "" || specCopy.Spec.Type == clusterCopy.Spec.Type
145+
return false, !typeMatches
144146
}
145147

146148
func unrecognizedObjectDiffFunc(spec, cluster crclient.Object) (delete, update bool) {

0 commit comments

Comments
 (0)