Commit f25419ca authored by Brad Davidson's avatar Brad Davidson Committed by Brad Davidson

Add ServiceAccount for svclb pods

For 1.24 and earlier, the svclb pods need a ServiceAccount so that we can allow their sysctls in PSPs Signed-off-by: 's avatarBrad Davidson <brad.davidson@rancher.com>
parent 8016ae2b
...@@ -56,6 +56,10 @@ func (k *k3s) Register(ctx context.Context, ...@@ -56,6 +56,10 @@ func (k *k3s) Register(ctx context.Context,
return err return err
} }
if err := k.createServiceLBServiceAccount(ctx); err != nil {
return err
}
go wait.Until(k.runWorker, time.Second, ctx.Done()) go wait.Until(k.runWorker, time.Second, ctx.Done())
return k.removeServiceFinalizers(ctx) return k.removeServiceFinalizers(ctx)
...@@ -74,6 +78,20 @@ func (k *k3s) createServiceLBNamespace(ctx context.Context) error { ...@@ -74,6 +78,20 @@ func (k *k3s) createServiceLBNamespace(ctx context.Context) error {
return err return err
} }
// createServiceLBServiceAccount ensures that the ServiceAccount used by pods exists
func (k *k3s) createServiceLBServiceAccount(ctx context.Context) error {
_, err := k.client.CoreV1().ServiceAccounts(k.LBNamespace).Create(ctx, &core.ServiceAccount{
ObjectMeta: meta.ObjectMeta{
Name: "svclb",
Namespace: k.LBNamespace,
},
}, meta.CreateOptions{})
if apierrors.IsAlreadyExists(err) {
return nil
}
return err
}
// onChangePod handles changes to Pods. // onChangePod handles changes to Pods.
// If the pod has labels that tie it to a service, and the pod has an IP assigned, // If the pod has labels that tie it to a service, and the pod has an IP assigned,
// enqueue an update to the service's status. // enqueue an update to the service's status.
...@@ -422,6 +440,7 @@ func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) { ...@@ -422,6 +440,7 @@ func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) {
}, },
}, },
Spec: core.PodSpec{ Spec: core.PodSpec{
ServiceAccountName: "svclb",
AutomountServiceAccountToken: utilpointer.Bool(false), AutomountServiceAccountToken: utilpointer.Bool(false),
}, },
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment