Example #1
0
 def create_agent_clusterrole(self, clusterrole_path,
                              clusterrolebinding_path):
     clusterrole_yaml = yaml.load(open(clusterrole_path).read())
     self.clusterrole_name = clusterrole_yaml["metadata"]["name"]
     clusterrolebinding_yaml = yaml.load(
         open(clusterrolebinding_path).read())
     self.clusterrolebinding_name = clusterrolebinding_yaml["metadata"][
         "name"]
     if self.namespace != "default":
         self.clusterrole_name = self.clusterrole_name + "-" + self.namespace
         clusterrole_yaml["metadata"]["name"] = self.clusterrole_name
         self.clusterrolebinding_name = self.clusterrolebinding_name + "-" + self.namespace
         clusterrolebinding_yaml["metadata"][
             "name"] = self.clusterrolebinding_name
     if clusterrolebinding_yaml["roleRef"]["kind"] == "ClusterRole":
         clusterrolebinding_yaml["roleRef"]["name"] = self.clusterrole_name
     for subject in clusterrolebinding_yaml["subjects"]:
         subject["namespace"] = self.namespace
     if not k8s.has_clusterrole(self.clusterrole_name):
         print('Creating cluster role "%s" from %s ...' %
               (self.clusterrole_name, clusterrole_path))
         k8s.create_clusterrole(clusterrole_yaml)
     if not k8s.has_clusterrolebinding(self.clusterrolebinding_name):
         print('Creating cluster role binding "%s" from %s ...' %
               (self.clusterrolebinding_name, clusterrolebinding_path))
         k8s.create_clusterrolebinding(clusterrolebinding_yaml)
Example #2
0
def create_cluster_admin_rolebinding(minikube):
    clusterrolebinding_yaml = yaml.load(open(CLUSTERROLEBINDING_YAML_PATH).read())
    name = clusterrolebinding_yaml.get("metadata", {}).get("name")
    assert name, "name not found in %s" % CLUSTERROLEBINDING_YAML_PATH
    print("Creating %s cluster role binding ..." % name)
    create_clusterrolebinding(body=clusterrolebinding_yaml)
    minikube.exec_kubectl("describe clusterrolebinding %s" % name)