Skip to content

Commit

Permalink
test: add more traffic manager e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiying-lin committed Dec 24, 2024
1 parent 153b55b commit f536370
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,35 @@ func trafficManagerProfileForTest(name string) *fleetnetv1alpha1.TrafficManagerP
}
}

func buildFalseCondition() []metav1.Condition {
func buildFalseCondition(generation int64) []metav1.Condition {
return []metav1.Condition{
{
Status: metav1.ConditionFalse,
Type: string(fleetnetv1alpha1.TrafficManagerBackendConditionAccepted),
Reason: string(fleetnetv1alpha1.TrafficManagerBackendReasonInvalid),
Status: metav1.ConditionFalse,
Type: string(fleetnetv1alpha1.TrafficManagerBackendConditionAccepted),
Reason: string(fleetnetv1alpha1.TrafficManagerBackendReasonInvalid),
ObservedGeneration: generation,
},
}
}

func buildUnknownCondition() []metav1.Condition {
func buildUnknownCondition(generation int64) []metav1.Condition {
return []metav1.Condition{
{
Status: metav1.ConditionUnknown,
Type: string(fleetnetv1alpha1.TrafficManagerBackendConditionAccepted),
Reason: string(fleetnetv1alpha1.TrafficManagerBackendReasonPending),
Status: metav1.ConditionUnknown,
Type: string(fleetnetv1alpha1.TrafficManagerBackendConditionAccepted),
Reason: string(fleetnetv1alpha1.TrafficManagerBackendReasonPending),
ObservedGeneration: generation,
},
}
}

func buildTrueCondition() []metav1.Condition {
func buildTrueCondition(generation int64) []metav1.Condition {
return []metav1.Condition{
{
Status: metav1.ConditionTrue,
Type: string(fleetnetv1alpha1.TrafficManagerBackendConditionAccepted),
Reason: string(fleetnetv1alpha1.TrafficManagerBackendReasonAccepted),
Status: metav1.ConditionTrue,
Type: string(fleetnetv1alpha1.TrafficManagerBackendConditionAccepted),
Reason: string(fleetnetv1alpha1.TrafficManagerBackendReasonAccepted),
ObservedGeneration: generation,
},
}
}
Expand Down Expand Up @@ -123,7 +126,7 @@ var _ = Describe("Test TrafficManagerBackend Controller", func() {
},
Spec: backend.Spec,
Status: fleetnetv1alpha1.TrafficManagerBackendStatus{
Conditions: buildFalseCondition(),
Conditions: buildFalseCondition(backend.Generation),
},
}
validator.ValidateTrafficManagerBackend(ctx, k8sClient, &want)
Expand Down Expand Up @@ -167,7 +170,7 @@ var _ = Describe("Test TrafficManagerBackend Controller", func() {
},
Spec: backend.Spec,
Status: fleetnetv1alpha1.TrafficManagerBackendStatus{
Conditions: buildUnknownCondition(),
Conditions: buildUnknownCondition(backend.Generation),
},
}
validator.ValidateTrafficManagerBackend(ctx, k8sClient, &want)
Expand All @@ -187,7 +190,7 @@ var _ = Describe("Test TrafficManagerBackend Controller", func() {
},
Spec: backend.Spec,
Status: fleetnetv1alpha1.TrafficManagerBackendStatus{
Conditions: buildFalseCondition(),
Conditions: buildFalseCondition(backend.Generation),
},
}
validator.ValidateTrafficManagerBackend(ctx, k8sClient, &want)
Expand Down Expand Up @@ -245,7 +248,7 @@ var _ = Describe("Test TrafficManagerBackend Controller", func() {
},
Spec: backend.Spec,
Status: fleetnetv1alpha1.TrafficManagerBackendStatus{
Conditions: buildUnknownCondition(),
Conditions: buildUnknownCondition(backend.Generation),
},
}
validator.ValidateTrafficManagerBackend(ctx, k8sClient, &want)
Expand Down Expand Up @@ -371,7 +374,7 @@ var _ = Describe("Test TrafficManagerBackend Controller", func() {
},
Spec: backend.Spec,
Status: fleetnetv1alpha1.TrafficManagerBackendStatus{
Conditions: buildFalseCondition(),
Conditions: buildFalseCondition(backend.Generation),
},
}
validator.ValidateTrafficManagerBackend(ctx, k8sClient, &want)
Expand All @@ -398,7 +401,7 @@ var _ = Describe("Test TrafficManagerBackend Controller", func() {
},
Spec: backend.Spec,
Status: fleetnetv1alpha1.TrafficManagerBackendStatus{
Conditions: buildUnknownCondition(),
Conditions: buildUnknownCondition(backend.Generation),
},
}
validator.ValidateTrafficManagerBackend(ctx, k8sClient, &want)
Expand Down Expand Up @@ -456,7 +459,7 @@ var _ = Describe("Test TrafficManagerBackend Controller", func() {
},
Spec: backend.Spec,
Status: fleetnetv1alpha1.TrafficManagerBackendStatus{
Conditions: buildFalseCondition(),
Conditions: buildFalseCondition(backend.Generation),
},
}
validator.ValidateTrafficManagerBackend(ctx, k8sClient, &want)
Expand Down Expand Up @@ -586,7 +589,7 @@ var _ = Describe("Test TrafficManagerBackend Controller", func() {
},
Spec: backend.Spec,
Status: fleetnetv1alpha1.TrafficManagerBackendStatus{
Conditions: buildFalseCondition(),
Conditions: buildFalseCondition(backend.Generation),
},
}
validator.ValidateTrafficManagerBackend(ctx, k8sClient, &want)
Expand All @@ -611,7 +614,7 @@ var _ = Describe("Test TrafficManagerBackend Controller", func() {
},
Spec: backend.Spec,
Status: fleetnetv1alpha1.TrafficManagerBackendStatus{
Conditions: buildUnknownCondition(),
Conditions: buildUnknownCondition(backend.Generation),
},
}
validator.ValidateTrafficManagerBackend(ctx, k8sClient, &want)
Expand All @@ -637,7 +640,7 @@ var _ = Describe("Test TrafficManagerBackend Controller", func() {
},
Spec: backend.Spec,
Status: fleetnetv1alpha1.TrafficManagerBackendStatus{
Conditions: buildUnknownCondition(),
Conditions: buildUnknownCondition(backend.Generation),
},
}
validator.ValidateTrafficManagerBackendConsistently(ctx, k8sClient, &want)
Expand Down Expand Up @@ -701,7 +704,7 @@ var _ = Describe("Test TrafficManagerBackend Controller", func() {
},
Spec: backend.Spec,
Status: fleetnetv1alpha1.TrafficManagerBackendStatus{
Conditions: buildFalseCondition(),
Conditions: buildFalseCondition(backend.Generation),
},
}
validator.ValidateTrafficManagerBackend(ctx, k8sClient, &want)
Expand All @@ -727,7 +730,7 @@ var _ = Describe("Test TrafficManagerBackend Controller", func() {
},
Spec: backend.Spec,
Status: fleetnetv1alpha1.TrafficManagerBackendStatus{
Conditions: buildUnknownCondition(),
Conditions: buildUnknownCondition(backend.Generation),
},
}
validator.ValidateTrafficManagerBackend(ctx, k8sClient, &want)
Expand Down Expand Up @@ -757,7 +760,7 @@ var _ = Describe("Test TrafficManagerBackend Controller", func() {
},
Spec: backend.Spec,
Status: fleetnetv1alpha1.TrafficManagerBackendStatus{
Conditions: buildFalseCondition(),
Conditions: buildFalseCondition(backend.Generation),
Endpoints: []fleetnetv1alpha1.TrafficManagerEndpointStatus{
{
Name: fmt.Sprintf(AzureResourceEndpointNameFormat, backendName+"#", serviceName, memberClusterNames[0]),
Expand Down Expand Up @@ -797,7 +800,7 @@ var _ = Describe("Test TrafficManagerBackend Controller", func() {
},
Spec: backend.Spec,
Status: fleetnetv1alpha1.TrafficManagerBackendStatus{
Conditions: buildTrueCondition(),
Conditions: buildTrueCondition(backend.Generation),
Endpoints: []fleetnetv1alpha1.TrafficManagerEndpointStatus{
{
Name: fmt.Sprintf(AzureResourceEndpointNameFormat, backendName+"#", serviceName, memberClusterNames[0]),
Expand Down Expand Up @@ -845,7 +848,7 @@ var _ = Describe("Test TrafficManagerBackend Controller", func() {
},
Spec: backend.Spec,
Status: fleetnetv1alpha1.TrafficManagerBackendStatus{
Conditions: buildFalseCondition(),
Conditions: buildFalseCondition(backend.Generation),
Endpoints: []fleetnetv1alpha1.TrafficManagerEndpointStatus{
{
Name: fmt.Sprintf(AzureResourceEndpointNameFormat, backendName+"#", serviceName, memberClusterNames[0]),
Expand Down Expand Up @@ -885,7 +888,7 @@ var _ = Describe("Test TrafficManagerBackend Controller", func() {
},
Spec: backend.Spec,
Status: fleetnetv1alpha1.TrafficManagerBackendStatus{
Conditions: buildUnknownCondition(),
Conditions: buildUnknownCondition(backend.Generation),
},
}
validator.ValidateTrafficManagerBackend(ctx, k8sClient, &want)
Expand Down Expand Up @@ -919,7 +922,7 @@ var _ = Describe("Test TrafficManagerBackend Controller", func() {
},
Spec: backend.Spec,
Status: fleetnetv1alpha1.TrafficManagerBackendStatus{
Conditions: buildFalseCondition(),
Conditions: buildFalseCondition(backend.Generation),
},
}
validator.ValidateTrafficManagerBackend(ctx, k8sClient, &want)
Expand All @@ -942,7 +945,7 @@ var _ = Describe("Test TrafficManagerBackend Controller", func() {
},
Spec: backend.Spec,
Status: fleetnetv1alpha1.TrafficManagerBackendStatus{
Conditions: buildTrueCondition(),
Conditions: buildTrueCondition(backend.Generation),
Endpoints: []fleetnetv1alpha1.TrafficManagerEndpointStatus{
{
Name: fmt.Sprintf(AzureResourceEndpointNameFormat, backendName+"#", serviceName, memberClusterNames[0]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ var _ = Describe("Test TrafficManagerProfile Controller", func() {
DNSName: ptr.To(fqdn),
Conditions: []metav1.Condition{
{
Status: metav1.ConditionTrue,
Type: string(fleetnetv1alpha1.TrafficManagerProfileConditionProgrammed),
Reason: string(fleetnetv1alpha1.TrafficManagerProfileReasonProgrammed),
Status: metav1.ConditionTrue,
Type: string(fleetnetv1alpha1.TrafficManagerProfileConditionProgrammed),
Reason: string(fleetnetv1alpha1.TrafficManagerProfileReasonProgrammed),
ObservedGeneration: profile.Generation,
},
},
},
Expand All @@ -91,9 +92,10 @@ var _ = Describe("Test TrafficManagerProfile Controller", func() {
Status: fleetnetv1alpha1.TrafficManagerProfileStatus{
Conditions: []metav1.Condition{
{
Status: metav1.ConditionFalse,
Type: string(fleetnetv1alpha1.TrafficManagerProfileConditionProgrammed),
Reason: string(fleetnetv1alpha1.TrafficManagerProfileReasonInvalid),
Status: metav1.ConditionFalse,
Type: string(fleetnetv1alpha1.TrafficManagerProfileConditionProgrammed),
Reason: string(fleetnetv1alpha1.TrafficManagerProfileReasonInvalid),
ObservedGeneration: profile.Generation,
},
},
},
Expand Down Expand Up @@ -148,9 +150,10 @@ var _ = Describe("Test TrafficManagerProfile Controller", func() {
DNSName: ptr.To(fmt.Sprintf(fakeprovider.ProfileDNSNameFormat, name)),
Conditions: []metav1.Condition{
{
Status: metav1.ConditionTrue,
Type: string(fleetnetv1alpha1.TrafficManagerProfileConditionProgrammed),
Reason: string(fleetnetv1alpha1.TrafficManagerProfileReasonProgrammed),
Status: metav1.ConditionTrue,
Type: string(fleetnetv1alpha1.TrafficManagerProfileConditionProgrammed),
Reason: string(fleetnetv1alpha1.TrafficManagerProfileReasonProgrammed),
ObservedGeneration: profile.Generation,
},
},
},
Expand Down Expand Up @@ -188,9 +191,10 @@ var _ = Describe("Test TrafficManagerProfile Controller", func() {
Status: fleetnetv1alpha1.TrafficManagerProfileStatus{
Conditions: []metav1.Condition{
{
Status: metav1.ConditionFalse,
Type: string(fleetnetv1alpha1.TrafficManagerProfileConditionProgrammed),
Reason: string(fleetnetv1alpha1.TrafficManagerProfileReasonDNSNameNotAvailable),
Status: metav1.ConditionFalse,
Type: string(fleetnetv1alpha1.TrafficManagerProfileConditionProgrammed),
Reason: string(fleetnetv1alpha1.TrafficManagerProfileReasonDNSNameNotAvailable),
ObservedGeneration: profile.Generation,
},
},
},
Expand Down Expand Up @@ -228,9 +232,10 @@ var _ = Describe("Test TrafficManagerProfile Controller", func() {
Status: fleetnetv1alpha1.TrafficManagerProfileStatus{
Conditions: []metav1.Condition{
{
Status: metav1.ConditionUnknown,
Type: string(fleetnetv1alpha1.TrafficManagerProfileConditionProgrammed),
Reason: string(fleetnetv1alpha1.TrafficManagerProfileReasonPending),
Status: metav1.ConditionUnknown,
Type: string(fleetnetv1alpha1.TrafficManagerProfileConditionProgrammed),
Reason: string(fleetnetv1alpha1.TrafficManagerProfileReasonPending),
ObservedGeneration: profile.Generation,
},
},
},
Expand Down Expand Up @@ -268,9 +273,10 @@ var _ = Describe("Test TrafficManagerProfile Controller", func() {
Status: fleetnetv1alpha1.TrafficManagerProfileStatus{
Conditions: []metav1.Condition{
{
Status: metav1.ConditionFalse,
Type: string(fleetnetv1alpha1.TrafficManagerProfileConditionProgrammed),
Reason: string(fleetnetv1alpha1.TrafficManagerProfileReasonInvalid),
Status: metav1.ConditionFalse,
Type: string(fleetnetv1alpha1.TrafficManagerProfileConditionProgrammed),
Reason: string(fleetnetv1alpha1.TrafficManagerProfileReasonInvalid),
ObservedGeneration: profile.Generation,
},
},
},
Expand Down Expand Up @@ -308,9 +314,10 @@ var _ = Describe("Test TrafficManagerProfile Controller", func() {
Status: fleetnetv1alpha1.TrafficManagerProfileStatus{
Conditions: []metav1.Condition{
{
Status: metav1.ConditionUnknown,
Type: string(fleetnetv1alpha1.TrafficManagerProfileConditionProgrammed),
Reason: string(fleetnetv1alpha1.TrafficManagerProfileReasonPending),
Status: metav1.ConditionUnknown,
Type: string(fleetnetv1alpha1.TrafficManagerProfileConditionProgrammed),
Reason: string(fleetnetv1alpha1.TrafficManagerProfileReasonPending),
ObservedGeneration: profile.Generation,
},
},
},
Expand Down
15 changes: 14 additions & 1 deletion test/common/trafficmanager/azureprovider/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/onsi/gomega"

"go.goms.io/fleet-networking/pkg/common/azureerrors"
)

var (
cmpProfileOptions = cmp.Options{
cmpopts.IgnoreFields(armtrafficmanager.Profile{}, "ID", "Name", "Type"),
cmpopts.IgnoreFields(armtrafficmanager.MonitorConfig{}, "ProfileMonitorStatus"), // cannot predict the monitor status
cmpopts.IgnoreFields(armtrafficmanager.MonitorConfig{}, "ProfileMonitorStatus"), // cannot predict the monitor status
cmpopts.IgnoreFields(armtrafficmanager.Endpoint{}, "ID"), // ignore the resource ID for now
cmpopts.IgnoreFields(armtrafficmanager.EndpointProperties{}, "TargetResourceID", "EndpointLocation", "EndpointMonitorStatus", "Priority"), // cannot predict the status
cmpopts.SortSlices(func(e1, e2 armtrafficmanager.Endpoint) bool {
return *e1.Name < *e2.Name
}),
}
)

Expand All @@ -35,3 +42,9 @@ func (v *Validator) ValidateProfile(ctx context.Context, name string, want armtr
diff := cmp.Diff(want, res.Profile, cmpProfileOptions)
gomega.Expect(diff).Should(gomega.BeEmpty(), "trafficManagerProfile mismatch (-want, +got) :\n%s", diff)
}

// IsProfileDeleted validates the traffic manager profile is deleted.
func (v *Validator) IsProfileDeleted(ctx context.Context, name string) {
_, err := v.ProfileClient.Get(ctx, v.ResourceGroup, name, nil)
gomega.Expect(azureerrors.IsNotFound(err)).Should(gomega.BeTrue(), "trafficManagerProfile %s still exists", name)
}
Loading

0 comments on commit f536370

Please sign in to comment.