func()

in integration/janitor/janitor.go [39:72]


func (j *cloudMapJanitor) Cleanup(ctx context.Context, nsName string) {
	fmt.Printf("Cleaning up all test resources in Cloud Map for namespace : %s\n", nsName)

	nsMap, err := j.sdApi.GetNamespaceMap(ctx)
	j.checkOrFail(err, "", "could not find namespace to clean")

	ns, found := nsMap[nsName]
	if !found {
		fmt.Println("namespace does not exist in account, nothing to clean")
		return
	}

	fmt.Printf("found namespace to clean: %s\n", ns.Id)

	svcIdMap, err := j.sdApi.GetServiceIdMap(ctx, ns.Id)
	j.checkOrFail(err,
		fmt.Sprintf("namespace has %d services to clean", len(svcIdMap)),
		"could not find services to clean")

	for svcName, svcId := range svcIdMap {
		fmt.Printf("found service to clean: %s\n", svcId)
		j.deregisterInstances(ctx, nsName, svcName, svcId)

		delSvcErr := j.sdApi.DeleteService(ctx, svcId)
		j.checkOrFail(delSvcErr, "service deleted", "could not cleanup service")
	}

	opId, err := j.sdApi.DeleteNamespace(ctx, ns.Id)
	if err == nil {
		fmt.Println("namespace delete in progress")
		_, err = j.sdApi.PollNamespaceOperation(ctx, opId)
	}
	j.checkOrFail(err, "clean up successful", "could not cleanup namespace")
}