-
Notifications
You must be signed in to change notification settings - Fork 33
chore(logme): introduce v2api waiter #7898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
j1n-o9r
wants to merge
6
commits into
main
Choose a base branch
from
chore/logme-v2api-waiter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e13df68
chore(logme): copy waiter
j1n-o9r 6cf1b20
chore(logme): try fix linter
j1n-o9r 4e21afc
chore(logme): created test
j1n-o9r a30544a
chore(logme): write changelog
j1n-o9r 58b8276
chore(logme): remove if statement that introduces unreachable code path
j1n-o9r 0268308
chore(logme): add deprecated status till end of period
j1n-o9r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| v1.0.0 | ||
| v1.0.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| package wait | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "net/http" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/stackitcloud/stackit-sdk-go/core/oapierror" | ||
| "github.com/stackitcloud/stackit-sdk-go/core/wait" | ||
| logme "github.com/stackitcloud/stackit-sdk-go/services/logme/v2api" | ||
| ) | ||
|
|
||
| const ( | ||
| // Deprecated: symbol is not used anymore, use the packages enum instead, will be removed 2026-12, use `go fix` for automatic fixing | ||
| //go:fix inline | ||
| INSTANCESTATUS_ACTIVE = logme.INSTANCESTATUS_ACTIVE | ||
| // Deprecated: symbol is not used anymore, use the packages enum instead, will be removed 2026-12, use `go fix` for automatic fixing | ||
| //go:fix inline | ||
| INSTANCESTATUS_FAILED = logme.INSTANCESTATUS_FAILED | ||
| // Deprecated: symbol is not used anymore, use the packages enum instead, will be removed 2026-12, use `go fix` for automatic fixing | ||
| //go:fix inline | ||
| INSTANCESTATUS_STOPPED = logme.INSTANCESTATUS_STOPPED | ||
| // Deprecated: symbol is not used anymore, use the packages enum instead, will be removed 2026-12, use `go fix` for automatic fixing | ||
| //go:fix inline | ||
| INSTANCESTATUS_CREATING = logme.INSTANCESTATUS_CREATING | ||
| // Deprecated: symbol is not used anymore, use the packages enum instead, will be removed 2026-12, use `go fix` for automatic fixing | ||
| //go:fix inline | ||
| INSTANCESTATUS_DELETING = logme.INSTANCESTATUS_DELETING | ||
| // Deprecated: symbol is not used anymore, use the packages enum instead, will be removed 2026-12, use `go fix` for automatic fixing | ||
| //go:fix inline | ||
| INSTANCESTATUS_UPDATING = logme.INSTANCESTATUS_UPDATING | ||
| ) | ||
|
|
||
| // CreateInstanceWaitHandler will wait for instance creation | ||
| func CreateInstanceWaitHandler(ctx context.Context, client logme.DefaultAPI, projectId, region, instanceId string) *wait.AsyncActionHandler[logme.Instance] { | ||
| waitConfig := wait.WaiterHelper[logme.Instance, logme.InstanceStatus]{ | ||
| FetchInstance: client.GetInstance(ctx, projectId, region, instanceId).Execute, | ||
| GetState: func(response *logme.Instance) (logme.InstanceStatus, error) { | ||
| if response == nil { | ||
| return "", errors.New("empty response") | ||
| } | ||
| if response.Status == nil { | ||
| return "", errors.New("status is missing in response") | ||
| } | ||
| return *response.Status, nil | ||
| }, | ||
| ActiveState: []logme.InstanceStatus{logme.INSTANCESTATUS_ACTIVE}, | ||
| ErrorState: []logme.InstanceStatus{logme.INSTANCESTATUS_FAILED}, | ||
| } | ||
|
|
||
| handler := wait.New(waitConfig.Wait()) | ||
| handler.SetTimeout(45 * time.Minute) | ||
| return handler | ||
| } | ||
|
|
||
| // PartialUpdateInstanceWaitHandler will wait for instance update | ||
| func PartialUpdateInstanceWaitHandler(ctx context.Context, client logme.DefaultAPI, projectId, region, instanceId string) *wait.AsyncActionHandler[logme.Instance] { | ||
| waitConfig := wait.WaiterHelper[logme.Instance, logme.InstanceStatus]{ | ||
| FetchInstance: client.GetInstance(ctx, projectId, region, instanceId).Execute, | ||
| GetState: func(response *logme.Instance) (logme.InstanceStatus, error) { | ||
| if response == nil { | ||
| return "", errors.New("empty response") | ||
| } | ||
| if response.Status == nil { | ||
| return "", errors.New("status is missing in response") | ||
| } | ||
| return *response.Status, nil | ||
| }, | ||
| ActiveState: []logme.InstanceStatus{logme.INSTANCESTATUS_ACTIVE}, | ||
| ErrorState: []logme.InstanceStatus{logme.INSTANCESTATUS_FAILED}, | ||
| } | ||
|
|
||
| handler := wait.New(waitConfig.Wait()) | ||
| handler.SetTimeout(45 * time.Minute) | ||
| return handler | ||
| } | ||
|
|
||
| // DeleteInstanceWaitHandler will wait for instance deletion | ||
| func DeleteInstanceWaitHandler(ctx context.Context, a logme.DefaultAPI, projectId, region, instanceId string) *wait.AsyncActionHandler[struct{}] { | ||
| handler := wait.New(func() (waitFinished bool, response *struct{}, err error) { | ||
| s, err := a.GetInstance(ctx, projectId, region, instanceId).Execute() | ||
| if err == nil { | ||
| if s.Status == nil { | ||
| return false, nil, fmt.Errorf("delete failed for instance with id %s. The response is not valid: The status is missing", instanceId) | ||
| } | ||
| if *s.Status == logme.INSTANCESTATUS_ACTIVE { | ||
| if strings.Contains(s.LastOperation.Description, "DeleteFailed") || strings.Contains(s.LastOperation.Description, "failed") { | ||
| return true, nil, fmt.Errorf("instance was deleted successfully but has errors: %s", s.LastOperation.Description) | ||
| } | ||
| return true, nil, nil | ||
| } | ||
| return false, nil, nil | ||
| } | ||
| oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped | ||
| if !ok { | ||
| return false, nil, fmt.Errorf("could not convert error to oapierror.GenericOpenAPIError") | ||
| } | ||
| if oapiErr.StatusCode != http.StatusGone { | ||
| return false, nil, err | ||
| } | ||
| return true, nil, nil | ||
| }) | ||
| handler.SetTimeout(15 * time.Minute) | ||
| return handler | ||
| } | ||
|
|
||
| // CreateCredentialsWaitHandler will wait for credentials creation | ||
| func CreateCredentialsWaitHandler(ctx context.Context, a logme.DefaultAPI, projectId, region, instanceId, credentialsId string) *wait.AsyncActionHandler[logme.CredentialsResponse] { | ||
| handler := wait.New(func() (waitFinished bool, response *logme.CredentialsResponse, err error) { | ||
| s, err := a.GetCredentials(ctx, projectId, region, instanceId, credentialsId).Execute() | ||
| if err != nil { | ||
| oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped | ||
| if !ok { | ||
| return false, nil, fmt.Errorf("could not convert error to oapierror.GenericOpenAPIError") | ||
| } | ||
| // If the request returns 404, the credentials have not been created yet | ||
| if oapiErr.StatusCode == http.StatusNotFound { | ||
| return false, nil, nil | ||
| } | ||
| return false, nil, err | ||
| } | ||
| if s.Id == credentialsId { | ||
| return true, s, nil | ||
| } | ||
| return false, nil, nil | ||
| }) | ||
| handler.SetTimeout(1 * time.Minute) | ||
| return handler | ||
| } | ||
|
|
||
| // DeleteCredentialsWaitHandler will wait for credentials deletion | ||
| func DeleteCredentialsWaitHandler(ctx context.Context, a logme.DefaultAPI, projectId, region, instanceId, credentialsId string) *wait.AsyncActionHandler[struct{}] { | ||
| handler := wait.New(func() (waitFinished bool, response *struct{}, err error) { | ||
| _, err = a.GetCredentials(ctx, projectId, region, instanceId, credentialsId).Execute() | ||
| if err == nil { | ||
| return false, nil, nil | ||
| } | ||
| oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped | ||
| if !ok { | ||
| return false, nil, fmt.Errorf("could not convert error to oapierror.GenericOpenAPIError") | ||
| } | ||
| if oapiErr.StatusCode != http.StatusNotFound && oapiErr.StatusCode != http.StatusGone { | ||
| return false, nil, err | ||
| } | ||
| return true, nil, nil | ||
| }) | ||
| handler.SetTimeout(1 * time.Minute) | ||
| return handler | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introducing deprecated code in a new file????