diff --git a/docs/content/en/docs/crd-ref/lifecycle/v1alpha3/_index.md b/docs/content/en/docs/crd-ref/lifecycle/v1alpha3/_index.md index ad2f234e3a..271e40457e 100644 --- a/docs/content/en/docs/crd-ref/lifecycle/v1alpha3/_index.md +++ b/docs/content/en/docs/crd-ref/lifecycle/v1alpha3/_index.md @@ -14,6 +14,8 @@ Package v1alpha3 contains API Schema definitions for the lifecycle v1alpha3 API ### Resource Types - [KeptnApp](#keptnapp) +- [KeptnAppCreationRequest](#keptnappcreationrequest) +- [KeptnAppCreationRequestList](#keptnappcreationrequestlist) - [KeptnAppList](#keptnapplist) - [KeptnAppVersion](#keptnappversion) - [KeptnAppVersionList](#keptnappversionlist) @@ -175,6 +177,55 @@ _Appears in:_ | `spec` _[KeptnAppSpec](#keptnappspec)_ | | +#### KeptnAppCreationRequest + + + +KeptnAppCreationRequest is the Schema for the keptnappcreationrequests API + +_Appears in:_ +- [KeptnAppCreationRequestList](#keptnappcreationrequestlist) + +| Field | Description | +| --- | --- | +| `apiVersion` _string_ | `lifecycle.keptn.sh/v1alpha3` +| `kind` _string_ | `KeptnAppCreationRequest` +| `metadata` _[ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#objectmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. | +| `spec` _[KeptnAppCreationRequestSpec](#keptnappcreationrequestspec)_ | | + + +#### KeptnAppCreationRequestList + + + +KeptnAppCreationRequestList contains a list of KeptnAppCreationRequest + + + +| Field | Description | +| --- | --- | +| `apiVersion` _string_ | `lifecycle.keptn.sh/v1alpha3` +| `kind` _string_ | `KeptnAppCreationRequestList` +| `metadata` _[ListMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#listmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. | +| `items` _[KeptnAppCreationRequest](#keptnappcreationrequest) array_ | | + + +#### KeptnAppCreationRequestSpec + + + +KeptnAppCreationRequestSpec defines the desired state of KeptnAppCreationRequest + +_Appears in:_ +- [KeptnAppCreationRequest](#keptnappcreationrequest) + +| Field | Description | +| --- | --- | +| `appName` _string_ | AppName is the name of the KeptnApp the KeptnAppCreationRequest should create if no user-defined object with that name is found. | + + + + #### KeptnAppList diff --git a/helm/chart/README.md b/helm/chart/README.md index f459266109..aa4d068a84 100644 --- a/helm/chart/README.md +++ b/helm/chart/README.md @@ -80,6 +80,7 @@ checks | `lifecycleOperator.manager.containerSecurityContext.runAsUser` | | `65532` | | `lifecycleOperator.manager.containerSecurityContext.seccompProfile.type` | | `RuntimeDefault` | | `lifecycleOperator.manager.env.keptnAppControllerLogLevel` | sets the log level of Keptn App Controller | `0` | +| `lifecycleOperator.manager.env.keptnAppCreationRequestControllerLogLevel` | sets the log level of Keptn App Creation Request Controller | `0` | | `lifecycleOperator.manager.env.keptnAppVersionControllerLogLevel` | sets the log level of Keptn AppVersion Controller | `0` | | `lifecycleOperator.manager.env.keptnEvaluationControllerLogLevel` | sets the log level of Keptn Evaluation Controller | `0` | | `lifecycleOperator.manager.env.keptnTaskControllerLogLevel` | sets the log level of Keptn Task Controller | `0` | diff --git a/helm/chart/doc.yaml b/helm/chart/doc.yaml index 21ffc56149..11687c8b15 100644 --- a/helm/chart/doc.yaml +++ b/helm/chart/doc.yaml @@ -118,6 +118,7 @@ ## @param lifecycleOperator.manager.containerSecurityContext.seccompProfile.type ## @param lifecycleOperator.manager.env.keptnAppControllerLogLevel sets the log level of Keptn App Controller +## @param lifecycleOperator.manager.env.keptnAppCreationRequestControllerLogLevel sets the log level of Keptn App Creation Request Controller ## @param lifecycleOperator.manager.env.keptnAppVersionControllerLogLevel sets the log level of Keptn AppVersion Controller ## @param lifecycleOperator.manager.env.keptnEvaluationControllerLogLevel sets the log level of Keptn Evaluation Controller ## @param lifecycleOperator.manager.env.keptnTaskControllerLogLevel sets the log level of Keptn Task Controller diff --git a/helm/chart/values.yaml b/helm/chart/values.yaml index 32a4dedbd5..01e663f335 100644 --- a/helm/chart/values.yaml +++ b/helm/chart/values.yaml @@ -66,6 +66,7 @@ lifecycleOperator: env: functionRunnerImage: ghcr.keptn.sh/keptn/functions-runtime:v0.7.0 keptnAppControllerLogLevel: "0" + keptnAppCreationRequestControllerLogLevel: "0" keptnAppVersionControllerLogLevel: "0" keptnEvaluationControllerLogLevel: "0" keptnTaskControllerLogLevel: "0" diff --git a/operator/PROJECT b/operator/PROJECT index 6c3ec1efaf..5e2a1e5003 100644 --- a/operator/PROJECT +++ b/operator/PROJECT @@ -258,4 +258,13 @@ resources: kind: KeptnEvaluationProvider path: github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3 version: v1alpha3 +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: keptn.sh + group: lifecycle + kind: KeptnAppCreationRequest + path: github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3 + version: v1alpha3 version: "3" diff --git a/operator/apis/lifecycle/v1alpha3/keptnappcreationrequest_types.go b/operator/apis/lifecycle/v1alpha3/keptnappcreationrequest_types.go new file mode 100644 index 0000000000..4eb0811844 --- /dev/null +++ b/operator/apis/lifecycle/v1alpha3/keptnappcreationrequest_types.go @@ -0,0 +1,61 @@ +/* +Copyright 2022. + +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 v1alpha3 + +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. + +// KeptnAppCreationRequestSpec defines the desired state of KeptnAppCreationRequest +type KeptnAppCreationRequestSpec struct { + // AppName is the name of the KeptnApp the KeptnAppCreationRequest should create if no user-defined object with that name is found. + AppName string `json:"appName"` +} + +// KeptnAppCreationRequestStatus defines the observed state of KeptnAppCreationRequest +type KeptnAppCreationRequestStatus 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 + +// KeptnAppCreationRequest is the Schema for the keptnappcreationrequests API +type KeptnAppCreationRequest struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec KeptnAppCreationRequestSpec `json:"spec,omitempty"` + Status KeptnAppCreationRequestStatus `json:"status,omitempty"` +} + +//+kubebuilder:object:root=true + +// KeptnAppCreationRequestList contains a list of KeptnAppCreationRequest +type KeptnAppCreationRequestList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []KeptnAppCreationRequest `json:"items"` +} + +func init() { + SchemeBuilder.Register(&KeptnAppCreationRequest{}, &KeptnAppCreationRequestList{}) +} diff --git a/operator/apis/lifecycle/v1alpha3/zz_generated.deepcopy.go b/operator/apis/lifecycle/v1alpha3/zz_generated.deepcopy.go index 4d6c1ecc81..7ee7cd41e2 100644 --- a/operator/apis/lifecycle/v1alpha3/zz_generated.deepcopy.go +++ b/operator/apis/lifecycle/v1alpha3/zz_generated.deepcopy.go @@ -197,6 +197,95 @@ func (in *KeptnApp) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KeptnAppCreationRequest) DeepCopyInto(out *KeptnAppCreationRequest) { + *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 KeptnAppCreationRequest. +func (in *KeptnAppCreationRequest) DeepCopy() *KeptnAppCreationRequest { + if in == nil { + return nil + } + out := new(KeptnAppCreationRequest) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KeptnAppCreationRequest) 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 *KeptnAppCreationRequestList) DeepCopyInto(out *KeptnAppCreationRequestList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]KeptnAppCreationRequest, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KeptnAppCreationRequestList. +func (in *KeptnAppCreationRequestList) DeepCopy() *KeptnAppCreationRequestList { + if in == nil { + return nil + } + out := new(KeptnAppCreationRequestList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KeptnAppCreationRequestList) 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 *KeptnAppCreationRequestSpec) DeepCopyInto(out *KeptnAppCreationRequestSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KeptnAppCreationRequestSpec. +func (in *KeptnAppCreationRequestSpec) DeepCopy() *KeptnAppCreationRequestSpec { + if in == nil { + return nil + } + out := new(KeptnAppCreationRequestSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KeptnAppCreationRequestStatus) DeepCopyInto(out *KeptnAppCreationRequestStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KeptnAppCreationRequestStatus. +func (in *KeptnAppCreationRequestStatus) DeepCopy() *KeptnAppCreationRequestStatus { + if in == nil { + return nil + } + out := new(KeptnAppCreationRequestStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *KeptnAppList) DeepCopyInto(out *KeptnAppList) { *out = *in diff --git a/operator/config/crd/bases/lifecycle.keptn.sh_keptnappcreationrequests.yaml b/operator/config/crd/bases/lifecycle.keptn.sh_keptnappcreationrequests.yaml new file mode 100644 index 0000000000..c0930ef75a --- /dev/null +++ b/operator/config/crd/bases/lifecycle.keptn.sh_keptnappcreationrequests.yaml @@ -0,0 +1,55 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.11.3 + creationTimestamp: null + name: keptnappcreationrequests.lifecycle.keptn.sh +spec: + group: lifecycle.keptn.sh + names: + kind: KeptnAppCreationRequest + listKind: KeptnAppCreationRequestList + plural: keptnappcreationrequests + singular: keptnappcreationrequest + scope: Namespaced + versions: + - name: v1alpha3 + schema: + openAPIV3Schema: + description: KeptnAppCreationRequest is the Schema for the keptnappcreationrequests + 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: KeptnAppCreationRequestSpec defines the desired state of + KeptnAppCreationRequest + properties: + appName: + description: AppName is the name of the KeptnApp the KeptnAppCreationRequest + should create if no user-defined object with that name is found. + type: string + required: + - appName + type: object + status: + description: KeptnAppCreationRequestStatus defines the observed state + of KeptnAppCreationRequest + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/operator/config/crd/kustomization.yaml b/operator/config/crd/kustomization.yaml index d8607bd6e4..a7c0b7e0b8 100644 --- a/operator/config/crd/kustomization.yaml +++ b/operator/config/crd/kustomization.yaml @@ -12,6 +12,7 @@ resources: - bases/lifecycle.keptn.sh_keptnevaluationproviders.yaml - bases/lifecycle.keptn.sh_keptnevaluations.yaml - bases/options.keptn.sh_keptnconfigs.yaml +- bases/lifecycle.keptn.sh_keptnappcreationrequests.yaml #+kubebuilder:scaffold:crdkustomizeresource patchesStrategicMerge: @@ -31,6 +32,7 @@ patchesStrategicMerge: #- patches/webhook_in_lifecycle_keptnappversions.yaml #- patches/webhook_in_lifecycle_keptnworkloadinstances.yaml #- patches/webhook_in_lifecycle_keptnevaluationproviders.yaml +#- patches/webhook_in_keptnappcreationrequests.yaml #+kubebuilder:scaffold:crdkustomizewebhookpatch # the following config is for teaching kustomize how to do kustomization for CRDs. diff --git a/operator/config/crd/patches/webhook_in_lifecycle_keptnappcreationrequests.yaml b/operator/config/crd/patches/webhook_in_lifecycle_keptnappcreationrequests.yaml new file mode 100644 index 0000000000..fb68a5908b --- /dev/null +++ b/operator/config/crd/patches/webhook_in_lifecycle_keptnappcreationrequests.yaml @@ -0,0 +1,16 @@ +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: keptnappcreationrequests.lifecycle.keptn.sh +spec: + conversion: + strategy: Webhook + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert + conversionReviewVersions: + - v1 diff --git a/operator/config/manager/manager.yaml b/operator/config/manager/manager.yaml index 24b5b52f79..ff2a30393f 100644 --- a/operator/config/manager/manager.yaml +++ b/operator/config/manager/manager.yaml @@ -73,6 +73,8 @@ spec: value: otel-collector:4317 - name: KEPTN_APP_CONTROLLER_LOG_LEVEL value: "0" + - name: KEPTN_APP_CREATION_REQUEST_CONTROLLER_LOG_LEVEL + value: "0" - name: KEPTN_APP_VERSION_CONTROLLER_LOG_LEVEL value: "0" - name: KEPTN_EVALUATION_CONTROLLER_LOG_LEVEL diff --git a/operator/config/rbac/lifecycle_keptnappcreationrequest_editor_role.yaml b/operator/config/rbac/lifecycle_keptnappcreationrequest_editor_role.yaml new file mode 100644 index 0000000000..675405d4a9 --- /dev/null +++ b/operator/config/rbac/lifecycle_keptnappcreationrequest_editor_role.yaml @@ -0,0 +1,31 @@ +# permissions for end users to edit keptnappcreationrequests. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: clusterrole + app.kubernetes.io/instance: keptnappcreationrequest-editor-role + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: keptn-lifecycle-toolkit + app.kubernetes.io/part-of: keptn-lifecycle-toolkit + app.kubernetes.io/managed-by: kustomize + name: keptnappcreationrequest-editor-role +rules: +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnappcreationrequests + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnappcreationrequests/status + verbs: + - get diff --git a/operator/config/rbac/lifecycle_keptnappcreationrequest_viewer_role.yaml b/operator/config/rbac/lifecycle_keptnappcreationrequest_viewer_role.yaml new file mode 100644 index 0000000000..5e01a264eb --- /dev/null +++ b/operator/config/rbac/lifecycle_keptnappcreationrequest_viewer_role.yaml @@ -0,0 +1,27 @@ +# permissions for end users to view keptnappcreationrequests. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: clusterrole + app.kubernetes.io/instance: keptnappcreationrequest-viewer-role + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: keptn-lifecycle-toolkit + app.kubernetes.io/part-of: keptn-lifecycle-toolkit + app.kubernetes.io/managed-by: kustomize + name: keptnappcreationrequest-viewer-role +rules: +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnappcreationrequests + verbs: + - get + - list + - watch +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnappcreationrequests/status + verbs: + - get diff --git a/operator/config/rbac/role.yaml b/operator/config/rbac/role.yaml index 58f727d947..9deb085059 100644 --- a/operator/config/rbac/role.yaml +++ b/operator/config/rbac/role.yaml @@ -85,6 +85,32 @@ rules: - secrets verbs: - get +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnappcreationrequests + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnappcreationrequests/finalizers + verbs: + - update +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnappcreationrequests/status + verbs: + - get + - patch + - update - apiGroups: - lifecycle.keptn.sh resources: diff --git a/operator/config/samples/lifecycle_v1alpha3_keptnappcreationrequest.yaml b/operator/config/samples/lifecycle_v1alpha3_keptnappcreationrequest.yaml new file mode 100644 index 0000000000..3bda2955d9 --- /dev/null +++ b/operator/config/samples/lifecycle_v1alpha3_keptnappcreationrequest.yaml @@ -0,0 +1,12 @@ +apiVersion: lifecycle.keptn.sh/v1alpha3 +kind: KeptnAppCreationRequest +metadata: + labels: + app.kubernetes.io/name: keptnappcreationrequest + app.kubernetes.io/instance: keptnappcreationrequest-sample + app.kubernetes.io/part-of: keptn-lifecycle-toolkit + app.kubernetes.io/managed-by: kustomize + app.kubernetes.io/created-by: keptn-lifecycle-toolkit + name: keptnappcreationrequest-sample +spec: + appName: my-app diff --git a/operator/controllers/lifecycle/keptnappcreationrequest/controller.go b/operator/controllers/lifecycle/keptnappcreationrequest/controller.go new file mode 100644 index 0000000000..e8d9fcab6b --- /dev/null +++ b/operator/controllers/lifecycle/keptnappcreationrequest/controller.go @@ -0,0 +1,57 @@ +/* +Copyright 2022. + +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 keptnappcreationrequest + +import ( + "context" + + "github.com/go-logr/logr" + lifecyclev1alpha3 "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3" + "k8s.io/apimachinery/pkg/runtime" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +// KeptnAppCreationRequestReconciler reconciles a KeptnAppCreationRequest object +type KeptnAppCreationRequestReconciler struct { + client.Client + Scheme *runtime.Scheme + Log logr.Logger +} + +//+kubebuilder:rbac:groups=lifecycle.keptn.sh,resources=keptnappcreationrequests,verbs=get;list;watch;create;update;patch;delete +//+kubebuilder:rbac:groups=lifecycle.keptn.sh,resources=keptnappcreationrequests/status,verbs=get;update;patch +//+kubebuilder:rbac:groups=lifecycle.keptn.sh,resources=keptnappcreationrequests/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. +// the KeptnAppCreationRequest 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.14.1/pkg/reconcile +func (r *KeptnAppCreationRequestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + return ctrl.Result{}, nil +} + +// SetupWithManager sets up the controller with the Manager. +func (r *KeptnAppCreationRequestReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&lifecyclev1alpha3.KeptnAppCreationRequest{}). + Complete(r) +} diff --git a/operator/controllers/lifecycle/keptnappcreationrequest/controller_test.go b/operator/controllers/lifecycle/keptnappcreationrequest/controller_test.go new file mode 100644 index 0000000000..1a980c1890 --- /dev/null +++ b/operator/controllers/lifecycle/keptnappcreationrequest/controller_test.go @@ -0,0 +1,49 @@ +package keptnappcreationrequest + +import ( + "context" + "testing" + + "github.com/go-logr/logr" + klcv1alpha3 "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3" + "github.com/stretchr/testify/require" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + controllerruntime "sigs.k8s.io/controller-runtime" + k8sfake "sigs.k8s.io/controller-runtime/pkg/client/fake" +) + +func TestKeptnAppCreationRequestReconciler_Reconcile(t *testing.T) { + fakeClient := k8sfake.NewClientBuilder().WithObjects().Build() + + err := klcv1alpha3.AddToScheme(fakeClient.Scheme()) + require.Nil(t, err) + + kacr := &klcv1alpha3.KeptnAppCreationRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-kacr", + Namespace: "my-namespace", + }, + Spec: klcv1alpha3.KeptnAppCreationRequestSpec{ + AppName: "my-app", + }, + } + + err = fakeClient.Create(context.TODO(), kacr) + require.Nil(t, err) + + r := &KeptnAppCreationRequestReconciler{ + Client: fakeClient, + Scheme: fakeClient.Scheme(), + Log: logr.Logger{}, + } + + _, err = r.Reconcile(context.Background(), controllerruntime.Request{ + NamespacedName: types.NamespacedName{ + Namespace: kacr.Namespace, + Name: kacr.Name, + }, + }) + + require.Nil(t, err) +} diff --git a/operator/main.go b/operator/main.go index cdd6d104b2..d11dc1b427 100644 --- a/operator/main.go +++ b/operator/main.go @@ -33,6 +33,7 @@ import ( "github.com/keptn/lifecycle-toolkit/operator/cmd/webhook" controllercommon "github.com/keptn/lifecycle-toolkit/operator/controllers/common" "github.com/keptn/lifecycle-toolkit/operator/controllers/lifecycle/keptnapp" + "github.com/keptn/lifecycle-toolkit/operator/controllers/lifecycle/keptnappcreationrequest" "github.com/keptn/lifecycle-toolkit/operator/controllers/lifecycle/keptnappversion" "github.com/keptn/lifecycle-toolkit/operator/controllers/lifecycle/keptnevaluation" "github.com/keptn/lifecycle-toolkit/operator/controllers/lifecycle/keptntask" @@ -72,14 +73,15 @@ type envConfig struct { PodNamespace string `envconfig:"POD_NAMESPACE" default:""` PodName string `envconfig:"POD_NAME" default:""` - KeptnAppControllerLogLevel int `envconfig:"KEPTN_APP_CONTROLLER_LOG_LEVEL" default:"0"` - KeptnAppVersionControllerLogLevel int `envconfig:"KEPTN_APP_VERSION_CONTROLLER_LOG_LEVEL" default:"0"` - KeptnEvaluationControllerLogLevel int `envconfig:"KEPTN_EVALUATION_CONTROLLER_LOG_LEVEL" default:"0"` - KeptnTaskControllerLogLevel int `envconfig:"KEPTN_TASK_CONTROLLER_LOG_LEVEL" default:"0"` - KeptnTaskDefinitionControllerLogLevel int `envconfig:"KEPTN_TASK_DEFINITION_CONTROLLER_LOG_LEVEL" default:"0"` - KeptnWorkloadControllerLogLevel int `envconfig:"KEPTN_WORKLOAD_CONTROLLER_LOG_LEVEL" default:"0"` - KeptnWorkloadInstanceControllerLogLevel int `envconfig:"KEPTN_WORKLOAD_INSTANCE_CONTROLLER_LOG_LEVEL" default:"0"` - KeptnOptionsControllerLogLevel int `envconfig:"OPTIONS_CONTROLLER_LOG_LEVEL" default:"0"` + KeptnAppControllerLogLevel int `envconfig:"KEPTN_APP_CONTROLLER_LOG_LEVEL" default:"0"` + KeptnAppCreationRequestControllerLogLevel int `envconfig:"KEPTN_APP_CREATION_REQUEST_CONTROLLER_LOG_LEVEL" default:"0"` + KeptnAppVersionControllerLogLevel int `envconfig:"KEPTN_APP_VERSION_CONTROLLER_LOG_LEVEL" default:"0"` + KeptnEvaluationControllerLogLevel int `envconfig:"KEPTN_EVALUATION_CONTROLLER_LOG_LEVEL" default:"0"` + KeptnTaskControllerLogLevel int `envconfig:"KEPTN_TASK_CONTROLLER_LOG_LEVEL" default:"0"` + KeptnTaskDefinitionControllerLogLevel int `envconfig:"KEPTN_TASK_DEFINITION_CONTROLLER_LOG_LEVEL" default:"0"` + KeptnWorkloadControllerLogLevel int `envconfig:"KEPTN_WORKLOAD_CONTROLLER_LOG_LEVEL" default:"0"` + KeptnWorkloadInstanceControllerLogLevel int `envconfig:"KEPTN_WORKLOAD_INSTANCE_CONTROLLER_LOG_LEVEL" default:"0"` + KeptnOptionsControllerLogLevel int `envconfig:"OPTIONS_CONTROLLER_LOG_LEVEL" default:"0"` KeptnOptionsCollectorURL string `envconfig:"OTEL_COLLECTOR_URL" default:""` } @@ -201,6 +203,17 @@ func main() { os.Exit(1) } + appCreationRequestLogger := ctrl.Log.WithName("KeptnAppCreationRequest Controller") + appCreationRequestReconciler := &keptnappcreationrequest.KeptnAppCreationRequestReconciler{ + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + Log: appCreationRequestLogger.V(env.KeptnAppCreationRequestControllerLogLevel), + } + if err := appCreationRequestReconciler.SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "KeptnAppCreationRequest") + os.Exit(1) + } + workloadLogger := ctrl.Log.WithName("KeptnWorkload Controller") workloadReconciler := &keptnworkload.KeptnWorkloadReconciler{ Client: mgr.GetClient(), diff --git a/test/integration/app-creation-request/00-assert.yaml b/test/integration/app-creation-request/00-assert.yaml new file mode 100644 index 0000000000..3bb778d462 --- /dev/null +++ b/test/integration/app-creation-request/00-assert.yaml @@ -0,0 +1,6 @@ +apiVersion: lifecycle.keptn.sh/v1alpha3 +kind: KeptnAppCreationRequest +metadata: + name: my-kacr +spec: + appName: my-app diff --git a/test/integration/app-creation-request/00-install.yaml b/test/integration/app-creation-request/00-install.yaml new file mode 100644 index 0000000000..3bb778d462 --- /dev/null +++ b/test/integration/app-creation-request/00-install.yaml @@ -0,0 +1,6 @@ +apiVersion: lifecycle.keptn.sh/v1alpha3 +kind: KeptnAppCreationRequest +metadata: + name: my-kacr +spec: + appName: my-app