Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/common/condition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func UnconflictedServiceExportConflictCondition(internalServiceExport fleetnetv1
Type: string(fleetnetv1alpha1.ServiceExportConflict),
Status: metav1.ConditionFalse,
Reason: conditionReasonNoConflictFound,
ObservedGeneration: internalServiceExport.Spec.ServiceReference.Generation, // use the generation of the original object
ObservedGeneration: internalServiceExport.Generation,
Message: fmt.Sprintf("service %s is exported without conflict", svcName),
}
}
Expand All @@ -91,7 +91,7 @@ func ConflictedServiceExportConflictCondition(internalServiceExport fleetnetv1al
Type: string(fleetnetv1alpha1.ServiceExportConflict),
Status: metav1.ConditionTrue,
Reason: conditionReasonConflictFound,
ObservedGeneration: internalServiceExport.Spec.ServiceReference.Generation, // use the generation of the original object
ObservedGeneration: internalServiceExport.Generation,
Message: fmt.Sprintf("service %s is in conflict with other exported services", svcName),
}
}
10 changes: 8 additions & 2 deletions pkg/common/condition/condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ func TestEqualConditionIgnoreReason(t *testing.T) {

func TestUnconflictedServiceExportConflictCondition(t *testing.T) {
input := fleetnetv1alpha1.InternalServiceExport{
ObjectMeta: metav1.ObjectMeta{
Generation: 456,
},
Spec: fleetnetv1alpha1.InternalServiceExportSpec{
Ports: []fleetnetv1alpha1.ServicePort{
{
Expand Down Expand Up @@ -267,7 +270,7 @@ func TestUnconflictedServiceExportConflictCondition(t *testing.T) {
Type: string(fleetnetv1alpha1.ServiceExportConflict),
Status: metav1.ConditionFalse,
Reason: conditionReasonNoConflictFound,
ObservedGeneration: 123, // use the generation of the original object
ObservedGeneration: 456,
Message: "service test-ns/test-svc is exported without conflict",
}
got := UnconflictedServiceExportConflictCondition(input)
Expand All @@ -278,6 +281,9 @@ func TestUnconflictedServiceExportConflictCondition(t *testing.T) {

func TestConflictedServiceExportConflictCondition(t *testing.T) {
input := fleetnetv1alpha1.InternalServiceExport{
ObjectMeta: metav1.ObjectMeta{
Generation: 123,
},
Spec: fleetnetv1alpha1.InternalServiceExportSpec{
Ports: []fleetnetv1alpha1.ServicePort{
{
Expand All @@ -300,7 +306,7 @@ func TestConflictedServiceExportConflictCondition(t *testing.T) {
Namespace: "test-ns",
Name: "test-svc",
ResourceVersion: "0",
Generation: 123,
Generation: 456,
UID: "0",
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ var _ = Describe("Test InternalServiceExport Controller", func() {

By("Checking internalServiceExportA status")
Eventually(func() string {
want := fleetnetv1alpha1.InternalServiceExportStatus{
Conditions: []metav1.Condition{
unconflictedServiceExportConflictCondition(testNamespace, testServiceName),
},
}
key := types.NamespacedName{Namespace: testMemberClusterA, Name: testName}
if err := k8sClient.Get(ctx, key, internalServiceExportA); err != nil {
return err.Error()
}
want := fleetnetv1alpha1.InternalServiceExportStatus{
Conditions: []metav1.Condition{
unconflictedServiceExportConflictCondition(testNamespace, testServiceName, internalServiceExportA.Generation),
},
}
return cmp.Diff(want, internalServiceExportA.Status, options...)
}, timeout, interval).Should(BeEmpty())

Expand All @@ -170,15 +170,15 @@ var _ = Describe("Test InternalServiceExport Controller", func() {

By("Checking internalServiceExportB status")
Eventually(func() string {
want := fleetnetv1alpha1.InternalServiceExportStatus{
Conditions: []metav1.Condition{
unconflictedServiceExportConflictCondition(testNamespace, testServiceName),
},
}
key := types.NamespacedName{Namespace: testMemberClusterB, Name: testName}
if err := k8sClient.Get(ctx, key, internalServiceExportB); err != nil {
return err.Error()
}
want := fleetnetv1alpha1.InternalServiceExportStatus{
Conditions: []metav1.Condition{
unconflictedServiceExportConflictCondition(testNamespace, testServiceName, internalServiceExportB.Generation),
},
}
return cmp.Diff(want, internalServiceExportB.Status, options...)
}, timeout, interval).Should(BeEmpty())

Expand Down Expand Up @@ -313,15 +313,15 @@ var _ = Describe("Test InternalServiceExport Controller", func() {

By("Checking internalServiceExportA status")
Eventually(func() string {
want := fleetnetv1alpha1.InternalServiceExportStatus{
Conditions: []metav1.Condition{
unconflictedServiceExportConflictCondition(testNamespace, testServiceName),
},
}
key := types.NamespacedName{Namespace: testMemberClusterA, Name: testName}
if err := k8sClient.Get(ctx, key, internalServiceExportA); err != nil {
return err.Error()
}
want := fleetnetv1alpha1.InternalServiceExportStatus{
Conditions: []metav1.Condition{
unconflictedServiceExportConflictCondition(testNamespace, testServiceName, internalServiceExportA.Generation),
},
}
return cmp.Diff(want, internalServiceExportA.Status, options...)
}, timeout, interval).Should(BeEmpty())

Expand Down Expand Up @@ -386,15 +386,15 @@ var _ = Describe("Test InternalServiceExport Controller", func() {

By("Checking internalServiceExportA status")
Eventually(func() string {
want := fleetnetv1alpha1.InternalServiceExportStatus{
Conditions: []metav1.Condition{
conflictedServiceExportConflictCondition(testNamespace, testServiceName),
},
}
key := types.NamespacedName{Namespace: testMemberClusterA, Name: testName}
if err := k8sClient.Get(ctx, key, internalServiceExportA); err != nil {
return err.Error()
}
want := fleetnetv1alpha1.InternalServiceExportStatus{
Conditions: []metav1.Condition{
conflictedServiceExportConflictCondition(testNamespace, testServiceName, internalServiceExportA.Generation),
},
}
return cmp.Diff(want, internalServiceExportA.Status, options...)
}, timeout, interval).Should(BeEmpty())

Expand Down
87 changes: 50 additions & 37 deletions pkg/controllers/hub/internalserviceexport/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,22 @@ func internalServiceExportReconciler(client client.Client) *Reconciler {
}
}

func unconflictedServiceExportConflictCondition(svcNamespace string, svcName string) metav1.Condition {
func unconflictedServiceExportConflictCondition(svcNamespace string, svcName string, observedGeneration int64) metav1.Condition {
return metav1.Condition{
Type: string(fleetnetv1alpha1.ServiceExportConflict),
Status: metav1.ConditionFalse,
ObservedGeneration: 0,
ObservedGeneration: observedGeneration,
LastTransitionTime: metav1.Now(),
Reason: conditionReasonNoConflictFound,
Message: fmt.Sprintf("service %s/%s is exported without conflict", svcNamespace, svcName),
}
}

func conflictedServiceExportConflictCondition(svcNamespace string, svcName string) metav1.Condition {
func conflictedServiceExportConflictCondition(svcNamespace string, svcName string, observedGeneration int64) metav1.Condition {
return metav1.Condition{
Type: string(fleetnetv1alpha1.ServiceExportConflict),
Status: metav1.ConditionTrue,
ObservedGeneration: 0,
ObservedGeneration: observedGeneration,
LastTransitionTime: metav1.Now(),
Reason: conditionReasonConflictFound,
Message: fmt.Sprintf("service %s/%s is in conflict with other exported services", svcNamespace, svcName),
Expand Down Expand Up @@ -370,6 +370,7 @@ func TestHandleDelete_EmptyServiceImportSpec(t *testing.T) {
}

func TestHandleUpdate(t *testing.T) {
internalServiceExportGeneration := int64(456)
importServicePorts := []fleetnetv1alpha1.ServicePort{
{
Name: "portA",
Expand Down Expand Up @@ -397,8 +398,9 @@ func TestHandleUpdate(t *testing.T) {
name: "no serviceImport exists",
internalSvcExport: &fleetnetv1alpha1.InternalServiceExport{
ObjectMeta: metav1.ObjectMeta{
Name: testName,
Namespace: testMemberNamespace,
Name: testName,
Namespace: testMemberNamespace,
Generation: internalServiceExportGeneration,
},
Spec: fleetnetv1alpha1.InternalServiceExportSpec{
Ports: []fleetnetv1alpha1.ServicePort{
Expand Down Expand Up @@ -430,8 +432,9 @@ func TestHandleUpdate(t *testing.T) {
want: ctrl.Result{RequeueAfter: internalserviceexportRetryInterval},
wantInternalSvcExport: &fleetnetv1alpha1.InternalServiceExport{
ObjectMeta: metav1.ObjectMeta{
Name: testName,
Namespace: testMemberNamespace,
Name: testName,
Namespace: testMemberNamespace,
Generation: internalServiceExportGeneration,
},
Spec: fleetnetv1alpha1.InternalServiceExportSpec{
Ports: []fleetnetv1alpha1.ServicePort{
Expand Down Expand Up @@ -471,8 +474,9 @@ func TestHandleUpdate(t *testing.T) {
name: "serviceExport just created and has the same spec as serviceImport",
internalSvcExport: &fleetnetv1alpha1.InternalServiceExport{
ObjectMeta: metav1.ObjectMeta{
Name: testName,
Namespace: testMemberNamespace,
Name: testName,
Namespace: testMemberNamespace,
Generation: internalServiceExportGeneration,
},
Spec: fleetnetv1alpha1.InternalServiceExportSpec{
Ports: importServicePorts,
Expand Down Expand Up @@ -505,8 +509,9 @@ func TestHandleUpdate(t *testing.T) {
want: ctrl.Result{},
wantInternalSvcExport: &fleetnetv1alpha1.InternalServiceExport{
ObjectMeta: metav1.ObjectMeta{
Name: testName,
Namespace: testMemberNamespace,
Name: testName,
Namespace: testMemberNamespace,
Generation: internalServiceExportGeneration,
},
Spec: fleetnetv1alpha1.InternalServiceExportSpec{
Ports: importServicePorts,
Expand All @@ -522,7 +527,7 @@ func TestHandleUpdate(t *testing.T) {
},
Status: fleetnetv1alpha1.InternalServiceExportStatus{
Conditions: []metav1.Condition{
unconflictedServiceExportConflictCondition(testNamespace, testServiceName),
unconflictedServiceExportConflictCondition(testNamespace, testServiceName, internalServiceExportGeneration),
},
},
},
Expand All @@ -549,8 +554,9 @@ func TestHandleUpdate(t *testing.T) {
name: "serviceExport just created and has the different spec as serviceImport",
internalSvcExport: &fleetnetv1alpha1.InternalServiceExport{
ObjectMeta: metav1.ObjectMeta{
Name: testName,
Namespace: testMemberNamespace,
Name: testName,
Namespace: testMemberNamespace,
Generation: internalServiceExportGeneration,
},
Spec: fleetnetv1alpha1.InternalServiceExportSpec{
Ports: []fleetnetv1alpha1.ServicePort{
Expand Down Expand Up @@ -591,8 +597,9 @@ func TestHandleUpdate(t *testing.T) {
want: ctrl.Result{},
wantInternalSvcExport: &fleetnetv1alpha1.InternalServiceExport{
ObjectMeta: metav1.ObjectMeta{
Name: testName,
Namespace: testMemberNamespace,
Name: testName,
Namespace: testMemberNamespace,
Generation: internalServiceExportGeneration,
},
Spec: fleetnetv1alpha1.InternalServiceExportSpec{
Ports: []fleetnetv1alpha1.ServicePort{
Expand All @@ -616,7 +623,7 @@ func TestHandleUpdate(t *testing.T) {
},
Status: fleetnetv1alpha1.InternalServiceExportStatus{
Conditions: []metav1.Condition{
conflictedServiceExportConflictCondition(testNamespace, testServiceName),
conflictedServiceExportConflictCondition(testNamespace, testServiceName, internalServiceExportGeneration),
},
},
},
Expand All @@ -640,8 +647,9 @@ func TestHandleUpdate(t *testing.T) {
name: "update serviceExport and old serviceExport has the same spec as serviceImport",
internalSvcExport: &fleetnetv1alpha1.InternalServiceExport{
ObjectMeta: metav1.ObjectMeta{
Name: testName,
Namespace: testMemberNamespace,
Name: testName,
Namespace: testMemberNamespace,
Generation: internalServiceExportGeneration,
},
Spec: fleetnetv1alpha1.InternalServiceExportSpec{
Ports: []fleetnetv1alpha1.ServicePort{
Expand All @@ -665,7 +673,7 @@ func TestHandleUpdate(t *testing.T) {
},
Status: fleetnetv1alpha1.InternalServiceExportStatus{
Conditions: []metav1.Condition{
unconflictedServiceExportConflictCondition(testNamespace, testServiceName),
unconflictedServiceExportConflictCondition(testNamespace, testServiceName, internalServiceExportGeneration),
},
},
},
Expand All @@ -690,8 +698,9 @@ func TestHandleUpdate(t *testing.T) {
want: ctrl.Result{},
wantInternalSvcExport: &fleetnetv1alpha1.InternalServiceExport{
ObjectMeta: metav1.ObjectMeta{
Name: testName,
Namespace: testMemberNamespace,
Name: testName,
Namespace: testMemberNamespace,
Generation: internalServiceExportGeneration,
},
Spec: fleetnetv1alpha1.InternalServiceExportSpec{
Ports: []fleetnetv1alpha1.ServicePort{
Expand All @@ -715,7 +724,7 @@ func TestHandleUpdate(t *testing.T) {
},
Status: fleetnetv1alpha1.InternalServiceExportStatus{
Conditions: []metav1.Condition{
conflictedServiceExportConflictCondition(testNamespace, testServiceName),
conflictedServiceExportConflictCondition(testNamespace, testServiceName, internalServiceExportGeneration),
},
},
},
Expand All @@ -739,8 +748,9 @@ func TestHandleUpdate(t *testing.T) {
name: "update serviceExport and old serviceExport has the different spec as serviceImport",
internalSvcExport: &fleetnetv1alpha1.InternalServiceExport{
ObjectMeta: metav1.ObjectMeta{
Name: testName,
Namespace: testMemberNamespace,
Name: testName,
Namespace: testMemberNamespace,
Generation: internalServiceExportGeneration,
},
Spec: fleetnetv1alpha1.InternalServiceExportSpec{
Ports: importServicePorts,
Expand All @@ -756,7 +766,7 @@ func TestHandleUpdate(t *testing.T) {
},
Status: fleetnetv1alpha1.InternalServiceExportStatus{
Conditions: []metav1.Condition{
conflictedServiceExportConflictCondition(testNamespace, testServiceName),
conflictedServiceExportConflictCondition(testNamespace, testServiceName, internalServiceExportGeneration),
},
},
},
Expand All @@ -778,8 +788,9 @@ func TestHandleUpdate(t *testing.T) {
want: ctrl.Result{},
wantInternalSvcExport: &fleetnetv1alpha1.InternalServiceExport{
ObjectMeta: metav1.ObjectMeta{
Name: testName,
Namespace: testMemberNamespace,
Name: testName,
Namespace: testMemberNamespace,
Generation: internalServiceExportGeneration,
},
Spec: fleetnetv1alpha1.InternalServiceExportSpec{
Ports: importServicePorts,
Expand All @@ -795,7 +806,7 @@ func TestHandleUpdate(t *testing.T) {
},
Status: fleetnetv1alpha1.InternalServiceExportStatus{
Conditions: []metav1.Condition{
unconflictedServiceExportConflictCondition(testNamespace, testServiceName),
unconflictedServiceExportConflictCondition(testNamespace, testServiceName, internalServiceExportGeneration),
},
},
},
Expand All @@ -822,8 +833,9 @@ func TestHandleUpdate(t *testing.T) {
name: "there is only one serviceExport and port spec has been changed",
internalSvcExport: &fleetnetv1alpha1.InternalServiceExport{
ObjectMeta: metav1.ObjectMeta{
Name: testName,
Namespace: testMemberNamespace,
Name: testName,
Namespace: testMemberNamespace,
Generation: internalServiceExportGeneration,
},
Spec: fleetnetv1alpha1.InternalServiceExportSpec{
Ports: []fleetnetv1alpha1.ServicePort{
Expand All @@ -847,7 +859,7 @@ func TestHandleUpdate(t *testing.T) {
},
Status: fleetnetv1alpha1.InternalServiceExportStatus{
Conditions: []metav1.Condition{
unconflictedServiceExportConflictCondition(testNamespace, testServiceName),
unconflictedServiceExportConflictCondition(testNamespace, testServiceName, internalServiceExportGeneration),
},
},
},
Expand All @@ -869,8 +881,9 @@ func TestHandleUpdate(t *testing.T) {
want: ctrl.Result{RequeueAfter: internalserviceexportRetryInterval},
wantInternalSvcExport: &fleetnetv1alpha1.InternalServiceExport{
ObjectMeta: metav1.ObjectMeta{
Name: testName,
Namespace: testMemberNamespace,
Name: testName,
Namespace: testMemberNamespace,
Generation: internalServiceExportGeneration,
},
Spec: fleetnetv1alpha1.InternalServiceExportSpec{
Ports: []fleetnetv1alpha1.ServicePort{
Expand All @@ -894,7 +907,7 @@ func TestHandleUpdate(t *testing.T) {
},
Status: fleetnetv1alpha1.InternalServiceExportStatus{
Conditions: []metav1.Condition{
unconflictedServiceExportConflictCondition(testNamespace, testServiceName),
unconflictedServiceExportConflictCondition(testNamespace, testServiceName, internalServiceExportGeneration),
},
},
},
Expand Down Expand Up @@ -928,7 +941,7 @@ func TestHandleUpdate(t *testing.T) {
}
want := tc.want
if !cmp.Equal(got, want) {
t.Errorf("handleDelete() = %+v, want %+v", got, want)
t.Errorf("handleUpdate() = %+v, want %+v", got, want)
}
options := []cmp.Option{
cmpopts.IgnoreFields(metav1.ObjectMeta{}, "ResourceVersion"),
Expand Down
Loading
Loading