Skip to content

Instantly share code, notes, and snippets.

@sdodson
Created February 19, 2018 21:29
Show Gist options
  • Select an option

  • Save sdodson/d584c7659b92d4350b8a7baee24d26ec to your computer and use it in GitHub Desktop.

Select an option

Save sdodson/d584c7659b92d4350b8a7baee24d26ec to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import subprocess
system_hostname = subprocess.Popen("hostname -f", shell=True, stdout=subprocess.PIPE).stdout.read().strip()
port = '443'
cluster_hostname = subprocess.Popen("grep masterURL /etc/origin/master/master-config.yaml | awk '{ print $2 }' | cut -d/ -f3 | cut -d: -f1", shell=True, stdout=subprocess.PIPE).stdout.read().strip()
print "oc config set-cluster --certificate-authority=/etc/origin/master/ca.crt --embed-certs=true --server=https://{0}:{1} {2}:{1} --config=/etc/origin/master/openshift-master.kubeconfig".format(system_hostname, port, system_hostname.replace('.', '-'))
print "oc config set-context --cluster={0}:{1} --namespace=default --user=system:openshift-master/{2}:{1} default/{0}:{1}/system:openshift-master --config=/etc/origin/master/openshift-master.kubeconfig".format(system_hostname.replace('.', '-'), port, cluster_hostname.replace('.', '-'))
print "oc config use-context default/{0}:{1}/system:openshift-master --config=/etc/origin/master/openshift-master.kubeconfig".format(system_hostname.replace('.', '-'), port)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment