File: useWaitForDeletionFunction.go

package info (click to toggle)
golang-github-ionos-cloud-sdk-go 6.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,332 kB
  • sloc: sh: 35; makefile: 3
file content (32 lines) | stat: -rw-r--r-- 1,000 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main

import (
	"context"
	"fmt"
	ionoscloud "github.com/ionos-cloud/sdk-go/v6"
	"log"
)

func processRequestClusterDelete(apiClient *ionoscloud.APIClient, resourceID string) (*ionoscloud.APIResponse, error) {
	apiRequest := apiClient.KubernetesApi.K8sFindByClusterId(context.Background(), resourceID)
	_, apiResp, err := apiRequest.Execute()
	if err != nil {
		return apiResp, fmt.Errorf("error occurred when executing the api get resource operation: %w", err)
	}

	return apiResp, nil
}

func main() {
	cfg := ionoscloud.NewConfigurationFromEnv()
	apiClient := ionoscloud.NewAPIClient(cfg)
	resourceId := "c376e371-51bb-45f2-9b24-3da0fc3a6cfc" // you can pass the resource id after you create a resource using resource.GetId()

	deleted, err := apiClient.WaitForDeletion(context.Background(), processRequestClusterDelete, resourceId)
	if err != nil {
		log.Fatal(err)
	}
	if deleted == true {
		// put your code here(for example you can delete a k8s nodepool and after that a cluster)
	}
}