MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / deleteNamespace

Function deleteNamespace

tests/utils/namespaces/namespace.go:176–203  ·  view source on GitHub ↗

deleteNamespace deletes a namespace if existent

(
	ctx context.Context,
	crudClient client.Client,
	name string,
	opts ...client.DeleteOption,
)

Source from the content-addressed store, hash-verified

174
175// deleteNamespace deletes a namespace if existent
176func 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
206func DeleteNamespaceAndWait(

Callers 2

cleanupNamespaceFunction · 0.85
DeleteNamespaceAndWaitFunction · 0.85

Calls 2

DeleteFunction · 0.92
getPreserveNamespacesFunction · 0.85

Tested by

no test coverage detected