Skip to content

Commit

Permalink
delete storageclass from cs cr
Browse files Browse the repository at this point in the history
Signed-off-by: Allen Li <[email protected]>
  • Loading branch information
qpdpQ committed Dec 11, 2024
1 parent 6cfa446 commit 6182c5c
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions preload_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,36 @@ function copy_resource() {
local newResourceName=${3:-$resourceName}
title " Copying $resourceType $resourceName from $FROM_NAMESPACE to $TO_NAMESPACE "
resource_exists=$(${OC} get $resourceType $resourceName -n $FROM_NAMESPACE || echo "fail")
storageClass_exist=$(${OC} get $resourceType $resourceName -n $FROM_NAMESPACE -o yaml | yq '.spec | has("storageClass")')
if [[ $resource_exists != "fail" ]]; then
$OC get $resourceType $resourceName -n $FROM_NAMESPACE -o yaml | \
$YQ '
.metadata.name = "'$newResourceName'" |
del(.metadata.creationTimestamp) |
del(.metadata.resourceVersion) |
del(.metadata.namespace) |
del(.metadata.uid) |
del(.metadata.ownerReferences) |
del(.metadata.managedFields) |
del(.metadata.labels)
' | \
$OC apply -n $TO_NAMESPACE -f - || error "Failed to copy over $resourceType $resourceName."

if [[ $resourceType == "commonservice" && $storageClass_exist == "true"]]; then
$OC get $resourceType $resourceName -n $FROM_NAMESPACE -o yaml | \
$YQ '
.metadata.name = "'$newResourceName'" |
del(.metadata.creationTimestamp) |
del(.metadata.resourceVersion) |
del(.metadata.namespace) |
del(.metadata.uid) |
del(.metadata.ownerReferences) |
del(.metadata.managedFields) |
del(.metadata.labels) |
del(.spec.storageClass)
' | \
$OC apply -n $TO_NAMESPACE -f - || error "Failed to copy over $resourceType $resourceName."
else
$OC get $resourceType $resourceName -n $FROM_NAMESPACE -o yaml | \
$YQ '
.metadata.name = "'$newResourceName'" |
del(.metadata.creationTimestamp) |
del(.metadata.resourceVersion) |
del(.metadata.namespace) |
del(.metadata.uid) |
del(.metadata.ownerReferences) |
del(.metadata.managedFields) |
del(.metadata.labels)
' | \
$OC apply -n $TO_NAMESPACE -f - || error "Failed to copy over $resourceType $resourceName."
fi
# Check if the resource is created in TO_NAMESPACE
check_copied_resource $resourceType $newResourceName $TO_NAMESPACE
else
Expand Down

0 comments on commit 6182c5c

Please sign in to comment.