(projectID string)
| 68 | } |
| 69 | |
| 70 | func deleteProject(projectID string) error { |
| 71 | // delete project from kubernetes |
| 72 | if err := project.DeleteProject(projectID); err != nil { |
| 73 | return err |
| 74 | } |
| 75 | |
| 76 | settings := cli.New() |
| 77 | actionConfig := new(action.Configuration) |
| 78 | if err := actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), os.Getenv("HELM_DRIVER"), log.Printf); err != nil { |
| 79 | return err |
| 80 | } |
| 81 | |
| 82 | kubeClint, err := actionConfig.KubernetesClientSet() |
| 83 | if err != nil { |
| 84 | return err |
| 85 | } |
| 86 | |
| 87 | // wait for project to get deleted in kubernetes |
| 88 | ticker := time.NewTicker(10 * time.Second) |
| 89 | defer ticker.Stop() |
| 90 | maxCount := 18 // wait for 3 minutes, 10 seconds * 18 = 180 seconds |
| 91 | counter := 0 |
| 92 | utils.LogInfo(fmt.Sprintf("Waiting for project (%s) to get deleted, this might take up to 3 minutes", projectID)) |
| 93 | |
| 94 | for range ticker.C { |
| 95 | namespacesList, err := kubeClint.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{LabelSelector: "app.kubernetes.io/managed-by=space-cloud"}) |
| 96 | if err != nil { |
| 97 | return err |
| 98 | } |
| 99 | doesExists := false |
| 100 | var ns v1.Namespace |
| 101 | for _, namespace := range namespacesList.Items { |
| 102 | if namespace.Name == projectID { |
| 103 | doesExists = true |
| 104 | ns = namespace |
| 105 | break |
| 106 | } |
| 107 | } |
| 108 | if !doesExists { |
| 109 | utils.LogInfo(fmt.Sprintf("Successfully deleted project (%s)", projectID)) |
| 110 | return nil |
| 111 | } |
| 112 | |
| 113 | counter++ |
| 114 | if counter == maxCount { |
| 115 | utils.LogInfo(fmt.Sprintf("Deleting project (%s) is taking to much time, skipping project (%s)", projectID, projectID)) |
| 116 | return nil |
| 117 | } |
| 118 | |
| 119 | utils.LogInfo(fmt.Sprintf("Project deletion status (%s)", ns.Status.Phase)) |
| 120 | } |
| 121 | return nil |
| 122 | } |
no test coverage detected