Add a flag to allow to schedule workload to the master node

pull/6/head
Evgeny L 2016-09-15 16:12:33 +00:00 committed by Ilya Dmitrichenko
parent 798bbaa83f
commit 6a20487b38
No known key found for this signature in database
GPG Key ID: E7889175A6C0CEB9
4 changed files with 20 additions and 8 deletions

View File

@ -45,6 +45,7 @@ type InitFlags struct {
DNSDomain string
}
CloudProvider string
Schedulable bool
}
const (

View File

@ -77,6 +77,10 @@ func NewCmdInit(out io.Writer, s *kubeadmapi.KubeadmConfig) *cobra.Command {
&s.InitFlags.CloudProvider, "cloud-provider", "",
`(optional) enable cloud proiver features (external load-balancers, storage, etc)`,
)
cmd.PersistentFlags().BoolVar(
&s.InitFlags.Schedulable, "schedule-workload", false,
`(optional) allow to schedule workload to the node`,
)
return cmd
}
@ -135,7 +139,7 @@ func RunInit(out io.Writer, cmd *cobra.Command, args []string, s *kubeadmapi.Kub
return err
}
if err := kubemaster.UpdateMasterRoleLabelsAndTaints(client); err != nil {
if err := kubemaster.UpdateMasterRoleLabelsAndTaints(client, s.Schedulable); err != nil {
return err
}

View File

@ -129,6 +129,10 @@ func NewCmdManualBootstrapInitMaster(out io.Writer, s *kubeadmapi.KubeadmConfig)
&s.InitFlags.Services.DNSDomain, "service-dns-domain", "cluster.local",
`(optional) use alterantive domain name for services, e.g. "myorg.internal"`,
)
cmd.PersistentFlags().BoolVar(
&s.InitFlags.Schedulable, "schedule-workload", false,
`(optional) allow to schedule workload to the node`,
)
return cmd
}
@ -181,7 +185,7 @@ func RunManualBootstrapInitMaster(out io.Writer, cmd *cobra.Command, args []stri
return err
}
if err := kubemaster.UpdateMasterRoleLabelsAndTaints(client); err != nil {
if err := kubemaster.UpdateMasterRoleLabelsAndTaints(client, s.Schedulable); err != nil {
return err
}

View File

@ -159,21 +159,24 @@ func findMyself(client *clientset.Clientset) (*api.Node, error) {
return node, nil
}
func attemptToUpdateMasterRoleLabelsAndTaints(client *clientset.Clientset) error {
func attemptToUpdateMasterRoleLabelsAndTaints(client *clientset.Clientset, schedulable bool) error {
n, err := findMyself(client)
if err != nil {
return err
}
n.ObjectMeta.Labels["kubeadm.alpha.kubernetes.io/role"] = "master"
taintsAnnotation, _ := json.Marshal([]api.Taint{{Key: "dedicated", Value: "master", Effect: "NoSchedule"}})
n.ObjectMeta.Annotations[api.TaintsAnnotationKey] = string(taintsAnnotation)
if !schedulable {
taintsAnnotation, _ := json.Marshal([]api.Taint{{Key: "dedicated", Value: "master", Effect: "NoSchedule"}})
n.ObjectMeta.Annotations[api.TaintsAnnotationKey] = string(taintsAnnotation)
}
if _, err := client.Nodes().Update(n); err != nil {
if apierrs.IsConflict(err) {
fmt.Println("<master/apiclient> temporarily unable to update master node metadata due to conflict (will retry)")
time.Sleep(500 * time.Millisecond)
attemptToUpdateMasterRoleLabelsAndTaints(client)
attemptToUpdateMasterRoleLabelsAndTaints(client, schedulable)
} else {
return err
}
@ -182,8 +185,8 @@ func attemptToUpdateMasterRoleLabelsAndTaints(client *clientset.Clientset) error
return nil
}
func UpdateMasterRoleLabelsAndTaints(client *clientset.Clientset) error {
err := attemptToUpdateMasterRoleLabelsAndTaints(client)
func UpdateMasterRoleLabelsAndTaints(client *clientset.Clientset, schedulable bool) error {
err := attemptToUpdateMasterRoleLabelsAndTaints(client, schedulable)
if err != nil {
return fmt.Errorf("<master/apiclient> failed to update master node - %s", err)
}