Add source kind and name to not found error

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
Stefan Prodan 2021-02-08 15:06:47 +02:00
parent 736867d359
commit e99f328200
No known key found for this signature in database
GPG Key ID: 3299AEB0E4085BAF
2 changed files with 10 additions and 1 deletions

View File

@ -16,6 +16,8 @@ limitations under the License.
package v1beta1
import "fmt"
// CrossNamespaceSourceReference contains enough information to let you locate the
// typed referenced object at cluster level
type CrossNamespaceSourceReference struct {
@ -36,3 +38,10 @@ type CrossNamespaceSourceReference struct {
// +optional
Namespace string `json:"namespace,omitempty"`
}
func (s *CrossNamespaceSourceReference) String() string {
if s.Namespace != "" {
return fmt.Sprintf("%s/%s/%s", s.Kind, s.Namespace, s.Name)
}
return fmt.Sprintf("%s/%s", s.Kind, s.Name)
}

View File

@ -147,7 +147,7 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
source, err := r.getSource(ctx, kustomization)
if err != nil {
if apierrors.IsNotFound(err) {
msg := "Source not found"
msg := fmt.Sprintf("Source '%s' not found", kustomization.Spec.SourceRef.String())
kustomization = kustomizev1.KustomizationNotReady(kustomization, "", kustomizev1.ArtifactFailedReason, msg)
if err := r.patchStatus(ctx, req, kustomization.Status); err != nil {
log.Error(err, "unable to update status for source not found")