Skip to content

Latest commit

 

History

History
83 lines (68 loc) · 3.45 KB

1.ExportingProjects.md

File metadata and controls

83 lines (68 loc) · 3.45 KB

Converting OpenShift Projects to Kubernetes Namespaces

OpenShift projects can be mapped to Kubernetes Namespaces.

Generating Kubernetes namespace for each OpenShift Project.

If you are migrating individual projects, here is a typical script to convert an OpenShift Project to Kubernetes namespace. Substitute the variable names accordingly before running.

PROJECT_NAME=<<yourprojectname>>
oc get project $PROJECT_NAME -o yaml | \
yq e '.apiVersion |= "v1"' - \
| yq e '.kind |= "Namespace"' - \
| yq e 'del(.metadata.creationTimestamp)' - \
| yq e 'del(.metadata.annotations.*)' - \
| yq e 'del(.metadata.managedFields)' - \
| yq e 'del(.metadata.labels)' - \
| yq e 'del(.metadata.resourceVersion)' - \
| yq e 'del(.metadata.selfLink)' - \
| yq e 'del(.metadata.uid)' - \
| yq e 'del(.status)' -

Running across the entire OpenShift Cluster

If you are migrating the whole cluster, you can generate namespace yamls for all the project running user workloads.

In a typical openshift cluster projects are used for cluster services as well. All projects beginning with kube- and openshift- are cluster services. In addition, there may be other projects like istio-system, knative-serving, knative-eventing etc, that run other services. While we are applying filters to not migrate such projects, depending on what is running on the cluster you may need additional filtering or you may need to remove any namespaces that should not be migrated.

Projects can be filtered by editing the PROJECT_FILTERS variable in the script below. The following script will show you list of projects.

PROJECT_FILTERS="^openshift-\|^kube-\|^istio-system\|^knative-"
for i in $(oc get projects -o jsonpath='{.items[*].metadata.name}'); do 
  if grep -v "$PROJECT_FILTERS" <<< $i ; then 
     echo $i 
  fi 
done

Based on what you installed on your cluster, you may have other openshift projects that you don't want to migrate. Verify the project listed to see if you want to filter any more. Edit the PROJECT_FILTERS as required and re-run.

Run the following command to generate kubernetes namespace configurations for the OpenShift projects. These namespaces will be saved into clusterconfigs/namespaces folder.

mkdir -p clusterconfigs/namespaces
PROJECT_FILTERS="^openshift-\|^kube-\|^istio-system\|^knative-"
for i in $(oc get projects -o jsonpath='{.items[*].metadata.name}'); do 
if grep -v "$PROJECT_FILTERS" <<< $i ; then 
    echo "Exporting Project: " $i; \
    mkdir -p clusterconfigs/namespaces/$i; \
    oc get project $i -o yaml | \
    yq e '.apiVersion |= "v1"' - \
    | yq e '.kind |= "Namespace"' - \
    | yq e 'del(.metadata.creationTimestamp)' - \
    | yq e 'del(.metadata.annotations.*)' - \
    | yq e 'del(.metadata.managedFields)' - \
    | yq e 'del(.metadata.labels)' - \
    | yq e 'del(.metadata.resourceVersion)' - \
    | yq e 'del(.metadata.selfLink)' - \
    | yq e 'del(.metadata.uid)' - \
    | yq e 'del(.status)' -  \
    > clusterconfigs/namespaces/$i/namespace.yaml
fi
done

List all the namespace yamls generated in clusterconfigs by running ls clusterconfigs/namespaces/NAMESPACE Verify each namespace file to make sure it is in the format you expect.

As an example:

$ cat clusterconfigs/namespaces/demo/namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  annotations: {}
  name: demo
spec:
  finalizers:
    - kubernetes