Handle deployment apply error

This commit is contained in:
Jian Qiu
2020-05-18 10:23:21 +08:00
parent b10a920e52
commit f30e60b60d
2 changed files with 20 additions and 1 deletions

View File

@@ -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.

View File

@@ -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")).