Commit 974af49e authored by Jordan Liggitt's avatar Jordan Liggitt

Tolerate AlreadyExists errors when creating service accounts

parent 990c0184
...@@ -22,6 +22,7 @@ import ( ...@@ -22,6 +22,7 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
apierrs "k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/meta" "k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/client/cache" "k8s.io/kubernetes/pkg/client/cache"
client "k8s.io/kubernetes/pkg/client/unversioned" client "k8s.io/kubernetes/pkg/client/unversioned"
...@@ -206,17 +207,18 @@ func (e *ServiceAccountsController) createServiceAccountIfNeeded(name, namespace ...@@ -206,17 +207,18 @@ func (e *ServiceAccountsController) createServiceAccountIfNeeded(name, namespace
e.createServiceAccount(name, namespace) e.createServiceAccount(name, namespace)
} }
// createDefaultServiceAccount creates a default ServiceAccount in the specified namespace // createServiceAccount creates a ServiceAccount with the specified name and namespace
func (e *ServiceAccountsController) createServiceAccount(name, namespace string) { func (e *ServiceAccountsController) createServiceAccount(name, namespace string) {
serviceAccount := &api.ServiceAccount{} serviceAccount := &api.ServiceAccount{}
serviceAccount.Name = name serviceAccount.Name = name
serviceAccount.Namespace = namespace serviceAccount.Namespace = namespace
if _, err := e.client.ServiceAccounts(namespace).Create(serviceAccount); err != nil { _, err := e.client.ServiceAccounts(namespace).Create(serviceAccount)
if err != nil && !apierrs.IsAlreadyExists(err) {
glog.Error(err) glog.Error(err)
} }
} }
// getDefaultServiceAccount returns the ServiceAccount with the given name for the given namespace // getServiceAccount returns the ServiceAccount with the given name for the given namespace
func (e *ServiceAccountsController) getServiceAccount(name, namespace string) (*api.ServiceAccount, error) { func (e *ServiceAccountsController) getServiceAccount(name, namespace string) (*api.ServiceAccount, error) {
key := &api.ServiceAccount{ObjectMeta: api.ObjectMeta{Namespace: namespace}} key := &api.ServiceAccount{ObjectMeta: api.ObjectMeta{Namespace: namespace}}
accounts, err := e.serviceAccounts.Index("namespace", key) accounts, err := e.serviceAccounts.Index("namespace", key)
......
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