Fix error reporting during pod service account creation

This commit is contained in:
Sergey Dudoladov 2018-04-20 14:20:38 +02:00
parent bd51d2922b
commit 5daf0a4172
1 changed files with 8 additions and 7 deletions

View File

@ -202,12 +202,12 @@ func (c *Cluster) initUsers() error {
func (c *Cluster) createPodServiceAccounts() error { func (c *Cluster) createPodServiceAccounts() error {
podServiceAccountName := c.Config.OpConfig.PodServiceAccountName podServiceAccountName := c.Config.OpConfig.PodServiceAccountName
c.setProcessName("creating pod service account in the watched namespaces") c.setProcessName(fmt.Sprintf("creating pod service account in the namespace %v", c.Namespace))
_, err := c.KubeClient.ServiceAccounts(c.Namespace).Get(podServiceAccountName, metav1.GetOptions{}) _, err := c.KubeClient.ServiceAccounts(c.Namespace).Get(podServiceAccountName, metav1.GetOptions{})
if err != nil { if err != nil {
c.logger.Warnf("the pod service account %q is absent from the namespace %q. Stateful sets in the namespace are unable to create pods.", podServiceAccountName, c.Namespace) c.logger.Warnf("the pod service account %q cannot be retrieved in the namespace %q. Stateful sets in the namespace may be unable to create pods. Error: %v", podServiceAccountName, c.Namespace, err)
// when created, each Cluster struct gets a separate copy of OpConfig // when created, each Cluster struct gets a separate copy of OpConfig
// including the nested PodServiceAccount struct, so no race condition here // including the nested PodServiceAccount struct, so no race condition here
@ -215,15 +215,16 @@ func (c *Cluster) createPodServiceAccounts() error {
_, err = c.KubeClient.ServiceAccounts(c.Namespace).Create(&c.OpConfig.PodServiceAccount) _, err = c.KubeClient.ServiceAccounts(c.Namespace).Create(&c.OpConfig.PodServiceAccount)
if err != nil { if err != nil {
c.logger.Warnf("cannot deploy the pod service account %q defined in the config map to the %q namespace: %v", podServiceAccountName, c.Namespace, err) return fmt.Errorf("cannot deploy the pod service account %q defined in the config map to the %q namespace: %v", podServiceAccountName, c.Namespace, err)
} else {
c.logger.Infof("successfully deployed the pod service account %q to the %q namespace", podServiceAccountName, c.Namespace)
} }
c.logger.Infof("successfully deployed the pod service account %q to the %q namespace", podServiceAccountName, c.Namespace)
} else { } else {
c.logger.Infof("successfully found the service account %q used to create pods to the namespace %q", podServiceAccountName, c.Namespace) c.logger.Infof("successfully found the service account %q used to create pods to the namespace %q", podServiceAccountName, c.Namespace)
} }
return err return nil
} }
// Create creates the new kubernetes objects associated with the cluster. // Create creates the new kubernetes objects associated with the cluster.
@ -289,7 +290,7 @@ func (c *Cluster) Create() error {
c.logger.Infof("pod disruption budget %q has been successfully created", util.NameFromMeta(pdb.ObjectMeta)) c.logger.Infof("pod disruption budget %q has been successfully created", util.NameFromMeta(pdb.ObjectMeta))
if err = c.createPodServiceAccounts(); err != nil { if err = c.createPodServiceAccounts(); err != nil {
return fmt.Errorf("could not sync pod service accounts: %v", err) return fmt.Errorf("could not create pod service account %v : %v", c.OpConfig.PodServiceAccountName, err)
} }
c.logger.Infof("pod service accounts have been successfully synced") c.logger.Infof("pod service accounts have been successfully synced")