From f30e60b60d4e01cda1505251fe449d166032f781 Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Mon, 18 May 2020 10:23:21 +0800 Subject: [PATCH] Handle deployment apply error --- .../controllers/manifestwork_controller.go | 2 +- .../manifestwork_controller_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/spoke/controllers/manifestwork_controller.go b/pkg/spoke/controllers/manifestwork_controller.go index 6de09a3ea..96f03478c 100644 --- a/pkg/spoke/controllers/manifestwork_controller.go +++ b/pkg/spoke/controllers/manifestwork_controller.go @@ -312,7 +312,7 @@ func isDecodeError(err error) bool { // isUnhandledError is to check if the error returned from resourceapply is due to that no typed // client can handle the object func isUnhandledError(err error) bool { - return err != nil && strings.HasPrefix(err.Error(), "cannot decode") + return err != nil && strings.HasPrefix(err.Error(), "unhandled type") } // isSameUnstructured compares the two unstructured object. diff --git a/pkg/spoke/controllers/manifestwork_controller_test.go b/pkg/spoke/controllers/manifestwork_controller_test.go index 4be2ca6a2..87a499281 100644 --- a/pkg/spoke/controllers/manifestwork_controller_test.go +++ b/pkg/spoke/controllers/manifestwork_controller_test.go @@ -125,6 +125,20 @@ func newFakeMapper() *resource.Mapper { }, }, }, + { + Group: metav1.APIGroup{ + Name: "apps", + Versions: []metav1.GroupVersionForDiscovery{ + {Version: "v1", GroupVersion: "apps/v1"}, + }, + PreferredVersion: metav1.GroupVersionForDiscovery{Version: "v1", GroupVersion: "apps/v1"}, + }, + VersionedResources: map[string][]metav1.APIResource{ + "v1": { + {Name: "deployments", Group: "apps", Namespaced: true, Kind: "Deployment"}, + }, + }, + }, } return &resource.Mapper{ Mapper: restmapper.NewDiscoveryRESTMapper(resources), @@ -309,6 +323,11 @@ func TestSync(t *testing.T) { withExpectedWorkAction("get", "update"). withExpectedKubeAction("get", "create"). withExpectedCondition(expectedCondition{string(workapiv1.ManifestApplied), metav1.ConditionTrue}), + newTestCase("create single deployment resource"). + withWorkManifest(newUnstructured("apps/v1", "Deployment", "ns1", "test")). + withExpectedWorkAction("get", "update"). + withExpectedDynamicAction("get", "create"). + withExpectedCondition(expectedCondition{string(workapiv1.ManifestApplied), metav1.ConditionTrue}), newTestCase("update single resource"). withWorkManifest(newUnstructured("v1", "Secret", "ns1", "test")). withSpokeObject(newSecret("test", "ns1", "value2")).