Skip to content

Commit

Permalink
Revert to v1beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
barchw committed Jul 10, 2024
1 parent 9e51979 commit 9372cc9
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 70 deletions.
88 changes: 44 additions & 44 deletions internal/builders/virtual_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ import (
apirulev2alpha1 "github.com/kyma-project/api-gateway/apis/gateway/v2alpha1"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/wrapperspb"
"istio.io/api/networking/v1"
networkingv1 "istio.io/client-go/pkg/apis/networking/v1"
istioapiv1beta1 "istio.io/api/networking/v1beta1"
networkingv1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1"
"strings"
"time"
)

// VirtualService returns builder for istio.io/client-go/pkg/apis/networking/v1/VirtualService type
// VirtualService returns builder for istio.io/client-go/pkg/apis/networking/v1beta1/VirtualService type
func VirtualService() *virtualService {
return &virtualService{
value: &networkingv1.VirtualService{},
value: &networkingv1beta1.VirtualService{},
}
}

type virtualService struct {
value *networkingv1.VirtualService
value *networkingv1beta1.VirtualService
}

func (vs *virtualService) Get() *networkingv1.VirtualService {
func (vs *virtualService) Get() *networkingv1beta1.VirtualService {
return vs.value
}

func (vs *virtualService) From(val *networkingv1.VirtualService) *virtualService {
func (vs *virtualService) From(val *networkingv1beta1.VirtualService) *virtualService {
vs.value = val
return vs
}
Expand Down Expand Up @@ -61,22 +61,22 @@ func (vs *virtualService) Spec(val *virtualServiceSpec) *virtualService {
return vs
}

// VirtualServiceSpec returns builder for istio.io/api/networking/v1/VirtualServiceSpec type
// VirtualServiceSpec returns builder for istio.io/api/networking/v1beta1/VirtualServiceSpec type
func VirtualServiceSpec() *virtualServiceSpec {
return &virtualServiceSpec{
value: &v1.VirtualService{},
value: &istioapiv1beta1.VirtualService{},
}
}

type virtualServiceSpec struct {
value *v1.VirtualService
value *istioapiv1beta1.VirtualService
}

func (vss *virtualServiceSpec) Get() *v1.VirtualService {
func (vss *virtualServiceSpec) Get() *istioapiv1beta1.VirtualService {
return vss.value
}

func (vss *virtualServiceSpec) From(val *v1.VirtualService) *virtualServiceSpec {
func (vss *virtualServiceSpec) From(val *istioapiv1beta1.VirtualService) *virtualServiceSpec {
vss.value = val
return vss
}
Expand All @@ -96,18 +96,18 @@ func (vss *virtualServiceSpec) HTTP(hr *httpRoute) *virtualServiceSpec {
return vss
}

// HTTPRoute returns builder for istio.io/api/networking/v1/HTTPRoute type
// HTTPRoute returns builder for istio.io/api/networking/v1beta1/HTTPRoute type
func HTTPRoute() *httpRoute {
return &httpRoute{
value: &v1.HTTPRoute{},
value: &istioapiv1beta1.HTTPRoute{},
}
}

type httpRoute struct {
value *v1.HTTPRoute
value *istioapiv1beta1.HTTPRoute
}

func (hr *httpRoute) Get() *v1.HTTPRoute {
func (hr *httpRoute) Get() *istioapiv1beta1.HTTPRoute {
return hr.value
}

Expand All @@ -126,7 +126,7 @@ func (hr *httpRoute) CorsPolicy(cc *corsPolicy) *httpRoute {
return hr
}

func (hr *httpRoute) Headers(h *v1.Headers) *httpRoute {
func (hr *httpRoute) Headers(h *istioapiv1beta1.Headers) *httpRoute {
hr.value.Headers = h
return hr
}
Expand All @@ -136,23 +136,23 @@ func (hr *httpRoute) Timeout(value time.Duration) *httpRoute {
return hr
}

// MatchRequest returns builder for istio.io/api/networking/v1/HTTPMatchRequest type
// MatchRequest returns builder for istio.io/api/networking/v1beta1/HTTPMatchRequest type
func MatchRequest() *matchRequest {
return &matchRequest{
value: &v1.HTTPMatchRequest{},
value: &istioapiv1beta1.HTTPMatchRequest{},
}
}

type matchRequest struct {
value *v1.HTTPMatchRequest
value *istioapiv1beta1.HTTPMatchRequest
}

func (mr *matchRequest) Get() *v1.HTTPMatchRequest {
func (mr *matchRequest) Get() *istioapiv1beta1.HTTPMatchRequest {
return mr.value
}

func (mr *matchRequest) Uri() *stringMatch {
mr.value.Uri = &v1.StringMatch{}
mr.value.Uri = &istioapiv1beta1.StringMatch{}
return &stringMatch{mr.value.Uri, func() *matchRequest { return mr }}
}

Expand All @@ -162,44 +162,44 @@ func (mr *matchRequest) MethodRegEx(httpMethods ...apirulev1beta1.HttpMethod) *m
methodStrings := apirulev1beta1.ConvertHttpMethodsToStrings(httpMethods)
methodsWithSeparator := strings.Join(methodStrings, "|")

mr.value.Method = &v1.StringMatch{
MatchType: &v1.StringMatch_Regex{
mr.value.Method = &istioapiv1beta1.StringMatch{
MatchType: &istioapiv1beta1.StringMatch_Regex{
Regex: fmt.Sprintf("^(%s)$", methodsWithSeparator),
},
}
return mr
}

type stringMatch struct {
value *v1.StringMatch
value *istioapiv1beta1.StringMatch
parent func() *matchRequest
}

func (st *stringMatch) Regex(val string) *matchRequest {
st.value.MatchType = &v1.StringMatch_Regex{Regex: val}
st.value.MatchType = &istioapiv1beta1.StringMatch_Regex{Regex: val}
return st.parent()
}

func (st *stringMatch) Prefix(val string) *matchRequest {
st.value.MatchType = &v1.StringMatch_Prefix{Prefix: val}
st.value.MatchType = &istioapiv1beta1.StringMatch_Prefix{Prefix: val}
return st.parent()
}

// RouteDestination returns builder for istio.io/api/networking/v1/HTTPRouteDestination type
// RouteDestination returns builder for istio.io/api/networking/v1beta1/HTTPRouteDestination type
func RouteDestination() *routeDestination {
return &routeDestination{&v1.HTTPRouteDestination{
Destination: &v1.Destination{
Port: &v1.PortSelector{},
return &routeDestination{&istioapiv1beta1.HTTPRouteDestination{
Destination: &istioapiv1beta1.Destination{
Port: &istioapiv1beta1.PortSelector{},
},
Weight: 100,
}}
}

type routeDestination struct {
value *v1.HTTPRouteDestination
value *istioapiv1beta1.HTTPRouteDestination
}

func (rd *routeDestination) Get() *v1.HTTPRouteDestination {
func (rd *routeDestination) Get() *istioapiv1beta1.HTTPRouteDestination {
return rd.value
}

Expand All @@ -213,18 +213,18 @@ func (rd *routeDestination) Port(val uint32) *routeDestination {
return rd
}

// CorsPolicy returns builder for istio.io/api/networking/v1/CorsPolicy type
// CorsPolicy returns builder for istio.io/api/networking/v1beta1/CorsPolicy type
func CorsPolicy() *corsPolicy {
return &corsPolicy{
value: &v1.CorsPolicy{},
value: &istioapiv1beta1.CorsPolicy{},
}
}

type corsPolicy struct {
value *v1.CorsPolicy
value *istioapiv1beta1.CorsPolicy
}

func (cp *corsPolicy) Get() *v1.CorsPolicy {
func (cp *corsPolicy) Get() *istioapiv1beta1.CorsPolicy {
if cp.value.AllowOrigins == nil {
return nil
}
Expand All @@ -249,7 +249,7 @@ func (cp *corsPolicy) AllowMethods(val ...string) *corsPolicy {
return cp
}

func (cp *corsPolicy) AllowOrigins(val ...*v1.StringMatch) *corsPolicy {
func (cp *corsPolicy) AllowOrigins(val ...*istioapiv1beta1.StringMatch) *corsPolicy {
if len(val) == 0 {
cp.value.AllowOrigins = nil
} else {
Expand Down Expand Up @@ -320,25 +320,25 @@ func (cp *corsPolicy) FromApiRuleCorsPolicy(corsPolicy apirulev1beta1.CorsPolicy
return cp
}

// NewHttpRouteHeadersBuilder returns builder for istio.io/api/networking/v1/Headers type
// NewHttpRouteHeadersBuilder returns builder for istio.io/api/networking/v1beta1/Headers type
func NewHttpRouteHeadersBuilder() HttpRouteHeadersBuilder {
return HttpRouteHeadersBuilder{
value: &v1.Headers{
Request: &v1.Headers_HeaderOperations{
value: &istioapiv1beta1.Headers{
Request: &istioapiv1beta1.Headers_HeaderOperations{
Set: make(map[string]string),
},
Response: &v1.Headers_HeaderOperations{
Response: &istioapiv1beta1.Headers_HeaderOperations{
Set: make(map[string]string),
},
},
}
}

type HttpRouteHeadersBuilder struct {
value *v1.Headers
value *istioapiv1beta1.Headers
}

func (h HttpRouteHeadersBuilder) Get() *v1.Headers {
func (h HttpRouteHeadersBuilder) Get() *istioapiv1beta1.Headers {
return h.value
}

Expand Down
8 changes: 4 additions & 4 deletions internal/builders/virtual_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"google.golang.org/protobuf/types/known/durationpb"
networkingv1 "istio.io/api/networking/v1"
networkingapiv1 "istio.io/client-go/pkg/apis/networking/v1"
v1beta12 "istio.io/api/networking/v1beta1"
networkingv1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
"regexp"
Expand All @@ -28,7 +28,7 @@ var _ = Describe("Builder for", func() {
name := "testName"
namespace := "testNs"

initialVs := networkingapiv1.VirtualService{}
initialVs := networkingv1beta1.VirtualService{}
initialVs.Name = "shoudBeOverwritten"
initialVs.Spec.Hosts = []string{"a,", "b", "c"}

Expand Down Expand Up @@ -162,7 +162,7 @@ var _ = Describe("Builder for", func() {
}))

Expect(result.Http[0].CorsPolicy.AllowOrigins).To(HaveLen(1))
Expect(result.Http[0].CorsPolicy.AllowOrigins).To(ConsistOf(&networkingv1.StringMatch{MatchType: &networkingv1.StringMatch_Exact{Exact: "localhost"}}))
Expect(result.Http[0].CorsPolicy.AllowOrigins).To(ConsistOf(&v1beta12.StringMatch{MatchType: &v1beta12.StringMatch_Exact{Exact: "localhost"}}))
Expect(result.Http[0].CorsPolicy.AllowCredentials).To(Not(BeNil()))
Expect(result.Http[0].CorsPolicy.AllowCredentials.Value).To(BeTrue())
Expect(result.Http[0].CorsPolicy.AllowMethods).To(ConsistOf("GET", "POST"))
Expand Down
4 changes: 2 additions & 2 deletions internal/processing/processors/v2alpha1/reconciliation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/kyma-project/api-gateway/internal/processing/processors/istio"
"github.com/kyma-project/api-gateway/internal/validation"
istioValidation "github.com/kyma-project/api-gateway/internal/validation/v1beta1/istio"
networkingapiv1 "istio.io/client-go/pkg/apis/networking/v1"
networkingapiv1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand All @@ -24,7 +24,7 @@ type Reconciliation struct {

func (r Reconciliation) Validate(ctx context.Context, client client.Client) ([]validation.Failure, error) {

var vsList networkingapiv1.VirtualServiceList
var vsList networkingapiv1beta1.VirtualServiceList
if err := client.List(ctx, &vsList); err != nil {
return make([]validation.Failure, 0), err
}
Expand Down
22 changes: 11 additions & 11 deletions internal/processing/processors/v2alpha1/reconciliation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import (
gatewayv1beta1 "github.com/kyma-project/api-gateway/apis/gateway/v1beta1"
gatewayv2alpha1 "github.com/kyma-project/api-gateway/apis/gateway/v2alpha1"
"github.com/kyma-project/api-gateway/internal/processing/processors/v2alpha1"
apinetworkingv1 "istio.io/api/networking/v1"
"istio.io/api/networking/v1beta1"
securityv1beta1 "istio.io/client-go/pkg/apis/security/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/ptr"
"net/http"

. "github.com/kyma-project/api-gateway/internal/processing/processing_test"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
networkingv1 "istio.io/client-go/pkg/apis/networking/v1"
networkingv1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -55,7 +55,7 @@ var _ = Describe("Reconciliation", func() {
// then
Expect(createdObjects).To(HaveLen(1))

Expect(createdObjects[0]).To(BeAssignableToTypeOf(&networkingv1.VirtualService{}))
Expect(createdObjects[0]).To(BeAssignableToTypeOf(&networkingv1beta1.VirtualService{}))
})

It("with v1beta1 JWT and v2alpha1 JWT should provide VirtualService, AuthorizationPolicy and RequestAuthentication", func() {
Expand Down Expand Up @@ -87,7 +87,7 @@ var _ = Describe("Reconciliation", func() {
vsCreated, apCreated, raCreated := false, false, false

for _, createdObj := range createdObjects {
vs, vsOk := createdObj.(*networkingv1.VirtualService)
vs, vsOk := createdObj.(*networkingv1beta1.VirtualService)
ra, raOk := createdObj.(*securityv1beta1.RequestAuthentication)
ap, apOk := createdObj.(*securityv1beta1.AuthorizationPolicy)

Expand Down Expand Up @@ -179,7 +179,7 @@ var _ = Describe("Reconciliation", func() {
vsCreated, raCreated, apCreated := false, false, false

for _, createdObj := range createdObjects {
vs, vsOk := createdObj.(*networkingv1.VirtualService)
vs, vsOk := createdObj.(*networkingv1beta1.VirtualService)
ra, raOk := createdObj.(*securityv1beta1.RequestAuthentication)
ap, apOk := createdObj.(*securityv1beta1.AuthorizationPolicy)

Expand Down Expand Up @@ -248,7 +248,7 @@ var _ = Describe("Reconciliation", func() {
numberOfCreatedRequestAuthentications := 0

for _, createdObj := range createdObjects {
vs, vsOk := createdObj.(*networkingv1.VirtualService)
vs, vsOk := createdObj.(*networkingv1beta1.VirtualService)
ra, raOk := createdObj.(*securityv1beta1.RequestAuthentication)
ap, apOk := createdObj.(*securityv1beta1.AuthorizationPolicy)

Expand All @@ -259,7 +259,7 @@ var _ = Describe("Reconciliation", func() {
Expect(len(http.Route)).To(Equal(1))
Expect(http.Route[0].Destination.Host).To(Equal("example-service.some-namespace.svc.cluster.local"))

switch http.Match[0].Uri.MatchType.(*apinetworkingv1.StringMatch_Regex).Regex {
switch http.Match[0].Uri.MatchType.(*v1beta1.StringMatch_Regex).Regex {
case "/test":
break
case "/different-path":
Expand Down Expand Up @@ -323,7 +323,7 @@ var _ = Describe("Reconciliation", func() {
vsCreated, raCreated, apCreated := false, false, false

for _, createdObj := range createdObjects {
vs, vsOk := createdObj.(*networkingv1.VirtualService)
vs, vsOk := createdObj.(*networkingv1beta1.VirtualService)
ra, raOk := createdObj.(*securityv1beta1.RequestAuthentication)
ap, apOk := createdObj.(*securityv1beta1.AuthorizationPolicy)

Expand All @@ -335,7 +335,7 @@ var _ = Describe("Reconciliation", func() {
Expect(len(http.Route)).To(Equal(1))
Expect(http.Route[0].Destination.Host).To(Equal("example-service.some-namespace.svc.cluster.local"))

switch http.Match[0].Uri.MatchType.(*apinetworkingv1.StringMatch_Regex).Regex {
switch http.Match[0].Uri.MatchType.(*v1beta1.StringMatch_Regex).Regex {
case "/test":
break
case "/different-path":
Expand Down Expand Up @@ -368,7 +368,7 @@ func getV2alpha1APIRuleFor(name, namespace string, rules []gatewayv2alpha1.Rule)
serviceHost := gatewayv2alpha1.Host("myService.test.com")

return &gatewayv2alpha1.APIRule{
ObjectMeta: metav1.ObjectMeta{
ObjectMeta: v1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Expand Down
Loading

0 comments on commit 9372cc9

Please sign in to comment.