diff options
author | 2021-08-09 22:44:48 +0200 | |
---|---|---|
committer | 2021-08-09 21:00:30 +0000 | |
commit | ce5c20b32d7fe6214c5d76b0676c2a5d89abe0e9 (patch) | |
tree | 791818e5c0f7b7372cc9884c58bbb471fcee22da | |
parent | df4c908a455a4e073fc8cb9b37304e164cebe234 (diff) |
Fixed issue of leftovers after instace create failurehonolulu
Fixed issue of leftovers after instace create failure
Issue-ID: MULTICLOUD-1269
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com>
Change-Id: I69b4a170d72a482f29fd79ecdfc949f55c70a61a
-rw-r--r-- | src/k8splugin/internal/app/client.go | 7 | ||||
-rw-r--r-- | src/k8splugin/internal/app/instance.go | 4 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/k8splugin/internal/app/client.go b/src/k8splugin/internal/app/client.go index 00fd8e97..405fdc33 100644 --- a/src/k8splugin/internal/app/client.go +++ b/src/k8splugin/internal/app/client.go @@ -353,16 +353,17 @@ func (k *KubernetesClient) updateKind(resTempl helm.KubernetesResourceTemplate, func (k *KubernetesClient) createResources(sortedTemplates []helm.KubernetesResourceTemplate, namespace string) ([]helm.KubernetesResource, error) { + var createdResources []helm.KubernetesResource + err := k.ensureNamespace(namespace) if err != nil { - return nil, pkgerrors.Wrap(err, "Creating Namespace") + return createdResources, pkgerrors.Wrap(err, "Creating Namespace") } - var createdResources []helm.KubernetesResource for _, resTempl := range sortedTemplates { resCreated, err := k.CreateKind(resTempl, namespace) if err != nil { - return nil, pkgerrors.Wrapf(err, "Error creating kind: %+v", resTempl.GVK) + return createdResources, pkgerrors.Wrapf(err, "Error creating kind: %+v", resTempl.GVK) } createdResources = append(createdResources, resCreated) } diff --git a/src/k8splugin/internal/app/instance.go b/src/k8splugin/internal/app/instance.go index c1ec35b6..4a326d50 100644 --- a/src/k8splugin/internal/app/instance.go +++ b/src/k8splugin/internal/app/instance.go @@ -164,6 +164,10 @@ func (v *InstanceClient) Create(i InstanceRequest) (InstanceResponse, error) { createdResources, err := k8sClient.createResources(sortedTemplates, profile.Namespace) if err != nil { + if len(createdResources) > 0 { + log.Printf("[Instance] Reverting created resources on Error: %s", err.Error()) + k8sClient.deleteResources(createdResources, profile.Namespace) + } return InstanceResponse{}, pkgerrors.Wrap(err, "Create Kubernetes Resources") } |