This repository has been archived by the owner on Feb 14, 2023. It is now read-only.
/
route_translator.go
82 lines (75 loc) · 2.41 KB
/
route_translator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package kubernetes
import (
cfmodel "code.cloudfoundry.org/capi-k8s-release/src/cf-api-controllers/cf/model"
"code.cloudfoundry.org/cf-k8s-networking/routecontroller/apis/networking/v1alpha1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"reflect"
)
const (
KubeNameLabel = "app.kubernetes.io/name"
KubeVersionLabel = "app.kubernetes.io/version"
KubeManagedByLabel = "app.kubernetes.io/managed-by"
KubeComponentLabel = "app.kubernetes.io/component"
KubePartOfLabel = "app.kubernetes.io/part-of"
CFAppGuidLabel = "cloudfoundry.org/app_guid"
CFProcessTypeLabel = "cloudfoundry.org/process_type"
CFOrgGuidLabel = "cloudfoundry.org/org_guid"
CFSpaceGuidLabel = "cloudfoundry.org/space_guid"
CFDomainGuidLabel = "cloudfoundry.org/domain_guid"
CFRouteGuidLabel = "cloudfoundry.org/route_guid"
)
func TranslateRoute(route *cfmodel.Route, space *cfmodel.Space, domain *cfmodel.Domain, namespace string) v1alpha1.Route {
destinations := make([]v1alpha1.RouteDestination, 0)
for _, dest := range route.Destinations {
destinations = append(destinations, v1alpha1.RouteDestination{
Guid: dest.GUID,
Port: &dest.Port,
Weight: dest.Weight,
App: v1alpha1.DestinationApp{
Guid: dest.App.GUID,
Process: v1alpha1.AppProcess{
Type: dest.App.Process.Type,
},
},
Selector: v1alpha1.DestinationSelector{
MatchLabels: map[string]string{
CFAppGuidLabel: dest.App.GUID,
CFProcessTypeLabel: dest.App.Process.Type,
},
},
})
}
routeCR := v1alpha1.Route{
TypeMeta: v1.TypeMeta{},
ObjectMeta: v1.ObjectMeta{
Name: route.GUID,
Namespace: namespace,
Labels: map[string]string{
KubeNameLabel: route.GUID,
KubeVersionLabel: "0.0.0",
KubeManagedByLabel: "cloudfoundry",
KubeComponentLabel: "cf-networking",
KubePartOfLabel: "cloudfoundry",
CFOrgGuidLabel: space.Relationships["organization"].Data.GUID,
CFSpaceGuidLabel: space.GUID,
CFDomainGuidLabel: domain.GUID,
CFRouteGuidLabel: route.GUID,
},
},
Spec: v1alpha1.RouteSpec{
Host: route.Host,
Path: route.Path,
Url: route.URL,
Domain: v1alpha1.RouteDomain{
Name: domain.Name,
Internal: domain.Internal,
},
Destinations: destinations,
},
Status: v1alpha1.RouteStatus{},
}
return routeCR
}
func CompareRoutes(desiredRoute, actualRoute v1alpha1.Route) bool {
return reflect.DeepEqual(desiredRoute.Spec, actualRoute.Spec)
}