Kubernetes: detect changes for resources other than endpoints

This commit is contained in:
Romain 2021-07-30 15:08:10 +02:00 committed by GitHub
parent 4b456f3b76
commit 7f307d60c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 4 deletions

View file

@ -48,12 +48,10 @@ func objChanged(oldObj, newObj interface{}) bool {
} }
if _, ok := oldObj.(*corev1.Endpoints); ok { if _, ok := oldObj.(*corev1.Endpoints); ok {
if endpointsChanged(oldObj.(*corev1.Endpoints), newObj.(*corev1.Endpoints)) { return endpointsChanged(oldObj.(*corev1.Endpoints), newObj.(*corev1.Endpoints))
return true
}
} }
return false return true
} }
func endpointsChanged(a, b *corev1.Endpoints) bool { func endpointsChanged(a, b *corev1.Endpoints) bool {

View file

@ -5,6 +5,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
) )
@ -60,6 +61,33 @@ func Test_detectChanges(t *testing.T) {
}, },
}, },
}, },
{
name: "Ingress With same version",
oldObj: &v1.Ingress{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "1",
},
},
newObj: &v1.Ingress{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "1",
},
},
},
{
name: "Ingress With different version",
oldObj: &v1.Ingress{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "1",
},
},
newObj: &v1.Ingress{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "2",
},
},
want: true,
},
{ {
name: "With same annotations", name: "With same annotations",
oldObj: &corev1.Endpoints{ oldObj: &corev1.Endpoints{