for ns in $(ls clusterconfigs/namespaces); do
echo "Exporting manifests for namespace: " $ns;
mkdir -p ocp-manifests/namespaces/$ns;
for dc in $(oc get dc -n $ns -o jsonpath='{.items[*].metadata.name}' ); do
echo "Exporting DeploymentConfigs: " $dc;
oc get dc $dc -n $ns -o yaml \
| yq e 'del(.metadata.creationTimestamp)' - \
| yq e 'del(.metadata.annotations.*)' - \
| yq e 'del(.metadata.labels.template*)' - \
| yq e 'del(.metadata.labels.xpaas)' - \
| yq e 'del(.metadata.resourceVersion)' - \
| yq e 'del(.metadata.selfLink)' - \
| yq e 'del(.metadata.uid)' - \
| yq e 'del(.metadata.generation)' - \
| yq e 'del(.metadata.managedFields)' - \
| yq e 'del(.status)' - \
> ocp-manifests/namespaces/$ns/$dc-dc.yaml;
done;
done
for ns in $(ls clusterconfigs/namespaces); do
echo "Exporting manifests for namespace: " $ns;
mkdir -p ocp-manifests/namespaces/$ns;
for deployment in $(oc get deployments -n $ns -o jsonpath='{.items[*].metadata.name}' ); do
echo "Exporting Deployments: " $deployment;
oc get deployment $deployment -n $ns -o yaml \
| yq e 'del(.metadata.creationTimestamp)' - \
| yq e 'del(.metadata.annotations.*)' - \
| yq e 'del(.metadata.labels.template*)' - \
| yq e 'del(.metadata.labels.xpaas)' - \
| yq e 'del(.metadata.resourceVersion)' - \
| yq e 'del(.metadata.selfLink)' - \
| yq e 'del(.metadata.uid)' - \
| yq e 'del(.metadata.generation)' - \
| yq e 'del(.metadata.managedFields)' - \
| yq e 'del(.status)' - \
> ocp-manifests/namespaces/$ns/$deployment-deployment.yaml
done;
done
CAUTION: You may not want to export secrets to a git repository
SECRET_FILTERS="^builder-\|^deployer-\|^default-\|^pipeline-"
oc get secrets -n demo -o jsonpath='{.items[*].metadata.name}' | grep -v $SECRET_FILTERS
for ns in $(ls clusterconfigs/namespaces); do
echo "Exporting manifests for namespace: " $ns;
mkdir -p ocp-manifests/namespaces/$ns;
for secret in $(oc get secrets -n $ns -o jsonpath='{.items[*].metadata.name}' ); do
if grep -v "$SECRET_FILTERS" <<< $secret ; then
echo "Exporting Secret: " $secret;
oc get secret $secret -n $ns -o yaml \
| yq e 'del(.metadata.creationTimestamp)' - \
| yq e 'del(.metadata.annotations.*)' - \
| yq e 'del(.metadata.resourceVersion)' - \
| yq e 'del(.metadata.selfLink)' - \
| yq e 'del(.metadata.uid)' - \
| yq e 'del(.metadata.generateName)' - \
| yq e 'del(.metadata.managedFields)' - \
| yq e 'del(.status)' - \
> ocp-manifests/namespaces/$ns/$secret-secret.yaml
fi
done;
done
for ns in $(ls clusterconfigs/namespaces); do
echo "Exporting manifests for namespace: " $ns;
mkdir -p ocp-manifests/namespaces/$ns;
for is in $(oc get is -n $ns -o jsonpath='{.items[*].metadata.name}' ); do
echo "Exporting ImageStreams: " $is;
oc get is $is -n $ns -o yaml \
| yq e 'del(.metadata.creationTimestamp)' - \
| yq e 'del(.metadata.annotations.*)' - \
| yq e 'del(.metadata.resourceVersion)' - \
| yq e 'del(.metadata.selfLink)' - \
| yq e 'del(.metadata.generation)' - \
| yq e 'del(.metadata.managedFields)' - \
| yq e 'del(.metadata.uid)' - \
> ocp-manifests/namespaces/$ns/$is-is.yaml
done;
done
for ns in $(ls clusterconfigs/namespaces); do
echo "Exporting manifests for namespace: " $ns;
mkdir -p ocp-manifests/namespaces/$ns;
for service in $(oc get service -n $ns -o jsonpath='{.items[*].metadata.name}' ); do
echo "Exporting service: " $service;
oc get svc $service -n $ns -o yaml \
| yq e 'del(.metadata.creationTimestamp)' - \
| yq e 'del(.metadata.annotations.*)' - \
| yq e 'del(.metadata.labels.template*)' - \
| yq e 'del(.metadata.labels.xpaas)' - \
| yq e 'del(.metadata.resourceVersion)' - \
| yq e 'del(.metadata.selfLink)' - \
| yq e 'del(.metadata.uid)' - \
| yq e 'del(.metadata.managedFields)' - \
| yq e 'del(.status)' - \
| yq e 'del(.spec.clusterIP)' - \
| yq e 'del(.spec.clusterIPs)' - \
> ocp-manifests/namespaces/$ns/$service-service.yaml
done;
done
for ns in $(ls clusterconfigs/namespaces); do
echo "Exporting manifests for namespace: " $ns;
mkdir -p ocp-manifests/namespaces/$ns;
for route in $(oc get route -n $ns -o jsonpath='{.items[*].metadata.name}' ); do
echo "Exporting Route: " $route;
oc get route $route -n $ns -o yaml \
| yq e 'del(.metadata.creationTimestamp)' - \
| yq e 'del(.metadata.annotations.*)' - \
| yq e 'del(.metadata.labels.template*)' - \
| yq e 'del(.metadata.labels.xpaas)' - \
| yq e 'del(.metadata.resourceVersion)' - \
| yq e 'del(.metadata.selfLink)' - \
| yq e 'del(.metadata.managedFields)' - \
| yq e 'del(.metadata.uid)' - \
| yq e 'del(.status)' - \
> ocp-manifests/namespaces/$ns/$route-route.yaml
done;
done
for ns in $(ls clusterconfigs/namespaces); do
echo "Exporting manifests for namespace: " $ns;
mkdir -p ocp-manifests/namespaces/$ns;
for cm in $(oc get cm -n $ns -o jsonpath='{.items[*].metadata.name}' ); do
echo "Exporting ConfigMap: " $cm;
oc get cm $cm -n $ns -o yaml \
| yq e 'del(.metadata.creationTimestamp)' - \
| yq e 'del(.metadata.annotations.*)' - \
| yq e 'del(.metadata.resourceVersion)' - \
| yq e 'del(.metadata.selfLink)' - \
| yq e 'del(.metadata.managedFields)' - \
| yq e 'del(.metadata.uid)' - \
| yq e 'del(.status)' - \
> ocp-manifests/namespaces/$ns/$cm-cm.yaml
done;
done
for ns in $(ls clusterconfigs/namespaces); do
echo "Exporting manifests for namespace: " $ns;
mkdir -p ocp-manifests/namespaces/$ns;
for pvc in $(oc get pvc -n $ns -o jsonpath='{.items[*].metadata.name}' ); do
echo "Exporting PVC: " $pvc;
oc get pvc $pvc -n $ns -o yaml \
| yq e 'del(.metadata.creationTimestamp)' - \
| yq e 'del(.metadata.annotations.*)' - \
| yq e 'del(.metadata.resourceVersion)' - \
| yq e 'del(.metadata.selfLink)' - \
| yq e 'del(.metadata.managedFields)' - \
| yq e 'del(.metadata.uid)' - \
| yq e 'del(.status)' - \
> ocp-manifests/namespaces/$ns/$pvc-pvc.yaml
done;
done