deleteNamespace deletes a namespace if existent
( ctx context.Context, crudClient client.Client, name string, opts ...client.DeleteOption, )
| 174 | |
| 175 | // deleteNamespace deletes a namespace if existent |
| 176 | func deleteNamespace( |
| 177 | ctx context.Context, |
| 178 | crudClient client.Client, |
| 179 | name string, |
| 180 | opts ...client.DeleteOption, |
| 181 | ) error { |
| 182 | // Exit immediately if the name is empty |
| 183 | if name == "" { |
| 184 | return errors.New("cannot delete namespace with empty name") |
| 185 | } |
| 186 | |
| 187 | // Exit immediately if the namespace is listed in PreserveNamespaces |
| 188 | for _, v := range getPreserveNamespaces() { |
| 189 | if strings.HasPrefix(name, v) { |
| 190 | return nil |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | u := &unstructured.Unstructured{} |
| 195 | u.SetName(name) |
| 196 | u.SetGroupVersionKind(schema.GroupVersionKind{ |
| 197 | Group: "", |
| 198 | Version: "v1", |
| 199 | Kind: "Namespace", |
| 200 | }) |
| 201 | |
| 202 | return objects.Delete(ctx, crudClient, u, opts...) |
| 203 | } |
| 204 | |
| 205 | // DeleteNamespaceAndWait deletes a namespace if existent and returns when deletion is completed |
| 206 | func DeleteNamespaceAndWait( |
no test coverage detected