Skip to content

Commit

Permalink
Convert API version from v1beta1 to v1alpha3
Browse files Browse the repository at this point in the history
  • Loading branch information
sgayangi committed Sep 18, 2024
1 parent c840e78 commit 7480be3
Show file tree
Hide file tree
Showing 48 changed files with 677 additions and 417 deletions.
2 changes: 1 addition & 1 deletion adapter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/pelletier/go-toml v1.9.5
github.com/prometheus/client_golang v1.18.0
github.com/sirupsen/logrus v1.9.0
github.com/wso2/apk/common-go-libs v0.0.0-20231208100153-24bee7b4bd81
github.com/wso2/apk/common-go-libs v0.0.0-20240911043600-b84cd52d2bd3
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb
google.golang.org/grpc v1.62.0
google.golang.org/protobuf v1.34.1
Expand Down
4 changes: 2 additions & 2 deletions adapter/internal/oasparser/envoyconf/internal_dtos.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package envoyconf

import (
"github.com/wso2/apk/adapter/internal/oasparser/model"
"github.com/wso2/apk/common-go-libs/apis/dp/v1beta1"
"github.com/wso2/apk/common-go-libs/apis/dp/v1alpha3"
)

// routeCreateParams is the DTO used to provide information to the envoy route create function
Expand All @@ -41,7 +41,7 @@ type routeCreateParams struct {
isDefaultVersion bool
createDefaultPath bool
apiLevelRateLimitPolicy *model.RateLimitPolicy
apiProperties []v1beta1.Property
apiProperties []v1alpha3.Property
environment string
envType string
mirrorClusterNames map[string][]string
Expand Down
4 changes: 2 additions & 2 deletions adapter/internal/oasparser/envoyconf/routes_with_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import (
logging "github.com/wso2/apk/adapter/internal/logging"
"github.com/wso2/apk/adapter/internal/oasparser/constants"
"github.com/wso2/apk/adapter/internal/oasparser/model"
"github.com/wso2/apk/common-go-libs/apis/dp/v1beta1"
"github.com/wso2/apk/common-go-libs/apis/dp/v1alpha3"
"google.golang.org/protobuf/proto"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)
Expand Down Expand Up @@ -1610,7 +1610,7 @@ func getUpgradeConfig(apiType string) []*routev3.RouteAction_UpgradeConfig {
return upgradeConfig
}

func getAPIProperties(apiPropertiesConfig []v1beta1.Property) string {
func getAPIProperties(apiPropertiesConfig []v1alpha3.Property) string {
var apiProperties = make(map[string]string)
for _, val := range apiPropertiesConfig {
apiProperties[val.Name] = val.Value
Expand Down
38 changes: 19 additions & 19 deletions adapter/internal/oasparser/envoyconf/routes_with_clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ import (
operatorutils "github.com/wso2/apk/adapter/internal/operator/utils"
"github.com/wso2/apk/common-go-libs/apis/dp/v1alpha1"
"github.com/wso2/apk/common-go-libs/apis/dp/v1alpha2"
"github.com/wso2/apk/common-go-libs/apis/dp/v1beta1"
"github.com/wso2/apk/common-go-libs/apis/dp/v1alpha3"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8types "k8s.io/apimachinery/pkg/types"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)

func TestCreateRoutesWithClustersWithExactAndRegularExpressionRules(t *testing.T) {
apiState := synchronizer.APIState{}
apiDefinition := v1beta1.API{
apiDefinition := v1alpha3.API{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "test-api-2",
},
Spec: v1beta1.APISpec{
Spec: v1alpha3.APISpec{
APIName: "test-api-2",
APIVersion: "2.0.0",
BasePath: "/test-api/2.0.0",
Production: []v1beta1.EnvConfig{
Production: []v1alpha3.EnvConfig{
{
RouteRefs: []string{
"test-api-2-prod-http-route",
Expand Down Expand Up @@ -211,16 +211,16 @@ func TestExtractAPIDetailsFromHTTPRouteForSpecificEnvironment(t *testing.T) {
func generateSampleAPI(apiName string, apiVersion string, basePath string) synchronizer.APIState {

apiState := synchronizer.APIState{}
apiDefinition := v1beta1.API{
apiDefinition := v1alpha3.API{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: apiName,
},
Spec: v1beta1.APISpec{
Spec: v1alpha3.APISpec{
APIName: apiName,
APIVersion: apiVersion,
BasePath: basePath,
Production: []v1beta1.EnvConfig{
Production: []v1alpha3.EnvConfig{
{
RouteRefs: []string{
apiName + "-prod-http-route",
Expand Down Expand Up @@ -274,16 +274,16 @@ func generateSampleAPI(apiName string, apiVersion string, basePath string) synch
// TODO: Fix this test case
func TestCreateRoutesWithClustersWithMultiplePathPrefixRules(t *testing.T) {
apiState := synchronizer.APIState{}
apiDefinition := v1beta1.API{
apiDefinition := v1alpha3.API{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "test-api-1",
},
Spec: v1beta1.APISpec{
Spec: v1alpha3.APISpec{
APIName: "test-api",
APIVersion: "1.0.0",
BasePath: "/test-api/1.0.0",
Production: []v1beta1.EnvConfig{
Production: []v1alpha3.EnvConfig{
{
RouteRefs: []string{
"test-api-1-prod-http-route",
Expand Down Expand Up @@ -423,16 +423,16 @@ func TestCreateRoutesWithClustersWithMultiplePathPrefixRules(t *testing.T) {

func TestCreateRoutesWithClustersWithBackendTLSConfigs(t *testing.T) {
apiState := synchronizer.APIState{}
apiDefinition := v1beta1.API{
apiDefinition := v1alpha3.API{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "test-api-3",
},
Spec: v1beta1.APISpec{
Spec: v1alpha3.APISpec{
APIName: "test-api-3",
APIVersion: "1.0.0",
BasePath: "/test-api-3/1.0.0",
Production: []v1beta1.EnvConfig{
Production: []v1alpha3.EnvConfig{
{
RouteRefs: []string{
"test-api-3-prod-http-route",
Expand Down Expand Up @@ -546,16 +546,16 @@ func TestCreateHealthEndpoint(t *testing.T) {

func TestCreateRoutesWithClustersDifferentBackendRefs(t *testing.T) {
apiState := synchronizer.APIState{}
apiDefinition := v1beta1.API{
apiDefinition := v1alpha3.API{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "test-api-different-backendrefs",
},
Spec: v1beta1.APISpec{
Spec: v1alpha3.APISpec{
APIName: "test-api-different-backendrefs",
APIVersion: "1.0.0",
BasePath: "/test-api-different-backendrefs/1.0.0",
Production: []v1beta1.EnvConfig{
Production: []v1alpha3.EnvConfig{
{
RouteRefs: []string{
"test-api-different-backendrefs-prod-http-route",
Expand Down Expand Up @@ -638,16 +638,16 @@ func TestCreateRoutesWithClustersDifferentBackendRefs(t *testing.T) {

func TestCreateRoutesWithClustersSameBackendRefs(t *testing.T) {
apiState := synchronizer.APIState{}
apiDefinition := v1beta1.API{
apiDefinition := v1alpha3.API{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "test-api-same-backendrefs",
},
Spec: v1beta1.APISpec{
Spec: v1alpha3.APISpec{
APIName: "test-api-same-backendrefs",
APIVersion: "1.0.0",
BasePath: "/test-api-same-backendrefs/1.0.0",
Production: []v1beta1.EnvConfig{
Production: []v1alpha3.EnvConfig{
{
RouteRefs: []string{
"test-api-same-backendrefs-prod-http-route",
Expand Down
17 changes: 12 additions & 5 deletions adapter/internal/oasparser/model/adapter_internal_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
dpv1alpha1 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha1"
dpv1alpha2 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha2"
dpv1alpha3 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha3"
dpv1beta1 "github.com/wso2/apk/common-go-libs/apis/dp/v1beta1"
"golang.org/x/exp/maps"
"k8s.io/apimachinery/pkg/types"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
Expand Down Expand Up @@ -74,7 +73,7 @@ type AdapterInternalAPI struct {
apiDefinitionFile []byte
apiDefinitionEndpoint string
subscriptionValidation bool
APIProperties []dpv1beta1.Property
APIProperties []dpv1alpha3.Property
// GraphQLSchema string
// GraphQLComplexities GraphQLComplexityYaml
IsSystemAPI bool
Expand Down Expand Up @@ -1308,10 +1307,18 @@ func (adapterInternalAPI *AdapterInternalAPI) SetInfoGRPCRouteCR(grpcRoute *gwap
adapterInternalAPI.disableAuthentications = *authScheme.Spec.Override.Disabled
}
authSpec := utils.SelectPolicy(&authScheme.Spec.Override, &authScheme.Spec.Default, nil, nil)
if authSpec != nil && authSpec.AuthTypes != nil && authSpec.AuthTypes.Oauth2.Required != "" {
adapterInternalAPI.SetXWSO2ApplicationSecurity(authSpec.AuthTypes.Oauth2.Required == "mandatory")
if authSpec != nil && authSpec.AuthTypes != nil {
if authSpec.AuthTypes.OAuth2.Required != "" {
adapterInternalAPI.SetApplicationSecurity(constants.OAuth2, authSpec.AuthTypes.OAuth2.Required == "mandatory")
} else {
adapterInternalAPI.SetApplicationSecurity(constants.OAuth2, true)
}

if authSpec.AuthTypes.APIKey != nil {
adapterInternalAPI.SetApplicationSecurity(constants.APIKey, authSpec.AuthTypes.APIKey.Required == "mandatory")
}
} else {
adapterInternalAPI.SetXWSO2ApplicationSecurity(true)
adapterInternalAPI.SetApplicationSecurity(constants.OAuth2, true)
}
adapterInternalAPI.disableScopes = disableScopes
// Check whether the API has a backend JWT token
Expand Down
3 changes: 1 addition & 2 deletions adapter/internal/oasparser/model/http_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
dpv1alpha1 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha1"
dpv1alpha2 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha2"
dpv1alpha3 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha3"
"github.com/wso2/apk/common-go-libs/apis/dp/v1beta1"
"k8s.io/apimachinery/pkg/types"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)
Expand Down Expand Up @@ -311,7 +310,7 @@ func getAllowedOperations(httpMethod *gwapiv1.HTTPMethod, policies OperationPoli
}

// SetInfoAPICR populates ID, ApiType, Version and XWso2BasePath of adapterInternalAPI.
func (swagger *AdapterInternalAPI) SetInfoAPICR(api v1beta1.API) {
func (swagger *AdapterInternalAPI) SetInfoAPICR(api dpv1alpha3.API) {
swagger.UUID = string(api.ObjectMeta.UID)
swagger.title = api.Spec.APIName
swagger.apiType = api.Spec.APIType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ spec:
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1beta1
name: v1alpha3
schema:
openAPIV3Schema:
description: API is the Schema for the apis API
Expand Down
40 changes: 40 additions & 0 deletions adapter/internal/operator/config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ webhooks:
resources:
- apis
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /mutate-dp-wso2-com-v1alpha3-api
failurePolicy: Fail
name: mapi.kb.io
rules:
- apiGroups:
- dp.wso2.com
apiVersions:
- v1alpha3
operations:
- CREATE
- UPDATE
resources:
- apis
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
Expand Down Expand Up @@ -230,6 +250,26 @@ webhooks:
resources:
- apis
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /validate-dp-wso2-com-v1alpha3-api
failurePolicy: Fail
name: vapi.kb.io
rules:
- apiGroups:
- dp.wso2.com
apiVersions:
- v1alpha3
operations:
- CREATE
- UPDATE
resources:
- apis
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
Expand Down
Loading

0 comments on commit 7480be3

Please sign in to comment.