From e4c13905d8c32eb993cdea5e876f8c71a9238766 Mon Sep 17 00:00:00 2001 From: Ryan Payne Date: Wed, 31 Jan 2024 12:18:42 -0600 Subject: [PATCH] feat: generate boilerplate for IAR --- PROJECT | 9 + api/falcon/v1alpha1/falconimage_types.go | 48 ++++ api/falcon/v1alpha1/zz_generated.deepcopy.go | 89 ++++++ cmd/main.go | 8 + .../falcon.crowdstrike.com_falconimages.yaml | 49 ++++ config/crd/kustomization.yaml | 3 + .../cainjection_in_falcon_falconimages.yaml | 7 + .../webhook_in_falcon_falconimages.yaml | 16 ++ .../rbac/falcon_falconimage_editor_role.yaml | 31 ++ .../rbac/falcon_falconimage_viewer_role.yaml | 27 ++ config/rbac/role.yaml | 26 ++ .../samples/falcon_v1alpha1_falconimage.yaml | 12 + config/samples/kustomization.yaml | 1 + deploy/falcon-operator.yaml | 75 +++++ .../falcon_image/falconimage_controller.go | 46 +++ .../controller/falcon_image/suite_test.go | 269 ++++++++++++++++++ 16 files changed, 716 insertions(+) create mode 100644 api/falcon/v1alpha1/falconimage_types.go create mode 100644 config/crd/bases/falcon.crowdstrike.com_falconimages.yaml create mode 100644 config/crd/patches/cainjection_in_falcon_falconimages.yaml create mode 100644 config/crd/patches/webhook_in_falcon_falconimages.yaml create mode 100644 config/rbac/falcon_falconimage_editor_role.yaml create mode 100644 config/rbac/falcon_falconimage_viewer_role.yaml create mode 100644 config/samples/falcon_v1alpha1_falconimage.yaml create mode 100644 internal/controller/falcon_image/falconimage_controller.go create mode 100644 internal/controller/falcon_image/suite_test.go diff --git a/PROJECT b/PROJECT index 88db8788..c3e7a743 100644 --- a/PROJECT +++ b/PROJECT @@ -38,4 +38,13 @@ resources: kind: FalconAdmission path: github.com/crowdstrike/falcon-operator/api/falcon/v1alpha1 version: v1alpha1 +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: crowdstrike.com + group: falcon + kind: FalconImage + path: github.com/crowdstrike/falcon-operator/api/falcon/v1alpha1 + version: v1alpha1 version: "3" diff --git a/api/falcon/v1alpha1/falconimage_types.go b/api/falcon/v1alpha1/falconimage_types.go new file mode 100644 index 00000000..9b8a4b93 --- /dev/null +++ b/api/falcon/v1alpha1/falconimage_types.go @@ -0,0 +1,48 @@ +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. + +// FalconImageSpec defines the desired state of FalconImage +type FalconImageSpec struct { + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + // Important: Run "make" to regenerate code after modifying this file + + // Foo is an example field of FalconImage. Edit falconimage_types.go to remove/update + Foo string `json:"foo,omitempty"` +} + +// FalconImageStatus defines the observed state of FalconImage +type FalconImageStatus struct { + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster + // Important: Run "make" to regenerate code after modifying this file +} + +//+kubebuilder:object:root=true +//+kubebuilder:subresource:status + +// FalconImage is the Schema for the falconimages API +type FalconImage struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec FalconImageSpec `json:"spec,omitempty"` + Status FalconImageStatus `json:"status,omitempty"` +} + +//+kubebuilder:object:root=true + +// FalconImageList contains a list of FalconImage +type FalconImageList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []FalconImage `json:"items"` +} + +func init() { + SchemeBuilder.Register(&FalconImage{}, &FalconImageList{}) +} diff --git a/api/falcon/v1alpha1/zz_generated.deepcopy.go b/api/falcon/v1alpha1/zz_generated.deepcopy.go index 53d869ed..bfa7f1a2 100644 --- a/api/falcon/v1alpha1/zz_generated.deepcopy.go +++ b/api/falcon/v1alpha1/zz_generated.deepcopy.go @@ -754,6 +754,95 @@ func (in *FalconContainerStatus) DeepCopy() *FalconContainerStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *FalconImage) DeepCopyInto(out *FalconImage) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FalconImage. +func (in *FalconImage) DeepCopy() *FalconImage { + if in == nil { + return nil + } + out := new(FalconImage) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *FalconImage) 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 *FalconImageList) DeepCopyInto(out *FalconImageList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]FalconImage, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FalconImageList. +func (in *FalconImageList) DeepCopy() *FalconImageList { + if in == nil { + return nil + } + out := new(FalconImageList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *FalconImageList) 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 *FalconImageSpec) DeepCopyInto(out *FalconImageSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FalconImageSpec. +func (in *FalconImageSpec) DeepCopy() *FalconImageSpec { + if in == nil { + return nil + } + out := new(FalconImageSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *FalconImageStatus) DeepCopyInto(out *FalconImageStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FalconImageStatus. +func (in *FalconImageStatus) DeepCopy() *FalconImageStatus { + if in == nil { + return nil + } + out := new(FalconImageStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *FalconNodeSensor) DeepCopyInto(out *FalconNodeSensor) { *out = *in diff --git a/cmd/main.go b/cmd/main.go index 53349b57..5e246ea6 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -38,6 +38,7 @@ import ( falconv1alpha1 "github.com/crowdstrike/falcon-operator/api/falcon/v1alpha1" admissioncontroller "github.com/crowdstrike/falcon-operator/internal/controller/admission" containercontroller "github.com/crowdstrike/falcon-operator/internal/controller/falcon_container" + imagecontroller "github.com/crowdstrike/falcon-operator/internal/controller/falcon_image" nodecontroller "github.com/crowdstrike/falcon-operator/internal/controller/falcon_node" "github.com/crowdstrike/falcon-operator/pkg/common" "github.com/crowdstrike/falcon-operator/version" @@ -167,6 +168,13 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "FalconAdmission") os.Exit(1) } + if err = (&imagecontroller.FalconImageReconciler{ + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "FalconImage") + os.Exit(1) + } // +kubebuilder:scaffold:builder if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { diff --git a/config/crd/bases/falcon.crowdstrike.com_falconimages.yaml b/config/crd/bases/falcon.crowdstrike.com_falconimages.yaml new file mode 100644 index 00000000..394d003a --- /dev/null +++ b/config/crd/bases/falcon.crowdstrike.com_falconimages.yaml @@ -0,0 +1,49 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.12.0 + name: falconimages.falcon.crowdstrike.com +spec: + group: falcon.crowdstrike.com + names: + kind: FalconImage + listKind: FalconImageList + plural: falconimages + singular: falconimage + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: FalconImage is the Schema for the falconimages 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: + description: FalconImageSpec defines the desired state of FalconImage + properties: + foo: + description: Foo is an example field of FalconImage. Edit falconimage_types.go + to remove/update + type: string + type: object + status: + description: FalconImageStatus defines the observed state of FalconImage + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index f8c85497..e1a4752e 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -5,6 +5,7 @@ resources: - bases/falcon.crowdstrike.com_falconadmissions.yaml - bases/falcon.crowdstrike.com_falconcontainers.yaml - bases/falcon.crowdstrike.com_falconnodesensors.yaml +- bases/falcon.crowdstrike.com_falconimages.yaml #+kubebuilder:scaffold:crdkustomizeresource patches: @@ -13,6 +14,7 @@ patches: #- path: patches/webhook_in_falconadmissions.yaml #- path: patches/webhook_in_falconcontainers.yaml #- path: patches/webhook_in_falconnodesensors.yaml +#- path: patches/webhook_in_falconimages.yaml #+kubebuilder:scaffold:crdkustomizewebhookpatch # [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix. @@ -20,6 +22,7 @@ patches: #- path: patches/cainjection_in_falconadmissions.yaml #- path: patches/cainjection_in_falconcontainers.yaml #- path: patches/cainjection_in_falconnodesensors.yaml +#- path: patches/cainjection_in_falconimages.yaml #+kubebuilder:scaffold:crdkustomizecainjectionpatch # the following config is for teaching kustomize how to do kustomization for CRDs. diff --git a/config/crd/patches/cainjection_in_falcon_falconimages.yaml b/config/crd/patches/cainjection_in_falcon_falconimages.yaml new file mode 100644 index 00000000..398a45ab --- /dev/null +++ b/config/crd/patches/cainjection_in_falcon_falconimages.yaml @@ -0,0 +1,7 @@ +# The following patch adds a directive for certmanager to inject CA into the CRD +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + cert-manager.io/inject-ca-from: CERTIFICATE_NAMESPACE/CERTIFICATE_NAME + name: falconimages.falcon.crowdstrike.com diff --git a/config/crd/patches/webhook_in_falcon_falconimages.yaml b/config/crd/patches/webhook_in_falcon_falconimages.yaml new file mode 100644 index 00000000..b62ab3e8 --- /dev/null +++ b/config/crd/patches/webhook_in_falcon_falconimages.yaml @@ -0,0 +1,16 @@ +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: falconimages.falcon.crowdstrike.com +spec: + conversion: + strategy: Webhook + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert + conversionReviewVersions: + - v1 diff --git a/config/rbac/falcon_falconimage_editor_role.yaml b/config/rbac/falcon_falconimage_editor_role.yaml new file mode 100644 index 00000000..cd8e65e1 --- /dev/null +++ b/config/rbac/falcon_falconimage_editor_role.yaml @@ -0,0 +1,31 @@ +# permissions for end users to edit falconimages. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: clusterrole + app.kubernetes.io/instance: falconimage-editor-role + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: falcon-operator + app.kubernetes.io/part-of: falcon-operator + app.kubernetes.io/managed-by: kustomize + name: falconimage-editor-role +rules: +- apiGroups: + - falcon.crowdstrike.com + resources: + - falconimages + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - falcon.crowdstrike.com + resources: + - falconimages/status + verbs: + - get diff --git a/config/rbac/falcon_falconimage_viewer_role.yaml b/config/rbac/falcon_falconimage_viewer_role.yaml new file mode 100644 index 00000000..b7e02989 --- /dev/null +++ b/config/rbac/falcon_falconimage_viewer_role.yaml @@ -0,0 +1,27 @@ +# permissions for end users to view falconimages. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: clusterrole + app.kubernetes.io/instance: falconimage-viewer-role + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: falcon-operator + app.kubernetes.io/part-of: falcon-operator + app.kubernetes.io/managed-by: kustomize + name: falconimage-viewer-role +rules: +- apiGroups: + - falcon.crowdstrike.com + resources: + - falconimages + verbs: + - get + - list + - watch +- apiGroups: + - falcon.crowdstrike.com + resources: + - falconimages/status + verbs: + - get diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 8064fddb..53a76769 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -222,6 +222,32 @@ rules: - get - patch - update +- apiGroups: + - falcon.crowdstrike.com + resources: + - falconimages + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - falcon.crowdstrike.com + resources: + - falconimages/finalizers + verbs: + - update +- apiGroups: + - falcon.crowdstrike.com + resources: + - falconimages/status + verbs: + - get + - patch + - update - apiGroups: - falcon.crowdstrike.com resources: diff --git a/config/samples/falcon_v1alpha1_falconimage.yaml b/config/samples/falcon_v1alpha1_falconimage.yaml new file mode 100644 index 00000000..da59166f --- /dev/null +++ b/config/samples/falcon_v1alpha1_falconimage.yaml @@ -0,0 +1,12 @@ +apiVersion: falcon.crowdstrike.com/v1alpha1 +kind: FalconImage +metadata: + labels: + app.kubernetes.io/name: falconimage + app.kubernetes.io/instance: falconimage-sample + app.kubernetes.io/part-of: falcon-operator + app.kubernetes.io/managed-by: kustomize + app.kubernetes.io/created-by: falcon-operator + name: falconimage-sample +spec: + # TODO(user): Add fields here diff --git a/config/samples/kustomization.yaml b/config/samples/kustomization.yaml index c7e6491c..8d0d6bb6 100644 --- a/config/samples/kustomization.yaml +++ b/config/samples/kustomization.yaml @@ -3,4 +3,5 @@ resources: - falcon_v1alpha1_falconadmission.yaml - falcon_v1alpha1_falconcontainer.yaml - falcon_v1alpha1_falconnodesensor.yaml +- falcon_v1alpha1_falconimage.yaml #+kubebuilder:scaffold:manifestskustomizesamples diff --git a/deploy/falcon-operator.yaml b/deploy/falcon-operator.yaml index 1567f09b..417bf509 100644 --- a/deploy/falcon-operator.yaml +++ b/deploy/falcon-operator.yaml @@ -2568,6 +2568,55 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.12.0 + name: falconimages.falcon.crowdstrike.com +spec: + group: falcon.crowdstrike.com + names: + kind: FalconImage + listKind: FalconImageList + plural: falconimages + singular: falconimage + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: FalconImage is the Schema for the falconimages 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: + description: FalconImageSpec defines the desired state of FalconImage + properties: + foo: + description: Foo is an example field of FalconImage. Edit falconimage_types.go + to remove/update + type: string + type: object + status: + description: FalconImageStatus defines the observed state of FalconImage + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.12.0 @@ -3567,6 +3616,32 @@ rules: - get - patch - update +- apiGroups: + - falcon.crowdstrike.com + resources: + - falconimages + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - falcon.crowdstrike.com + resources: + - falconimages/finalizers + verbs: + - update +- apiGroups: + - falcon.crowdstrike.com + resources: + - falconimages/status + verbs: + - get + - patch + - update - apiGroups: - falcon.crowdstrike.com resources: diff --git a/internal/controller/falcon_image/falconimage_controller.go b/internal/controller/falcon_image/falconimage_controller.go new file mode 100644 index 00000000..e72cc824 --- /dev/null +++ b/internal/controller/falcon_image/falconimage_controller.go @@ -0,0 +1,46 @@ +package falcon + +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/log" + + falconv1alpha1 "github.com/crowdstrike/falcon-operator/api/falcon/v1alpha1" +) + +// FalconImageReconciler reconciles a FalconImage object +type FalconImageReconciler struct { + client.Client + Scheme *runtime.Scheme +} + +//+kubebuilder:rbac:groups=falcon.crowdstrike.com,resources=falconimages,verbs=get;list;watch;create;update;patch;delete +//+kubebuilder:rbac:groups=falcon.crowdstrike.com,resources=falconimages/status,verbs=get;update;patch +//+kubebuilder:rbac:groups=falcon.crowdstrike.com,resources=falconimages/finalizers,verbs=update + +// Reconcile is part of the main kubernetes reconciliation loop which aims to +// move the current state of the cluster closer to the desired state. +// TODO(user): Modify the Reconcile function to compare the state specified by +// the FalconImage object against the actual cluster state, and then +// perform operations to make the cluster state reflect the state specified by +// the user. +// +// For more details, check Reconcile and its Result here: +// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.15.0/pkg/reconcile +func (r *FalconImageReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + _ = log.FromContext(ctx) + + // TODO(user): your logic here + + return ctrl.Result{}, nil +} + +// SetupWithManager sets up the controller with the Manager. +func (r *FalconImageReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&falconv1alpha1.FalconImage{}). + Complete(r) +} diff --git a/internal/controller/falcon_image/suite_test.go b/internal/controller/falcon_image/suite_test.go new file mode 100644 index 00000000..706c1b69 --- /dev/null +++ b/internal/controller/falcon_image/suite_test.go @@ -0,0 +1,269 @@ +/* + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright The Falcon Operator Authors. + + 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 + + https://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 falcon + +import ( + "path/filepath" + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/envtest" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/log/zap" + + falconv1alpha1 "github.com/crowdstrike/falcon-operator/api/falcon/v1alpha1" + //+kubebuilder:scaffold:imports +) + +// These tests use Ginkgo (BDD-style Go testing framework). Refer to +// http://onsi.github.io/ginkgo/ to learn more about Ginkgo. + +var cfg *rest.Config +var k8sClient client.Client +var testEnv *envtest.Environment + +func TestControllers(t *testing.T) { + RegisterFailHandler(Fail) + + RunSpecs(t, "Controller Suite") +} + +var _ = BeforeSuite(func() { + logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) + + By("bootstrapping test environment") + testEnv = &envtest.Environment{ + CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, + ErrorIfCRDPathMissing: true, + } + + var err error + // cfg is defined in this file globally. + cfg, err = testEnv.Start() + Expect(err).NotTo(HaveOccurred()) + Expect(cfg).NotTo(BeNil()) + + err = falconv1alpha1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + //+kubebuilder:scaffold:scheme + + k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) + Expect(err).NotTo(HaveOccurred()) + Expect(k8sClient).NotTo(BeNil()) + +}) + +var _ = AfterSuite(func() { + By("tearing down the test environment") + err := testEnv.Stop() + Expect(err).NotTo(HaveOccurred()) +})