mirror of https://github.com/k3s-io/k3s
Add a flag to allow to schedule workload to the master node
parent
798bbaa83f
commit
6a20487b38
|
@ -45,6 +45,7 @@ type InitFlags struct {
|
|||
DNSDomain string
|
||||
}
|
||||
CloudProvider string
|
||||
Schedulable bool
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue