diff --git a/apis/project.cattle.io/v3/schema/endpoint_address.go b/apis/project.cattle.io/v3/schema/endpoint_address.go index 608da81d..05d3faaa 100644 --- a/apis/project.cattle.io/v3/schema/endpoint_address.go +++ b/apis/project.cattle.io/v3/schema/endpoint_address.go @@ -1,6 +1,8 @@ package schema import ( + "fmt" + "github.com/rancher/norman/types" "github.com/rancher/norman/types/convert" "github.com/rancher/norman/types/mapper" @@ -22,9 +24,12 @@ func (e EndpointAddressMapper) FromInternal(data map[string]interface{}) { } var noPortsIPs []string + var noPortsUnavailIPs []string + var podIDs []string var result []interface{} for _, subset := range subsets { var ips []string + var unAvailIPs []string for _, ip := range subset.Addresses { if ip.IP != "" { ips = append(ips, ip.IP) @@ -32,17 +37,32 @@ func (e EndpointAddressMapper) FromInternal(data map[string]interface{}) { if ip.Hostname != "" { ips = append(ips, ip.Hostname) } + if ip.TargetRef != nil && ip.TargetRef.Kind == "Pod" { + podIDs = append(podIDs, fmt.Sprintf("%s:%s", ip.TargetRef.Namespace, + ip.TargetRef.Name)) + } } - if len(ips) == 0 { + for _, ip := range subset.NotReadyAddresses { + if ip.IP != "" { + unAvailIPs = append(ips, ip.IP) + } + if ip.Hostname != "" { + unAvailIPs = append(ips, ip.Hostname) + } + } + + if len(subset.Ports) == 0 { noPortsIPs = append(noPortsIPs, ips...) + noPortsUnavailIPs = append(noPortsIPs, unAvailIPs...) } else { for _, port := range subset.Ports { if len(ips) > 0 { result = append(result, map[string]interface{}{ - "addresses": ips, - "port": port.Port, - "protocol": port.Protocol, + "addresses": ips, + "notReadyAddresses": unAvailIPs, + "port": port.Port, + "protocol": port.Protocol, }) } } @@ -51,13 +71,17 @@ func (e EndpointAddressMapper) FromInternal(data map[string]interface{}) { if len(noPortsIPs) > 0 { result = append(result, map[string]interface{}{ - "addresses": noPortsIPs, + "addresses": noPortsIPs, + "notReadyAddresses": noPortsUnavailIPs, }) } if len(result) > 0 { data["targets"] = result } + if len(podIDs) > 0 { + data["podIds"] = podIDs + } } func (e EndpointAddressMapper) ToInternal(data map[string]interface{}) { diff --git a/apis/project.cattle.io/v3/schema/schema.go b/apis/project.cattle.io/v3/schema/schema.go index 12fdd0d3..25cd9cad 100644 --- a/apis/project.cattle.io/v3/schema/schema.go +++ b/apis/project.cattle.io/v3/schema/schema.go @@ -7,6 +7,7 @@ import ( "github.com/rancher/types/factory" "github.com/rancher/types/mapper" "k8s.io/api/core/v1" + "k8s.io/api/extensions/v1beta1" "k8s.io/kubernetes/staging/src/k8s.io/api/apps/v1beta2" ) @@ -22,9 +23,10 @@ var ( Schemas = factory.Schemas(&Version). // Namespace must be first + Init(namespaceTypes). + Init(ingressTypes). Init(secretTypes). Init(serviceTypes). - Init(namespaceTypes). Init(podTypes). Init(deploymentTypes). Init(statefulSetTypes). @@ -339,5 +341,29 @@ func serviceTypes(schemas *types.Schemas) *types.Schemas { schema.CodeName = "Endpoint" }, projectOverride{}, struct { Targets []Target `json:"targets"` + PodIDs []string `json:"podIds" norman:"type=array[reference[pod]]"` + }{}) +} + +func ingressTypes(schemas *types.Schemas) *types.Schemas { + return schemas. + AddMapperForType(&Version, v1beta1.HTTPIngressPath{}, + &m.Embed{Field: "backend"}, + ). + AddMapperForType(&Version, v1beta1.Ingress{}, + &mapper.NamespaceIDMapper{}, + &m.Move{From: "backend", To: "defaultBackend"}, + ). + AddMapperForType(&Version, v1beta1.IngressTLS{}, + &m.Move{From: "secretName", To: "certificateName"}, + ). + MustImport(&Version, v1beta1.IngressBackend{}, struct { + WorkloadIDs string `json:"workloadIds" norman:"type=array[reference[workload]]"` + ServiceName string `norman:"type=reference[service]"` + }{}). + MustImport(&Version, v1beta1.IngressTLS{}, struct { + SecretName string `norman:"type=reference[certificate]"` + }{}). + MustImport(&Version, v1beta1.Ingress{}, projectOverride{}, struct { }{}) } diff --git a/apis/project.cattle.io/v3/schema/types.go b/apis/project.cattle.io/v3/schema/types.go index e7e7a1da..1926afbd 100644 --- a/apis/project.cattle.io/v3/schema/types.go +++ b/apis/project.cattle.io/v3/schema/types.go @@ -83,7 +83,8 @@ type projectOverride struct { } type Target struct { - Addresses []string `json:"addresses"` - Port *int32 `json:"port"` - Protocol string `json:"protocol" norman:"type=enum,options=TCP|UDP"` + Addresses []string `json:"addresses"` + NotReadyAddresses []string `json:"notReadyAddresses"` + Port *int32 `json:"port"` + Protocol string `json:"protocol" norman:"type=enum,options=TCP|UDP"` }