// Execute will add rbac permissions for coredns to sync cluster information
Execute will add rbac permissions for coredns to sync cluster information
// Execute will add rbac permissions for coredns to sync cluster information
func (p *updatePhaseCoreDNS) Execute(ctx context.Context) error {
	_, err := p.kubernetesOperation.Client.RbacV1().ClusterRoles().
		Create(ctx, &rbacv1.ClusterRole{
			ObjectMeta: metav1.ObjectMeta{Name: CoreDNSResourceName},
			Rules: []rbacv1.PolicyRule{
				{
					APIGroups: []string{""},
					Verbs:     []string{"list", "watch"},
					Resources: []string{"endpoints", "services", "namespaces", "pods"},
				},
			},
		}, metav1.CreateOptions{})
	err = rigging.ConvertError(err)
	if err != nil {
		if trace.IsAlreadyExists(err) {
			p.Infof("ClusterRoles/%v already exists, skiping...", CoreDNSResourceName)
		} else {
			return trace.Wrap(err)
		}
	} else {
		p.Infof("ClusterRole/%v created.", CoreDNSResourceName)
	}
	_, err = p.kubernetesOperation.Client.RbacV1().ClusterRoleBindings().
		Create(ctx, &rbacv1.ClusterRoleBinding{
			ObjectMeta: metav1.ObjectMeta{Name: CoreDNSResourceName},
			RoleRef: rbacv1.RoleRef{
				APIGroup: "rbac.authorization.k8s.io",
				Kind:     "ClusterRole",
				Name:     CoreDNSResourceName,
			},
			Subjects: []rbacv1.Subject{
				{
					Kind:     "User",
					Name:     "coredns",
					APIGroup: "rbac.authorization.k8s.io",
				},
			},
		}, metav1.CreateOptions{})
	err = rigging.ConvertError(err)
	if err != nil {
		if trace.IsAlreadyExists(err) {
			p.Infof("ClusterRoleBinding/%v already exists, skiping...", CoreDNSResourceName)
		} else {
			return trace.Wrap(err)
		}
	} else {
		p.Infof("ClusterRoleBinding/%v created.", CoreDNSResourceName)
	}
	err = p.generateCorefile(ctx)
	return trace.Wrap(err)
}
func ( p * updatePhaseCoreDNS ) Execute ( ctx context . Context ) error { _ , err := p . kubernetesOperation . Client . RbacV1 ( ) . ClusterRoles ( ) . Create ( ctx , & rbacv1 . ClusterRole { ObjectMeta : metav1 . ObjectMeta { Name : CoreDNSResourceName } , Rules : [ ] rbacv1 . PolicyRule { { APIGroups : [ ] string { " " } , Verbs : [ ] string { " " , " " } , Resources : [ ] string { " " , " " , " " , " " } , } , } , } , metav1 . CreateOptions { } ) err = rigging . ConvertError ( err ) if err != nil { if trace . IsAlreadyExists ( err ) { p . Infof ( " " , CoreDNSResourceName ) } else { return trace . Wrap ( err ) } } else { p . Infof ( " " , CoreDNSResourceName ) } _ , err = p . kubernetesOperation . Client . RbacV1 ( ) . ClusterRoleBindings ( ) . Create ( ctx , & rbacv1 . ClusterRoleBinding { ObjectMeta : metav1 . ObjectMeta { Name : CoreDNSResourceName } , RoleRef : rbacv1 . RoleRef { APIGroup : " " , Kind : " " , Name : CoreDNSResourceName , } , Subjects : [ ] rbacv1 . Subject { { Kind : " " , Name : " " , APIGroup : " " , } , } , } , metav1 . CreateOptions { } ) err = rigging . ConvertError ( err ) if err != nil { if trace . IsAlreadyExists ( err ) { p . Infof ( " " , CoreDNSResourceName ) } else { return trace . Wrap ( err ) } } else { p . Infof ( " " , CoreDNSResourceName ) } err = p . generateCorefile ( ctx ) return trace . Wrap ( err ) }
Execute will add rbac permissions for coredns to sync cluster information
Execute will add rbac permissions for coredns to sync cluster information