2017-12-14 21:56:19 +00:00
|
|
|
package authz
|
|
|
|
|
|
|
|
import (
|
2018-01-09 22:10:56 +00:00
|
|
|
"context"
|
|
|
|
|
2017-12-14 21:56:19 +00:00
|
|
|
"github.com/rancher/rke/k8s"
|
2018-01-09 22:10:56 +00:00
|
|
|
"github.com/rancher/rke/log"
|
2017-12-16 03:37:45 +00:00
|
|
|
"github.com/rancher/rke/templates"
|
2017-12-14 21:56:19 +00:00
|
|
|
)
|
|
|
|
|
2018-01-09 22:10:56 +00:00
|
|
|
func ApplyJobDeployerServiceAccount(ctx context.Context, kubeConfigPath string) error {
|
|
|
|
log.Infof(ctx, "[authz] Creating rke-job-deployer ServiceAccount")
|
2017-12-14 21:56:19 +00:00
|
|
|
k8sClient, err := k8s.NewClient(kubeConfigPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-12-16 03:37:45 +00:00
|
|
|
if err := k8s.UpdateClusterRoleBindingFromYaml(k8sClient, templates.JobDeployerClusterRoleBinding); err != nil {
|
2017-12-14 21:56:19 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-12-16 03:37:45 +00:00
|
|
|
if err := k8s.UpdateServiceAccountFromYaml(k8sClient, templates.JobDeployerServiceAccount); err != nil {
|
2017-12-14 21:56:19 +00:00
|
|
|
return err
|
|
|
|
}
|
2018-01-09 22:10:56 +00:00
|
|
|
log.Infof(ctx, "[authz] rke-job-deployer ServiceAccount created successfully")
|
2017-12-14 21:56:19 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-01-09 22:10:56 +00:00
|
|
|
func ApplySystemNodeClusterRoleBinding(ctx context.Context, kubeConfigPath string) error {
|
|
|
|
log.Infof(ctx, "[authz] Creating system:node ClusterRoleBinding")
|
2017-12-14 21:56:19 +00:00
|
|
|
k8sClient, err := k8s.NewClient(kubeConfigPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-12-16 03:37:45 +00:00
|
|
|
if err := k8s.UpdateClusterRoleBindingFromYaml(k8sClient, templates.SystemNodeClusterRoleBinding); err != nil {
|
2017-12-14 21:56:19 +00:00
|
|
|
return err
|
|
|
|
}
|
2018-01-09 22:10:56 +00:00
|
|
|
log.Infof(ctx, "[authz] system:node ClusterRoleBinding created successfully")
|
2017-12-14 21:56:19 +00:00
|
|
|
return nil
|
|
|
|
}
|