diff --git a/.gitignore b/.gitignore index d8322f6fa..421070bfd 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,5 @@ vendor *.swp *.swo *~ + +kuadrant-controller diff --git a/apis/apim/v1alpha1/api_types.go b/apis/apim/v1alpha1/api_types.go deleted file mode 100644 index 0c3aaef72..000000000 --- a/apis/apim/v1alpha1/api_types.go +++ /dev/null @@ -1,60 +0,0 @@ -/* -Copyright 2021 Red Hat, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1alpha1 - -import ( - v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -type OPARef struct { - URL string `json:"URL,omitempty"` - ConfigMap *v1.LocalObjectReference `json:"configMap,omitempty"` -} - -type APIMetadata struct { - Version string `json:"version"` - Title string `json:"title"` - Description string `json:"description,omitempty"` - OpenAPIRef OPARef `json:"openAPIRef,omitempty"` -} - -type APISpec struct { - Info APIMetadata `json:"info"` -} - -// +kubebuilder:object:root=true -// API is the Schema for the apis API -type API struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec APISpec `json:"spec"` -} - -// +kubebuilder:object:root=true - -// APIList contains a list of API -type APIList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []API `json:"items"` -} - -func init() { - SchemeBuilder.Register(&API{}, &APIList{}) -} diff --git a/apis/apim/v1alpha1/zz_generated.deepcopy.go b/apis/apim/v1alpha1/zz_generated.deepcopy.go index abb5edc85..cfba2fe22 100644 --- a/apis/apim/v1alpha1/zz_generated.deepcopy.go +++ b/apis/apim/v1alpha1/zz_generated.deepcopy.go @@ -22,100 +22,9 @@ package v1alpha1 import ( apiv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1" - "k8s.io/api/core/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *API) DeepCopyInto(out *API) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new API. -func (in *API) DeepCopy() *API { - if in == nil { - return nil - } - out := new(API) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *API) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *APIList) DeepCopyInto(out *APIList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]API, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIList. -func (in *APIList) DeepCopy() *APIList { - if in == nil { - return nil - } - out := new(APIList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *APIList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *APIMetadata) DeepCopyInto(out *APIMetadata) { - *out = *in - in.OpenAPIRef.DeepCopyInto(&out.OpenAPIRef) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIMetadata. -func (in *APIMetadata) DeepCopy() *APIMetadata { - if in == nil { - return nil - } - out := new(APIMetadata) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *APISpec) DeepCopyInto(out *APISpec) { - *out = *in - in.Info.DeepCopyInto(&out.Info) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APISpec. -func (in *APISpec) DeepCopy() *APISpec { - if in == nil { - return nil - } - out := new(APISpec) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ActionSpecifier) DeepCopyInto(out *ActionSpecifier) { *out = *in @@ -151,26 +60,6 @@ func (in *NetworkingRef) DeepCopy() *NetworkingRef { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *OPARef) DeepCopyInto(out *OPARef) { - *out = *in - if in.ConfigMap != nil { - in, out := &in.ConfigMap, &out.ConfigMap - *out = new(v1.LocalObjectReference) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OPARef. -func (in *OPARef) DeepCopy() *OPARef { - if in == nil { - return nil - } - out := new(OPARef) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RLGenericKey) DeepCopyInto(out *RLGenericKey) { *out = *in diff --git a/config/crd/bases/apim.kuadrant.io_apis.yaml b/config/crd/bases/apim.kuadrant.io_apis.yaml deleted file mode 100644 index 351ed3f77..000000000 --- a/config/crd/bases/apim.kuadrant.io_apis.yaml +++ /dev/null @@ -1,78 +0,0 @@ - ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.7.0 - creationTimestamp: null - name: apis.apim.kuadrant.io -spec: - group: apim.kuadrant.io - names: - kind: API - listKind: APIList - plural: apis - singular: api - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: API is the Schema for the apis API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - properties: - info: - properties: - description: - type: string - openAPIRef: - properties: - URL: - type: string - configMap: - description: LocalObjectReference contains enough information - to let you locate the referenced object inside the same - namespace. - properties: - name: - description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - TODO: Add other useful fields. apiVersion, kind, uid?' - type: string - type: object - type: object - title: - type: string - version: - type: string - required: - - title - - version - type: object - required: - - info - type: object - required: - - spec - type: object - served: true - storage: true -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index 7e744cb42..9bb4801c1 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -2,7 +2,6 @@ # since it depends on service name and namespace that are out of this kustomize package. # It should be run by config/default resources: -- bases/apim.kuadrant.io_apis.yaml - bases/apim.kuadrant.io_ratelimitpolicies.yaml #+kubebuilder:scaffold:crdkustomizeresource diff --git a/config/deploy/manifests.yaml b/config/deploy/manifests.yaml index 353408c8d..0a9a223bd 100644 --- a/config/deploy/manifests.yaml +++ b/config/deploy/manifests.yaml @@ -8,78 +8,6 @@ metadata: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.7.0 - creationTimestamp: null - labels: - app: kuadrant - name: apis.apim.kuadrant.io -spec: - group: apim.kuadrant.io - names: - kind: API - listKind: APIList - plural: apis - singular: api - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: API is the Schema for the apis API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - properties: - info: - properties: - description: - type: string - openAPIRef: - properties: - URL: - type: string - configMap: - description: LocalObjectReference contains enough information to let you locate the referenced object inside the same namespace. - properties: - name: - description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?' - type: string - type: object - type: object - title: - type: string - version: - type: string - required: - - title - - version - type: object - required: - - info - type: object - required: - - spec - type: object - served: true - storage: true -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.7.0 @@ -270,32 +198,6 @@ metadata: app: kuadrant name: kuadrant-manager-role rules: -- apiGroups: - - apim.kuadrant.io - resources: - - apis - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - apim.kuadrant.io - resources: - - apis/finalizers - verbs: - - update -- apiGroups: - - apim.kuadrant.io - resources: - - apis/status - verbs: - - get - - patch - - update - apiGroups: - apim.kuadrant.io resources: diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index d57ef8fca..4694e7696 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -6,32 +6,6 @@ metadata: creationTimestamp: null name: manager-role rules: -- apiGroups: - - apim.kuadrant.io - resources: - - apis - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - apim.kuadrant.io - resources: - - apis/finalizers - verbs: - - update -- apiGroups: - - apim.kuadrant.io - resources: - - apis/status - verbs: - - get - - patch - - update - apiGroups: - apim.kuadrant.io resources: diff --git a/controllers/apim/api_controller.go b/controllers/apim/api_controller.go deleted file mode 100644 index 763c8434e..000000000 --- a/controllers/apim/api_controller.go +++ /dev/null @@ -1,82 +0,0 @@ -/* -Copyright 2021 Red Hat, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package apim - -import ( - "context" - - "k8s.io/apimachinery/pkg/runtime" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - - "github.com/go-logr/logr" - apimv1alpha1 "github.com/kuadrant/kuadrant-controller/apis/apim/v1alpha1" - "github.com/kuadrant/kuadrant-controller/pkg/reconcilers" - apierrors "k8s.io/apimachinery/pkg/api/errors" -) - -const APIFinalizerName = "kuadrant.io/envoyfilters" - -// APIReconciler reconciles a API object -type APIReconciler struct { - *reconcilers.BaseReconciler - Scheme *runtime.Scheme -} - -//+kubebuilder:rbac:groups=apim.kuadrant.io,resources=apis,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=apim.kuadrant.io,resources=apis/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=apim.kuadrant.io,resources=apis/finalizers,verbs=update - -func (r *APIReconciler) Reconcile(eventCtx context.Context, req ctrl.Request) (ctrl.Result, error) { - logger := r.Logger().WithValues("API", req.NamespacedName) - logger.Info("Reconciling API object") - ctx := logr.NewContext(eventCtx, logger) - - var api apimv1alpha1.API - if err := r.Client().Get(ctx, req.NamespacedName, &api); err != nil { - if apierrors.IsNotFound(err) { - logger.Info("no API resource found.") - return ctrl.Result{}, nil - } - logger.Error(err, "failed to get API object") - return ctrl.Result{}, err - } - - if api.GetDeletionTimestamp() != nil && controllerutil.ContainsFinalizer(&api, APIFinalizerName) { - controllerutil.RemoveFinalizer(&api, APIFinalizerName) - if err := r.BaseReconciler.UpdateResource(ctx, &api); client.IgnoreNotFound(err) != nil { - return ctrl.Result{Requeue: true}, err - } - return ctrl.Result{}, nil - } - - if !controllerutil.ContainsFinalizer(&api, APIFinalizerName) { - controllerutil.AddFinalizer(&api, APIFinalizerName) - if err := r.BaseReconciler.UpdateResource(ctx, &api); client.IgnoreNotFound(err) != nil { - return ctrl.Result{Requeue: true}, err - } - } - return ctrl.Result{}, nil -} - -// SetupWithManager sets up the controller with the Manager. -func (r *APIReconciler) SetupWithManager(mgr ctrl.Manager) error { - return ctrl.NewControllerManagedBy(mgr). - For(&apimv1alpha1.API{}). - Complete(r) -} diff --git a/main.go b/main.go index ad621b3ce..080ba0746 100644 --- a/main.go +++ b/main.go @@ -107,20 +107,6 @@ func main() { os.Exit(1) } - apiBaseReconciler := reconcilers.NewBaseReconciler( - mgr.GetClient(), mgr.GetScheme(), mgr.GetAPIReader(), - log.Log.WithName("api"), - mgr.GetEventRecorderFor("API"), - ) - - if err = (&apimcontrollers.APIReconciler{ - BaseReconciler: apiBaseReconciler, - Scheme: mgr.GetScheme(), - }).SetupWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create controller", "controller", "API") - os.Exit(1) - } - rateLimitPolicyBaseReconciler := reconcilers.NewBaseReconciler( mgr.GetClient(), mgr.GetScheme(), mgr.GetAPIReader(), log.Log.WithName("ratelimitpolicy"),