new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/Domain.java
private static boolean createRbacApiObjectsForWLDFScript(String domainNamespace, String opNamespace)
      throws ApiException {
    LoggingFacade logger = getLogger();
    // create cluster role
    if (!clusterRoleExists(WLDF_CLUSTER_ROLE_NAME)) {
      logger.info("Creating cluster role {0}", WLDF_CLUSTER_ROLE_NAME);

      V1ClusterRole v1ClusterRole = new V1ClusterRole()
          .kind(RBAC_CLUSTER_ROLE)
          .apiVersion(RBAC_API_VERSION)
          .metadata(new V1ObjectMeta()
              .name(WLDF_CLUSTER_ROLE_NAME))
          .addRulesItem(new V1PolicyRule()
              .addApiGroupsItem("weblogic.oracle")
              .addResourcesItem("domains")
              .addVerbsItem("get")
              .addVerbsItem("list")
              .addVerbsItem("update"))
          .addRulesItem(new V1PolicyRule()
              .addApiGroupsItem("apiextensions.k8s.io")
              .addResourcesItem("customresourcedefinitions")
              .addVerbsItem("get")
              .addVerbsItem("list"));

      if (!createClusterRole(v1ClusterRole)) {
        return false;
      }
    }

    // create cluster role binding
    if (!clusterRoleBindingExists(WLDF_CLUSTER_ROLE_BINDING_NAME)) {
      logger.info("Creating cluster role binding {0}", WLDF_CLUSTER_ROLE_BINDING_NAME);

      V1ClusterRoleBinding v1ClusterRoleBinding = new V1ClusterRoleBinding()
          .kind(RBAC_CLUSTER_ROLE_BINDING)
          .apiVersion(RBAC_API_VERSION)
          .metadata(new V1ObjectMeta()
              .name(WLDF_CLUSTER_ROLE_BINDING_NAME))
          .addSubjectsItem(new V1Subject()
              .kind("ServiceAccount")
              .name("default")
              .namespace(domainNamespace)
              .apiGroup(""))
          .roleRef(new V1RoleRef()
              .kind(RBAC_CLUSTER_ROLE)
              .name(WLDF_CLUSTER_ROLE_NAME)
              .apiGroup(RBAC_API_GROUP));

      if (!createClusterRoleBinding(v1ClusterRoleBinding)) {
        return false;
      }
    }

    // create domain operator role binding
    if (!roleBindingExists(WLDF_ROLE_BINDING_NAME, opNamespace)) {
      logger.info("Creating role binding {0} in namespace {1}", WLDF_ROLE_BINDING_NAME, opNamespace);

      V1RoleBinding v1RoleBinding = new V1RoleBinding()
          .kind(RBAC_ROLE_BINDING)
          .apiVersion(RBAC_API_VERSION)
          .metadata(new V1ObjectMeta()
              .name(WLDF_ROLE_BINDING_NAME)
              .namespace(opNamespace))
          .addSubjectsItem(new V1Subject()
              .kind("ServiceAccount")
              .name("default")
              .namespace(domainNamespace)
              .apiGroup(""))
          .roleRef(new V1RoleRef()
              .kind(RBAC_CLUSTER_ROLE)
              .name("cluster-admin")
              .apiGroup(RBAC_API_GROUP));

      return createNamespacedRoleBinding(opNamespace, v1RoleBinding);
    }

    return true;
  }
/**
   * Create cluster role, cluster role binding and role binding used by WLDF script action.
   *
   * @param domainNamespace WebLogic domain namespace
   * @param opNamespace WebLogic operator namespace
   */
Create cluster role, cluster role binding and role binding used by WLDF script action.
@param domainNamespace WebLogic domain namespace
@param opNamespace WebLogic operator namespace
Create cluster role cluster role binding and role binding used by WLDF script action . @param domainNamespace WebLogic domain namespace @param opNamespace WebLogic operator namespace
private static boolean createRbacApiObjectsForWLDFScript(String domainNamespace, String opNamespace)
      throws ApiException {
    LoggingFacade logger = getLogger();
    if (!clusterRoleExists(WLDF_CLUSTER_ROLE_NAME)) {
      logger.info("Creating cluster role {0}", WLDF_CLUSTER_ROLE_NAME);
      V1ClusterRole v1ClusterRole = new V1ClusterRole()
          .kind(RBAC_CLUSTER_ROLE)
          .apiVersion(RBAC_API_VERSION)
          .metadata(new V1ObjectMeta()
              .name(WLDF_CLUSTER_ROLE_NAME))
          .addRulesItem(new V1PolicyRule()
              .addApiGroupsItem("weblogic.oracle")
              .addResourcesItem("domains")
              .addVerbsItem("get")
              .addVerbsItem("list")
              .addVerbsItem("update"))
          .addRulesItem(new V1PolicyRule()
              .addApiGroupsItem("apiextensions.k8s.io")
              .addResourcesItem("customresourcedefinitions")
              .addVerbsItem("get")
              .addVerbsItem("list"));
      if (!createClusterRole(v1ClusterRole)) {
        return false;
      }
    }
     binding
    if (!clusterRoleBindingExists(WLDF_CLUSTER_ROLE_BINDING_NAME)) {
      logger.info("Creating cluster role binding {0}", WLDF_CLUSTER_ROLE_BINDING_NAME);
      V1ClusterRoleBinding v1ClusterRoleBinding = new V1ClusterRoleBinding()
          .kind(RBAC_CLUSTER_ROLE_BINDING)
          .apiVersion(RBAC_API_VERSION)
          .metadata(new V1ObjectMeta()
              .name(WLDF_CLUSTER_ROLE_BINDING_NAME))
          .addSubjectsItem(new V1Subject()
              .kind("ServiceAccount")
              .name("default")
              .namespace(domainNamespace)
              .apiGroup(""))
          .roleRef(new V1RoleRef()
              .kind(RBAC_CLUSTER_ROLE)
              .name(WLDF_CLUSTER_ROLE_NAME)
              .apiGroup(RBAC_API_GROUP));
      if (!createClusterRoleBinding(v1ClusterRoleBinding)) {
        return false;
      }
    }
    if (!roleBindingExists(WLDF_ROLE_BINDING_NAME, opNamespace)) {
      logger.info("Creating role binding {0} in namespace {1}", WLDF_ROLE_BINDING_NAME, opNamespace);
      V1RoleBinding v1RoleBinding = new V1RoleBinding()
          .kind(RBAC_ROLE_BINDING)
          .apiVersion(RBAC_API_VERSION)
          .metadata(new V1ObjectMeta()
              .name(WLDF_ROLE_BINDING_NAME)
              .namespace(opNamespace))
          .addSubjectsItem(new V1Subject()
              .kind("ServiceAccount")
              .name("default")
              .namespace(domainNamespace)
              .apiGroup(""))
          .roleRef(new V1RoleRef()
              .kind(RBAC_CLUSTER_ROLE)
              .name("cluster-admin")
              .apiGroup(RBAC_API_GROUP));
      return createNamespacedRoleBinding(opNamespace, v1RoleBinding);
    }
    return true;
  }
