summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/helm
diff options
context:
space:
mode:
Diffstat (limited to 'src/k8splugin/internal/helm')
-rw-r--r--src/k8splugin/internal/helm/helm.go10
-rw-r--r--src/k8splugin/internal/helm/helm_test.go43
2 files changed, 53 insertions, 0 deletions
diff --git a/src/k8splugin/internal/helm/helm.go b/src/k8splugin/internal/helm/helm.go
index 6064b2c8..b27c8aee 100644
--- a/src/k8splugin/internal/helm/helm.go
+++ b/src/k8splugin/internal/helm/helm.go
@@ -249,3 +249,13 @@ func getGroupVersionKind(data string) (schema.GroupVersionKind, error) {
return *gvk, nil
}
+
+//GetReverseK8sResources reverse list of resources for delete purpose
+func GetReverseK8sResources(resources []KubernetesResource) []KubernetesResource {
+ reversed := []KubernetesResource{}
+
+ for i := len(resources) - 1; i >= 0; i-- {
+ reversed = append(reversed, resources[i])
+ }
+ return reversed
+}
diff --git a/src/k8splugin/internal/helm/helm_test.go b/src/k8splugin/internal/helm/helm_test.go
index b805b59b..951ff92b 100644
--- a/src/k8splugin/internal/helm/helm_test.go
+++ b/src/k8splugin/internal/helm/helm_test.go
@@ -26,6 +26,7 @@ import (
"testing"
"gopkg.in/yaml.v2"
+ "k8s.io/apimachinery/pkg/runtime/schema"
)
func TestProcessValues(t *testing.T) {
@@ -265,3 +266,45 @@ func TestGenerateKubernetesArtifacts(t *testing.T) {
})
}
}
+
+func TestReverseResources(t *testing.T) {
+
+ t.Run("Successfully reverse resources", func(t *testing.T) {
+ data := []KubernetesResource{
+ {
+ GVK: schema.GroupVersionKind{
+ Group: "apps",
+ Version: "v1",
+ Kind: "Deployment"},
+ Name: "deployment-1",
+ },
+ {
+ GVK: schema.GroupVersionKind{
+ Group: "apps",
+ Version: "v1",
+ Kind: "Deployment"},
+ Name: "deployment-2",
+ },
+ {
+ GVK: schema.GroupVersionKind{
+ Group: "",
+ Version: "v1",
+ Kind: "Service"},
+ Name: "service-1",
+ },
+ {
+ GVK: schema.GroupVersionKind{
+ Group: "",
+ Version: "v1",
+ Kind: "Service"},
+ Name: "service-2",
+ },
+ }
+
+ reversed := GetReverseK8sResources(data)
+
+ if reversed[0] != data[len(data)-1] {
+ t.Fatalf("Unexpected k8s resource at position 0 %s", reversed[0])
+ }
+ })
+}