1
0
mirror of https://github.com/rancher/types.git synced 2025-07-02 16:31:48 +00:00

Add ingress type

This commit is contained in:
Darren Shepherd 2017-12-23 22:23:41 -07:00
parent df3a71adc2
commit 52161ec23b
3 changed files with 60 additions and 9 deletions

View File

@ -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{}) {

View File

@ -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 {
}{})
}

View File

@ -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"`
}