Skip to content

Commit

Permalink
support v1 apis (#418)
Browse files Browse the repository at this point in the history
Signed-off-by: Fernando Cainelli <[email protected]>
  • Loading branch information
cainelli authored Sep 4, 2024
1 parent 2ab6e68 commit 84a9ed6
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 107 deletions.
2 changes: 1 addition & 1 deletion examples/delegate_virtualservice.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
apiVersion: networking.istio.io/v1alpha3
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: merchants
Expand Down
2 changes: 1 addition & 1 deletion examples/multidocument_virtualservice.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
set:
x-custom-header: ok
---
apiVersion: networking.istio.io/v1alpha3
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: example
Expand Down
10 changes: 5 additions & 5 deletions internal/pkg/parser/virtualservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"fmt"
"os"

networking "istio.io/api/networking/v1alpha3"
v1alpha3 "istio.io/client-go/pkg/apis/networking/v1alpha3"
networking "istio.io/api/networking/v1"
v1 "istio.io/client-go/pkg/apis/networking/v1"
"istio.io/istio/pilot/pkg/config/kube/crd"
"istio.io/istio/pkg/config/schema/gvk"
)

func ParseVirtualServices(files []string) ([]*v1alpha3.VirtualService, error) {
out := []*v1alpha3.VirtualService{}
func ParseVirtualServices(files []string) ([]*v1.VirtualService, error) {
out := []*v1.VirtualService{}
for _, file := range files {
fileContent, err := os.ReadFile(file)
if err != nil {
Expand All @@ -29,7 +29,7 @@ func ParseVirtualServices(files []string) ([]*v1alpha3.VirtualService, error) {
if !ok {
return nil, fmt.Errorf("failed to convert spec in %q to VirtualService: %w", file, err)
}
vs := &v1alpha3.VirtualService{
vs := &v1.VirtualService{
ObjectMeta: c.ToObjectMeta(),
Spec: *spec, //nolint as deep copying mess up with reflect.DeepEqual comparison.
}
Expand Down
14 changes: 7 additions & 7 deletions internal/pkg/unit/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"slices"

"github.com/getyourguide/istio-config-validator/internal/pkg/parser"
networkingv1alpha3 "istio.io/api/networking/v1alpha3"
v1alpha3 "istio.io/client-go/pkg/apis/networking/v1alpha3"
networking "istio.io/api/networking/v1"
v1 "istio.io/client-go/pkg/apis/networking/v1"
)

// Run is the entrypoint to run all unit tests defined in test cases
Expand Down Expand Up @@ -56,7 +56,7 @@ func Run(testfiles, configfiles []string, strict bool) ([]string, []string, erro
return summary, details, fmt.Errorf("error getting delegate virtual service: %v", err)
}
checkHosts = false
route, err = GetRoute(input, []*v1alpha3.VirtualService{vs}, checkHosts)
route, err = GetRoute(input, []*v1.VirtualService{vs}, checkHosts)
if err != nil {
details = append(details, fmt.Sprintf("FAIL input:[%v]", input))
return summary, details, fmt.Errorf("error getting destinations for delegate %v: %v", route.Delegate, err)
Expand Down Expand Up @@ -100,7 +100,7 @@ func Run(testfiles, configfiles []string, strict bool) ([]string, []string, erro
}

// GetRoute returns the route that matched a given input.
func GetRoute(input parser.Input, virtualServices []*v1alpha3.VirtualService, checkHosts bool) (*networkingv1alpha3.HTTPRoute, error) {
func GetRoute(input parser.Input, virtualServices []*v1.VirtualService, checkHosts bool) (*networking.HTTPRoute, error) {
for _, vs := range virtualServices {
spec := &vs.Spec
if checkHosts && !slices.Contains(spec.Hosts, input.Authority) {
Expand All @@ -113,19 +113,19 @@ func GetRoute(input parser.Input, virtualServices []*v1alpha3.VirtualService, ch
}
for _, matchBlock := range httpRoute.Match {
if match, err := matchRequest(input, matchBlock); err != nil {
return &networkingv1alpha3.HTTPRoute{}, err
return &networking.HTTPRoute{}, err
} else if match {
return httpRoute, nil
}
}
}
}

return &networkingv1alpha3.HTTPRoute{}, nil
return &networking.HTTPRoute{}, nil
}

// GetDelegatedVirtualService returns the virtualservice matching namespace/name matching the delegate argument.
func GetDelegatedVirtualService(delegate *networkingv1alpha3.Delegate, virtualServices []*v1alpha3.VirtualService) (*v1alpha3.VirtualService, error) {
func GetDelegatedVirtualService(delegate *networking.Delegate, virtualServices []*v1.VirtualService) (*v1.VirtualService, error) {
for _, vs := range virtualServices {
if vs.Name == delegate.Name {
if delegate.Namespace != "" && vs.Namespace != delegate.Namespace {
Expand Down
Loading

0 comments on commit 84a9ed6

Please sign in to comment.