diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f8c194e32..0a3a936482 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/services/registry/CHANGELOG.md b/services/registry/CHANGELOG.md index 90f1fd7a59..d5d0c61d52 100644 --- a/services/registry/CHANGELOG.md +++ b/services/registry/CHANGELOG.md @@ -1,7 +1,11 @@ +## v0.2.1 +- **Bugfix:** Waiter `DeleteArtifactoryWaitHandler` allow hard delete on ERROR state +- **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 \ No newline at end of file +- `v1`: New package which can be used for communication with the registry v1 API diff --git a/services/registry/VERSION b/services/registry/VERSION index 81fd7ba087..eac0a1441d 100644 --- a/services/registry/VERSION +++ b/services/registry/VERSION @@ -1 +1 @@ -v0.2.0 \ No newline at end of file +v0.2.1 \ No newline at end of file diff --git a/services/registry/v1api/wait/wait.go b/services/registry/v1api/wait/wait.go index d24ea56651..de85d5202a 100644 --- a/services/registry/v1api/wait/wait.go +++ b/services/registry/v1api/wait/wait.go @@ -3,6 +3,7 @@ package wait import ( "context" "errors" + "fmt" "net/http" "time" @@ -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, @@ -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]{ 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}, } @@ -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 } diff --git a/services/registry/v1api/wait/wait_test.go b/services/registry/v1api/wait/wait_test.go index 179f7c2b6c..6d30546e6c 100644 --- a/services/registry/v1api/wait/wait_test.go +++ b/services/registry/v1api/wait/wait_test.go @@ -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", @@ -253,6 +255,32 @@ func TestGetStateArtifactory(t *testing.T) { want: ArtifactoryActive, wantErr: false, }, + { + name: "error state with description", + resp: ®istry.Artifactory{ + State: ArtifactoryError, + ErrorDescription: utils.Ptr("provisioning failed"), + }, + want: ArtifactoryError, + wantErr: true, + }, + { + name: "error state with empty description", + resp: ®istry.Artifactory{ + State: ArtifactoryError, + ErrorDescription: utils.Ptr(""), + }, + want: ArtifactoryError, + wantErr: false, + }, + { + name: "error state without description", + resp: ®istry.Artifactory{ + State: ArtifactoryError, + }, + want: ArtifactoryError, + wantErr: false, + }, } for _, tt := range tests { @@ -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: ®istry.Artifactory{ + State: ArtifactoryActive, + }, + want: ArtifactoryActive, + wantErr: false, + }, + { + name: "error state", + resp: ®istry.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) + } + }) + } +}