diff --git a/common-controller/internal/operator/controllers/dp/ratelimitpolicy_controller.go b/common-controller/internal/operator/controllers/dp/ratelimitpolicy_controller.go index 91ae9ee52..e794f530f 100644 --- a/common-controller/internal/operator/controllers/dp/ratelimitpolicy_controller.go +++ b/common-controller/internal/operator/controllers/dp/ratelimitpolicy_controller.go @@ -46,7 +46,7 @@ import ( "github.com/wso2/apk/common-controller/internal/utils" xds "github.com/wso2/apk/common-controller/internal/xds" dpv1alpha1 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha1" - dpv1alpha2 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha2" + dpv1beta1 "github.com/wso2/apk/common-go-libs/apis/dp/v1beta1" "github.com/wso2/apk/common-go-libs/constants" ) @@ -87,7 +87,7 @@ func NewratelimitController(mgr manager.Manager, ratelimitStore *cache.Ratelimit conf := config.ReadConfigs() predicates := []predicate.Predicate{predicate.NewPredicateFuncs(utils.FilterByNamespaces(conf.CommonController.Operator.Namespaces))} - if err := c.Watch(source.Kind(mgr.GetCache(), &dpv1alpha2.API{}), + if err := c.Watch(source.Kind(mgr.GetCache(), &dpv1beta1.API{}), handler.EnqueueRequestsFromMapFunc(ratelimitReconsiler.getRatelimitForAPI), predicates...); err != nil { loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2611, logging.BLOCKER, "Error watching API resources: %v", err)) @@ -177,7 +177,7 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) Reconcile(ctx context.Cont } func (ratelimitReconsiler *RateLimitPolicyReconciler) getRatelimitForAPI(ctx context.Context, obj k8client.Object) []reconcile.Request { - api, ok := obj.(*dpv1alpha2.API) + api, ok := obj.(*dpv1beta1.API) if !ok { loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2622, logging.TRIVIAL, "Unexpected object type, bypassing reconciliation: %v", api)) @@ -242,13 +242,13 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) getRatelimitForHTTPRoute(c return requests } -func (ratelimitReconsiler *RateLimitPolicyReconciler) marshelRateLimit(ctx context.Context, ratelimitKey types.NamespacedName, +func (ratelimitReconciler *RateLimitPolicyReconciler) marshelRateLimit(ctx context.Context, ratelimitKey types.NamespacedName, ratelimitPolicy dpv1alpha1.RateLimitPolicy) ([]dpv1alpha1.ResolveRateLimitAPIPolicy, error) { policyList := []dpv1alpha1.ResolveRateLimitAPIPolicy{} - var api dpv1alpha2.API + var api dpv1beta1.API - if err := ratelimitReconsiler.client.Get(ctx, types.NamespacedName{ + if err := ratelimitReconciler.client.Get(ctx, types.NamespacedName{ Namespace: ratelimitKey.Namespace, Name: string(ratelimitPolicy.Spec.TargetRef.Name)}, &api); err != nil { @@ -288,7 +288,7 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) marshelRateLimit(ctx conte resolveRatelimit.Environment = environment if len(api.Spec.Production) > 0 && api.Spec.APIType == "REST" { - resolveResourceList, err := ratelimitReconsiler.getHTTPRouteResourceList(ctx, ratelimitKey, ratelimitPolicy, + resolveResourceList, err := ratelimitReconciler.getHTTPRouteResourceList(ctx, ratelimitKey, ratelimitPolicy, api.Spec.Production[0].RouteRefs) if err != nil { return nil, err @@ -300,7 +300,7 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) marshelRateLimit(ctx conte } if len(api.Spec.Sandbox) > 0 && api.Spec.APIType == "REST" { - resolveResourceList, err := ratelimitReconsiler.getHTTPRouteResourceList(ctx, ratelimitKey, ratelimitPolicy, + resolveResourceList, err := ratelimitReconciler.getHTTPRouteResourceList(ctx, ratelimitKey, ratelimitPolicy, api.Spec.Sandbox[0].RouteRefs) if err != nil { return nil, err diff --git a/common-controller/internal/operator/operator.go b/common-controller/internal/operator/operator.go index 473ca72d9..dad00bc2a 100644 --- a/common-controller/internal/operator/operator.go +++ b/common-controller/internal/operator/operator.go @@ -39,6 +39,7 @@ import ( cpv1alpha2 "github.com/wso2/apk/common-go-libs/apis/cp/v1alpha2" dpv1alpha1 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha1" dpv1alpha2 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha2" + dpv1beta1 "github.com/wso2/apk/common-go-libs/apis/dp/v1beta1" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" clientgoscheme "k8s.io/client-go/kubernetes/scheme" @@ -63,6 +64,7 @@ func init() { utilruntime.Must(dpv1alpha2.AddToScheme(scheme)) utilruntime.Must(cpv1alpha2.AddToScheme(scheme)) utilruntime.Must(cpv1alpha2.AddToScheme(scheme)) + utilruntime.Must(dpv1beta1.AddToScheme(scheme)) //+kubebuilder:scaffold:scheme } @@ -132,6 +134,11 @@ func InitOperator(metricsConfig config.Metrics) { "Unable to create webhook API, error: %v", err)) } + if err = (&dpv1beta1.API{}).SetupWebhookWithManager(mgr); err != nil { + loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2601, logging.MAJOR, + "Unable to create webhook API, error: %v", err)) + } + if err = (&dpv1alpha1.RateLimitPolicy{}).SetupWebhookWithManager(mgr); err != nil { loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2637, logging.MAJOR, "Unable to create webhook for Ratelimit, error: %v", err))