private static boolean createRbacApiObjectsForWLDFScript ( String domainNamespace , String opNamespace ) throws ApiException { LoggingFacade logger = getLogger ( ) ; if ( ! clusterRoleExists ( WLDF_CLUSTER_ROLE_NAME ) ) { logger . info ( "Creating cluster role {0}" , WLDF_CLUSTER_ROLE_NAME ) ; V1ClusterRole v1ClusterRole = new V1ClusterRole ( ) . kind ( RBAC_CLUSTER_ROLE ) . apiVersion ( RBAC_API_VERSION ) . metadata ( new V1ObjectMeta ( ) . name ( WLDF_CLUSTER_ROLE_NAME ) ) . addRulesItem ( new V1PolicyRule ( ) . addApiGroupsItem ( "weblogic.oracle" ) . addResourcesItem ( "domains" ) . addVerbsItem ( "get" ) . addVerbsItem ( "list" ) . addVerbsItem ( "update" ) ) . addRulesItem ( new V1PolicyRule ( ) . addApiGroupsItem ( "apiextensions.k8s.io" ) . addResourcesItem ( "customresourcedefinitions" ) . addVerbsItem ( "get" ) . addVerbsItem ( "list" ) ) ; if ( ! createClusterRole ( v1ClusterRole ) ) { return false ; } } if ( ! clusterRoleBindingExists ( WLDF_CLUSTER_ROLE_BINDING_NAME ) ) { logger . info ( "Creating cluster role binding {0}" , WLDF_CLUSTER_ROLE_BINDING_NAME ) ; V1ClusterRoleBinding v1ClusterRoleBinding = new V1ClusterRoleBinding ( ) . kind ( RBAC_CLUSTER_ROLE_BINDING ) . apiVersion ( RBAC_API_VERSION ) . metadata ( new V1ObjectMeta ( ) . name ( WLDF_CLUSTER_ROLE_BINDING_NAME ) ) . addSubjectsItem ( new V1Subject ( ) . kind ( "ServiceAccount" ) . name ( "default" ) . namespace ( domainNamespace ) . apiGroup ( "" ) ) . roleRef ( new V1RoleRef ( ) . kind ( RBAC_CLUSTER_ROLE ) . name ( WLDF_CLUSTER_ROLE_NAME ) . apiGroup ( RBAC_API_GROUP ) ) ; if ( ! createClusterRoleBinding ( v1ClusterRoleBinding ) ) { return false ; } } if ( ! roleBindingExists ( WLDF_ROLE_BINDING_NAME , opNamespace ) ) { logger . info ( "Creating role binding {0} in namespace {1}" , WLDF_ROLE_BINDING_NAME , opNamespace ) ; V1RoleBinding v1RoleBinding = new V1RoleBinding ( ) . kind ( RBAC_ROLE_BINDING ) . apiVersion ( RBAC_API_VERSION ) . metadata ( new V1ObjectMeta ( ) . name ( WLDF_ROLE_BINDING_NAME ) . namespace ( opNamespace ) ) . addSubjectsItem ( new V1Subject ( ) . kind ( "ServiceAccount" ) . name ( "default" ) . namespace ( domainNamespace ) . apiGroup ( "" ) ) . roleRef ( new V1RoleRef ( ) . kind ( RBAC_CLUSTER_ROLE ) . name ( "cluster-admin" ) . apiGroup ( RBAC_API_GROUP ) ) ; return createNamespacedRoleBinding ( opNamespace , v1RoleBinding ) ; } return true ; }
Create cluster role, cluster role binding and role binding used by WLDF script action.
Create cluster role cluster role binding and role binding used by WLDF script action .
// create cluster role // create cluster role binding // create domain operator role binding