Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Mustafa Abdelrahman <[email protected]>
  • Loading branch information
MustafaSaber committed Aug 1, 2023
1 parent 8250265 commit e7342ee
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 7 deletions.
8 changes: 3 additions & 5 deletions dataclients/kubernetes/definitions/ingressv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,18 @@ func ValidateIngressV1(_ *IngressV1Item) error {
return nil
}

// ValidateIngresses is a no-op
func ValidateIngressesV1(ingressList IngressV1List) error {
var err error
var errs []error
// discover all errors to avoid the user having to repeatedly validate
for _, i := range ingressList.Items {
nerr := ValidateIngressV1(i)
if nerr != nil {
name := i.Metadata.Name
namespace := i.Metadata.Namespace
nerr = fmt.Errorf("%s/%s: %w", name, namespace, nerr)
err = errorsJoin(err, nerr)
errs = append(errs, fmt.Errorf("%s/%s: %w", name, namespace, nerr))
}
}
return err
return errorsJoin(errs...)
}

func GetHostsFromIngressRulesV1(ing *IngressV1Item) []string {
Expand Down
48 changes: 47 additions & 1 deletion dataclients/kubernetes/definitions/routegroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ type skipperBackendParser struct {

type BackendReference struct {
// BackendName references the skipperBackend by name
BackendName string `json:"backendName"`
BackendName string `json:"backendName" yaml:"backendName"`

// Weight defines the traffic weight, if there are 2 or more
// default backends
Expand Down Expand Up @@ -298,6 +298,52 @@ func (sb *SkipperBackend) UnmarshalJSON(value []byte) error {
return nil
}

// UnmarshalYAML creates a new skipperBackend, safe to be called on nil pointer
func (sb *SkipperBackend) UnmarshalYAML(unmarshal func(interface{}) error) error {
if sb == nil {
return nil
}

var p skipperBackendParser
if err := unmarshal(&p); err != nil {
return err
}

var perr error
bt, err := backendTypeFromString(p.Type)
if err != nil {
// we cannot return an error here, because then the parsing of
// all route groups would fail. We'll report the error in the
// validation phase, only for the containing route group
perr = err
}

a, err := loadbalancer.AlgorithmFromString(p.Algorithm)
if err != nil {
// we cannot return an error here, because then the parsing of
// all route groups would fail. We'll report the error in the
// validation phase, only for the containing route group
perr = err
}

if a == loadbalancer.None {
a = loadbalancer.RoundRobin
}

var b SkipperBackend
b.Name = p.Name
b.Type = bt
b.Address = p.Address
b.ServiceName = p.ServiceName
b.ServicePort = p.ServicePort
b.Algorithm = a
b.Endpoints = p.Endpoints
b.parseError = perr

*sb = b
return nil
}

func (rg *RouteGroupSpec) UniqueHosts() []string {
return uniqueStrings(rg.Hosts)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
items:
# RouteGroup with no metadata
- apiVersion: zalando.org/v1
kind: RouteGroup
spec:
Expand All @@ -8,6 +9,8 @@ items:
- filters:
- inlineContent("/foo")
- path: /foo

# RouteGroup with no backends
- apiVersion: zalando.org/v1
kind: RouteGroup
metadata:
Expand All @@ -18,4 +21,23 @@ items:
routes:
- filters:
- inlineContent("/foo")
- path: /foo
- path: /foo

# valid
- apiVersion: zalando.org/v1
kind: RouteGroup
metadata:
name: rg1
spec:
backends:
- name: "shunt"
type: "shunt"
hosts:
- test.example.com
routes:
- backends:
- backendName: "shunt"
weight: 10
filters:
- inlineContent("/foo")
path: /foo

0 comments on commit e7342ee

Please sign in to comment.