이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Appendix A. Restore owner references script


This Bash script is for restoring the ownerReferences when restoring Red Hat Trusted Artifact Signer (RHTAS) data to a different OpenShift cluster.

#!/bin/bash

# List of resources to check
RESOURCES=("Fulcio" "Rekor" "Trillian" "TimestampAuthority" "CTlog" "Tuf")


function validate_owner() {
    local RESOURCE=$1
    local ITEM=$2
    local OWNER_NAME=$3

    # Check all the labels exist and are the same
    LABELS=("app.kubernetes.io/instance" "app.kubernetes.io/part-of" "velero.io/backup-name" "velero.io/restore-name")
    for LABEL in "${LABELS[@]}"; do
        PARENT_LABEL=$(oc get Securesign "$OWNER_NAME" -o json | jq -r ".metadata.labels[\"$LABEL\"]")
        CHILD_LABEL=$(oc get $RESOURCE "$ITEM" -o json | jq -r ".metadata.labels[\"$LABEL\"]")

        if [[ -z "$CHILD_LABEL" || $CHILD_LABEL == "null" ]]; then
            echo "  $LABEL label missing in $RESOURCE"
            return 1
        elif [[ -z "$PARENT_LABEL" || $PARENT_LABEL == "null" ]]; then
            echo "  $LABEL label missing in Securesign"
            return 1
        elif [[ "$CHILD_LABEL" != "$PARENT_LABEL" ]]; then
            echo "  $LABEL labels not matching: $CHILD_LABEL != $PARENT_LABEL"
            return 1
        fi
    done

    return 0
}


for RESOURCE in "${RESOURCES[@]}"; do
    echo "Checking $RESOURCE ..."

    # Get all resources missing ownerReferences
    MISSING_REFS=$(oc get $RESOURCE -o json | jq -r '.items[] | select(.metadata.ownerReferences == null) | .metadata.name')

    for ITEM in $MISSING_REFS; do
        echo "  Missing ownerReferences in $RESOURCE/$ITEM"

        # Find the expected owner based on labels
        OWNER_NAME=$(oc get $RESOURCE "$ITEM" -o json | jq -r '.metadata.labels["app.kubernetes.io/name"]')

        if [[ -z "$OWNER_NAME" || "$OWNER_NAME" == "null" ]]; then
            echo "  Skipping $RESOURCE/$ITEM: name not found in labels"
            continue
        fi

        if ! validate_owner $RESOURCE $ITEM $OWNER_NAME; then
          echo "  Skipping ..."
          continue
        fi

        # Try to get the owner's UID from Securesign
        OWNER_UID=$(oc get Securesign "$OWNER_NAME" -o jsonpath='{.metadata.uid}' 2>/dev/null)

        if [[ -z "$OWNER_UID" || "$OWNER_UID" == "null" ]]; then
            echo "  Failed to find Securesign/$OWNER_NAME UID, skipping ..."
            continue
        fi

        echo "  Found owner: Securesign/$OWNER_NAME (UID: $OWNER_UID)"

        # Patch the object with the restored ownerReference
        oc patch $RESOURCE "$ITEM" --type='merge' -p "{
          \"metadata\": {
            \"ownerReferences\": [
              {
                \"apiVersion\": \"rhtas.redhat.com/v1alpha1\",
                \"kind\": \"Securesign\",
                \"name\": \"$OWNER_NAME\",
                \"uid\": \"$OWNER_UID\",
                \"controller\": true,
                \"blockOwnerDeletion\": true
              }
            ]
          }
        }"

        echo "Restored ownerReferences for $RESOURCE/$ITEM"
    done
done

echo "Done"
Copy to Clipboard Toggle word wrap
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat