Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

## Release (2026-MM-DD)

- `registry`:
- [v0.2.1](services/registry/CHANGELOG.md#v021)
- **Bugfix:** Waiter `DeleteArtifactoryWaitHandler` allow hard delete on ERROR state
- **Feature:** Add `ErrorDescription` information to `CreateArtifactoryWaitHandler` and `UpdateArtifactoryWaitHandler`
- `sca`:
- [v0.3.0](services/sca/CHANGELOG.md#v030)
- `v1alphaapi`: Align package to latest API specification
Expand Down
6 changes: 5 additions & 1 deletion services/registry/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## v0.2.1
- **Bugfix:** Waiter `DeleteArtifactoryWaitHandler` allow hard delete on ERROR state
Comment thread
martinezmo marked this conversation as resolved.
Resolved
- **Feature:** Add `ErrorDescription` information to `CreateArtifactoryWaitHandler` and `UpdateArtifactoryWaitHandler`

## v0.2.0
- `v1api`:
- **Feature:** Add `ErrorDescription` field to `Artifactory` which describes the reason for the error state

## v0.1.0
- **New:** SDK module for STACKIT Container Registry service.
- `v1`: New package which can be used for communication with the registry v1 API
- `v1`: New package which can be used for communication with the registry v1 API
2 changes: 1 addition & 1 deletion services/registry/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.2.0
v0.2.1
42 changes: 37 additions & 5 deletions services/registry/v1api/wait/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package wait
import (
"context"
"errors"
"fmt"
"net/http"
"time"

Expand All @@ -13,11 +14,11 @@ import (
const (
ArtifactoryReconciling = registry.ARTIFACTORYSTATE_RECONCILING
ArtifactoryActive = registry.ARTIFACTORYSTATE_ACTIVE
ArtifactoryDeleted = registry.ARTIFACTORYSTATE_DELETED
ArtifactoryError = registry.ARTIFACTORYSTATE_ERROR
)

// CreateArtifactoryWaitHandler will wait for the artifactory to be created/ready.
// If there is an error state, it will return the error immediately.
func CreateArtifactoryWaitHandler(ctx context.Context, a registry.DefaultAPI, projectId, regionId, artifactoryId string) *wait.AsyncActionHandler[registry.Artifactory] {
waitConfig := wait.WaiterHelper[registry.Artifactory, registry.ArtifactoryState]{
FetchInstance: a.GetArtifactory(ctx, projectId, regionId, artifactoryId).Execute,
Expand Down Expand Up @@ -46,12 +47,24 @@ func UpdateArtifactoryWaitHandler(ctx context.Context, a registry.DefaultAPI, pr
}

// DeleteArtifactoryWaitHandler will wait for the artifactory to be deleted.
//
// The API provides a single delete call, but the internal deletion behavior
// depends on the status of the backend custom resource (CR) when delete is called:
// 1. Soft delete (CR is in Active state):
// Active -> Reconciling -> HTTP 404 (Not Found).
// The artifactory is soft-deleted; the API returns HTTP 404 (Not Found),
// even though the underlying custom resource still remains internally.
// 2. Hard delete (CR is in Error state):
// Error -> HTTP 404 (Not Found).
// The custom resource is permanently purged without transitioning through Reconciling.
//
// In both flows, the wait handler polls until GetArtifactory returns HTTP 404 (Not Found).
func DeleteArtifactoryWaitHandler(ctx context.Context, a registry.DefaultAPI, projectId, regionId, artifactoryId string) *wait.AsyncActionHandler[registry.Artifactory] {
waitConfig := wait.WaiterHelper[registry.Artifactory, registry.ArtifactoryState]{
Comment thread
martinezmo marked this conversation as resolved.
Resolved
FetchInstance: a.GetArtifactory(ctx, projectId, regionId, artifactoryId).Execute,
GetState: getStateArtifactory,
ActiveState: nil,
ErrorState: []registry.ArtifactoryState{registry.ARTIFACTORYSTATE_ERROR},
GetState: getStateArtifactoryDelete,
ActiveState: []registry.ArtifactoryState{},
ErrorState: nil,
DeleteHttpErrorStatusCodes: []int{http.StatusNotFound},
}

Expand All @@ -60,9 +73,28 @@ func DeleteArtifactoryWaitHandler(ctx context.Context, a registry.DefaultAPI, pr
return handler
}

// For insert and update the error state is an error and the error is enriched with the information got from the container registry API.
func getStateArtifactory(response *registry.Artifactory) (registry.ArtifactoryState, error) {
if response == nil {
return "", errors.New("empty response")
}
return response.GetState(), nil

state := response.GetState()
// If the state is error, enrich the description with the information got from the container registry API
if state == registry.ARTIFACTORYSTATE_ERROR {
if response.ErrorDescription != nil && *response.ErrorDescription != "" {
return state, fmt.Errorf("%s", *response.ErrorDescription)
}
}
return state, nil
}

// Special case of getState, in delete action the error state is not an error itself but a normal state.
func getStateArtifactoryDelete(response *registry.Artifactory) (registry.ArtifactoryState, error) {
if response == nil {
return "", errors.New("empty response")
}

state := response.GetState()
return state, nil
}
77 changes: 74 additions & 3 deletions services/registry/v1api/wait/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,21 @@ func TestDeleteArtifactoryWaitHandler(t *testing.T) {
wantErr: false,
},
{
name: "success delayed after reconciling",
name: "soft delete: success delayed after active and reconciling",
responses: []response{
{state: ArtifactoryActive},
{state: ArtifactoryReconciling},
{status: http.StatusNotFound},
},
wantErr: false,
},
{
name: "error state",
name: "hard delete: success delayed after error",
responses: []response{
{state: ArtifactoryError},
{status: http.StatusNotFound},
},
wantErr: true,
wantErr: false,
},
{
name: "api error",
Expand Down Expand Up @@ -253,6 +255,32 @@ func TestGetStateArtifactory(t *testing.T) {
want: ArtifactoryActive,
wantErr: false,
},
{
name: "error state with description",
resp: &registry.Artifactory{
State: ArtifactoryError,
ErrorDescription: utils.Ptr("provisioning failed"),
},
want: ArtifactoryError,
wantErr: true,
},
{
name: "error state with empty description",
resp: &registry.Artifactory{
State: ArtifactoryError,
ErrorDescription: utils.Ptr(""),
},
want: ArtifactoryError,
wantErr: false,
},
{
name: "error state without description",
resp: &registry.Artifactory{
State: ArtifactoryError,
},
want: ArtifactoryError,
wantErr: false,
},
}

for _, tt := range tests {
Expand All @@ -267,3 +295,46 @@ func TestGetStateArtifactory(t *testing.T) {
})
}
}

func TestGetStateArtifactoryDelete(t *testing.T) {
tests := []struct {
name string
resp *registry.Artifactory
want registry.ArtifactoryState
wantErr bool
}{
{
name: "nil response",
resp: nil,
wantErr: true,
},
{
name: "valid state",
resp: &registry.Artifactory{
State: ArtifactoryActive,
},
want: ArtifactoryActive,
wantErr: false,
},
{
name: "error state",
resp: &registry.Artifactory{
State: ArtifactoryError,
},
want: ArtifactoryError,
wantErr: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := getStateArtifactoryDelete(tt.resp)
if (err != nil) != tt.wantErr {
t.Fatalf("getStateArtifactoryDelete() error = %v, wantErr %v", err, tt.wantErr)
}
if got != tt.want {
t.Fatalf("getStateArtifactoryDelete() = %v, want %v", got, tt.want)
}
})
}
}