From e0bf40c680002d1b90972a17f0f22be7618ced64 Mon Sep 17 00:00:00 2001 From: roy wang Date: Fri, 9 Oct 2020 21:22:12 +0900 Subject: [PATCH] healthscope support PodSpecWorkload Signed-off-by: roy wang --- .../healthscope/healthscope_controller.go | 5 ++-- .../core/scopes/healthscope/standard.go | 24 ++++++++++--------- .../core/scopes/healthscope/standard_test.go | 10 ++++---- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/pkg/controller/v1alpha2/core/scopes/healthscope/healthscope_controller.go b/pkg/controller/v1alpha2/core/scopes/healthscope/healthscope_controller.go index 19bc8ed0..ad3ce3c7 100644 --- a/pkg/controller/v1alpha2/core/scopes/healthscope/healthscope_controller.go +++ b/pkg/controller/v1alpha2/core/scopes/healthscope/healthscope_controller.go @@ -38,8 +38,7 @@ import ( const ( reconcileTimeout = 1 * time.Minute - // shortWait = 30 * time.Second - longWait = 1 * time.Minute + longWait = 1 * time.Minute ) // Reconcile error strings. @@ -123,7 +122,7 @@ func NewReconciler(m ctrl.Manager, o ...ReconcilerOption) *Reconciler { record: event.NewNopRecorder(), traitChecker: WorkloadHealthCheckFn(CheckByHealthCheckTrait), checkers: []WorloadHealthChecker{ - WorkloadHealthCheckFn(CheckStandardContainerziedHealth), + WorkloadHealthCheckFn(CheckPodSpecWorkloadHealth), WorkloadHealthCheckFn(CheckContainerziedWorkloadHealth), WorkloadHealthCheckFn(CheckDeploymentHealth), WorkloadHealthCheckFn(CheckStatefulsetHealth), diff --git a/pkg/controller/v1alpha2/core/scopes/healthscope/standard.go b/pkg/controller/v1alpha2/core/scopes/healthscope/standard.go index 861b7112..aaf82f7b 100644 --- a/pkg/controller/v1alpha2/core/scopes/healthscope/standard.go +++ b/pkg/controller/v1alpha2/core/scopes/healthscope/standard.go @@ -13,33 +13,35 @@ import ( ) var ( - standardContainerziedGVK = schema.GroupVersionKind{ + // PodSpecWorkload is a generic PaaS workload which adopts full K8s pod spec. + // More details refer to oam-dev/kubevela + podSpecWorkloadGVK = schema.GroupVersionKind{ Group: "standard.oam.dev", Version: "v1alpha1", - Kind: "Containerized", + Kind: "PodSpecWorkload", } ) -// CheckStandardContainerziedHealth check health condition of containerizeds.standard.oam.dev -func CheckStandardContainerziedHealth(ctx context.Context, c client.Client, ref runtimev1alpha1.TypedReference, namespace string) *WorkloadHealthCondition { - if ref.GroupVersionKind() != standardContainerziedGVK { +// CheckPodSpecWorkloadHealth check health condition of podspecworkloads.standard.oam.dev +func CheckPodSpecWorkloadHealth(ctx context.Context, c client.Client, ref runtimev1alpha1.TypedReference, namespace string) *WorkloadHealthCondition { + if ref.GroupVersionKind() != podSpecWorkloadGVK { return nil } r := &WorkloadHealthCondition{ HealthStatus: StatusHealthy, TargetWorkload: ref, } - containerizedObj := unstructured.Unstructured{} - containerizedObj.SetGroupVersionKind(ref.GroupVersionKind()) - if err := c.Get(ctx, types.NamespacedName{Namespace: namespace, Name: ref.Name}, &containerizedObj); err != nil { + workloadObj := unstructured.Unstructured{} + workloadObj.SetGroupVersionKind(ref.GroupVersionKind()) + if err := c.Get(ctx, types.NamespacedName{Namespace: namespace, Name: ref.Name}, &workloadObj); err != nil { r.HealthStatus = StatusUnhealthy r.Diagnosis = errors.Wrap(err, errHealthCheck).Error() return r } - r.ComponentName = getComponentNameFromLabel(&containerizedObj) - r.TargetWorkload.UID = containerizedObj.GetUID() + r.ComponentName = getComponentNameFromLabel(&workloadObj) + r.TargetWorkload.UID = workloadObj.GetUID() - childRefsData, _, _ := unstructured.NestedSlice(containerizedObj.Object, "status", "resources") + childRefsData, _, _ := unstructured.NestedSlice(workloadObj.Object, "status", "resources") childRefs := []runtimev1alpha1.TypedReference{} for _, v := range childRefsData { v := v.(map[string]interface{}) diff --git a/pkg/controller/v1alpha2/core/scopes/healthscope/standard_test.go b/pkg/controller/v1alpha2/core/scopes/healthscope/standard_test.go index ca7f5813..5f61818a 100644 --- a/pkg/controller/v1alpha2/core/scopes/healthscope/standard_test.go +++ b/pkg/controller/v1alpha2/core/scopes/healthscope/standard_test.go @@ -15,10 +15,10 @@ import ( "github.com/crossplane/oam-kubernetes-runtime/pkg/oam/util" ) -func TestCheckStandardContainerziedHealth(t *testing.T) { +func TestCheckPodSpecWorkloadHealth(t *testing.T) { mockClient := test.NewMockClient() scRef := runtimev1alpha1.TypedReference{} - scRef.SetGroupVersionKind(standardContainerziedGVK) + scRef.SetGroupVersionKind(podSpecWorkloadGVK) deployRef := runtimev1alpha1.TypedReference{} deployRef.SetGroupVersionKind(apps.SchemeGroupVersion.WithKind(kindDeployment)) @@ -29,7 +29,7 @@ func TestCheckStandardContainerziedHealth(t *testing.T) { svcRefData, _ := util.Object2Map(svcRef) scUnstructured := unstructured.Unstructured{} - scUnstructured.SetGroupVersionKind(standardContainerziedGVK) + scUnstructured.SetGroupVersionKind(podSpecWorkloadGVK) unstructured.SetNestedSlice(scUnstructured.Object, []interface{}{deployRefData, svcRefData}, "status", "resources") tests := []struct { @@ -92,7 +92,7 @@ func TestCheckStandardContainerziedHealth(t *testing.T) { }, }, { - caseName: "unhealthy for ContainerizedWorkload not found", + caseName: "unhealthy for PodSpecWorkload not found", wlRef: scRef, mockGetFn: func(ctx context.Context, key types.NamespacedName, obj runtime.Object) error { return errMockErr @@ -123,7 +123,7 @@ func TestCheckStandardContainerziedHealth(t *testing.T) { for _, tc := range tests { func(t *testing.T) { mockClient.MockGet = tc.mockGetFn - result := CheckStandardContainerziedHealth(ctx, mockClient, tc.wlRef, namespace) + result := CheckPodSpecWorkloadHealth(ctx, mockClient, tc.wlRef, namespace) if tc.expect == nil { assert.Nil(t, result, tc.caseName) } else {