summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal
diff options
context:
space:
mode:
authorLukasz Rajewski <lukasz.rajewski@orange.com>2021-08-09 22:44:48 +0200
committerLukasz Rajewski <lukasz.rajewski@orange.com>2021-08-09 22:44:48 +0200
commit6875d67ee2ad879170774304dd35d9a14dd9f50c (patch)
tree8d4df538a9c1d6673216e6280f72f46e5297462d /src/k8splugin/internal
parentb64758e33cb291a6e9afa80a89a57f6cd3a3562d (diff)
Fixed issue of leftovers after instace create failure
Fixed issue of leftovers after instace create failure Issue-ID: MULTICLOUD-1269 Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com> Change-Id: I69b4a170d72a482f29fd79ecdfc949f55c70a61a
Diffstat (limited to 'src/k8splugin/internal')
-rw-r--r--src/k8splugin/internal/app/client.go7
-rw-r--r--src/k8splugin/internal/app/instance.go4
2 files changed, 8 insertions, 3 deletions
diff --git a/src/k8splugin/internal/app/client.go b/src/k8splugin/internal/app/client.go
index 623a8dc7..87e5c379 100644
--- a/src/k8splugin/internal/app/client.go
+++ b/src/k8splugin/internal/app/client.go
@@ -440,16 +440,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 8c924af3..c7fd8e52 100644
--- a/src/k8splugin/internal/app/instance.go
+++ b/src/k8splugin/internal/app/instance.go
@@ -177,6 +177,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")
}