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

This commit is contained in:
Evgeny L
2016-09-15 16:12:33 +00:00
committed by Ilya Dmitrichenko
parent 798bbaa83f
commit 6a20487b38
4 changed files with 20 additions and 8 deletions

View File

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

View File

@@ -77,6 +77,10 @@ func NewCmdInit(out io.Writer, s *kubeadmapi.KubeadmConfig) *cobra.Command {
&s.InitFlags.CloudProvider, "cloud-provider", "", &s.InitFlags.CloudProvider, "cloud-provider", "",
`(optional) enable cloud proiver features (external load-balancers, storage, etc)`, `(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 return cmd
} }
@@ -135,7 +139,7 @@ func RunInit(out io.Writer, cmd *cobra.Command, args []string, s *kubeadmapi.Kub
return err return err
} }
if err := kubemaster.UpdateMasterRoleLabelsAndTaints(client); err != nil { if err := kubemaster.UpdateMasterRoleLabelsAndTaints(client, s.Schedulable); err != nil {
return err 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", &s.InitFlags.Services.DNSDomain, "service-dns-domain", "cluster.local",
`(optional) use alterantive domain name for services, e.g. "myorg.internal"`, `(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 return cmd
} }
@@ -181,7 +185,7 @@ func RunManualBootstrapInitMaster(out io.Writer, cmd *cobra.Command, args []stri
return err return err
} }
if err := kubemaster.UpdateMasterRoleLabelsAndTaints(client); err != nil { if err := kubemaster.UpdateMasterRoleLabelsAndTaints(client, s.Schedulable); err != nil {
return err return err
} }

View File

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