Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement/routeref #2094

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b89380b
update httprouterefs to routerefs in cc
AmaliMatharaarachchi Jan 24, 2024
474e481
rename httprouterefs to routerefs
AmaliMatharaarachchi Jan 24, 2024
b64bb30
rename httprouterefs to routerefs in crs
AmaliMatharaarachchi Jan 24, 2024
ce0bb1a
remove debug logs
AmaliMatharaarachchi Jan 24, 2024
8d674e0
fix lint issues
AmaliMatharaarachchi Mar 6, 2024
273952a
httpRouteRef=>routeRef change
tharindu1st Mar 6, 2024
bc0601a
Add modify api test
Tharsanan1 Feb 22, 2024
f9d923f
Update test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest…
Tharsanan1 Feb 28, 2024
9dfe2f6
Update test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest…
Tharsanan1 Feb 28, 2024
fa29953
Update test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest…
Tharsanan1 Feb 28, 2024
4006891
Change gateway name
Tharsanan1 Mar 6, 2024
7c3a922
Add prometheus configs to adapter enforcer router
sgayangi Feb 19, 2024
6781d04
Add Prometheus support to common controller
sgayangi Feb 25, 2024
dde944a
Update exposed adapter and enforcer metrics
sgayangi Feb 25, 2024
3d36273
Update enforcer metric configs
sgayangi Feb 27, 2024
ebac428
Add Prometheus support to Config DS
sgayangi Feb 28, 2024
d1dfc14
Update configurations for Prometheus
sgayangi Feb 28, 2024
44302fc
Add Prometheus support to IdP DS
sgayangi Feb 29, 2024
3483bd4
Add Prometheus support to ratelimiter
sgayangi Mar 1, 2024
e532eff
Address review comments
sgayangi Mar 3, 2024
287c2c3
Watch for CM and secrets in token issuer controller
Tharsanan1 Feb 28, 2024
923f35b
Add predicates to tokenissuer watch
Tharsanan1 Mar 6, 2024
c4be1ed
Revert "Test api resource modifications"
Tharsanan1 Mar 6, 2024
826c877
Update ports used for Prometheus
sgayangi Mar 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestCreateRoutesWithClustersWithExactAndRegularExpressionRules(t *testing.T
BasePath: "/test-api/2.0.0",
Production: []v1alpha2.EnvConfig{
{
HTTPRouteRefs: []string{
RouteRefs: []string{
"test-api-2-prod-http-route",
},
},
Expand Down Expand Up @@ -218,7 +218,7 @@ func generateSampleAPI(apiName string, apiVersion string, basePath string) synch
BasePath: basePath,
Production: []v1alpha2.EnvConfig{
{
HTTPRouteRefs: []string{
RouteRefs: []string{
apiName + "-prod-http-route",
},
},
Expand Down Expand Up @@ -281,7 +281,7 @@ func TestCreateRoutesWithClustersWithMultiplePathPrefixRules(t *testing.T) {
BasePath: "/test-api/1.0.0",
Production: []v1alpha2.EnvConfig{
{
HTTPRouteRefs: []string{
RouteRefs: []string{
"test-api-1-prod-http-route",
},
},
Expand Down Expand Up @@ -430,7 +430,7 @@ func TestCreateRoutesWithClustersWithBackendTLSConfigs(t *testing.T) {
BasePath: "/test-api-3/1.0.0",
Production: []v1alpha2.EnvConfig{
{
HTTPRouteRefs: []string{
RouteRefs: []string{
"test-api-3-prod-http-route",
},
},
Expand Down Expand Up @@ -553,7 +553,7 @@ func TestCreateRoutesWithClustersDifferentBackendRefs(t *testing.T) {
BasePath: "/test-api-different-backendrefs/1.0.0",
Production: []v1alpha2.EnvConfig{
{
HTTPRouteRefs: []string{
RouteRefs: []string{
"test-api-different-backendrefs-prod-http-route",
},
},
Expand Down Expand Up @@ -645,7 +645,7 @@ func TestCreateRoutesWithClustersSameBackendRefs(t *testing.T) {
BasePath: "/test-api-same-backendrefs/1.0.0",
Production: []v1alpha2.EnvConfig{
{
HTTPRouteRefs: []string{
RouteRefs: []string{
"test-api-same-backendrefs-prod-http-route",
},
},
Expand Down
12 changes: 6 additions & 6 deletions adapter/internal/operator/controllers/dp/api_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ func (apiReconciler *APIReconciler) applyStartupAPIs() {
func (apiReconciler *APIReconciler) resolveAPIRefs(ctx context.Context, api dpv1alpha2.API) (*synchronizer.APIEvent, error) {
var prodRouteRefs, sandRouteRefs []string
if len(api.Spec.Production) > 0 {
prodRouteRefs = api.Spec.Production[0].HTTPRouteRefs
prodRouteRefs = api.Spec.Production[0].RouteRefs
}
if len(api.Spec.Sandbox) > 0 {
sandRouteRefs = api.Spec.Sandbox[0].HTTPRouteRefs
sandRouteRefs = api.Spec.Sandbox[0].RouteRefs
}

apiState := &synchronizer.APIState{
Expand Down Expand Up @@ -1484,7 +1484,7 @@ func addIndexes(ctx context.Context, mgr manager.Manager) error {
api := rawObj.(*dpv1alpha2.API)
var httpRoutes []string
if len(api.Spec.Production) > 0 {
for _, ref := range api.Spec.Production[0].HTTPRouteRefs {
for _, ref := range api.Spec.Production[0].RouteRefs {
if ref != "" {
httpRoutes = append(httpRoutes,
types.NamespacedName{
Expand All @@ -1495,7 +1495,7 @@ func addIndexes(ctx context.Context, mgr manager.Manager) error {
}
}
if len(api.Spec.Sandbox) > 0 {
for _, ref := range api.Spec.Sandbox[0].HTTPRouteRefs {
for _, ref := range api.Spec.Sandbox[0].RouteRefs {
if ref != "" {
httpRoutes = append(httpRoutes,
types.NamespacedName{
Expand All @@ -1515,7 +1515,7 @@ func addIndexes(ctx context.Context, mgr manager.Manager) error {
api := rawObj.(*dpv1alpha2.API)
var gqlRoutes []string
if len(api.Spec.Production) > 0 {
for _, ref := range api.Spec.Production[0].HTTPRouteRefs {
for _, ref := range api.Spec.Production[0].RouteRefs {
if ref != "" {
gqlRoutes = append(gqlRoutes,
types.NamespacedName{
Expand All @@ -1526,7 +1526,7 @@ func addIndexes(ctx context.Context, mgr manager.Manager) error {
}
}
if len(api.Spec.Sandbox) > 0 {
for _, ref := range api.Spec.Sandbox[0].HTTPRouteRefs {
for _, ref := range api.Spec.Sandbox[0].RouteRefs {
if ref != "" {
gqlRoutes = append(gqlRoutes,
types.NamespacedName{
Expand Down
4 changes: 2 additions & 2 deletions adapter/internal/operator/synchronizer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func deployMultipleAPIsInGateway(event *APIEvent, successChannel *chan SuccessEv

updated := xds.UpdateXdsCacheOnAPIChange(updatedLabelsMap)
if updated {
loggers.LoggerAPKOperator.Info("XDS cache updated for apis: %+v", updatedAPIs)
loggers.LoggerAPKOperator.Infof("XDS cache updated for apis: %+v", updatedAPIs)
*successChannel <- SuccessEvent{
APINamespacedName: updatedAPIs,
State: event.EventType,
Expand All @@ -234,7 +234,7 @@ func deployMultipleAPIsInGateway(event *APIEvent, successChannel *chan SuccessEv
paritionCh <- event
}
} else {
loggers.LoggerAPKOperator.Info("XDS cache not updated for APIs : %+v", updatedAPIs)
loggers.LoggerAPKOperator.Infof("XDS cache not updated for APIs : %+v", updatedAPIs)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) marshelRateLimit(ctx conte

if len(api.Spec.Production) > 0 && api.Spec.APIType == "REST" {
resolveResourceList, err := ratelimitReconsiler.getHTTPRouteResourceList(ctx, ratelimitKey, ratelimitPolicy,
api.Spec.Production[0].HTTPRouteRefs)
api.Spec.Production[0].RouteRefs)
if err != nil {
return nil, err
}
Expand All @@ -301,7 +301,7 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) marshelRateLimit(ctx conte

if len(api.Spec.Sandbox) > 0 && api.Spec.APIType == "REST" {
resolveResourceList, err := ratelimitReconsiler.getHTTPRouteResourceList(ctx, ratelimitKey, ratelimitPolicy,
api.Spec.Sandbox[0].HTTPRouteRefs)
api.Spec.Sandbox[0].RouteRefs)
if err != nil {
return nil, err
}
Expand Down
42 changes: 16 additions & 26 deletions common-go-libs/apis/dp/v1alpha1/api_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ func (src *API) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.BasePath = src.Spec.BasePath
dst.Spec.Organization = src.Spec.Organization
dst.Spec.SystemAPI = src.Spec.SystemAPI
if src.Spec.Production != nil {
src.Spec.Production = []EnvConfig{}
for _, productionRef := range src.Spec.Production {
dst.Spec.Production = append(dst.Spec.Production, v1alpha2.EnvConfig{
RouteRefs: productionRef.HTTPRouteRefs,
})
}
}
if src.Spec.Sandbox != nil {
src.Spec.Sandbox = []EnvConfig{}
for _, sandboxRef := range src.Spec.Sandbox {
dst.Spec.Sandbox = append(dst.Spec.Sandbox, v1alpha2.EnvConfig{
RouteRefs: sandboxRef.HTTPRouteRefs,
})
}
}

// Convert []Property to []v1alpha2.Property
var properties []v1alpha2.Property
Expand All @@ -47,19 +63,6 @@ func (src *API) ConvertTo(dstRaw conversion.Hub) error {
}
dst.Spec.APIProperties = properties

// Convert []EnvConfig to []v1alpha2.EnvConfig
var production []v1alpha2.EnvConfig
for _, p := range src.Spec.Production {
production = append(production, v1alpha2.EnvConfig(p))
}
dst.Spec.Production = production

var sandbox []v1alpha2.EnvConfig
for _, s := range src.Spec.Sandbox {
sandbox = append(sandbox, v1alpha2.EnvConfig(s))
}
dst.Spec.Sandbox = sandbox

// Status
dst.Status.DeploymentStatus = v1alpha2.DeploymentStatus(src.Status.DeploymentStatus)

Expand Down Expand Up @@ -91,19 +94,6 @@ func (src *API) ConvertFrom(srcRaw conversion.Hub) error {
}
src.Spec.APIProperties = properties

// Convert []EnvConfig to []v1alpha1.EnvConfig
var production []EnvConfig
for _, p := range dst.Spec.Production {
production = append(production, EnvConfig(p))
}
src.Spec.Production = production

var sandbox []EnvConfig
for _, s := range dst.Spec.Sandbox {
sandbox = append(sandbox, EnvConfig(s))
}
src.Spec.Sandbox = sandbox

// Status
src.Status.DeploymentStatus = DeploymentStatus(dst.Status.DeploymentStatus)

Expand Down
6 changes: 3 additions & 3 deletions common-go-libs/apis/dp/v1alpha2/api_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type APISpec struct {
// +optional
IsDefaultVersion bool `json:"isDefaultVersion"`

// DefinitionFileRef contains the OpenAPI 3 or Swagger
// DefinitionFileRef contains the
// definition of the API in a ConfigMap.
//
// +optional
Expand Down Expand Up @@ -124,8 +124,8 @@ type Property struct {

// EnvConfig contains the environment specific configuration
type EnvConfig struct {
// HTTPRouteRefs denotes the environment of the API.
HTTPRouteRefs []string `json:"httpRouteRefs"`
// RouteRefs denotes the environment of the API.
RouteRefs []string `json:"routeRefs"`
}

// APIStatus defines the observed state of API
Expand Down
11 changes: 5 additions & 6 deletions common-go-libs/apis/dp/v1alpha2/api_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func (r *API) ValidateDelete() (admission.Warnings, error) {

// validateAPI validate api crd fields
func (r *API) validateAPI() error {
loggers.LoggerAPKOperator.Error("validating...")
var allErrs field.ErrorList
conf := config.ReadConfigs()
namespaces := conf.CommonController.Operator.Namespaces
Expand Down Expand Up @@ -127,17 +126,18 @@ func (r *API) validateAPI() error {
allErrs = append(allErrs, field.Required(field.NewPath("spec").Child("organization"), "Organization can not be empty"))
}

if !(len(r.Spec.Production) > 0 && r.Spec.Production[0].HTTPRouteRefs != nil && len(r.Spec.Production[0].HTTPRouteRefs) > 0) && !(len(r.Spec.Sandbox) > 0 && r.Spec.Sandbox[0].HTTPRouteRefs != nil && len(r.Spec.Sandbox[0].HTTPRouteRefs) > 0) {
if !(len(r.Spec.Production) > 0 && r.Spec.Production[0].RouteRefs != nil && len(r.Spec.Production[0].RouteRefs) > 0) &&
!(len(r.Spec.Sandbox) > 0 && r.Spec.Sandbox[0].RouteRefs != nil && len(r.Spec.Sandbox[0].RouteRefs) > 0) {
allErrs = append(allErrs, field.Required(field.NewPath("spec"),
"both API production and sandbox endpoint references cannot be empty"))
}

var prodHTTPRoute1, sandHTTPRoute1 []string
if len(r.Spec.Production) > 0 {
prodHTTPRoute1 = r.Spec.Production[0].HTTPRouteRefs
prodHTTPRoute1 = r.Spec.Production[0].RouteRefs
}
if len(r.Spec.Sandbox) > 0 {
sandHTTPRoute1 = r.Spec.Sandbox[0].HTTPRouteRefs
sandHTTPRoute1 = r.Spec.Sandbox[0].RouteRefs
}

if isEmptyStringsInArray(prodHTTPRoute1) {
Expand Down Expand Up @@ -263,8 +263,7 @@ func validateGzip(name, namespace string) (string, string) {
configMap := &corev1.ConfigMap{}
if err := c.Get(context.Background(), types.NamespacedName{Name: string(name), Namespace: namespace}, configMap); err == nil {
var apiDef []byte
for key, val := range configMap.BinaryData {
loggers.LoggerAPKOperator.Error(key)
for _, val := range configMap.BinaryData {
// config map data key is "swagger.yaml"
apiDef = []byte(val)
}
Expand Down
4 changes: 2 additions & 2 deletions common-go-libs/apis/dp/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions common-go-libs/config/crd/bases/dp.wso2.com_apis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ spec:
pattern: ^[/][a-zA-Z0-9~/_.-]*$
type: string
definitionFileRef:
description: DefinitionFileRef contains the OpenAPI 3 or Swagger definition
of the API in a ConfigMap.
description: DefinitionFileRef contains the definition of the API
in a ConfigMap.
type: string
definitionPath:
default: /api-definition
Expand All @@ -285,13 +285,13 @@ spec:
items:
description: EnvConfig contains the environment specific configuration
properties:
httpRouteRefs:
description: HTTPRouteRefs denotes the environment of the API.
routeRefs:
description: RouteRefs denotes the environment of the API.
items:
type: string
type: array
required:
- httpRouteRefs
- routeRefs
type: object
maxItems: 1
nullable: true
Expand All @@ -302,13 +302,13 @@ spec:
items:
description: EnvConfig contains the environment specific configuration
properties:
httpRouteRefs:
description: HTTPRouteRefs denotes the environment of the API.
routeRefs:
description: RouteRefs denotes the environment of the API.
items:
type: string
type: array
required:
- httpRouteRefs
- routeRefs
type: object
maxItems: 1
nullable: true
Expand Down
1 change: 1 addition & 0 deletions common-go-libs/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down
6 changes: 3 additions & 3 deletions developer/tryout/samples/sample-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# -----------------------------------------------------------------------
apiVersion: dp.wso2.com/v1alpha1
apiVersion: dp.wso2.com/v1alpha2
kind: API
metadata:
name: http-bin-api
Expand All @@ -24,11 +24,11 @@ spec:
basePath: /http-bin-api/1.0.8
definitionFileRef: swagger-definition-http-bin-api
production:
- httpRouteRefs:
- routeRefs:
- prod-http-route-http-bin-api-p1
- prod-http-route-http-bin-api-p2
sandbox:
- httpRouteRefs:
- routeRefs:
- sand-http-route-http-bin-api
organization: a3b58ccf-6ecc-4557-b5bb-0a35cce38256
---
Expand Down
Loading
Loading