openshift/openshift-restclient-python

Is there a support for oc adm ?

michalrabinowitch opened this issue · 2 comments

I wish to run the following command using the client - is it supported?
If not any chance this can be done with some request ?
oc adm policy add-scc-to-group scc system:serviceaccounts:my-project
Thanks!

Yes, it is possible to achieve this, although it's not quite as easy as through the command line client. Basically, to add an scc to a group, you need to GET the scc, edit its definition to include your group, and then PUT the scc. It would look something like this, assuming that your scc is called myscc and your group is called mygroup:

import kubernetes
from openshift.dynamic import DynamicClient
GROUP_NAME = 'mygroup'
SCC_NAME = 'myscc'

client = DynamicClient(kubernetes.config.new_client_from_config())
v1_scc = client.resources.get(api_version='security.openshift.io/v1', kind='SecurityContextConstraints')

myscc = v1_scc.get(name=SCC_NAME)
myscc.groups.append(GROUP_NAME)
v1_scc.replace(body=myscc)

if you run oc adm policy add-scc-to-group scc system:serviceaccounts:my-project --v=8, you'll see that this is also the series of requests made by the command line client.

Let me know if you have any issues!

@fabianvf thanks for your help !