Skip to content

Commit

Permalink
Merge pull request #116 from ferryproxy/fix/route-policy
Browse files Browse the repository at this point in the history
Reload latest generated route
  • Loading branch information
wzshiming authored Aug 31, 2022
2 parents 0a1f1bf + 41c0d9b commit bc4d741
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/ferryproxy/api/apis/traffic/v1alpha2"
versioned "github.com/ferryproxy/client-go/generated/clientset/versioned"
externalversions "github.com/ferryproxy/client-go/generated/informers/externalversions"
"github.com/ferryproxy/ferry/pkg/consts"
"github.com/ferryproxy/ferry/pkg/ferry-controller/router/resource"
"github.com/ferryproxy/ferry/pkg/utils/diffobjs"
"github.com/ferryproxy/ferry/pkg/utils/maps"
Expand Down Expand Up @@ -103,6 +104,20 @@ func (c *RoutePolicyController) Run(ctx context.Context) error {
}
c.clientset = clientset
c.ctx = ctx

list, err := c.clientset.
TrafficV1alpha2().
Routes(c.namespace).
List(ctx, metav1.ListOptions{
LabelSelector: labels.FormatLabels(labelsForRoute),
})
if err != nil {
return err
}
for _, item := range list.Items {
c.cacheRoutePolicyRoutes = append(c.cacheRoutePolicyRoutes, item.DeepCopy())
}

informerFactory := externalversions.NewSharedInformerFactoryWithOptions(clientset, 0,
externalversions.WithNamespace(c.namespace))
informer := informerFactory.
Expand Down Expand Up @@ -325,7 +340,7 @@ func policiesToRoutes(clusterCache ClusterCache, policies []*v1alpha2.RoutePolic
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-%s-%s-%s-%s-%s-%s", policy.Name, exportHubName, exportNamespace, exportName, importHubName, importNamespace, importName),
Namespace: policy.Namespace,
Labels: policy.Labels,
Labels: maps.Merge(policy.Labels, labelsForRoute),
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: v1alpha2.GroupVersion.String(),
Expand Down Expand Up @@ -399,3 +414,7 @@ type groupRoutePolicy struct {
Export v1alpha2.RoutePolicySpecRuleService
Import v1alpha2.RoutePolicySpecRuleService
}

var labelsForRoute = map[string]string{
consts.LabelGeneratedKey: consts.LabelGeneratedValue,
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func Test_policiesToRoutes(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-export-1-default-app-1-import-1-default-app-1",
OwnerReferences: ownerReferences,
Labels: labelsForRoute,
},
Spec: v1alpha2.RouteSpec{
Import: v1alpha2.RouteSpecRule{
Expand All @@ -228,6 +229,7 @@ func Test_policiesToRoutes(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-export-1-default-app-2-import-1-default-app-2",
OwnerReferences: ownerReferences,
Labels: labelsForRoute,
},
Spec: v1alpha2.RouteSpec{
Import: v1alpha2.RouteSpecRule{
Expand Down Expand Up @@ -278,6 +280,7 @@ func Test_policiesToRoutes(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-export-1-default-app-1-import-1-default-app-1",
OwnerReferences: ownerReferences,
Labels: labelsForRoute,
},
Spec: v1alpha2.RouteSpec{
Import: v1alpha2.RouteSpecRule{
Expand Down Expand Up @@ -328,6 +331,7 @@ func Test_policiesToRoutes(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-export-1-default-app-1-import-1-default-app-1",
OwnerReferences: ownerReferences,
Labels: labelsForRoute,
},
Spec: v1alpha2.RouteSpec{
Import: v1alpha2.RouteSpecRule{
Expand All @@ -350,6 +354,7 @@ func Test_policiesToRoutes(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-export-1-default-app-2-import-1-default-app-2",
OwnerReferences: ownerReferences,
Labels: labelsForRoute,
},
Spec: v1alpha2.RouteSpec{
Import: v1alpha2.RouteSpecRule{
Expand Down Expand Up @@ -400,6 +405,7 @@ func Test_policiesToRoutes(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-export-1-default-app-1-import-1-default-app-1",
OwnerReferences: ownerReferences,
Labels: labelsForRoute,
},
Spec: v1alpha2.RouteSpec{
Import: v1alpha2.RouteSpecRule{
Expand Down Expand Up @@ -452,6 +458,7 @@ func Test_policiesToRoutes(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-export-1-default-app-1-import-1-default-app-1",
OwnerReferences: ownerReferences,
Labels: labelsForRoute,
},
Spec: v1alpha2.RouteSpec{
Import: v1alpha2.RouteSpecRule{
Expand All @@ -474,6 +481,7 @@ func Test_policiesToRoutes(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-export-1-test-app-1-import-1-test-app-1",
OwnerReferences: ownerReferences,
Labels: labelsForRoute,
},
Spec: v1alpha2.RouteSpec{
Import: v1alpha2.RouteSpecRule{
Expand Down Expand Up @@ -526,6 +534,7 @@ func Test_policiesToRoutes(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-export-1-default-app-1-import-1-default-app-1",
OwnerReferences: ownerReferences,
Labels: labelsForRoute,
},
Spec: v1alpha2.RouteSpec{
Import: v1alpha2.RouteSpecRule{
Expand Down Expand Up @@ -578,6 +587,7 @@ func Test_policiesToRoutes(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-export-1-default-app-1-import-1-default-app-1",
OwnerReferences: ownerReferences,
Labels: labelsForRoute,
},
Spec: v1alpha2.RouteSpec{
Import: v1alpha2.RouteSpecRule{
Expand All @@ -600,6 +610,7 @@ func Test_policiesToRoutes(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-export-1-test-app-1-import-1-test-app-1",
OwnerReferences: ownerReferences,
Labels: labelsForRoute,
},
Spec: v1alpha2.RouteSpec{
Import: v1alpha2.RouteSpecRule{
Expand Down Expand Up @@ -652,6 +663,7 @@ func Test_policiesToRoutes(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-export-1-default-app-1-import-1-default-app-1",
OwnerReferences: ownerReferences,
Labels: labelsForRoute,
},
Spec: v1alpha2.RouteSpec{
Import: v1alpha2.RouteSpecRule{
Expand Down Expand Up @@ -720,6 +732,7 @@ func Test_policiesToRoutes(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-export-1-default-app-1-import-1-default-app-1",
OwnerReferences: ownerReferences,
Labels: labelsForRoute,
},
Spec: v1alpha2.RouteSpec{
Import: v1alpha2.RouteSpecRule{
Expand All @@ -742,6 +755,7 @@ func Test_policiesToRoutes(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-export-2-default-app-1-import-1-default-app-1",
OwnerReferences: ownerReferences,
Labels: labelsForRoute,
},
Spec: v1alpha2.RouteSpec{
Import: v1alpha2.RouteSpecRule{
Expand Down

0 comments on commit bc4d741

Please sign in to comment.