mirror of
https://github.com/cozystack/cozystack.git
synced 2026-10-26 21:17:32 +09:00
WrapPreservingStatus rewrites Group, Kind and Name of a backend status to the aggregated resource but left Details.UID as the HelmRelease's, so a client that keys on details saw an identity the tenant cannot look up. The UID goes with the rest of the remap, and a test pins it. Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com> Assisted-by: LLM
49 lines
1.6 KiB
Go
49 lines
1.6 KiB
Go
/*
|
|
Copyright 2026 The Cozystack Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package registry
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
)
|
|
|
|
// WrapPreservingStatus maps a backing API error to the requested resource.
|
|
// ErrorToAPIStatus does not unwrap errors, so the result must implement
|
|
// APIStatus directly to retain the backend's HTTP code and reason.
|
|
func WrapPreservingStatus(msg string, err error, resource schema.GroupResource, name string) error {
|
|
msg = fmt.Sprintf("%s %q: %s", resource.String(), name, msg)
|
|
var status apierrors.APIStatus
|
|
if errors.As(err, &status) {
|
|
backendStatus := status.Status()
|
|
st := backendStatus.DeepCopy()
|
|
if st.Details == nil {
|
|
st.Details = &metav1.StatusDetails{}
|
|
}
|
|
st.Details.Group = resource.Group
|
|
st.Details.Kind = resource.Resource
|
|
st.Details.Name = name
|
|
st.Details.UID = ""
|
|
st.Message = fmt.Sprintf("%s: %s", msg, st.Message)
|
|
return &apierrors.StatusError{ErrStatus: *st}
|
|
}
|
|
return fmt.Errorf("%s: %w", msg, err)
|
|
}
|