-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Abdul Hameed <[email protected]>
- Loading branch information
1 parent
7be6b71
commit e2b0b8f
Showing
2 changed files
with
197 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 196 additions & 0 deletions
196
infra/feast-operator/internal/controller/featurestore_controller_loglevel_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
/* | ||
Copyright 2024 Feast Community. | ||
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 controller | ||
|
||
import ( | ||
"context" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
appsv1 "k8s.io/api/apps/v1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
apimeta "k8s.io/apimachinery/pkg/api/meta" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
|
||
"github.com/feast-dev/feast/infra/feast-operator/api/feastversion" | ||
feastdevv1alpha1 "github.com/feast-dev/feast/infra/feast-operator/api/v1alpha1" | ||
"github.com/feast-dev/feast/infra/feast-operator/internal/controller/handler" | ||
"github.com/feast-dev/feast/infra/feast-operator/internal/controller/services" | ||
) | ||
|
||
var _ = Describe("FeatureStore Controller - Feast service LogLevel", func() { | ||
Context("When reconciling a FeatureStore resource", func() { | ||
const resourceName = "test-loglevel" | ||
|
||
ctx := context.Background() | ||
|
||
typeNamespacedName := types.NamespacedName{ | ||
Name: resourceName, | ||
Namespace: "default", | ||
} | ||
featurestore := &feastdevv1alpha1.FeatureStore{} | ||
|
||
BeforeEach(func() { | ||
By("creating the custom resource for the Kind FeatureStore") | ||
err := k8sClient.Get(ctx, typeNamespacedName, featurestore) | ||
if err != nil && errors.IsNotFound(err) { | ||
resource := &feastdevv1alpha1.FeatureStore{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: resourceName, | ||
Namespace: "default", | ||
}, | ||
Spec: feastdevv1alpha1.FeatureStoreSpec{ | ||
FeastProject: feastProject, | ||
Services: &feastdevv1alpha1.FeatureStoreServices{ | ||
Registry: &feastdevv1alpha1.Registry{ | ||
Local: &feastdevv1alpha1.LocalRegistryConfig{}, | ||
}, | ||
OnlineStore: &feastdevv1alpha1.OnlineStore{ | ||
LogLevel: "debug", | ||
}, | ||
OfflineStore: &feastdevv1alpha1.OfflineStore{ | ||
LogLevel: "info", | ||
}, | ||
}, | ||
}, | ||
} | ||
Expect(k8sClient.Create(ctx, resource)).To(Succeed()) | ||
} | ||
}) | ||
AfterEach(func() { | ||
resource := &feastdevv1alpha1.FeatureStore{} | ||
err := k8sClient.Get(ctx, typeNamespacedName, resource) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("Cleanup the specific resource instance FeatureStore") | ||
Expect(k8sClient.Delete(ctx, resource)).To(Succeed()) | ||
}) | ||
|
||
It("should successfully reconcile the resource", func() { | ||
By("Reconciling the created resource") | ||
controllerReconciler := &FeatureStoreReconciler{ | ||
Client: k8sClient, | ||
Scheme: k8sClient.Scheme(), | ||
} | ||
|
||
_, err := controllerReconciler.Reconcile(ctx, reconcile.Request{ | ||
NamespacedName: typeNamespacedName, | ||
}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
resource := &feastdevv1alpha1.FeatureStore{} | ||
err = k8sClient.Get(ctx, typeNamespacedName, resource) | ||
Expect(err).NotTo(HaveOccurred()) | ||
feast := services.FeastServices{ | ||
Handler: handler.FeastHandler{ | ||
Client: controllerReconciler.Client, | ||
Context: ctx, | ||
Scheme: controllerReconciler.Scheme, | ||
FeatureStore: resource, | ||
}, | ||
} | ||
|
||
Expect(resource.Status).NotTo(BeNil()) | ||
Expect(resource.Status.FeastVersion).To(Equal(feastversion.FeastVersion)) | ||
Expect(resource.Status.Applied.FeastProject).To(Equal(resource.Spec.FeastProject)) | ||
Expect(resource.Status.Applied.Services).NotTo(BeNil()) | ||
Expect(resource.Status.Applied.Services.OfflineStore).NotTo(BeNil()) | ||
Expect(resource.Status.Applied.Services.OnlineStore).NotTo(BeNil()) | ||
Expect(resource.Status.Applied.Services.Registry).NotTo(BeNil()) | ||
|
||
Expect(resource.Status.Conditions).NotTo(BeEmpty()) | ||
cond := apimeta.FindStatusCondition(resource.Status.Conditions, feastdevv1alpha1.ReadyType) | ||
Expect(cond).ToNot(BeNil()) | ||
Expect(cond.Status).To(Equal(metav1.ConditionTrue)) | ||
Expect(cond.Reason).To(Equal(feastdevv1alpha1.ReadyReason)) | ||
Expect(cond.Type).To(Equal(feastdevv1alpha1.ReadyType)) | ||
Expect(cond.Message).To(Equal(feastdevv1alpha1.ReadyMessage)) | ||
|
||
cond = apimeta.FindStatusCondition(resource.Status.Conditions, feastdevv1alpha1.RegistryReadyType) | ||
Expect(cond).ToNot(BeNil()) | ||
Expect(cond.Status).To(Equal(metav1.ConditionTrue)) | ||
Expect(cond.Reason).To(Equal(feastdevv1alpha1.ReadyReason)) | ||
Expect(cond.Type).To(Equal(feastdevv1alpha1.RegistryReadyType)) | ||
Expect(cond.Message).To(Equal(feastdevv1alpha1.RegistryReadyMessage)) | ||
|
||
cond = apimeta.FindStatusCondition(resource.Status.Conditions, feastdevv1alpha1.ClientReadyType) | ||
Expect(cond).ToNot(BeNil()) | ||
Expect(cond.Status).To(Equal(metav1.ConditionTrue)) | ||
Expect(cond.Reason).To(Equal(feastdevv1alpha1.ReadyReason)) | ||
Expect(cond.Type).To(Equal(feastdevv1alpha1.ClientReadyType)) | ||
Expect(cond.Message).To(Equal(feastdevv1alpha1.ClientReadyMessage)) | ||
|
||
cond = apimeta.FindStatusCondition(resource.Status.Conditions, feastdevv1alpha1.OfflineStoreReadyType) | ||
Expect(cond).ToNot(BeNil()) | ||
Expect(cond.Status).To(Equal(metav1.ConditionTrue)) | ||
Expect(cond.Reason).To(Equal(feastdevv1alpha1.ReadyReason)) | ||
Expect(cond.Type).To(Equal(feastdevv1alpha1.OfflineStoreReadyType)) | ||
Expect(cond.Message).To(Equal(feastdevv1alpha1.OfflineStoreReadyMessage)) | ||
|
||
cond = apimeta.FindStatusCondition(resource.Status.Conditions, feastdevv1alpha1.OnlineStoreReadyType) | ||
Expect(cond).ToNot(BeNil()) | ||
Expect(cond.Status).To(Equal(metav1.ConditionTrue)) | ||
Expect(cond.Reason).To(Equal(feastdevv1alpha1.ReadyReason)) | ||
Expect(cond.Type).To(Equal(feastdevv1alpha1.OnlineStoreReadyType)) | ||
Expect(cond.Message).To(Equal(feastdevv1alpha1.OnlineStoreReadyMessage)) | ||
Expect(resource.Status.Phase).To(Equal(feastdevv1alpha1.ReadyPhase)) | ||
|
||
deploy := &appsv1.Deployment{} | ||
err = k8sClient.Get(ctx, types.NamespacedName{ | ||
Name: feast.GetFeastServiceName(services.RegistryFeastType), | ||
Namespace: resource.Namespace, | ||
}, | ||
deploy) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(deploy.Spec.Replicas).To(Equal(&services.DefaultReplicas)) | ||
Expect(controllerutil.HasControllerReference(deploy)).To(BeTrue()) | ||
Expect(deploy.Spec.Template.Spec.Containers).To(HaveLen(1)) | ||
command := deploy.Spec.Template.Spec.Containers[0].Command | ||
Expect(command).NotTo(ContainElement("--log-level")) | ||
|
||
err = k8sClient.Get(ctx, types.NamespacedName{ | ||
Name: feast.GetFeastServiceName(services.OfflineFeastType), | ||
Namespace: resource.Namespace, | ||
}, | ||
deploy) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(deploy.Spec.Replicas).To(Equal(&services.DefaultReplicas)) | ||
Expect(controllerutil.HasControllerReference(deploy)).To(BeTrue()) | ||
Expect(deploy.Spec.Template.Spec.Containers).To(HaveLen(1)) | ||
command = deploy.Spec.Template.Spec.Containers[0].Command | ||
Expect(command).To(ContainElement("--log-level")) | ||
Expect(command).To(ContainElement("INFO")) | ||
|
||
err = k8sClient.Get(ctx, types.NamespacedName{ | ||
Name: feast.GetFeastServiceName(services.OnlineFeastType), | ||
Namespace: resource.Namespace, | ||
}, | ||
deploy) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(deploy.Spec.Replicas).To(Equal(&services.DefaultReplicas)) | ||
Expect(controllerutil.HasControllerReference(deploy)).To(BeTrue()) | ||
Expect(deploy.Spec.Template.Spec.Containers).To(HaveLen(1)) | ||
command = deploy.Spec.Template.Spec.Containers[0].Command | ||
Expect(command).To(ContainElement("--log-level")) | ||
Expect(command).To(ContainElement("DEBUG")) | ||
}) | ||
|
||
}) | ||
}) |