Created
August 29, 2017 11:43
-
-
Save treacher/fe1a1f8cece6e9dd1c5ce63aa8e2cc67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (c *NamespaceController) createRoleBinding(obj interface{}) { | |
namespaceObj := obj.(*v1.Namespace) | |
namespaceName := namespaceObj.Name | |
roleBinding := &v1beta1.RoleBinding{ | |
TypeMeta: metav1.TypeMeta{ | |
Kind: "RoleBinding", | |
APIVersion: "rbac.authorization.k8s.io/v1beta1", | |
}, | |
ObjectMeta: metav1.ObjectMeta{ | |
Name: fmt.Sprintf("ad-kubernetes-%s", namespaceName), | |
Namespace: namespaceName, | |
}, | |
Subjects: []v1beta1.Subject{ | |
v1beta1.Subject{ | |
Kind: "Group", | |
Name: fmt.Sprintf("ad-kubernetes-%s", namespaceName), | |
}, | |
}, | |
RoleRef: v1beta1.RoleRef{ | |
APIGroup: "rbac.authorization.k8s.io", | |
Kind: "ClusterRole", | |
Name: "edit", | |
}, | |
} | |
_, err := c.kclient.Rbac().RoleBindings(namespaceName).Create(roleBinding) | |
if err != nil { | |
log.Println(fmt.Sprintf("Failed to create Role Binding: %s", err.Error())) | |
} else { | |
log.Println(fmt.Sprintf("Created AD RoleBinding for Namespace: %s", roleBinding.Name)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment